apps/progs.pl: more consistent output for digests
[openssl.git] / apps / progs.pl
1 #!/usr/bin/perl
2 # Generate progs.h file by looking for command mains in list of C files
3 # passed on the command line.
4
5 use strict;
6 use warnings;
7
8 my %commands = ();
9 my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
10
11 foreach my $filename (@ARGV) {
12         open F, $filename or die "Coudn't open $_: $!\n";
13         foreach (grep /$cmdre/, <F>) {
14                 my @foo = /$cmdre/;
15                 $commands{$1} = 1;
16         }
17         close F;
18 }
19
20 @ARGV = sort keys %commands;
21
22 print <<'EOF';
23 /*
24  * Automatically generated by progs.pl for openssl.c
25  * Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
26  * See the openssl.c for copyright details.
27  */
28
29 typedef enum FUNC_TYPE {
30     FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
31     FT_md_alg, FT_cipher_alg
32 } FUNC_TYPE;
33
34 typedef struct function_st {
35     FUNC_TYPE type;
36     const char *name;
37     int (*func)(int argc,char *argv[]);
38     const OPTIONS *help;
39 } FUNCTION;
40
41 DEFINE_LHASH_OF(FUNCTION);
42
43 EOF
44
45 foreach (@ARGV) {
46         printf "extern int %s_main(int argc, char *argv[]);\n", $_;
47 }
48
49 print "\n";
50
51 foreach (@ARGV) {
52         printf "extern OPTIONS %s_options[];\n", $_;
53 }
54 print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
55 print "static FUNCTION functions[] = {\n";
56 foreach (@ARGV) {
57         my $str="    { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
58         if (/^s_/ || /^ciphers$/) {
59                 print "#if !defined(OPENSSL_NO_SOCK)\n${str}#endif\n";
60         } elsif (/^engine$/) {
61                 print "#ifndef OPENSSL_NO_ENGINE\n${str}#endif\n";
62         } elsif (/^rsa$/ || /^genrsa$/ || /^rsautl$/) {
63                 print "#ifndef OPENSSL_NO_RSA\n${str}#endif\n";
64         } elsif (/^dsa$/ || /^gendsa$/ || /^dsaparam$/) {
65                 print "#ifndef OPENSSL_NO_DSA\n${str}#endif\n";
66         } elsif (/^ec$/ || /^ecparam$/) {
67                 print "#ifndef OPENSSL_NO_EC\n${str}#endif\n";
68         } elsif (/^dh$/ || /^gendh$/ || /^dhparam$/) {
69                 print "#ifndef OPENSSL_NO_DH\n${str}#endif\n";
70         } elsif (/^pkcs12$/) {
71                 print "#if !defined(OPENSSL_NO_DES)\n${str}#endif\n";
72         } elsif (/^cms$/) {
73                 print "#ifndef OPENSSL_NO_CMS\n${str}#endif\n";
74         } elsif (/^ocsp$/) {
75                 print "#ifndef OPENSSL_NO_OCSP\n${str}#endif\n";
76         } elsif (/^srp$/) {
77                 print "#ifndef OPENSSL_NO_SRP\n${str}#endif\n";
78         } else {
79                 print $str;
80         }
81 }
82
83 foreach (
84         "md2", "md4", "md5",
85         "md_ghost94",
86         "sha1", "sha224", "sha256", "sha384", "sha512",
87         "mdc2", "rmd160", "blake2b512", "blake2s256"
88 ) {
89         my $str = "    { FT_md, \"".$_."\", dgst_main},\n";
90         if (/blake2/) {
91                 print "#ifndef OPENSSL_NO_BLAKE2\n${str}#endif\n";
92         } elsif (/sha/) {
93                 print "${str}";
94         } else {
95                 print "#ifndef OPENSSL_NO_".uc($_)."\n${str}#endif\n";
96         }
97 }
98
99 foreach (
100         "aes-128-cbc", "aes-128-ecb",
101         "aes-192-cbc", "aes-192-ecb",
102         "aes-256-cbc", "aes-256-ecb",
103         "camellia-128-cbc", "camellia-128-ecb",
104         "camellia-192-cbc", "camellia-192-ecb",
105         "camellia-256-cbc", "camellia-256-ecb",
106         "base64", "zlib",
107         "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
108         "rc2", "bf", "cast", "rc5",
109         "des-ecb", "des-ede",    "des-ede3",
110         "des-cbc", "des-ede-cbc","des-ede3-cbc",
111         "des-cfb", "des-ede-cfb","des-ede3-cfb",
112         "des-ofb", "des-ede-ofb","des-ede3-ofb",
113         "idea-cbc","idea-ecb",    "idea-cfb", "idea-ofb",
114         "seed-cbc","seed-ecb",    "seed-cfb", "seed-ofb",
115         "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
116         "bf-cbc",  "bf-ecb",     "bf-cfb",   "bf-ofb",
117         "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
118         "cast-cbc", "rc5-cbc",   "rc5-ecb",  "rc5-cfb",  "rc5-ofb"
119 ) {
120         my $str="    { FT_cipher, \"$_\", enc_main, enc_options },\n";
121         if (/des/) {
122                 printf "#ifndef OPENSSL_NO_DES\n${str}#endif\n";
123         } elsif (/aes/) {
124                 printf "#ifndef OPENSSL_NO_AES\n${str}#endif\n";
125         } elsif (/camellia/) {
126                 printf "#ifndef OPENSSL_NO_CAMELLIA\n${str}#endif\n";
127         } elsif (/idea/) {
128                 printf "#ifndef OPENSSL_NO_IDEA\n${str}#endif\n";
129         } elsif (/seed/) {
130                 printf "#ifndef OPENSSL_NO_SEED\n${str}#endif\n";
131         } elsif (/rc4/) {
132                 printf "#ifndef OPENSSL_NO_RC4\n${str}#endif\n";
133         } elsif (/rc2/) {
134                 printf "#ifndef OPENSSL_NO_RC2\n${str}#endif\n";
135         } elsif (/bf/) {
136                 printf "#ifndef OPENSSL_NO_BF\n${str}#endif\n";
137         } elsif (/cast/) {
138                 printf "#ifndef OPENSSL_NO_CAST\n${str}#endif\n";
139         } elsif (/rc5/) {
140                 printf "#ifndef OPENSSL_NO_RC5\n${str}#endif\n";
141         } elsif (/zlib/) {
142                 printf "#ifdef ZLIB\n${str}#endif\n";
143         } else {
144                 print $str;
145         }
146 }
147
148 print "    { 0, NULL, NULL}\n};\n";
149 printf "#endif\n";