diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 09:25:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 09:25:10 +0000 |
commit | 5dced3d1b3deca80e01415a2e35dc7972dcbfae7 (patch) | |
tree | 6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /lib/ss/ct_c.sed | |
parent | Initial commit. (diff) | |
download | e2fsprogs-5dced3d1b3deca80e01415a2e35dc7972dcbfae7.tar.xz e2fsprogs-5dced3d1b3deca80e01415a2e35dc7972dcbfae7.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ss/ct_c.sed')
-rw-r--r-- | lib/ss/ct_c.sed | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/lib/ss/ct_c.sed b/lib/ss/ct_c.sed new file mode 100644 index 0000000..9e5eebb --- /dev/null +++ b/lib/ss/ct_c.sed @@ -0,0 +1,160 @@ +# +# This script parses a command_table file into something which is a bit +# easier for an awk script to understand. +# +# Input syntax: a .ct file +# +# Output syntax: +# (for the command_table line) +# command_table <command_table> +# +#(for each request definition) +# BOR +# sub: <subroutine name> +# hlp: <help text> +# cmd: <command> +# opt: <option> +# EOR +# (there may be more than one 'cmd' or 'opt' line +# +# A number sent to the output represents a parse error --- it will be +# followed by the next line which will have the form: +# ERROR: <error text> +# +# The design of this output syntax is such that it should be easy for +# an awk script to parse. + +# +# The first section of this script is just to canonicalize the file. +# It removes comments, and puts each command_table request onto a single +# line +# +:FIRST +y/ / / +s/^ *// +s/#.*$// +/; *$/!{ +N +y/ / / +s/\n */ / +bFIRST +} +s/, */, /g +# +# Now we take care of some syntactic sugar..... +# +/^unimplemented/ { + s/^unimplemented [A-Za-z_0-9]*/request ss_unimplemented/ + s/;/, (dont_list, dont_summarize);/ +} +/^unknown/ { + s/^unknown /request ss_unknown, "", / +} +# +# Dispatch based on the keyword.... illegal keywords are prefixed by ERROR: +# and are handled by the awk script. +# +/^command_table /bCMD +/^request /bREQUEST +/^end;/bEND +s/ .*// +s/^/ERROR: unknown keyword: / += +b +# +# Handle the command_table keyword +# +:CMD +s/;$// +p +d +b +# +# Handle the request keyword --- this is the heart of the sed script. +# +:REQUEST +s/^request *// +h +i\ +BOR +# First, parse out the subroutine name +s/^/sub: / +s/,.*// +p +# Next, parse out the help message, being careful to handle a quoted string +g +s/^[^,]*, *// +h +/^"/ { + s/^"// + s/".*// + x + s/^"[^"]*", *// + x + b EMITHLP +} +s/[^a-zA-Z0-9].*// +x +s/[a-zA-Z0-9]*, *// +x +:EMITHLP +s/^/hlp: / +p +# Next take care of the command names +:CMDLIST +g +/^(/b OPTIONS +/^;/b EOR +/^"/ { + s/^"// + s/".*// + x + s/^"[^"]*"// + s/, *// + x + b EMITREQ +} +s/[^A-Za-z_0-9].*// +x +s/[A-Za-z_0-9]*// +s/, *// +x +:EMITREQ +s/^/cmd: / +p +b CMDLIST +# +# Here we parse the list of options. +# +: OPTIONS +g +s/^(// +h +: OPTLIST +/^)/ b EOR +/^[^A-Za-z_0-9]/ { + = + c\ +ERROR: parse error in options list +} +s/[^A-Za-z_0-9].*// +x +s/[A-Za-z_0-9]*// +s/, *// +x +s/^/opt: / +p +g +b OPTLIST +: EOR +c\ +EOR\ + +d +b +# +# Handle the end keyword --- it's basically ignored. +# +:END +d +b |