file.c: Add profiling of CPU seconds consumed during file load
[geda-pcb/gde.git] / src / gather-actions
blobf0241587782aab2a5de49d2a7dc9886dd3bea755
1 #!/usr/bin/perl
2 # -*- perl -*-
3 # $Id$
5 # COPYRIGHT
6 # PCB, interactive printed circuit board design
7 # Copyright (C) 2004 DJ Delorie
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # Contact addresses for paper mail and Email:
24 # DJ Delorie, 334 North Road, Deerfield NH 03037-1110, USA
25 # dj@delorie.com
27 #-----------------------------------------------------------------------------
28 # Include a comment like this anywhere in your source to automatically
29 # register an action. The gather-actions script looks for these and
30 # generates the list, but the comment keeps it from actually doing
31 # anything in your source. Note: do not quote the name, and include no
32 # extra spaces.
34 # /* ACTION(name,func) */
36 # Similarly, but for menu flags. The parm is passed to the func, so
37 # you can have one function support multiple flags. */
39 # /* FLAG(name,func,parm) */
41 # Similarly, but for menu generators. In the menu resource, entries of
42 # the form "@func" will call the func named in this table to include a
43 # dynamically generated set of buttons. */
45 # /* MENU(name,func) */
46 #-----------------------------------------------------------------------------
48 $verbose = 0;
50 open(OUT, "> actionlist.c");
51 select OUT;
53 print "/* This file is generated by gather-actions. DO NOT EDIT. */\n";
54 print "\n";
55 print "#include \"global.h\"\n";
56 print "#include \"X11/Intrinsic.h\"\n";
57 print "\n";
59 foreach $file (@ARGV) {
60 next if $file =~ /\.h$/;
61 open(F, $file);
62 while (<F>) {
63 if (/\/\* ACTION\((.*)\) *(POPUP|CREATE)?/) {
64 print STDERR "action: $1 $2\n" if $verbose;
65 ($name, $func) = split(',', $1, 2);
66 push(@actions, "$name\0$func\0$2");
67 push(@actionfuncs, "$func");
68 } elsif (/\/\* FLAG\((.*)\)/) {
69 print STDERR "flag: $1\n" if $verbose;
70 ($name, $func, $parm) = split(',', $1, 3);
71 $parm = 0 unless $parm =~ /\S/;
72 push(@flags, "$name\0$func\0$parm");
73 push(@flagfuncs, "$func");
74 } elsif (/\/\* MENU\((.*)\)/) {
75 print STDERR "menu: $1\n" if $verbose;
76 ($name, $func) = split(',', $1,2);
77 push(@menus, "$name\0$func");
78 push(@menufuncs, "$func");
81 close(F);
84 #-----------------------------------------------------------------------------
86 for $func (sort @actionfuncs) {
87 print "extern void $func(Widget,XEvent *,String *, Cardinal *);\n";
90 print "\n";
91 print "XtActionsRec ActionList[] = {\n";
92 for $a (sort @actions) {
93 ($name, $func, $types) = split(/\0/, $a);
94 print " {\"$name\", $func},\n";
97 print " {0,0}\n";
98 print "};\n";
99 print "\n";
101 print "struct { char *name; int type; } ActionTypeList[] = {\n";
102 for $a (sort @actions) {
103 ($name, $func, $types) = split(/\0/, $a);
104 $type = 0;
105 $type = "'p'" if $types =~ /popup/i;
106 $type = "'c'" if $types =~ /create/i;
107 print " {\"$name\", $type},\n";
109 print " {0,0}\n";
110 print "};\n";
111 print "\n";
113 $n = $#actions + 1;
114 print "int ActionListSize = $n;\n";
116 #-----------------------------------------------------------------------------
118 for $func (sort @flagfuncs) {
119 print "extern int $func(int);\n";
122 print "\n";
123 print "struct {\n";
124 print " char *name;\n";
125 print " int (*func)(int);\n";
126 print " int parm;\n";
127 print "} FlagFuncList[] = {\n";
129 for $f (sort @flags) {
130 ($name, $func, $parm) = split(/\0/, $f);
131 print " {\"$name\", $func, $parm },\n";
134 print " {0,0,0}\n";
135 print "};\n";
136 print "\n";
138 $n = $#flags + 1;
139 print "int FlagFuncListSize = $n;\n";
141 #-----------------------------------------------------------------------------
143 print "struct Resource;\n";
144 for $func (sort @menufuncs) {
145 print "extern void $func(struct Resource *);\n";
148 print "\n";
149 print "struct {\n";
150 print " char *name;\n";
151 print " void (*func)(struct Resource *);\n";
152 print "} MenuFuncList[] = {\n";
154 for $f (sort @menus) {
155 ($name, $func) = split(/\0/, $f);
156 print " {\"$name\", $func },\n";
159 print " {0,0}\n";
160 print "};\n";
161 print "\n";
163 $n = $#menus + 1;
164 print "int MenuFuncListSize = $n;\n";
166 #-----------------------------------------------------------------------------
168 close(OUT);