Whamcloud - gitweb
ChangeLog, mke2fs.c:
[tools/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         print "#ifndef __STDC__" > outfile
8         print "#define const" > outfile
9         print "#endif" > outfile
10         print "" > outfile
11 }
12         
13 /^BOR$/ {
14         cmdnum++
15         options = 0
16         cmdtab = ""
17         printf "static char const * const ssu%05d[] = {\n", cmdnum > outfile
18 }
19
20 /^sub/ {
21         subr = substr($0, 6, length($0)-5)
22 }
23
24 /^hlp/ {
25         help = substr($0, 6, length($0)-5)
26 }
27
28 /^cmd/ {
29         cmd = substr($0, 6, length($0)-5)
30         printf "%s\"%s\",\n", cmdtab, cmd > outfile
31         cmdtab = "    "
32 }
33
34 /^opt/ {
35         opt = substr($0, 6, length($0)-5)
36         if (opt == "dont_list") {
37                 options += 1
38         }
39         if (opt == "dont_summarize") {
40                 options += 2
41         }
42 }
43
44 /^EOR/ {
45         print "    (char const *)0" > outfile
46         print "};" > outfile 
47         printf "extern void %s __SS_PROTO;\n", subr > outfile
48         # Work around a bug in gawk 3.0.5
49         awk_bug = cmdnum
50         subr_tab[awk_bug] = subr
51         options_tab[awk_bug] = options
52         help_tab[awk_bug] = help
53 }
54
55 /^[0-9]/ {
56         linenum = $1;
57 }
58
59 /^ERROR/ {
60         error = substr($0, 8, length($0)-7)
61         printf "Error in line %d: %s\n", linenum, error
62         print "#__ERROR_IN_FILE__" > outfile
63 }
64
65 END {
66         printf "static ss_request_entry ssu%05d[] = {\n", cmdnum+1 > outfile
67         for (i=1; i <= cmdnum; i++) {
68                 printf "    { ssu%05d,\n", i > outfile
69                 printf "      %s,\n", subr_tab[i] > outfile
70                 printf "      \"%s\",\n", help_tab[i] > outfile
71                 printf "      %d },\n", options_tab[i] > outfile
72         }
73         print "    { 0, 0, 0, 0 }" > outfile
74         print "};" > outfile
75         print "" > outfile
76         printf "ss_request_table %s = { 2, ssu%05d };\n", \
77                 cmdtbl, cmdnum+1 > outfile
78 }
79