Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Refactoring code #5
Browse files Browse the repository at this point in the history
  • Loading branch information
pixiupl committed Jan 15, 2018
1 parent 3dea9d9 commit a81a38f
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions tools/unamalgam.py
Expand Up @@ -6,8 +6,8 @@
cur_src = None
in_mod = False
ofile = None

strip_re = re.compile(r'/\* Amalgamated: (.*) \*/')

def clean(l):
return strip_re.sub(r'\1', l)

Expand All @@ -19,25 +19,17 @@ def clean(l):
l = next(f)
g = re.match(r'#line [01] "(.*)"', l)
cur_src = g.group(1)

# if there is currently opened file, close it
if ofile:
ofile.close()

ofile.close()
cur_src = re.sub(r'\.\./', '', cur_src)

# create directory for the next file if needed
cur_src_dir = os.path.dirname(cur_src)
if cur_src_dir != '' and not os.path.exists(cur_src_dir):
os.makedirs(cur_src_dir)

# open next file for writing
os.makedirs(cur_src_dir)
ofile = open(cur_src, "w")
print >>sys.stderr, '=> %s' % cur_src
manifest.append(cur_src)
next(f)
elif ofile:
ofile.write(clean(l))

m = open('%s.manifest' % os.path.basename(fname), 'w')
print >>m, '\n'.join(manifest)

0 comments on commit a81a38f

Please sign in to comment.