mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 08:28:53 +02:00
glib-mkenums: add --identifier-prefix and --symbol-prefix args
Allow passing --identifier-prefix and --symbol-prefix to glib-mkenums, with the same meanings as in g-ir-scanner, to allow fixing up the enum name parsing globally rather than needing to add a /<* *>/ override to each enum. https://bugzilla.gnome.org/show_bug.cgi?id=661797
This commit is contained in:
@@ -117,6 +117,30 @@ where section may be <literal>file-header</literal>,
|
|||||||
</para></listitem>
|
</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--identifier-prefix</option> <replaceable>prefix</replaceable></term>
|
||||||
|
<listitem><para>
|
||||||
|
Indicates what portion of the enum name should be intepreted as the
|
||||||
|
prefix (eg, the "<literal>Gtk</literal>" in
|
||||||
|
"<literal>GtkDirectionType</literal>"). Normally this will be figured
|
||||||
|
out automatically, but you may need to override the default if your
|
||||||
|
namespace is capitalized oddly.
|
||||||
|
</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--symbol-prefix</option> <replaceable>prefix</replaceable></term>
|
||||||
|
<listitem><para>
|
||||||
|
Indicates what prefix should be used to correspond to the identifier
|
||||||
|
prefix in related C function names (eg, the "<literal>gtk</literal>"
|
||||||
|
in "<literal>gtk_direction_type_get_type</literal>". Equivalently,
|
||||||
|
this is the lowercase version of the prefix component of the enum
|
||||||
|
value names (eg, the "<literal>GTK</literal>" in
|
||||||
|
"<literal>GTK_DIR_UP</literal>". The default value is the identifier
|
||||||
|
prefix, converted to lowercase.
|
||||||
|
</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>--help</option></term>
|
<term><option>--help</option></term>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
|
@@ -143,16 +143,18 @@ sub usage {
|
|||||||
print "Help Options:\n";
|
print "Help Options:\n";
|
||||||
print " -h, --help Show this help message\n\n";
|
print " -h, --help Show this help message\n\n";
|
||||||
print "Utility Options:\n";
|
print "Utility Options:\n";
|
||||||
print " --fhead <text> Output file header\n";
|
print " --identifier-prefix <text> Identifier prefix\n";
|
||||||
print " --fprod <text> Per input file production\n";
|
print " --symbol-prefix <text> Symbol prefix\n";
|
||||||
print " --ftail <text> Output file trailer\n";
|
print " --fhead <text> Output file header\n";
|
||||||
print " --eprod <text> Per enum text (produced prior to value itarations)\n";
|
print " --fprod <text> Per input file production\n";
|
||||||
print " --vhead <text> Value header, produced before iterating over enum values\n";
|
print " --ftail <text> Output file trailer\n";
|
||||||
print " --vprod <text> Value text, produced for each enum value\n";
|
print " --eprod <text> Per enum text (produced prior to value itarations)\n";
|
||||||
print " --vtail <text> Value tail, produced after iterating over enum values\n";
|
print " --vhead <text> Value header, produced before iterating over enum values\n";
|
||||||
print " --comments <text> Comment structure\n";
|
print " --vprod <text> Value text, produced for each enum value\n";
|
||||||
print " --template file Template file\n";
|
print " --vtail <text> Value tail, produced after iterating over enum values\n";
|
||||||
print " -v, --version Print version informations\n\n";
|
print " --comments <text> Comment structure\n";
|
||||||
|
print " --template file Template file\n";
|
||||||
|
print " -v, --version Print version informations\n\n";
|
||||||
print "Production text substitutions:\n";
|
print "Production text substitutions:\n";
|
||||||
print " \@EnumName\@ PrefixTheXEnum\n";
|
print " \@EnumName\@ PrefixTheXEnum\n";
|
||||||
print " \@enum_name\@ prefix_the_xenum\n";
|
print " \@enum_name\@ prefix_the_xenum\n";
|
||||||
@@ -171,6 +173,8 @@ sub usage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# production variables:
|
# production variables:
|
||||||
|
my $idprefix = ""; # "G", "Gtk", etc
|
||||||
|
my $symprefix = ""; # "g", "gtk", etc, if not just lc($idprefix)
|
||||||
my $fhead = ""; # output file header
|
my $fhead = ""; # output file header
|
||||||
my $fprod = ""; # per input file production
|
my $fprod = ""; # per input file production
|
||||||
my $ftail = ""; # output file trailer
|
my $ftail = ""; # output file trailer
|
||||||
@@ -233,6 +237,8 @@ while ($_=$ARGV[0],/^-/) {
|
|||||||
shift;
|
shift;
|
||||||
last if /^--$/;
|
last if /^--$/;
|
||||||
if (/^--template$/) { read_template_file (shift); }
|
if (/^--template$/) { read_template_file (shift); }
|
||||||
|
elsif (/^--identifier-prefix$/) { $idprefix = shift }
|
||||||
|
elsif (/^--symbol-prefix$/) { $symprefix = shift }
|
||||||
elsif (/^--fhead$/) { $fhead = $fhead . shift }
|
elsif (/^--fhead$/) { $fhead = $fhead . shift }
|
||||||
elsif (/^--fprod$/) { $fprod = $fprod . shift }
|
elsif (/^--fprod$/) { $fprod = $fprod . shift }
|
||||||
elsif (/^--ftail$/) { $ftail = $ftail . shift }
|
elsif (/^--ftail$/) { $ftail = $ftail . shift }
|
||||||
@@ -380,7 +386,7 @@ while (<>) {
|
|||||||
|
|
||||||
$enumname_prefix = $enumlong;
|
$enumname_prefix = $enumlong;
|
||||||
$enumname_prefix =~ s/_$enumshort$//;
|
$enumname_prefix =~ s/_$enumshort$//;
|
||||||
} else {
|
} elsif (!$symprefix && !$idprefix) {
|
||||||
# enumname is e.g. GMatchType
|
# enumname is e.g. GMatchType
|
||||||
$enspace = $enumname;
|
$enspace = $enumname;
|
||||||
$enspace =~ s/^([A-Z][a-z]*).*$/$1/;
|
$enspace =~ s/^([A-Z][a-z]*).*$/$1/;
|
||||||
@@ -401,6 +407,21 @@ while (<>) {
|
|||||||
if (defined($option_lowercase_name)) {
|
if (defined($option_lowercase_name)) {
|
||||||
$enumsym = $option_lowercase_name;
|
$enumsym = $option_lowercase_name;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$enumshort = $enumname;
|
||||||
|
if ($idprefix) {
|
||||||
|
$enumshort =~ s/^${idprefix}//;
|
||||||
|
} else {
|
||||||
|
$enumshort =~ s/^[A-Z][a-z]*//;
|
||||||
|
}
|
||||||
|
$enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g;
|
||||||
|
$enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
|
||||||
|
$enumshort = uc($enumshort);
|
||||||
|
|
||||||
|
$enumname_prefix = $symprefix && uc($symprefix) || uc($idprefix);
|
||||||
|
|
||||||
|
$enumlong = $enumname_prefix . "_" . $enumshort;
|
||||||
|
$enumsym = lc($enumlong);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($firstenum) {
|
if ($firstenum) {
|
||||||
|
Reference in New Issue
Block a user