3 # Convert help for ginsh operators from man page to C source
4 import sys, re, optparse
6 rxStart = re.compile('^.*GINSH_OP_HELP_START$')
7 rxEnd = re.compile('^.*GINSH_OP_HELP_END$')
8 fcnRx = re.compile('^[.]B\s+')
9 minusRx = re.compile('\\\\[-]')
10 codeFmt = 'insert_help("operators", "%s\\t" "%s");\n'
12 def extractHelp(inp, out):
13 sym, synopsis = None, None
23 out.write(codeFmt % ( sym, synopsis ))
27 sym = minusRx.sub('-', l)
28 elif l.lower() == '.tp':
29 out.write(codeFmt % ( sym, synopsis ))
30 sym, synopsis = None, None
35 op = optparse.OptionParser()
36 op.add_option('-o', dest = 'outfile')
37 options, args = op.parse_args()
40 if not options.outfile is None:
41 outfile = open(options.outfile, 'wt')
43 infile = open(args[0])
44 extractHelp(infile, outfile)
45 if infile != sys.stdin:
48 if outfile != sys.stdout:
51 if __name__ == "__main__":