Preparing for release of 3.2.2pre3
[rsync.git] / daemon-parm.awk
blobefc15474c2268d1db61f4242a805c08380bc564b
1 #!/usr/bin/awk -f
3 # The caller must pass arg: daemon-parm.txt
4 # The resulting code is output into daemon-parm.h
6 BEGIN {
7 heading = "/* DO NOT EDIT THIS FILE! It is auto-generated from a list of values in " ARGV[1] "! */"
8 sect = psect = defines = accessors = prior_ptype = ""
9 values = "\nstatic const all_vars Defaults = {\n { /* Globals: */\n"
10 params = "\nstatic struct parm_struct parm_table[] = {"
11 exp_line = "\n/********** EXP **********/\n"
12 tdstruct = "typedef struct {"
15 /^\s*$/ { next }
16 /^#/ { next }
18 /^Globals:/ {
19 if (defines != "") {
20 print "The Globals section must come first!"
21 defines = ""
22 exit
24 defines = tdstruct
25 exps = exp_values = exp_line
26 sect = "GLOBAL"
27 psect = ", P_GLOBAL, &Vars.g."
28 next
31 /^Locals:/ {
32 if (sect == "") {
33 print "The Locals section must come after the Globals!"
34 exit
36 defines = defines exps "} global_vars;\n\n" tdstruct
37 values = values exp_values "\n }, { /* Locals: */\n"
38 exps = exp_values = exp_line
39 sect = "LOCAL"
40 psect = ", P_LOCAL, &Vars.l."
41 next
44 /^(STRING|PATH|INTEGER|ENUM|BOOL)/ {
45 ptype = $1
46 name = $2
47 $1 = $2 = ""
48 sub(/^[ \t]+/, "")
50 if (ptype != prior_ptype) {
51 defines = defines "\n/********** " ptype " **********/\n"
52 values = values "\n/********** " ptype " **********/\n"
53 params = params "\n"
54 accessors = accessors "\n"
55 prior_ptype = ptype
58 if (ptype == "STRING" || ptype == "PATH") {
59 atype = "STRING"
60 vtype = "char*"
61 } else if (ptype == "BOOL") {
62 atype = vtype = "BOOL"
63 } else {
64 atype = "INTEGER"
65 vtype = "int"
68 # We have 2 variables that don't match their conf string. Oh well...
69 if (name == "bind_address")
70 spname = "address"
71 else if (name == "rsync_port")
72 spname = "port"
73 else {
74 spname = name
75 gsub(/_/, " ", spname)
76 gsub(/-/, "", name)
79 if (ptype == "ENUM")
80 enum = "enum_" name
81 else
82 enum = "NULL"
84 defines = defines "\t" vtype " " name ";\n"
85 values = values "\t" $0 ", /* " name " */\n"
86 params = params " {\"" spname "\", P_" ptype psect name ", " enum ", 0},\n"
87 accessors = accessors "FN_" sect "_" atype "(lp_" name ", " name ")\n"
89 if (vtype == "char*") {
90 exps = exps "\tBOOL " name "_EXP;\n"
91 exp_values = exp_values "\tFalse, /* " name "_EXP */\n"
94 next
97 /./ {
98 print "Extraneous line:" $0
99 defines = ""
100 exit
103 END {
104 if (sect != "" && defines != "") {
105 defines = defines exps "} local_vars;\n\n"
106 defines = defines tdstruct "\n\tglobal_vars g;\n\tlocal_vars l;\n} all_vars;\n"
107 values = values exp_values "\n }\n};\n\nstatic all_vars Vars;\n"
108 params = params "\n {NULL, P_BOOL, P_NONE, NULL, NULL, 0}\n};\n"
109 print heading "\n\n" defines values params accessors > "daemon-parm.h"
110 } else {
111 print "Failed to parse the data in " ARGV[1]
112 exit 1