"Fossies" - the Fresh Open Source Software Archive

Member "hydra-3.3.2/mpl/confdb/cmd_prefix_config_h.pl" (12 Nov 2019, 1822 Bytes) of package /linux/misc/hydra-3.3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cmd_prefix_config_h.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 use strict;
    3 
    4 # This script is to be run by AC_CONFIG_COMMANDS in configure.ac.
    5 # USAGE:
    6 #     AC_CONFIG_COMMANDS([prefix-config],[perl cmd_prefix_config_h.pl PREFIX input_config.h output_config.h])
    7 #
    8 # The script will read "input_config.h", and write "output_config.h", adding prefix to every defined macros. This script is a replacement to AX_PREFIX_CONFIG_H.
    9 
   10 sub add_prefix {
   11     my ($name, $prefix) = @_;
   12     if($name=~/^(inline|const|restrict)/){
   13         # leave c99 keywords alone
   14     }
   15     elsif($name=~/^_/){
   16         # leave underscore keywords alone, e.g _MINIX
   17     }
   18     elsif($name=~/^$prefix\_/i){
   19         # avoid double prefix
   20     }
   21     elsif($name=~/^[A-Z0-9_]+$/){
   22         $name = uc($prefix)."_$name";
   23     }
   24     else{
   25         $name = "_".lc($prefix)."_$name";
   26     }
   27     return $name;
   28 }
   29 
   30 my ($prefix, $config_in, $config_out)=@ARGV;
   31 if(!$prefix){
   32     die "missing prefix!\n";
   33 }
   34 if(!$config_in){
   35     $config_in = "config.h";
   36 }
   37 if(!$config_out){
   38     $config_out = $config_in;
   39 }
   40 my @lines;
   41 open In, "$config_in" or die "Can't open $config_in.\n";
   42 while(<In>){
   43     if(/^#define\s+(\w+)\s*(.+)/){
   44         my $name = add_prefix($1, $prefix);
   45         push @lines, "#ifndef $name\n";
   46         push @lines, "#define $name $2\n";
   47         push @lines, "#endif\n";
   48         next;
   49     }
   50     elsif(/^\/\*\s*#undef (\w+)/){
   51         my $name = add_prefix($1, $prefix);
   52         push @lines, "/* #undef $name */\n";
   53         next;
   54     }
   55     push @lines, $_;
   56 }
   57 close In;
   58 my $DEFH=uc($config_out);
   59 $DEFH=~s/\W/_/g;
   60 open Out, ">$config_out" or die "Can't write $config_out.\n";
   61 print Out "#ifndef $DEFH\n";
   62 print Out "#define $DEFH 1\n\n";
   63 print Out "\x2f* $config_out. Generated automatically at end of configure. *\x2f\n";
   64 print Out @lines;
   65 print Out "\x2f* once: $DEFH *\x2f\n";
   66 print Out "#endif\n";
   67 close Out;