]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - lib/ss/ct_c.awk
Change compile_et to generate header files that use <et/com_err.h>
[thirdparty/e2fsprogs.git] / lib / ss / ct_c.awk
1 /^command_table / {
2 cmdtbl = $2;
3 printf "/* %s.c - automatically generated from %s.ct */\n", \
4 rootname, rootname > outfile
5 print "#include <ss/ss.h>" > outfile
6 print "" >outfile
7 }
8
9 /^BOR$/ {
10 cmdnum++
11 options = 0
12 cmdtab = ""
13 printf "static char const * const ssu%05d[] = {\n", cmdnum > outfile
14 }
15
16 /^sub/ {
17 subr = substr($0, 6, length($0)-5)
18 }
19
20 /^hlp/ {
21 help = substr($0, 6, length($0)-5)
22 }
23
24 /^cmd/ {
25 cmd = substr($0, 6, length($0)-5)
26 printf "%s\"%s\",\n", cmdtab, cmd > outfile
27 cmdtab = " "
28 }
29
30 /^opt/ {
31 opt = substr($0, 6, length($0)-5)
32 if (opt == "dont_list") {
33 options += 1
34 }
35 if (opt == "dont_summarize") {
36 options += 2
37 }
38 }
39
40 /^EOR/ {
41 print " (char const *)0" > outfile
42 print "};" > outfile
43 printf "extern void %s __SS_PROTO;\n", subr > outfile
44 # Work around a bug in gawk 3.0.5
45 awk_bug = cmdnum
46 subr_tab[awk_bug] = subr
47 options_tab[awk_bug] = options
48 help_tab[awk_bug] = help
49 }
50
51 /^[0-9]/ {
52 linenum = $1;
53 }
54
55 /^ERROR/ {
56 error = substr($0, 8, length($0)-7)
57 printf "Error in line %d: %s\n", linenum, error
58 print "#__ERROR_IN_FILE__" > outfile
59 }
60
61 END {
62 printf "static ss_request_entry ssu%05d[] = {\n", cmdnum+1 > outfile
63 for (i=1; i <= cmdnum; i++) {
64 printf " { ssu%05d,\n", i > outfile
65 printf " %s,\n", subr_tab[i] > outfile
66 printf " \"%s\",\n", help_tab[i] > outfile
67 printf " %d },\n", options_tab[i] > outfile
68 }
69 print " { 0, 0, 0, 0 }" > outfile
70 print "};" > outfile
71 print "" > outfile
72 printf "ss_request_table %s = { 2, ssu%05d };\n", \
73 cmdtbl, cmdnum+1 > outfile
74 }
75