1 # extract - extract C source files from GTK Tutorial
2 # Copyright (C) Tony Gale 1998
3 # Contact: gale@gtk.org
6 # -c : Just do checking rather than output files
7 # -f <filename> : Extract a specific file
8 # -d : Extract files to current directory
11 BEGIN {in_example=0; check=0; spec_example=""; do_output=0; flatten=0; verbose=0;
12 for (i=0 ; i < ARGC ; i++) {
13 if ( ARGV[i] == "-c" ) {
16 } else if ( ARGV[i] == "-f" ) {
17 spec_example=ARGV[i+1];
20 if ( length(spec_example) == 0 ) {
21 print "usage: -f <filename>";
24 } else if ( ARGV[i] == "-d" ) {
27 } else if ( ARGV[i] == "-v" ) {
34 $2 == "example-end" && in_example == 0 { printf("\nERROR: multiple ends at line %d\n", NR) > "/dev/stderr";
36 $2 == "example-end" { in_example=0; do_output=0 }
38 in_example==1 && check==0 && do_output==1 { gsub(/&/, "\\&", $0);
39 gsub(/</, "<", $0);
40 gsub(/>/, ">", $0);
43 $2 == "example-start" && in_example == 1 { printf("\nERROR: nested example at line %d\n", NR) > "/dev/stderr";
46 $2 == "example-start" { in_example=1 }
48 $2 == "example-start" && check == 0 \
49 { if ( (spec_example == "") || (spec_example == $4) ) {
53 file_name = sprintf("%s/%s",$3, $4);
54 command = sprintf("mkdir -p %s", $3);
60 printf("%s\n", file_name);