Commit af3e11d0 authored by Jack Jansen's avatar Jack Jansen

More modifications to bring the script output in line with the real thing.

parent 78182d27
...@@ -10,9 +10,10 @@ import macostools ...@@ -10,9 +10,10 @@ import macostools
BEGINDEFINITION=re.compile("^<<(?P<name>.*)>>=\s*") BEGINDEFINITION=re.compile("^<<(?P<name>.*)>>=\s*")
USEDEFINITION=re.compile("^(?P<pre>.*)<<(?P<name>.*)>>(?P<post>[^=].*)") USEDEFINITION=re.compile("^(?P<pre>.*)<<(?P<name>.*)>>(?P<post>[^=].*)")
ENDDEFINITION=re.compile("^@") ENDDEFINITION=re.compile("^@")
GREMLINS=re.compile("[\xa0\xca]")
DEFAULT_CONFIG=""" DEFAULT_CONFIG="""
config = [ filepatterns = [
("^.*\.cp$", ":unweave-src"), ("^.*\.cp$", ":unweave-src"),
("^.*\.h$", ":unweave-include"), ("^.*\.h$", ":unweave-include"),
] ]
...@@ -38,6 +39,13 @@ class Processor: ...@@ -38,6 +39,13 @@ class Processor:
self.gencomments = config["gencomments"] self.gencomments = config["gencomments"]
else: else:
self.gencomments = 0 self.gencomments = 0
if config.has_key("filepatterns"):
self.filepatterns = config["filepatterns"]
else:
self.filepatterns = []
self.filepattern_relist = []
for pat, dummy in self.filepatterns:
self.filepattern_relist.append(re.compile(pat))
def _readline(self): def _readline(self):
"""Read a line. Allow for pushback""" """Read a line. Allow for pushback"""
...@@ -100,9 +108,16 @@ class Processor: ...@@ -100,9 +108,16 @@ class Processor:
savedcomment = savedcomment + [(lineno, '//\n')] + defline savedcomment = savedcomment + [(lineno, '//\n')] + defline
else: else:
savedcomment = defline savedcomment = defline
savedcomment = self._extendlines(savedcomment) savedcomment = self._processcomment(savedcomment)
value = savedcomment + value value = savedcomment + value
savedcomment = [] savedcomment = []
isfilepattern = 0
for rexp in self.filepattern_relist:
if rexp.search(name):
isfilepattern = 1
break
if 0 and not isfilepattern:
value = self._addspace(value)
self._define(name, value) self._define(name, value)
else: else:
if self.gencomments: if self.gencomments:
...@@ -110,17 +125,25 @@ class Processor: ...@@ -110,17 +125,25 @@ class Processor:
if savedcomment or line.strip(): if savedcomment or line.strip():
savedcomment.append((lineno, '// '+line)) savedcomment.append((lineno, '// '+line))
def _extendlines(self, comment): def _processcomment(self, comment):
# This routine mimicks some artefact of Matthias' code. # This routine mimicks some artefact of Matthias' code.
rv = [] rv = []
for lineno, line in comment: for lineno, line in comment:
line = line[:-1] line = line[:-1]
line = GREMLINS.subn(' ', line)[0]
if len(line) < 75: if len(line) < 75:
line = line + (75-len(line))*' ' line = line + (75-len(line))*' '
line = line + '\n' line = line + '\n'
rv.append((lineno, line)) rv.append((lineno, line))
return rv return rv
def _addspace(self, value, howmany):
# Yet another routine to mimick yet another artefact
rv = value[0:1]
for lineno, line in value[1:]:
rv.append((lineno, (' '*howmany)+line))
return rv
def resolve(self): def resolve(self):
"""Resolve all references""" """Resolve all references"""
for name in self.items.keys(): for name in self.items.keys():
...@@ -141,15 +164,22 @@ class Processor: ...@@ -141,15 +164,22 @@ class Processor:
# No rest for the wicked: we have work to do. # No rest for the wicked: we have work to do.
self.resolving[name] = 1 self.resolving[name] = 1
result = [] result = []
lastlineincomplete = 0
for lineno, line in self.items[name]: for lineno, line in self.items[name]:
mo = USEDEFINITION.search(line) mo = USEDEFINITION.search(line)
if mo: if mo:
# We replace the complete line. Is this correct? # We replace the complete line. Is this correct?
macro = mo.group('name') macro = mo.group('name')
replacement = self._resolve_one(macro) replacement = self._resolve_one(macro)
if lastlineincomplete:
replacement = self._addspace(replacement, lastlineincomplete)
result = result + replacement result = result + replacement
else: else:
result.append((lineno, line)) result.append((lineno, line))
if line[-1] == '\n':
lastlineincomplete = 0
else:
lastlineincomplete = len(line)
self.items[name] = result self.items[name] = result
self.resolved[name] = 1 self.resolved[name] = 1
del self.resolving[name] del self.resolving[name]
...@@ -194,7 +224,7 @@ def process(file, config): ...@@ -194,7 +224,7 @@ def process(file, config):
pr = Processor(file, config) pr = Processor(file, config)
pr.read() pr.read()
pr.resolve() pr.resolve()
for pattern, folder in config['config']: for pattern, folder in config['filepatterns']:
pr.save(folder, pattern) pr.save(folder, pattern)
def readconfig(): def readconfig():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment