Support for template files.

This commit is contained in:
Matthias Clasen 2002-10-15 22:26:39 +00:00
parent d1f37d5053
commit a821e2c40e
3 changed files with 70 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2002-10-16 Matthias Clasen <maclas@gmx.de>
* glib-mkenums.in: Support for template files.
* glib-mkenums.1: Document --template.
2002-10-15 Matthias Clasen <maclas@gmx.de>
* gtype.c (g_type_interface_prerequisites): New function to obtain

View File

@ -1,4 +1,4 @@
.TH GLIB-MKENUMS 1 "20 Apr 2001"
.TH GLIB-MKENUMS 1 "27 Jul 2002"
.SH NAME
glib-mkenums \- C language enum description generation utility
.SH SYNOPSIS
@ -45,6 +45,20 @@ Put out <text> after iterating over all values of an enum.
Template for auto-generated comments, the default (for C code generations) is
"/* @comment@ */".
.TP
\fI--template file
Read templates from the given file. The templates are enclosed in
specially-formatted C comments
.PP
.RS
.nf
/*** BEGIN section ***/
/*** END section ***/
.fi
.PP
where section may be file-header, file-production, file-tail,
enumeration-production, value-header, value-production, value-tail or
comment.
.TP
\fI-h, --help\fP
Print brief help and exit.
.TP

View File

@ -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;