Commit 49eacae2 authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

applied patch from David Necas which introduces an underscore_name option

Tue Oct 10 12:06:08 2006  Tim Janik  <timj@gtk.org>

        * glib-mkenums.in:
        * glib-mkenums.1: applied patch from David Necas which introduces
        an underscore_name option and fixes #358734.
parent 4766e33d
Tue Oct 10 12:06:08 2006 Tim Janik <timj@gtk.org>
* glib-mkenums.in:
* glib-mkenums.1: applied patch from David Necas which introduces
an underscore_name option and fixes #358734.
Mon Oct 2 15:50:16 2006 Tim Janik <timj@gtk.org> Mon Oct 2 15:50:16 2006 Tim Janik <timj@gtk.org>
* gvalue.c (g_value_peek_pointer): reverted a change to have an * gvalue.c (g_value_peek_pointer): reverted a change to have an
......
...@@ -126,8 +126,9 @@ start out with the trigraph sequence "/*<" and end with the trigraph sequence "> ...@@ -126,8 +126,9 @@ start out with the trigraph sequence "/*<" and end with the trigraph sequence ">
Per enum definition, the options "skip" and "flags" can be specified, to indicate Per enum definition, the options "skip" and "flags" can be specified, to indicate
this enum definition to be skipped, or for it to be treated as a flags definition, or this enum definition to be skipped, or for it to be treated as a flags definition, or
to specify the common prefix to be stripped from all values to generate value nicknames, to specify the common prefix to be stripped from all values to generate value nicknames,
respectively. The "lowercase_name" option can be used to specify the word separation used respectively. The "underscore_name" option can be used to specify the underscorized name
in the *_get_type() function. For instance, /*< lowercase_name=gnome_vfs_uri_hide_options >*/. variant used in the *_get_type() function and *_TYPE_* macro. For instance,
/*< underscore_name=gnome_vfs_uri_hide_options >*/.
.PP .PP
Per value definition, the options "skip" and "nick" are supported. The former causes the Per value definition, the options "skip" and "nick" are supported. The former causes the
value to be skipped, and the latter can be used to specify the otherwise auto-generated value to be skipped, and the latter can be used to specify the otherwise auto-generated
......
...@@ -3,8 +3,14 @@ ...@@ -3,8 +3,14 @@
# glib-mkenums.pl # glib-mkenums.pl
# Information about the current enumeration # Information about the current enumeration
my $flags; # Is enumeration a bitmask? my $flags; # Is enumeration a bitmask?
my $option_lowercase_name; # A lower case name to use as part of the *_get_type() function, instead of the one that we guess. my $option_underscore_name; # Overriden underscore variant of the enum name
# For instance, when an enum uses abnormal capitalization and we can not guess where to put the underscores. # for example to fix the cases we don't get the
# mixed-case -> underscorized transform right.
my $option_lowercase_name; # DEPRECATED. A lower case name to use as part
# of the *_get_type() function, instead of the
# one that we guess. For instance, when an enum
# uses abnormal capitalization and we can not
# guess where to put the underscores.
my $seenbitshift; # Have we seen bitshift operators? my $seenbitshift; # Have we seen bitshift operators?
my $enum_prefix; # Prefix for this enumeration my $enum_prefix; # Prefix for this enumeration
my $enumname; # Name for this enumeration my $enumname; # Name for this enumeration
...@@ -184,8 +190,7 @@ sub read_template_file { ...@@ -184,8 +190,7 @@ sub read_template_file {
elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) {
$in = 'junk'; $in = 'junk';
next; next;
} } else {
else {
die "Malformed template file $file\n"; die "Malformed template file $file\n";
} }
} }
...@@ -274,11 +279,21 @@ while (<>) { ...@@ -274,11 +279,21 @@ while (<>) {
next if defined $options{skip}; next if defined $options{skip};
$enum_prefix = $options{prefix}; $enum_prefix = $options{prefix};
$flags = $options{flags}; $flags = $options{flags};
$option_lowercase_name = $options{lowercase_name}; $option_lowercase_name = $options{lowercase_name};
$option_underscore_name = $options{underscore_name};
} else { } else {
$enum_prefix = undef; $enum_prefix = undef;
$flags = undef; $flags = undef;
$option_lowercase_name = undef; $option_lowercase_name = undef;
$option_underscore_name = undef;
}
if (defined $option_lowercase_name) {
if (defined $option_underscore_name) {
print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n";
$option_lowercase_name = undef;
} else {
print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n";
}
} }
# Didn't have trailing '{' look on next lines # Didn't have trailing '{' look on next lines
if (!defined $1 && !defined $4) { if (!defined $1 && !defined $4) {
...@@ -340,24 +355,29 @@ while (<>) { ...@@ -340,24 +355,29 @@ while (<>) {
# Spit out the output # Spit out the output
if (defined $option_underscore_name) {
# enumname is e.g. GMatchType $enumlong = uc $option_underscore_name;
$enspace = $enumname; $enumsym = lc $option_underscore_name;
$enspace =~ s/^([A-Z][a-z]*).*$/$1/; $enumshort = $enumlong;
$enumshort =~ s/^[A-Z][A-Z0-9]*_//;
$enumshort = $enumname; } else {
$enumshort =~ s/^[A-Z][a-z]*//; # enumname is e.g. GMatchType
$enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; $enspace = $enumname;
$enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; $enspace =~ s/^([A-Z][a-z]*).*$/$1/;
$enumshort = uc($enumshort);
$enumshort = $enumname;
$enumlong = uc($enspace) . "_" . $enumshort; $enumshort =~ s/^[A-Z][a-z]*//;
$enumsym = lc($enspace) . "_" . lc($enumshort); $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g;
$enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
#The options might override the lower case name if it could not be generated correctly: $enumshort = uc($enumshort);
if (defined($option_lowercase_name)) {
$enumsym = $option_lowercase_name; $enumlong = uc($enspace) . "_" . $enumshort;
} $enumsym = lc($enspace) . "_" . lc($enumshort);
if (defined($option_lowercase_name)) {
$enumsym = $option_lowercase_name;
}
}
if ($firstenum) { if ($firstenum) {
$firstenum = 0; $firstenum = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment