2
# Copyright 2009 The Go Authors. All rights reserved.
3
# Use of this source code is governed by a BSD-style
4
# license that can be found in the LICENSE file.
6
# generate HTML for a program excerpt.
7
# first arg is file name
8
# second arg is awk pattern to match start line
9
# third arg is awk pattern to stop processing
11
# missing third arg means print one line
12
# third arg "END" means proces rest of file
13
# missing second arg means process whole file
17
# prog.sh foo.go # whole file
18
# prog.sh foo.go "/^func.main/" # signature of main
19
# prog.sh foo.go "/^func.main/" "/^}/ # body of main
21
# non-blank lines are annotated with line number in file
23
# line numbers are printed %.2d to make them equal-width for nice formatting.
24
# the format gives a leading 0. the format %2d gives a leading space but
25
# that appears to confuse sanjay's makehtml formatter into bungling quotes
26
# because it makes some lines look indented.
28
echo "<pre> <!-- $* -->"
32
if test "$3" = "END" # $2 to end of file
35
function LINE() { printf("%.2d\t%s\n", NR, $0) }
36
BEGIN { printing = 0 }
37
'$2' { printing = 1; LINE(); getline }
38
printing { if($0 ~ /./) { LINE() } else { print "" } }
42
function LINE() { printf("%.2d\t%s\n", NR, $0) }
43
BEGIN { printing = 0 }
44
'$2' { printing = 1; LINE(); getline }
45
'$3' && printing { if(printing) {printing = 0; LINE(); exit} }
46
printing { if($0 ~ /./) { LINE() } else { print "" } }
52
function LINE() { printf("%.2d\t%s\n", NR, $0) }
53
'$2' { LINE(); getline; exit }
58
function LINE() { printf("%.2d\t%s\n", NR, $0) }
59
{ if($0 ~ /./) { LINE() } else { print "" } }
63
echo >&2 usage: prog.sh file.go /func.main/ /^}/