From a821e2c40e2425a69bcba652546c15806c2b93ec Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 15 Oct 2002 22:26:39 +0000 Subject: [PATCH] Support for template files. --- gobject/ChangeLog | 6 ++++++ gobject/glib-mkenums.1 | 16 ++++++++++++++- gobject/glib-mkenums.in | 52 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/gobject/ChangeLog b/gobject/ChangeLog index d31dd81..4c8bdc9 100644 --- a/gobject/ChangeLog +++ b/gobject/ChangeLog @@ -1,3 +1,9 @@ +2002-10-16 Matthias Clasen + + * glib-mkenums.in: Support for template files. + + * glib-mkenums.1: Document --template. + 2002-10-15 Matthias Clasen * gtype.c (g_type_interface_prerequisites): New function to obtain diff --git a/gobject/glib-mkenums.1 b/gobject/glib-mkenums.1 index df0d22a..46c6caf 100644 --- a/gobject/glib-mkenums.1 +++ b/gobject/glib-mkenums.1 @@ -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 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 diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in index 2f8bb05..ec2575f 100755 --- a/gobject/glib-mkenums.in +++ b/gobject/glib-mkenums.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 value text, produced for each enum value\n"; print STDERR " --vtail value tail, produced after iterating over enum values\n"; print STDERR " --comments 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 () { + 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; -- 2.7.4