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# 44# Now we take care of some syntatic sugar..... 45# 46/^unimplemented/ { 47 s/^unimplemented [A-Za-z_0-9]*/request ss_unimplemented/ 48 s/;/, (dont_list, dont_summarize);/ 49} 50/^unknown/ { 51 s/^unknown /request ss_unknown, "", / 52} 53# 54# Dispatch based on the keyword.... illegal keywords are prefixed by ERROR: 55# and are handled by the awk script. 56# 57/^command_table /bCMD 58/^request /bREQUEST 59/^end;/bEND 60s/ .*// 61s/^/ERROR: unknown keyword: / 62= 63b 64# 65# Handle the command_table keyword 66# 67:CMD 68s/;$// 69p 70d 71b 72# 73# Handle the request keyword --- this is the heart of the sed script. 74# 75:REQUEST 76s/^request *// 77h 78i\ 79BOR 80# First, parse out the subroutine name 81s/^/sub: / 82s/,.*// 83p 84# Next, parse out the help message, being careful to handle a quoted string 85g 86s/^[^,]*, *// 87h 88/^"/ { 89 s/^"// 90 s/".*// 91 x 92 s/^"[^"]*", *// 93 x 94 b EMITHLP 95} 96s/[^a-zA-Z0-9].*// 97x 98s/[a-zA-Z0-9]*, *// 99x 100:EMITHLP 101s/^/hlp: / 102p 103# Next take care of the command names 104:CMDLIST 105g 106/^(/b OPTIONS 107/^;/b EOR 108/^"/ { 109 s/^"// 110 s/".*// 111 x 112 s/^"[^"]*"// 113 s/, *// 114 x 115 b EMITREQ 116} 117s/[^A-Za-z_0-9].*// 118x 119s/[A-Za-z_0-9]*// 120s/, *// 121x 122:EMITREQ 123s/^/cmd: / 124p 125b CMDLIST 126# 127# Here we parse the list of options. 128# 129: OPTIONS 130g 131s/^(// 132h 133: OPTLIST 134/^)/ b EOR 135/^[^A-Za-z_0-9]/ { 136 = 137 c\ 138ERROR: parse error in options list 139} 140s/[^A-Za-z_0-9].*// 141x 142s/[A-Za-z_0-9]*// 143s/, *// 144x 145s/^/opt: / 146p 147g 148b OPTLIST 149: EOR 150c\ 151EOR\ 152 153d 154b 155# 156# Handle the end keyword --- it's basically ignored. 157# 158:END 159d 160b 161