ohair@314: #!/bin/ksh -p ohair@314: # ohair@314: # CDDL HEADER START ohair@314: # ohair@314: # The contents of this file are subject to the terms of the ohair@314: # Common Development and Distribution License (the "License"). ohair@314: # You may not use this file except in compliance with the License. ohair@314: # ohair@314: # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE ohair@314: # or http://www.opensolaris.org/os/licensing. ohair@314: # See the License for the specific language governing permissions ohair@314: # and limitations under the License. ohair@314: # ohair@314: # When distributing Covered Code, include this CDDL HEADER in each ohair@314: # file and include the License file at usr/src/OPENSOLARIS.LICENSE. ohair@314: # If applicable, add the following below this CDDL HEADER, with the ohair@314: # fields enclosed by brackets "[]" replaced with your own identifying ohair@314: # information: Portions Copyright [yyyy] [name of copyright owner] ohair@314: # ohair@314: # CDDL HEADER END ohair@314: # mduigou@616: # Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. ohair@314: # Use is subject to license terms. ohair@314: # ohair@314: # This script takes a file list and a workspace and builds a set of html files ohair@314: # suitable for doing a code review of source changes via a web page. ohair@314: # Documentation is available via 'webrev -h'. ohair@314: # ohair@314: ihse@907: WEBREV_UPDATED=25.1-hg+openjdk.java.net ohair@314: ohair@314: HTML=' ohair@314: ohair@314: \n' ohair@314: ohair@314: FRAMEHTML=' ohair@314: ohair@314: \n' ohair@314: mduigou@851: STDHEAD=' mduigou@851: ohair@314: ohair@314: ohair@314: ohair@314: ohair@314: ohair@314: ohair@314: ' ohair@314: ohair@314: # ohair@314: # UDiffs need a slightly different CSS rule for 'new' items (we don't ohair@314: # want them to be bolded as we do in cdiffs or sdiffs). ohair@314: # ohair@314: UDIFFCSS=' ohair@314: ohair@314: ' ohair@314: ohair@314: # ohair@314: # input_cmd | html_quote | output_cmd ohair@314: # or ohair@314: # html_quote filename | output_cmd ohair@314: # ohair@314: # Make a piece of source code safe for display in an HTML
block. ohair@314: # ohair@314: html_quote() ohair@314: { mduigou@851: sed -e "s/&/\&/g" -e "s/&#\([x]*[0-9A-Fa-f]\{2,5\}\);/\\1;/g" -e "s/\</g" -e "s/>/\>/g" "$@" | expand mduigou@851: } mduigou@851: mduigou@851: # mduigou@851: # input_cmd | html_quote | output_cmd mduigou@851: # or mduigou@851: # html_dequote filename | output_cmd mduigou@851: # mduigou@851: # Replace HTML entities with literals mduigou@851: # mduigou@851: html_dequote() mduigou@851: { mduigou@851: sed -e "s/"/\"/g" -e "s/'/\'/g" -e "s/&/\&/g" -e "s/</<'/g" -e "s/>/>/g" "$@" | expand ohair@314: } ohair@314: ohair@314: # ohair@314: # input_cmd | bug2url | output_cmd ohair@314: # ohair@314: # Scan for bugids and insert links to the relevent bug database. ohair@314: # ohair@314: bug2url() ohair@314: { mduigou@616: sed -e 's|[0-9]\{5,\}|&|g' ohair@314: } ohair@314: ohair@314: # ohair@314: # strip_unchanged| output_cmd ohair@314: # ohair@314: # Removes chunks of sdiff documents that have not changed. This makes it ohair@314: # easier for a code reviewer to find the bits that have changed. ohair@314: # ohair@314: # Deleted lines of text are replaced by a horizontal rule. Some ohair@314: # identical lines are retained before and after the changed lines to ohair@314: # provide some context. The number of these lines is controlled by the ohair@314: # variable C in the $AWK script below. ohair@314: # ohair@314: # The script detects changed lines as any line that has a "%%4d %%s\\n\", NR, $0}\n" ohair@314: printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n" ohair@314: } ohair@314: /^ {next} ohair@314: /^>/ {next} ohair@314: /^---/ {next} ohair@314: ohair@314: { ohair@314: split($1, a, /[cad]/) ; ohair@314: if (index($1, "a")) { ohair@314: if (a[1] == 0) { ohair@314: n = split(a[2], r, /,/); ohair@314: if (n == 1) ohair@314: printf "BEGIN\t\t{sp(1)}\n" ohair@314: else ohair@314: printf "BEGIN\t\t{sp(%d)}\n",\ ohair@314: (r[2] - r[1]) + 1 ohair@314: next ohair@314: } ohair@314: ohair@314: printf "NR==%s\t\t{", a[1] ohair@314: n = split(a[2], r, /,/); ohair@314: s = r[1]; ohair@314: if (n == 1) ohair@314: printf "bl();printf \"\\n\"; next}\n" ohair@314: else { ohair@314: n = r[2] - r[1] ohair@314: printf "bl();sp(%d);next}\n",\ ohair@314: (r[2] - r[1]) + 1 ohair@314: } ohair@314: next ohair@314: } ohair@314: if (index($1, "d")) { ohair@314: n = split(a[1], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: if (n == 1) ohair@314: printf "NR==%s\t\t{removed(); next}\n" , n1 ohair@314: else ohair@314: printf "NR==%s,NR==%s\t{removed(); next}\n" , n1, n2 ohair@314: next ohair@314: } ohair@314: if (index($1, "c")) { ohair@314: n = split(a[1], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: final = n2 ohair@314: d1 = 0 ohair@314: if (n == 1) ohair@314: printf "NR==%s\t\t{changed();" , n1 ohair@314: else { ohair@314: d1 = n2 - n1 ohair@314: printf "NR==%s,NR==%s\t{changed();" , n1, n2 ohair@314: } ohair@314: m = split(a[2], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: if (m > 1) { ohair@314: d2 = n2 - n1 ohair@314: if (d2 > d1) { ohair@314: if (n > 1) printf "if (NR==%d)", final ohair@314: printf "sp(%d);", d2 - d1 ohair@314: } ohair@314: } ohair@314: printf "next}\n" ; ohair@314: ohair@314: next ohair@314: } ohair@314: } ohair@314: ohair@314: END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" } ohair@314: ' /tmp/$$.diffs > /tmp/$$.file1 ohair@314: ohair@314: # ohair@314: # Now generate the HTML for the new file ohair@314: # ohair@314: $AWK ' ohair@314: BEGIN { ohair@314: printf "function sp(n) {for (i=0;i \\n\", NR, $0}\n" ohair@314: printf "function changed() " ohair@314: printf "{printf \"%%4d %%s\\n\", NR, $0}\n" ohair@314: printf "function changed() " ohair@314: printf "{printf \"%%4d %%s\\n\", NR, $0}\n" ohair@314: printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n" ohair@314: } ohair@314: ohair@314: /^ {next} ohair@314: /^>/ {next} ohair@314: /^---/ {next} ohair@314: ohair@314: { ohair@314: split($1, a, /[cad]/) ; ohair@314: if (index($1, "d")) { ohair@314: if (a[2] == 0) { ohair@314: n = split(a[1], r, /,/); ohair@314: if (n == 1) ohair@314: printf "BEGIN\t\t{sp(1)}\n" ohair@314: else ohair@314: printf "BEGIN\t\t{sp(%d)}\n",\ ohair@314: (r[2] - r[1]) + 1 ohair@314: next ohair@314: } ohair@314: ohair@314: printf "NR==%s\t\t{", a[2] ohair@314: n = split(a[1], r, /,/); ohair@314: s = r[1]; ohair@314: if (n == 1) ohair@314: printf "bl();printf \"\\n\"; next}\n" ohair@314: else { ohair@314: n = r[2] - r[1] ohair@314: printf "bl();sp(%d);next}\n",\ ohair@314: (r[2] - r[1]) + 1 ohair@314: } ohair@314: next ohair@314: } ohair@314: if (index($1, "a")) { ohair@314: n = split(a[2], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: if (n == 1) ohair@314: printf "NR==%s\t\t{new() ; next}\n" , n1 ohair@314: else ohair@314: printf "NR==%s,NR==%s\t{new() ; next}\n" , n1, n2 ohair@314: next ohair@314: } ohair@314: if (index($1, "c")) { ohair@314: n = split(a[2], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: final = n2 ohair@314: d2 = 0; ohair@314: if (n == 1) { ohair@314: final = n1 ohair@314: printf "NR==%s\t\t{changed();" , n1 ohair@314: } else { ohair@314: d2 = n2 - n1 ohair@314: printf "NR==%s,NR==%s\t{changed();" , n1, n2 ohair@314: } ohair@314: m = split(a[1], r, /,/); ohair@314: n1 = r[1] ohair@314: n2 = r[2] ohair@314: if (m > 1) { ohair@314: d1 = n2 - n1 ohair@314: if (d1 > d2) { ohair@314: if (n > 1) printf "if (NR==%d)", final ohair@314: printf "sp(%d);", d1 - d2 ohair@314: } ohair@314: } ohair@314: printf "next}\n" ; ohair@314: next ohair@314: } ohair@314: } ohair@314: END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" } ohair@314: ' /tmp/$$.diffs > /tmp/$$.file2 ohair@314: ohair@314: # ohair@314: # Post-process the HTML files by running them back through $AWK ohair@314: # ohair@314: html_quote < $1 | $AWK -f /tmp/$$.file1 > /tmp/$$.file1.html ohair@314: ohair@314: html_quote < $2 | $AWK -f /tmp/$$.file2 > /tmp/$$.file2.html ohair@314: ohair@314: # ohair@314: # Now combine into a valid HTML file and side-by-side into a table ohair@314: # ohair@314: print "$HTML$STDHEAD" ohair@314: print " $WNAME Sdiff $TPATH " ohair@314: print "" ohair@314: print "$TPATH/$TNAME
" ohair@314: print "Print this page" ohair@314: print "$COMMENT\n" ohair@314: print "" ohair@314: print "" ohair@314: ohair@314: framed_sdiff $TNAME $TPATH /tmp/$$.file1.html /tmp/$$.file2.html \ ohair@314: "$COMMENT" ohair@314: } ohair@314: ohair@314: ohair@314: # ohair@314: # framed_sdiff
" ohair@314: print " " ohair@314: ohair@314: strip_unchanged /tmp/$$.file1.html ohair@314: ohair@314: print "" ohair@314: print " " ohair@314: ohair@314: strip_unchanged /tmp/$$.file2.html ohair@314: ohair@314: print "ohair@314: # ohair@314: # Expects lefthand and righthand side html files created by sdiff_to_html. ohair@314: # We use insert_anchors() to augment those with HTML navigation anchors, ohair@314: # and then emit the main frame. Content is placed into: ohair@314: # ohair@314: # $WDIR/DIR/$TNAME.lhs.html ohair@314: # $WDIR/DIR/$TNAME.rhs.html ohair@314: # $WDIR/DIR/$TNAME.frames.html ohair@314: # ohair@314: # NOTE: We rely on standard usage of $WDIR and $DIR. ohair@314: # ohair@314: function framed_sdiff ohair@314: { ohair@314: typeset TNAME=$1 ohair@314: typeset TPATH=$2 ohair@314: typeset lhsfile=$3 ohair@314: typeset rhsfile=$4 ohair@314: typeset comments=$5 ohair@314: typeset RTOP ohair@314: ohair@314: # Enable html files to access WDIR via a relative path. ohair@314: RTOP=$(relative_dir $TPATH $WDIR) ohair@314: ohair@314: # Make the rhs/lhs files and output the frameset file. ohair@314: print "$HTML$STDHEAD" > $WDIR/$DIR/$TNAME.lhs.html ohair@314: ohair@314: cat >> $WDIR/$DIR/$TNAME.lhs.html <<-EOF ohair@314: ohair@314: ohair@314: ohair@314: ohair@314: $comments
ohair@314: EOF ohair@314: ohair@314: cp $WDIR/$DIR/$TNAME.lhs.html $WDIR/$DIR/$TNAME.rhs.html ohair@314: ohair@314: insert_anchors $lhsfile >> $WDIR/$DIR/$TNAME.lhs.html ohair@314: insert_anchors $rhsfile >> $WDIR/$DIR/$TNAME.rhs.html ohair@314: ohair@314: close='' ohair@314: ohair@314: print $close >> $WDIR/$DIR/$TNAME.lhs.html ohair@314: print $close >> $WDIR/$DIR/$TNAME.rhs.html ohair@314: ohair@314: print "$FRAMEHTML$STDHEAD" > $WDIR/$DIR/$TNAME.frames.html ohair@314: print "$WNAME Framed-Sdiff " \ ohair@314: "$TPATH/$TNAME " >> $WDIR/$DIR/$TNAME.frames.html ohair@314: cat >> $WDIR/$DIR/$TNAME.frames.html <<-EOF ohair@314: ohair@314: