Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | #!/usr/local/bin/perl |
2 | # $Id: docyacc.pl,v 1.1.1.1 2003/11/04 23:34:58 mjames Exp $ |
||
3 | # $Log: docyacc.pl,v $ |
||
4 | # Revision 1.1.1.1 2003/11/04 23:34:58 mjames |
||
5 | # Imported into local repositrory |
||
6 | # |
||
7 | # Revision 1.4 2002/09/30 13:28:02 MJAMES |
||
8 | # Tidy up |
||
9 | # |
||
10 | # Revision 1.1.1.1 2002/09/09 15:06:16 mjames |
||
11 | # no message |
||
12 | # |
||
13 | # Revision 1.3 2001/10/31 22:20:03 mjames |
||
14 | # Tidying up problematical comments caused by CVS |
||
15 | # 'intelligent' comment guessing |
||
16 | # |
||
17 | # Revision 1.2 2001/10/07 20:51:31 mjames |
||
18 | # Modified Perl command to generate better formed HTML |
||
19 | # |
||
20 | # Revision 1.1 2001/10/02 20:47:41 mjames |
||
21 | # Yacc documentation generator : produces HTML file. |
||
22 | # |
||
23 | # |
||
24 | # State variable $i = |
||
25 | #1 = title |
||
26 | #2 = text |
||
27 | #3 = listing |
||
28 | #0 = nothing |
||
29 | |||
30 | # phase 1 : open file and search for all of the headlines |
||
31 | |||
32 | open INFILE,"<${ARGV[0]}"; |
||
33 | |||
34 | |||
35 | print "<html>\n"; |
||
36 | print "<title>Index of ${ARGV[0]}</title>\n"; |
||
37 | print "<h1>Index of ${ARGV[0]}</h1>\n"; |
||
38 | print "Key objects are here\n" ; |
||
39 | print "<a name=\"top\"><table>\n"; |
||
40 | |||
41 | # loop 1 : index all of the entries |
||
42 | |||
43 | $i=0; |
||
44 | $tag = 0; |
||
45 | $patterns = 0; |
||
46 | while ( <INFILE> ) { |
||
47 | # should be more escapes here. |
||
48 | s/</\</g; |
||
49 | |||
50 | $targ = $_; |
||
51 | chomp $targ; |
||
52 | if ($targ =~ s/^([a-zA-Z0-9_]+)\s*\:(.*)/$1/ ) |
||
53 | { |
||
54 | $rest = $2; |
||
55 | $link = $1; |
||
56 | $link =~ s/ $//; |
||
57 | # remember the text of the link for future |
||
58 | $links[$pattern++] = $link; |
||
59 | $targ =~ s/ /_/g; |
||
60 | $targ =~ s/_$//g; |
||
61 | print "<tr><td><a href=\"\#\_$targ\_\">$link</a><td>$rest</tr>\n"; |
||
62 | }; |
||
63 | }; |
||
64 | |||
65 | print "</table><br><hr><br>"; |
||
66 | |||
67 | |||
68 | sort @links; |
||
69 | |||
70 | |||
71 | close INFILE; |
||
72 | open INFILE,"<${ARGV[0]}"; |
||
73 | |||
74 | print "<hr><pre>"; |
||
75 | |||
76 | while ( <INFILE> ) { |
||
77 | |||
78 | # should be more escapes here. |
||
79 | s/&/\&ersand;/g; |
||
80 | s/</\</g; |
||
81 | |||
82 | $line = $_; |
||
83 | chomp $line; |
||
84 | $targ = $line; |
||
85 | #detect anchor target |
||
86 | if ($targ =~ s/^([a-zA-Z0-9_]+)\s*\:(.*)/$1/ ) |
||
87 | { |
||
88 | $patt = $1; |
||
89 | #make spaces into underscores |
||
90 | $targ =~ s/ /_/g; |
||
91 | #kill trailing underscore |
||
92 | $targ =~ s/_$//; |
||
93 | |||
94 | $line =~ s/$patt/<a href=\"\#top\">Top of Document<\/a><hr><a name=\"\_$targ\_\">$patt/; |
||
95 | }; |
||
96 | |||
97 | #very slow but acceptable, search from longest to shortest string |
||
98 | # more than one link on an input line : repeat search for all strings |
||
99 | for ($j=$pattern-1 ;$j>= 0;$j--) |
||
100 | { |
||
101 | $tail = $line; |
||
102 | #miss out any already anchored text and get maximal match |
||
103 | # more than one match for the same link on the same line ? |
||
104 | |||
105 | if ( $tail =~ m/[^>_]$links[$j]\W+/ ) |
||
106 | { |
||
107 | # got match |
||
108 | $targ = $links[$j]; |
||
109 | if(length $targ >= 2) |
||
110 | { |
||
111 | $targ =~ s/ /_/g; |
||
112 | $targ =~ s/_$//g; |
||
113 | $line =~ s/(.*[^>_])($links[$j])(\W+.*)/$1<a href=\"\#\_$targ\_\">$links[$j]<\/a>$3/; |
||
114 | $tail = $3; |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | # print the output line |
||
120 | print "<br>$line\n"; |
||
121 | }; |
||
122 | |||
123 | |||
124 | |||
125 | print "</pre>\n"; |
||
126 | |||
127 | print "</html>\n"; |