changeset 16:3c0717d36741 misc

Output material name tables too.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Apr 2009 14:26:49 +0000
parents 79c79d865218
children da0c7dc4952a
files materials/csv2phpsql.pl
diffstat 1 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/materials/csv2phpsql.pl	Thu Apr 16 12:40:12 2009 +0000
+++ b/materials/csv2phpsql.pl	Thu Apr 16 14:26:49 2009 +0000
@@ -286,7 +286,7 @@
 ###
 ### Parse input
 ###
-my $opts = shift || die("Usage: kakka [-sql|-php] < material_info.csv\n");
+my $opts = shift || die("Usage: kakka [-sql|-php|-mat] < material_info.csv\n");
 
 my %data = ();
 while (<STDIN>) {
@@ -308,16 +308,27 @@
 ###
 ### Dump data ...
 ###
-
-if ($opts eq "-php") {
-  print "<?\n";
-  print "\$transNameTable = array(";
+if ($opts eq "-mat") {
+  print "my \%alloyNames = (";
+  my $n = 0;
+  foreach my $i (sort { $a cmp $b } keys %data) {
+    print "\"$i\" => $n,";
+    $n++;
+  }
+  print ");\n\n";
+  print "my \@alloyNameTable = (";
+  foreach my $i (sort { $a cmp $b } keys %data) {
+    print "\"$i\",";
+  }
+  print ");\n\n";
+} elsif ($opts eq "-php") {
+  print "<?\n".
+  "\$transNameTable = array(";
   foreach my $i (@names) {
     print "\"$i\",";
   }
-  print ");\n\n";
-
-  print "\$transTable = array(\n";
+  print ");\n\n".
+  "\$transTable = array(\n";
   foreach my $i (sort { $a <=> $b } keys %transtab) {
     print "  array(";
     foreach my $j (keys %{$transtab{$i}}) {
@@ -328,10 +339,9 @@
     }
     print "),\n";
   }
-  print ");\n\n";
-
-  print "\$matTable = array(\n";
-  foreach my $i (sort keys %data) {
+  print ");\n\n".
+  "\$matTable = array(\n";
+  foreach my $i (sort { $a cmp $b } keys %data) {
     print "  \"$i\" => array(";
     foreach my $j (sort { $a <=> $b } keys %{$data{$i}}) {
       my $s = $data{$i}{$j};
@@ -363,7 +373,7 @@
 );
   |;
 
-  foreach my $i (sort keys %data) {
+  foreach my $i (sort { $a cmp $b } keys %data) {
     print "INSERT INTO material_info VALUES ('$i', ";
     foreach my $j (sort { $a <=> $b } keys %{$data{$i}}) {
       my $s = $data{$i}{$j};