source: trunk/third/gtk/examples/extract.awk @ 14482

Revision 14482, 1.5 KB checked in by ghudson, 25 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14481, which included commits to RCS files with non-trunk default branches.
Line 
1# extract - extract C source files from GTK Tutorial
2# Copyright (C) Tony Gale 1998
3# Contact: gale@gtk.org
4#
5# Command Switches:
6# -c : Just do checking rather than output files
7# -f <filename> : Extract a specific file
8# -d : Extract files to current directory
9 
10BEGIN {in_example=0; check=0; spec_example=""; do_output=0; flatten=0
11       for (i=0 ; i < ARGC ; i++) {
12        if ( ARGV[i] == "-c" ) {
13          check = 1;
14          ARGV[i]="";
15        } else if ( ARGV[i] == "-f" ) {
16          spec_example=ARGV[i+1];
17          ARGV[i]="";
18          ARGV[i+1]="";
19          if ( length(spec_example) == 0 ) {
20            print "usage: -f <filename>";
21            exit;
22          }
23        } else if ( ARGV[i] == "-d" ) {
24          flatten = 1;
25          ARGV[i]="";
26        }
27       }
28      }
29
30$2 == "example-start" && in_example == 1 { printf("\nERROR: nested example at line %d\n", NR) > "/dev/stderr";
31                                           exit}
32
33$2 == "example-start"                    { in_example=1 }
34
35$2 == "example-start" && check == 0 \
36  { if ( (spec_example == "") || (spec_example == $4) ) {
37    if ( flatten == 0 ) {
38      if (file_name != "")
39          close(file_name);
40      file_name = sprintf("%s/%s",$3, $4);
41      command = sprintf("mkdir -p %s", $3);
42      system(command);
43    } else {
44      file_name = $4;
45    }
46    do_output=1;
47  }
48  }
49
50in_example==1 && check==0 && do_output==1 { gsub(/&amp;/, "\\&", $0);
51                                            print $0 >file_name }
52
53$2 == "example-end" && in_example == 0    { printf("\nERROR: multiple ends at line %d\n", NR) > "/dev/stderr";
54                                            exit}
55$2 == "example-end"                       { in_example=0; do_output=0 }
56
57
58END {}
59
Note: See TracBrowser for help on using the repository browser.