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