3 # Generate sudo_defs_table and associated defines
5 # Input should be formatted thusly:
9 # description (or NULL)
10 # array of struct def_values if TYPE == T_TUPLE
12 # Deal with optional -o (output) argument
13 if ($#ARGV > 0 && $ARGV[0] eq "-o") {
15 $header = $cfile = shift;
19 die "usage: $0 input_file\n" unless $#ARGV == 0;
22 if (!defined($header)) {
24 $header =~ s/(\.in)?$/.h/;
26 if (!defined($cfile)) {
28 $cfile =~ s/(\.in)?$/.c/;
31 open(IN, "<$infile") || die "$0: can't open $infile: $!\n";
32 open(HEADER, ">$header") || die "$0: can't open $header: $!\n";
33 open(CFILE, ">$cfile") || die "$0: can't open $cfile: $!\n";
36 @tuple_values = ( "never" );
44 # Store previous record and begin new one
45 $records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var);
60 } elsif ($field == 2) {
65 # Strip leading and trailing double quote and escape the rest
71 } elsif ($field == 3 || $field == 4) {
75 die "$0: syntax error near line $.\n" if $type !~ /^T_TUPLE/;
77 foreach $v (@$values) {
78 push(@tuple_values, $v) unless grep(/^$v$/, @tuple_values);
82 die "$0: syntax error near line $.\n";
86 $records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var);
88 # Print out value arrays
89 for ($i = 0; $i < $count; $i++) {
90 if (defined($records[$i]->[3])) {
91 die "Values list specified for non-tupple\n" unless
92 $records[$i]->[1] =~ /^T_TUPLE/;
93 printf CFILE "static struct def_values def_data_%s[] = {\n", $records[$i]->[0];
94 foreach (@{$records[$i]->[3]}) {
95 print CFILE " { \"$_\", $_ },\n";
97 print CFILE " { NULL, 0 },\n";
103 print CFILE "struct sudo_defs_types sudo_defs_table[] = {\n {\n";
104 for ($i = 0; $i < $count; $i++) {
105 &print_record($records[$i], $i);
107 print CFILE "\tNULL, 0, NULL\n }\n};\n";
109 # Print out def_tuple
111 print HEADER "\nenum def_tupple {\n";
112 for ($i = 0; $i <= $#tuple_values; $i++) {
113 printf HEADER "\t%s%s\n", $tuple_values[$i],
114 $i != $#tuple_values ? "," : "";
124 my ($rec, $recnum) = @_;
125 my ($i, $v, $defname);
126 # each variable gets a macro to access its value
128 if (/^T_U?INT/) { $v = "ival"; }
129 elsif (/^T_STR/) { $v = "str"; }
130 elsif (/^T_FLAG/) { $v = "flag"; }
131 elsif (/^T_MODE/) { $v = "mode"; }
132 elsif (/^T_LIST/) { $v = "list"; }
133 elsif (/^T_LOGFAC/) { $v = "ival"; }
134 elsif (/^T_LOGPRI/) { $v = "ival"; }
135 elsif (/^T_TUPLE/) { $v = "tuple"; }
136 else { die "$0: unknown defaults type: $type\n"; }
138 printf HEADER "#define %-23s (sudo_defs_table[$recnum].sd_un.${v})\n",
141 $defname = "I_" . uc($rec->[0]);
142 printf HEADER "#define %-24s%d", $defname, $recnum;
143 #print HEADER "\t/* $rec->[2] */" if defined($rec->[2]);
146 print CFILE "\t\"$rec->[0]\", $rec->[1],\n\t$rec->[2],\n";
147 if (defined($rec->[3])) {
148 printf CFILE "\tdef_data_$rec->[0],\n";
150 printf CFILE "\tNULL,\n";
152 printf CFILE "\t$rec->[4],\n" if defined($rec->[4]);
153 print CFILE " }, {\n";