2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-30 13:58:05 +00:00

use strict

This commit is contained in:
Todd C. Miller
2016-08-31 14:33:24 -06:00
parent 7a54b49fc4
commit c9572db75a

View File

@@ -10,6 +10,9 @@
# array of struct def_values if TYPE == T_TUPLE # array of struct def_values if TYPE == T_TUPLE
use warnings; use warnings;
use strict;
my ($header, $cfile, $infile);
# Deal with optional -o (output) argument # Deal with optional -o (output) argument
if ($#ARGV > 0 && $ARGV[0] eq "-o") { if ($#ARGV > 0 && $ARGV[0] eq "-o") {
@@ -34,9 +37,10 @@ open(IN, "<$infile") || die "$0: can't open $infile: $!\n";
open(HEADER, ">$header") || die "$0: can't open $header: $!\n"; open(HEADER, ">$header") || die "$0: can't open $header: $!\n";
open(CFILE, ">$cfile") || die "$0: can't open $cfile: $!\n"; open(CFILE, ">$cfile") || die "$0: can't open $cfile: $!\n";
$count = 0; my $count = 0;
@tuple_values = ( "never" ); my @tuple_values = ( "never" );
@records = (); my @records = ();
my ($var, $type, $desc, $values, $callback, $field);
while (<IN>) { while (<IN>) {
chomp; chomp;
s/\s*#.*$//; s/\s*#.*$//;
@@ -76,7 +80,7 @@ while (<IN>) {
} else { } else {
die "$0: syntax error near line $.\n" if $type !~ /^T_TUPLE/; die "$0: syntax error near line $.\n" if $type !~ /^T_TUPLE/;
$values = [ split ]; $values = [ split ];
foreach $v (@$values) { foreach my $v (@$values) {
push(@tuple_values, $v) unless grep(/^$v$/, @tuple_values); push(@tuple_values, $v) unless grep(/^$v$/, @tuple_values);
} }
} }
@@ -88,11 +92,12 @@ while (<IN>) {
$records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var); $records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var);
# Print out value arrays # Print out value arrays
for ($i = 0; $i < $count; $i++) { for (my $i = 0; $i < $count; $i++) {
if (defined($records[$i]->[3])) { if (defined($records[$i]->[3])) {
die "Values list specified for non-tuple\n" unless die "Values list specified for non-tuple\n" unless
$records[$i]->[1] =~ /^T_TUPLE/; $records[$i]->[1] =~ /^T_TUPLE/;
printf CFILE "static struct def_values def_data_%s[] = {\n", $records[$i]->[0]; printf CFILE "static struct def_values def_data_%s[] = {\n",
$records[$i]->[0];
foreach (@{$records[$i]->[3]}) { foreach (@{$records[$i]->[3]}) {
print CFILE " { \"$_\", $_ },\n"; print CFILE " { \"$_\", $_ },\n";
} }
@@ -103,7 +108,7 @@ for ($i = 0; $i < $count; $i++) {
# Print each record # Print each record
print CFILE "struct sudo_defs_types sudo_defs_table[] = {\n {\n"; print CFILE "struct sudo_defs_types sudo_defs_table[] = {\n {\n";
for ($i = 0; $i < $count; $i++) { for (my $i = 0; $i < $count; $i++) {
print_record($records[$i], $i); print_record($records[$i], $i);
} }
print CFILE "\tNULL, 0, NULL\n }\n};\n"; print CFILE "\tNULL, 0, NULL\n }\n};\n";
@@ -111,7 +116,7 @@ print CFILE "\tNULL, 0, NULL\n }\n};\n";
# Print out def_tuple # Print out def_tuple
if (@tuple_values) { if (@tuple_values) {
print HEADER "\nenum def_tuple {\n"; print HEADER "\nenum def_tuple {\n";
for ($i = 0; $i <= $#tuple_values; $i++) { for (my $i = 0; $i <= $#tuple_values; $i++) {
printf HEADER "\t%s%s\n", $tuple_values[$i], printf HEADER "\t%s%s\n", $tuple_values[$i],
$i != $#tuple_values ? "," : ""; $i != $#tuple_values ? "," : "";
} }