changeset 112:f690940e9118 misc

Improvements.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 19 Dec 2010 18:37:59 +0000
parents 70acbee45ec3
children cf1e0eeb686e
files materials/mkalloyinfo.sh materials/parsealloys.pl materials/parsematerial.pl
diffstat 3 files changed, 41 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/materials/mkalloyinfo.sh	Sun Dec 05 23:53:32 2010 +0000
+++ b/materials/mkalloyinfo.sh	Sun Dec 19 18:37:59 2010 +0000
@@ -8,7 +8,7 @@
 
 echo "Generating alloy data ..."
 cat ggr_alloys.txt data-*.log > tmp
-tail -45000 ~/tiny.log | grep -B1 "^You mix .* and create a quantity of " >> tmp
+cat $HOME/tf/logs/*.log | grep -B1 "^You mix .* and create a quantity of " >> tmp
 perl -w parsealloys.pl -php < tmp > "$ALLOYPHP"
 perl -w parsealloys.pl < tmp > "$ALLOYTXT"
 
--- a/materials/parsealloys.pl	Sun Dec 05 23:53:32 2010 +0000
+++ b/materials/parsealloys.pl	Sun Dec 19 18:37:59 2010 +0000
@@ -34,7 +34,7 @@
 
 while (<STDIN>) {
   chomp;
-  if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+)$/) {
+  if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+?)\.?$/) {
     addCombo($1, $2, $3);
   } elsif (/^([a-zA-Z0-9]+)#([a-z ]+)\+([a-z ]+)=([a-z ]+)$/) {
     addCombo($2, $3, $4);
--- a/materials/parsematerial.pl	Sun Dec 05 23:53:32 2010 +0000
+++ b/materials/parsematerial.pl	Sun Dec 19 18:37:59 2010 +0000
@@ -2,13 +2,19 @@
 # Superklunssi by Ggr
 use strict;
 
-my ($opt_header, $opt_csv, $opt_tf);
+my $opt_header = 0;
+my $opt_mode = "";
 
-if ($#ARGV >= 0) {
-  if ($ARGV[0] eq "-head") { $opt_header = 1; }
-  elsif ($ARGV[0] eq "-csv") { $opt_csv = 1; }
-  elsif ($ARGV[0] eq "-tf") { $opt_tf = 1; }
-}   
+while (defined(my $arg = shift)) {
+  if ($arg eq "-head") { $opt_header = 1; }
+  elsif ($arg eq "-csv") { $opt_mode = $arg; }
+  elsif ($arg eq "-tf") { $opt_mode = $arg; }
+  elsif ($arg eq "-names") { $opt_mode = $arg; }
+  else {
+    die("Invalid option '$arg'\n");
+  }
+}
+
 
 my @titles = (
   "Name","Weight","Sturdyness","Magic","Flammability",
@@ -104,9 +110,31 @@
   }
 }
 
+# Sort the entries by name
 my @entries = sort { $a cmp $b } keys %data;
 
-if ($opt_csv) {
+
+# Print header
+if ($opt_header) {
+  my $str = "";
+  for (my $i = 0; $i < @names; $i++) {
+    $str .= sprintf("%-".$widths[$i]."s | ", $titles[$i]);
+  }
+  print "$str\n";
+  $str =~ s/[^|]/-/g;
+  $str =~ s/\|/+/g;
+  print "$str\n";
+}
+
+# Print names only
+if ($opt_mode eq "-names") {
+  foreach my $name (@entries) {
+    print "$name\n";
+  }
+}
+
+# Print CSV list
+elsif ($opt_mode eq "-csv") {
   foreach my $name (@entries) {
     my $s = "";
     foreach my $field (@names) {
@@ -118,16 +146,10 @@
     }
     print "$s\n";
   }
-} elsif ($opt_header) {
-  my $str = "";
-  for (my $i = 0; $i < @names; $i++) {
-    $str .= sprintf("%-".$widths[$i]."s | ", $titles[$i]);
-  }
-  print "$str\n";
-  $str =~ s/[^|]/-/g;
-  $str =~ s/\|/+/g;
-  print "$str\n";
-} elsif ($opt_tf) {
+}
+
+# Print TinyFugue formatted data
+elsif ($opt_mode eq "-tf") {
   print "/set gmat_names=".join(' ', @entries)."\n";
   print "/set gmat_ntypes=".join(' ', map(lc($data{$_}{"type"}), @entries))."\n";