3 # Information about the current enumeration
4 # Modifed to generate output for clg
7 my $flags; # Is enumeration a bitmask
8 my $seenbitshift; # Have we seen bitshift operators?
9 my $prefix; # Prefix for this enumeration
10 my $enumname; # Name for this enumeration
11 my $firstenum = 1; # Is this the first enumeration in file?
12 my @entries; # [ $name, $val ] for each entry
18 for $opt (split /\s*,\s*/, $opts) {
19 my ($key,$val) = $opt =~ /\s*(\w+)(?:=(\S+))?/;
20 defined $val or $val = 1;
21 push @opts, $key, $val;
29 # Read lines until we have no open comments
34 defined ($new = <$file>) || die "Unmatched comment";
46 # Handle include files
47 if (/^\#include\s*<([^>]*)>/ ) {
49 open NEWFILE
, $file or die "Cannot open include file $file: $!\n";
51 if (parse_entries
(\
*NEWFILE
)) {
58 if (/^\s*\}\s*(\w+)/) {
73 my ($name, $value, $options) = ($1,$2,$3);
75 if (!defined $flags && defined $value && $value =~ /<</) {
78 if (defined $options) {
79 my %options = parse_options
($options);
80 if (!defined $options{skip
}) {
81 push @entries, [ $name, $value, $options{nick
} ];
84 push @entries, [ $name, $value ];
87 print STDERR
"Can't understand: $_\n";
96 $enumname =~ s/([A-Z])/-$1/g;
97 return substr (lc ($enumname), 5);
107 if ($ARGV[0] eq "arrays") {
110 } elsif ($ARGV[0] eq "defs") {
120 print ";; generated by a modified makeenums.pl ; -*- lisp -*-\n\n";
122 print "/* Generated by makeenums.pl */\n\n";
128 close (ARGV
); # reset line numbering
129 $firstenum = 1; # Flag to print filename at next enum
132 if (m@
^\s
*typedef\s
+enum\s
*
139 my %options = parse_options
($2);
140 $prefix = $options{prefix
};
141 $flags = $options{flags
};
146 # Didn't have trailing '{' look on next lines
158 # Now parse the entries
159 parse_entries
(\
*ARGV
);
161 # figure out if this was a flags or enums enumeration
163 if (!defined $flags) {
164 $flags = $seenbitshift;
167 # Autogenerate a prefix
169 if (!defined $prefix) {
172 if (defined $prefix) {
173 my $tmp = ~ ($name ^ $prefix);
174 ($tmp) = $tmp =~ /(^\xff*)/;
175 $prefix = $prefix & $tmp;
180 # Trim so that it ends in an underscore
181 $prefix =~ s/_[^_]*$/_/;
184 for $entry (@entries) {
185 my ($name,$value,$nick) = @
{$entry};
187 if (!defined $nick) {
188 ($nick = $name) =~ s/^$prefix//;
191 @
{$entry} = ($name, $value, $nick);
195 # Spit out the output
199 print qq(\n; enumerations from
"$ARGV"\n);
203 my $lispname = make_lispname
($enumname);
204 print "\n(deftype (".$lispname." \"".$enumname."\") ()\n '(". ($flags ?
"flags" : "enum");
208 my ($name,$value,$nick) = @
{$_};
211 if (defined $value) {
215 if ($flags && not ($value =~ s/1\s+<<\s+(\d+)/$1/)) {
220 print " (:$nick $value)";
231 my $valuename = $enumname;
232 $valuename =~ s/([^A-Z])([A-Z])/$1_$2/g;
233 $valuename =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
234 $valuename = lc($valuename);
236 print "static const GtkEnumValue _${valuename}_values[] = {\n";
238 my ($name,$value,$nick) = @
{$_};
239 print qq( { $name, "$name", "$nick" },\n);
241 print " { 0, NULL, NULL }\n";