Annotation of cvsweb/cvsweb.cgi, Revision 1.11
1.1 jfieber 1: #!/usr/bin/perl -s
2: #
3: # cvsweb - a CGI interface to the CVS tree.
4: #
5: # Written by Bill Fenner <fenner@parc.xerox.com> on his own time.
6: # Insert BSD copyright here.
7: #
8: #HTTP_USER_AGENT: Mozilla/1.1N (X11; I; SunOS 4.1.3_U1 sun4m) via proxy gateway CERN-HTTPD/3.0 libwww/2.17
9: #SERVER_NAME: www.freebsd.org
10: #QUERY_STRING: baz
11: #SCRIPT_FILENAME: /usr/local/www/cgi-bin/env.pl
12: #SERVER_PORT: 80
13: #HTTP_ACCEPT: */*, image/gif, image/x-xbitmap, image/jpeg
14: #SERVER_PROTOCOL: HTTP/1.0
15: #HTTP_COOKIE: s=beta26429821397802167
16: #PATH_INFO: /foo/bar
17: #REMOTE_ADDR: 13.1.64.94
18: #DOCUMENT_ROOT: /usr/local/www/data/
19: #PATH: /sbin:/bin:/usr/sbin:/usr/bin
20: #PATH_TRANSLATED: /usr/local/www/data//foo/bar
21: #GATEWAY_INTERFACE: CGI/1.1
22: #REQUEST_METHOD: GET
23: #SCRIPT_NAME: /cgi-bin/env.pl
24: #SERVER_SOFTWARE: Apache/1.0.0
25: #REMOTE_HOST: beta.xerox.com
26: #SERVER_ADMIN: webmaster@freebsd.org
27: #
28: require 'timelocal.pl';
29: require 'ctime.pl';
30:
1.2 jfieber 31: $hsty_base = "";
32: require 'cgi-style.pl';
1.11 ! wosch 33: #&get_the_source;
1.2 jfieber 34:
1.10 wosch 35: %CVSROOT = (
36: 'freebsd', '/home/ncvs',
37: 'openbsd', '/home/OpenBSD/cvs',
38: 'learn', '/c/learncvs',
39: );
40:
41: $cvstreedefault = 'freebsd';
42: $cvstree = $cvstreedefault;
43: $cvsroot = $CVSROOT{"$cvstree"} || "/home/ncvs";
44:
45:
1.1 jfieber 46: $intro = "
47: This is a WWW interface to the FreeBSD CVS tree.
48: You can browse the file hierarchy by picking directories
49: (which have slashes after them, e.g. <b>src/</b>).
50: If you pick a file, you will see the revision history
51: for that file.
52: Selecting a revision number will download that revision of
53: the file. There is a link at each revision to display
54: diffs between that revision and the previous one, and
55: a form at the bottom of the page that allows you to
56: display diffs between arbitrary revisions.
57: <p>
1.7 fenner 58: If you would like to use this CGI script on your own web server and
59: CVS tree, see <A HREF=\"http://www.freebsd.org/~fenner/cvsweb/\">
60: the CVSWeb distribution site</A>.
61: <p>
1.1 jfieber 62: Please send any suggestions, comments, etc. to
1.10 wosch 63: <A HREF=\"mailto:fenner\@freebsd.org\">Bill Fenner <fenner\@freebsd.org></A>
1.1 jfieber 64: ";
65: $shortinstr = "
66: Click on a directory to enter that directory. Click on a file to display
67: its revision history and to get a
68: chance to display diffs between revisions.
69: ";
70:
71: $verbose = $v;
72: ($where = $ENV{'PATH_INFO'}) =~ s|^/||;
73: $where =~ s|/$||;
74: ($scriptname = $ENV{'SCRIPT_NAME'}) =~ s|^/?|/|;
75: $scriptname =~ s|/$||;
76: $scriptwhere = $scriptname . '/' . $where;
77: $scriptwhere =~ s|/$||;
78:
1.7 fenner 79:
1.9 fenner 80: if ($query = $ENV{'QUERY_STRING'}) {
81: foreach (split(/&/, $query)) {
1.7 fenner 82: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
83: if (/(\S+)=(.*)/) {
84: $input{$1} = $2;
85: } else {
86: $input{$_}++;
87: }
88: }
1.9 fenner 89: $query = "?" . $query;
1.7 fenner 90: }
1.10 wosch 91:
92:
1.11 ! wosch 93: $config = '/usr/local/etc/cvsweb';
! 94: do "$config" if -f $config;
1.10 wosch 95:
96: if ($input{'cvsroot'}) {
97: if ($CVSROOT{$input{'cvsroot'}}) {
98: $cvstree = $input{'cvsroot'};
99: $cvsroot = $CVSROOT{"$cvstree"};
100: }
101: }
1.11 ! wosch 102: do "$config-$cvstree" if -f "$config-$cvstree";
1.10 wosch 103:
104: $fullname = $cvsroot . '/' . $where;
105: if (!-d $cvsroot) {
106: &fatal("500 Internal Error",'$CVSROOT not found!');
107: }
108:
109:
1.1 jfieber 110: if (-d $fullname) {
111: opendir(DIR, $fullname) || &fatal("404 Not Found","$where: $!");
112: @dir = readdir(DIR);
113: closedir(DIR);
114: if ($where eq '') {
1.2 jfieber 115: print &html_header("FreeBSD CVS Repository");
1.1 jfieber 116: print $intro;
117: } else {
1.2 jfieber 118: print &html_header("/$where");
1.1 jfieber 119: print $shortinstr;
120: }
121: print "<p>Current directory: <b>/$where</b>\n";
1.2 jfieber 122: print "<P><HR NOSHADE>\n";
1.1 jfieber 123: # Using <MENU> in this manner violates the HTML2.0 spec but
124: # provides the results that I want in most browsers. Another
125: # case of layout spooging up HTML.
126: print "<MENU>\n";
1.9 fenner 127: lookingforattic:
128: for ($i = 0; $i <= $#dir; $i++) {
129: if ($dir[$i] eq "Attic") {
130: last lookingforattic;
131: }
132: }
133: if (!$input{"showattic"} && ($i <= $#dir) &&
134: opendir(DIR, $fullname . "/Attic")) {
135: splice(@dir, $i, 1,
136: grep((s|^|Attic/|,!m|/\.|), readdir(DIR)));
137: closedir(DIR);
138: }
139: # Sort without the Attic/ pathname.
140: foreach (sort {($c=$a)=~s|.*/||;($d=$b)=~s|.*/||;($c cmp $d)} @dir) {
1.1 jfieber 141: if ($_ eq '.') {
142: next;
143: }
1.9 fenner 144: if (s|^Attic/||) {
145: $attic = " (in the Attic)";
146: } else {
147: $attic = "";
148: }
1.1 jfieber 149: if ($_ eq '..') {
150: next if ($where eq '');
151: ($updir = $scriptwhere) =~ s|[^/]+$||;
152: print "<IMG SRC=\"/icons/back.gif\"> ",
1.9 fenner 153: &link("Previous Directory",$updir . $query), "<BR>";
1.7 fenner 154: # print "<IMG SRC=???> ",
155: # &link("Directory-wide diffs", $scriptwhere . '/*'), "<BR>";
1.1 jfieber 156: } elsif (-d $fullname . "/" . $_) {
157: print "<IMG SRC=\"/icons/dir.gif\"> ",
1.9 fenner 158: &link($_ . "/", $scriptwhere . '/' . $_ . '/' . $query), $attic, "<BR>";
1.1 jfieber 159: } elsif (s/,v$//) {
1.7 fenner 160: # TODO: add date/time? How about sorting?
1.1 jfieber 161: print "<IMG SRC=\"/icons/text.gif\"> ",
1.9 fenner 162: &link($_, $scriptwhere . '/' .
163: ($attic ? "Attic/" : "") . $_ . $query),
164: $attic, "<BR>";
1.1 jfieber 165: }
166: }
167: print "</MENU>\n";
1.9 fenner 168: if ($input{"only_on_branch"}) {
169: print "<HR><FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
170: print "Currently showing only branch $input{'only_on_branch'}.\n";
171: $input{"only_on_branch"}="";
172: foreach $k (keys %input) {
173: print "<INPUT TYPE=hidden NAME=$k VALUE=$input{$k}>\n" if $input{$k};
174: }
175: print "<INPUT TYPE=SUBMIT VALUE=\"Show all branches\">\n";
176: print "</FORM>\n";
177: }
178: $formwhere = $scriptwhere;
179: $formwhere =~ s|Attic/?$|| if ($input{"showattic"});
180: print "<HR><FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
181: $input{"showattic"}=!$input{"showattic"};
182: foreach $k (keys %input) {
183: print "<INPUT TYPE=hidden NAME=$k VALUE=$input{$k}>\n" if $input{$k};
184: }
185: print "<INPUT TYPE=SUBMIT VALUE=\"";
186: print ($input{"showattic"} ? "Show" : "Hide");
187: print " attic directories\">\n";
188: print "</FORM>\n";
1.2 jfieber 189: print &html_footer;
1.1 jfieber 190: print "</BODY></HTML>\n";
191: } elsif (-f $fullname . ',v') {
1.7 fenner 192: if ($input{'rev'} =~ /^[\d\.]+$/) {
193: &checkout($fullname, $input{'rev'});
194: exit;
195: }
196: if ($input{'r1'} && $input{'r2'}) {
197: &dodiff($fullname, $input{'r1'}, $input{'tr1'},
198: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.1 jfieber 199: exit;
200: }
201: open(RCS, "rlog '$fullname'|") || &fatal("500 Internal Error",
202: "Failed to spawn rlog");
203: while (<RCS>) {
204: print if ($verbose);
1.8 fenner 205: if (/^branch:\s+([\d\.]+)/) {
206: $curbranch = $1;
207: }
1.1 jfieber 208: if ($symnames) {
209: if (/^\s+([^:]+):\s+([\d\.]+)/) {
210: $symrev{$1} = $2;
211: if ($revsym{$2}) {
212: $revsym{$2} .= ", ";
213: }
214: $revsym{$2} .= $1;
215: } else {
216: $symnames = 0;
217: }
218: } elsif (/^symbolic names/) {
219: $symnames = 1;
220: } elsif (/^-----/) {
221: last;
222: }
223: }
1.7 fenner 224:
225: if ($onlyonbranch = $input{'only_on_branch'}) {
226: ($onlyonbranch = $symrev{$onlyonbranch}) =~ s/\.0\././;
227: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
228: }
229:
1.1 jfieber 230: # each log entry is of the form:
231: # ----------------------------
232: # revision 3.7.1.1
233: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
234: # log info
235: # ----------------------------
236: logentry:
237: while (!/^=========/) {
238: $_ = <RCS>;
239: print "R:", $_ if ($verbose);
240: if (/^revision ([\d\.]+)/) {
241: $rev = $1;
242: } elsif (/^========/ || /^----------------------------$/) {
243: next logentry;
244: } else {
245: &fatal("500 Internal Error","Error parsing RCS output: $_");
246: }
247: $_ = <RCS>;
248: print "D:", $_ if ($verbose);
1.9 fenner 249: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);|) {
1.1 jfieber 250: $yr = $1;
251: # damn 2-digit year routines
252: if ($yr > 100) {
253: $yr -= 1900;
254: }
255: $date{$rev} = &timelocal($6,$5,$4,$3,$2 - 1,$yr);
256: $author{$rev} = $7;
1.9 fenner 257: $state{$rev} = $8;
1.1 jfieber 258: } else {
259: &fatal("500 Internal Error", "Error parsing RCS output: $_");
260: }
261: line:
262: while (<RCS>) {
263: print "L:", $_ if ($verbose);
264: next line if (/^branches:\s/);
265: last line if (/^----------------------------$/ || /^=========/);
266: $log{$rev} .= $_;
267: }
268: print "E:", $_ if ($verbose);
269: }
270: close(RCS);
271: print "Done reading RCS file\n" if ($verbose);
272: #
273: # Sort the revisions into commit-date order.
274: @revorder = sort {$date{$b} <=> $date{$a}} keys %date;
275: print "Done sorting revisions\n" if ($verbose);
276: #
277: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 278: # branch, unless there is a branch tag in the RCS file in which case it's the
279: # highest revision on that branch. Find it by looking through @revorder; it
280: # is the first commit listed on the appropriate branch.
281: $headrev = $curbranch || "1";
1.1 jfieber 282: revision:
283: for ($i = 0; $i <= $#revorder; $i++) {
1.8 fenner 284: if ($revorder[$i] =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1.1 jfieber 285: if ($revsym{$revorder[$i]}) {
286: $revsym{$revorder[$i]} .= ", ";
287: }
288: $revsym{$revorder[$i]} .= "HEAD";
289: $symrev{"HEAD"} = $revorder[$i];
290: last revision;
291: }
292: }
293: print "Done finding HEAD\n" if ($verbose);
294: #
295: # Now that we know all of the revision numbers, we can associate
296: # absolute revision numbers with all of the symbolic names, and
297: # pass them to the form so that the same association doesn't have
298: # to be built then.
299: #
300: # should make this a case-insensitive sort
301: foreach (sort keys %symrev) {
302: $rev = $symrev{$_};
303: if ($rev =~ /^(\d+(\.\d+)+)\.0\.(\d+)$/) {
1.7 fenner 304: push(@branchnames, $_);
1.1 jfieber 305: #
306: # A revision number of A.B.0.D really translates into
307: # "the highest current revision on branch A.B.D".
308: #
309: # If there is no branch A.B.D, then it translates into
310: # the head A.B .
311: #
312: $head = $1;
313: $branch = $3;
314: $regex = $head . "." . $branch;
315: $regex =~ s/\./\./g;
316: # <
317: # \____/
318: $rev = $head;
319:
320: revision:
321: foreach $r (@revorder) {
322: if ($r =~ /^${regex}/) {
323: $rev = $head . "." . $branch;
324: last revision;
325: }
326: }
327: $revsym{$rev} .= ", " if ($revsym{$rev});
328: $revsym{$rev} .= $_;
1.8 fenner 329: if ($rev ne $head) {
330: $branchpoint{$head} .= ", " if ($branchpoint{$head});
331: $branchpoint{$head} .= $_;
332: }
1.1 jfieber 333: }
334: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
335: }
336: print "Done associating revisions with branches\n" if ($verbose);
1.2 jfieber 337: print &html_header("CVS log for $where");
1.9 fenner 338: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
339: print "Up to ", &link($upwhere,$scriptname . "/" . $upwhere . $query);
1.1 jfieber 340: print "<BR>\n";
341: print "<A HREF=\"#diff\">Request diff between arbitrary revisions</A>\n";
1.2 jfieber 342: print "<HR NOSHADE>\n";
1.8 fenner 343: if ($curbranch) {
344: print "Default branch is ";
345: print ($revsym{$curbranch} || $curbranch);
346: } else {
347: print "No default branch";
348: }
349: print "<BR><HR NOSHADE>\n";
1.1 jfieber 350: # The other possible U.I. I can see is to have each revision be hot
351: # and have the first one you click do ?r1=foo
352: # and since there's no r2 it keeps going & the next one you click
353: # adds ?r2=foo and performs the query.
354: # I suppose there's no reason we can't try both and see which one
355: # people prefer...
356:
357: for ($i = 0; $i <= $#revorder; $i++) {
358: $_ = $revorder[$i];
1.7 fenner 359: ($br = $_) =~ s/\.\d+$//;
360: next if ($onlyonbranch && $br ne $onlyonbranch &&
361: $_ ne $onlybranchpoint);
1.4 fenner 362: print "<a NAME=\"rev$_\"></a>";
363: foreach $sym (split(", ", $revsym{$_})) {
364: print "<a NAME=\"$sym\"></a>";
365: }
366: if ($revsym{$br} && !$nameprinted{$br}) {
367: foreach $sym (split(", ", $revsym{$br})) {
368: print "<a NAME=\"$sym\"></a>";
369: }
370: $nameprinted{$br}++;
371: }
372: print "\n";
1.10 wosch 373: print "<A HREF=\"$scriptwhere?rev=$_" .
374: &cvsroot . qq{"><b>$_</b></A>};
1.1 jfieber 375: if (/^1\.1\.1\.\d+$/) {
376: print " <i>(vendor branch)</i>";
377: }
378: print " <i>" . &ctime($date{$_}) . "</i> by ";
379: print "<i>" . $author{$_} . "</i>\n";
380: if ($revsym{$_}) {
381: print "<BR>CVS Tags: <b>$revsym{$_}</b>";
382: }
1.4 fenner 383: if ($revsym{$br}) {
1.1 jfieber 384: if ($revsym{$_}) {
385: print "; ";
386: } else {
387: print "<BR>";
388: }
1.8 fenner 389: print "Branch: <b>$revsym{$br}</b>\n";
390: }
391: if ($branchpoint{$_}) {
392: if ($revsym{$br} || $revsym{$_}) {
393: print "; ";
394: } else {
395: print "<BR>";
396: }
397: print "Branch point for: <b>$branchpoint{$_}</b>\n";
1.1 jfieber 398: }
399: # Find the previous revision on this branch.
400: @prevrev = split(/\./, $_);
401: if (--$prevrev[$#prevrev] == 0) {
402: # If it was X.Y.Z.1, just make it X.Y
403: if ($#prevrev > 1) {
404: pop(@prevrev);
405: pop(@prevrev);
406: } else {
407: # It was rev 1.1 (XXX does CVS use revisions
408: # greater than 1.x?)
409: if ($prevrev[0] != 1) {
410: print "<i>* I can't figure out the previous revision! *</i>\n";
411: }
412: }
413: }
414: if ($prevrev[$#prevrev] != 0) {
415: $prev = join(".", @prevrev);
1.7 fenner 416: print "<BR><A HREF=\"${scriptwhere}.diff?r1=$prev";
1.10 wosch 417: print "&r2=$_" . &cvsroot . qq{">Diffs to $prev</A>\n};
1.1 jfieber 418: #
419: # Plus, if it's on a branch, and it's not a vendor branch,
420: # offer to diff with the immediately-preceding commit if it
421: # is not the previous revision as calculated above
422: # and if it is on the HEAD (or at least on a higher branch)
423: # (e.g. change gets committed and then brought
424: # over to -stable)
425: if (!/^1\.1\.1\.\d+$/ && ($i != $#revorder) &&
426: ($prev ne $revorder[$i+1])) {
427: @tmp1 = split(/\./, $revorder[$i+1]);
428: @tmp2 = split(/\./, $_);
429: if ($#tmp1 < $#tmp2) {
1.7 fenner 430: print "; <A HREF=\"${scriptwhere}.diff?r1=$revorder[$i+1]";
1.10 wosch 431: print "&r2=$_" . &cvsroot .
432: qq{">Diffs to $revorder[$i+1]</A>\n};
1.1 jfieber 433: }
434: }
435: }
1.9 fenner 436: if ($state{$_} eq "dead") {
437: print "<BR><B><I>FILE REMOVED</I></B>\n";
438: }
1.1 jfieber 439: print "<PRE>\n";
1.7 fenner 440: print &htmlify($log{$_}, 1);
1.2 jfieber 441: print "</PRE><HR NOSHADE>\n";
1.1 jfieber 442: }
443: print "<A NAME=diff>\n";
444: print "This form allows you to request diff's between any two\n";
445: print "revisions of a file. You may select a symbolic revision\n";
446: print "name using the selection box or you may type in a numeric\n";
447: print "name using the type-in text box.\n";
448: print "</A><P>\n";
1.7 fenner 449: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\">\n";
1.10 wosch 450: print qq{<input type=hidden name=cvsroot value=$cvstree>\n}
451: if &cvsroot;
1.1 jfieber 452: print "Diffs between \n";
453: print "<SELECT NAME=\"r1\">\n";
454: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
455: print $sel;
456: print "</SELECT>\n";
457: print "<INPUT TYPE=\"TEXT\" NAME=\"tr1\" VALUE=\"$revorder[$#revorder]\">\n";
458: print " and \n";
459: print "<SELECT NAME=\"r2\">\n";
460: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
461: print $sel;
462: print "</SELECT>\n";
463: print "<INPUT TYPE=\"TEXT\" NAME=\"tr2\" VALUE=\"$revorder[0]\">\n";
464: print "<BR><INPUT TYPE=RADIO NAME=\"f\" VALUE=u CHECKED>Unidiff<br>\n";
465: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=c>Context diff<br>\n";
1.7 fenner 466: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=s>Side-by-Side<br>\n";
1.1 jfieber 467: print "<INPUT TYPE=SUBMIT VALUE=\"Get Diffs\">\n";
468: print "</FORM>\n";
1.7 fenner 469: print "<HR noshade>\n";
470: print "<A name=branch>\n";
471: print "You may select to see revision information from only\n";
472: print "a single branch.\n";
473: print "</A><P>\n";
474: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.10 wosch 475: print qq{<input type=hidden name=cvsroot value=$cvstree>\n}
476: if &cvsroot;
1.7 fenner 477: print "Branch: \n";
478: print "<SELECT NAME=\"only_on_branch\">\n";
1.9 fenner 479: print "<OPTION VALUE=\"\"";
480: print " SELECTED" if ($input{"only_on_branch"} eq "");
481: print ">Show all branches\n";
1.7 fenner 482: foreach (sort @branchnames) {
1.9 fenner 483: print "<OPTION";
484: print " SELECTED" if ($input{"only_on_branch"} eq $_);
485: print ">${_}\n";
1.7 fenner 486: }
487: print "</SELECT>\n";
488: print "<INPUT TYPE=SUBMIT VALUE=\"View Branch\">\n";
489: print "</FORM>\n";
1.2 jfieber 490: print &html_footer;
1.1 jfieber 491: print "</BODY></HTML>\n";
1.7 fenner 492: } elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
493: $input{'r1'} && $input{'r2'}) {
1.9 fenner 494: # Allow diffs using the ".diff" extension
495: # so that browsers that default to the URL
496: # for a save filename don't save diff's as
497: # e.g. foo.c
1.7 fenner 498: &dodiff($fullname, $input{'r1'}, $input{'tr1'},
499: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.9 fenner 500: exit;
501: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
502: -f $newname . ",v") {
503: # The file has been removed and is in the Attic.
504: # Send a redirect pointing to the file in the Attic.
505: ($newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
506: &redirect($newplace);
1.7 fenner 507: exit;
508: } elsif (0 && (@files = &safeglob($fullname . ",v"))) {
509: print "Content-type: text/plain\n\n";
510: print "You matched the following files:\n";
511: print join("\n", @files);
512: # Find the tags from each file
513: # Display a form offering diffs between said tags
1.1 jfieber 514: } else {
1.5 fenner 515: # Assume it's a module name with a potential path following it.
1.7 fenner 516: ($module = $where) =~ s|/.*||;
1.5 fenner 517: $xtra = $&;
1.4 fenner 518: # Is there an indexed version of modules?
519: if (open(MODULES, "$cvsroot/CVSROOT/modules")) {
520: while (<MODULES>) {
1.8 fenner 521: if (/^(\S+)\s+(\S+)/o && $module eq $1
522: && -d "${cvsroot}/$2" && $module ne $2) {
523: &redirect($scriptname . '/' . $2 . $xtra);
1.4 fenner 524: }
525: }
526: }
1.7 fenner 527: &fatal("404 Not Found","$where: no such file or directory");
1.1 jfieber 528: }
529:
530: sub htmlify {
1.7 fenner 531: local($string, $pr) = @_;
1.1 jfieber 532:
1.2 jfieber 533: $string =~ s/&/&/g;
1.1 jfieber 534: $string =~ s/</</g;
535: $string =~ s/>/>/g;
536:
1.7 fenner 537: if ($pr) {
538: $string =~ s|\bpr(\W+[a-z]+/\W*)(\d+)|<A HREF=/cgi/query-pr.cgi?pr=$2>$&</A>|ig;
539: }
540:
1.1 jfieber 541: $string;
542: }
543:
544: sub link {
545: local($name, $where) = @_;
546:
547: "<A HREF=\"$where\">$name</A>\n";
548: }
549:
550: sub revcmp {
551: local($rev1, $rev2) = @_;
552: local(@r1) = split(/\./, $rev1);
553: local(@r2) = split(/\./, $rev2);
554: local($a,$b);
555:
1.5 fenner 556: while (($a = shift(@r1)) && ($b = shift(@r2))) {
1.1 jfieber 557: if ($a != $b) {
558: return $a <=> $b;
559: }
560: }
561: if (@r1) { return 1; }
562: if (@r2) { return -1; }
563: return 0;
564: }
565:
566: sub fatal {
567: local($errcode, $errmsg) = @_;
568: print "Status: $errcode\n";
1.7 fenner 569: print &html_header("Error");
570: # print "Content-type: text/html\n";
571: # print "\n";
572: # print "<HTML><HEAD><TITLE>Error</TITLE></HEAD>\n";
573: # print "<BODY>Error: $errmsg</BODY></HTML>\n";
574: print "Error: $errmsg\n";
575: print &html_footer;
1.4 fenner 576: exit(1);
577: }
578:
579: sub redirect {
580: local($url) = @_;
581: print "Status: 301 Moved\n";
582: print "Location: $url\n";
1.7 fenner 583: print &html_header("Moved");
584: # print "Content-type: text/html\n";
585: # print "\n";
586: # print "<HTML><HEAD><TITLE>Moved</TITLE></HEAD>\n";
587: # print "<BODY>This document is located <A HREF=$url>here</A>.</BODY></HTML>\n";
588: print "This document is located <A HREF=$url>here</A>.\n";
589: print &html_footer;
1.1 jfieber 590: exit(1);
1.7 fenner 591: }
592:
593: sub safeglob {
594: local($filename) = @_;
595: local($dirname);
596: local(@results);
597:
598: ($dirname = $filename) =~ s|/[^/]+$||;
599: $filename =~ s|.*/||;
600:
601: if (opendir(DIR, $dirname)) {
602: $glob = $filename;
603: # transform filename from glob to regex. Deal with:
604: # [, {, ?, * as glob chars
605: # make sure to escape all other regex chars
1.8 fenner 606: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1.7 fenner 607: $glob =~ s/\*/.*/g;
608: $glob =~ s/\?/./g;
1.8 fenner 609: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1.7 fenner 610: foreach (readdir(DIR)) {
611: if (/^${glob}$/) {
612: push(@results, $dirname . "/" .$_);
613: }
614: }
615: }
616:
617: @results;
618: }
1.8 fenner 619:
1.7 fenner 620: sub checkout {
621: local($fullname, $rev) = @_;
622:
623: open(RCS, "co -p$rev '$fullname' 2>&1 |") ||
624: &fail("500 Internal Error", "Couldn't co: $!");
625: # /home/ncvs/src/sys/netinet/igmp.c,v --> standard output
1.8 fenner 626: # or
627: # /home/ncvs/src/sys/netinet/igmp.c,v --> stdout
1.7 fenner 628: # revision 1.1.1.2
629: # /*
630: $_ = <RCS>;
1.8 fenner 631: if (/^(\S+),v\s+-->\s+st(andar)?d ?out(put)?\s*$/o && $1 eq $fullname) {
1.7 fenner 632: # As expected
633: } else {
634: &fatal("500 Internal Error",
635: "Unexpected output from co: $_");
636: }
637: $_ = <RCS>;
638: if (/^revision\s+$rev\s*$/) {
639: # As expected
640: } else {
641: &fatal("500 Internal Error",
642: "Unexpected output from co: $_");
643: }
644: $| = 1;
645: print "Content-type: text/plain\n\n";
646: print <RCS>;
647: close(RCS);
648: }
649:
650: sub dodiff {
651: local($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
652:
653: if ($r1 =~ /([^:]+)(:(.+))?/) {
654: $rev1 = $1;
655: $sym1 = $3;
656: }
657: if ($rev1 eq 'text') {
658: $rev1 = $tr1;
659: }
660: if ($r2 =~ /([^:]+)(:(.+))?/) {
661: $rev2 = $1;
662: $sym2 = $3;
663: }
664: if ($rev2 eq 'text') {
665: $rev2 = $tr2;
666: }
667: if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) {
668: &fatal("404 Not Found",
669: "Malformed query \"$ENV{'QUERY_STRING'}\"");
670: }
671: #
672: # rev1 and rev2 are now both numeric revisions.
673: # Thus we do a DWIM here and swap them if rev1 is after rev2.
674: # XXX should we warn about the fact that we do this?
675: if (&revcmp($rev1,$rev2) > 0) {
676: ($tmp1, $tmp2) = ($rev1, $sym1);
677: ($rev1, $sym1) = ($rev2, $sym2);
678: ($rev2, $sym2) = ($tmp1, $tmp2);
679: }
680: #
681: # XXX Putting '-p' here is a personal preference
682: if ($f eq 'c') {
683: $difftype = '-p -c';
684: $diffname = "Context diff";
685: } elsif ($f eq 's') {
686: $difftype = '--side-by-side --width=164';
687: $diffname = "Side by Side";
688: } else {
689: $difftype = '-p -u';
690: $diffname = "Unidiff";
691: }
692: # XXX should this just be text/plain
693: # or should it have an HTML header and then a <pre>
694: print "Content-type: text/plain\n\n";
695: open(RCSDIFF, "rcsdiff $difftype -r$rev1 -r$rev2 '$fullname' 2>&1 |") ||
696: &fail("500 Internal Error", "Couldn't rcsdiff: $!");
697: #
698: #===================================================================
699: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
700: #retrieving revision 1.16
701: #retrieving revision 1.17
702: #diff -c -r1.16 -r1.17
703: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
704: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
705: #
706: # Ideas:
707: # - nuke the stderr output if it's what we expect it to be
708: # - Add "no differences found" if the diff command supplied no output.
709: #
710: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
711: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
712: # (bogus example, but...)
713: #
714: if ($difftype eq '-u') {
715: $f1 = '---';
716: $f2 = '\+\+\+';
717: } else {
718: $f1 = '\*\*\*';
719: $f2 = '---';
720: }
721: while (<RCSDIFF>) {
722: if (m|^$f1 $cvsroot|o) {
723: s|$cvsroot/||o;
724: if ($sym1) {
725: chop;
726: $_ .= " " . $sym1 . "\n";
727: }
728: } elsif (m|^$f2 $cvsroot|o) {
729: s|$cvsroot/||o;
730: if ($sym2) {
731: chop;
732: $_ .= " " . $sym2 . "\n";
733: }
734: }
735: print $_;
736: }
737: close(RCSDIFF);
1.10 wosch 738: }
739:
740: sub cvsroot {
741: return '' if $cvstree eq $cvstreedefault;
742: return "&cvsroot=" . $cvstree;
1.1 jfieber 743: }
CVSweb