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