From 0d43b366156d823a6ff41234275801f60d418ae3 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 14 Oct 2008 22:30:21 +0000 Subject: [PATCH] Teach wmlscope to selectively ignore multiple macro definitions. --- data/core/macros/carryover-utils.cfg | 4 ++++ data/tools/wesnoth/wmltools.py | 13 ++++++++++++- data/tools/wmlscope | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/data/core/macros/carryover-utils.cfg b/data/core/macros/carryover-utils.cfg index bafd94b661f..b0856d74df5 100644 --- a/data/core/macros/carryover-utils.cfg +++ b/data/core/macros/carryover-utils.cfg @@ -61,3 +61,7 @@ #enddef # wmlscope: stop ignoring #endif + +# wmlscope: prune NEW_GOLD_CARRYOVER +# wmlscope: prune NEW_GOLD_CARRYOVER_NOTE_20 +# wmlscope: prune NEW_GOLD_CARRYOVER_NOTE_40 diff --git a/data/tools/wesnoth/wmltools.py b/data/tools/wesnoth/wmltools.py index 82134249ae4..2069d78bd6d 100644 --- a/data/tools/wesnoth/wmltools.py +++ b/data/tools/wesnoth/wmltools.py @@ -266,7 +266,7 @@ class CrossRef: try: pattern = re.compile(os.sep + pattern + "$") except sre_constants.error: - print >>sys.stderr, "macroscope: confused by %s" % pattern + print >>sys.stderr, "wmlscope: confused by %s" % pattern return None key = None for trial in self.fileref: @@ -337,6 +337,17 @@ class CrossRef: if namespace not in self.properties: self.properties[namespace] = {} self.properties[namespace][prop] = value + m = re.search("# *wmlscope: prune (.*)", line) + if m: + name = m.group(1) + if warnlevel >= 2: + print '"%s", line %d: pruning definitions of %s' \ + % (filename, n+1, name ) + if name not in self.xref: + print >>sys.stderr, "wmlscope: can't prune undefined macro %s" % name + else: + self.xref[name] = self.xref[name][:1] + continue if "# wmlscope: start ignoring" in line: if warnlevel > 1: print '"%s", line %d: starting ignoring' \ diff --git a/data/tools/wmlscope b/data/tools/wmlscope index a5677d5eb11..b3c79167daf 100755 --- a/data/tools/wmlscope +++ b/data/tools/wmlscope @@ -42,6 +42,14 @@ # a name generated from the attack name. This behavior can be suppressed # by adding a magic comment containing the string "no-icon" to the name= line. # +# The collowing magic comment: +# +# # prune FOOBAR +# +# will cause wmlscope to forget about all but one of the definitions of FOOBAR +# it has seen. This will be useful mainly for symbols that have different +# definitions enabled by an #ifdef. +# # The checking done by this tool has a couple of flaws: # # (1) It doesn't actually evaluate file inclusions. Instead, any