[glib] Add @basename@ substitution to glib-mkenums



commit 6d1474e7f1f6e964d8db377fe732b9273cf17a84
Author: Christian Persch <chpe gnome org>
Date:   Mon Jun 29 15:28:22 2009 +0200

    Add @basename@ substitution to glib-mkenums
    
    Since @filename@ contains the full filename as given to the glib-mkenum
    command, possibly including path elements (e.g. when using a non-srcdir
    build), it is unsuitable to use in a #include statement in the generated
    file if one wants to distribute it. This patch adds @basename@ which
    expands to the base name of the input filename. Bug #587307.

 gobject/glib-mkenums.1  |    3 +++
 gobject/glib-mkenums.in |    9 +++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/gobject/glib-mkenums.1 b/gobject/glib-mkenums.1
index 0837d08..cacddff 100644
--- a/gobject/glib-mkenums.1
+++ b/gobject/glib-mkenums.1
@@ -118,6 +118,9 @@ The same as \fI type@\fP with all letters uppercased (e.g. FLAGS).
 .TP 12
 \fI filename@
 The name of the input file currently being processed (e.g. foo.h).
+.TP 12
+\fI basename@
+The base name of the input file currently being processed (e.g. foo.h). (Since: 2.22)
 
 .SS Trigraph extensions
 Some C comments are treated specially in the parsed enum definitions, such comments
diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in
index 9bb5aa9..1e40622 100755
--- a/gobject/glib-mkenums.in
+++ b/gobject/glib-mkenums.in
@@ -1,5 +1,7 @@
 #! PERL_PATH@ -w
 
+use File::Basename;
+
 # glib-mkenums.pl 
 # Information about the current enumeration
 my $flags;			# Is enumeration a bitmask?
@@ -160,6 +162,7 @@ sub usage {
     print "  \ Type\@                either Enum or Flags\n";
     print "  \ TYPE\@                either ENUM or FLAGS\n";
     print "  \ filename\@            name of current input file\n";
+    print "  \ basename\@            base name of the current input file (Since: 2.22)\n";
     exit 0;
 }
 
@@ -247,8 +250,10 @@ while ($_=$ARGV[0],/^-/) {
 
 if (length($fhead)) {
     my $prod = $fhead;
+    my $base = basename ($ARGV[0]);
 
     $prod =~ s/\ filename\@/$ARGV[0]/g;
+    $prod =~ s/\ basename\@/$base/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;
     chomp ($prod);
@@ -397,8 +402,10 @@ while (<>) {
 	    
 	    if (length($fprod)) {
 		my $prod = $fprod;
+		my $base = basename ($ARGV);
 
 		$prod =~ s/\ filename\@/$ARGV/g;
+		$prod =~ s/\ basename\@/$base/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;
 	        chomp ($prod);
@@ -485,8 +492,10 @@ while (<>) {
 
 if (length($ftail)) {
     my $prod = $ftail;
+    my $base = basename ($ARGV);
 
     $prod =~ s/\ filename\@/$ARGV/g;
+    $prod =~ s/\ basename\@/$base/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;
     chomp ($prod);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]