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.
19 print STDERR localtime() ." ($$) $0 Starting\n";
23 # Bewitched, debugged and bewildered?
26 # SGML headers - use for debugging your SGML output :)
29 # Definitions of things....
34 # Default output level
37 # Command line parameters
38 if(my $var = shift(@ARGV))
43 # Disable line buffering
49 print("<!doctype linuxdoc system>\n") ;
50 print("<article>\n") ;
65 # Is this a command definition line?
66 # if(m/^=== ([\d])\^([\w,\W]*)\^([\w,\W]*)/)
67 if(m/^=== ([\d])\^(.*)\^(.*)/)
74 print("Command $2\n") ;
75 print("Description $3\n") ;
81 $help{$cmd}{level} = $1 ;
82 $help{$cmd}{command} = $2 ;
83 $help{$cmd}{description} = $3 ;
85 # Not a command definition line - Carry On Appending(tm)....
88 $help{$cmd}{comment} .= $_ . "\n" ;
93 # Go through all of the records in the hash in order
94 foreach $cmd (sort(keys %help))
96 # Level checking goes here.
97 if($help{$cmd}{level} > $level) { next ; }
99 # Need to change characters that SGML doesn't like at this point.
100 # Perhaps we should use a function for each of these variables?
102 $help{$cmd}{command} =~ s/</</g ;
103 $help{$cmd}{command} =~ s/>/>/g ;
105 $help{$cmd}{command} =~ s/\[/[/g ;
106 $help{$cmd}{command} =~ s/\]/]/g ;
107 # Change to lower case
108 $help{$cmd}{command} = lc($help{$cmd}{command}) ;
111 $help{$cmd}{description} =~ s/</</g ;
112 $help{$cmd}{description} =~ s/>/>/g ;
115 if($help{$cmd}{comment})
117 $help{$cmd}{comment} =~ s/</</g ;
118 $help{$cmd}{comment} =~ s/>/>/g ;
121 # Output the section details and command summary.
122 print("<sect1>$help{$cmd}{command}") ;
123 if($level > 0) { print(" ($help{$cmd}{level})") ; }
127 print("<bf>$help{$cmd}{command}</bf> $help{$cmd}{description}\n") ;
131 # Output the command comments.
134 # Loop through each line of the command comments.
135 # If the first character of the line is whitespace, then use tscreen
136 # Once a tscreen block has started, continue until the next blank line.
139 # Is the comment field blank? Then trying to split will error - lets not.
140 if(!$help{$cmd}{comment})
145 # Work through the comments line by line
146 foreach $line (split('\n', $help{$cmd}{comment}))
148 # Leading whitespace or not?
149 if($line =~ m/^\s+\S+/)
154 print("<tscreen><verb>\n") ;
162 print("</verb></tscreen>\n") ;
168 # We fell out of the command comments still in a block - Ouch....
171 print("</verb></tscreen>\n\n") ;
175 print("</article>\n") ;
177 # Is it 'cos we is dun ?
178 print STDERR localtime()." ($$) $0 Exiting ($count read)\n" ;