Added Nitfol and Frotz source code.
[projects/chimara/chimara.git] / interpreters / nitfol / y2help.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 # Generate help (both C and texinfo) from inform.y
5 #
6 # This one doesn't even pretend to be nitfol-independant.
7
8 my $helptext;
9 my $helpcommand;
10 my $helpargs;
11 my @helpentry;
12 my %helptable;
13
14 # command => [ [ argtype1, argtype2, ... ], helptext [ helpname, ... ] ]
15
16 while(<>) {
17     if(/^\/\* :: (.*) \*\//) {
18         $helptext = $1;
19         $_ = <>;
20         /\| (\S+)\s *(.*?(\/\*.*?\*\/)?.*?)\{/;
21         $helpcommand = $1;
22         $_ = $2;
23         s/\/\*(.*?)\*\//$1/;
24         s/\'(.)\'/$1/;
25         s/NUM/\@var\{num\}/g;
26         s/FILE/\@var\{file\}/g;
27         s/commaexp/\@var\{exp\}/g;
28         s/linespec/\@var\{linespec\}/g;
29         s/IF/if/g;               # Ugly, but oh well...
30         s/TO/to/g;
31         $helpargs = $_;
32         if($helptable{$helpcommand}[0]) {
33             push @{ $helptable{$helpcommand}[0] }, $helpargs;
34             $helptable{$helpcommand}[1] = $helptable{$helpcommand}[1] . "\\n" . $helptext;
35         } else {
36             @{ $helptable{$helpcommand}[0] } = ( $helpargs );
37             $helptable{$helpcommand}[1] = $helptext;
38         }
39     } elsif(/static name_token infix_commands/) {
40         while(<> =~ /\{\s*(\S+)\,\s*\"(.*?)\"\s*\}/) {
41             $helpcommand = $1; $helptext = $2;
42             push @{ $helptable{$helpcommand}[2] }, $helptext;
43         }
44     }
45 }
46
47 open("MYTEXINFO", ">dbg_help.texi") || die "Unable to write to dbg_help.texi";
48 select "MYTEXINFO";
49
50 foreach $helpcommand ( keys %helptable) {
51     my $tag = "\@item ";
52     foreach my $helparg (@{ $helptable{$helpcommand}[0] }) {
53         print $tag, @{$helptable{$helpcommand}[2]}[0], " $helparg\n";
54         $tag = "\@itemx ";
55     }
56     $_ = $helptable{$helpcommand}[1];
57     s/\\n/  /g;
58     print "$_\n\n";
59 }
60
61 close "MYTEXINFO";
62
63 open("MYCHELP",   ">dbg_help.h")    || die "Unable to write to dbg_help.c";
64 select "MYCHELP";
65
66 print "static name_token command_help[] = {\n";
67
68 my $flag = 0;
69 foreach $helpcommand ( keys %helptable) {
70     if($flag) {
71         print ",\n";
72     }
73     $flag = 1;
74     print "  { $helpcommand, \"", texi2txt($helptable{$helpcommand}[1]), "\" }";
75 }
76 print "\n};\n";
77 close "MYCHELP";
78
79 sub texi2txt
80 {
81     $_ = $_[0];
82     s/\@code\{(.*?)\}/\'$1\'/g;
83     s/\@file\{(.*?)\}/\'$1\'/g;
84     s/\@\@/\@/g;
85     return $_;
86 }