OK, automatic documentation extraction from macros is fully working.

This commit is contained in:
Eric S. Raymond 2007-04-17 03:31:37 +00:00
parent 2848838cf5
commit 364e9da699
5 changed files with 34 additions and 15 deletions

View file

@ -18,7 +18,7 @@
#-----------------------------------------------------------------
# forest/pine<->Castle|Encampment special cases, also used by some other
# terrain
# Macro's moved to terrain-graphics/forestcastle.cfg
# Macros moved to terrain-graphics/forestcastle.cfg
#-----------------------------------------------------------------
{FORESTADJCASTLEA Ff (C*,K*,_K,Xu,Ql,Qxu,Rf*) 100 forest/pine-castle}

View file

@ -1,7 +1,7 @@
# Recipes for various sanity checks.
#
# Hack this if our location in the Wesnoth source tree changes
TOPDIR = ../..
TOPDIR = ../../
# References to terrain graphics go through so many layers of nasty
# opaque macros that trying to reference-check them is hopeless.
# So suppress reporting them unused even if they seem to have
@ -36,6 +36,6 @@ definitions:
macro-reference.xhtml:
@cat helpheader.xhtml >macro-reference.xhtml
@./macroscope --extracthelp --exclude data/scenarios --exclude data/campaigns $(EXCLUDE) $(TOPDIR) >>macro-reference.xhtml
@./macroscope --extracthelp --exclude data/scenarios --exclude data/tutorial --exclude data/campaigns $(EXCLUDE) $(TOPDIR) >>macro-reference.xhtml
@cat helptrailer.xhtml >>macro-reference.xhtml

View file

@ -8,8 +8,12 @@
<link rev="made" href="mailto:esr@snark.thyrsus.com" />
<style type="text/css">
/*<![CDATA[*/
.listing {font-family:monospace;}
.bold {font-style:bold;}
.file_header: {font-style:normal; font-weight:bold;}
.file_explanation {font-style:normal; font-weight:bold;}
.macro_name {font-style:normal; font-weight:bold;}
.macro_formals {font-style:italic; font-weight:normal;}
.macro_explanation {font-style:normal; font-weight:normal;}
.listing {font-style:normal; font-family:monospace;}
/*]]>*/
</style>
</head>

View file

@ -46,10 +46,10 @@ def htmlize(line):
"HTML-escape a text line"
return line.replace("<", "&lt;").replace(">", "&gt;").replace("&", "&amp;")
def interpret(lines):
def interpret(lines, css):
"Interpret the ! convention for .cfg comments."
inlisting = False
outstr = "<p>"
outstr = '<p class="%s">' % css
for line in lines:
line = line.rstrip()
if not inlisting and not line:
@ -290,10 +290,10 @@ class CrossRef:
nrefs = len(defloc.references)
if nrefs:
print name
def extracthelp(self, fp):
def extracthelp(self, pref, fp):
"Deliver all macro help comments in HTML form."
doclist = self.xref.keys()
doclist = filter(lambda x: self.xref[x].docstring, doclist)
doclist = filter(lambda x: self.xref[x].docstring.count("\n") > 1, doclist)
doclist.sort(lambda x, y: cmp(self.xref[x], self.xref[y]))
outstr = ""
filename = None
@ -305,7 +305,11 @@ class CrossRef:
outstr += "</dl>\n"
counted += 1
filename = entry.filename
outstr += "<h1>From file: " + filename + "</h1>\n"
if filename.startswith(pref):
displayname = filename[len(pref):]
else:
displayname = filename
outstr += "<h1 class='file_header'>From file: " + displayname + "</h1>\n"
hdr = []
dfp = open(filename)
for line in dfp:
@ -315,7 +319,7 @@ class CrossRef:
break
dfp.close()
if hdr:
outstr += interpret(hdr)
outstr += interpret(hdr, "file_explanation")
outstr += "<dl>\n"
if entry.docstring:
lines = entry.docstring.split("\n")
@ -325,12 +329,12 @@ class CrossRef:
if not lines: # Ignore definitions without a docstring
continue
outstr += "\n<dt>\n"
outstr += "<emphasis role='bold'>" + header[0] + "</emphasis>"
outstr += "<em class='macro_name'>" + header[0] + "</em>"
if header[1:]:
outstr += " <emphasis>"+" ".join(header[1:])+"</emphasis>"
outstr += " <em class='macro_formals'>"+" ".join(header[1:])+"</em>"
outstr += "\n</dt>\n"
outstr += "<dd>\n"
outstr += interpret(lines)
outstr += interpret(lines, "macro_explanation")
outstr += "</dd>\n"
outstr += "</dl>\n"
fp.write(outstr)
@ -402,7 +406,7 @@ Usage: macroscope [options] dirpath
filelist = allfiles(dirpath, "|".join(exclude))
xref = CrossRef(filelist)
if extracthelp:
xref.extracthelp(sys.stdout)
xref.extracthelp(dirpath[0], sys.stdout)
elif listfiles:
for filename in filelist:
print filename

View file

@ -1,6 +1,9 @@
# Traits for the [modifications] clause of SingleWML descriptions
#textdomain wesnoth
#define TRAIT_LOYAL
# Units with trait Loyal have no upkeep.
[trait]
id=loyal
male_name= _ "loyal"
@ -13,6 +16,7 @@
#enddef
#define TRAIT_UNDEAD
# Units with trait Undead cannot be poisoned.
[trait]
id=undead
male_name= _ "undead"
@ -22,6 +26,7 @@
#enddef
#define TRAIT_STRONG
# Units with trait Strong get a +1 increment in hitpoints and melee damage.
[trait]
id=strong
male_name= _ "strong"
@ -39,6 +44,7 @@
#enddef
#define TRAIT_DEXTROUS
# Units with trait Dextrous get a +1 to ranged damage.
[trait]
id=dextrous
male_name= _ "dextrous"
@ -52,6 +58,7 @@
#enddef
#define TRAIT_QUICK
# Units with trait Quick have +1 movement.
[trait]
id=quick
male_name= _ "quick"
@ -68,6 +75,7 @@
#enddef
#define TRAIT_INTELLIGENT
# Units with trait Intelligent get a 20% decrease in XP required to advance.
[trait]
id=intelligent
male_name= _ "intelligent"
@ -80,6 +88,7 @@
#enddef
#define TRAIT_RESILIENT
# Units with trait Resilient get 10% more HP plus 3.
[trait]
id=resilient
male_name= _ "resilient"
@ -96,6 +105,7 @@
#enddef
#define TRAIT_HEALTHY
# Units with trait Healthy heal at 3HP per turn.
[trait]
id=healthy
male_name= _ "healthy"
@ -109,6 +119,7 @@
#enddef
#define TRAIT_FEARLESS
# Units with trait Fearless fight normally during unfavorable day/night times.
[trait]
id=fearless
male_name= _ "fearless"