Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | #!/usr/local/bin/perl |
| 2 | # $Id: doc2.pl,v 1.1.1.1 2003/11/04 23:34:58 mjames Exp $ |
||
| 3 | # $Log: doc2.pl,v $ |
||
| 4 | # Revision 1.1.1.1 2003/11/04 23:34:58 mjames |
||
| 5 | # Imported into local repositrory |
||
| 6 | # |
||
| 7 | # Revision 1.7 2002/09/30 13:26:33 MJAMES |
||
| 8 | # Files split from one HTML monster into one per command |
||
| 9 | # |
||
| 10 | # Revision 1.1.1.1 2002/09/09 15:06:16 mjames |
||
| 11 | # no message |
||
| 12 | # |
||
| 13 | # Revision 1.6 2002/08/06 12:52:44 mjames |
||
| 14 | # Merge in from latest version |
||
| 15 | # |
||
| 16 | # Revision 1.6 2002/03/08 14:56:13 mjames |
||
| 17 | # Edited all of the commands in the cmdexec1.c and cmdexec2.c files |
||
| 18 | # so that they can be read by doc2.pl |
||
| 19 | # |
||
| 20 | # Revision 1.5 2001/12/20 13:54:19 mjames |
||
| 21 | # Update version number to 15.1 |
||
| 22 | # |
||
| 23 | # Revision 1.4 2001/10/31 22:20:03 mjames |
||
| 24 | # Tidying up problematical comments caused by CVS |
||
| 25 | # 'intelligent' comment guessing |
||
| 26 | # |
||
| 27 | # Revision 1.3 2001/10/02 20:54:45 mjames |
||
| 28 | # Tidied up the formatted HTML, making sensible crossreference |
||
| 29 | # links from within document text. |
||
| 30 | # |
||
| 31 | # Revision 1.2 2001/10/01 21:56:47 mjames |
||
| 32 | # Added crossreferences from text |
||
| 33 | # SO that e.g see fred command' will generate an html link to fred. |
||
| 34 | # |
||
| 35 | # Argument 0 is file to index |
||
| 36 | # Argument is path to output file. |
||
| 37 | # |
||
| 38 | # State variable $i = |
||
| 39 | #1 = title |
||
| 40 | #2 = text |
||
| 41 | #3 = listing |
||
| 42 | #0 = nothing |
||
| 43 | |||
| 44 | # phase 1 : open file and search for all of the headlines |
||
| 45 | |||
| 46 | open INFILE,"<${ARGV[0]}"; |
||
| 47 | open INDEXFILE,">${ARGV[1]}/index.htm"; |
||
| 48 | |||
| 49 | print INDEXFILE "<title>VERTICAL Automatically Generated Documentation</title>"; |
||
| 50 | print INDEXFILE "<html>\n"; |
||
| 51 | print INDEXFILE "<h1>Index of commands</h1>\n"; |
||
| 52 | print INDEXFILE "Items marked as PROGRAM are implemented as separate preprocessors for Vertical.\n" ; |
||
| 53 | print INDEXFILE "Call these from a shell command line rather than within Vertical.\n"; |
||
| 54 | print INDEXFILE "<a name=\"top\"><table>\n"; |
||
| 55 | |||
| 56 | # loop 1 : index all of the entries |
||
| 57 | |||
| 58 | $i=0; |
||
| 59 | $tag = 0; |
||
| 60 | $patterns = 0; |
||
| 61 | |||
| 62 | #bit mask giving pattern membership |
||
| 63 | $bit = 1; |
||
| 64 | $areacnt = 0; |
||
| 65 | |||
| 66 | while ( <INFILE> ) { |
||
| 67 | # should be more escapes here. |
||
| 68 | s/</\</g; |
||
| 69 | |||
| 70 | if ($i==1 && $tag ==0 ) { |
||
| 71 | $targ = $_; |
||
| 72 | chomp $targ; |
||
| 73 | if ($targ =~ s/([a-zA-Z0-9_ ]+)(.*)/$1/ ) { |
||
| 74 | $rest = $2; |
||
| 75 | $link = $1; |
||
| 76 | $link =~ s/ $//g; |
||
| 77 | # remember the text of the link for future |
||
| 78 | $links[$pattern] = $link; |
||
| 79 | $targ =~ s/ /_/g; |
||
| 80 | $targ =~ s/_$//g; |
||
| 81 | $linktxt[$pattern] = "<tr><td><a href=\"./$targ.htm\">$link</a><td>$rest</tr>\n"; |
||
| 82 | print INDEXFILE $linktxt; |
||
| 83 | $prevpatt = $pattern; |
||
| 84 | $pattern++; |
||
| 85 | }; |
||
| 86 | $tag = 1; |
||
| 87 | $i = 0; |
||
| 88 | }; |
||
| 89 | #decode keywords |
||
| 90 | if (/\@application +([^\n\r ]+)/) { |
||
| 91 | $app_area = $1; |
||
| 92 | chomp $app_area; |
||
| 93 | $ii=0; |
||
| 94 | $app_area; |
||
| 95 | while(($ii < @areas) && ($areas[$ii] ne $app_area)) |
||
| 96 | { $ii++; } |
||
| 97 | if( $ii == @areas) |
||
| 98 | { |
||
| 99 | # print "<!-- found new $app_area = $ii -->\n"; |
||
| 100 | $areas[$ii] = $app_area; |
||
| 101 | $bitflag[$ii] = $bit; |
||
| 102 | $bit = $bit * 2; |
||
| 103 | } |
||
| 104 | else |
||
| 105 | { |
||
| 106 | # print "<!-- found existing $app_area = $ii -->\n"; |
||
| 107 | } |
||
| 108 | $linkflags[$prevpatt] |= $bitflag[$ii]; |
||
| 109 | $tag = 0; |
||
| 110 | } |
||
| 111 | if (/\@title/) { |
||
| 112 | $i=1; |
||
| 113 | $tag = 0; |
||
| 114 | } |
||
| 115 | elsif (/\@end/ ) { |
||
| 116 | $i=0; |
||
| 117 | }; |
||
| 118 | }; |
||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | print INDEXFILE "</table><br><hr><br>"; |
||
| 123 | |||
| 124 | |||
| 125 | sort @links; |
||
| 126 | |||
| 127 | |||
| 128 | close INFILE; |
||
| 129 | open INFILE,"<${ARGV[0]}"; |
||
| 130 | |||
| 131 | while ( <INFILE> ) { |
||
| 132 | |||
| 133 | # should be more escapes here. |
||
| 134 | s/&/\&/g; |
||
| 135 | s/</\</g; |
||
| 136 | |||
| 137 | if ($i==1 && $tag ==0 ) { |
||
| 138 | $targ = $_; |
||
| 139 | chomp $targ; |
||
| 140 | if ($targ =~ s/([a-zA-Z0-9_ ]+).*/$1/ ) { |
||
| 141 | #make spaces into underscores |
||
| 142 | $targ =~ s/ /_/g; |
||
| 143 | #kill trailing underscore |
||
| 144 | $targ =~ s/_$//; |
||
| 145 | if (<OUTFILE>) |
||
| 146 | { |
||
| 147 | print OUTFILE "</html>"; |
||
| 148 | } |
||
| 149 | open OUTFILE,">${ARGV[1]}/$targ.htm"; |
||
| 150 | print OUTFILE "<title>$targ</title>\n"; |
||
| 151 | print OUTFILE "<html><h2>"; |
||
| 152 | }; |
||
| 153 | $tag = 1; |
||
| 154 | }; |
||
| 155 | |||
| 156 | if (/\@title/) { |
||
| 157 | $i=1; |
||
| 158 | $tag = 0; |
||
| 159 | #print OUTFILE "<h2>\n"; |
||
| 160 | } |
||
| 161 | elsif (/\@application +([^\n\r ]+)/) { |
||
| 162 | $tag = 0; |
||
| 163 | if ($i==1) { |
||
| 164 | print OUTFILE "</h2><hr>\n"; |
||
| 165 | $i=0; |
||
| 166 | }; |
||
| 167 | if ($i==3) { |
||
| 168 | print OUTFILE "</pre>\n"; |
||
| 169 | }; |
||
| 170 | if ($i!=4) |
||
| 171 | { |
||
| 172 | $i = 4; |
||
| 173 | print OUTFILE "<ul><font size=-1>\n" |
||
| 174 | } |
||
| 175 | printf OUTFILE "<li>used with : <a href=\".\/index.htm#index_$1\">$1</a><font size=+0>\n"; |
||
| 176 | } |
||
| 177 | # create a list of links to the indexes |
||
| 178 | elsif (/\@list_index([^\n\r ]*)/) { |
||
| 179 | printf INDEXFILE ("<h2>List of Indexes</h2><ul>\n"); |
||
| 180 | $ii=0; |
||
| 181 | while($ii < @areas) |
||
| 182 | { |
||
| 183 | print INDEXFILE "<li><a href=\".\/index.htm#index_$areas[$ii]\">$areas[$ii]</a></li>\n"; |
||
| 184 | $ii++; |
||
| 185 | } |
||
| 186 | printf INDEXFILE "<font size=+0></ul><br>\n"; |
||
| 187 | } |
||
| 188 | # we create an index of links to relevant code |
||
| 189 | elsif (/\@index +([^\n\r ]+)/) { |
||
| 190 | if ($i==1) { |
||
| 191 | print INDEXFILE "</h2><hr>\n"; |
||
| 192 | $i=0; |
||
| 193 | }; |
||
| 194 | if ($i==3) { |
||
| 195 | print OUTFILE "</pre>\n"; |
||
| 196 | $i = 0; |
||
| 197 | }; |
||
| 198 | if ($i==4) |
||
| 199 | { |
||
| 200 | $i = 0; |
||
| 201 | print INDEXFILE "<font size=+0></ul><br>\n" |
||
| 202 | } |
||
| 203 | print INDEXFILE "<a name=\"index_$1\"><h3>Index $1</h3>\n<table>\n"; |
||
| 204 | # locate application area |
||
| 205 | $app_area = $1; |
||
| 206 | chomp $app_area; |
||
| 207 | $ii=0; |
||
| 208 | while(($ii < @areas) && ($areas[$ii] ne $app_area)) |
||
| 209 | { $ii++; } |
||
| 210 | # if we have found the area |
||
| 211 | if( $ii != @areas) |
||
| 212 | { |
||
| 213 | # print "<!-- found existing $app_area = $ii -->\n"; |
||
| 214 | $flag = $bitflag[$ii]; |
||
| 215 | for ($i =0; $i< @linkflags; $i++) |
||
| 216 | { |
||
| 217 | # printf("flag %d\n",$flag & $linkflags[$i]); |
||
| 218 | if ( $flag & $linkflags[$i]) |
||
| 219 | { |
||
| 220 | print INDEXFILE "$linktxt[$i]\n"; |
||
| 221 | } |
||
| 222 | |||
| 223 | } |
||
| 224 | } |
||
| 225 | printf INDEXFILE "</table>\n"; |
||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | } |
||
| 230 | elsif (/\@text/ ) { |
||
| 231 | if ($i==1) { |
||
| 232 | print OUTFILE "</h2><hr>\n"; |
||
| 233 | }; |
||
| 234 | if ($i==3) { |
||
| 235 | print OUTFILE "</pre>\n"; |
||
| 236 | }; |
||
| 237 | if ($i==4) |
||
| 238 | { |
||
| 239 | $i = 0; |
||
| 240 | print OUTFILE "<font size=+0></ul><br>\n" |
||
| 241 | } |
||
| 242 | $i=2; |
||
| 243 | } |
||
| 244 | elsif (/\@listing/ ) { |
||
| 245 | if ($i==1) { |
||
| 246 | print OUTFILE "</h1><pre>\n"; |
||
| 247 | }; |
||
| 248 | if ($i==2) { |
||
| 249 | print OUTFILE "<pre>\n"; |
||
| 250 | }; |
||
| 251 | if ($i==4) |
||
| 252 | { |
||
| 253 | $i = 0; |
||
| 254 | print OUTFILE "<font size=+0></ul><br>\n" |
||
| 255 | } |
||
| 256 | $i=3; |
||
| 257 | } |
||
| 258 | elsif (/\@end/ ) { |
||
| 259 | if ($i==1) { |
||
| 260 | print OUTFILE "</h1>\n"; |
||
| 261 | }; |
||
| 262 | |||
| 263 | if ($i==3) { |
||
| 264 | print OUTFILE "</pre>\n"; |
||
| 265 | }; |
||
| 266 | if ($i==4) |
||
| 267 | { |
||
| 268 | $i = 0; |
||
| 269 | print OUTFILE "<font size=+0></ul><br>\n" |
||
| 270 | } |
||
| 271 | print OUTFILE "<br><a href=\".\/index.htm#top\">Vertical Index</a>\n<hr>\n"; |
||
| 272 | $i=0; |
||
| 273 | } |
||
| 274 | elsif (/\@break/ ) { |
||
| 275 | if ($i==1 || $i==2 ) { |
||
| 276 | print OUTFILE "<br>\n"; |
||
| 277 | }; |
||
| 278 | if ($i==3) { |
||
| 279 | print OUTFILE "</pre><br><pre>\n"; |
||
| 280 | }; |
||
| 281 | if ($i==4) |
||
| 282 | { |
||
| 283 | $i = 0; |
||
| 284 | print OUTFILE "<font size=+0></ul><br>\n" |
||
| 285 | } |
||
| 286 | } |
||
| 287 | else { |
||
| 288 | if ($i) { |
||
| 289 | #very slow but acceptable, search from longest to shortest string |
||
| 290 | # more than one link on an input line : repeat search for all strings |
||
| 291 | $line = $_; |
||
| 292 | chomp $line; |
||
| 293 | # only put up links in $i==2 normal text |
||
| 294 | for ($j = $pattern-1 ;$i ==2 && $j>=0 ;$j--) |
||
| 295 | { |
||
| 296 | # same link more than once on same input line. |
||
| 297 | $tail = $line; |
||
| 298 | #dont match stuff already either _link_name or >link_name |
||
| 299 | # make sure that what follows is not part of a word |
||
| 300 | if ( $tail =~ m/\W$links[$j]\W/i ) |
||
| 301 | { |
||
| 302 | # got match |
||
| 303 | $targ = $links[$j]; |
||
| 304 | if(length $targ >= 2) |
||
| 305 | { |
||
| 306 | $targ =~ s/ /_/g; |
||
| 307 | $targ =~ s/_$//g; |
||
| 308 | $line =~ s/(.*\W)($links[$j])(\W.*)/$1<a href=\".\/$targ.htm\">$links[$j]<\/a>$3/i; |
||
| 309 | #recycle tail to see if any more . |
||
| 310 | $tail = $3; |
||
| 311 | |||
| 312 | } |
||
| 313 | }; |
||
| 314 | } |
||
| 315 | |||
| 316 | # print the output line |
||
| 317 | print OUTFILE $line; |
||
| 318 | }; |
||
| 319 | }; |
||
| 320 | }; |
||
| 321 | |||
| 322 | |||
| 323 | |||
| 324 | |||
| 325 | |||
| 326 | print INDEXFILE "</html>\n"; |