3 # Information about the current enumeration
5 my $flags; # Is enumeration a bitmask
6 my $seenbitshift; # Have we seen bitshift operators?
7 my $prefix; # Prefix for this enumeration
8 my $enumname; # Name for this enumeration
9 my $firstenum = 1; # Is this the first enumeration in file?
10 my @entries; # [ $name, $val ] for each entry
16 for $opt (split /\s*,\s*/, $opts) {
17 my ($key,$val) = $opt =~ /\s*(\w+)(?:=(\S+))?/;
18 defined $val or $val = 1;
19 push @opts, $key, $val;
27 # Read lines until we have no open comments
32 defined ($new = <$file>) || die "Unmatched comment";
44 # Handle include files
45 if (/^\#include\s*<([^>]*)>/ ) {
47 open NEWFILE, $file or die "Cannot open include file $file: $!\n";
49 if (parse_entries (\*NEWFILE)) {
56 if (/^\s*\}\s*(\w+)/) {
71 my ($name, $value, $options) = ($1,$2,$3);
73 if (!defined $flags && defined $value && $value =~ /<</) {
76 if (defined $options) {
77 my %options = parse_options($options);
78 if (!defined $options{skip}) {
79 push @entries, [ $name, $options{nick} ];
82 push @entries, [ $name ];
85 print STDERR "Can't understand: $_\n";
98 if ($ARGV[0] eq "arrays") {
101 } elsif ($ARGV[0] eq "defs") {
111 print ";; generated by makeenums.pl ; -*- scheme -*-\n\n";
113 print "/* Generated by makeenums.pl */\n\n";
119 close (ARGV); # reset line numbering
120 $firstenum = 1; # Flag to print filename at next enum
123 if (m@^\s*typedef\s+enum\s*
130 my %options = parse_options($2);
131 $prefix = $options{prefix};
132 $flags = $options{flags};
137 # Didn't have trailing '{' look on next lines
149 # Now parse the entries
150 parse_entries (\*ARGV);
152 # figure out if this was a flags or enums enumeration
154 if (!defined $flags) {
155 $flags = $seenbitshift;
158 # Autogenerate a prefix
160 if (!defined $prefix) {
163 if (defined $prefix) {
164 my $tmp = ~ ($name ^ $prefix);
165 ($tmp) = $tmp =~ /(^\xff*)/;
166 $prefix = $prefix & $tmp;
171 # Trim so that it ends in an underscore
172 $prefix =~ s/_[^_]*$/_/;
175 for $entry (@entries) {
176 my ($name,$nick) = @{$entry};
177 if (!defined $nick) {
178 ($nick = $name) =~ s/^$prefix//;
181 @{$entry} = ($name, $nick);
185 # Spit out the output
189 print qq(\n; enumerations from "$ARGV"\n);
193 print "\n(define-".($flags ? "flags" : "enum")." $enumname";
196 my ($name,$nick) = @{$_};
197 print "\n ($nick $name)";
202 my $valuename = $enumname;
203 $valuename =~ s/([^A-Z])([A-Z])/$1_$2/g;
204 $valuename =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
205 $valuename = lc($valuename);
207 print "static const GtkEnumValue _${valuename}_values[] = {\n";
209 my ($name,$nick) = @{$_};
210 print qq( { $name, "$name", "$nick" },\n);
212 print " { 0, NULL, NULL }\n";