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