]> Pileus Git - ~andy/gtk/blob - demos/gtk-demo/geninclude.pl.in
Silence compiler warnings
[~andy/gtk] / demos / gtk-demo / geninclude.pl.in
1 #!@PERL@ -w
2
3 print <<EOT;
4 typedef GtkWidget *(*GDoDemoFunc) (GtkWidget *do_widget);
5
6 typedef struct _Demo Demo;
7
8 struct _Demo 
9 {
10   gchar *name;
11   gchar *title;
12   gchar *filename;
13   GDoDemoFunc func;
14   Demo *children;
15 };
16
17 EOT
18
19 for $file (@ARGV) {
20     my %demo;
21     
22     ($basename = $file) =~ s/\.c$//;
23
24     open INFO_FILE, $file or die "Cannot open '$file'\n";
25     $title = <INFO_FILE>;
26     $title =~ s@^\s*/\*\s*@@;
27     $extra = "";
28     if ($title =~ /^(.*)::(.*)$/) {
29         $title = $1;
30         $extra = " $2";
31     }
32     $title =~ s@\s*$@@;
33     $extra =~ s@^\s*@@;
34     $extra =~ s@\s*$@@;
35
36     close INFO_FILE;
37
38     print "GtkWidget *do_$basename (GtkWidget *do_widget);\n";
39
40     push @demos, {"name" => $basename, "title" => $title, "file" => "$file $extra",
41                   "func"  => "do_$basename"};
42 }
43
44 # generate a list of 'parent names'
45 foreach $href (@demos) {
46     if ($href->{"title"} =~ m|^([-\w\s]+)/[-\w\s]+$|) {
47         my $parent_name = $1;
48         my $do_next = 0;
49
50         # parent detected
51         if (defined @parents) {
52             foreach $foo (@parents) {
53                 if ($foo eq $parent_name) {
54                     $do_next = 1;
55                 }
56             }
57             
58             if ($do_next) {
59                 next;
60             }
61         }
62
63         push @parents, $parent_name;
64
65         $tmp = (defined @child_arrays)?($#child_arrays + 1):0;
66         push @child_arrays, "child$tmp";
67
68         push @demos, {"name" => "NULL", "title" => $parent_name, "file" => "NULL",
69                       "func" => "NULL"};
70     }
71 }
72
73 if (defined @parents) {
74     $i = 0;
75     for ($i = 0; $i <= $#parents; $i++) {
76         $first = 1;
77         
78         print "\nDemo ", $child_arrays[$i], "[] = {\n";
79         
80         $j = 0;
81         for ($j = 0; $j <= $#demos; $j++) {
82             $href = $demos[$j];
83             
84             if (!defined $demos[$j]) {
85                 next;
86             }
87             
88             if ($demos[$j]{"title"} =~ m|^$parents[$i]/([-\w\s]+)$|) {
89                 if ($first) {
90                     $first = 0;
91                 } else {
92                     print ",\n";
93                 }
94                 
95                 print qq (  { "$demos[$j]{name}", "$1", "$demos[$j]{file}", $demos[$j]{func}, NULL });
96
97                 # hack ... ugly
98                 $demos[$j]{"title"} = "foo";
99             }
100         }
101
102         print ",\n";
103         print qq (  { NULL } );
104         print "\n};\n";
105     }   
106 }
107
108 # sort @demos
109 @demos_old = @demos;
110
111 @demos = sort {
112     $a->{"title"} cmp $b->{"title"};
113 } @demos_old;
114
115 # sort the child arrays
116 if (defined @child_arrays) {
117     for ($i = 0; $i <= $#child_arrays; $i++) {
118         @foo_old = @{$child_arrays[$i]};
119
120         @{$child_arrays[$i]} = sort {
121             $a->{"title"} cmp $b->{"title"};
122         } @foo_old;
123     }
124 }
125
126 # toplevel
127 print "\nDemo gtk_demos[] = {\n";
128
129 $first = 1;
130 foreach $href (@demos) {
131     $handled = 0;
132
133     # ugly evil hack
134     if ($href->{title} eq "foo") {
135         next;
136     }
137
138     if ($first) {
139         $first = 0;
140     } else {
141         print ", \n";
142     }
143
144     if (defined @parents) {
145         for ($i = 0; $i <= $#parents; $i++) {
146             if ($parents[$i] eq $href->{title}) {
147
148                 if ($href->{file} eq 'NULL') {
149                     print qq (  { NULL, "$href->{title}", NULL, $href->{func}, $child_arrays[$i] });
150                 } else {
151                     print qq (  { "$href->{name}", "$href->{title}", "$href->{file}", $href->{func}, $child_arrays[$i] });
152                 }
153                 
154                 $handled = 1;
155                 last;
156             }
157         }
158     }
159     
160     if ($handled) {
161         next;
162     }
163     
164     print qq (  { "$href->{name}", "$href->{title}", "$href->{file}", $href->{func}, NULL });
165 }
166
167 print ",\n";
168 print qq (  { NULL } );
169 print "\n};\n";
170
171 exit 0;