medit/moo/mooutils/xml2h.py

25 lines
521 B
Python
Raw Normal View History

#!/usr/bin/env python
2006-04-03 00:48:27 -07:00
import sys
if not sys.argv[2:]:
print 'usage: %s <var_name> <file_name>' % (sys.argv[0],)
2006-04-03 00:48:27 -07:00
sys.exit(1)
if sys.argv[1] == '--txt':
line_term = '\\n'
VARNAME, INPUT = sys.argv[2:]
else:
line_term = ''
VARNAME, INPUT = sys.argv[1:]
2006-04-03 00:48:27 -07:00
file = open(INPUT, "r")
sys.stdout.write('static const char %s[] = \"\"\n' % (VARNAME,))
for line in file:
line = line[:-1]
line = '"' + line.replace('"', '\\"') + line_term + '"\n'
2006-04-03 00:48:27 -07:00
sys.stdout.write(line)
sys.stdout.write(';\n')