| 1 |
#!/usr/bin/awk -f |
| 2 |
|
| 3 |
# The caller must pass arg: daemon-parm.txt |
| 4 |
# The resulting code is output into daemon-parm.h |
| 5 |
|
| 6 |
BEGIN { |
| 7 |
heading = "/* DO NOT EDIT THIS FILE! It is auto-generated from a list of values in " ARGV[1] "! */\n\n" |
| 8 |
sect = psect = defines = accessors = prior_ptype = "" |
| 9 |
parms = "\nstatic const struct parm_struct parm_table[] = {" |
| 10 |
comment_fmt = "\n/********** %s **********/\n" |
| 11 |
tdstruct = "typedef struct {" |
| 12 |
} |
| 13 |
|
| 14 |
/^\s*$/ { next } |
| 15 |
/^#/ { next } |
| 16 |
|
| 17 |
/^Globals:/ { |
| 18 |
if (defines != "") { |
| 19 |
print "The Globals section must come first!" |
| 20 |
defines = "" |
| 21 |
exit |
| 22 |
} |
| 23 |
defines = tdstruct |
| 24 |
values = "\nstatic const all_vars Defaults = {\n { /* Globals: */\n" |
| 25 |
exps = exp_values = sprintf(comment_fmt, "EXP") |
| 26 |
sect = "GLOBAL" |
| 27 |
psect = ", P_GLOBAL, &Vars.g." |
| 28 |
next |
| 29 |
} |
| 30 |
|
| 31 |
/^Locals:/ { |
| 32 |
if (sect == "") { |
| 33 |
print "The Locals section must come after the Globals!" |
| 34 |
exit |
| 35 |
} |
| 36 |
defines = defines exps "} global_vars;\n\n" tdstruct |
| 37 |
values = values exp_values "\n }, { /* Locals: */\n" |
| 38 |
exps = exp_values = sprintf(comment_fmt, "EXP") |
| 39 |
sect = "LOCAL" |
| 40 |
psect = ", P_LOCAL, &Vars.l." |
| 41 |
next |
| 42 |
} |
| 43 |
|
| 44 |
/^(STRING|CHAR|PATH|INTEGER|ENUM|OCTAL|BOOL|BOOLREV|BOOL3)[ \t]/ { |
| 45 |
ptype = $1 |
| 46 |
name = $2 |
| 47 |
$1 = $2 = "" |
| 48 |
sub(/^[ \t]+/, "") |
| 49 |
|
| 50 |
if (ptype != prior_ptype) { |
| 51 |
comment = sprintf(comment_fmt, ptype) |
| 52 |
defines = defines comment |
| 53 |
values = values comment |
| 54 |
parms = parms "\n" |
| 55 |
accessors = accessors "\n" |
| 56 |
prior_ptype = ptype |
| 57 |
} |
| 58 |
|
| 59 |
if (ptype == "STRING" || ptype == "PATH") { |
| 60 |
atype = "STRING" |
| 61 |
vtype = "char*" |
| 62 |
} else if (ptype ~ /BOOL/) { |
| 63 |
atype = vtype = "BOOL" |
| 64 |
} else if (ptype == "CHAR") { |
| 65 |
atype = "CHAR" |
| 66 |
vtype = "char" |
| 67 |
} else { |
| 68 |
atype = "INTEGER" |
| 69 |
vtype = "int" |
| 70 |
} |
| 71 |
|
| 72 |
# The name might be var_name|public_name |
| 73 |
pubname = name |
| 74 |
sub(/\|.*/, "", name) |
| 75 |
sub(/.*\|/, "", pubname) |
| 76 |
gsub(/_/, " ", pubname) |
| 77 |
gsub(/-/, "", name) |
| 78 |
|
| 79 |
if (ptype == "ENUM") |
| 80 |
enum = "enum_" name |
| 81 |
else |
| 82 |
enum = "NULL" |
| 83 |
|
| 84 |
defines = defines "\t" vtype " " name ";\n" |
| 85 |
values = values "\t" $0 ", /* " name " */\n" |
| 86 |
parms = parms " {\"" pubname "\", P_" ptype psect name ", " enum ", 0},\n" |
| 87 |
# The shell-executed hook params (whose %RSYNC_*% expansion is fed to |
| 88 |
# /bin/sh) use the _SHELL accessor, which single-quotes peer-controlled |
| 89 |
# values to prevent injection. Ordinary string params must NOT quote -- |
| 90 |
# it would corrupt a documented `path = /home/%RSYNC_USER_NAME%` etc. |
| 91 |
if (atype == "STRING" && (name == "early_exec" || name == "prexfer_exec" || name == "postxfer_exec" || name == "name_converter")) |
| 92 |
accessors = accessors "FN_" sect "_STRING_SHELL(lp_" name ", " name ")\n" |
| 93 |
else |
| 94 |
accessors = accessors "FN_" sect "_" atype "(lp_" name ", " name ")\n" |
| 95 |
|
| 96 |
if (vtype == "char*") { |
| 97 |
exps = exps "\tBOOL " name "_EXP;\n" |
| 98 |
exp_values = exp_values "\tFalse, /* " name "_EXP */\n" |
| 99 |
} |
| 100 |
|
| 101 |
next |
| 102 |
} |
| 103 |
|
| 104 |
/./ { |
| 105 |
print "Extraneous line:" $0 |
| 106 |
defines = "" |
| 107 |
exit |
| 108 |
} |
| 109 |
|
| 110 |
END { |
| 111 |
if (sect != "" && defines != "") { |
| 112 |
defines = defines exps "} local_vars;\n\n" |
| 113 |
defines = defines tdstruct "\n\tglobal_vars g;\n\tlocal_vars l;\n} all_vars;\n" |
| 114 |
values = values exp_values "\n }\n};\n\nstatic all_vars Vars;\n" |
| 115 |
parms = parms "\n {NULL, P_BOOL, P_NONE, NULL, NULL, 0}\n};\n" |
| 116 |
print heading defines values parms accessors > "daemon-parm.h" |
| 117 |
} else { |
| 118 |
print "Failed to parse the data in " ARGV[1] |
| 119 |
exit 1 |
| 120 |
} |
| 121 |
} |