1 | #!/usr/local/bin/perl |
---|
2 | # |
---|
3 | # src2html.cgi -- A search script to file symbols in a src2html tree. |
---|
4 | # You need to install this in your httpd script directory AND set the |
---|
5 | # httpd web root below. |
---|
6 | # |
---|
7 | # We need the cgi-lib.pl package to be available to Perl |
---|
8 | require 'cgi-lib.pl'; |
---|
9 | # |
---|
10 | ## We MUST know the root of the httpd server, so we can find the ctags |
---|
11 | ## |
---|
12 | # |
---|
13 | $Http_root= "/usr/pub/pub/www"; |
---|
14 | |
---|
15 | # Parse input -> %in |
---|
16 | &ReadParse; # and print first 2 lines |
---|
17 | |
---|
18 | @keys= keys(%in); # We only expect one name/val pair |
---|
19 | if ($#keys != 0) { # Otherwise, return an error document |
---|
20 | print <<"query_error"; |
---|
21 | Content-type: text/html |
---|
22 | |
---|
23 | <header><title>Query Error</title></header><body> |
---|
24 | <h1>Query Error</h1> |
---|
25 | The document you used to query this source tree has an error in it. |
---|
26 | You should email the maintainer of the source tree with a copy of the |
---|
27 | document with the query form in it. |
---|
28 | </body> |
---|
29 | query_error |
---|
30 | exit(1); |
---|
31 | } |
---|
32 | # Given the name, determine which tree |
---|
33 | $Htmltree= "$Http_root/$keys[0]"; |
---|
34 | $Htmltree=~ s/\/[^\/]*$//; # Location of the Html tree root |
---|
35 | $Srctree= "/$keys[0]"; # URL of the actual source |
---|
36 | $Ctags= "$Htmltree/ctags"; # Location of the ctags files |
---|
37 | |
---|
38 | @symbol= split(/\s+/, $in{$keys[0]}); # Get one symbol to search for |
---|
39 | |
---|
40 | if ($#symbol != 0) { # Hmm, <> 1 symbol, return an error |
---|
41 | print <<"symbol_error"; |
---|
42 | Content-type: text/html |
---|
43 | |
---|
44 | <header><title>$Htmltree Search Error</title></header><body> |
---|
45 | <h1>$Htmltree Search Error</h1> |
---|
46 | Hmm, you either sent in no symbols to me to search, or a number of |
---|
47 | symbols to find, separated by whitespace.<p> |
---|
48 | The search function can only handle regexp expressions with no |
---|
49 | whitespace. Try resubmitting your query. |
---|
50 | </body> |
---|
51 | symbol_error |
---|
52 | exit(1); |
---|
53 | } |
---|
54 | # Let's go to work, egrep the ctags |
---|
55 | |
---|
56 | # Naftali Schwartz (nschwart@SLINKY.CS.NYU.EDU) reports that using the ^ |
---|
57 | # on the following line stops the script from working under SunOS 4.1.3. |
---|
58 | # Sounds like ctags-new doesn't start the symbol in the 1st column. |
---|
59 | open(IN, "cat $Ctags/* | egrep ^$symbol[0] |") || die "$0: egrep failed\n"; |
---|
60 | $cnt=0; |
---|
61 | while(<IN>) { |
---|
62 | ($sym, $line, $file, $com)= split(/\s+/); |
---|
63 | $Sym[$cnt]=$sym; $Line[$cnt]= $line; $File[$cnt]= $file; $cnt++; |
---|
64 | } |
---|
65 | close(IN); |
---|
66 | # How many did we get? Zero, no symbol |
---|
67 | if ($cnt == 0) { |
---|
68 | print <<"symbol_missing"; |
---|
69 | Content-type: text/html |
---|
70 | |
---|
71 | <header><title>$Htmltree Search Error</title></header><body> |
---|
72 | <h1>$Htmltree Search Error</h1> |
---|
73 | The symbol $symbol[0] does not appear in the source tree. |
---|
74 | </body> |
---|
75 | symbol_missing |
---|
76 | exit(1); |
---|
77 | } |
---|
78 | |
---|
79 | if ($cnt == 1) { # Exactly one, return ptr to that doc |
---|
80 | print "Location: $Srctree/$File[0]"; |
---|
81 | |
---|
82 | # I used to use the commented out line under NCSA httpd because the other |
---|
83 | # line didn't work. You may need to try things out on your server. |
---|
84 | print ".html\#$Sym[0]\n\n"; |
---|
85 | # print ".html\n\n"; |
---|
86 | exit(0); |
---|
87 | } |
---|
88 | # Else return a list of choices |
---|
89 | print <<"many_found"; |
---|
90 | Content-type: text/html |
---|
91 | |
---|
92 | <header><title>$Htmltree Search</title></header><body> |
---|
93 | <h1>$Htmltree Search</h1><ul> |
---|
94 | many_found |
---|
95 | for ($i = 0; $i < $cnt; $i++) { |
---|
96 | print "<li><a href= \"$Srctree/$File[$i]"; |
---|
97 | print ".html#$Sym[$i]\">$Sym[$i]</a> $File[$i]:$Line[$i]\n"; |
---|
98 | } |
---|
99 | print "</ul></body>\n"; |
---|
100 | exit(0); |
---|