diff options
author | BST 1998 Tony Gale <gale@gtk.org> | 1998-06-04 11:15:55 +0000 |
---|---|---|
committer | Tony Gale <gale@src.gnome.org> | 1998-06-04 11:15:55 +0000 |
commit | 68935c790b7b4292df3297957394b34d2c36ca9d (patch) | |
tree | fc818c2cc1abf918433ecf9a68ddfa82ccebcddf /examples/extract.awk | |
parent | 7c8ae8a5f5bbbd1f140f2daa3285f173da00085e (diff) | |
download | gtk+-68935c790b7b4292df3297957394b34d2c36ca9d.tar.gz |
New files to automagically extract code examples from the tutorial.
Thu Jun 4 12:12:11 BST 1998 Tony Gale <gale@gtk.org>
* examples/extract.sh, examples/extract.awk:
New files to automagically extract code examples from the
tutorial.
Diffstat (limited to 'examples/extract.awk')
-rw-r--r-- | examples/extract.awk | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/extract.awk b/examples/extract.awk new file mode 100644 index 0000000000..44cd32a3d2 --- /dev/null +++ b/examples/extract.awk @@ -0,0 +1,57 @@ +# extract - extract C source files from GTK Tutorial +# Copyright (C) Tony Gale 1998 +# Contact: gale@gtk.org +# +# Command Switches: +# -c : Just do checking rather than output files +# -f <filename> : Extract a specific file +# -d : Extract files to current directory + +BEGIN {in_example=0; check=0; spec_example=""; do_output=0; flatten=0 + for (i=0 ; i < ARGC ; i++) { + if ( ARGV[i] == "-c" ) { + check = 1; + ARGV[i]=""; + } else if ( ARGV[i] == "-f" ) { + spec_example=ARGV[i+1]; + ARGV[i]=""; + ARGV[i+1]=""; + if ( length(spec_example) == 0 ) { + print "usage: -f <filename>"; + exit; + } + } else if ( ARGV[i] == "-d" ) { + flatten = 1; + ARGV[i]=""; + } + } + } + +$2 == "example-start" && in_example == 1 { printf("\nERROR: nested example at line %d\n", NR) > "/dev/stderr"; + exit} + +$2 == "example-start" { in_example=1 } + +$2 == "example-start" && check == 0 \ + { if ( (spec_example == "") || (spec_example == $4) ) { + if ( flatten == 0 ) { + file_name = sprintf("%s/%s",$3, $4); + command = sprintf("mkdir -p %s", $3); + system(command); + } else { + file_name = $4; + } + do_output=1; + } + } + +in_example==1 && check==0 && do_output==1 { gsub(/&/, "\\&", $0); + print $0 >file_name } + +$2 == "example-end" && in_example == 0 { printf("\nERROR: multiple ends at line %d\n", NR) > "/dev/stderr"; + exit} +$2 == "example-end" { in_example=0; do_output=0 } + + +END {} + |