Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0eea1663
Commit
0eea1663
authored
Feb 13, 2001
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapted unweave to Matthias' fixes. It's still off-by-one-space in some cases.
parent
54019966
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
15 deletions
+53
-15
Mac/scripts/unweave.py
Mac/scripts/unweave.py
+53
-15
No files found.
Mac/scripts/unweave.py
View file @
0eea1663
...
@@ -11,8 +11,17 @@ BEGINDEFINITION=re.compile("^<<(?P<name>.*)>>=\s*")
...
@@ -11,8 +11,17 @@ 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("
^@
")
DEFAULT_CONFIG="""
config = [
("
^
.
*
\
.
cp
$
", "
:
unweave
-
src
"),
("
^
.
*
\
.
h
$
", "
:
unweave
-
include
"),
]
genlinedirectives = 0
gencomments = 1
"""
class Processor:
class Processor:
def __init__(self, filename):
def __init__(self, filename
, config={}
):
self.items = {}
self.items = {}
self.filename = filename
self.filename = filename
self.fp = open(filename)
self.fp = open(filename)
...
@@ -20,6 +29,15 @@ class Processor:
...
@@ -20,6 +29,15 @@ class Processor:
self.resolving = {}
self.resolving = {}
self.resolved = {}
self.resolved = {}
self.pushback = None
self.pushback = None
# Options
if config.has_key("
genlinedirectives
"):
self.genlinedirectives = config["
genlinedirectives
"]
else:
self.genlinedirectives = 1
if config.has_key("
gencomments
"):
self.gencomments = config["
gencomments
"]
else:
self.gencomments = 0
def _readline(self):
def _readline(self):
"""Read a line. Allow for pushback"""
"""Read a line. Allow for pushback"""
...
@@ -50,10 +68,9 @@ class Processor:
...
@@ -50,10 +68,9 @@ class Processor:
if mo:
if mo:
pre = mo.group('pre')
pre = mo.group('pre')
if pre:
if pre:
rv.append((lineno, pre+'
\
n
'))
## rv.append((lineno, pre+'
\
n
'))
rv.append((lineno, pre))
rv.append((lineno, line))
rv.append((lineno, line))
# For simplicity we add #line directives now, if
# needed.
if mo:
if mo:
post = mo.group('post')
post = mo.group('post')
if post and post != '
\
n
':
if post and post != '
\
n
':
...
@@ -69,6 +86,7 @@ class Processor:
...
@@ -69,6 +86,7 @@ class Processor:
def read(self):
def read(self):
"""Read the source file and store all definitions"""
"""Read the source file and store all definitions"""
savedcomment = []
while 1:
while 1:
lineno, line = self._readline()
lineno, line = self._readline()
if not line: break
if not line: break
...
@@ -76,10 +94,33 @@ class Processor:
...
@@ -76,10 +94,33 @@ class Processor:
if mo:
if mo:
name = mo.group('name')
name = mo.group('name')
value = self._readitem()
value = self._readitem()
if self.gencomments:
defline = [(lineno, '// <%s>=
\
n
'%name)]
if savedcomment:
savedcomment = savedcomment + [(lineno, '//
\
n
')] + defline
else:
savedcomment = defline
savedcomment = self._extendlines(savedcomment)
value = savedcomment + value
savedcomment = []
self._define(name, value)
self._define(name, value)
else:
else:
pass # We could output the TeX code but we don't bother.
if self.gencomments:
# It seems initial blank lines are ignored:-(
if savedcomment or line.strip():
savedcomment.append((lineno, '// '+line))
def _extendlines(self, comment):
# This routine mimicks some artefact of Matthias' code.
rv = []
for lineno, line in comment:
line = line[:-1]
if len(line) < 75:
line = line + (75-len(line))*' '
line = line + '
\
n
'
rv.append((lineno, 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():
...
@@ -134,7 +175,7 @@ class Processor:
...
@@ -134,7 +175,7 @@ class Processor:
rv = []
rv = []
for lineno, line in data:
for lineno, line in data:
curlineno = curlineno + 1
curlineno = curlineno + 1
if line and line != '
\
n
' and lineno != curlineno:
if
self.genlinedirectives and
line and line != '
\
n
' and lineno != curlineno:
rv.append(self._linedirective(lineno))
rv.append(self._linedirective(lineno))
curlineno = lineno
curlineno = lineno
rv.append(line)
rv.append(line)
...
@@ -150,27 +191,24 @@ class Processor:
...
@@ -150,27 +191,24 @@ class Processor:
fp = open(pathname, "
w
").writelines(data)
fp = open(pathname, "
w
").writelines(data)
def process(file, config):
def process(file, config):
pr = Processor(file)
pr = Processor(file
, config
)
pr.read()
pr.read()
pr.resolve()
pr.resolve()
for pattern, folder in config:
for pattern, folder in config
['config']
:
pr.save(folder, pattern)
pr.save(folder, pattern)
def readconfig():
def readconfig():
"""Read a configuration file, if it doesn't exist create it."""
"""Read a configuration file, if it doesn't exist create it."""
configname = sys.argv[0] + '.config'
configname = sys.argv[0] + '.config'
if not os.path.exists(configname):
if not os.path.exists(configname):
confstr = """config = [
confstr = DEFAULT_CONFIG
("
^
.
*
\
.
cp
$
", "
:
unweave
-
src
"),
("
^
.
*
\
.
h
$
", "
:
unweave
-
include
"),
]"""
open(configname, "
w
").write(confstr)
open(configname, "
w
").write(confstr)
print "
Created
config
file
", configname
print "
Created
config
file
", configname
## print "
Please
check
and
adapt
(
if
needed
)
"
## print "
Please
check
and
adapt
(
if
needed
)
"
## sys.exit(0)
## sys.exit(0)
namespace = {}
namespace = {}
execfile(configname, namespace)
execfile(configname, namespace)
return namespace
['config']
return namespace
def main():
def main():
config = readconfig()
config = readconfig()
...
@@ -185,7 +223,7 @@ def main():
...
@@ -185,7 +223,7 @@ def main():
fss, ok = macfs.PromptGetFile("
Select
.
nw
source
file
", "
TEXT
")
fss, ok = macfs.PromptGetFile("
Select
.
nw
source
file
", "
TEXT
")
if not ok:
if not ok:
sys.exit(0)
sys.exit(0)
process(fss.as_pathname())
process(fss.as_pathname()
, config
)
if __name__ == "
__main__
":
if __name__ == "
__main__
":
main()
main()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment