summaryrefslogtreecommitdiffstats
path: root/lib/ss/ct_c.awk
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
commit464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch)
tree6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /lib/ss/ct_c.awk
parentInitial commit. (diff)
downloade2fsprogs-db58a52ab489b66cea7224323c4c6171ccc2a9dd.tar.xz
e2fsprogs-db58a52ab489b66cea7224323c4c6171ccc2a9dd.zip
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ss/ct_c.awk')
-rw-r--r--lib/ss/ct_c.awk75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/ss/ct_c.awk b/lib/ss/ct_c.awk
new file mode 100644
index 0000000..a4424c8
--- /dev/null
+++ b/lib/ss/ct_c.awk
@@ -0,0 +1,75 @@
+/^command_table / {
+ cmdtbl = $2;
+ printf "/* %s.c - automatically generated from %s.ct */\n", \
+ rootname, rootname > outfile
+ print "#include <ss/ss.h>" > outfile
+ print "" >outfile
+}
+
+/^BOR$/ {
+ cmdnum++
+ options = 0
+ cmdtab = ""
+ printf "static char const * const ssu%05d[] = {\n", cmdnum > outfile
+}
+
+/^sub/ {
+ subr = substr($0, 6, length($0)-5)
+}
+
+/^hlp/ {
+ help = substr($0, 6, length($0)-5)
+}
+
+/^cmd/ {
+ cmd = substr($0, 6, length($0)-5)
+ printf "%s\"%s\",\n", cmdtab, cmd > outfile
+ cmdtab = " "
+}
+
+/^opt/ {
+ opt = substr($0, 6, length($0)-5)
+ if (opt == "dont_list") {
+ options += 1
+ }
+ if (opt == "dont_summarize") {
+ options += 2
+ }
+}
+
+/^EOR/ {
+ print " (char const *)0" > outfile
+ print "};" > outfile
+ printf "extern void %s __SS_PROTO;\n", subr > outfile
+ # Work around a bug in gawk 3.0.5
+ awk_bug = cmdnum
+ subr_tab[awk_bug] = subr
+ options_tab[awk_bug] = options
+ help_tab[awk_bug] = help
+}
+
+/^[0-9]/ {
+ linenum = $1;
+}
+
+/^ERROR/ {
+ error = substr($0, 8, length($0)-7)
+ printf "Error in line %d: %s\n", linenum, error
+ print "#__ERROR_IN_FILE__" > outfile
+}
+
+END {
+ printf "static ss_request_entry ssu%05d[] = {\n", cmdnum+1 > outfile
+ for (i=1; i <= cmdnum; i++) {
+ printf " { ssu%05d,\n", i > outfile
+ printf " %s,\n", subr_tab[i] > outfile
+ printf " \"%s\",\n", help_tab[i] > outfile
+ printf " %d },\n", options_tab[i] > outfile
+ }
+ print " { 0, 0, 0, 0 }" > outfile
+ print "};" > outfile
+ print "" > outfile
+ printf "ss_request_table %s = { 2, ssu%05d };\n", \
+ cmdtbl, cmdnum+1 > outfile
+}
+