#!/usr/bin/perl

sub abort;

$file    = $ARGV[0];
$theme   = $ARGV[1];

if (!defined($file)) {
   abort " must define a file name \n\n";
}
if (!defined($theme)) {
   abort " must define a theme \n\n";
}
                                                                                

$fileout = "$file.sql";
open (OUT,">$fileout") || die print "cannot open output SQL file"; 
print OUT "use pirate1 ;\n";


open(IN,"$file");
@page = (<IN>);
close(IN);

$counter = 0;
foreach (@page) {
 $counter = $counter + 1;
# print $_;
 $inputline = $_;
 chop $inputline;
 $firstchar = substr($inputline,0,1);
 $firstchar =~ tr/a-z/A-Z/;
 $rest = substr($inputline,1,999);
# print OUT "$firstchar"."$rest";
 $line = "$firstchar"."$rest";
 
 ($name,$definition) = split(' \| ',$line);

  print "name is $name definition = $definition \n";
  print OUT " insert into DOM_Names_All (NAME,EXPLANATION,THEME) values(\"$name\",\"$definition\",\"$theme\");\n";
}

close (OUT);



print "\n\n $counter names found in $file for theme $theme \n\n";

print " to insert names into the database do this\n";
print "      mysql pirate1 -u tester -h fat-dbs -p < $file.sql    \n";
sub abort {
    my $why = shift;
    die <<EOF;
 
Sorry, the script failed.  Here's why:
 
   $why
 
EOF
;
}
 
