| # Copyright 2009 The Go Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style |
| # license that can be found in the LICENSE file. |
| # generate HTML for a program excerpt. |
| # second arg is awk pattern to match start line |
| # third arg is awk pattern to stop processing |
| # missing third arg means print one line |
| # third arg "END" means proces rest of file |
| # missing second arg means process whole file |
| # prog.sh foo.go # whole file |
| # prog.sh foo.go "/^func.main/" # signature of main |
| # prog.sh foo.go "/^func.main/" "/^}/ # body of main |
| # non-blank lines are annotated with line number in file |
| if test "$3" = "END" # $2 to end of file |
| '$2' { printing = 1; print NR "\t" $0; getline } |
| printing { if($0 ~ /./) { print NR "\t" $0 } else { print "" } } |
| '$2' { printing = 1; print NR "\t" $0; getline } |
| '$3' && printing { if(printing) {printing = 0; print NR "\t" $0; exit} } |
| printing { if($0 ~ /./) { print NR "\t" $0 } else { print "" } } |
| '$2' { print NR "\t" $0; getline; exit } |
| { if($0 ~ /./) { print NR "\t" $0 } else { print "" } } |
| echo >&2 usage: prog.sh file.go /func.main/ /^}/ |