Home | History | Annotate | Download | only in ss
      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
     33 y/	/ /
     34 s/^ *//
     35 s/#.*$//
     36 /; *$/!{
     37 N
     38 y/	/ /
     39 s/\n */ /
     40 bFIRST
     41 }
     42 s/, */, /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
     60 s/ .*//
     61 s/^/ERROR: unknown keyword: /
     62 =
     63 b
     64 #
     65 # Handle the command_table keyword
     66 #
     67 :CMD
     68 s/;$//
     69 p
     70 d
     71 b
     72 #
     73 # Handle the request keyword --- this is the heart of the sed script.
     74 # 
     75 :REQUEST
     76 s/^request *//
     77 h
     78 i\
     79 BOR
     80 # First, parse out the subroutine name
     81 s/^/sub: /
     82 s/,.*//
     83 p
     84 # Next, parse out the help message, being careful to handle a quoted string
     85 g
     86 s/^[^,]*, *//
     87 h
     88 /^"/ {
     89 	s/^"//
     90 	s/".*//
     91 	x
     92 	s/^"[^"]*", *//
     93 	x
     94 	b EMITHLP
     95 }
     96 s/[^a-zA-Z0-9].*//
     97 x
     98 s/[a-zA-Z0-9]*, *//
     99 x
    100 :EMITHLP
    101 s/^/hlp: /
    102 p
    103 # Next take care of the command names
    104 :CMDLIST
    105 g
    106 /^(/b OPTIONS
    107 /^;/b EOR
    108 /^"/ {
    109 	s/^"//
    110 	s/".*//
    111 	x
    112 	s/^"[^"]*"//
    113 	s/, *//
    114 	x
    115 	b EMITREQ
    116 }
    117 s/[^A-Za-z_0-9].*//
    118 x
    119 s/[A-Za-z_0-9]*//
    120 s/, *//
    121 x
    122 :EMITREQ
    123 s/^/cmd: /
    124 p
    125 b CMDLIST
    126 #
    127 # Here we parse the list of options.
    128 #
    129 : OPTIONS
    130 g
    131 s/^(//
    132 h
    133 : OPTLIST
    134 /^)/ b EOR
    135 /^[^A-Za-z_0-9]/ {
    136 	=
    137 	c\
    138 ERROR: parse error in options list
    139 }
    140 s/[^A-Za-z_0-9].*//
    141 x
    142 s/[A-Za-z_0-9]*//
    143 s/, *//
    144 x
    145 s/^/opt: /
    146 p
    147 g
    148 b OPTLIST
    149 : EOR
    150 c\
    151 EOR\
    152 
    153 d
    154 b
    155 #
    156 # Handle the end keyword --- it's basically ignored.
    157 #
    158 :END
    159 d
    160 b
    161