~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to doc/prog.sh

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
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.
5
 
 
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
10
 
#
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
14
 
#
15
 
# examples:
16
 
#
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
20
 
#
21
 
# non-blank lines are annotated with line number in file
22
 
 
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.
27
 
 
28
 
echo "<pre> <!-- $* -->"
29
 
 
30
 
case $# in
31
 
3)
32
 
        if test "$3" = "END"  # $2 to end of file
33
 
        then
34
 
                awk '
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 "" } }
39
 
                '
40
 
        else    # $2 through $3
41
 
                awk '
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 "" } }
47
 
                '
48
 
        fi
49
 
        ;;
50
 
2)      # one line
51
 
        awk '
52
 
                function LINE() { printf("%.2d\t%s\n", NR, $0) }
53
 
                '$2' { LINE(); getline; exit }
54
 
        '
55
 
        ;;
56
 
1)      # whole file
57
 
        awk '
58
 
                function LINE() { printf("%.2d\t%s\n", NR, $0) }
59
 
                { if($0 ~ /./) { LINE() } else { print "" } }
60
 
        '
61
 
        ;;
62
 
*)
63
 
        echo >&2 usage: prog.sh file.go /func.main/ /^}/
64
 
esac <$1 |
65
 
sed '
66
 
        s/&/\&amp;/g
67
 
        s/"/\&quot;/g
68
 
        s/</\&lt;/g
69
 
        s/>/\&gt;/g
70
 
'
71
 
 
72
 
echo '</pre>'