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