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