mkdef.pl revision 109998
155714Skris#!/usr/local/bin/perl -w 255714Skris# 355714Skris# generate a .def file 455714Skris# 555714Skris# It does this by parsing the header files and looking for the 655714Skris# prototyped functions: it then prunes the output. 755714Skris# 868651Skris# Intermediary files are created, call libeay.num and ssleay.num,... 968651Skris# Previously, they had the following format: 1068651Skris# 1168651Skris# routine-name nnnn 1268651Skris# 1368651Skris# But that isn't enough for a number of reasons, the first on being that 1468651Skris# this format is (needlessly) very Win32-centric, and even then... 1568651Skris# One of the biggest problems is that there's no information about what 1668651Skris# routines should actually be used, which varies with what crypto algorithms 1768651Skris# are disabled. Also, some operating systems (for example VMS with VAX C) 1868651Skris# need to keep track of the global variables as well as the functions. 1968651Skris# 2068651Skris# So, a remake of this script is done so as to include information on the 2168651Skris# kind of symbol it is (function or variable) and what algorithms they're 2268651Skris# part of. This will allow easy translating to .def files or the corresponding 2368651Skris# file in other operating systems (a .opt file for VMS, possibly with a .mar 2468651Skris# file). 2568651Skris# 2668651Skris# The format now becomes: 2768651Skris# 2868651Skris# routine-name nnnn info 2968651Skris# 3068651Skris# and the "info" part is actually a colon-separated string of fields with 3168651Skris# the following meaning: 3268651Skris# 3368651Skris# existence:platform:kind:algorithms 3468651Skris# 3568651Skris# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is 3668651Skris# found somewhere in the source, 3768651Skris# - "platforms" is empty if it exists on all platforms, otherwise it contains 3868651Skris# comma-separated list of the platform, just as they are if the symbol exists 3968651Skris# for those platforms, or prepended with a "!" if not. This helps resolve 40109998Smarkm# symbol name variants for platforms where the names are too long for the 4168651Skris# compiler or linker, or if the systems is case insensitive and there is a 42109998Smarkm# clash, or the symbol is implemented differently (see 43109998Smarkm# EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found 44109998Smarkm# in the file crypto/symhacks.h. 45109998Smarkm# The semantics for the platforms is that every item is checked against the 46109998Smarkm# environment. For the negative items ("!FOO"), if any of them is false 47109998Smarkm# (i.e. "FOO" is true) in the environment, the corresponding symbol can't be 48109998Smarkm# used. For the positive itms, if all of them are false in the environment, 49109998Smarkm# the corresponding symbol can't be used. Any combination of positive and 50109998Smarkm# negative items are possible, and of course leave room for some redundancy. 5168651Skris# - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious. 5268651Skris# - "algorithms" is a comma-separated list of algorithm names. This helps 5368651Skris# exclude symbols that are part of an algorithm that some user wants to 5468651Skris# exclude. 5568651Skris# 5655714Skris 57109998Smarkmmy $debug=0; 58109998Smarkm 5968651Skrismy $crypto_num= "util/libeay.num"; 6068651Skrismy $ssl_num= "util/ssleay.num"; 61109998Smarkmmy $libname; 6255714Skris 6355714Skrismy $do_update = 0; 64109998Smarkmmy $do_rewrite = 1; 6555714Skrismy $do_crypto = 0; 6655714Skrismy $do_ssl = 0; 6759191Skrismy $do_ctest = 0; 6868651Skrismy $do_ctestall = 0; 69109998Smarkmmy $do_checkexist = 0; 7055714Skris 71109998Smarkmmy $VMSVAX=0; 72109998Smarkmmy $VMSAlpha=0; 7368651Skrismy $VMS=0; 7468651Skrismy $W32=0; 7568651Skrismy $W16=0; 7659191Skrismy $NT=0; 77109998Smarkmmy $OS2=0; 7855714Skris# Set this to make typesafe STACK definitions appear in DEF 7968651Skrismy $safe_stack_def = 0; 8055714Skris 81109998Smarkmmy @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT", 82109998Smarkm "EXPORT_VAR_AS_FUNCTION" ); 83109998Smarkmmy @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" ); 8468651Skrismy @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF", 85109998Smarkm "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1", 86109998Smarkm "RIPEMD", 87109998Smarkm "MDC2", "RSA", "DSA", "DH", "EC", "HMAC", "AES", 88109998Smarkm # Envelope "algorithms" 89109998Smarkm "EVP", "X509", "ASN1_TYPEDEFS", 90109998Smarkm # Helper "algorithms" 91109998Smarkm "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR", 92109998Smarkm "LOCKING", 93109998Smarkm # External "algorithms" 94109998Smarkm "FP_API", "STDIO", "SOCK", "KRB5" ); 9568651Skris 9659191Skrismy $options=""; 9755714Skrisopen(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n"; 9855714Skriswhile(<IN>) { 9955714Skris $options=$1 if (/^OPTIONS=(.*)$/); 10055714Skris} 10155714Skrisclose(IN); 10255714Skris 10359191Skris# The following ciphers may be excluded (by Configure). This means functions 10459191Skris# defined with ifndef(NO_XXX) are not included in the .def file, and everything 10559191Skris# in directory xxx is ignored. 10659191Skrismy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; 10768651Skrismy $no_cast; 10868651Skrismy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; 109109998Smarkmmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5; 110109998Smarkmmy $no_ec; 11168651Skrismy $no_fp_api; 11259191Skris 11355714Skrisforeach (@ARGV, split(/ /, $options)) 11455714Skris { 115109998Smarkm $debug=1 if $_ eq "debug"; 11655714Skris $W32=1 if $_ eq "32"; 11768651Skris $W16=1 if $_ eq "16"; 11855714Skris if($_ eq "NT") { 11955714Skris $W32 = 1; 12055714Skris $NT = 1; 12155714Skris } 122109998Smarkm if ($_ eq "VMS-VAX") { 123109998Smarkm $VMS=1; 124109998Smarkm $VMSVAX=1; 125109998Smarkm } 126109998Smarkm if ($_ eq "VMS-Alpha") { 127109998Smarkm $VMS=1; 128109998Smarkm $VMSAlpha=1; 129109998Smarkm } 13068651Skris $VMS=1 if $_ eq "VMS"; 131109998Smarkm $OS2=1 if $_ eq "OS2"; 13268651Skris 13355714Skris $do_ssl=1 if $_ eq "ssleay"; 134109998Smarkm if ($_ eq "ssl") { 135109998Smarkm $do_ssl=1; 136109998Smarkm $libname=$_ 137109998Smarkm } 13855714Skris $do_crypto=1 if $_ eq "libeay"; 139109998Smarkm if ($_ eq "crypto") { 140109998Smarkm $do_crypto=1; 141109998Smarkm $libname=$_; 142109998Smarkm } 14355714Skris $do_update=1 if $_ eq "update"; 14468651Skris $do_rewrite=1 if $_ eq "rewrite"; 14559191Skris $do_ctest=1 if $_ eq "ctest"; 14668651Skris $do_ctestall=1 if $_ eq "ctestall"; 147109998Smarkm $do_checkexist=1 if $_ eq "exist"; 14868651Skris #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; 14955714Skris 15055714Skris if (/^no-rc2$/) { $no_rc2=1; } 15155714Skris elsif (/^no-rc4$/) { $no_rc4=1; } 15255714Skris elsif (/^no-rc5$/) { $no_rc5=1; } 15355714Skris elsif (/^no-idea$/) { $no_idea=1; } 15472613Skris elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; } 15555714Skris elsif (/^no-bf$/) { $no_bf=1; } 15655714Skris elsif (/^no-cast$/) { $no_cast=1; } 15755714Skris elsif (/^no-md2$/) { $no_md2=1; } 15868651Skris elsif (/^no-md4$/) { $no_md4=1; } 15955714Skris elsif (/^no-md5$/) { $no_md5=1; } 16055714Skris elsif (/^no-sha$/) { $no_sha=1; } 16155714Skris elsif (/^no-ripemd$/) { $no_ripemd=1; } 16255714Skris elsif (/^no-mdc2$/) { $no_mdc2=1; } 16355714Skris elsif (/^no-rsa$/) { $no_rsa=1; } 16455714Skris elsif (/^no-dsa$/) { $no_dsa=1; } 16555714Skris elsif (/^no-dh$/) { $no_dh=1; } 166109998Smarkm elsif (/^no-ec$/) { $no_ec=1; } 16755714Skris elsif (/^no-hmac$/) { $no_hmac=1; } 168109998Smarkm elsif (/^no-aes$/) { $no_aes=1; } 169109998Smarkm elsif (/^no-evp$/) { $no_evp=1; } 170109998Smarkm elsif (/^no-lhash$/) { $no_lhash=1; } 171109998Smarkm elsif (/^no-stack$/) { $no_stack=1; } 172109998Smarkm elsif (/^no-err$/) { $no_err=1; } 173109998Smarkm elsif (/^no-buffer$/) { $no_buffer=1; } 174109998Smarkm elsif (/^no-bio$/) { $no_bio=1; } 175109998Smarkm #elsif (/^no-locking$/) { $no_locking=1; } 176109998Smarkm elsif (/^no-comp$/) { $no_comp=1; } 177109998Smarkm elsif (/^no-dso$/) { $no_dso=1; } 178109998Smarkm elsif (/^no-krb5$/) { $no_krb5=1; } 17955714Skris } 18055714Skris 18159191Skris 182109998Smarkmif (!$libname) { 183109998Smarkm if ($do_ssl) { 184109998Smarkm $libname="SSLEAY"; 185109998Smarkm } 186109998Smarkm if ($do_crypto) { 187109998Smarkm $libname="LIBEAY"; 188109998Smarkm } 189109998Smarkm} 190109998Smarkm 19168651Skris# If no platform is given, assume WIN32 192109998Smarkmif ($W32 + $W16 + $VMS + $OS2 == 0) { 19368651Skris $W32 = 1; 19468651Skris} 19568651Skris 19668651Skris# Add extra knowledge 19768651Skrisif ($W16) { 19868651Skris $no_fp_api=1; 19968651Skris} 20068651Skris 20155714Skrisif (!$do_ssl && !$do_crypto) 20255714Skris { 203109998Smarkm print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 20455714Skris exit(1); 20555714Skris } 20655714Skris 20755714Skris%ssl_list=&load_numbers($ssl_num); 20855714Skris$max_ssl = $max_num; 20955714Skris%crypto_list=&load_numbers($crypto_num); 21055714Skris$max_crypto = $max_num; 21155714Skris 21259191Skrismy $ssl="ssl/ssl.h"; 213109998Smarkm$ssl.=" ssl/kssl.h"; 21455714Skris 21559191Skrismy $crypto ="crypto/crypto.h"; 216109998Smarkm$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 217109998Smarkm$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 218109998Smarkm$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 219109998Smarkm$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 220109998Smarkm$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 221109998Smarkm$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 222109998Smarkm$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 223109998Smarkm$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 224109998Smarkm$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 225109998Smarkm$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 226109998Smarkm$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 227109998Smarkm$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 228109998Smarkm$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 229109998Smarkm$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 23055714Skris 23155714Skris$crypto.=" crypto/bn/bn.h"; 232109998Smarkm$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 233109998Smarkm$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 234109998Smarkm$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 235109998Smarkm$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 236109998Smarkm$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 23755714Skris 238109998Smarkm$crypto.=" crypto/engine/engine.h"; 239109998Smarkm$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 240109998Smarkm$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 241109998Smarkm$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 242109998Smarkm$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 243109998Smarkm$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 24455714Skris$crypto.=" crypto/conf/conf.h"; 24555714Skris$crypto.=" crypto/txt_db/txt_db.h"; 24655714Skris 247109998Smarkm$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 24855714Skris$crypto.=" crypto/objects/objects.h"; 24955714Skris$crypto.=" crypto/pem/pem.h"; 25055714Skris#$crypto.=" crypto/meth/meth.h"; 25155714Skris$crypto.=" crypto/asn1/asn1.h"; 252109998Smarkm$crypto.=" crypto/asn1/asn1t.h"; 25355714Skris$crypto.=" crypto/asn1/asn1_mac.h"; 254109998Smarkm$crypto.=" crypto/err/err.h" ; # unless $no_err; 25555714Skris$crypto.=" crypto/pkcs7/pkcs7.h"; 25655714Skris$crypto.=" crypto/pkcs12/pkcs12.h"; 25755714Skris$crypto.=" crypto/x509/x509.h"; 25855714Skris$crypto.=" crypto/x509/x509_vfy.h"; 25955714Skris$crypto.=" crypto/x509v3/x509v3.h"; 26055714Skris$crypto.=" crypto/rand/rand.h"; 261109998Smarkm$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 262109998Smarkm$crypto.=" crypto/ocsp/ocsp.h"; 263109998Smarkm$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 264109998Smarkm$crypto.=" crypto/krb5/krb5_asn.h"; 26555714Skris$crypto.=" crypto/tmdiff.h"; 26655714Skris 26768651Skrismy $symhacks="crypto/symhacks.h"; 26855714Skris 26968651Skrismy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 27068651Skrismy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 27155714Skris 27255714Skrisif ($do_update) { 27355714Skris 27455714Skrisif ($do_ssl == 1) { 27568651Skris 27668651Skris &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 27768651Skris if ($do_rewrite == 1) { 27868651Skris open(OUT, ">$ssl_num"); 27968651Skris &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 28068651Skris } else { 28168651Skris open(OUT, ">>$ssl_num"); 28268651Skris } 28368651Skris &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 28455714Skris close OUT; 28555714Skris} 28655714Skris 28755714Skrisif($do_crypto == 1) { 28868651Skris 28968651Skris &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 29068651Skris if ($do_rewrite == 1) { 29168651Skris open(OUT, ">$crypto_num"); 29268651Skris &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 29368651Skris } else { 29468651Skris open(OUT, ">>$crypto_num"); 29568651Skris } 29668651Skris &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 29755714Skris close OUT; 29859191Skris} 29955714Skris 300109998Smarkm} elsif ($do_checkexist) { 301109998Smarkm &check_existing(*ssl_list, @ssl_symbols) 302109998Smarkm if $do_ssl == 1; 303109998Smarkm &check_existing(*crypto_list, @crypto_symbols) 304109998Smarkm if $do_crypto == 1; 30568651Skris} elsif ($do_ctest || $do_ctestall) { 30659191Skris 30759191Skris print <<"EOF"; 30859191Skris 30959191Skris/* Test file to check all DEF file symbols are present by trying 31059191Skris * to link to all of them. This is *not* intended to be run! 31159191Skris */ 31259191Skris 31359191Skrisint main() 31459191Skris{ 31559191SkrisEOF 31668651Skris &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 31759191Skris if $do_ssl == 1; 31859191Skris 31968651Skris &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 32059191Skris if $do_crypto == 1; 32159191Skris 32259191Skris print "}\n"; 32359191Skris 32455714Skris} else { 32555714Skris 326109998Smarkm &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 32755714Skris if $do_ssl == 1; 32855714Skris 329109998Smarkm &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 33055714Skris if $do_crypto == 1; 33155714Skris 33255714Skris} 33355714Skris 33455714Skris 33555714Skrissub do_defs 33655714Skris{ 33768651Skris my($name,$files,$symhacksfile)=@_; 33859191Skris my $file; 33955714Skris my @ret; 34068651Skris my %syms; 34168651Skris my %platform; # For anything undefined, we assume "" 34268651Skris my %kind; # For anything undefined, we assume "FUNCTION" 34368651Skris my %algorithm; # For anything undefined, we assume "" 344109998Smarkm my %variant; 345109998Smarkm my %variant_cnt; # To be able to allocate "name{n}" if "name" 346109998Smarkm # is the same name as the original. 34759191Skris my $cpp; 348109998Smarkm my %unknown_algorithms = (); 34955714Skris 35068651Skris foreach $file (split(/\s+/,$symhacksfile." ".$files)) 35155714Skris { 352109998Smarkm print STDERR "DEBUG: starting on $file:\n" if $debug; 35355714Skris open(IN,"<$file") || die "unable to open $file:$!\n"; 35459191Skris my $line = "", my $def= ""; 35555714Skris my %tag = ( 35668651Skris (map { $_ => 0 } @known_platforms), 357109998Smarkm (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 358109998Smarkm (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 35955714Skris NOPROTO => 0, 36055714Skris PERL5 => 0, 36155714Skris _WINDLL => 0, 36255714Skris CONST_STRICT => 0, 36355714Skris TRUE => 1, 36455714Skris ); 36568651Skris my $symhacking = $file eq $symhacksfile; 366109998Smarkm my @current_platforms = (); 367109998Smarkm my @current_algorithms = (); 368109998Smarkm 369109998Smarkm # params: symbol, alias, platforms, kind 370109998Smarkm # The reason to put this subroutine in a variable is that 371109998Smarkm # it will otherwise create it's own, unshared, version of 372109998Smarkm # %tag and %variant... 373109998Smarkm my $make_variant = sub 374109998Smarkm { 375109998Smarkm my ($s, $a, $p, $k) = @_; 376109998Smarkm my ($a1, $a2); 377109998Smarkm 378109998Smarkm print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 379109998Smarkm if (defined($p)) 380109998Smarkm { 381109998Smarkm $a1 = join(",",$p, 382109998Smarkm grep(!/^$/, 383109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 384109998Smarkm @known_platforms)); 385109998Smarkm } 386109998Smarkm else 387109998Smarkm { 388109998Smarkm $a1 = join(",", 389109998Smarkm grep(!/^$/, 390109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 391109998Smarkm @known_platforms)); 392109998Smarkm } 393109998Smarkm $a2 = join(",", 394109998Smarkm grep(!/^$/, 395109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 396109998Smarkm @known_ossl_platforms)); 397109998Smarkm print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 398109998Smarkm if ($a1 eq "") { $a1 = $a2; } 399109998Smarkm elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 400109998Smarkm if ($a eq $s) 401109998Smarkm { 402109998Smarkm if (!defined($variant_cnt{$s})) 403109998Smarkm { 404109998Smarkm $variant_cnt{$s} = 0; 405109998Smarkm } 406109998Smarkm $variant_cnt{$s}++; 407109998Smarkm $a .= "{$variant_cnt{$s}}"; 408109998Smarkm } 409109998Smarkm my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 410109998Smarkm my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 411109998Smarkm if (!grep(/^$togrep$/, 412109998Smarkm split(/;/, defined($variant{$s})?$variant{$s}:""))) { 413109998Smarkm if (defined($variant{$s})) { $variant{$s} .= ";"; } 414109998Smarkm $variant{$s} .= $toadd; 415109998Smarkm } 416109998Smarkm print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 417109998Smarkm }; 418109998Smarkm 419109998Smarkm print STDERR "DEBUG: parsing ----------\n" if $debug; 42055714Skris while(<IN>) { 421109998Smarkm last if (/\/\* Error codes for the \w+ functions\. \*\//); 42255714Skris if ($line ne '') { 42355714Skris $_ = $line . $_; 42455714Skris $line = ''; 42555714Skris } 42655714Skris 42755714Skris if (/\\$/) { 428109998Smarkm chomp; # remove eol 429109998Smarkm chop; # remove ending backslash 43055714Skris $line = $_; 43155714Skris next; 43255714Skris } 43355714Skris 43468651Skris $cpp = 1 if /^\#.*ifdef.*cplusplus/; 43555714Skris if ($cpp) { 43668651Skris $cpp = 0 if /^\#.*endif/; 43755714Skris next; 43855714Skris } 43955714Skris 44055714Skris s/\/\*.*?\*\///gs; # ignore comments 44155714Skris s/{[^{}]*}//gs; # ignore {} blocks 442109998Smarkm print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 443109998Smarkm if (/^\#\s*ifndef\s+(.*)/) { 444109998Smarkm push(@tag,"-"); 44555714Skris push(@tag,$1); 44655714Skris $tag{$1}=-1; 447109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 448109998Smarkm } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 449109998Smarkm push(@tag,"-"); 450109998Smarkm if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 451109998Smarkm my $tmp_1 = $1; 452109998Smarkm my $tmp_; 453109998Smarkm foreach $tmp_ (split '\&\&',$tmp_1) { 454109998Smarkm $tmp_ =~ /!defined\(([^\)]+)\)/; 455109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 456109998Smarkm push(@tag,$1); 457109998Smarkm $tag{$1}=-1; 458109998Smarkm } 459109998Smarkm } else { 460109998Smarkm print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 461109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 462109998Smarkm push(@tag,$1); 463109998Smarkm $tag{$1}=-1; 464109998Smarkm } 465109998Smarkm } elsif (/^\#\s*ifdef\s+(.*)/) { 466109998Smarkm push(@tag,"-"); 46755714Skris push(@tag,$1); 46855714Skris $tag{$1}=1; 469109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 470109998Smarkm } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 471109998Smarkm push(@tag,"-"); 472109998Smarkm if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 473109998Smarkm my $tmp_1 = $1; 474109998Smarkm my $tmp_; 475109998Smarkm foreach $tmp_ (split '\|\|',$tmp_1) { 476109998Smarkm $tmp_ =~ /defined\(([^\)]+)\)/; 477109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 478109998Smarkm push(@tag,$1); 479109998Smarkm $tag{$1}=1; 480109998Smarkm } 481109998Smarkm } else { 482109998Smarkm print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 483109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 484109998Smarkm push(@tag,$1); 485109998Smarkm $tag{$1}=1; 486109998Smarkm } 48768651Skris } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 488109998Smarkm my $tag_i = $#tag; 489109998Smarkm while($tag[$tag_i] ne "-") { 490109998Smarkm if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 491109998Smarkm $tag{$tag[$tag_i]}=2; 492109998Smarkm print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 493109998Smarkm } 494109998Smarkm $tag_i--; 49568651Skris } 49655714Skris } elsif (/^\#\s*endif/) { 497109998Smarkm my $tag_i = $#tag; 498109998Smarkm while($tag[$tag_i] ne "-") { 499109998Smarkm my $t=$tag[$tag_i]; 500109998Smarkm print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 501109998Smarkm if ($tag{$t}==2) { 502109998Smarkm $tag{$t}=-1; 503109998Smarkm } else { 504109998Smarkm $tag{$t}=0; 505109998Smarkm } 506109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 507109998Smarkm pop(@tag); 508109998Smarkm if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 509109998Smarkm $t=$1; 510109998Smarkm } else { 511109998Smarkm $t=""; 512109998Smarkm } 513109998Smarkm if ($t ne "" 514109998Smarkm && !grep(/^$t$/, @known_algorithms)) { 515109998Smarkm $unknown_algorithms{$t} = 1; 516109998Smarkm #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 517109998Smarkm } 518109998Smarkm $tag_i--; 51968651Skris } 52055714Skris pop(@tag); 52155714Skris } elsif (/^\#\s*else/) { 522109998Smarkm my $tag_i = $#tag; 523109998Smarkm while($tag[$tag_i] ne "-") { 524109998Smarkm my $t=$tag[$tag_i]; 525109998Smarkm $tag{$t}= -$tag{$t}; 526109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 527109998Smarkm $tag_i--; 528109998Smarkm } 52955714Skris } elsif (/^\#\s*if\s+1/) { 530109998Smarkm push(@tag,"-"); 53155714Skris # Dummy tag 53255714Skris push(@tag,"TRUE"); 53355714Skris $tag{"TRUE"}=1; 534109998Smarkm print STDERR "DEBUG: $file: found 1\n" if $debug; 53559191Skris } elsif (/^\#\s*if\s+0/) { 536109998Smarkm push(@tag,"-"); 53759191Skris # Dummy tag 53859191Skris push(@tag,"TRUE"); 53959191Skris $tag{"TRUE"}=-1; 540109998Smarkm print STDERR "DEBUG: $file: found 0\n" if $debug; 54168651Skris } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 542109998Smarkm && $symhacking && $tag{'TRUE'} != -1) { 543109998Smarkm # This is for aliasing. When we find an alias, 544109998Smarkm # we have to invert 545109998Smarkm &$make_variant($1,$2); 546109998Smarkm print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 54768651Skris } 54868651Skris if (/^\#/) { 549109998Smarkm @current_platforms = 550109998Smarkm grep(!/^$/, 551109998Smarkm map { $tag{$_} == 1 ? $_ : 552109998Smarkm $tag{$_} == -1 ? "!".$_ : "" } 553109998Smarkm @known_platforms); 554109998Smarkm push @current_platforms 555109998Smarkm , grep(!/^$/, 556109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 557109998Smarkm $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 558109998Smarkm @known_ossl_platforms); 559109998Smarkm @current_algorithms = 560109998Smarkm grep(!/^$/, 561109998Smarkm map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 562109998Smarkm @known_algorithms); 563109998Smarkm $def .= 564109998Smarkm "#INFO:" 565109998Smarkm .join(',',@current_platforms).":" 566109998Smarkm .join(',',@current_algorithms).";"; 56759191Skris next; 56868651Skris } 569109998Smarkm if ($tag{'TRUE'} != -1) { 570109998Smarkm if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 571109998Smarkm next; 572109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 573109998Smarkm $def .= "int d2i_$3(void);"; 574109998Smarkm $def .= "int i2d_$3(void);"; 575109998Smarkm # Variant for platforms that do not 576109998Smarkm # have to access globale variables 577109998Smarkm # in shared libraries through functions 578109998Smarkm $def .= 579109998Smarkm "#INFO:" 580109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 581109998Smarkm .join(',',@current_algorithms).";"; 582109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 583109998Smarkm $def .= 584109998Smarkm "#INFO:" 585109998Smarkm .join(',',@current_platforms).":" 586109998Smarkm .join(',',@current_algorithms).";"; 587109998Smarkm # Variant for platforms that have to 588109998Smarkm # access globale variables in shared 589109998Smarkm # libraries through functions 590109998Smarkm &$make_variant("$2_it","$2_it", 591109998Smarkm "EXPORT_VAR_AS_FUNCTION", 592109998Smarkm "FUNCTION"); 593109998Smarkm next; 594109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 595109998Smarkm $def .= "int d2i_$3(void);"; 596109998Smarkm $def .= "int i2d_$3(void);"; 597109998Smarkm $def .= "int $3_free(void);"; 598109998Smarkm $def .= "int $3_new(void);"; 599109998Smarkm # Variant for platforms that do not 600109998Smarkm # have to access globale variables 601109998Smarkm # in shared libraries through functions 602109998Smarkm $def .= 603109998Smarkm "#INFO:" 604109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 605109998Smarkm .join(',',@current_algorithms).";"; 606109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 607109998Smarkm $def .= 608109998Smarkm "#INFO:" 609109998Smarkm .join(',',@current_platforms).":" 610109998Smarkm .join(',',@current_algorithms).";"; 611109998Smarkm # Variant for platforms that have to 612109998Smarkm # access globale variables in shared 613109998Smarkm # libraries through functions 614109998Smarkm &$make_variant("$2_it","$2_it", 615109998Smarkm "EXPORT_VAR_AS_FUNCTION", 616109998Smarkm "FUNCTION"); 617109998Smarkm next; 618109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 619109998Smarkm /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 620109998Smarkm $def .= "int d2i_$1(void);"; 621109998Smarkm $def .= "int i2d_$1(void);"; 622109998Smarkm $def .= "int $1_free(void);"; 623109998Smarkm $def .= "int $1_new(void);"; 624109998Smarkm # Variant for platforms that do not 625109998Smarkm # have to access globale variables 626109998Smarkm # in shared libraries through functions 627109998Smarkm $def .= 628109998Smarkm "#INFO:" 629109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 630109998Smarkm .join(',',@current_algorithms).";"; 631109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 632109998Smarkm $def .= 633109998Smarkm "#INFO:" 634109998Smarkm .join(',',@current_platforms).":" 635109998Smarkm .join(',',@current_algorithms).";"; 636109998Smarkm # Variant for platforms that have to 637109998Smarkm # access globale variables in shared 638109998Smarkm # libraries through functions 639109998Smarkm &$make_variant("$1_it","$1_it", 640109998Smarkm "EXPORT_VAR_AS_FUNCTION", 641109998Smarkm "FUNCTION"); 642109998Smarkm next; 643109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 644109998Smarkm $def .= "int d2i_$2(void);"; 645109998Smarkm $def .= "int i2d_$2(void);"; 646109998Smarkm # Variant for platforms that do not 647109998Smarkm # have to access globale variables 648109998Smarkm # in shared libraries through functions 649109998Smarkm $def .= 650109998Smarkm "#INFO:" 651109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 652109998Smarkm .join(',',@current_algorithms).";"; 653109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 654109998Smarkm $def .= 655109998Smarkm "#INFO:" 656109998Smarkm .join(',',@current_platforms).":" 657109998Smarkm .join(',',@current_algorithms).";"; 658109998Smarkm # Variant for platforms that have to 659109998Smarkm # access globale variables in shared 660109998Smarkm # libraries through functions 661109998Smarkm &$make_variant("$2_it","$2_it", 662109998Smarkm "EXPORT_VAR_AS_FUNCTION", 663109998Smarkm "FUNCTION"); 664109998Smarkm next; 665109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 666109998Smarkm $def .= "int d2i_$2(void);"; 667109998Smarkm $def .= "int i2d_$2(void);"; 668109998Smarkm $def .= "int $2_free(void);"; 669109998Smarkm $def .= "int $2_new(void);"; 670109998Smarkm # Variant for platforms that do not 671109998Smarkm # have to access globale variables 672109998Smarkm # in shared libraries through functions 673109998Smarkm $def .= 674109998Smarkm "#INFO:" 675109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 676109998Smarkm .join(',',@current_algorithms).";"; 677109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 678109998Smarkm $def .= 679109998Smarkm "#INFO:" 680109998Smarkm .join(',',@current_platforms).":" 681109998Smarkm .join(',',@current_algorithms).";"; 682109998Smarkm # Variant for platforms that have to 683109998Smarkm # access globale variables in shared 684109998Smarkm # libraries through functions 685109998Smarkm &$make_variant("$2_it","$2_it", 686109998Smarkm "EXPORT_VAR_AS_FUNCTION", 687109998Smarkm "FUNCTION"); 688109998Smarkm next; 689109998Smarkm } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 690109998Smarkm # Variant for platforms that do not 691109998Smarkm # have to access globale variables 692109998Smarkm # in shared libraries through functions 693109998Smarkm $def .= 694109998Smarkm "#INFO:" 695109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 696109998Smarkm .join(',',@current_algorithms).";"; 697109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 698109998Smarkm $def .= 699109998Smarkm "#INFO:" 700109998Smarkm .join(',',@current_platforms).":" 701109998Smarkm .join(',',@current_algorithms).";"; 702109998Smarkm # Variant for platforms that have to 703109998Smarkm # access globale variables in shared 704109998Smarkm # libraries through functions 705109998Smarkm &$make_variant("$1_it","$1_it", 706109998Smarkm "EXPORT_VAR_AS_FUNCTION", 707109998Smarkm "FUNCTION"); 708109998Smarkm next; 709109998Smarkm } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 710109998Smarkm next; 711109998Smarkm } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 712109998Smarkm next; 713109998Smarkm } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 714109998Smarkm /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) { 715109998Smarkm # Things not in Win16 716109998Smarkm $def .= 717109998Smarkm "#INFO:" 718109998Smarkm .join(',',"!WIN16",@current_platforms).":" 719109998Smarkm .join(',',@current_algorithms).";"; 720109998Smarkm $def .= "int PEM_read_$1(void);"; 721109998Smarkm $def .= "int PEM_write_$1(void);"; 722109998Smarkm $def .= 723109998Smarkm "#INFO:" 724109998Smarkm .join(',',@current_platforms).":" 725109998Smarkm .join(',',@current_algorithms).";"; 726109998Smarkm # Things that are everywhere 727109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 728109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 729109998Smarkm next; 730109998Smarkm } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 731109998Smarkm /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 732109998Smarkm # Things not in Win16 733109998Smarkm $def .= 734109998Smarkm "#INFO:" 735109998Smarkm .join(',',"!WIN16",@current_platforms).":" 736109998Smarkm .join(',',@current_algorithms).";"; 737109998Smarkm $def .= "int PEM_write_$1(void);"; 738109998Smarkm $def .= 739109998Smarkm "#INFO:" 740109998Smarkm .join(',',@current_platforms).":" 741109998Smarkm .join(',',@current_algorithms).";"; 742109998Smarkm # Things that are everywhere 743109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 744109998Smarkm next; 745109998Smarkm } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 746109998Smarkm /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 747109998Smarkm # Things not in Win16 748109998Smarkm $def .= 749109998Smarkm "#INFO:" 750109998Smarkm .join(',',"!WIN16",@current_platforms).":" 751109998Smarkm .join(',',@current_algorithms).";"; 752109998Smarkm $def .= "int PEM_read_$1(void);"; 753109998Smarkm $def .= 754109998Smarkm "#INFO:" 755109998Smarkm .join(',',@current_platforms).":" 756109998Smarkm .join(',',@current_algorithms).";"; 757109998Smarkm # Things that are everywhere 758109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 759109998Smarkm next; 760109998Smarkm } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 761109998Smarkm # Variant for platforms that do not 762109998Smarkm # have to access globale variables 763109998Smarkm # in shared libraries through functions 764109998Smarkm $def .= 765109998Smarkm "#INFO:" 766109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 767109998Smarkm .join(',',@current_algorithms).";"; 768109998Smarkm $def .= "OPENSSL_EXTERN int _shadow_$2;"; 769109998Smarkm $def .= 770109998Smarkm "#INFO:" 771109998Smarkm .join(',',@current_platforms).":" 772109998Smarkm .join(',',@current_algorithms).";"; 773109998Smarkm # Variant for platforms that have to 774109998Smarkm # access globale variables in shared 775109998Smarkm # libraries through functions 776109998Smarkm &$make_variant("_shadow_$2","_shadow_$2", 777109998Smarkm "EXPORT_VAR_AS_FUNCTION", 778109998Smarkm "FUNCTION"); 779109998Smarkm } elsif ($tag{'CONST_STRICT'} != 1) { 78068651Skris if (/\{|\/\*|\([^\)]*$/) { 78155714Skris $line = $_; 78255714Skris } else { 78355714Skris $def .= $_; 78455714Skris } 78555714Skris } 78655714Skris } 787109998Smarkm } 78855714Skris close(IN); 78955714Skris 79068651Skris my $algs; 79168651Skris my $plays; 79268651Skris 793109998Smarkm print STDERR "DEBUG: postprocessing ----------\n" if $debug; 79455714Skris foreach (split /;/, $def) { 79568651Skris my $s; my $k = "FUNCTION"; my $p; my $a; 79655714Skris s/^[\n\s]*//g; 79755714Skris s/[\n\s]*$//g; 79868651Skris next if(/\#undef/); 79955714Skris next if(/typedef\W/); 80068651Skris next if(/\#define/); 80168651Skris 802109998Smarkm print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 80368651Skris if (/^\#INFO:([^:]*):(.*)$/) { 80468651Skris $plats = $1; 80568651Skris $algs = $2; 806109998Smarkm print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 80768651Skris next; 808109998Smarkm } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 80968651Skris $s = $1; 81068651Skris $k = "VARIABLE"; 811109998Smarkm print STDERR "DEBUG: found external variable $s\n" if $debug; 812109998Smarkm } elsif (/\(\*(\w*(\{[0-9]+\})?)\([^\)]+/) { 81368651Skris $s = $1; 814109998Smarkm print STDERR "DEBUG: found ANSI C function $s\n" if $debug; 81555714Skris } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) { 81655714Skris # K&R C 817109998Smarkm print STDERR "DEBUG: found K&R C function $s\n" if $debug; 81855714Skris next; 819109998Smarkm } elsif (/\w+\W+\w+(\{[0-9]+\})?\W*\(.*\)$/s) { 82055714Skris while (not /\(\)$/s) { 82155714Skris s/[^\(\)]*\)$/\)/s; 82255714Skris s/\([^\(\)]*\)\)$/\)/s; 82355714Skris } 82455714Skris s/\(void\)//; 825109998Smarkm /(\w+(\{[0-9]+\})?)\W*\(\)/s; 82668651Skris $s = $1; 827109998Smarkm print STDERR "DEBUG: found function $s\n" if $debug; 82855714Skris } elsif (/\(/ and not (/=/)) { 82955714Skris print STDERR "File $file: cannot parse: $_;\n"; 83068651Skris next; 83168651Skris } else { 83268651Skris next; 83355714Skris } 83468651Skris 83568651Skris $syms{$s} = 1; 83668651Skris $kind{$s} = $k; 83768651Skris 83868651Skris $p = $plats; 83968651Skris $a = $algs; 84068651Skris $a .= ",BF" if($s =~ /EVP_bf/); 84168651Skris $a .= ",CAST" if($s =~ /EVP_cast/); 84268651Skris $a .= ",DES" if($s =~ /EVP_des/); 84368651Skris $a .= ",DSA" if($s =~ /EVP_dss/); 84468651Skris $a .= ",IDEA" if($s =~ /EVP_idea/); 84568651Skris $a .= ",MD2" if($s =~ /EVP_md2/); 84668651Skris $a .= ",MD4" if($s =~ /EVP_md4/); 84768651Skris $a .= ",MD5" if($s =~ /EVP_md5/); 84868651Skris $a .= ",RC2" if($s =~ /EVP_rc2/); 84968651Skris $a .= ",RC4" if($s =~ /EVP_rc4/); 85068651Skris $a .= ",RC5" if($s =~ /EVP_rc5/); 85168651Skris $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 85268651Skris $a .= ",SHA" if($s =~ /EVP_sha/); 85368651Skris $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 85468651Skris $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 85568651Skris $a .= ",RSA" if($s =~ /RSAPrivateKey/); 85668651Skris $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 85768651Skris 858109998Smarkm $platform{$s} = 859109998Smarkm &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 86068651Skris $algorithm{$s} .= ','.$a; 86168651Skris 862109998Smarkm if (defined($variant{$s})) { 863109998Smarkm foreach $v (split /;/,$variant{$s}) { 864109998Smarkm (my $r, my $p, my $k) = split(/:/,$v); 865109998Smarkm my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 866109998Smarkm $syms{$r} = 1; 867109998Smarkm if (!defined($k)) { $k = $kind{$s}; } 868109998Smarkm $kind{$r} = $k."(".$s.")"; 869109998Smarkm $algorithm{$r} = $algorithm{$s}; 870109998Smarkm $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 871109998Smarkm $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 872109998Smarkm print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 873109998Smarkm } 87468651Skris } 875109998Smarkm print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 87655714Skris } 87755714Skris } 87855714Skris 87968651Skris # Prune the returned symbols 88055714Skris 88168651Skris delete $syms{"bn_dump1"}; 88268651Skris $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 88368651Skris 884109998Smarkm $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 885109998Smarkm $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 886109998Smarkm $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 887109998Smarkm $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 88868651Skris 88968651Skris # Info we know about 89068651Skris 89168651Skris push @ret, map { $_."\\".&info_string($_,"EXIST", 89268651Skris $platform{$_}, 89368651Skris $kind{$_}, 89468651Skris $algorithm{$_}) } keys %syms; 89568651Skris 896109998Smarkm if (keys %unknown_algorithms) { 897109998Smarkm print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 898109998Smarkm print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 899109998Smarkm } 90068651Skris return(@ret); 90168651Skris} 90268651Skris 903109998Smarkm# Param: string of comma-separated platform-specs. 904109998Smarkmsub reduce_platforms 905109998Smarkm{ 906109998Smarkm my ($platforms) = @_; 90768651Skris my $pl = defined($platforms) ? $platforms : ""; 90868651Skris my %p = map { $_ => 0 } split /,/, $pl; 90968651Skris my $ret; 91068651Skris 911109998Smarkm print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 912109998Smarkm if $debug; 91368651Skris # We do this, because if there's code like the following, it really 91468651Skris # means the function exists in all cases and should therefore be 91568651Skris # everywhere. By increasing and decreasing, we may attain 0: 91668651Skris # 91768651Skris # ifndef WIN16 91868651Skris # int foo(); 91968651Skris # else 92068651Skris # int _fat foo(); 92168651Skris # endif 92268651Skris foreach $platform (split /,/, $pl) { 92368651Skris if ($platform =~ /^!(.*)$/) { 92468651Skris $p{$1}--; 92568651Skris } else { 92668651Skris $p{$platform}++; 92755714Skris } 92855714Skris } 92968651Skris foreach $platform (keys %p) { 93068651Skris if ($p{$platform} == 0) { delete $p{$platform}; } 93155714Skris } 93255714Skris 93368651Skris delete $p{""}; 934109998Smarkm 935109998Smarkm $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 936109998Smarkm print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 937109998Smarkm if $debug; 938109998Smarkm return $ret; 939109998Smarkm} 940109998Smarkm 941109998Smarkmsub info_string { 942109998Smarkm (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 943109998Smarkm 944109998Smarkm my %a = defined($algorithms) ? 945109998Smarkm map { $_ => 1 } split /,/, $algorithms : (); 946109998Smarkm my $k = defined($kind) ? $kind : "FUNCTION"; 947109998Smarkm my $ret; 948109998Smarkm my $p = &reduce_platforms($platforms); 949109998Smarkm 95068651Skris delete $a{""}; 95155714Skris 95268651Skris $ret = $exist; 953109998Smarkm $ret .= ":".$p; 95468651Skris $ret .= ":".$k; 955109998Smarkm $ret .= ":".join(',',sort keys %a); 95668651Skris return $ret; 95755714Skris} 95855714Skris 95968651Skrissub maybe_add_info { 96068651Skris (my $name, *nums, my @symbols) = @_; 96168651Skris my $sym; 96268651Skris my $new_info = 0; 963109998Smarkm my %syms=(); 96468651Skris 96568651Skris print STDERR "Updating $name info\n"; 96668651Skris foreach $sym (@symbols) { 96768651Skris (my $s, my $i) = split /\\/, $sym; 96868651Skris if (defined($nums{$s})) { 969109998Smarkm $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 97068651Skris (my $n, my $dummy) = split /\\/, $nums{$s}; 97168651Skris if (!defined($dummy) || $i ne $dummy) { 97268651Skris $nums{$s} = $n."\\".$i; 97368651Skris $new_info++; 974109998Smarkm print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 97568651Skris } 97668651Skris } 977109998Smarkm $syms{$s} = 1; 97868651Skris } 979109998Smarkm 980109998Smarkm my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 981109998Smarkm foreach $sym (@s) { 982109998Smarkm (my $n, my $i) = split /\\/, $nums{$sym}; 983109998Smarkm if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 984109998Smarkm $new_info++; 985109998Smarkm print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 986109998Smarkm } 987109998Smarkm } 98868651Skris if ($new_info) { 98968651Skris print STDERR "$new_info old symbols got an info update\n"; 99068651Skris if (!$do_rewrite) { 99168651Skris print STDERR "You should do a rewrite to fix this.\n"; 99268651Skris } 99368651Skris } else { 99468651Skris print STDERR "No old symbols needed info update\n"; 99568651Skris } 99668651Skris} 99768651Skris 998109998Smarkm# Param: string of comma-separated keywords, each possibly prefixed with a "!" 999109998Smarkmsub is_valid 1000109998Smarkm{ 1001109998Smarkm my ($keywords_txt,$platforms) = @_; 1002109998Smarkm my (@keywords) = split /,/,$keywords_txt; 1003109998Smarkm my ($falsesum, $truesum) = (0, !grep(/^[^!]/,@keywords)); 1004109998Smarkm 1005109998Smarkm # Param: one keyword 1006109998Smarkm sub recognise 1007109998Smarkm { 1008109998Smarkm my ($keyword,$platforms) = @_; 1009109998Smarkm 1010109998Smarkm if ($platforms) { 1011109998Smarkm # platforms 1012109998Smarkm if ($keyword eq "VMS" && $VMS) { return 1; } 1013109998Smarkm if ($keyword eq "WIN32" && $W32) { return 1; } 1014109998Smarkm if ($keyword eq "WIN16" && $W16) { return 1; } 1015109998Smarkm if ($keyword eq "WINNT" && $NT) { return 1; } 1016109998Smarkm if ($keyword eq "OS2" && $OS2) { return 1; } 1017109998Smarkm # Special platforms: 1018109998Smarkm # EXPORT_VAR_AS_FUNCTION means that global variables 1019109998Smarkm # will be represented as functions. This currently 1020109998Smarkm # only happens on VMS-VAX. 1021109998Smarkm if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1022109998Smarkm return 1; 1023109998Smarkm } 1024109998Smarkm return 0; 1025109998Smarkm } else { 1026109998Smarkm # algorithms 1027109998Smarkm if ($keyword eq "RC2" && $no_rc2) { return 0; } 1028109998Smarkm if ($keyword eq "RC4" && $no_rc4) { return 0; } 1029109998Smarkm if ($keyword eq "RC5" && $no_rc5) { return 0; } 1030109998Smarkm if ($keyword eq "IDEA" && $no_idea) { return 0; } 1031109998Smarkm if ($keyword eq "DES" && $no_des) { return 0; } 1032109998Smarkm if ($keyword eq "BF" && $no_bf) { return 0; } 1033109998Smarkm if ($keyword eq "CAST" && $no_cast) { return 0; } 1034109998Smarkm if ($keyword eq "MD2" && $no_md2) { return 0; } 1035109998Smarkm if ($keyword eq "MD4" && $no_md4) { return 0; } 1036109998Smarkm if ($keyword eq "MD5" && $no_md5) { return 0; } 1037109998Smarkm if ($keyword eq "SHA" && $no_sha) { return 0; } 1038109998Smarkm if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1039109998Smarkm if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1040109998Smarkm if ($keyword eq "RSA" && $no_rsa) { return 0; } 1041109998Smarkm if ($keyword eq "DSA" && $no_dsa) { return 0; } 1042109998Smarkm if ($keyword eq "DH" && $no_dh) { return 0; } 1043109998Smarkm if ($keyword eq "EC" && $no_ec) { return 0; } 1044109998Smarkm if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1045109998Smarkm if ($keyword eq "AES" && $no_aes) { return 0; } 1046109998Smarkm if ($keyword eq "EVP" && $no_evp) { return 0; } 1047109998Smarkm if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1048109998Smarkm if ($keyword eq "STACK" && $no_stack) { return 0; } 1049109998Smarkm if ($keyword eq "ERR" && $no_err) { return 0; } 1050109998Smarkm if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1051109998Smarkm if ($keyword eq "BIO" && $no_bio) { return 0; } 1052109998Smarkm if ($keyword eq "COMP" && $no_comp) { return 0; } 1053109998Smarkm if ($keyword eq "DSO" && $no_dso) { return 0; } 1054109998Smarkm if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1055109998Smarkm if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1056109998Smarkm 1057109998Smarkm # Nothing recognise as true 1058109998Smarkm return 1; 1059109998Smarkm } 1060109998Smarkm } 1061109998Smarkm 1062109998Smarkm foreach $k (@keywords) { 1063109998Smarkm if ($k =~ /^!(.*)$/) { 1064109998Smarkm $falsesum += &recognise($1,$platforms); 1065109998Smarkm } else { 1066109998Smarkm $truesum += &recognise($k,$platforms); 1067109998Smarkm } 1068109998Smarkm } 1069109998Smarkm print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1070109998Smarkm return (!$falsesum) && $truesum; 1071109998Smarkm} 1072109998Smarkm 107359191Skrissub print_test_file 107459191Skris{ 1075109998Smarkm (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 107659191Skris my $n = 1; my @e; my @r; 107768651Skris my $sym; my $prev = ""; my $prefSSLeay; 107859191Skris 1079109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1080109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 108168651Skris @symbols=((sort @e),(sort @r)); 108259191Skris 108368651Skris foreach $sym (@symbols) { 108468651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1085109998Smarkm my $v = 0; 1086109998Smarkm $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1087109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1088109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1089109998Smarkm if (!defined($nums{$s})) { 1090109998Smarkm print STDERR "Warning: $s does not have a number assigned\n" 1091109998Smarkm if(!$do_update); 1092109998Smarkm } elsif (is_valid($p,1) && is_valid($a,0)) { 1093109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1094109998Smarkm if ($prev eq $s2) { 1095109998Smarkm print OUT "\t/* The following has already appeared previously */\n"; 1096109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1097109998Smarkm } 1098109998Smarkm $prev = $s2; # To warn about duplicates... 1099109998Smarkm 1100109998Smarkm ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1101109998Smarkm if ($v) { 1102109998Smarkm print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 110368651Skris } else { 1104109998Smarkm print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 110568651Skris } 110659191Skris } 110759191Skris } 110859191Skris} 110959191Skris 111055714Skrissub print_def_file 111155714Skris{ 111268651Skris (*OUT,my $name,*nums,my @symbols)=@_; 1113109998Smarkm my $n = 1; my @e; my @r; my @v; my $prev=""; 1114109998Smarkm my $liboptions=""; 111555714Skris 111655714Skris if ($W32) 111755714Skris { $name.="32"; } 1118109998Smarkm elsif ($W16) 111955714Skris { $name.="16"; } 1120109998Smarkm elsif ($OS2) 1121109998Smarkm { $liboptions = "INITINSTANCE\nDATA NONSHARED"; } 112255714Skris 112355714Skris print OUT <<"EOF"; 112455714Skris; 112555714Skris; Definition file for the DLL version of the $name library from OpenSSL 112655714Skris; 112755714Skris 1128109998SmarkmLIBRARY $name $liboptions 112955714Skris 113055714SkrisDESCRIPTION 'OpenSSL $name - http://www.openssl.org/' 113155714Skris 113255714SkrisEOF 113355714Skris 1134109998Smarkm if ($W16) { 113555714Skris print <<"EOF"; 113655714SkrisCODE PRELOAD MOVEABLE 113755714SkrisDATA PRELOAD MOVEABLE SINGLE 113855714Skris 113955714SkrisEXETYPE WINDOWS 114055714Skris 114155714SkrisHEAPSIZE 4096 114255714SkrisSTACKSIZE 8192 114355714Skris 114455714SkrisEOF 114555714Skris } 114655714Skris 114755714Skris print "EXPORTS\n"; 114855714Skris 1149109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1150109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1151109998Smarkm (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1152109998Smarkm @symbols=((sort @e),(sort @r), (sort @v)); 115355714Skris 115455714Skris 115568651Skris foreach $sym (@symbols) { 115668651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1157109998Smarkm my $v = 0; 1158109998Smarkm $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 115968651Skris if (!defined($nums{$s})) { 116068651Skris printf STDERR "Warning: $s does not have a number assigned\n" 1161109998Smarkm if(!$do_update); 116255714Skris } else { 1163109998Smarkm (my $n, my $dummy) = split /\\/, $nums{$s}; 116468651Skris my %pf = (); 1165109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1166109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1167109998Smarkm if (is_valid($p,1) && is_valid($a,0)) { 1168109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1169109998Smarkm if ($prev eq $s2) { 1170109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1171109998Smarkm } 1172109998Smarkm $prev = $s2; # To warn about duplicates... 1173109998Smarkm if($v && !$OS2) { 1174109998Smarkm printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1175109998Smarkm } else { 1176109998Smarkm printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1177109998Smarkm } 117868651Skris } 117955714Skris } 118055714Skris } 118155714Skris printf OUT "\n"; 118255714Skris} 118355714Skris 118455714Skrissub load_numbers 118555714Skris{ 118655714Skris my($name)=@_; 118755714Skris my(@a,%ret); 118855714Skris 118955714Skris $max_num = 0; 119068651Skris $num_noinfo = 0; 119168651Skris $prev = ""; 1192109998Smarkm $prev_cnt = 0; 119355714Skris 119455714Skris open(IN,"<$name") || die "unable to open $name:$!\n"; 119555714Skris while (<IN>) { 119655714Skris chop; 119755714Skris s/#.*$//; 119855714Skris next if /^\s*$/; 119955714Skris @a=split; 120068651Skris if (defined $ret{$a[0]}) { 1201109998Smarkm # This is actually perfectly OK 1202109998Smarkm #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 120368651Skris } 120468651Skris if ($max_num > $a[1]) { 120568651Skris print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 120668651Skris } 1207109998Smarkm elsif ($max_num == $a[1]) { 120868651Skris # This is actually perfectly OK 120968651Skris #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1210109998Smarkm if ($a[0] eq $prev) { 1211109998Smarkm $prev_cnt++; 1212109998Smarkm $a[0] .= "{$prev_cnt}"; 1213109998Smarkm } 121468651Skris } 1215109998Smarkm else { 1216109998Smarkm $prev_cnt = 0; 1217109998Smarkm } 121868651Skris if ($#a < 2) { 121968651Skris # Existence will be proven later, in do_defs 122068651Skris $ret{$a[0]}=$a[1]; 122168651Skris $num_noinfo++; 122268651Skris } else { 122368651Skris $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 122468651Skris } 122555714Skris $max_num = $a[1] if $a[1] > $max_num; 122668651Skris $prev=$a[0]; 122755714Skris } 122868651Skris if ($num_noinfo) { 122968651Skris print STDERR "Warning: $num_noinfo symbols were without info."; 123068651Skris if ($do_rewrite) { 123168651Skris printf STDERR " The rewrite will fix this.\n"; 123268651Skris } else { 123368651Skris printf STDERR " You should do a rewrite to fix this.\n"; 123468651Skris } 123568651Skris } 123655714Skris close(IN); 123755714Skris return(%ret); 123855714Skris} 123955714Skris 124068651Skrissub parse_number 124168651Skris{ 124268651Skris (my $str, my $what) = @_; 124368651Skris (my $n, my $i) = split(/\\/,$str); 124468651Skris if ($what eq "n") { 124568651Skris return $n; 124668651Skris } else { 124768651Skris return $i; 124868651Skris } 124968651Skris} 125068651Skris 125168651Skrissub rewrite_numbers 125268651Skris{ 125368651Skris (*OUT,$name,*nums,@symbols)=@_; 125468651Skris my $thing; 125568651Skris 125668651Skris print STDERR "Rewriting $name\n"; 125768651Skris 1258109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 125968651Skris my $r; my %r; my %rsyms; 126068651Skris foreach $r (@r) { 126168651Skris (my $s, my $i) = split /\\/, $r; 126268651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 126368651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 126468651Skris $r{$a} = $s."\\".$i; 126568651Skris $rsyms{$s} = 1; 126668651Skris } 126768651Skris 1268109998Smarkm my %syms = (); 1269109998Smarkm foreach $_ (@symbols) { 1270109998Smarkm (my $n, my $i) = split /\\/; 1271109998Smarkm $syms{$n} = 1; 1272109998Smarkm } 1273109998Smarkm 1274109998Smarkm my @s=sort { 1275109998Smarkm &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1276109998Smarkm || $a cmp $b 1277109998Smarkm } keys %nums; 127868651Skris foreach $sym (@s) { 127968651Skris (my $n, my $i) = split /\\/, $nums{$sym}; 128068651Skris next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 128168651Skris next if defined($rsyms{$sym}); 1282109998Smarkm print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1283109998Smarkm $i="NOEXIST::FUNCTION:" 1284109998Smarkm if !defined($i) || $i eq "" || !defined($syms{$sym}); 1285109998Smarkm my $s2 = $sym; 1286109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1287109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 128868651Skris if (exists $r{$sym}) { 128968651Skris (my $s, $i) = split /\\/,$r{$sym}; 1290109998Smarkm my $s2 = $s; 1291109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1292109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 129368651Skris } 129468651Skris } 129568651Skris} 129668651Skris 129755714Skrissub update_numbers 129855714Skris{ 129968651Skris (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 130068651Skris my $new_syms = 0; 130168651Skris 130268651Skris print STDERR "Updating $name numbers\n"; 130368651Skris 1304109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 130568651Skris my $r; my %r; my %rsyms; 130668651Skris foreach $r (@r) { 130768651Skris (my $s, my $i) = split /\\/, $r; 130868651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 130968651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 131068651Skris $r{$a} = $s."\\".$i; 131168651Skris $rsyms{$s} = 1; 131268651Skris } 131368651Skris 131468651Skris foreach $sym (@symbols) { 131568651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 131668651Skris next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 131768651Skris next if defined($rsyms{$sym}); 131868651Skris die "ERROR: Symbol $sym had no info attached to it." 131968651Skris if $i eq ""; 132068651Skris if (!exists $nums{$s}) { 132168651Skris $new_syms++; 1322109998Smarkm my $s2 = $s; 1323109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1324109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 132568651Skris if (exists $r{$s}) { 132668651Skris ($s, $i) = split /\\/,$r{$s}; 1327109998Smarkm $s =~ s/\{[0-9]+\}$//; 1328109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 132968651Skris } 133055714Skris } 133155714Skris } 133268651Skris if($new_syms) { 133368651Skris print STDERR "$new_syms New symbols added\n"; 133455714Skris } else { 133568651Skris print STDERR "No New symbols Added\n"; 133655714Skris } 133755714Skris} 133868651Skris 133968651Skrissub check_existing 134068651Skris{ 134168651Skris (*nums, my @symbols)=@_; 134268651Skris my %existing; my @remaining; 134368651Skris @remaining=(); 134468651Skris foreach $sym (@symbols) { 134568651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 134668651Skris $existing{$s}=1; 134768651Skris } 134868651Skris foreach $sym (keys %nums) { 134968651Skris if (!exists $existing{$sym}) { 135068651Skris push @remaining, $sym; 135168651Skris } 135268651Skris } 135368651Skris if(@remaining) { 135468651Skris print STDERR "The following symbols do not seem to exist:\n"; 135568651Skris foreach $sym (@remaining) { 135668651Skris print STDERR "\t",$sym,"\n"; 135768651Skris } 135868651Skris } 135968651Skris} 136068651Skris 1361