mkdef.pl revision 298999
11590Srgrimes#!/usr/local/bin/perl -w
21590Srgrimes#
31590Srgrimes# generate a .def file
41590Srgrimes#
51590Srgrimes# It does this by parsing the header files and looking for the
61590Srgrimes# prototyped functions: it then prunes the output.
71590Srgrimes#
81590Srgrimes# Intermediary files are created, call libeay.num and ssleay.num,...
91590Srgrimes# Previously, they had the following format:
101590Srgrimes#
111590Srgrimes#	routine-name	nnnn
121590Srgrimes#
131590Srgrimes# But that isn't enough for a number of reasons, the first on being that
141590Srgrimes# this format is (needlessly) very Win32-centric, and even then...
151590Srgrimes# One of the biggest problems is that there's no information about what
161590Srgrimes# routines should actually be used, which varies with what crypto algorithms
171590Srgrimes# are disabled.  Also, some operating systems (for example VMS with VAX C)
181590Srgrimes# need to keep track of the global variables as well as the functions.
191590Srgrimes#
201590Srgrimes# So, a remake of this script is done so as to include information on the
211590Srgrimes# kind of symbol it is (function or variable) and what algorithms they're
221590Srgrimes# part of.  This will allow easy translating to .def files or the corresponding
231590Srgrimes# file in other operating systems (a .opt file for VMS, possibly with a .mar
241590Srgrimes# file).
251590Srgrimes#
261590Srgrimes# The format now becomes:
271590Srgrimes#
281590Srgrimes#	routine-name	nnnn	info
291590Srgrimes#
301590Srgrimes# and the "info" part is actually a colon-separated string of fields with
311590Srgrimes# the following meaning:
321590Srgrimes#
331590Srgrimes#	existence:platform:kind:algorithms
341590Srgrimes#
351590Srgrimes# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
361590Srgrimes#   found somewhere in the source,
371590Srgrimes# - "platforms" is empty if it exists on all platforms, otherwise it contains
381590Srgrimes#   comma-separated list of the platform, just as they are if the symbol exists
391590Srgrimes#   for those platforms, or prepended with a "!" if not.  This helps resolve
401590Srgrimes#   symbol name variants for platforms where the names are too long for the
411590Srgrimes#   compiler or linker, or if the systems is case insensitive and there is a
421590Srgrimes#   clash, or the symbol is implemented differently (see
431590Srgrimes#   EXPORT_VAR_AS_FUNCTION).  This script assumes renaming of symbols is found
4461575Sroberto#   in the file crypto/symhacks.h.
4523695Speter#   The semantics for the platforms is that every item is checked against the
4661575Sroberto#   environment.  For the negative items ("!FOO"), if any of them is false
4761575Sroberto#   (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
4861575Sroberto#   used.  For the positive itms, if all of them are false in the environment,
4961575Sroberto#   the corresponding symbol can't be used.  Any combination of positive and
501590Srgrimes#   negative items are possible, and of course leave room for some redundancy.
511590Srgrimes# - "kind" is "FUNCTION" or "VARIABLE".  The meaning of that is obvious.
521590Srgrimes# - "algorithms" is a comma-separated list of algorithm names.  This helps
531590Srgrimes#   exclude symbols that are part of an algorithm that some user wants to
541590Srgrimes#   exclude.
551590Srgrimes#
561590Srgrimes
571590Srgrimesmy $debug=0;
581590Srgrimes
5917534Sachemy $crypto_num= "util/libeay.num";
6072945Sknumy $ssl_num=    "util/ssleay.num";
611590Srgrimesmy $libname;
621590Srgrimes
631590Srgrimesmy $do_update = 0;
6423695Spetermy $do_rewrite = 1;
651590Srgrimesmy $do_crypto = 0;
661590Srgrimesmy $do_ssl = 0;
671590Srgrimesmy $do_ctest = 0;
681590Srgrimesmy $do_ctestall = 0;
691590Srgrimesmy $do_checkexist = 0;
701590Srgrimes
711590Srgrimesmy $VMSVAX=0;
721590Srgrimesmy $VMSNonVAX=0;
731590Srgrimesmy $VMS=0;
7441399Sbdemy $W32=0;
751590Srgrimesmy $W16=0;
7661575Srobertomy $NT=0;
7772945Sknumy $OS2=0;
781590Srgrimes# Set this to make typesafe STACK definitions appear in DEF
791590Srgrimesmy $safe_stack_def = 0;
801590Srgrimes
811590Srgrimesmy @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT",
821590Srgrimes			"EXPORT_VAR_AS_FUNCTION", "ZLIB", "OPENSSL_FIPS" );
831590Srgrimesmy @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" );
841590Srgrimesmy @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
851590Srgrimes			 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
861590Srgrimes			 "SHA256", "SHA512", "RIPEMD",
8725942Sjdp			 "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA", "EC2M",
881590Srgrimes			 "HMAC", "AES", "CAMELLIA", "SEED", "GOST",
8917534Sache			 # EC_NISTP_64_GCC_128
9017534Sache			 "EC_NISTP_64_GCC_128",
911590Srgrimes			 # Envelope "algorithms"
921590Srgrimes			 "EVP", "X509", "ASN1_TYPEDEFS",
931590Srgrimes			 # Helper "algorithms"
9425942Sjdp			 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
951590Srgrimes			 "LOCKING",
9672945Sknu			 # External "algorithms"
971590Srgrimes			 "FP_API", "STDIO", "SOCK", "KRB5", "DGRAM",
9872945Sknu			 # Engines
9972945Sknu			 "STATIC_ENGINE", "ENGINE", "HW", "GMP",
10072945Sknu			 # RFC3779
1011590Srgrimes			 "RFC3779",
1021590Srgrimes			 # TLS
10325942Sjdp			 "TLSEXT", "PSK", "SRP", "HEARTBEATS",
1041590Srgrimes			 # CMS
1051590Srgrimes			 "CMS",
1061590Srgrimes			 # CryptoAPI Engine
10725942Sjdp			 "CAPIENG",
1081590Srgrimes			 # SSL v2
1091590Srgrimes			 "SSL2",
1101590Srgrimes			 # SSL v2 method
1111590Srgrimes			 "SSL2_METHOD",
1121590Srgrimes			 # SSL v3 method
1131590Srgrimes			 "SSL3_METHOD",
1141590Srgrimes			 # JPAKE
1151590Srgrimes			 "JPAKE",
1161590Srgrimes			 # NEXTPROTONEG
1171590Srgrimes			 "NEXTPROTONEG",
1181590Srgrimes			 # Deprecated functions
1191590Srgrimes			 "DEPRECATED",
1201590Srgrimes			 # Hide SSL internals
12141391Swosch			 "SSL_INTERN",
12241391Swosch			 # SCTP
12341391Swosch		 	 "SCTP",
1241590Srgrimes			 # SRTP
1251590Srgrimes			 "SRTP",
1261590Srgrimes			 # Unit testing
1271590Srgrimes		 	 "UNIT_TEST");
1281590Srgrimes
1291590Srgrimesmy $options="";
1301590Srgrimesopen(IN,"<Makefile") || die "unable to open Makefile!\n";
1311590Srgrimeswhile(<IN>) {
1328874Srgrimes    $options=$1 if (/^OPTIONS=(.*)$/);
1331590Srgrimes}
1341590Srgrimesclose(IN);
1351590Srgrimes
1361590Srgrimes# The following ciphers may be excluded (by Configure). This means functions
1371590Srgrimes# defined with ifndef(NO_XXX) are not included in the .def file, and everything
1381590Srgrimes# in directory xxx is ignored.
1391590Srgrimesmy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
1401590Srgrimesmy $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed;
1411590Srgrimesmy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
1421590Srgrimesmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
1431590Srgrimesmy $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw;
1441590Srgrimesmy $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated;
1451590Srgrimesmy $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng;
1461590Srgrimesmy $no_jpake; my $no_srp; my $no_ssl2; my $no_ec2m; my $no_nistp_gcc;
1471590Srgrimesmy $no_nextprotoneg; my $no_sctp; my $no_srtp;
1481590Srgrimesmy $no_unit_test; my $no_ssl3_method; my $no_ssl2_method;
1491590Srgrimes
1501590Srgrimesmy $fips;
1511590Srgrimes
1521590Srgrimesmy $zlib;
1531590Srgrimes
1541590Srgrimes
1551590Srgrimesforeach (@ARGV, split(/ /, $options))
1561590Srgrimes	{
1571590Srgrimes	$debug=1 if $_ eq "debug";
1581590Srgrimes	$W32=1 if $_ eq "32";
1591590Srgrimes	$W16=1 if $_ eq "16";
1601590Srgrimes	if($_ eq "NT") {
1611590Srgrimes		$W32 = 1;
1621590Srgrimes		$NT = 1;
1631590Srgrimes	}
1641590Srgrimes	if ($_ eq "VMS-VAX") {
1651590Srgrimes		$VMS=1;
1661590Srgrimes		$VMSVAX=1;
1671590Srgrimes	}
1681590Srgrimes	if ($_ eq "VMS-NonVAX") {
16972945Sknu		$VMS=1;
1701590Srgrimes		$VMSNonVAX=1;
1711590Srgrimes	}
172	$VMS=1 if $_ eq "VMS";
173	$OS2=1 if $_ eq "OS2";
174	$fips=1 if /^fips/;
175	if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
176			 || $_ eq "enable-zlib-dynamic") {
177		$zlib = 1;
178	}
179
180	$do_ssl=1 if $_ eq "ssleay";
181	if ($_ eq "ssl") {
182		$do_ssl=1;
183		$libname=$_
184	}
185	$do_crypto=1 if $_ eq "libeay";
186	if ($_ eq "crypto") {
187		$do_crypto=1;
188		$libname=$_;
189	}
190	$no_static_engine=1 if $_ eq "no-static-engine";
191	$no_static_engine=0 if $_ eq "enable-static-engine";
192	$do_update=1 if $_ eq "update";
193	$do_rewrite=1 if $_ eq "rewrite";
194	$do_ctest=1 if $_ eq "ctest";
195	$do_ctestall=1 if $_ eq "ctestall";
196	$do_checkexist=1 if $_ eq "exist";
197	#$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
198
199	if    (/^no-rc2$/)      { $no_rc2=1; }
200	elsif (/^no-rc4$/)      { $no_rc4=1; }
201	elsif (/^no-rc5$/)      { $no_rc5=1; }
202	elsif (/^no-idea$/)     { $no_idea=1; }
203	elsif (/^no-des$/)      { $no_des=1; $no_mdc2=1; }
204	elsif (/^no-bf$/)       { $no_bf=1; }
205	elsif (/^no-cast$/)     { $no_cast=1; }
206	elsif (/^no-whirlpool$/)     { $no_whirlpool=1; }
207	elsif (/^no-md2$/)      { $no_md2=1; }
208	elsif (/^no-md4$/)      { $no_md4=1; }
209	elsif (/^no-md5$/)      { $no_md5=1; }
210	elsif (/^no-sha$/)      { $no_sha=1; }
211	elsif (/^no-ripemd$/)   { $no_ripemd=1; }
212	elsif (/^no-mdc2$/)     { $no_mdc2=1; }
213	elsif (/^no-rsa$/)      { $no_rsa=1; }
214	elsif (/^no-dsa$/)      { $no_dsa=1; }
215	elsif (/^no-dh$/)       { $no_dh=1; }
216	elsif (/^no-ec$/)       { $no_ec=1; }
217	elsif (/^no-ecdsa$/)	{ $no_ecdsa=1; }
218	elsif (/^no-ecdh$/) 	{ $no_ecdh=1; }
219	elsif (/^no-hmac$/)	{ $no_hmac=1; }
220	elsif (/^no-aes$/)	{ $no_aes=1; }
221	elsif (/^no-camellia$/)	{ $no_camellia=1; }
222	elsif (/^no-seed$/)     { $no_seed=1; }
223	elsif (/^no-evp$/)	{ $no_evp=1; }
224	elsif (/^no-lhash$/)	{ $no_lhash=1; }
225	elsif (/^no-stack$/)	{ $no_stack=1; }
226	elsif (/^no-err$/)	{ $no_err=1; }
227	elsif (/^no-buffer$/)	{ $no_buffer=1; }
228	elsif (/^no-bio$/)	{ $no_bio=1; }
229	#elsif (/^no-locking$/)	{ $no_locking=1; }
230	elsif (/^no-comp$/)	{ $no_comp=1; }
231	elsif (/^no-dso$/)	{ $no_dso=1; }
232	elsif (/^no-krb5$/)	{ $no_krb5=1; }
233	elsif (/^no-engine$/)	{ $no_engine=1; }
234	elsif (/^no-hw$/)	{ $no_hw=1; }
235	elsif (/^no-gmp$/)	{ $no_gmp=1; }
236	elsif (/^no-rfc3779$/)	{ $no_rfc3779=1; }
237	elsif (/^no-tlsext$/)	{ $no_tlsext=1; }
238	elsif (/^no-cms$/)	{ $no_cms=1; }
239	elsif (/^no-ec2m$/)	{ $no_ec2m=1; }
240	elsif (/^no-ec_nistp_64_gcc_128$/)	{ $no_nistp_gcc=1; }
241	elsif (/^no-nextprotoneg$/)	{ $no_nextprotoneg=1; }
242	elsif (/^no-ssl2$/)	{ $no_ssl2=1; }
243	elsif (/^no-ssl2-method$/) { $no_ssl2_method=1; }
244	elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; }
245	elsif (/^no-capieng$/)	{ $no_capieng=1; }
246	elsif (/^no-jpake$/)	{ $no_jpake=1; }
247	elsif (/^no-srp$/)	{ $no_srp=1; }
248	elsif (/^no-sctp$/)	{ $no_sctp=1; }
249	elsif (/^no-srtp$/)	{ $no_srtp=1; }
250	elsif (/^no-unit-test$/){ $no_unit_test=1; }
251	}
252
253
254if (!$libname) {
255	if ($do_ssl) {
256		$libname="SSLEAY";
257	}
258	if ($do_crypto) {
259		$libname="LIBEAY";
260	}
261}
262
263# If no platform is given, assume WIN32
264if ($W32 + $W16 + $VMS + $OS2 == 0) {
265	$W32 = 1;
266}
267
268# Add extra knowledge
269if ($W16) {
270	$no_fp_api=1;
271}
272
273if (!$do_ssl && !$do_crypto)
274	{
275	print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
276	exit(1);
277	}
278
279%ssl_list=&load_numbers($ssl_num);
280$max_ssl = $max_num;
281%crypto_list=&load_numbers($crypto_num);
282$max_crypto = $max_num;
283
284my $ssl="ssl/ssl.h";
285$ssl.=" ssl/kssl.h";
286$ssl.=" ssl/tls1.h";
287$ssl.=" ssl/srtp.h";
288
289my $crypto ="crypto/crypto.h";
290$crypto.=" crypto/cryptlib.h";
291$crypto.=" crypto/o_dir.h";
292$crypto.=" crypto/o_str.h";
293$crypto.=" crypto/o_time.h";
294$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des;
295$crypto.=" crypto/idea/idea.h" ; # unless $no_idea;
296$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4;
297$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5;
298$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2;
299$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf;
300$crypto.=" crypto/cast/cast.h" ; # unless $no_cast;
301$crypto.=" crypto/whrlpool/whrlpool.h" ;
302$crypto.=" crypto/md2/md2.h" ; # unless $no_md2;
303$crypto.=" crypto/md4/md4.h" ; # unless $no_md4;
304$crypto.=" crypto/md5/md5.h" ; # unless $no_md5;
305$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2;
306$crypto.=" crypto/sha/sha.h" ; # unless $no_sha;
307$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd;
308$crypto.=" crypto/aes/aes.h" ; # unless $no_aes;
309$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia;
310$crypto.=" crypto/seed/seed.h"; # unless $no_seed;
311
312$crypto.=" crypto/bn/bn.h";
313$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa;
314$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa;
315$crypto.=" crypto/dh/dh.h" ; # unless $no_dh;
316$crypto.=" crypto/ec/ec.h" ; # unless $no_ec;
317$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa;
318$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh;
319$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac;
320$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac;
321
322$crypto.=" crypto/engine/engine.h"; # unless $no_engine;
323$crypto.=" crypto/stack/stack.h" ; # unless $no_stack;
324$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer;
325$crypto.=" crypto/bio/bio.h" ; # unless $no_bio;
326$crypto.=" crypto/dso/dso.h" ; # unless $no_dso;
327$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash;
328$crypto.=" crypto/conf/conf.h";
329$crypto.=" crypto/txt_db/txt_db.h";
330
331$crypto.=" crypto/evp/evp.h" ; # unless $no_evp;
332$crypto.=" crypto/objects/objects.h";
333$crypto.=" crypto/pem/pem.h";
334#$crypto.=" crypto/meth/meth.h";
335$crypto.=" crypto/asn1/asn1.h";
336$crypto.=" crypto/asn1/asn1t.h";
337$crypto.=" crypto/asn1/asn1_mac.h";
338$crypto.=" crypto/err/err.h" ; # unless $no_err;
339$crypto.=" crypto/pkcs7/pkcs7.h";
340$crypto.=" crypto/pkcs12/pkcs12.h";
341$crypto.=" crypto/x509/x509.h";
342$crypto.=" crypto/x509/x509_vfy.h";
343$crypto.=" crypto/x509v3/x509v3.h";
344$crypto.=" crypto/ts/ts.h";
345$crypto.=" crypto/rand/rand.h";
346$crypto.=" crypto/comp/comp.h" ; # unless $no_comp;
347$crypto.=" crypto/ocsp/ocsp.h";
348$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h";
349$crypto.=" crypto/krb5/krb5_asn.h";
350#$crypto.=" crypto/store/store.h";
351$crypto.=" crypto/pqueue/pqueue.h";
352$crypto.=" crypto/cms/cms.h";
353$crypto.=" crypto/jpake/jpake.h";
354$crypto.=" crypto/modes/modes.h";
355$crypto.=" crypto/srp/srp.h";
356
357my $symhacks="crypto/symhacks.h";
358
359my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
360my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
361
362if ($do_update) {
363
364if ($do_ssl == 1) {
365
366	&maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
367	if ($do_rewrite == 1) {
368		open(OUT, ">$ssl_num");
369		&rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
370	} else {
371		open(OUT, ">>$ssl_num");
372	}
373	&update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
374	close OUT;
375}
376
377if($do_crypto == 1) {
378
379	&maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
380	if ($do_rewrite == 1) {
381		open(OUT, ">$crypto_num");
382		&rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
383	} else {
384		open(OUT, ">>$crypto_num");
385	}
386	&update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
387	close OUT;
388}
389
390} elsif ($do_checkexist) {
391	&check_existing(*ssl_list, @ssl_symbols)
392		if $do_ssl == 1;
393	&check_existing(*crypto_list, @crypto_symbols)
394		if $do_crypto == 1;
395} elsif ($do_ctest || $do_ctestall) {
396
397	print <<"EOF";
398
399/* Test file to check all DEF file symbols are present by trying
400 * to link to all of them. This is *not* intended to be run!
401 */
402
403int main()
404{
405EOF
406	&print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
407		if $do_ssl == 1;
408
409	&print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
410		if $do_crypto == 1;
411
412	print "}\n";
413
414} else {
415
416	&print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
417		if $do_ssl == 1;
418
419	&print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
420		if $do_crypto == 1;
421
422}
423
424
425sub do_defs
426{
427	my($name,$files,$symhacksfile)=@_;
428	my $file;
429	my @ret;
430	my %syms;
431	my %platform;		# For anything undefined, we assume ""
432	my %kind;		# For anything undefined, we assume "FUNCTION"
433	my %algorithm;		# For anything undefined, we assume ""
434	my %variant;
435	my %variant_cnt;	# To be able to allocate "name{n}" if "name"
436				# is the same name as the original.
437	my $cpp;
438	my %unknown_algorithms = ();
439
440	foreach $file (split(/\s+/,$symhacksfile." ".$files))
441		{
442		print STDERR "DEBUG: starting on $file:\n" if $debug;
443		open(IN,"<$file") || die "unable to open $file:$!\n";
444		my $line = "", my $def= "";
445		my %tag = (
446			(map { $_ => 0 } @known_platforms),
447			(map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
448			(map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
449			NOPROTO		=> 0,
450			PERL5		=> 0,
451			_WINDLL		=> 0,
452			CONST_STRICT	=> 0,
453			TRUE		=> 1,
454		);
455		my $symhacking = $file eq $symhacksfile;
456		my @current_platforms = ();
457		my @current_algorithms = ();
458
459		# params: symbol, alias, platforms, kind
460		# The reason to put this subroutine in a variable is that
461		# it will otherwise create it's own, unshared, version of
462		# %tag and %variant...
463		my $make_variant = sub
464		{
465			my ($s, $a, $p, $k) = @_;
466			my ($a1, $a2);
467
468			print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
469			if (defined($p))
470			{
471				$a1 = join(",",$p,
472					   grep(!/^$/,
473						map { $tag{$_} == 1 ? $_ : "" }
474						@known_platforms));
475			}
476			else
477			{
478				$a1 = join(",",
479					   grep(!/^$/,
480						map { $tag{$_} == 1 ? $_ : "" }
481						@known_platforms));
482			}
483			$a2 = join(",",
484				   grep(!/^$/,
485					map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
486					@known_ossl_platforms));
487			print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
488			if ($a1 eq "") { $a1 = $a2; }
489			elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
490			if ($a eq $s)
491			{
492				if (!defined($variant_cnt{$s}))
493				{
494					$variant_cnt{$s} = 0;
495				}
496				$variant_cnt{$s}++;
497				$a .= "{$variant_cnt{$s}}";
498			}
499			my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
500			my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
501			if (!grep(/^$togrep$/,
502				  split(/;/, defined($variant{$s})?$variant{$s}:""))) {
503				if (defined($variant{$s})) { $variant{$s} .= ";"; }
504				$variant{$s} .= $toadd;
505			}
506			print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
507		};
508
509		print STDERR "DEBUG: parsing ----------\n" if $debug;
510		while(<IN>) {
511			if (/\/\* Error codes for the \w+ functions\. \*\//)
512				{
513				undef @tag;
514				last;
515				}
516			if ($line ne '') {
517				$_ = $line . $_;
518				$line = '';
519			}
520
521			if (/\\$/) {
522				chomp; # remove eol
523				chop; # remove ending backslash
524				$line = $_;
525				next;
526			}
527
528			if(/\/\*/) {
529				if (not /\*\//) {	# multiline comment...
530					$line = $_;	# ... just accumulate
531					next;
532				} else {
533					s/\/\*.*?\*\///gs;# wipe it
534				}
535			}
536
537			if ($cpp) {
538				$cpp++ if /^#\s*if/;
539				$cpp-- if /^#\s*endif/;
540				next;
541	    		}
542			$cpp = 1 if /^#.*ifdef.*cplusplus/;
543
544			s/{[^{}]*}//gs;                      # ignore {} blocks
545			print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
546			print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
547			if (/^\#\s*ifndef\s+(.*)/) {
548				push(@tag,"-");
549				push(@tag,$1);
550				$tag{$1}=-1;
551				print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
552			} elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
553				push(@tag,"-");
554				if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
555					my $tmp_1 = $1;
556					my $tmp_;
557					foreach $tmp_ (split '\&\&',$tmp_1) {
558						$tmp_ =~ /!defined\(([^\)]+)\)/;
559						print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
560						push(@tag,$1);
561						$tag{$1}=-1;
562					}
563				} else {
564					print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
565					print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
566					push(@tag,$1);
567					$tag{$1}=-1;
568				}
569			} elsif (/^\#\s*ifdef\s+(\S*)/) {
570				push(@tag,"-");
571				push(@tag,$1);
572				$tag{$1}=1;
573				print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
574			} elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
575				push(@tag,"-");
576				if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
577					my $tmp_1 = $1;
578					my $tmp_;
579					foreach $tmp_ (split '\|\|',$tmp_1) {
580						$tmp_ =~ /defined\(([^\)]+)\)/;
581						print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
582						push(@tag,$1);
583						$tag{$1}=1;
584					}
585				} else {
586					print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
587					print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
588					push(@tag,$1);
589					$tag{$1}=1;
590				}
591			} elsif (/^\#\s*error\s+(\w+) is disabled\./) {
592				my $tag_i = $#tag;
593				while($tag[$tag_i] ne "-") {
594					if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
595						$tag{$tag[$tag_i]}=2;
596						print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
597					}
598					$tag_i--;
599				}
600			} elsif (/^\#\s*endif/) {
601				my $tag_i = $#tag;
602				while($tag_i > 0 && $tag[$tag_i] ne "-") {
603					my $t=$tag[$tag_i];
604					print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
605					if ($tag{$t}==2) {
606						$tag{$t}=-1;
607					} else {
608						$tag{$t}=0;
609					}
610					print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
611					pop(@tag);
612					if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
613						$t=$1;
614					} else {
615						$t="";
616					}
617					if ($t ne ""
618					    && !grep(/^$t$/, @known_algorithms)) {
619						$unknown_algorithms{$t} = 1;
620						#print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
621					}
622					$tag_i--;
623				}
624				pop(@tag);
625			} elsif (/^\#\s*else/) {
626				my $tag_i = $#tag;
627				while($tag[$tag_i] ne "-") {
628					my $t=$tag[$tag_i];
629					$tag{$t}= -$tag{$t};
630					print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
631					$tag_i--;
632				}
633			} elsif (/^\#\s*if\s+1/) {
634				push(@tag,"-");
635				# Dummy tag
636				push(@tag,"TRUE");
637				$tag{"TRUE"}=1;
638				print STDERR "DEBUG: $file: found 1\n" if $debug;
639			} elsif (/^\#\s*if\s+0/) {
640				push(@tag,"-");
641				# Dummy tag
642				push(@tag,"TRUE");
643				$tag{"TRUE"}=-1;
644				print STDERR "DEBUG: $file: found 0\n" if $debug;
645			} elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
646				 && $symhacking && $tag{'TRUE'} != -1) {
647				# This is for aliasing.  When we find an alias,
648				# we have to invert
649				&$make_variant($1,$2);
650				print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
651			}
652			if (/^\#/) {
653				@current_platforms =
654				    grep(!/^$/,
655					 map { $tag{$_} == 1 ? $_ :
656						   $tag{$_} == -1 ? "!".$_  : "" }
657					 @known_platforms);
658				push @current_platforms
659				    , grep(!/^$/,
660					   map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
661						     $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_  : "" }
662					   @known_ossl_platforms);
663				@current_algorithms =
664				    grep(!/^$/,
665					 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
666					 @known_algorithms);
667				$def .=
668				    "#INFO:"
669					.join(',',@current_platforms).":"
670					    .join(',',@current_algorithms).";";
671				next;
672			}
673			if ($tag{'TRUE'} != -1) {
674				if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
675					next;
676				} elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
677					$def .= "int d2i_$3(void);";
678					$def .= "int i2d_$3(void);";
679					# Variant for platforms that do not
680					# have to access globale variables
681					# in shared libraries through functions
682					$def .=
683					    "#INFO:"
684						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
685						    .join(',',@current_algorithms).";";
686					$def .= "OPENSSL_EXTERN int $2_it;";
687					$def .=
688					    "#INFO:"
689						.join(',',@current_platforms).":"
690						    .join(',',@current_algorithms).";";
691					# Variant for platforms that have to
692					# access globale variables in shared
693					# libraries through functions
694					&$make_variant("$2_it","$2_it",
695						      "EXPORT_VAR_AS_FUNCTION",
696						      "FUNCTION");
697					next;
698				} elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
699					$def .= "int d2i_$3(void);";
700					$def .= "int i2d_$3(void);";
701					$def .= "int $3_free(void);";
702					$def .= "int $3_new(void);";
703					# Variant for platforms that do not
704					# have to access globale variables
705					# in shared libraries through functions
706					$def .=
707					    "#INFO:"
708						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
709						    .join(',',@current_algorithms).";";
710					$def .= "OPENSSL_EXTERN int $2_it;";
711					$def .=
712					    "#INFO:"
713						.join(',',@current_platforms).":"
714						    .join(',',@current_algorithms).";";
715					# Variant for platforms that have to
716					# access globale variables in shared
717					# libraries through functions
718					&$make_variant("$2_it","$2_it",
719						      "EXPORT_VAR_AS_FUNCTION",
720						      "FUNCTION");
721					next;
722				} elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
723					 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
724					$def .= "int d2i_$1(void);";
725					$def .= "int i2d_$1(void);";
726					$def .= "int $1_free(void);";
727					$def .= "int $1_new(void);";
728					# Variant for platforms that do not
729					# have to access globale variables
730					# in shared libraries through functions
731					$def .=
732					    "#INFO:"
733						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
734						    .join(',',@current_algorithms).";";
735					$def .= "OPENSSL_EXTERN int $1_it;";
736					$def .=
737					    "#INFO:"
738						.join(',',@current_platforms).":"
739						    .join(',',@current_algorithms).";";
740					# Variant for platforms that have to
741					# access globale variables in shared
742					# libraries through functions
743					&$make_variant("$1_it","$1_it",
744						      "EXPORT_VAR_AS_FUNCTION",
745						      "FUNCTION");
746					next;
747				} elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
748					$def .= "int d2i_$2(void);";
749					$def .= "int i2d_$2(void);";
750					# Variant for platforms that do not
751					# have to access globale variables
752					# in shared libraries through functions
753					$def .=
754					    "#INFO:"
755						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
756						    .join(',',@current_algorithms).";";
757					$def .= "OPENSSL_EXTERN int $2_it;";
758					$def .=
759					    "#INFO:"
760						.join(',',@current_platforms).":"
761						    .join(',',@current_algorithms).";";
762					# Variant for platforms that have to
763					# access globale variables in shared
764					# libraries through functions
765					&$make_variant("$2_it","$2_it",
766						      "EXPORT_VAR_AS_FUNCTION",
767						      "FUNCTION");
768					next;
769				} elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
770					$def .= "int $1_free(void);";
771					$def .= "int $1_new(void);";
772					next;
773				} elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
774					$def .= "int d2i_$2(void);";
775					$def .= "int i2d_$2(void);";
776					$def .= "int $2_free(void);";
777					$def .= "int $2_new(void);";
778					# Variant for platforms that do not
779					# have to access globale variables
780					# in shared libraries through functions
781					$def .=
782					    "#INFO:"
783						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
784						    .join(',',@current_algorithms).";";
785					$def .= "OPENSSL_EXTERN int $2_it;";
786					$def .=
787					    "#INFO:"
788						.join(',',@current_platforms).":"
789						    .join(',',@current_algorithms).";";
790					# Variant for platforms that have to
791					# access globale variables in shared
792					# libraries through functions
793					&$make_variant("$2_it","$2_it",
794						      "EXPORT_VAR_AS_FUNCTION",
795						      "FUNCTION");
796					next;
797				} elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
798					# Variant for platforms that do not
799					# have to access globale variables
800					# in shared libraries through functions
801					$def .=
802					    "#INFO:"
803						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
804						    .join(',',@current_algorithms).";";
805					$def .= "OPENSSL_EXTERN int $1_it;";
806					$def .=
807					    "#INFO:"
808						.join(',',@current_platforms).":"
809						    .join(',',@current_algorithms).";";
810					# Variant for platforms that have to
811					# access globale variables in shared
812					# libraries through functions
813					&$make_variant("$1_it","$1_it",
814						      "EXPORT_VAR_AS_FUNCTION",
815						      "FUNCTION");
816					next;
817				} elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
818					$def .= "int i2d_$1_NDEF(void);";
819				} elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
820					next;
821				} elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
822					$def .= "int $1_print_ctx(void);";
823					next;
824				} elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
825					$def .= "int $2_print_ctx(void);";
826					next;
827				} elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
828					next;
829				} elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
830					 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
831					 /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
832					# Things not in Win16
833					$def .=
834					    "#INFO:"
835						.join(',',"!WIN16",@current_platforms).":"
836						    .join(',',@current_algorithms).";";
837					$def .= "int PEM_read_$1(void);";
838					$def .= "int PEM_write_$1(void);";
839					$def .=
840					    "#INFO:"
841						.join(',',@current_platforms).":"
842						    .join(',',@current_algorithms).";";
843					# Things that are everywhere
844					$def .= "int PEM_read_bio_$1(void);";
845					$def .= "int PEM_write_bio_$1(void);";
846					next;
847				} elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
848					 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
849					# Things not in Win16
850					$def .=
851					    "#INFO:"
852						.join(',',"!WIN16",@current_platforms).":"
853						    .join(',',@current_algorithms).";";
854					$def .= "int PEM_write_$1(void);";
855					$def .=
856					    "#INFO:"
857						.join(',',@current_platforms).":"
858						    .join(',',@current_algorithms).";";
859					# Things that are everywhere
860					$def .= "int PEM_write_bio_$1(void);";
861					next;
862				} elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
863					 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
864					# Things not in Win16
865					$def .=
866					    "#INFO:"
867						.join(',',"!WIN16",@current_platforms).":"
868						    .join(',',@current_algorithms).";";
869					$def .= "int PEM_read_$1(void);";
870					$def .=
871					    "#INFO:"
872						.join(',',@current_platforms).":"
873						    .join(',',@current_algorithms).";";
874					# Things that are everywhere
875					$def .= "int PEM_read_bio_$1(void);";
876					next;
877				} elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
878					# Variant for platforms that do not
879					# have to access globale variables
880					# in shared libraries through functions
881					$def .=
882					    "#INFO:"
883						.join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
884						    .join(',',@current_algorithms).";";
885					$def .= "OPENSSL_EXTERN int _shadow_$2;";
886					$def .=
887					    "#INFO:"
888						.join(',',@current_platforms).":"
889						    .join(',',@current_algorithms).";";
890					# Variant for platforms that have to
891					# access globale variables in shared
892					# libraries through functions
893					&$make_variant("_shadow_$2","_shadow_$2",
894						      "EXPORT_VAR_AS_FUNCTION",
895						      "FUNCTION");
896				} elsif ($tag{'CONST_STRICT'} != 1) {
897					if (/\{|\/\*|\([^\)]*$/) {
898						$line = $_;
899					} else {
900						$def .= $_;
901					}
902				}
903			}
904		}
905		close(IN);
906
907		my $algs;
908		my $plays;
909
910		print STDERR "DEBUG: postprocessing ----------\n" if $debug;
911		foreach (split /;/, $def) {
912			my $s; my $k = "FUNCTION"; my $p; my $a;
913			s/^[\n\s]*//g;
914			s/[\n\s]*$//g;
915			next if(/\#undef/);
916			next if(/typedef\W/);
917			next if(/\#define/);
918
919			# Reduce argument lists to empty ()
920			# fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
921			while(/\(.*\)/s) {
922				s/\([^\(\)]+\)/\{\}/gs;
923				s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;	#(*f{}) -> f
924			}
925			# pretend as we didn't use curly braces: {} -> ()
926			s/\{\}/\(\)/gs;
927
928			s/STACK_OF\(\)/void/gs;
929			s/LHASH_OF\(\)/void/gs;
930
931			print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
932			if (/^\#INFO:([^:]*):(.*)$/) {
933				$plats = $1;
934				$algs = $2;
935				print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
936				next;
937			} elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
938				$s = $1;
939				$k = "VARIABLE";
940				print STDERR "DEBUG: found external variable $s\n" if $debug;
941			} elsif (/TYPEDEF_\w+_OF/s) {
942				next;
943			} elsif (/(\w+)\s*\(\).*/s) {	# first token prior [first] () is
944				$s = $1;		# a function name!
945				print STDERR "DEBUG: found function $s\n" if $debug;
946			} elsif (/\(/ and not (/=/)) {
947				print STDERR "File $file: cannot parse: $_;\n";
948				next;
949			} else {
950				next;
951			}
952
953			$syms{$s} = 1;
954			$kind{$s} = $k;
955
956			$p = $plats;
957			$a = $algs;
958			$a .= ",BF" if($s =~ /EVP_bf/);
959			$a .= ",CAST" if($s =~ /EVP_cast/);
960			$a .= ",DES" if($s =~ /EVP_des/);
961			$a .= ",DSA" if($s =~ /EVP_dss/);
962			$a .= ",IDEA" if($s =~ /EVP_idea/);
963			$a .= ",MD2" if($s =~ /EVP_md2/);
964			$a .= ",MD4" if($s =~ /EVP_md4/);
965			$a .= ",MD5" if($s =~ /EVP_md5/);
966			$a .= ",RC2" if($s =~ /EVP_rc2/);
967			$a .= ",RC4" if($s =~ /EVP_rc4/);
968			$a .= ",RC5" if($s =~ /EVP_rc5/);
969			$a .= ",RIPEMD" if($s =~ /EVP_ripemd/);
970			$a .= ",SHA" if($s =~ /EVP_sha/);
971			$a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
972			$a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
973			$a .= ",RSA" if($s =~ /RSAPrivateKey/);
974			$a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
975
976			$platform{$s} =
977			    &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
978			$algorithm{$s} .= ','.$a;
979
980			if (defined($variant{$s})) {
981				foreach $v (split /;/,$variant{$s}) {
982					(my $r, my $p, my $k) = split(/:/,$v);
983					my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
984					$syms{$r} = 1;
985					if (!defined($k)) { $k = $kind{$s}; }
986					$kind{$r} = $k."(".$s.")";
987					$algorithm{$r} = $algorithm{$s};
988					$platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
989					$platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
990					print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
991				}
992			}
993			print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
994		}
995	}
996
997	# Prune the returned symbols
998
999        delete $syms{"bn_dump1"};
1000	$platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh";
1001
1002	$platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
1003	$platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
1004	$platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
1005	$platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
1006	$platform{"EVP_sha384"} = "!VMSVAX";
1007	$platform{"EVP_sha512"} = "!VMSVAX";
1008	$platform{"SHA384_Init"} = "!VMSVAX";
1009	$platform{"SHA384_Transform"} = "!VMSVAX";
1010	$platform{"SHA384_Update"} = "!VMSVAX";
1011	$platform{"SHA384_Final"} = "!VMSVAX";
1012	$platform{"SHA384"} = "!VMSVAX";
1013	$platform{"SHA512_Init"} = "!VMSVAX";
1014	$platform{"SHA512_Transform"} = "!VMSVAX";
1015	$platform{"SHA512_Update"} = "!VMSVAX";
1016	$platform{"SHA512_Final"} = "!VMSVAX";
1017	$platform{"SHA512"} = "!VMSVAX";
1018	$platform{"WHIRLPOOL_Init"} = "!VMSVAX";
1019	$platform{"WHIRLPOOL"} = "!VMSVAX";
1020	$platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX";
1021	$platform{"EVP_whirlpool"} = "!VMSVAX";
1022	$platform{"WHIRLPOOL_Final"} = "!VMSVAX";
1023	$platform{"WHIRLPOOL_Update"} = "!VMSVAX";
1024
1025
1026	# Info we know about
1027
1028	push @ret, map { $_."\\".&info_string($_,"EXIST",
1029					      $platform{$_},
1030					      $kind{$_},
1031					      $algorithm{$_}) } keys %syms;
1032
1033	if (keys %unknown_algorithms) {
1034		print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
1035		print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
1036	}
1037	return(@ret);
1038}
1039
1040# Param: string of comma-separated platform-specs.
1041sub reduce_platforms
1042{
1043	my ($platforms) = @_;
1044	my $pl = defined($platforms) ? $platforms : "";
1045	my %p = map { $_ => 0 } split /,/, $pl;
1046	my $ret;
1047
1048	print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
1049	    if $debug;
1050	# We do this, because if there's code like the following, it really
1051	# means the function exists in all cases and should therefore be
1052	# everywhere.  By increasing and decreasing, we may attain 0:
1053	#
1054	# ifndef WIN16
1055	#    int foo();
1056	# else
1057	#    int _fat foo();
1058	# endif
1059	foreach $platform (split /,/, $pl) {
1060		if ($platform =~ /^!(.*)$/) {
1061			$p{$1}--;
1062		} else {
1063			$p{$platform}++;
1064		}
1065	}
1066	foreach $platform (keys %p) {
1067		if ($p{$platform} == 0) { delete $p{$platform}; }
1068	}
1069
1070	delete $p{""};
1071
1072	$ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
1073	print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1074	    if $debug;
1075	return $ret;
1076}
1077
1078sub info_string {
1079	(my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1080
1081	my %a = defined($algorithms) ?
1082	    map { $_ => 1 } split /,/, $algorithms : ();
1083	my $k = defined($kind) ? $kind : "FUNCTION";
1084	my $ret;
1085	my $p = &reduce_platforms($platforms);
1086
1087	delete $a{""};
1088
1089	$ret = $exist;
1090	$ret .= ":".$p;
1091	$ret .= ":".$k;
1092	$ret .= ":".join(',',sort keys %a);
1093	return $ret;
1094}
1095
1096sub maybe_add_info {
1097	(my $name, *nums, my @symbols) = @_;
1098	my $sym;
1099	my $new_info = 0;
1100	my %syms=();
1101
1102	print STDERR "Updating $name info\n";
1103	foreach $sym (@symbols) {
1104		(my $s, my $i) = split /\\/, $sym;
1105		if (defined($nums{$s})) {
1106			$i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1107			(my $n, my $dummy) = split /\\/, $nums{$s};
1108			if (!defined($dummy) || $i ne $dummy) {
1109				$nums{$s} = $n."\\".$i;
1110				$new_info++;
1111				print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1112			}
1113		}
1114		$syms{$s} = 1;
1115	}
1116
1117	my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1118	foreach $sym (@s) {
1119		(my $n, my $i) = split /\\/, $nums{$sym};
1120		if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1121			$new_info++;
1122			print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1123		}
1124	}
1125	if ($new_info) {
1126		print STDERR "$new_info old symbols got an info update\n";
1127		if (!$do_rewrite) {
1128			print STDERR "You should do a rewrite to fix this.\n";
1129		}
1130	} else {
1131		print STDERR "No old symbols needed info update\n";
1132	}
1133}
1134
1135# Param: string of comma-separated keywords, each possibly prefixed with a "!"
1136sub is_valid
1137{
1138	my ($keywords_txt,$platforms) = @_;
1139	my (@keywords) = split /,/,$keywords_txt;
1140	my ($falsesum, $truesum) = (0, 1);
1141
1142	# Param: one keyword
1143	sub recognise
1144	{
1145		my ($keyword,$platforms) = @_;
1146
1147		if ($platforms) {
1148			# platforms
1149			if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
1150			if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
1151			if ($keyword eq "VMS" && $VMS) { return 1; }
1152			if ($keyword eq "WIN32" && $W32) { return 1; }
1153			if ($keyword eq "WIN16" && $W16) { return 1; }
1154			if ($keyword eq "WINNT" && $NT) { return 1; }
1155			if ($keyword eq "OS2" && $OS2) { return 1; }
1156			# Special platforms:
1157			# EXPORT_VAR_AS_FUNCTION means that global variables
1158			# will be represented as functions.  This currently
1159			# only happens on VMS-VAX.
1160			if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) {
1161				return 1;
1162			}
1163			if ($keyword eq "OPENSSL_FIPS" && $fips) {
1164				return 1;
1165			}
1166			if ($keyword eq "ZLIB" && $zlib) { return 1; }
1167			return 0;
1168		} else {
1169			# algorithms
1170			if ($keyword eq "RC2" && $no_rc2) { return 0; }
1171			if ($keyword eq "RC4" && $no_rc4) { return 0; }
1172			if ($keyword eq "RC5" && $no_rc5) { return 0; }
1173			if ($keyword eq "IDEA" && $no_idea) { return 0; }
1174			if ($keyword eq "DES" && $no_des) { return 0; }
1175			if ($keyword eq "BF" && $no_bf) { return 0; }
1176			if ($keyword eq "CAST" && $no_cast) { return 0; }
1177			if ($keyword eq "MD2" && $no_md2) { return 0; }
1178			if ($keyword eq "MD4" && $no_md4) { return 0; }
1179			if ($keyword eq "MD5" && $no_md5) { return 0; }
1180			if ($keyword eq "SHA" && $no_sha) { return 0; }
1181			if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; }
1182			if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
1183			if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; }
1184			if ($keyword eq "RSA" && $no_rsa) { return 0; }
1185			if ($keyword eq "DSA" && $no_dsa) { return 0; }
1186			if ($keyword eq "DH" && $no_dh) { return 0; }
1187			if ($keyword eq "EC" && $no_ec) { return 0; }
1188			if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; }
1189			if ($keyword eq "ECDH" && $no_ecdh) { return 0; }
1190			if ($keyword eq "HMAC" && $no_hmac) { return 0; }
1191			if ($keyword eq "AES" && $no_aes) { return 0; }
1192			if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; }
1193			if ($keyword eq "SEED" && $no_seed) { return 0; }
1194			if ($keyword eq "EVP" && $no_evp) { return 0; }
1195			if ($keyword eq "LHASH" && $no_lhash) { return 0; }
1196			if ($keyword eq "STACK" && $no_stack) { return 0; }
1197			if ($keyword eq "ERR" && $no_err) { return 0; }
1198			if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
1199			if ($keyword eq "BIO" && $no_bio) { return 0; }
1200			if ($keyword eq "COMP" && $no_comp) { return 0; }
1201			if ($keyword eq "DSO" && $no_dso) { return 0; }
1202			if ($keyword eq "KRB5" && $no_krb5) { return 0; }
1203			if ($keyword eq "ENGINE" && $no_engine) { return 0; }
1204			if ($keyword eq "HW" && $no_hw) { return 0; }
1205			if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
1206			if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
1207			if ($keyword eq "GMP" && $no_gmp) { return 0; }
1208			if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
1209			if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; }
1210			if ($keyword eq "PSK" && $no_psk) { return 0; }
1211			if ($keyword eq "CMS" && $no_cms) { return 0; }
1212			if ($keyword eq "EC2M" && $no_ec2m) { return 0; }
1213			if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; }
1214			if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc)
1215					{ return 0; }
1216			if ($keyword eq "SSL2" && $no_ssl2) { return 0; }
1217			if ($keyword eq "SSL2_METHOD" && $no_ssl2_method) { return 0; }
1218			if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; }
1219			if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
1220			if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
1221			if ($keyword eq "SRP" && $no_srp) { return 0; }
1222			if ($keyword eq "SCTP" && $no_sctp) { return 0; }
1223			if ($keyword eq "SRTP" && $no_srtp) { return 0; }
1224			if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; }
1225			if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
1226
1227			# Nothing recognise as true
1228			return 1;
1229		}
1230	}
1231
1232	foreach $k (@keywords) {
1233		if ($k =~ /^!(.*)$/) {
1234			$falsesum += &recognise($1,$platforms);
1235		} else {
1236			$truesum *= &recognise($k,$platforms);
1237		}
1238	}
1239	print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1240	return (!$falsesum) && $truesum;
1241}
1242
1243sub print_test_file
1244{
1245	(*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1246	my $n = 1; my @e; my @r;
1247	my $sym; my $prev = ""; my $prefSSLeay;
1248
1249	(@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1250	(@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1251	@symbols=((sort @e),(sort @r));
1252
1253	foreach $sym (@symbols) {
1254		(my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1255		my $v = 0;
1256		$v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1257		my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1258		my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1259		if (!defined($nums{$s})) {
1260			print STDERR "Warning: $s does not have a number assigned\n"
1261			    if(!$do_update);
1262		} elsif (is_valid($p,1) && is_valid($a,0)) {
1263			my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1264			if ($prev eq $s2) {
1265				print OUT "\t/* The following has already appeared previously */\n";
1266				print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1267			}
1268			$prev = $s2;	# To warn about duplicates...
1269
1270			($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/);
1271			if ($v) {
1272				print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1273			} else {
1274				print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1275			}
1276		}
1277	}
1278}
1279
1280sub get_version {
1281   local *MF;
1282   my $v = '?';
1283   open MF, 'Makefile' or return $v;
1284   while (<MF>) {
1285     $v = $1, last if /^VERSION=(.*?)\s*$/;
1286   }
1287   close MF;
1288   return $v;
1289}
1290
1291sub print_def_file
1292{
1293	(*OUT,my $name,*nums,my @symbols)=@_;
1294	my $n = 1; my @e; my @r; my @v; my $prev="";
1295	my $liboptions="";
1296	my $libname = $name;
1297	my $http_vendor = 'www.openssl.org/';
1298	my $version = get_version();
1299	my $what = "OpenSSL: implementation of Secure Socket Layer";
1300	my $description = "$what $version, $name - http://$http_vendor";
1301
1302	if ($W32)
1303		{ $libname.="32"; }
1304	elsif ($W16)
1305		{ $libname.="16"; }
1306	elsif ($OS2)
1307		{ # DLL names should not clash on the whole system.
1308		  # However, they should not have any particular relationship
1309		  # to the name of the static library.  Chose descriptive names
1310		  # (must be at most 8 chars).
1311		  my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
1312		  $libname = $translate{$name} || $name;
1313		  $liboptions = <<EOO;
1314INITINSTANCE
1315DATA MULTIPLE NONSHARED
1316EOO
1317		  # Vendor field can't contain colon, drat; so we omit http://
1318		  $description = "\@#$http_vendor:$version#\@$what; DLL for library $name.  Build for EMX -Zmtd";
1319		}
1320
1321	print OUT <<"EOF";
1322;
1323; Definition file for the DLL version of the $name library from OpenSSL
1324;
1325
1326LIBRARY         $libname	$liboptions
1327
1328EOF
1329
1330	if ($W16) {
1331		print <<"EOF";
1332CODE            PRELOAD MOVEABLE
1333DATA            PRELOAD MOVEABLE SINGLE
1334
1335EXETYPE		WINDOWS
1336
1337HEAPSIZE	4096
1338STACKSIZE	8192
1339
1340EOF
1341	}
1342
1343	print "EXPORTS\n";
1344
1345	(@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1346	(@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1347	(@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1348	@symbols=((sort @e),(sort @r), (sort @v));
1349
1350
1351	foreach $sym (@symbols) {
1352		(my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1353		my $v = 0;
1354		$v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1355		if (!defined($nums{$s})) {
1356			printf STDERR "Warning: $s does not have a number assigned\n"
1357			    if(!$do_update);
1358		} else {
1359			(my $n, my $dummy) = split /\\/, $nums{$s};
1360			my %pf = ();
1361			my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1362			my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1363			if (is_valid($p,1) && is_valid($a,0)) {
1364				my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1365				if ($prev eq $s2) {
1366					print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1367				}
1368				$prev = $s2;	# To warn about duplicates...
1369				if($v && !$OS2) {
1370					printf OUT "    %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n;
1371				} else {
1372					printf OUT "    %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n;
1373				}
1374			}
1375		}
1376	}
1377	printf OUT "\n";
1378}
1379
1380sub load_numbers
1381{
1382	my($name)=@_;
1383	my(@a,%ret);
1384
1385	$max_num = 0;
1386	$num_noinfo = 0;
1387	$prev = "";
1388	$prev_cnt = 0;
1389
1390	open(IN,"<$name") || die "unable to open $name:$!\n";
1391	while (<IN>) {
1392		chop;
1393		s/#.*$//;
1394		next if /^\s*$/;
1395		@a=split;
1396		if (defined $ret{$a[0]}) {
1397			# This is actually perfectly OK
1398			#print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1399		}
1400		if ($max_num > $a[1]) {
1401			print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1402		}
1403		elsif ($max_num == $a[1]) {
1404			# This is actually perfectly OK
1405			#print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1406			if ($a[0] eq $prev) {
1407				$prev_cnt++;
1408				$a[0] .= "{$prev_cnt}";
1409			}
1410		}
1411		else {
1412			$prev_cnt = 0;
1413		}
1414		if ($#a < 2) {
1415			# Existence will be proven later, in do_defs
1416			$ret{$a[0]}=$a[1];
1417			$num_noinfo++;
1418		} else {
1419			$ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker
1420		}
1421		$max_num = $a[1] if $a[1] > $max_num;
1422		$prev=$a[0];
1423	}
1424	if ($num_noinfo) {
1425		print STDERR "Warning: $num_noinfo symbols were without info.";
1426		if ($do_rewrite) {
1427			printf STDERR "  The rewrite will fix this.\n";
1428		} else {
1429			printf STDERR "  You should do a rewrite to fix this.\n";
1430		}
1431	}
1432	close(IN);
1433	return(%ret);
1434}
1435
1436sub parse_number
1437{
1438	(my $str, my $what) = @_;
1439	(my $n, my $i) = split(/\\/,$str);
1440	if ($what eq "n") {
1441		return $n;
1442	} else {
1443		return $i;
1444	}
1445}
1446
1447sub rewrite_numbers
1448{
1449	(*OUT,$name,*nums,@symbols)=@_;
1450	my $thing;
1451
1452	print STDERR "Rewriting $name\n";
1453
1454	my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1455	my $r; my %r; my %rsyms;
1456	foreach $r (@r) {
1457		(my $s, my $i) = split /\\/, $r;
1458		my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1459		$i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1460		$r{$a} = $s."\\".$i;
1461		$rsyms{$s} = 1;
1462	}
1463
1464	my %syms = ();
1465	foreach $_ (@symbols) {
1466		(my $n, my $i) = split /\\/;
1467		$syms{$n} = 1;
1468	}
1469
1470	my @s=sort {
1471	    &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1472	    || $a cmp $b
1473	} keys %nums;
1474	foreach $sym (@s) {
1475		(my $n, my $i) = split /\\/, $nums{$sym};
1476		next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1477		next if defined($rsyms{$sym});
1478		print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1479		$i="NOEXIST::FUNCTION:"
1480			if !defined($i) || $i eq "" || !defined($syms{$sym});
1481		my $s2 = $sym;
1482		$s2 =~ s/\{[0-9]+\}$//;
1483		printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
1484		if (exists $r{$sym}) {
1485			(my $s, $i) = split /\\/,$r{$sym};
1486			my $s2 = $s;
1487			$s2 =~ s/\{[0-9]+\}$//;
1488			printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
1489		}
1490	}
1491}
1492
1493sub update_numbers
1494{
1495	(*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1496	my $new_syms = 0;
1497
1498	print STDERR "Updating $name numbers\n";
1499
1500	my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1501	my $r; my %r; my %rsyms;
1502	foreach $r (@r) {
1503		(my $s, my $i) = split /\\/, $r;
1504		my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1505		$i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1506		$r{$a} = $s."\\".$i;
1507		$rsyms{$s} = 1;
1508	}
1509
1510	foreach $sym (@symbols) {
1511		(my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1512		next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1513		next if defined($rsyms{$sym});
1514		die "ERROR: Symbol $sym had no info attached to it."
1515		    if $i eq "";
1516		if (!exists $nums{$s}) {
1517			$new_syms++;
1518			my $s2 = $s;
1519			$s2 =~ s/\{[0-9]+\}$//;
1520			printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i;
1521			if (exists $r{$s}) {
1522				($s, $i) = split /\\/,$r{$s};
1523				$s =~ s/\{[0-9]+\}$//;
1524				printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i;
1525			}
1526		}
1527	}
1528	if($new_syms) {
1529		print STDERR "$new_syms New symbols added\n";
1530	} else {
1531		print STDERR "No New symbols Added\n";
1532	}
1533}
1534
1535sub check_existing
1536{
1537	(*nums, my @symbols)=@_;
1538	my %existing; my @remaining;
1539	@remaining=();
1540	foreach $sym (@symbols) {
1541		(my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1542		$existing{$s}=1;
1543	}
1544	foreach $sym (keys %nums) {
1545		if (!exists $existing{$sym}) {
1546			push @remaining, $sym;
1547		}
1548	}
1549	if(@remaining) {
1550		print STDERR "The following symbols do not seem to exist:\n";
1551		foreach $sym (@remaining) {
1552			print STDERR "\t",$sym,"\n";
1553		}
1554	}
1555}
1556
1557