]> Cypherpunks repositories - gostls13.git/commitdiff
- stub for tutorial
authorRob Pike <r@golang.org>
Wed, 10 Sep 2008 18:46:05 +0000 (11:46 -0700)
committerRob Pike <r@golang.org>
Wed, 10 Sep 2008 18:46:05 +0000 (11:46 -0700)
- tools to make it easy to embed programs

R=gri
DELTA=103  (97 added, 2 deleted, 4 changed)
OCL=15085
CL=15085

doc/go_tutorial.txt [new file with mode: 0644]
doc/prog.sh [new file with mode: 0755]

diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt
new file mode 100644 (file)
index 0000000..500231e
--- /dev/null
@@ -0,0 +1,21 @@
+Get Going
+----
+
+Rob Pike
+
+----
+(September 10, 2008)
+
+
+This document is a tutorial introduction to the basics of the Go systems programming
+language, intended for programmers familiar with C or C++.
+
+--PROG progs/helloworld.go
+
+--PROG progs/helloworld.go /func.main/ END
+
+--PROG progs/helloworld.go /print/
+
+--PROG progs/helloworld.go /func/
+
+Now is the time.
diff --git a/doc/prog.sh b/doc/prog.sh
new file mode 100755 (executable)
index 0000000..8f376b6
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+# 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.
+# first arg is file name
+# 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 
+#
+# examples:
+#
+#      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
+
+echo "<pre> <!-- $* -->"
+
+case $# in
+3)
+       if test "$3" = "END"  # $2 to end of file
+       then
+               awk '
+                       BEGIN { printing = 0 }
+                       '$2' { printing = 1; print NR "\t" $0; getline }
+                       printing { if($0 ~ /./) { print NR "\t" $0 } else { print "" } }
+               '
+       else    # $2 through $3
+               awk '
+                       BEGIN { printing = 0 }
+                       '$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 "" } }
+               '
+       fi
+       ;;
+2)     # one line
+       awk '
+               '$2' { print NR "\t" $0; getline; exit }
+       '
+       ;;
+1)     # whole file
+       awk '
+               { if($0 ~ /./) { print NR "\t" $0 } else { print "" } }
+       '
+       ;;
+*)
+       echo >&2 usage: prog.sh file.go /func.main/ /^}/
+esac <$1 |
+sed '
+       s/&/\&amp;/g
+       s/"/\&quot;/g
+       s/</\&lt;/g
+       s/>/\&gt;/g
+'
+
+echo '</pre>'