mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Convert amalgam.py to Python 3
No mongoose.{c,h} diffs PUBLISHED_FROM=a995a6d6548a914087969e28908f4e8c9ef1d379
This commit is contained in:
parent
ca11f5ab49
commit
e61f20f1ed
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Generate a reversible amalgamation of several C source files
|
||||
# along with their required internal headers.
|
||||
@ -32,10 +32,10 @@
|
||||
#
|
||||
|
||||
import argparse
|
||||
import io
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
from StringIO import StringIO
|
||||
|
||||
parser = argparse.ArgumentParser(description='Produce an amalgamated source')
|
||||
parser.add_argument('--prefix', default="NS",
|
||||
@ -65,11 +65,11 @@ class File(object):
|
||||
def __init__(self, name, parent_name):
|
||||
self.name = name
|
||||
self.parent_name = parent_name
|
||||
self.buf = StringIO()
|
||||
self.buf = io.StringIO()
|
||||
emit_file(self.buf, self.name, self.parent_name)
|
||||
|
||||
def emit(self):
|
||||
print self.buf.getvalue(),
|
||||
print('%s' % self.buf.getvalue(), end='')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
@ -104,21 +104,20 @@ def resolve(path, parent_name):
|
||||
break
|
||||
if os.path.exists(p) and not args.norel:
|
||||
p = os.path.realpath(p).replace('%s%s' % (os.getcwd(), os.sep), '')
|
||||
# print >>sys.stderr, '%s %s -> %s (cwd %s)' % (path, parent_name, p, os.getcwd())
|
||||
return p.replace(os.sep, '/')
|
||||
|
||||
def emit_line_directive(out, name, parent_name):
|
||||
print >>out, '''#ifdef %(prefix)s_MODULE_LINES
|
||||
print ('''#ifdef %(prefix)s_MODULE_LINES
|
||||
#line 1 "%(name)s"
|
||||
#endif''' % dict(
|
||||
prefix = args.prefix,
|
||||
name = resolve(name, parent_name),
|
||||
)
|
||||
), file=out)
|
||||
|
||||
def emit_body(out, name, parent_name):
|
||||
resolved_name = resolve(name, parent_name)
|
||||
if not args.strict and not os.path.exists(resolved_name):
|
||||
print >>out, '#include "%s"' % (name,)
|
||||
print('#include "%s"' % name, file=out)
|
||||
return
|
||||
|
||||
with open(resolved_name) as f:
|
||||
@ -130,7 +129,7 @@ def emit_body(out, name, parent_name):
|
||||
if re.match('\s*\*/$', l):
|
||||
in_comment = False
|
||||
if not re.match('.*Copyright.*Cesanta', comment, re.M | re.S):
|
||||
print >>out, comment,
|
||||
out.write(comment)
|
||||
continue
|
||||
|
||||
if re.match('/\*$', l):
|
||||
@ -145,9 +144,9 @@ def emit_body(out, name, parent_name):
|
||||
if not should_ignore(path_to_include, parent_name):
|
||||
already_included.add(path_to_include)
|
||||
includes.append(File(path_to_include, resolved_name))
|
||||
print >>out, '/* Amalgamated: %s */' % (all,)
|
||||
print('/* Amalgamated: %s */' % all, file=out)
|
||||
else:
|
||||
print >>out, l,
|
||||
out.write(l)
|
||||
|
||||
|
||||
def emit_file(out, name, parent_name):
|
||||
@ -174,17 +173,17 @@ if sys.platform == "win32":
|
||||
|
||||
if args.license:
|
||||
with open(args.license) as f:
|
||||
print f.read()
|
||||
print(f.read())
|
||||
|
||||
if args.public:
|
||||
print '#include "%s"' % (args.public)
|
||||
print('#include "%s"' % args.public)
|
||||
|
||||
for i in includes:
|
||||
i.emit()
|
||||
|
||||
if args.export:
|
||||
print '#ifndef %s_EXPORT_INTERNAL_HEADERS' % (args.prefix,)
|
||||
print('#ifndef %s_EXPORT_INTERNAL_HEADERS' % (args.prefix,))
|
||||
for i in sources:
|
||||
i.emit()
|
||||
if args.export:
|
||||
print '#endif /* %s_EXPORT_INTERNAL_HEADERS */' % (args.prefix,)
|
||||
print('#endif /* %s_EXPORT_INTERNAL_HEADERS */' % (args.prefix,))
|
||||
|
Loading…
Reference in New Issue
Block a user