3 # Convert help for ginsh functions from man page to C source
4 import sys, re, optparse
6 rxStart = re.compile('^.*GINSH_FCN_HELP_START$')
7 rxEnd = re.compile('^.*GINSH_FCN_HELP_END$')
8 fcnRx = re.compile('^[.]BI\s+')
9 hlpRx = re.compile('\\\\[-]')
10 codeFmt = 'insert_help("%s",\n"%s"\n);\n'
13 pStr = fcnRx.sub('', pStr)
14 pStr = re.sub('\s', '', pStr)
15 pStr = re.sub('"', '', pStr)
16 pStr = re.sub(',', ', ', pStr)
17 pStr = re.sub('\\[', ' [', pStr)
18 name = pStr.split('(')[0]
21 def extractHelp(inp, out):
22 name, proto, synopsis = None, None, None
33 name, proto = parseProto(l)
35 l = hlpRx.sub('', l).strip()
36 l = re.sub('"', "'", l)
37 synopsis = '%s"\n" - %s' % ( proto, l )
38 elif l.lower() == '.br':
39 synopsis = synopsis or proto
40 out.write(codeFmt % ( name, synopsis ))
41 name, proto, synopsis = None, None, None
44 op = optparse.OptionParser()
45 op.add_option('-o', dest = 'outfile')
46 options, args = op.parse_args()
49 if not options.outfile is None:
50 outfile = open(options.outfile, 'wt')
52 infile = open(args[0])
53 extractHelp(infile, outfile)
54 if infile != sys.stdin:
57 if outfile != sys.stdout:
60 if __name__ == '__main__':