1# 2# This script parses a command_table file into something which is a bit 3# easier for an awk script to understand. 4# 5# Input syntax: a .ct file 6# 7# Output syntax: 8# (for the command_table line) 9# command_table <command_table> 10# 11#(for each request definition) 12# BOR 13# sub: <subroutine name> 14# hlp: <help text> 15# cmd: <command> 16# opt: <option> 17# EOR 18# (there may be more than one 'cmd' or 'opt' line 19# 20# A number sent to the output represents a parse error --- it will be 21# followed by the next line which will have the form: 22# ERROR: <error text> 23# 24# The design of this output syntax is such that it should be easy for 25# an awk script to parse. 26 27# 28# The first section of this script is just to cannoicalize the file. 29# It removes comments, and puts each command_table request onto a single 30# line 31# 32:FIRST 33y/ / / 34s/^ *// 35s/#.*$// 36/; *$/!{ 37N 38y/ / / 39s/\n */ / 40bFIRST 41} 42s/, */, /g 43/^$/d 44# 45# Now we take care of some syntactic sugar..... 46# 47/^unimplemented/ { 48 s/^unimplemented [A-Za-z_0-9]*/request ss_unimplemented/ 49 s/;/, (dont_list, dont_summarize);/ 50} 51/^unknown/ { 52 s/^unknown /request ss_unknown, "", / 53} 54# 55# Dispatch based on the keyword.... illegal keywords are prefixed by ERROR: 56# and are handled by the awk script. 57# 58/^command_table /bCMD 59/^request /bREQUEST 60/^end;/bEND 61s/ .*// 62s/^/ERROR: unknown keyword: / 63= 64b 65# 66# Handle the command_table keyword 67# 68:CMD 69s/;$// 70p 71d 72b 73# 74# Handle the request keyword --- this is the heart of the sed script. 75# 76:REQUEST 77s/^request *// 78h 79i\ 80BOR 81# First, parse out the subroutine name 82s/^/sub: / 83s/,.*// 84p 85# Next, parse out the help message, being careful to handle a quoted string 86g 87s/^[^,]*, *// 88h 89/^"/ { 90 s/^"// 91 s/".*// 92 x 93 s/^"[^"]*", *// 94 x 95 b EMITHLP 96} 97s/[^a-zA-Z0-9].*// 98x 99s/[a-zA-Z0-9]*, *// 100x 101:EMITHLP 102s/^/hlp: / 103p 104# Next take care of the command names 105:CMDLIST 106g 107/^(/b OPTIONS 108/^;/b EOR 109/^"/ { 110 s/^"// 111 s/".*// 112 x 113 s/^"[^"]*"// 114 s/, *// 115 x 116 b EMITREQ 117} 118s/[^A-Za-z_0-9].*// 119x 120s/[A-Za-z_0-9]*// 121s/, *// 122x 123:EMITREQ 124s/^/cmd: / 125p 126b CMDLIST 127# 128# Here we parse the list of options. 129# 130: OPTIONS 131g 132s/^(// 133h 134: OPTLIST 135/^)/ b EOR 136/^[^A-Za-z_0-9]/ { 137 = 138 c\ 139ERROR: parse error in options list 140} 141s/[^A-Za-z_0-9].*// 142x 143s/[A-Za-z_0-9]*// 144s/, *// 145x 146s/^/opt: / 147p 148g 149b OPTLIST 150: EOR 151c\ 152EOR\ 153 154d 155b 156# 157# Handle the end keyword --- it's basically ignored. 158# 159:END 160d 161b 162