mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-05 15:38:44 +02:00
Support for template files.
This commit is contained in:
@@ -113,7 +113,7 @@ sub parse_entries {
|
||||
}
|
||||
|
||||
sub version {
|
||||
print STDERR "glib-mkenums version glib-2.0\n"; # FIXME: autogen version?
|
||||
print STDERR "glib-mkenums version glib-@GLIB_VERSION@\n";
|
||||
print STDERR "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n";
|
||||
print STDERR "You may redistribute copies of glib-mkenums under the terms of\n";
|
||||
print STDERR "the GNU General Public License which can be found in the\n";
|
||||
@@ -131,6 +131,7 @@ sub usage {
|
||||
print STDERR " --vprod <text> value text, produced for each enum value\n";
|
||||
print STDERR " --vtail <text> value tail, produced after iterating over enum values\n";
|
||||
print STDERR " --comments <text> comment structure\n";
|
||||
print STDERR " --template file template file\n";
|
||||
print STDERR " -h, --help show this help message\n";
|
||||
print STDERR " -v, --version print version informations\n";
|
||||
print STDERR "Production text substitutions:\n";
|
||||
@@ -158,13 +159,58 @@ my $vtail = ""; # value tail, produced after iterating over enum values
|
||||
# other options
|
||||
my $comment_tmpl = "/* \@comment\@ */";
|
||||
|
||||
sub read_template_file {
|
||||
my ($file) = @_;
|
||||
my %tmpl = ('file-header', $fhead,
|
||||
'file-production', $fprod,
|
||||
'file-tail', $ftail,
|
||||
'enumeration-production', $eprod,
|
||||
'value-header', $vhead,
|
||||
'value-production', $vprod,
|
||||
'value-tail', $vtail,
|
||||
'comment', $comment_tmpl);
|
||||
my $in = 'junk';
|
||||
open (FILE, $file) || die "Can't open $file: $!\n";
|
||||
while (<FILE>) {
|
||||
if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) {
|
||||
if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) {
|
||||
$in = $2;
|
||||
next;
|
||||
}
|
||||
elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) {
|
||||
$in = 'junk';
|
||||
next;
|
||||
}
|
||||
else {
|
||||
die "Malformed template file $file\n";
|
||||
}
|
||||
}
|
||||
if (!($in eq 'junk')) {
|
||||
$tmpl{$in} .= $_;
|
||||
}
|
||||
}
|
||||
close (FILE);
|
||||
if (!($in eq 'junk')) {
|
||||
die "Malformed template file $file\n";
|
||||
}
|
||||
$fhead = $tmpl{'file-header'};
|
||||
$fprod = $tmpl{'file-production'};
|
||||
$ftail = $tmpl{'file-tail'};
|
||||
$eprod = $tmpl{'enumeration-production'};
|
||||
$vhead = $tmpl{'value-header'};
|
||||
$vprod = $tmpl{'value-production'};
|
||||
$vtail = $tmpl{'value-tail'};
|
||||
$comment_tmpl = $tmpl{'comment'};
|
||||
}
|
||||
|
||||
if (!defined $ARGV[0]) {
|
||||
usage;
|
||||
}
|
||||
while ($_ = $ARGV[0], /^-/) {
|
||||
shift;
|
||||
last if /^--$/;
|
||||
if (/^--fhead$/) { $fhead = $fhead . shift }
|
||||
if (/^--template$/) { read_template_file (shift); }
|
||||
elsif (/^--fhead$/) { $fhead = $fhead . shift }
|
||||
elsif (/^--fprod$/) { $fprod = $fprod . shift }
|
||||
elsif (/^--ftail$/) { $ftail = $ftail . shift }
|
||||
elsif (/^--eprod$/) { $eprod = $eprod . shift }
|
||||
@@ -187,7 +233,7 @@ while ($_ = $ARGV[0], /^-/) {
|
||||
if (length($fhead)) {
|
||||
my $prod = $fhead;
|
||||
|
||||
$prod =~ s/\@filename\@/$ARGV/g;
|
||||
$prod =~ s/\@filename\@/$ARGV[0]/g;
|
||||
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
||||
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
||||
|
||||
|
Reference in New Issue
Block a user