Change the command line options of mkerr.pl so -static is now default and
[openssl.git] / util / mkerr.pl
index 47896eab6f2721b94712cf12c37cec3c483e0280..ccf766b9a04156bcc66bb9dc66ad3473ff75a96e 100644 (file)
@@ -3,9 +3,10 @@
 my $config = "crypto/err/openssl.ec";
 my $debug = 0;
 my $rebuild = 0;
 my $config = "crypto/err/openssl.ec";
 my $debug = 0;
 my $rebuild = 0;
-my $static = 0;
+my $static = 1;
 my $recurse = 0;
 my $reindex = 0;
 my $recurse = 0;
 my $reindex = 0;
+my $dowrite = 0;
 
 
 while (@ARGV) {
 
 
 while (@ARGV) {
@@ -25,8 +26,11 @@ while (@ARGV) {
        } elsif($arg eq "-reindex") {
                $reindex = 1;
                shift @ARGV;
        } elsif($arg eq "-reindex") {
                $reindex = 1;
                shift @ARGV;
-       } elsif($arg eq "-static") {
-               $static = 1;
+       } elsif($arg eq "-nostatic") {
+               $static = 0;
+               shift @ARGV;
+       } elsif($arg eq "-write") {
+               $dowrite = 1;
                shift @ARGV;
        } else {
                last;
                shift @ARGV;
        } else {
                last;
@@ -108,12 +112,11 @@ while (($lib, $hdr) = each %hinc)
        }
 
        foreach (split /;/, $def) {
        }
 
        foreach (split /;/, $def) {
-               s/^[\n\s]*//g;
+           s/^[\n\s]*//g;
            s/[\n\s]*$//g;
            s/[\n\s]*$//g;
+           next if (/\w+\W+(\w+)\W*\(\s*\)$/s); # K&R C
            next if (/\(\*(\w*)\([^\)]+/);
            next if (/\(\*(\w*)\([^\)]+/);
-           next if (/\w+\W+(\w+)\W*\(\s*\)$/s);
            if (/\w+\W+\w+\W*\(.*\)$/s) {
            if (/\w+\W+\w+\W*\(.*\)$/s) {
-               s/\)[\s\n]*$/\)/s;
                while (not /\(\)$/s) {
                    s/[^\(\)]*\)$/\)/s;
                    s/\([^\(\)]*\)\)$/\)/s;
                while (not /\(\)$/s) {
                    s/[^\(\)]*\)$/\)/s;
                    s/\([^\(\)]*\)\)$/\)/s;
@@ -168,23 +171,28 @@ while (($lib, $hdr) = each %hinc)
 # oddly named structure BIO_F_CTX which needs to be ignored.
 # If a code doesn't exist in list compiled from headers then mark it
 # with the value "X" as a place holder to give it a value later.
 # oddly named structure BIO_F_CTX which needs to be ignored.
 # If a code doesn't exist in list compiled from headers then mark it
 # with the value "X" as a place holder to give it a value later.
+# Store all function and reason codes found in %ufcodes and %urcodes
+# so all those unreferenced can be printed out.
 
 
 foreach $file (@source) {
        # Don't parse the error source file.
        next if exists $cskip{$file};
 
 
 foreach $file (@source) {
        # Don't parse the error source file.
        next if exists $cskip{$file};
-       open(IN, "<$file") || die "Can't open source file $_\n";
+       open(IN, "<$file") || die "Can't open source file $file\n";
        while(<IN>) {
        while(<IN>) {
-               if(/(([A-Z0-9]+)_F_[A-Z0-9_]+)/) {
+               if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
                        next unless exists $csrc{$2};
                        next if($1 eq "BIO_F_BUFFER_CTX");
                        next unless exists $csrc{$2};
                        next if($1 eq "BIO_F_BUFFER_CTX");
+                       $ufcodes{$1} = 1;
                        if(!exists $fcodes{$1}) {
                                $fcodes{$1} = "X";
                                $fnew{$2}++;
                        }
                        if(!exists $fcodes{$1}) {
                                $fcodes{$1} = "X";
                                $fnew{$2}++;
                        }
+                       $notrans{$1} = 1 unless exists $ftrans{$3};
                }
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
                        next unless exists $csrc{$2};
                }
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
                        next unless exists $csrc{$2};
+                       $urcodes{$1} = 1;
                        if(!exists $rcodes{$1}) {
                                $rcodes{$1} = "X";
                                $rnew{$2}++;
                        if(!exists $rcodes{$1}) {
                                $rcodes{$1} = "X";
                                $rnew{$2}++;
@@ -206,7 +214,7 @@ foreach $lib (keys %csrc)
        } else {
                print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
                print STDERR " $rnew{$lib} New Reasons.\n";
        } else {
                print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
                print STDERR " $rnew{$lib} New Reasons.\n";
-
+               next unless $dowrite;
        }
 
        # If we get here then we have some new error codes so we
        }
 
        # If we get here then we have some new error codes so we
@@ -354,8 +362,6 @@ EOF
                $fn = $1;
                if(exists $ftrans{$fn}) {
                        $fn = $ftrans{$fn};
                $fn = $1;
                if(exists $ftrans{$fn}) {
                        $fn = $ftrans{$fn};
-               } else {
-                       push @notrans, $i;
                }
                print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
        }
                }
                print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
        }
@@ -417,7 +423,7 @@ static ERR_STRING_DATA ${lib}_lib_name[]=
 
 int ${lib}_lib_error_code=0;
 
 
 int ${lib}_lib_error_code=0;
 
-void ERR_load_${lib}_strings()
+void ERR_load_${lib}_strings(void)
        {
        static int init=1;
 
        {
        static int init=1;
 
@@ -439,11 +445,7 @@ void ERR_load_${lib}_strings()
                }
        }
 
                }
        }
 
-void ERR_${lib}_error(function,reason,file,line)
-int function;
-int reason;
-char *file;
-int line;
+void ERR_${lib}_error(int function, int reason, char *file, int line)
        {
        if (${lib}_lib_error_code == 0)
                ${lib}_lib_error_code=ERR_get_next_error_library();
        {
        if (${lib}_lib_error_code == 0)
                ${lib}_lib_error_code=ERR_get_next_error_library();
@@ -457,9 +459,35 @@ EOF
 
 }
 
 
 }
 
-if($debug && defined(@notrans)) {
+if($debug && defined(%notrans)) {
        print STDERR "The following function codes were not translated:\n";
        print STDERR "The following function codes were not translated:\n";
-       foreach(@notrans)
+       foreach(sort keys %notrans)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+# Make a list of unreferenced function and reason codes
+
+foreach (keys %fcodes) {
+       push (@funref, $_) unless exists $ufcodes{$_};
+}
+
+foreach (keys %rcodes) {
+       push (@runref, $_) unless exists $urcodes{$_};
+}
+
+if($debug && defined(@funref) ) {
+       print STDERR "The following function codes were not referenced:\n";
+       foreach(sort @funref)
+       {
+               print STDERR "$_\n";
+       }
+}
+
+if($debug && defined(@runref) ) {
+       print STDERR "The following reason codes were not referenced:\n";
+       foreach(sort @runref)
        {
                print STDERR "$_\n";
        }
        {
                print STDERR "$_\n";
        }