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 foreach my $infile (@ARGV) {
15 if (! -r $infile) { die "$0: Unable to read $infile\n"; }
21 if (!$ARGV[0]) { die "Usage: $0 <files> > nki.inf\n"; }
24 print "! The following code was automatically generated by nki2inf.pl\n";
25 print "! Do not edit this file.\n";
26 print "! Instead, edit your raw NKI list and run nki2inf.pl again.\n";
28 print "! Because you can't directly use double quotes, backslashes,\n";
29 print "! tildes, or atsigns in Inform, the following substitutions\n";
30 print "! are used to generate those characters:\n";
32 print "! ~ --> \@\@126\n";
33 print "! \\ --> \@\@92\n";
34 print "! \@ --> \@\@64\n\n";
36 print "[ lookup_msg num;\n";
37 print "\tswitch(num) {\n";
39 foreach my $infile (@ARGV) {
40 open (INFILE, "< $infile") || die "$0: Cannot open $infile\n";
44 next if /^\s*($|#|!)/;
48 $line =~ s/@/\@\@64/g;
49 $line =~ s/\\/\@\@92/g;
50 print "$count:\treturn \"$line\";\n";
53 print "default: return \"Unknown NKI (this should not happen)\";\n\t}\n];\n";
54 print "Constant MESSAGE_NUM $count;\n";