bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] maint.mk: change semantics/name of tight_scope variables


From: Jim Meyering
Subject: [PATCH] maint.mk: change semantics/name of tight_scope variables
Date: Mon, 09 May 2011 19:31:13 +0200

Feedback welcome.

In using this in iwhd, I decided to extend
the variable-matching code, and the easiest way
was to allow for /default_regexp/ || /custom_regexp/.
Since each has a single (...) match, it "just works".
I'm sure I could use some fancy new regexp capability
that's only available in perl-5.12, but this is simple
and allows for easy -- and more maintainable imho -- extension.

See the comment for an example.

>From 91fd934273607a4a395917d5230bd8dd5c866d94 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 9 May 2011 19:28:11 +0200
Subject: [PATCH] maint.mk: change semantics/name of tight_scope variables

* top/maint.mk (_gl_TS_var_match, _gl_TS_function_match):
Rename variables to align with semantics that make them more useful.
---
 ChangeLog    |    4 ++++
 top/maint.mk |   19 ++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 22442c5..be6516f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-05-09  Jim Meyering  <address@hidden>

+       maint.mk: change semantics/name of tight_scope variables
+       * top/maint.mk (_gl_TS_var_match, _gl_TS_function_match):
+       Rename variables to align with semantics that make them more useful.
+
        maint.mk: tweak new rule's name not to impinge
        * top/maint.mk (_gl_tight_scope): Rename from sc_tight_scope-0.
        (sc_tight_scope): Use new rule name rather than address@hidden
diff --git a/top/maint.mk b/top/maint.mk
index 6e810ba..346fe00 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1351,13 +1351,22 @@ ifeq (a,b)
 # and `usage' are exceptions: they're always extern, but
 # do not need to be marked.
 _gl_TS_unmarked_extern_functions ?= main usage
-_gl_TS_function_regex ?= \
-  ^(?:extern|XTERN) +(?:void|(?:struct |const |enum )?\S+) +\**(\S+) +\(
+_gl_TS_function_match ?= \
+  /^(?:extern|XTERN) +(?:void|(?:struct |const |enum )?\S+) +\**(\S+) +\(/

 # The second nm|grep checks for file-scope variables with `extern' scope.
 # Without gnulib's progname module, you might put program_name here.
 _gl_TS_unmarked_extern_vars ?=
-_gl_TS_var_regex ?= ^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?;
+
+# NOTE: the _match variables are perl expressions -- not mere regular
+# expressions -- so that you can extend them to match other patterns
+# and easily extract matched variable names.
+# For example, if your project declares some global variables via
+# a macro like this: GLOBAL(type, var_name, initializer), then you
+# can override this definition to automatically extract those names:
+# export _gl_TS_var_match = \
+#   /^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
+_gl_TS_var_match ?= /^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?;/
 .PHONY: _gl_tight_scope
 _gl_tight_scope: $(bin_PROGRAMS)
        t=exceptions-$$$$;                                              \
@@ -1372,14 +1381,14 @@ _gl_tight_scope: $(bin_PROGRAMS)
        ( printf '^%s$$\n' $(_gl_TS_unmarked_extern_functions);         \
          grep -h -A1 '^extern .*[^;]$$' $$src                          \
            | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
-         perl -lne '/$(_gl_TS_function_regex)/'                        \
+         perl -lne '$(_gl_TS_function_match)'                          \
                  -e 'and print $$1' $$hdr;                             \
        ) | sort -u | sed 's/^/^/;s/$$/$$/' > $$t;                      \
        nm -e *.$(OBJEXT) | sed -n 's/.* T //p' | grep -Ev -f $$t       \
          && { echo the above functions should have static scope >&2;   \
               exit 1; } || : ;                                         \
        ( printf '^%s$$\n' $(_gl_TS_unmarked_extern_vars);              \
-         perl -lne '/$(_gl_TS_var_regex)/ and print "^$$1\$$"'         \
+         perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"'           \
            $$hdr *.h ) | sort -u > $$t;                                \
        nm -e *.$(OBJEXT) | sed -n 's/.* [BCDGRS] //p'                  \
             | sort -u | grep -Ev -f $$t                                        
\
--
1.7.5.1.354.g761178



reply via email to

[Prev in Thread] Current Thread [Next in Thread]