Run perltidy, use strict+warnings on mkrc.pl
[openssl.git] / util / mkdef.pl
1 #! /usr/bin/env perl
2 # Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 #
10 # generate a .def file
11 #
12 # It does this by parsing the header files and looking for the
13 # prototyped functions: it then prunes the output.
14 #
15 # Intermediary files are created, call libcrypto.num and libssl.num,
16 # The format of these files is:
17 #
18 #       routine-name    nnnn    vers    info
19 #
20 # The "nnnn" and "vers" fields are the numeric id and version for the symbol
21 # respectively. The "info" part is actually a colon-separated string of fields
22 # with the following meaning:
23 #
24 #       existence:platform:kind:algorithms
25 #
26 # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
27 #   found somewhere in the source,
28 # - "platforms" is empty if it exists on all platforms, otherwise it contains
29 #   comma-separated list of the platform, just as they are if the symbol exists
30 #   for those platforms, or prepended with a "!" if not.  This helps resolve
31 #   symbol name variants for platforms where the names are too long for the
32 #   compiler or linker, or if the systems is case insensitive and there is a
33 #   clash, or the symbol is implemented differently (see
34 #   EXPORT_VAR_AS_FUNCTION).  This script assumes renaming of symbols is found
35 #   in the file crypto/symhacks.h.
36 #   The semantics for the platforms is that every item is checked against the
37 #   environment.  For the negative items ("!FOO"), if any of them is false
38 #   (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
39 #   used.  For the positive itms, if all of them are false in the environment,
40 #   the corresponding symbol can't be used.  Any combination of positive and
41 #   negative items are possible, and of course leave room for some redundancy.
42 # - "kind" is "FUNCTION" or "VARIABLE".  The meaning of that is obvious.
43 # - "algorithms" is a comma-separated list of algorithm names.  This helps
44 #   exclude symbols that are part of an algorithm that some user wants to
45 #   exclude.
46 #
47
48 use lib ".";
49 use configdata;
50 use File::Spec::Functions;
51
52 my $debug=0;
53
54 my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
55 my $ssl_num=    catfile($config{sourcedir},"util","libssl.num");
56 my $libname;
57
58 my $do_update = 0;
59 my $do_rewrite = 1;
60 my $do_crypto = 0;
61 my $do_ssl = 0;
62 my $do_ctest = 0;
63 my $do_ctestall = 0;
64 my $do_checkexist = 0;
65
66 my $VMS=0;
67 my $W32=0;
68 my $NT=0;
69 my $linux=0;
70 # Set this to make typesafe STACK definitions appear in DEF
71 my $safe_stack_def = 0;
72
73 my @known_platforms = ( "__FreeBSD__", "PERL5",
74                         "EXPORT_VAR_AS_FUNCTION", "ZLIB", "_WIN32"
75                         );
76 my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
77 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
78                          "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
79                          "SHA256", "SHA512", "RMD160",
80                          "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
81                          "HMAC", "AES", "CAMELLIA", "SEED", "GOST", "ARIA",
82                          "SCRYPT", "CHACHA", "POLY1305", "BLAKE2",
83                          "SIPHASH",
84                          # EC_NISTP_64_GCC_128
85                          "EC_NISTP_64_GCC_128",
86                          # Envelope "algorithms"
87                          "EVP", "X509", "ASN1_TYPEDEFS",
88                          # Helper "algorithms"
89                          "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
90                          "LOCKING",
91                          # External "algorithms"
92                          "FP_API", "STDIO", "SOCK", "DGRAM",
93                          "CRYPTO_MDEBUG",
94                          # Engines
95                          "STATIC_ENGINE", "ENGINE", "HW", "GMP",
96                          # Entropy Gathering
97                          "EGD",
98                          # Certificate Transparency
99                          "CT",
100                          # RFC3779
101                          "RFC3779",
102                          # TLS
103                          "PSK", "SRP", "HEARTBEATS",
104                          # CMS
105                          "CMS",
106                          "OCSP",
107                          # CryptoAPI Engine
108                          "CAPIENG",
109                          # SSL methods
110                          "SSL3_METHOD", "TLS1_METHOD", "TLS1_1_METHOD", "TLS1_2_METHOD", "DTLS1_METHOD", "DTLS1_2_METHOD",
111                          # NEXTPROTONEG
112                          "NEXTPROTONEG",
113                          # Deprecated functions
114                          "DEPRECATEDIN_0_9_8",
115                          "DEPRECATEDIN_1_0_0",
116                          "DEPRECATEDIN_1_1_0",
117                          "DEPRECATEDIN_1_2_0",
118                          # SCTP
119                          "SCTP",
120                          # SRTP
121                          "SRTP",
122                          # SSL TRACE
123                          "SSL_TRACE",
124                          # Unit testing
125                          "UNIT_TEST",
126                          # User Interface
127                          "UI",
128                          #
129                          "TS",
130                          # OCB mode
131                          "OCB",
132                          "CMAC",
133                          # APPLINK (win build feature?)
134                          "APPLINK"
135                      );
136
137 my %disabled_algorithms;
138
139 foreach (@known_algorithms) {
140     $disabled_algorithms{$_} = 0;
141 }
142 # disabled by default
143 $disabled_algorithms{"STATIC_ENGINE"} = 1;
144
145 my $apiv = sprintf "%x%02x%02x", split(/\./, $config{api});
146 foreach (keys %disabled_algorithms) {
147         if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
148                 my $depv = sprintf "%x%02x%02x", $1, $2, $3;
149                 $disabled_algorithms{$_} = 1 if $apiv ge $depv;
150         }
151 }
152
153 my $zlib;
154
155 foreach (@ARGV, split(/ /, $config{options}))
156         {
157         $debug=1 if $_ eq "debug";
158         $W32=1 if $_ eq "32";
159         die "win16 not supported" if $_ eq "16";
160         if($_ eq "NT") {
161                 $W32 = 1;
162                 $NT = 1;
163         }
164         if ($_ eq "linux") {
165                 $linux=1;
166         }
167         $VMS=1 if $_ eq "VMS";
168         if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
169                          || $_ eq "enable-zlib-dynamic") {
170                 $zlib = 1;
171         }
172
173         $do_ssl=1 if $_ eq "libssl";
174         if ($_ eq "ssl") {
175                 $do_ssl=1;
176                 $libname=$_
177         }
178         $do_crypto=1 if $_ eq "libcrypto";
179         if ($_ eq "crypto") {
180                 $do_crypto=1;
181                 $libname=$_;
182         }
183         $do_update=1 if $_ eq "update";
184         $do_rewrite=1 if $_ eq "rewrite";
185         $do_ctest=1 if $_ eq "ctest";
186         $do_ctestall=1 if $_ eq "ctestall";
187         $do_checkexist=1 if $_ eq "exist";
188         if (/^(enable|disable|no)-(.*)$/) {
189                 my $alg = uc $2;
190                 $alg =~ tr/-/_/;
191                 if (exists $disabled_algorithms{$alg}) {
192                         $disabled_algorithms{$alg} = $1 eq "enable" ? 0 : 1;
193                 }
194         }
195
196         }
197
198 if (!$libname) {
199         if ($do_ssl) {
200                 $libname="LIBSSL";
201         }
202         if ($do_crypto) {
203                 $libname="LIBCRYPTO";
204         }
205 }
206
207 # If no platform is given, assume WIN32
208 if ($W32 + $VMS + $linux == 0) {
209         $W32 = 1;
210 }
211 die "Please, only one platform at a time"
212     if ($W32 + $VMS + $linux > 1);
213
214 if (!$do_ssl && !$do_crypto)
215         {
216         print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
217         exit(1);
218         }
219
220 %ssl_list=&load_numbers($ssl_num);
221 $max_ssl = $max_num;
222 %crypto_list=&load_numbers($crypto_num);
223 $max_crypto = $max_num;
224
225 my $ssl="include/openssl/ssl.h";
226 $ssl.=" include/openssl/tls1.h";
227 $ssl.=" include/openssl/srtp.h";
228
229 # We use headers found in include/openssl and include/internal only.
230 # The latter is needed so libssl.so/.dll/.exe can link properly.
231 my $crypto ="include/openssl/crypto.h";
232 $crypto.=" include/internal/o_dir.h";
233 $crypto.=" include/internal/o_str.h";
234 $crypto.=" include/internal/err.h";
235 $crypto.=" include/openssl/des.h" ; # unless $no_des;
236 $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
237 $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
238 $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
239 $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
240 $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
241 $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
242 $crypto.=" include/openssl/whrlpool.h" ;
243 $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
244 $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
245 $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
246 $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
247 $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
248 $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
249 $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
250 $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
251 $crypto.=" include/openssl/seed.h"; # unless $no_seed;
252
253 $crypto.=" include/openssl/bn.h";
254 $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
255 $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
256 $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
257 $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
258 $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
259 $crypto.=" include/openssl/cmac.h" ;
260
261 $crypto.=" include/openssl/engine.h"; # unless $no_engine;
262 $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
263 $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
264 $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
265 $crypto.=" include/internal/dso.h" ; # unless $no_dso;
266 $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
267 $crypto.=" include/openssl/conf.h";
268 $crypto.=" include/openssl/txt_db.h";
269
270 $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
271 $crypto.=" include/openssl/objects.h";
272 $crypto.=" include/openssl/pem.h";
273 #$crypto.=" include/openssl/meth.h";
274 $crypto.=" include/openssl/asn1.h";
275 $crypto.=" include/openssl/asn1t.h";
276 $crypto.=" include/openssl/err.h" ; # unless $no_err;
277 $crypto.=" include/openssl/pkcs7.h";
278 $crypto.=" include/openssl/pkcs12.h";
279 $crypto.=" include/openssl/x509.h";
280 $crypto.=" include/openssl/x509_vfy.h";
281 $crypto.=" include/openssl/x509v3.h";
282 $crypto.=" include/openssl/ts.h";
283 $crypto.=" include/openssl/rand.h";
284 $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
285 $crypto.=" include/openssl/ocsp.h";
286 $crypto.=" include/openssl/ui.h";
287 #$crypto.=" include/openssl/store.h";
288 $crypto.=" include/openssl/cms.h";
289 $crypto.=" include/openssl/srp.h";
290 $crypto.=" include/openssl/modes.h";
291 $crypto.=" include/openssl/async.h";
292 $crypto.=" include/openssl/ct.h";
293 $crypto.=" include/openssl/kdf.h";
294
295 my $symhacks="include/openssl/symhacks.h";
296
297 my @ssl_symbols = &do_defs("LIBSSL", $ssl, $symhacks);
298 my @crypto_symbols = &do_defs("LIBCRYPTO", $crypto, $symhacks);
299
300 if ($do_update) {
301
302 if ($do_ssl == 1) {
303
304         &maybe_add_info("LIBSSL",*ssl_list,@ssl_symbols);
305         if ($do_rewrite == 1) {
306                 open(OUT, ">$ssl_num");
307                 &rewrite_numbers(*OUT,"LIBSSL",*ssl_list,@ssl_symbols);
308         } else {
309                 open(OUT, ">>$ssl_num");
310         }
311         &update_numbers(*OUT,"LIBSSL",*ssl_list,$max_ssl,@ssl_symbols);
312         close OUT;
313 }
314
315 if($do_crypto == 1) {
316
317         &maybe_add_info("LIBCRYPTO",*crypto_list,@crypto_symbols);
318         if ($do_rewrite == 1) {
319                 open(OUT, ">$crypto_num");
320                 &rewrite_numbers(*OUT,"LIBCRYPTO",*crypto_list,@crypto_symbols);
321         } else {
322                 open(OUT, ">>$crypto_num");
323         }
324         &update_numbers(*OUT,"LIBCRYPTO",*crypto_list,$max_crypto,@crypto_symbols);
325         close OUT;
326 }
327
328 } elsif ($do_checkexist) {
329         &check_existing(*ssl_list, @ssl_symbols)
330                 if $do_ssl == 1;
331         &check_existing(*crypto_list, @crypto_symbols)
332                 if $do_crypto == 1;
333 } elsif ($do_ctest || $do_ctestall) {
334
335         print <<"EOF";
336
337 /* Test file to check all DEF file symbols are present by trying
338  * to link to all of them. This is *not* intended to be run!
339  */
340
341 int main()
342 {
343 EOF
344         &print_test_file(*STDOUT,"LIBSSL",*ssl_list,$do_ctestall,@ssl_symbols)
345                 if $do_ssl == 1;
346
347         &print_test_file(*STDOUT,"LIBCRYPTO",*crypto_list,$do_ctestall,@crypto_symbols)
348                 if $do_crypto == 1;
349
350         print "}\n";
351
352 } else {
353
354         &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
355                 if $do_ssl == 1;
356
357         &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
358                 if $do_crypto == 1;
359
360 }
361
362
363 sub do_defs
364 {
365         my($name,$files,$symhacksfile)=@_;
366         my $file;
367         my @ret;
368         my %syms;
369         my %platform;           # For anything undefined, we assume ""
370         my %kind;               # For anything undefined, we assume "FUNCTION"
371         my %algorithm;          # For anything undefined, we assume ""
372         my %variant;
373         my %variant_cnt;        # To be able to allocate "name{n}" if "name"
374                                 # is the same name as the original.
375         my $cpp;
376         my %unknown_algorithms = ();
377         my $parens = 0;
378
379         foreach $file (split(/\s+/,$symhacksfile." ".$files))
380                 {
381                 my $fn = catfile($config{sourcedir},$file);
382                 print STDERR "DEBUG: starting on $fn:\n" if $debug;
383                 open(IN,"<$fn") || die "unable to open $fn:$!\n";
384                 my $line = "", my $def= "";
385                 my %tag = (
386                         (map { $_ => 0 } @known_platforms),
387                         (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
388                         (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
389                         (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
390                         (grep /^DEPRECATED_/, @known_algorithms),
391                         NOPROTO         => 0,
392                         PERL5           => 0,
393                         _WINDLL         => 0,
394                         CONST_STRICT    => 0,
395                         TRUE            => 1,
396                 );
397                 my $symhacking = $file eq $symhacksfile;
398                 my @current_platforms = ();
399                 my @current_algorithms = ();
400
401                 # params: symbol, alias, platforms, kind
402                 # The reason to put this subroutine in a variable is that
403                 # it will otherwise create it's own, unshared, version of
404                 # %tag and %variant...
405                 my $make_variant = sub
406                 {
407                         my ($s, $a, $p, $k) = @_;
408                         my ($a1, $a2);
409
410                         print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
411                         if (defined($p))
412                         {
413                                 $a1 = join(",",$p,
414                                            grep(!/^$/,
415                                                 map { $tag{$_} == 1 ? $_ : "" }
416                                                 @known_platforms));
417                         }
418                         else
419                         {
420                                 $a1 = join(",",
421                                            grep(!/^$/,
422                                                 map { $tag{$_} == 1 ? $_ : "" }
423                                                 @known_platforms));
424                         }
425                         $a2 = join(",",
426                                    grep(!/^$/,
427                                         map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
428                                         @known_ossl_platforms));
429                         print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
430                         if ($a1 eq "") { $a1 = $a2; }
431                         elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
432                         if ($a eq $s)
433                         {
434                                 if (!defined($variant_cnt{$s}))
435                                 {
436                                         $variant_cnt{$s} = 0;
437                                 }
438                                 $variant_cnt{$s}++;
439                                 $a .= "{$variant_cnt{$s}}";
440                         }
441                         my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
442                         my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
443                         if (!grep(/^$togrep$/,
444                                   split(/;/, defined($variant{$s})?$variant{$s}:""))) {
445                                 if (defined($variant{$s})) { $variant{$s} .= ";"; }
446                                 $variant{$s} .= $toadd;
447                         }
448                         print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
449                 };
450
451                 print STDERR "DEBUG: parsing ----------\n" if $debug;
452                 while(<IN>) {
453                         if($parens > 0) {
454                                 #Inside a DEPRECATEDIN
455                                 $stored_multiline .= $_;
456                                 $stored_multiline =~ s|\R$||; # Better chomp
457                                 print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
458                                 $parens = count_parens($stored_multiline);
459                                 if ($parens == 0) {
460                                         $def .= do_deprecated($stored_multiline,
461                                                         \@current_platforms,
462                                                         \@current_algorithms);
463                                 }
464                                 next;
465                         }
466                         if (/\/\* Error codes for the \w+ functions\. \*\//)
467                                 {
468                                 undef @tag;
469                                 last;
470                                 }
471                         if ($line ne '') {
472                                 $_ = $line . $_;
473                                 $line = '';
474                         }
475
476                         if (/\\$/) {
477                                 $line = $`; # keep what was before the backslash
478                                 next;
479                         }
480
481                         if(/\/\*/) {
482                                 if (not /\*\//) {       # multiline comment...
483                                         $line = $_;     # ... just accumulate
484                                         next;
485                                 } else {
486                                         s/\/\*.*?\*\///gs;# wipe it
487                                 }
488                         }
489
490                         if ($cpp) {
491                                 $cpp++ if /^#\s*if/;
492                                 $cpp-- if /^#\s*endif/;
493                                 next;
494                         }
495                         if (/^#.*ifdef.*cplusplus/) {
496                                 $cpp = 1;
497                                 next;
498                         }
499
500                         s/{[^{}]*}//gs;                      # ignore {} blocks
501                         print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
502                         print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
503                         if (/^\#\s*if\s+OPENSSL_API_COMPAT\s*(\S)\s*(0x[0-9a-fA-F]{8})L\s*$/) {
504                                 my $op = $1;
505                                 my $v = hex($2);
506                                 if ($op ne '<' && $op ne '>=') {
507                                     die "$file unacceptable operator $op: $_\n";
508                                 }
509                                 my ($one, $major, $minor) =
510                                     ( ($v >> 28) & 0xf,
511                                       ($v >> 20) & 0xff,
512                                       ($v >> 12) & 0xff );
513                                 my $t = "DEPRECATEDIN_${one}_${major}_${minor}";
514                                 push(@tag,"-");
515                                 push(@tag,$t);
516                                 $tag{$t}=($op eq '<' ? 1 : -1);
517                                 print STDERR "DEBUG: $file: found tag $t = $tag{$t}\n" if $debug;
518                         } elsif (/^\#\s*ifndef\s+(.*)/) {
519                                 push(@tag,"-");
520                                 push(@tag,$1);
521                                 $tag{$1}=-1;
522                                 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
523                         } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
524                                 push(@tag,"-");
525                                 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
526                                         my $tmp_1 = $1;
527                                         my $tmp_;
528                                         foreach $tmp_ (split '\&\&',$tmp_1) {
529                                                 $tmp_ =~ /!defined\(([^\)]+)\)/;
530                                                 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
531                                                 push(@tag,$1);
532                                                 $tag{$1}=-1;
533                                         }
534                                 } else {
535                                         print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
536                                         print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
537                                         push(@tag,$1);
538                                         $tag{$1}=-1;
539                                 }
540                         } elsif (/^\#\s*ifdef\s+(\S*)/) {
541                                 push(@tag,"-");
542                                 push(@tag,$1);
543                                 $tag{$1}=1;
544                                 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
545                         } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
546                                 push(@tag,"-");
547                                 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
548                                         my $tmp_1 = $1;
549                                         my $tmp_;
550                                         foreach $tmp_ (split '\|\|',$tmp_1) {
551                                                 $tmp_ =~ /defined\(([^\)]+)\)/;
552                                                 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
553                                                 push(@tag,$1);
554                                                 $tag{$1}=1;
555                                         }
556                                 } else {
557                                         print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
558                                         print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
559                                         push(@tag,$1);
560                                         $tag{$1}=1;
561                                 }
562                         } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
563                                 my $tag_i = $#tag;
564                                 while($tag[$tag_i] ne "-") {
565                                         if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
566                                                 $tag{$tag[$tag_i]}=2;
567                                                 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
568                                         }
569                                         $tag_i--;
570                                 }
571                         } elsif (/^\#\s*endif/) {
572                                 my $tag_i = $#tag;
573                                 while($tag_i > 0 && $tag[$tag_i] ne "-") {
574                                         my $t=$tag[$tag_i];
575                                         print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
576                                         if ($tag{$t}==2) {
577                                                 $tag{$t}=-1;
578                                         } else {
579                                                 $tag{$t}=0;
580                                         }
581                                         print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
582                                         pop(@tag);
583                                         if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
584                                                 $t=$1;
585                                         } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
586                                                 $t=$1;
587                                         } else {
588                                                 $t="";
589                                         }
590                                         if ($t ne ""
591                                             && !grep(/^$t$/, @known_algorithms)) {
592                                                 $unknown_algorithms{$t} = 1;
593                                                 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
594                                         }
595                                         $tag_i--;
596                                 }
597                                 pop(@tag);
598                         } elsif (/^\#\s*else/) {
599                                 my $tag_i = $#tag;
600                                 die "$file unmatched else\n" if $tag_i < 0;
601                                 while($tag[$tag_i] ne "-") {
602                                         my $t=$tag[$tag_i];
603                                         $tag{$t}= -$tag{$t};
604                                         print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
605                                         $tag_i--;
606                                 }
607                         } elsif (/^\#\s*if\s+1/) {
608                                 push(@tag,"-");
609                                 # Dummy tag
610                                 push(@tag,"TRUE");
611                                 $tag{"TRUE"}=1;
612                                 print STDERR "DEBUG: $file: found 1\n" if $debug;
613                         } elsif (/^\#\s*if\s+0/) {
614                                 push(@tag,"-");
615                                 # Dummy tag
616                                 push(@tag,"TRUE");
617                                 $tag{"TRUE"}=-1;
618                                 print STDERR "DEBUG: $file: found 0\n" if $debug;
619                         } elsif (/^\#\s*if\s+/) {
620                                 #Some other unrecognized "if" style
621                                 push(@tag,"-");
622                         } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
623                                  && $symhacking && $tag{'TRUE'} != -1) {
624                                 # This is for aliasing.  When we find an alias,
625                                 # we have to invert
626                                 &$make_variant($1,$2);
627                                 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
628                         }
629                         if (/^\#/) {
630                                 @current_platforms =
631                                     grep(!/^$/,
632                                          map { $tag{$_} == 1 ? $_ :
633                                                    $tag{$_} == -1 ? "!".$_  : "" }
634                                          @known_platforms);
635                                 push @current_platforms
636                                     , grep(!/^$/,
637                                            map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
638                                                      $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_  : "" }
639                                            @known_ossl_platforms);
640                                 @current_algorithms = ();
641                                 @current_algorithms =
642                                     grep(!/^$/,
643                                          map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
644                                          @known_algorithms);
645                                 push @current_algorithms
646                                     , grep(!/^$/,
647                                          map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
648                                          @known_algorithms);
649                                 push @current_algorithms,
650                                     grep { /^DEPRECATEDIN_/ && $tag{$_} == 1 }
651                                     @known_algorithms;
652                                 $def .=
653                                     "#INFO:"
654                                         .join(',',@current_platforms).":"
655                                             .join(',',@current_algorithms).";";
656                                 next;
657                         }
658                         if ($tag{'TRUE'} != -1) {
659                                 if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
660                                                 || /^\s*DEFINE_STACK_OF_CONST\s*\(\s*(\w*)\s*\)/) {
661                                         next;
662                                 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
663                                         $def .= "int d2i_$3(void);";
664                                         $def .= "int i2d_$3(void);";
665                                         # Variant for platforms that do not
666                                         # have to access globale variables
667                                         # in shared libraries through functions
668                                         $def .=
669                                             "#INFO:"
670                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
671                                                     .join(',',@current_algorithms).";";
672                                         $def .= "OPENSSL_EXTERN int $2_it;";
673                                         $def .=
674                                             "#INFO:"
675                                                 .join(',',@current_platforms).":"
676                                                     .join(',',@current_algorithms).";";
677                                         # Variant for platforms that have to
678                                         # access globale variables in shared
679                                         # libraries through functions
680                                         &$make_variant("$2_it","$2_it",
681                                                       "EXPORT_VAR_AS_FUNCTION",
682                                                       "FUNCTION");
683                                         next;
684                                 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
685                                         $def .= "int d2i_$3(void);";
686                                         $def .= "int i2d_$3(void);";
687                                         $def .= "int $3_free(void);";
688                                         $def .= "int $3_new(void);";
689                                         # Variant for platforms that do not
690                                         # have to access globale variables
691                                         # in shared libraries through functions
692                                         $def .=
693                                             "#INFO:"
694                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
695                                                     .join(',',@current_algorithms).";";
696                                         $def .= "OPENSSL_EXTERN int $2_it;";
697                                         $def .=
698                                             "#INFO:"
699                                                 .join(',',@current_platforms).":"
700                                                     .join(',',@current_algorithms).";";
701                                         # Variant for platforms that have to
702                                         # access globale variables in shared
703                                         # libraries through functions
704                                         &$make_variant("$2_it","$2_it",
705                                                       "EXPORT_VAR_AS_FUNCTION",
706                                                       "FUNCTION");
707                                         next;
708                                 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
709                                          /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
710                                         $def .= "int d2i_$1(void);";
711                                         $def .= "int i2d_$1(void);";
712                                         $def .= "int $1_free(void);";
713                                         $def .= "int $1_new(void);";
714                                         # Variant for platforms that do not
715                                         # have to access globale variables
716                                         # in shared libraries through functions
717                                         $def .=
718                                             "#INFO:"
719                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
720                                                     .join(',',@current_algorithms).";";
721                                         $def .= "OPENSSL_EXTERN int $1_it;";
722                                         $def .=
723                                             "#INFO:"
724                                                 .join(',',@current_platforms).":"
725                                                     .join(',',@current_algorithms).";";
726                                         # Variant for platforms that have to
727                                         # access globale variables in shared
728                                         # libraries through functions
729                                         &$make_variant("$1_it","$1_it",
730                                                       "EXPORT_VAR_AS_FUNCTION",
731                                                       "FUNCTION");
732                                         next;
733                                 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
734                                         $def .= "int d2i_$2(void);";
735                                         $def .= "int i2d_$2(void);";
736                                         # Variant for platforms that do not
737                                         # have to access globale variables
738                                         # in shared libraries through functions
739                                         $def .=
740                                             "#INFO:"
741                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
742                                                     .join(',',@current_algorithms).";";
743                                         $def .= "OPENSSL_EXTERN int $2_it;";
744                                         $def .=
745                                             "#INFO:"
746                                                 .join(',',@current_platforms).":"
747                                                     .join(',',@current_algorithms).";";
748                                         # Variant for platforms that have to
749                                         # access globale variables in shared
750                                         # libraries through functions
751                                         &$make_variant("$2_it","$2_it",
752                                                       "EXPORT_VAR_AS_FUNCTION",
753                                                       "FUNCTION");
754                                         next;
755                                 } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
756                                         $def .= "int $1_free(void);";
757                                         $def .= "int $1_new(void);";
758                                         next;
759                                 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
760                                         $def .= "int d2i_$2(void);";
761                                         $def .= "int i2d_$2(void);";
762                                         $def .= "int $2_free(void);";
763                                         $def .= "int $2_new(void);";
764                                         # Variant for platforms that do not
765                                         # have to access globale variables
766                                         # in shared libraries through functions
767                                         $def .=
768                                             "#INFO:"
769                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
770                                                     .join(',',@current_algorithms).";";
771                                         $def .= "OPENSSL_EXTERN int $2_it;";
772                                         $def .=
773                                             "#INFO:"
774                                                 .join(',',@current_platforms).":"
775                                                     .join(',',@current_algorithms).";";
776                                         # Variant for platforms that have to
777                                         # access globale variables in shared
778                                         # libraries through functions
779                                         &$make_variant("$2_it","$2_it",
780                                                       "EXPORT_VAR_AS_FUNCTION",
781                                                       "FUNCTION");
782                                         next;
783                                 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
784                                         # Variant for platforms that do not
785                                         # have to access globale variables
786                                         # in shared libraries through functions
787                                         $def .=
788                                             "#INFO:"
789                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
790                                                     .join(',',@current_algorithms).";";
791                                         $def .= "OPENSSL_EXTERN int $1_it;";
792                                         $def .=
793                                             "#INFO:"
794                                                 .join(',',@current_platforms).":"
795                                                     .join(',',@current_algorithms).";";
796                                         # Variant for platforms that have to
797                                         # access globale variables in shared
798                                         # libraries through functions
799                                         &$make_variant("$1_it","$1_it",
800                                                       "EXPORT_VAR_AS_FUNCTION",
801                                                       "FUNCTION");
802                                         next;
803                                 } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
804                                         $def .= "int i2d_$1_NDEF(void);";
805                                 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
806                                         next;
807                                 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
808                                         $def .= "int $1_print_ctx(void);";
809                                         next;
810                                 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
811                                         $def .= "int $2_print_ctx(void);";
812                                         next;
813                                 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
814                                         next;
815                                 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
816                                          /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
817                                          /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
818                                         $def .=
819                                             "#INFO:"
820                                                 .join(',',@current_platforms).":"
821                                                     .join(',',"STDIO",@current_algorithms).";";
822                                         $def .= "int PEM_read_$1(void);";
823                                         $def .= "int PEM_write_$1(void);";
824                                         $def .=
825                                             "#INFO:"
826                                                 .join(',',@current_platforms).":"
827                                                     .join(',',@current_algorithms).";";
828                                         # Things that are everywhere
829                                         $def .= "int PEM_read_bio_$1(void);";
830                                         $def .= "int PEM_write_bio_$1(void);";
831                                         next;
832                                 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
833                                         /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
834                                          /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
835                                         $def .=
836                                             "#INFO:"
837                                                 .join(',',@current_platforms).":"
838                                                     .join(',',"STDIO",@current_algorithms).";";
839                                         $def .= "int PEM_write_$1(void);";
840                                         $def .=
841                                             "#INFO:"
842                                                 .join(',',@current_platforms).":"
843                                                     .join(',',@current_algorithms).";";
844                                         # Things that are everywhere
845                                         $def .= "int PEM_write_bio_$1(void);";
846                                         next;
847                                 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
848                                          /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
849                                         $def .=
850                                             "#INFO:"
851                                                 .join(',',@current_platforms).":"
852                                                     .join(',',"STDIO",@current_algorithms).";";
853                                         $def .= "int PEM_read_$1(void);";
854                                         $def .=
855                                             "#INFO:"
856                                                 .join(',',@current_platforms).":"
857                                                     .join(',',"STDIO",@current_algorithms).";";
858                                         # Things that are everywhere
859                                         $def .= "int PEM_read_bio_$1(void);";
860                                         next;
861                                 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
862                                         # Variant for platforms that do not
863                                         # have to access globale variables
864                                         # in shared libraries through functions
865                                         $def .=
866                                             "#INFO:"
867                                                 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
868                                                     .join(',',@current_algorithms).";";
869                                         $def .= "OPENSSL_EXTERN int _shadow_$2;";
870                                         $def .=
871                                             "#INFO:"
872                                                 .join(',',@current_platforms).":"
873                                                     .join(',',@current_algorithms).";";
874                                         # Variant for platforms that have to
875                                         # access globale variables in shared
876                                         # libraries through functions
877                                         &$make_variant("_shadow_$2","_shadow_$2",
878                                                       "EXPORT_VAR_AS_FUNCTION",
879                                                       "FUNCTION");
880                                 } elsif (/^\s*DEPRECATEDIN/) {
881                                         $parens = count_parens($_);
882                                         if ($parens == 0) {
883                                                 $def .= do_deprecated($_,
884                                                         \@current_platforms,
885                                                         \@current_algorithms);
886                                         } else {
887                                                 $stored_multiline = $_;
888                                                 $stored_multiline =~ s|\R$||;
889                                                 print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
890                                                 next;
891                                         }
892                                 } elsif ($tag{'CONST_STRICT'} != 1) {
893                                         if (/\{|\/\*|\([^\)]*$/) {
894                                                 $line = $_;
895                                         } else {
896                                                 $def .= $_;
897                                         }
898                                 }
899                         }
900                 }
901                 close(IN);
902                 die "$file: Unmatched tags\n" if $#tag >= 0;
903
904                 my $algs;
905                 my $plays;
906
907                 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
908                 foreach (split /;/, $def) {
909                         my $s; my $k = "FUNCTION"; my $p; my $a;
910                         s/^[\n\s]*//g;
911                         s/[\n\s]*$//g;
912                         next if(/\#undef/);
913                         next if(/typedef\W/);
914                         next if(/\#define/);
915
916                         # Reduce argument lists to empty ()
917                         # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
918                         while(/\(.*\)/s) {
919                                 s/\([^\(\)]+\)/\{\}/gs;
920                                 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
921                         }
922                         # pretend as we didn't use curly braces: {} -> ()
923                         s/\{\}/\(\)/gs;
924
925                         s/STACK_OF\(\)/void/gs;
926                         s/LHASH_OF\(\)/void/gs;
927
928                         print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
929                         if (/^\#INFO:([^:]*):(.*)$/) {
930                                 $plats = $1;
931                                 $algs = $2;
932                                 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
933                                 next;
934                         } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
935                                 $s = $1;
936                                 $k = "VARIABLE";
937                                 print STDERR "DEBUG: found external variable $s\n" if $debug;
938                         } elsif (/TYPEDEF_\w+_OF/s) {
939                                 next;
940                         } elsif (/(\w+)\s*\(\).*/s) {   # first token prior [first] () is
941                                 $s = $1;                # a function name!
942                                 print STDERR "DEBUG: found function $s\n" if $debug;
943                         } elsif (/\(/ and not (/=/)) {
944                                 print STDERR "File $file: cannot parse: $_;\n";
945                                 next;
946                         } else {
947                                 next;
948                         }
949
950                         $syms{$s} = 1;
951                         $kind{$s} = $k;
952
953                         $p = $plats;
954                         $a = $algs;
955
956                         $platform{$s} =
957                             &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
958                         $algorithm{$s} .= ','.$a;
959
960                         if (defined($variant{$s})) {
961                                 foreach $v (split /;/,$variant{$s}) {
962                                         (my $r, my $p, my $k) = split(/:/,$v);
963                                         my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
964                                         $syms{$r} = 1;
965                                         if (!defined($k)) { $k = $kind{$s}; }
966                                         $kind{$r} = $k."(".$s.")";
967                                         $algorithm{$r} = $algorithm{$s};
968                                         $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
969                                         $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
970                                         print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
971                                 }
972                         }
973                         print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
974                 }
975         }
976
977         # Prune the returned symbols
978
979         delete $syms{"bn_dump1"};
980         $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
981
982         $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
983         $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
984         $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
985         $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
986
987         # Info we know about
988
989         push @ret, map { $_."\\".&info_string($_,"EXIST",
990                                               $platform{$_},
991                                               $kind{$_},
992                                               $algorithm{$_}) } keys %syms;
993
994         if (keys %unknown_algorithms) {
995                 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
996                 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
997         }
998         return(@ret);
999 }
1000
1001 # Param: string of comma-separated platform-specs.
1002 sub reduce_platforms
1003 {
1004         my ($platforms) = @_;
1005         my $pl = defined($platforms) ? $platforms : "";
1006         my %p = map { $_ => 0 } split /,/, $pl;
1007         my $ret;
1008
1009         print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
1010             if $debug;
1011         # We do this, because if there's code like the following, it really
1012         # means the function exists in all cases and should therefore be
1013         # everywhere.  By increasing and decreasing, we may attain 0:
1014         #
1015         # ifndef WIN16
1016         #    int foo();
1017         # else
1018         #    int _fat foo();
1019         # endif
1020         foreach $platform (split /,/, $pl) {
1021                 if ($platform =~ /^!(.*)$/) {
1022                         $p{$1}--;
1023                 } else {
1024                         $p{$platform}++;
1025                 }
1026         }
1027         foreach $platform (keys %p) {
1028                 if ($p{$platform} == 0) { delete $p{$platform}; }
1029         }
1030
1031         delete $p{""};
1032
1033         $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
1034         print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1035             if $debug;
1036         return $ret;
1037 }
1038
1039 sub info_string
1040 {
1041         (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1042
1043         my %a = defined($algorithms) ?
1044             map { $_ => 1 } split /,/, $algorithms : ();
1045         my $k = defined($kind) ? $kind : "FUNCTION";
1046         my $ret;
1047         my $p = &reduce_platforms($platforms);
1048
1049         delete $a{""};
1050
1051         $ret = $exist;
1052         $ret .= ":".$p;
1053         $ret .= ":".$k;
1054         $ret .= ":".join(',',sort keys %a);
1055         return $ret;
1056 }
1057
1058 sub maybe_add_info
1059 {
1060         (my $name, *nums, my @symbols) = @_;
1061         my $sym;
1062         my $new_info = 0;
1063         my %syms=();
1064
1065         foreach $sym (@symbols) {
1066                 (my $s, my $i) = split /\\/, $sym;
1067                 if (defined($nums{$s})) {
1068                         $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1069                         (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
1070                         if (!defined($dummy) || $i ne $dummy) {
1071                                 $nums{$s} = $n."\\".$vers."\\".$i;
1072                                 $new_info++;
1073                                 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1074                         }
1075                 }
1076                 $syms{$s} = 1;
1077         }
1078
1079         my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1080         foreach $sym (@s) {
1081                 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1082                 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1083                         $new_info++;
1084                         print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1085                 }
1086         }
1087         if ($new_info) {
1088                 print STDERR "$name: $new_info old symbols have updated info\n";
1089                 if (!$do_rewrite) {
1090                         print STDERR "You should do a rewrite to fix this.\n";
1091                 }
1092         } else {
1093         }
1094 }
1095
1096 # Param: string of comma-separated keywords, each possibly prefixed with a "!"
1097 sub is_valid
1098 {
1099         my ($keywords_txt,$platforms) = @_;
1100         my (@keywords) = split /,/,$keywords_txt;
1101         my ($falsesum, $truesum) = (0, 1);
1102
1103         # Param: one keyword
1104         sub recognise
1105         {
1106                 my ($keyword,$platforms) = @_;
1107
1108                 if ($platforms) {
1109                         # platforms
1110                         if ($keyword eq "VMS" && $VMS) { return 1; }
1111                         if ($keyword eq "WIN32" && $W32) { return 1; }
1112                         if ($keyword eq "_WIN32" && $W32) { return 1; }
1113                         if ($keyword eq "WINNT" && $NT) { return 1; }
1114                         # Special platforms:
1115                         # EXPORT_VAR_AS_FUNCTION means that global variables
1116                         # will be represented as functions.
1117                         if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && $W32) {
1118                                 return 1;
1119                         }
1120                         if ($keyword eq "ZLIB" && $zlib) { return 1; }
1121                         return 0;
1122                 } else {
1123                         # algorithms
1124                         if ($disabled_algorithms{$keyword} == 1) { return 0;}
1125
1126                         # Nothing recognise as true
1127                         return 1;
1128                 }
1129         }
1130
1131         foreach $k (@keywords) {
1132                 if ($k =~ /^!(.*)$/) {
1133                         $falsesum += &recognise($1,$platforms);
1134                 } else {
1135                         $truesum *= &recognise($k,$platforms);
1136                 }
1137         }
1138         print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1139         return (!$falsesum) && $truesum;
1140 }
1141
1142 sub print_test_file
1143 {
1144         (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1145         my $n = 1; my @e; my @r;
1146         my $sym; my $prev = ""; my $prefSSLeay;
1147
1148         (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1149         (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1150         @symbols=((sort @e),(sort @r));
1151
1152         foreach $sym (@symbols) {
1153                 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1154                 my $v = 0;
1155                 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1156                 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1157                 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1158                 if (!defined($nums{$s})) {
1159                         print STDERR "Warning: $s does not have a number assigned\n"
1160                             if(!$do_update);
1161                 } elsif (is_valid($p,1) && is_valid($a,0)) {
1162                         my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1163                         if ($prev eq $s2) {
1164                                 print OUT "\t/* The following has already appeared previously */\n";
1165                                 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1166                         }
1167                         $prev = $s2;    # To warn about duplicates...
1168
1169                         (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
1170                         if ($v) {
1171                                 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1172                         } else {
1173                                 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1174                         }
1175                 }
1176         }
1177 }
1178
1179 sub get_version
1180 {
1181    return $config{version};
1182 }
1183
1184 sub print_def_file
1185 {
1186         (*OUT,my $name,*nums,my @symbols)=@_;
1187         my $n = 1; my @e; my @r; my @v; my $prev="";
1188         my $liboptions="";
1189         my $libname = $name;
1190         my $http_vendor = 'www.openssl.org/';
1191         my $version = get_version();
1192         my $what = "OpenSSL: implementation of Secure Socket Layer";
1193         my $description = "$what $version, $name - http://$http_vendor";
1194         my $prevsymversion = "", $prevprevsymversion = "";
1195         # For VMS
1196         my $prevnum = 0;
1197         my $symvtextcount = 0;
1198
1199         if ($W32)
1200                 { $libname.="32"; }
1201
1202         if ($W32)
1203                 {
1204                 print OUT <<"EOF";
1205 ;
1206 ; Definition file for the DLL version of the $name library from OpenSSL
1207 ;
1208
1209 LIBRARY         $libname        $liboptions
1210
1211 EOF
1212
1213                 print "EXPORTS\n";
1214                 }
1215         elsif ($VMS)
1216                 {
1217                 print OUT <<"EOF";
1218 CASE_SENSITIVE=YES
1219 SYMBOL_VECTOR=(-
1220 EOF
1221                 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1222                 }
1223
1224         (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1225         (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1226         if ($VMS) {
1227             # VMS needs to have the symbols on slot number order
1228             @symbols=(map { $_->[1] }
1229                       sort { $a->[0] <=> $b->[0] }
1230                       map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
1231                             die "Error: $s doesn't have a number assigned\n"
1232                                 if !defined($nums{$s});
1233                             (my $n, my @rest) = split /\\/, $nums{$s};
1234                             [ $n, $_ ] } (@e, @r, @v));
1235         } else {
1236             @symbols=((sort @e),(sort @r), (sort @v));
1237         }
1238
1239         my ($baseversion, $currversion) = get_openssl_version();
1240         my $thisversion;
1241         do {
1242                 if (!defined($thisversion)) {
1243                         $thisversion = $baseversion;
1244                 } else {
1245                         $thisversion = get_next_version($thisversion);
1246                 }
1247                 foreach $sym (@symbols) {
1248                         (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1249                         my $v = 0;
1250                         $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1251                         if (!defined($nums{$s})) {
1252                                 die "Error: $s does not have a number assigned\n"
1253                                         if(!$do_update);
1254                         } else {
1255                                 (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
1256                                 next if $symversion ne $thisversion;
1257                                 my %pf = ();
1258                                 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1259                                 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1260                                 if (is_valid($p,1) && is_valid($a,0)) {
1261                                         my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1262                                         if ($prev eq $s2) {
1263                                                 print STDERR "Warning: Symbol '",$s2,
1264                                                         "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
1265                                                         ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1266                                         }
1267                                         $prev = $s2;    # To warn about duplicates...
1268                                         if($linux) {
1269                                                 if ($symversion ne $prevsymversion) {
1270                                                         if ($prevsymversion ne "") {
1271                                                                 if ($prevprevsymversion ne "") {
1272                                                                         print OUT "} OPENSSL_"
1273                                                                                                 ."$prevprevsymversion;\n\n";
1274                                                                 } else {
1275                                                                         print OUT "};\n\n";
1276                                                                 }
1277                                                         }
1278                                                         print OUT "OPENSSL_$symversion {\n    global:\n";
1279                                                         $prevprevsymversion = $prevsymversion;
1280                                                         $prevsymversion = $symversion;
1281                                                 }
1282                                                 print OUT "        $s2;\n";
1283                                         } elsif ($VMS) {
1284                                             while(++$prevnum < $n) {
1285                                                 my $symline=" ,SPARE -\n  ,SPARE -\n";
1286                                                 if ($symvtextcount + length($symline) - 2 > 1024) {
1287                                                     print OUT ")\nSYMBOL_VECTOR=(-\n";
1288                                                     $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1289                                                 }
1290                                                 if ($symvtextcount == 16) {
1291                                                     # Take away first comma
1292                                                     $symline =~ s/,//;
1293                                                 }
1294                                                 print OUT $symline;
1295                                                 $symvtextcount += length($symline) - 2;
1296                                             }
1297                                             (my $s_uc = $s) =~ tr/a-z/A-Z/;
1298                                             my $symtype=
1299                                                 $v ? "DATA" : "PROCEDURE";
1300                                             my $symline=
1301                                                 ($s_uc ne $s
1302                                                  ? " ,$s_uc/$s=$symtype -\n  ,$s=$symtype -\n"
1303                                                  : " ,$s=$symtype -\n  ,SPARE -\n");
1304                                             if ($symvtextcount + length($symline) - 2 > 1024) {
1305                                                 print OUT ")\nSYMBOL_VECTOR=(-\n";
1306                                                 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1307                                             }
1308                                             if ($symvtextcount == 16) {
1309                                                 # Take away first comma
1310                                                 $symline =~ s/,//;
1311                                             }
1312                                             print OUT $symline;
1313                                             $symvtextcount += length($symline) - 2;
1314                                         } elsif($v) {
1315                                                 printf OUT "    %s%-39s DATA\n",
1316                                                                 ($W32)?"":"_",$s2;
1317                                         } else {
1318                                                 printf OUT "    %s%s\n",
1319                                                                 ($W32)?"":"_",$s2;
1320                                         }
1321                                 }
1322                         }
1323                 }
1324         } while ($thisversion ne $currversion);
1325         if ($linux) {
1326                 if ($prevprevsymversion ne "") {
1327                         print OUT "    local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
1328                 } else {
1329                         print OUT "    local: *;\n};\n\n";
1330                 }
1331         } elsif ($VMS) {
1332             print OUT ")\n";
1333             (my $libvmaj, my $libvmin, my $libvedit) =
1334                 $currversion =~ /^(\d+)_(\d+)_(\d+)$/;
1335             # The reason to multiply the edit number with 100 is to make space
1336             # for the possibility that we want to encode the patch letters
1337             print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
1338         }
1339         printf OUT "\n";
1340 }
1341
1342 sub load_numbers
1343 {
1344         my($name)=@_;
1345         my(@a,%ret);
1346         my $prevversion;
1347
1348         $max_num = 0;
1349         $num_noinfo = 0;
1350         $prev = "";
1351         $prev_cnt = 0;
1352
1353         my ($baseversion, $currversion) = get_openssl_version();
1354
1355         open(IN,"<$name") || die "unable to open $name:$!\n";
1356         while (<IN>) {
1357                 s|\R$||;        # Better chomp
1358                 s/#.*$//;
1359                 next if /^\s*$/;
1360                 @a=split;
1361                 if (defined $ret{$a[0]}) {
1362                         # This is actually perfectly OK
1363                         #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1364                 }
1365                 if ($max_num > $a[1]) {
1366                         print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1367                 }
1368                 elsif ($max_num == $a[1]) {
1369                         # This is actually perfectly OK
1370                         #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1371                         if ($a[0] eq $prev) {
1372                                 $prev_cnt++;
1373                                 $a[0] .= "{$prev_cnt}";
1374                         }
1375                 }
1376                 else {
1377                         $prev_cnt = 0;
1378                 }
1379                 if ($#a < 2) {
1380                         # Existence will be proven later, in do_defs
1381                         $ret{$a[0]}=$a[1];
1382                         $num_noinfo++;
1383                 } else {
1384                         #Sanity check the version number
1385                         if (defined $prevversion) {
1386                                 check_version_lte($prevversion, $a[2]);
1387                         }
1388                         check_version_lte($a[2], $currversion);
1389                         $prevversion = $a[2];
1390                         $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
1391                 }
1392                 $max_num = $a[1] if $a[1] > $max_num;
1393                 $prev=$a[0];
1394         }
1395         if ($num_noinfo) {
1396                 print STDERR "Warning: $num_noinfo symbols were without info.";
1397                 if ($do_rewrite) {
1398                         printf STDERR "  The rewrite will fix this.\n";
1399                 } else {
1400                         printf STDERR "  You should do a rewrite to fix this.\n";
1401                 }
1402         }
1403         close(IN);
1404         return(%ret);
1405 }
1406
1407 sub parse_number
1408 {
1409         (my $str, my $what) = @_;
1410         (my $n, my $v, my $i) = split(/\\/,$str);
1411         if ($what eq "n") {
1412                 return $n;
1413         } else {
1414                 return $i;
1415         }
1416 }
1417
1418 sub rewrite_numbers
1419 {
1420         (*OUT,$name,*nums,@symbols)=@_;
1421         my $thing;
1422
1423         my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1424         my $r; my %r; my %rsyms;
1425         foreach $r (@r) {
1426                 (my $s, my $i) = split /\\/, $r;
1427                 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1428                 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1429                 $r{$a} = $s."\\".$i;
1430                 $rsyms{$s} = 1;
1431         }
1432
1433         my %syms = ();
1434         foreach $_ (@symbols) {
1435                 (my $n, my $i) = split /\\/;
1436                 $syms{$n} = 1;
1437         }
1438
1439         my @s=sort {
1440             &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1441             || $a cmp $b
1442         } keys %nums;
1443         foreach $sym (@s) {
1444                 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1445                 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1446                 next if defined($rsyms{$sym});
1447                 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1448                 $i="NOEXIST::FUNCTION:"
1449                         if !defined($i) || $i eq "" || !defined($syms{$sym});
1450                 my $s2 = $sym;
1451                 $s2 =~ s/\{[0-9]+\}$//;
1452                 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1453                 if (exists $r{$sym}) {
1454                         (my $s, $i) = split /\\/,$r{$sym};
1455                         my $s2 = $s;
1456                         $s2 =~ s/\{[0-9]+\}$//;
1457                         printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1458                 }
1459         }
1460 }
1461
1462 sub update_numbers
1463 {
1464         (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1465         my $new_syms = 0;
1466         my $basevers;
1467         my $vers;
1468
1469         ($basevers, $vers) = get_openssl_version();
1470
1471         my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1472         my $r; my %r; my %rsyms;
1473         foreach $r (@r) {
1474                 (my $s, my $i) = split /\\/, $r;
1475                 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1476                 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1477                 $r{$a} = $s."\\".$i;
1478                 $rsyms{$s} = 1;
1479         }
1480
1481         foreach $sym (@symbols) {
1482                 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1483                 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1484                 next if defined($rsyms{$sym});
1485                 die "ERROR: Symbol $sym had no info attached to it."
1486                     if $i eq "";
1487                 if (!exists $nums{$s}) {
1488                         $new_syms++;
1489                         my $s2 = $s;
1490                         $s2 =~ s/\{[0-9]+\}$//;
1491                         printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
1492                         if (exists $r{$s}) {
1493                                 ($s, $i) = split /\\/,$r{$s};
1494                                 $s =~ s/\{[0-9]+\}$//;
1495                                 printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
1496                         }
1497                 }
1498         }
1499         if($new_syms) {
1500                 print STDERR "$name: Added $new_syms new symbols\n";
1501         } else {
1502                 print STDERR "$name: No new symbols added\n";
1503         }
1504 }
1505
1506 sub check_existing
1507 {
1508         (*nums, my @symbols)=@_;
1509         my %existing; my @remaining;
1510         @remaining=();
1511         foreach $sym (@symbols) {
1512                 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1513                 $existing{$s}=1;
1514         }
1515         foreach $sym (keys %nums) {
1516                 if (!exists $existing{$sym}) {
1517                         push @remaining, $sym;
1518                 }
1519         }
1520         if(@remaining) {
1521                 print STDERR "The following symbols do not seem to exist:\n";
1522                 foreach $sym (@remaining) {
1523                         print STDERR "\t",$sym,"\n";
1524                 }
1525         }
1526 }
1527
1528 sub count_parens
1529 {
1530         my $line = shift(@_);
1531
1532         my $open = $line =~ tr/\(//;
1533         my $close = $line =~ tr/\)//;
1534
1535         return $open - $close;
1536 }
1537
1538 #Parse opensslv.h to get the current version number. Also work out the base
1539 #version, i.e. the lowest version number that is binary compatible with this
1540 #version
1541 sub get_openssl_version()
1542 {
1543         my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
1544         open (IN, "$fn") || die "Can't open opensslv.h";
1545
1546         while(<IN>) {
1547                 if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
1548                         my $suffix = $2;
1549                         (my $baseversion = $1) =~ s/\./_/g;
1550                         close IN;
1551                         return ($baseversion."0", $baseversion.$suffix);
1552                 }
1553         }
1554         die "Can't find OpenSSL version number\n";
1555 }
1556
1557 #Given an OpenSSL version number, calculate the next version number. If the
1558 #version number gets to a.b.czz then we go to a.b.(c+1)
1559 sub get_next_version()
1560 {
1561         my $thisversion = shift;
1562
1563         my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
1564
1565         if ($letter eq "zz") {
1566                 my $lastnum = substr($base, -1);
1567                 return substr($base, 0, length($base)-1).(++$lastnum);
1568         }
1569         return $base.get_next_letter($letter);
1570 }
1571
1572 #Given the letters off the end of an OpenSSL version string, calculate what
1573 #the letters for the next release would be.
1574 sub get_next_letter()
1575 {
1576         my $thisletter = shift;
1577         my $baseletter = "";
1578         my $endletter;
1579
1580         if ($thisletter eq "") {
1581                 return "a";
1582         }
1583         if ((length $thisletter) > 1) {
1584                 ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
1585         } else {
1586                 $endletter = $thisletter;
1587         }
1588
1589         if ($endletter eq "z") {
1590                 return $thisletter."a";
1591         } else {
1592                 return $baseletter.(++$endletter);
1593         }
1594 }
1595
1596 #Check if a version is less than or equal to the current version. Its a fatal
1597 #error if not. They must also only differ in letters, or the last number (i.e.
1598 #the first two numbers must be the same)
1599 sub check_version_lte()
1600 {
1601         my ($testversion, $currversion) = @_;
1602         my $lentv;
1603         my $lencv;
1604         my $cvbase;
1605
1606         my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
1607         my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
1608
1609         #Die if we can't parse the version numbers or they don't look sane
1610         die "Invalid version number: $testversion and $currversion\n"
1611                 if (!defined($cvnums) || !defined($tvnums)
1612                         || length($cvnums) != 5
1613                         || length($tvnums) != 5);
1614
1615         #If the base versions (without letters) don't match check they only differ
1616         #in the last number
1617         if ($cvnums ne $tvnums) {
1618                 die "Invalid version number: $testversion "
1619                         ."for current version $currversion\n"
1620                         if (substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
1621                 return;
1622         }
1623         #If we get here then the base version (i.e. the numbers) are the same - they
1624         #only differ in the letters
1625
1626         $lentv = length $testversion;
1627         $lencv = length $currversion;
1628
1629         #If the testversion has more letters than the current version then it must
1630         #be later (or malformed)
1631         if ($lentv > $lencv) {
1632                 die "Invalid version number: $testversion "
1633                         ."is greater than $currversion\n";
1634         }
1635
1636         #Get the last letter from the current version
1637         my ($cvletter) = $currversion =~ /([a-z])$/;
1638         if (defined $cvletter) {
1639                 ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
1640         } else {
1641                 $cvbase = $currversion;
1642         }
1643         die "Unable to parse version number $currversion" if (!defined $cvbase);
1644         my $tvbase;
1645         my ($tvletter) = $testversion =~ /([a-z])$/;
1646         if (defined $tvletter) {
1647                 ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
1648         } else {
1649                 $tvbase = $testversion;
1650         }
1651         die "Unable to parse version number $testversion" if (!defined $tvbase);
1652
1653         if ($lencv > $lentv) {
1654                 #If current version has more letters than testversion then testversion
1655                 #minus the final letter must be a substring of the current version
1656                 die "Invalid version number $testversion "
1657                         ."is greater than $currversion or is invalid\n"
1658                         if (index($cvbase, $tvbase) != 0);
1659         } else {
1660                 #If both versions have the same number of letters then they must be
1661                 #equal up to the last letter, and the last letter in testversion must
1662                 #be less than or equal to the last letter in current version.
1663                 die "Invalid version number $testversion "
1664                         ."is greater than $currversion\n"
1665                         if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
1666         }
1667 }
1668
1669 sub do_deprecated()
1670 {
1671         my ($decl, $plats, $algs) = @_;
1672         $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
1673             or die "Bad DEPRECTEDIN: $decl\n";
1674         my $info1 .= "#INFO:";
1675         $info1 .= join(',', @{$plats}) . ":";
1676         my $info2 = $info1;
1677         $info1 .= join(',',@{$algs}, $1) . ";";
1678         $info2 .= join(',',@{$algs}) . ";";
1679         return $info1 . $2 . ";" . $info2;
1680 }