]> Pileus Git - ~andy/gtk/blob - examples/extract.awk
Remove GtkTree completely
[~andy/gtk] / examples / extract.awk
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 # -v : Verbose
10  
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" ) {
14           check = 1;
15           ARGV[i]="";
16         } else if ( ARGV[i] == "-f" ) {
17           spec_example=ARGV[i+1];
18           ARGV[i]="";
19           ARGV[i+1]="";
20           if ( length(spec_example) == 0 ) {
21             print "usage: -f <filename>";
22             exit;
23           }
24         } else if ( ARGV[i] == "-d" ) {
25           flatten = 1;
26           ARGV[i]="";
27         } else if ( ARGV[i] == "-v" ) {
28           verbose = 1;
29           ARGV[i] = "";
30         }
31        }
32 }
33
34 $2 == "example-end" && in_example == 0    { printf("\nERROR: multiple ends at line %d\n", NR) > "/dev/stderr";
35                                             exit}
36 $2 == "example-end"                       { in_example=0; do_output=0 }
37
38 in_example==1 && check==0 && do_output==1 { gsub(/&amp;/, "\\&", $0);
39                                             gsub(/&lt;/, "<", $0);
40                                             gsub(/&gt;/, ">", $0);
41                                             print $0 >file_name } 
42
43 $2 == "example-start" && in_example == 1 { printf("\nERROR: nested example at line %d\n", NR) > "/dev/stderr";
44                                            exit}
45
46 $2 == "example-start"                    { in_example=1 }
47
48 $2 == "example-start" && check == 0 \
49   { if ( (spec_example == "") || (spec_example == $4) ) {
50     if ( flatten == 0 ) {
51       if (file_name != "")
52           close(file_name);
53       file_name = sprintf("%s/%s",$3, $4);
54       command = sprintf("mkdir -p %s", $3);
55       system(command);
56     } else {
57       file_name = $4;
58     }
59     if (verbose == 1)
60       printf("%s\n", file_name);
61     do_output=1;
62   }
63   }
64
65
66 END {}
67
68
69