3 # cat Commands_en.hlp | ./commands2sgml.pl <level> > commands.sgml
4 # Level 0 is assumed by default.
6 # This Perl may not be nice but it seems to work :)
7 # This is supposed to take a spider command definition file and
8 # convert it to SGML format suitable for inclusion in the spider manual.
10 # It is cunningly written with no language in mind, and should work for all
11 # command files in whatever language.
13 # I claim no suitability for purpose, and should this script mutate and eat
14 # your children I'm afraid I'm not responsible. Wild herds of rampaging
15 # Taiwanese suicide squirrels attacking your rabbit are also not my fault.
17 # Ian (M0AZM) 20030210.
22 print STDERR localtime() ." ($$) $0 Starting\n";
26 # Bewitched, debugged and bewildered?
29 # SGML headers - use for debugging your SGML output :)
32 # Definitions of things....
37 # Default output level, take $ARGV[0] as being a level
38 my $level = shift || 0 ;
40 # Disable line buffering
45 print("<!doctype linuxdoc system>\n") ;
46 print("<article>\n") ;
58 # Is this a command definition line?
59 # if(m/^=== ([\d])\^([\w,\W]*)\^([\w,\W]*)/)
60 if (/^=== ([\d])\^(.*)\^(.*)/) {
65 print("Command $2\n") ;
66 print("Description $3\n") ;
72 $help{$cmd}{level} = $1 ;
73 $help{$cmd}{command} = $2 ;
74 $help{$cmd}{description} = $3 ;
76 # Not a command definition line - Carry On Appending(tm)....
77 $help{$cmd}{comment} .= $_ . "\n" ;
82 # Go through all of the records in the hash in order
83 foreach $cmd (sort(keys %help)) {
85 # Level checking goes here.
86 next if $help{$cmd}{level} > $level;
88 # Need to change characters that SGML doesn't like at this point.
89 # Perhaps we should use a function for each of these variables?
91 $help{$cmd}{command} =~ s/</</g ;
92 $help{$cmd}{command} =~ s/>/>/g ;
95 $help{$cmd}{command} =~ s/\[/[/g ;
96 $help{$cmd}{command} =~ s/\]/]/g ;
98 # Change to lower case
99 $help{$cmd}{command} = lc($help{$cmd}{command}) ;
102 $help{$cmd}{description} =~ s/</</g ;
103 $help{$cmd}{description} =~ s/>/>/g ;
106 if ($help{$cmd}{comment}) {
107 $help{$cmd}{comment} =~ s/</</g ;
108 $help{$cmd}{comment} =~ s/>/>/g ;
111 # Output the section details and command summary.
112 print("<sect1>$help{$cmd}{command}") ;
113 print(" ($help{$cmd}{level})") if $level > 0;
117 print("<bf>$help{$cmd}{command}</bf> $help{$cmd}{description}\n") ;
121 # Output the command comments.
124 # Loop through each line of the command comments.
125 # If the first character of the line is whitespace, then use tscreen
126 # Once a tscreen block has started, continue until the next blank line.
129 # Is the comment field blank? Then trying to split will error - lets not.
130 next unless $help{$cmd}{comment};
132 # Work through the comments line by line
133 foreach $line (split('\n', $help{$cmd}{comment})) {
134 # Leading whitespace or not?
135 if ($line =~ /^\s+\S+/) {
138 print("<tscreen><verb>\n") ;
143 print("</verb></tscreen>\n") ;
149 # We fell out of the command comments still in a block - Ouch....
151 print("</verb></tscreen>\n\n") ;
155 print("</article>\n") ;
157 # Is it 'cos we is dun ?
158 print STDERR localtime()." ($$) $0 Exiting ($count read)\n" ;