apps/progs.pl: more consistent output for digests
[openssl.git] / apps / progs.pl
index 38e091e26eddfd328cb1dc8ed81a3b3478b280ff..b601fefb1b4bce59956dddd4ab69af52eb229df1 100644 (file)
@@ -1,5 +1,23 @@
-#!/usr/local/bin/perl
-# Generate progs.h file from list of "programs" passed on the command line.
+#!/usr/bin/perl
+# Generate progs.h file by looking for command mains in list of C files
+# passed on the command line.
+
+use strict;
+use warnings;
+
+my %commands = ();
+my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
+
+foreach my $filename (@ARGV) {
+       open F, $filename or die "Coudn't open $_: $!\n";
+       foreach (grep /$cmdre/, <F>) {
+               my @foo = /$cmdre/;
+               $commands{$1} = 1;
+       }
+       close F;
+}
+
+@ARGV = sort keys %commands;
 
 print <<'EOF';
 /*
@@ -20,26 +38,23 @@ typedef struct function_st {
     const OPTIONS *help;
 } FUNCTION;
 
-EOF
+DEFINE_LHASH_OF(FUNCTION);
 
-grep(s/\.o//, @ARGV);
-grep(s/^asn1pars$/asn1parse/, @ARGV);
-grep(s/^crl2p7$/crl2pkcs7/, @ARGV);
-push @ARGV, 'list';
-push @ARGV, 'help';
-push @ARGV, 'exit';
+EOF
 
 foreach (@ARGV) {
        printf "extern int %s_main(int argc, char *argv[]);\n", $_;
 }
 
-printf "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
+print "\n";
+
 foreach (@ARGV) {
        printf "extern OPTIONS %s_options[];\n", $_;
 }
-printf "FUNCTION functions[] = {\n";
+print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
+print "static FUNCTION functions[] = {\n";
 foreach (@ARGV) {
-       $str="    { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
+       my $str="    { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
        if (/^s_/ || /^ciphers$/) {
                print "#if !defined(OPENSSL_NO_SOCK)\n${str}#endif\n";
        } elsif (/^engine$/) {
@@ -68,12 +83,17 @@ foreach (@ARGV) {
 foreach (
        "md2", "md4", "md5",
        "md_ghost94",
-       "sha", "sha1", "sha224", "sha256", "sha384", "sha512",
-       "mdc2", "rmd160"
+       "sha1", "sha224", "sha256", "sha384", "sha512",
+       "mdc2", "rmd160", "blake2b512", "blake2s256"
 ) {
-        printf "#ifndef OPENSSL_NO_".uc($_)."\n" if ! /sha/;
-        printf "    { FT_md, \"".$_."\", dgst_main},\n";
-        printf "#endif\n" if ! /sha/;
+        my $str = "    { FT_md, \"".$_."\", dgst_main},\n";
+        if (/blake2/) {
+                print "#ifndef OPENSSL_NO_BLAKE2\n${str}#endif\n";
+        } elsif (/sha/) {
+                print "${str}";
+        } else {
+                print "#ifndef OPENSSL_NO_".uc($_)."\n${str}#endif\n";
+        }
 }
 
 foreach (
@@ -97,7 +117,7 @@ foreach (
        "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
        "cast-cbc", "rc5-cbc",   "rc5-ecb",  "rc5-cfb",  "rc5-ofb"
 ) {
-       $str="    { FT_cipher, \"$_\", enc_main, enc_options },\n";
+       my $str="    { FT_cipher, \"$_\", enc_main, enc_options },\n";
        if (/des/) {
                printf "#ifndef OPENSSL_NO_DES\n${str}#endif\n";
        } elsif (/aes/) {