1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-20 23:52:15 +00:00
stmbl/tools/create_cmd.py

33 lines
876 B
Python
Raw Permalink Normal View History

#! /bin/sh
"true" '''\'
if command -v python2 > /dev/null; then
exec python2 "$0" "$@"
else
exec python "$0" "$@"
fi
exit $?
'''
2017-02-25 21:37:29 +00:00
import re
import sys
cmd = []
for infile in sys.argv[1:]:
with open(infile) as f:
2017-04-12 02:05:46 +00:00
for line_number, line in enumerate(f):
2017-07-12 20:12:04 +00:00
match = re.search('COMMAND\("(\w*)", *(\w*), *"([^"]*)"\);', line)
2017-02-25 21:37:29 +00:00
if match:
2017-04-12 02:05:46 +00:00
cmd.append((match.groups(), infile, line_number))
2017-02-25 21:37:29 +00:00
print "//generated by " + sys.argv[0] + " DO NOT EDIT"
2017-07-12 20:12:04 +00:00
for (name, ptr, doc), file_name, line_number in cmd:
2017-04-12 02:05:46 +00:00
print "extern void " + ptr + "(char *); // found in " + file_name + " line: " + str(line_number + 1)
print "\n"
2017-02-25 21:37:29 +00:00
print "cmd_t cmd[] = {"
2017-07-12 20:12:04 +00:00
for (name, ptr, doc), file_name, line_number in cmd:
print " {\"" + name + "\", \"" + doc + "\", " + ptr + "}, // found in " + file_name + " line: " + str(line_number + 1)
2017-02-25 21:37:29 +00:00
print "};"