This repository was archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebrev.ksh
2948 lines (2616 loc) · 73.8 KB
/
webrev.ksh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
# Use is subject to license terms.
#
# This script takes a file list and a workspace and builds a set of html files
# suitable for doing a code review of source changes via a web page.
# Documentation is available via 'webrev -h'.
#
WEBREV_UPDATED=25.18-hg+openjdk.java.net
HTML='<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'
FRAMEHTML='<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'
STDHEAD='<meta charset="utf-8">
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<!--
Note to customizers: the body of the webrev is IDed as SUNWwebrev
to allow easy overriding by users of webrev via the userContent.css
mechanism available in some browsers.
For example, to have all "removed" information be red instead of
brown, set a rule in your userContent.css file like:
body#SUNWwebrev span.removed { color: red ! important; }
-->
<style type="text/css" media="screen">
body {
background-color: #eeeeee;
}
hr {
border: none 0;
border-top: 1px solid #aaa;
height: 1px;
}
div.summary {
font-size: .8em;
border-bottom: 1px solid #aaa;
padding-left: 1em;
padding-right: 1em;
}
div.summary h2 {
margin-bottom: 0.3em;
}
div.summary table th {
text-align: right;
vertical-align: top;
white-space: nowrap;
}
span.lineschanged {
font-size: 0.7em;
}
span.oldmarker {
color: red;
font-size: large;
font-weight: bold;
}
span.newmarker {
color: green;
font-size: large;
font-weight: bold;
}
span.removed {
color: brown;
}
span.changed {
color: blue;
}
span.new {
color: blue;
font-weight: bold;
}
a.print { font-size: x-small; }
</style>
<style type="text/css" media="print">
pre { font-size: 0.8em; font-family: courier, monospace; }
span.removed { color: #444; font-style: italic }
span.changed { font-weight: bold; }
span.new { font-weight: bold; }
span.newmarker { font-size: 1.2em; font-weight: bold; }
span.oldmarker { font-size: 1.2em; font-weight: bold; }
a.print {display: none}
hr { border: none 0; border-top: 1px solid #aaa; height: 1px; }
</style>
'
#
# UDiffs need a slightly different CSS rule for 'new' items (we don't
# want them to be bolded as we do in cdiffs or sdiffs).
#
UDIFFCSS='
<style type="text/css" media="screen">
span.new {
color: blue;
font-weight: normal;
}
</style>
'
#
# input_cmd | html_quote | output_cmd
# or
# html_quote filename | output_cmd
#
# Make a piece of source code safe for display in an HTML <pre> block.
#
html_quote()
{
sed -e "s/&/\&/g" -e "s/&#\([x]*[0-9A-Fa-f]\{2,5\}\);/\&#\1;/g" -e "s/</\</g" -e "s/>/\>/g" "$@" | expand
}
#
# input_cmd | html_quote | output_cmd
# or
# html_dequote filename | output_cmd
#
# Replace HTML entities with literals
#
html_dequote()
{
sed -e "s/"/\"/g" -e "s/'/\'/g" -e "s/&/\&/g" -e "s/</<'/g" -e "s/>/>/g" "$@" | expand
}
#
# input_cmd | bug2url | output_cmd
#
# Scan for bugids and insert <a> links to the relevent bug database.
#
bug2url()
{
sed -e 's|[0-9]\{5,\}|<a href=\"'$BUGURL$IDPREFIX'&\">&</a>|g'
}
#
# strip_unchanged <infile> | output_cmd
#
# Removes chunks of sdiff documents that have not changed. This makes it
# easier for a code reviewer to find the bits that have changed.
#
# Deleted lines of text are replaced by a horizontal rule. Some
# identical lines are retained before and after the changed lines to
# provide some context. The number of these lines is controlled by the
# variable C in the $AWK script below.
#
# The script detects changed lines as any line that has a "<span class="
# string embedded (unchanged lines have no particular class and are not
# part of a <span>). Blank lines (without a sequence number) are also
# detected since they flag lines that have been inserted or deleted.
#
strip_unchanged()
{
$AWK '
BEGIN { C = c = 20 }
NF == 0 || /span class=/ {
if (c > C) {
c -= C
inx = 0
if (c > C) {
print "\n</pre><hr></hr><pre>"
inx = c % C
c = C
}
for (i = 0; i < c; i++)
print ln[(inx + i) % C]
}
c = 0;
print
next
}
{ if (c >= C) {
ln[c % C] = $0
c++;
next;
}
c++;
print
}
END { if (c > (C * 2)) print "\n</pre><hr></hr>" }
' $1
}
prev_index_next_html()
{
RELROOT=$1
PREVIOUS_FILE=$2
NEXT_FILE=$3
EXTENSION=$4
if [[ $PREVIOUS_FILE = "no_prev" ]]
then
PREV_LINK="< prev"
else
PREV_LINK="<a href='${RELROOT}${PREVIOUS_FILE}.${EXTENSION}.html' target='_top'>< prev</a>"
fi
if [[ $NEXT_FILE = "no_next" ]]
then
NEXT_LINK="next >"
else
NEXT_LINK="<a href='${RELROOT}${NEXT_FILE}.${EXTENSION}.html' target='_top'>next ></a>"
fi
print "<center>${PREV_LINK} <a href='${RELROOT}index.html' target='_top'>index</a> ${NEXT_LINK}</center>"
}
#
# sdiff_to_html
#
# This function takes two files as arguments, obtains their diff, and
# processes the diff output to present the files as an HTML document with
# the files displayed side-by-side, differences shown in color. It also
# takes a delta comment, rendered as an HTML snippet, as the third
# argument. The function takes two files as arguments, then the name of
# file, the path, and the comment. The HTML will be delivered on stdout,
# e.g.
#
# $ sdiff_to_html old/usr/src/tools/scripts/webrev.sh \
# new/usr/src/tools/scripts/webrev.sh \
# webrev.sh usr/src/tools/scripts \
# '<a href="https://bugs.openjdk.java.net/browse/JDK-1234567">
# JDK-1234567</a> my bugid' > <file>.html
#
# framed_sdiff() is then called which creates $2.frames.html
# in the webrev tree.
#
# FYI: This function is rather unusual in its use of awk. The initial
# diff run produces conventional diff output showing changed lines mixed
# with editing codes. The changed lines are ignored - we're interested in
# the editing codes, e.g.
#
# 8c8
# 57a61
# 63c66,76
# 68,93d80
# 106d90
# 108,110d91
#
# These editing codes are parsed by the awk script and used to generate
# another awk script that generates HTML, e.g the above lines would turn
# into something like this:
#
# BEGIN { printf "<pre>\n" }
# function sp(n) {for (i=0;i<n;i++)printf "\n"}
# function wl(n) {printf "<font color=%s>%4d %s </font>\n", n, NR, $0}
# NR==8 {wl("#7A7ADD");next}
# NR==54 {wl("#7A7ADD");sp(3);next}
# NR==56 {wl("#7A7ADD");next}
# NR==57 {wl("black");printf "\n"; next}
# : :
#
# This script is then run on the original source file to generate the
# HTML that corresponds to the source file.
#
# The two HTML files are then combined into a single piece of HTML that
# uses an HTML table construct to present the files side by side. You'll
# notice that the changes are color-coded:
#
# black - unchanged lines
# blue - changed lines
# bold blue - new lines
# brown - deleted lines
#
# Blank lines are inserted in each file to keep unchanged lines in sync
# (side-by-side). This format is familiar to users of sdiff(1) or
# Teamware's filemerge tool.
#
sdiff_to_html()
{
diff $DIFFOPTS $1 $2 > /tmp/$$.diffs
TNAME=$3
TPATH=$4
COMMENT=$5
RELROOT=$6
PREVIOUS_FILE=$7
NEXT_FILE=$8
#
# Now we have the diffs, generate the HTML for the old file.
#
$AWK '
BEGIN {
printf "function sp(n) {for (i=0;i<n;i++)printf \"\\n\"}\n"
printf "function removed() "
printf "{printf \"<span class=\\\"removed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function changed() "
printf "{printf \"<span class=\\\"changed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n"
}
/^</ {next}
/^>/ {next}
/^---/ {next}
{
split($1, a, /[cad]/) ;
if (index($1, "a")) {
if (a[1] == 0) {
n = split(a[2], r, /,/);
if (n == 1)
printf "BEGIN\t\t{sp(1)}\n"
else
printf "BEGIN\t\t{sp(%d)}\n",\
(r[2] - r[1]) + 1
next
}
printf "NR==%s\t\t{", a[1]
n = split(a[2], r, /,/);
s = r[1];
if (n == 1)
printf "bl();printf \"\\n\"; next}\n"
else {
n = r[2] - r[1]
printf "bl();sp(%d);next}\n",\
(r[2] - r[1]) + 1
}
next
}
if (index($1, "d")) {
n = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
if (n == 1)
printf "NR==%s\t\t{removed(); next}\n" , n1
else
printf "NR==%s,NR==%s\t{removed(); next}\n" , n1, n2
next
}
if (index($1, "c")) {
n = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
final = n2
d1 = 0
if (n == 1)
printf "NR==%s\t\t{changed();" , n1
else {
d1 = n2 - n1
printf "NR==%s,NR==%s\t{changed();" , n1, n2
}
m = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
if (m > 1) {
d2 = n2 - n1
if (d2 > d1) {
if (n > 1) printf "if (NR==%d)", final
printf "sp(%d);", d2 - d1
}
}
printf "next}\n" ;
next
}
}
END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" }
' /tmp/$$.diffs > /tmp/$$.file1
#
# Now generate the HTML for the new file
#
$AWK '
BEGIN {
printf "function sp(n) {for (i=0;i<n;i++)printf \"\\n\"}\n"
printf "function new() "
printf "{printf \"<span class=\\\"new\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function changed() "
printf "{printf \"<span class=\\\"changed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n"
}
/^</ {next}
/^>/ {next}
/^---/ {next}
{
split($1, a, /[cad]/) ;
if (index($1, "d")) {
if (a[2] == 0) {
n = split(a[1], r, /,/);
if (n == 1)
printf "BEGIN\t\t{sp(1)}\n"
else
printf "BEGIN\t\t{sp(%d)}\n",\
(r[2] - r[1]) + 1
next
}
printf "NR==%s\t\t{", a[2]
n = split(a[1], r, /,/);
s = r[1];
if (n == 1)
printf "bl();printf \"\\n\"; next}\n"
else {
n = r[2] - r[1]
printf "bl();sp(%d);next}\n",\
(r[2] - r[1]) + 1
}
next
}
if (index($1, "a")) {
n = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
if (n == 1)
printf "NR==%s\t\t{new() ; next}\n" , n1
else
printf "NR==%s,NR==%s\t{new() ; next}\n" , n1, n2
next
}
if (index($1, "c")) {
n = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
final = n2
d2 = 0;
if (n == 1) {
final = n1
printf "NR==%s\t\t{changed();" , n1
} else {
d2 = n2 - n1
printf "NR==%s,NR==%s\t{changed();" , n1, n2
}
m = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
if (m > 1) {
d1 = n2 - n1
if (d1 > d2) {
if (n > 1) printf "if (NR==%d)", final
printf "sp(%d);", d1 - d2
}
}
printf "next}\n" ;
next
}
}
END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" }
' /tmp/$$.diffs > /tmp/$$.file2
#
# Post-process the HTML files by running them back through $AWK
#
html_quote < $1 | $AWK -f /tmp/$$.file1 > /tmp/$$.file1.html
html_quote < $2 | $AWK -f /tmp/$$.file2 > /tmp/$$.file2.html
#
# Now combine into a valid HTML file and side-by-side into a table
#
print "$HTML<head>$STDHEAD"
print "<title>$WNAME Sdiff $TPATH </title>"
print "</head><body id=\"SUNWwebrev\">"
prev_index_next_html "$RELROOT" "$PREVIOUS_FILE" "$NEXT_FILE" "sdiff"
print "<h2>$TPATH/$TNAME</h2>"
print "<a class=\"print\" href=\"javascript:print()\">Print this page</a>"
print "<pre>$COMMENT</pre>\n"
print "<table><tr valign=\"top\">"
print "<td><pre>"
strip_unchanged /tmp/$$.file1.html
print "</pre></td><td><pre>"
strip_unchanged /tmp/$$.file2.html
print "</pre></td>"
print "</tr></table>"
prev_index_next_html "$RELROOT" "$PREVIOUS_FILE" "$NEXT_FILE" "sdiff"
print "</body></html>"
framed_sdiff $TNAME $TPATH /tmp/$$.file1.html /tmp/$$.file2.html \
"$COMMENT" "$RELROOT" "$PREVIOUS_FILE" "$NEXT_FILE"
}
#
# framed_sdiff <filename> <filepath> <lhsfile> <rhsfile> <comment>
#
# Expects lefthand and righthand side html files created by sdiff_to_html.
# We use insert_anchors() to augment those with HTML navigation anchors,
# and then emit the main frame. Content is placed into:
#
# $WDIR/DIR/$TNAME.lhs.html
# $WDIR/DIR/$TNAME.rhs.html
# $WDIR/DIR/$TNAME.frames.html
#
# NOTE: We rely on standard usage of $WDIR and $DIR.
#
function framed_sdiff
{
typeset TNAME=$1
typeset TPATH=$2
typeset lhsfile=$3
typeset rhsfile=$4
typeset comments=$5
typeset RTOP
typeset RELROOT=$6
typeset PREVIOUS_FILE=$7
typeset NEXT_FILE=$8
# Enable html files to access WDIR via a relative path.
RTOP=$(relative_dir $TPATH $WDIR)
# Make the rhs/lhs files and output the frameset file.
print "$HTML<head>$STDHEAD" > $WDIR/$DIR/$TNAME.lhs.html
cat >> $WDIR/$DIR/$TNAME.lhs.html <<-EOF
<script type="text/javascript" src="$RTOP/ancnav.js"></script>
</head>
<body id="SUNWwebrev" onkeypress="keypress(event);">
<a name="0"></a>
<pre>$comments</pre><hr></hr>
EOF
cp $WDIR/$DIR/$TNAME.lhs.html $WDIR/$DIR/$TNAME.rhs.html
insert_anchors $lhsfile >> $WDIR/$DIR/$TNAME.lhs.html
insert_anchors $rhsfile >> $WDIR/$DIR/$TNAME.rhs.html
close='</body></html>'
print $close >> $WDIR/$DIR/$TNAME.lhs.html
print $close >> $WDIR/$DIR/$TNAME.rhs.html
typeset PREV_NEXT_FILE_NAME=$WDIR/$DIR/$TNAME.frames.prev_next.html
print "<body bgcolor='#eeeeee'><html>" > $PREV_NEXT_FILE_NAME
prev_index_next_html "$RELROOT" "$PREVIOUS_FILE" "$NEXT_FILE" "frames" >> $PREV_NEXT_FILE_NAME
print "</html></body>" >> $PREV_NEXT_FILE_NAME
print "$FRAMEHTML<head>$STDHEAD" > $WDIR/$DIR/$TNAME.frames.html
print "<title>$WNAME Framed-Sdiff " \
"$TPATH/$TNAME</title> </head>" >> $WDIR/$DIR/$TNAME.frames.html
cat >> $WDIR/$DIR/$TNAME.frames.html <<-EOF
<frameset rows="*,90">
<frameset cols="50%,50%">
<frame src="$TNAME.lhs.html" scrolling="auto" name="lhs" />
<frame src="$TNAME.rhs.html" scrolling="auto" name="rhs" />
</frameset>
<frameset rows="60, 30">
<frame src="$RTOP/ancnav.html" scrolling="no" marginwidth="0"
marginheight="0" name="nav" />
<frame src="$TNAME.frames.prev_next.html" scrolling="no" marginwidth="0"
marginheight="0" name="prev_next" />
</frameset>
<noframes>
<body id="SUNWwebrev">
Alas 'frames' webrev requires that your browser supports frames
and has the feature enabled.
</body>
</noframes>
</frameset>
</html>
EOF
}
#
# fix_postscript
#
# Merge codereview output files to a single conforming postscript file, by:
# - removing all extraneous headers/trailers
# - making the page numbers right
# - removing pages devoid of contents which confuse some
# postscript readers.
#
# From Casper.
#
function fix_postscript
{
infile=$1
cat > /tmp/$$.crmerge.pl << \EOF
print scalar(<>); # %!PS-Adobe---
print "%%Orientation: Landscape\n";
$pno = 0;
$doprint = 1;
$page = "";
while (<>) {
next if (/^%%Pages:\s*\d+/);
if (/^%%Page:/) {
if ($pno == 0 || $page =~ /\)S/) {
# Header or single page containing text
print "%%Page: ? $pno\n" if ($pno > 0);
print $page;
$pno++;
} else {
# Empty page, skip it.
}
$page = "";
$doprint = 1;
next;
}
# Skip from %%Trailer of one document to Endprolog
# %%Page of the next
$doprint = 0 if (/^%%Trailer/);
$page .= $_ if ($doprint);
}
if ($page =~ /\)S/) {
print "%%Page: ? $pno\n";
print $page;
} else {
$pno--;
}
print "%%Trailer\n%%Pages: $pno\n";
EOF
$PERL /tmp/$$.crmerge.pl < $infile
}
#
# input_cmd | insert_anchors | output_cmd
#
# Flag blocks of difference with sequentially numbered invisible
# anchors. These are used to drive the frames version of the
# sdiffs output.
#
# NOTE: Anchor zero flags the top of the file irrespective of changes,
# an additional anchor is also appended to flag the bottom.
#
# The script detects changed lines as any line that has a "<span
# class=" string embedded (unchanged lines have no class set and are
# not part of a <span>. Blank lines (without a sequence number)
# are also detected since they flag lines that have been inserted or
# deleted.
#
function insert_anchors
{
$AWK '
function ia() {
# This should be able to be a singleton <a /> but that
# seems to trigger a bug in firefox a:hover rule processing
printf "<a name=\"%d\" id=\"anc%d\"></a>", anc, anc++;
}
BEGIN {
anc=1;
inblock=1;
printf "<pre>\n";
}
NF == 0 || /^<span class=/ {
if (inblock == 0) {
ia();
inblock=1;
}
print;
next;
}
{
inblock=0;
print;
}
END {
ia();
printf "<b style=\"font-size: large; color: red\">";
printf "--- EOF ---</b>"
for(i=0;i<8;i++) printf "\n\n\n\n\n\n\n\n\n\n";
printf "</pre>"
printf "<form name=\"eof\">";
printf "<input name=\"value\" value=\"%d\" type=\"hidden\" />",
anc - 1;
printf "</form>";
}
' $1
}
#
# relative_dir
#
# Print a relative return path from $1 to $2. For example if
# $1=/tmp/myreview/raw_files/usr/src/tools/scripts and $2=/tmp/myreview,
# this function would print "../../../../".
#
# In the event that $1 is not in $2 a warning is printed to stderr,
# and $2 is returned-- the result of this is that the resulting webrev
# is not relocatable.
#
function relative_dir
{
d1=$1
d2=$2
if [[ "$d1" == "." ]]; then
print "."
else
typeset cur="${d1##$d2?(/)}"
typeset ret=""
if [[ $d2 == $cur ]]; then # Should never happen.
# Should never happen.
print -u2 "\nWARNING: relative_dir: \"$1\" not relative "
print -u2 "to \"$2\". Check input paths. Framed webrev "
print -u2 "will not be relocatable!"
print $2
return
fi
while [[ -n ${cur} ]];
do
cur=${cur%%*(/)*([!/])}
if [[ -z $ret ]]; then
ret=".."
else
ret="../$ret"
fi
done
print $ret
fi
}
#
# frame_nav_js
#
# Emit javascript for frame navigation
#
function frame_nav_js
{
cat << \EOF
var myInt;
var scrolling=0;
var sfactor = 3;
var scount=10;
function scrollByPix() {
if (scount<=0) {
sfactor*=1.2;
scount=10;
}
parent.lhs.scrollBy(0,sfactor);
parent.rhs.scrollBy(0,sfactor);
scount--;
}
function scrollToAnc(num) {
// Update the value of the anchor in the form which we use as
// storage for this value. setAncValue() will take care of
// correcting for overflow and underflow of the value and return
// us the new value.
num = setAncValue(num);
// Set location and scroll back a little to expose previous
// lines.
//
// Note that this could be improved: it is possible although
// complex to compute the x and y position of an anchor, and to
// scroll to that location directly.
//
parent.lhs.location.replace(parent.lhs.location.pathname + "#" + num);
parent.rhs.location.replace(parent.rhs.location.pathname + "#" + num);
parent.lhs.scrollBy(0,-30);
parent.rhs.scrollBy(0,-30);
}
function getAncValue()
{
return (parseInt(parent.nav.document.diff.real.value));
}
function setAncValue(val)
{
if (val <= 0) {
val = 0;
parent.nav.document.diff.real.value = val;
parent.nav.document.diff.display.value = "BOF";
return (val);
}
//
// The way we compute the max anchor value is to stash it
// inline in the left and right hand side pages-- it's the same
// on each side, so we pluck from the left.
//
maxval = parent.lhs.document.eof.value.value;
if (val < maxval) {
parent.nav.document.diff.real.value = val;
parent.nav.document.diff.display.value = val.toString();
return (val);
}
// this must be: val >= maxval
val = maxval;
parent.nav.document.diff.real.value = val;
parent.nav.document.diff.display.value = "EOF";
return (val);
}
function stopScroll() {
if (scrolling==1) {
clearInterval(myInt);
scrolling=0;
}
}
function startScroll() {
stopScroll();
scrolling=1;
myInt=setInterval("scrollByPix()",10);
}
function handlePress(b) {
switch (b) {
case 1 :
scrollToAnc(-1);
break;
case 2 :
scrollToAnc(getAncValue() - 1);
break;
case 3 :
sfactor=-3;
startScroll();
break;
case 4 :
sfactor=3;
startScroll();
break;
case 5 :
scrollToAnc(getAncValue() + 1);
break;
case 6 :
scrollToAnc(999999);
break;
}
}
function handleRelease(b) {
stopScroll();
}
function keypress(ev) {
var keynum;
var keychar;
if (window.event) { // IE
keynum = ev.keyCode;
} else if (ev.which) { // non-IE
keynum = ev.which;
}
keychar = String.fromCharCode(keynum);
if (keychar == "k") {
handlePress(2);
return (0);
} else if (keychar == "j" || keychar == " ") {
handlePress(5);
return (0);
}
return (1);
}
function ValidateDiffNum(){
val = parent.nav.document.diff.display.value;
if (val == "EOF") {
scrollToAnc(999999);
return;
}
if (val == "BOF") {
scrollToAnc(0);
return;
}
i=parseInt(val);
if (isNaN(i)) {
parent.nav.document.diff.display.value = getAncValue();
} else {
scrollToAnc(i);
}
return false;
}
EOF
}
#
# frame_navigation
#
# Output anchor navigation file for framed sdiffs.
#
function frame_navigation
{
print "$HTML<head>$STDHEAD"
cat << \EOF
<title>Anchor Navigation</title>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Type" content="text/html" />
<style type="text/css">
div.button td { padding-left: 5px; padding-right: 5px;
background-color: #eee; text-align: center;
border: 1px #444 outset; cursor: pointer; }
div.button a { font-weight: bold; color: black }
div.button td:hover { background: #ffcc99; }
</style>
EOF
print "<script type=\"text/javascript\" src=\"ancnav.js\"></script>"
cat << \EOF
</head>
<body id="SUNWwebrev" bgcolor="#eeeeee" onload="document.diff.real.focus();"
onkeypress="keypress(event);">
<noscript lang="javascript">
<center>
<p><big>Framed Navigation controls require Javascript</big><br />
Either this browser is incompatable or javascript is not enabled</p>
</center>
</noscript>
<table width="100%" border="0" align="center">
<tr>
<td valign="middle" width="25%">Diff navigation:
Use 'j' and 'k' for next and previous diffs; or use buttons
at right</td>
<td align="center" valign="top" width="50%">
<div class="button">
<table border="0" align="center">
<tr>
<td>
<a onMouseDown="handlePress(1);return true;"
onMouseUp="handleRelease(1);return true;"
onMouseOut="handleRelease(1);return true;"
onClick="return false;"
title="Go to Beginning Of file">BOF</a></td>
<td>
<a onMouseDown="handlePress(3);return true;"
onMouseUp="handleRelease(3);return true;"
onMouseOut="handleRelease(3);return true;"
title="Scroll Up: Press and Hold to accelerate"
onClick="return false;">Scroll Up</a></td>
<td>
<a onMouseDown="handlePress(2);return true;"
onMouseUp="handleRelease(2);return true;"
onMouseOut="handleRelease(2);return true;"
title="Go to previous Diff"
onClick="return false;">Prev Diff</a>
</td></tr>
<tr>
<td>
<a onMouseDown="handlePress(6);return true;"
onMouseUp="handleRelease(6);return true;"
onMouseOut="handleRelease(6);return true;"
onClick="return false;"
title="Go to End Of File">EOF</a></td>
<td>
<a onMouseDown="handlePress(4);return true;"
onMouseUp="handleRelease(4);return true;"
onMouseOut="handleRelease(4);return true;"
title="Scroll Down: Press and Hold to accelerate"
onClick="return false;">Scroll Down</a></td>
<td>
<a onMouseDown="handlePress(5);return true;"
onMouseUp="handleRelease(5);return true;"