3 # Usage: nk2inf.pl foobar.nki > nki.inf
5 # The Z-machine wants all of a program's data to be in the executable
6 # file. For the Inform edition of robotfindskitten, nki's are generated
7 # by a very long case statement. This script emits that case statement
8 # and a constant defining MESSAGE_NUM to the number of NKIs found. The
9 # result is then added to kitten.inf with an Include statement.
11 # This script automatically takes care of '`', '\', and '@' by replacing
12 # them with '@@126', '@@92', and '@@64' respectively.
14 my $infile = $ARGV[0];
18 if (!$infile) { die "Usage: $0 foobar.nki > nki.inf\n"; }
20 open (INFILE, "< $infile") || die "$0: Cannot open $infile\n";
22 print "! The following code was automatically generated by nki2inf.pl\n";
23 print "! Do not edit this file.\n";
24 print "! Instead, edit your raw NKI list and run nki2inf.pl again.\n";
26 print "! Because you can't directly use double quotes, backslashes,\n";
27 print "! tildes, or atsigns in Inform, the following substitutions\n";
28 print "! are used to generate those characters:\n";
30 print "! ~ --> \@\@126\n";
31 print "! \\ --> \@\@92\n";
32 print "! \@ --> \@\@64\n\n";
34 print "[ lookup_msg num;\n";
35 print "\tswitch(num) {\n";
39 next if /^\s*($|#|!)/;
43 $line =~ s/@/\@\@64/g;
44 $line =~ s/\\/\@\@92/g;
45 print "$count:\treturn \"$line\";\n";
47 print "default: return \"Unknown NKI (this should not happen)\";\n\t}\n];\n";
48 print "Constant MESSAGE_NUM $count;\n";