2003-01-07 Klee Dienes * bin/autoheader.in (categories): Contains a list of valid warning categories. (validate_category): Check the argument against @categories, generating an error if it does not match a valid category. (validate_warnings): Check the contents of @warning against @categories. (match_warning): Checks an exception type against @categories. Returns -1 if the exception should be treated as an error; 1 if it should be treated as a warning. (main): Call validate_warnings. Wrap the warning output for config.h.in auxiliary files with match_warning ('obsolete'). --- bin/autoheader.in 2002-12-19 12:36:35.000000000 -0500 +++ bin/autoheader.in 2002-12-28 20:52:48.000000000 -0500 @@ -47,7 +47,7 @@ my @prepend_include; my @include; my @warning; - +my @categories = ('obsolete'); # $HELP # ----- @@ -117,6 +117,47 @@ } } +sub validate_category { + my ($category) = @_; + foreach my $c (@categories) { + if ($category eq $c) { return; } + } + error "error: invalid warning category \"$category\""; +} + +sub validate_warnings { + foreach my $w (@warning) { + if ($w =~ /^(no-)?([-a-z]+)$/) { + my ($prefix, $value) = ($1, $2); + if ($value =~ /^(all|none|error)$/) { + if ($prefix ne "") { + error "error: a \"no-\" prefix may not be used with the 'all', 'none', or 'error' specifiers"; + } + } else { + validate_category ($value); + } + } else { + error "error: invalid warning specifier \"$w\""; + } + } +} + +sub match_warning { + my ($warning) = @_; + my $is_warning = 1; + my $is_error = 0; + validate_category ($warning); + foreach my $w (@warning) { + if ($w eq 'all') { $is_warning = 1; } + if ($w eq 'none') { $is_warning = 0; } + if ($w eq 'error') { $is_error = 1; } + if ($w eq $warning) { $is_warning = 1; } + if ($w eq ('no-'. $warning)) { $is_warning = 0; } + } + if ($is_warning && $is_error) { return -1; } + if ($is_warning) { return 1; } + return 0; +} ## -------------- ## ## Main program. ## @@ -124,6 +165,7 @@ mktmpdir ('ah'); parse_args; +validate_warnings; # Preach. my $config_h_top = find_file ("config.h.top?", @@ -133,25 +175,29 @@ my $acconfig_h = find_file ("acconfig.h?", reverse (@prepend_include), @include); if ($config_h_top || $config_h_bot || $acconfig_h) - { - my $msg = << "END"; - Using auxiliary files such as \`acconfig.h\', \`config.h.bot\' - and \`config.h.top\', to define templates for \`config.h.in\' - is deprecated and discouraged. - - Using the third argument of \`AC_DEFINE\' and - \`AC_DEFINE_UNQUOTED\' allows to define a template without - \`acconfig.h\': +{ + my $val = match_warning ('obsolete'); + if ($val) + { + my $msg = << "END"; +Using auxiliary files such as \`acconfig.h\', \`config.h.bot\' +and \`config.h.top\', to define templates for \`config.h.in\' +is deprecated and discouraged. + +Using the third argument of \`AC_DEFINE\' and +\`AC_DEFINE_UNQUOTED\' allows to define a template without +\`acconfig.h\': - AC_DEFINE([NEED_MAIN], 1, - [Define if a function \`main\' is needed.]) +AC_DEFINE([NEED_MAIN], 1, + [Define if a function \`main\' is needed.]) - More sophisticated templates can also be produced, see the - documentation. +More sophisticated templates can also be produced, see the +documentation. END - $msg =~ s/^ /WARNING: /gm; - print STDERR $msg; - } + $msg =~ s/^/WARNING: /gm; + print STDERR $msg; + } +} # Set up autoconf. my $autoconf = "$autom4te --language=autoconf ";