#!/usr/bin/perl 
############################################### 
# Convert all the .wo files in a given directory to WOOgnl format
############################################### 

use strict;

opendir(COMPONENTS, $ARGV[0]);
my @allfiles = readdir COMPONENTS;
foreach my $file (@allfiles) {
	if ($file =~ /.*?\.wo/ ) {
		print("processing \"$file\"...\n");
		my @lines = `convertToWOOgnl.pl $ARGV[0]/$file`;
		$file =~ /(.*?)\.wo/;
		my $fileName = $1;
		# now replace the contents of the HTML file with the output of the conversion and blank out the wod
		open(HTML,">$ARGV[0]/$file/$fileName.html") || die("Cannot Open File");
		foreach my $line (@lines) {
			print HTML "$line"; 
		}
		close(HTML);
		open(WOD,">$ARGV[0]/$file/$fileName.wod") || die("Cannot Open File");
		close(WOD);
	} else {
		print("skipping \"$file\"...\n");
	}
}
