mkdef.pl revision 111147
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" 94111147Snectar "FP_API", "STDIO", "SOCK", "KRB5", "ENGINE", "HW" ); 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; 110111147Snectarmy $no_ec; my $no_engine; my $no_hw; 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; } 179111147Snectar elsif (/^no-engine$/) { $no_engine=1; } 180111147Snectar elsif (/^no-hw$/) { $no_hw=1; } 18155714Skris } 18255714Skris 18359191Skris 184109998Smarkmif (!$libname) { 185109998Smarkm if ($do_ssl) { 186109998Smarkm $libname="SSLEAY"; 187109998Smarkm } 188109998Smarkm if ($do_crypto) { 189109998Smarkm $libname="LIBEAY"; 190109998Smarkm } 191109998Smarkm} 192109998Smarkm 19368651Skris# If no platform is given, assume WIN32 194109998Smarkmif ($W32 + $W16 + $VMS + $OS2 == 0) { 19568651Skris $W32 = 1; 19668651Skris} 19768651Skris 19868651Skris# Add extra knowledge 19968651Skrisif ($W16) { 20068651Skris $no_fp_api=1; 20168651Skris} 20268651Skris 20355714Skrisif (!$do_ssl && !$do_crypto) 20455714Skris { 205109998Smarkm print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 20655714Skris exit(1); 20755714Skris } 20855714Skris 20955714Skris%ssl_list=&load_numbers($ssl_num); 21055714Skris$max_ssl = $max_num; 21155714Skris%crypto_list=&load_numbers($crypto_num); 21255714Skris$max_crypto = $max_num; 21355714Skris 21459191Skrismy $ssl="ssl/ssl.h"; 215109998Smarkm$ssl.=" ssl/kssl.h"; 21655714Skris 21759191Skrismy $crypto ="crypto/crypto.h"; 218109998Smarkm$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 219109998Smarkm$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 220109998Smarkm$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 221109998Smarkm$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 222109998Smarkm$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 223109998Smarkm$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 224109998Smarkm$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 225109998Smarkm$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 226109998Smarkm$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 227109998Smarkm$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 228109998Smarkm$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 229109998Smarkm$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 230109998Smarkm$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 231109998Smarkm$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 23255714Skris 23355714Skris$crypto.=" crypto/bn/bn.h"; 234109998Smarkm$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 235109998Smarkm$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 236109998Smarkm$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 237109998Smarkm$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 238109998Smarkm$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 23955714Skris 240111147Snectar$crypto.=" crypto/engine/engine.h"; # unless $no_engine; 241109998Smarkm$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 242109998Smarkm$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 243109998Smarkm$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 244109998Smarkm$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 245109998Smarkm$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 24655714Skris$crypto.=" crypto/conf/conf.h"; 24755714Skris$crypto.=" crypto/txt_db/txt_db.h"; 24855714Skris 249109998Smarkm$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 25055714Skris$crypto.=" crypto/objects/objects.h"; 25155714Skris$crypto.=" crypto/pem/pem.h"; 25255714Skris#$crypto.=" crypto/meth/meth.h"; 25355714Skris$crypto.=" crypto/asn1/asn1.h"; 254109998Smarkm$crypto.=" crypto/asn1/asn1t.h"; 25555714Skris$crypto.=" crypto/asn1/asn1_mac.h"; 256109998Smarkm$crypto.=" crypto/err/err.h" ; # unless $no_err; 25755714Skris$crypto.=" crypto/pkcs7/pkcs7.h"; 25855714Skris$crypto.=" crypto/pkcs12/pkcs12.h"; 25955714Skris$crypto.=" crypto/x509/x509.h"; 26055714Skris$crypto.=" crypto/x509/x509_vfy.h"; 26155714Skris$crypto.=" crypto/x509v3/x509v3.h"; 26255714Skris$crypto.=" crypto/rand/rand.h"; 263109998Smarkm$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 264109998Smarkm$crypto.=" crypto/ocsp/ocsp.h"; 265109998Smarkm$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 266109998Smarkm$crypto.=" crypto/krb5/krb5_asn.h"; 26755714Skris$crypto.=" crypto/tmdiff.h"; 26855714Skris 26968651Skrismy $symhacks="crypto/symhacks.h"; 27055714Skris 27168651Skrismy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 27268651Skrismy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 27355714Skris 27455714Skrisif ($do_update) { 27555714Skris 27655714Skrisif ($do_ssl == 1) { 27768651Skris 27868651Skris &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 27968651Skris if ($do_rewrite == 1) { 28068651Skris open(OUT, ">$ssl_num"); 28168651Skris &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 28268651Skris } else { 28368651Skris open(OUT, ">>$ssl_num"); 28468651Skris } 28568651Skris &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 28655714Skris close OUT; 28755714Skris} 28855714Skris 28955714Skrisif($do_crypto == 1) { 29068651Skris 29168651Skris &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 29268651Skris if ($do_rewrite == 1) { 29368651Skris open(OUT, ">$crypto_num"); 29468651Skris &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 29568651Skris } else { 29668651Skris open(OUT, ">>$crypto_num"); 29768651Skris } 29868651Skris &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 29955714Skris close OUT; 30059191Skris} 30155714Skris 302109998Smarkm} elsif ($do_checkexist) { 303109998Smarkm &check_existing(*ssl_list, @ssl_symbols) 304109998Smarkm if $do_ssl == 1; 305109998Smarkm &check_existing(*crypto_list, @crypto_symbols) 306109998Smarkm if $do_crypto == 1; 30768651Skris} elsif ($do_ctest || $do_ctestall) { 30859191Skris 30959191Skris print <<"EOF"; 31059191Skris 31159191Skris/* Test file to check all DEF file symbols are present by trying 31259191Skris * to link to all of them. This is *not* intended to be run! 31359191Skris */ 31459191Skris 31559191Skrisint main() 31659191Skris{ 31759191SkrisEOF 31868651Skris &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 31959191Skris if $do_ssl == 1; 32059191Skris 32168651Skris &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 32259191Skris if $do_crypto == 1; 32359191Skris 32459191Skris print "}\n"; 32559191Skris 32655714Skris} else { 32755714Skris 328109998Smarkm &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 32955714Skris if $do_ssl == 1; 33055714Skris 331109998Smarkm &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 33255714Skris if $do_crypto == 1; 33355714Skris 33455714Skris} 33555714Skris 33655714Skris 33755714Skrissub do_defs 33855714Skris{ 33968651Skris my($name,$files,$symhacksfile)=@_; 34059191Skris my $file; 34155714Skris my @ret; 34268651Skris my %syms; 34368651Skris my %platform; # For anything undefined, we assume "" 34468651Skris my %kind; # For anything undefined, we assume "FUNCTION" 34568651Skris my %algorithm; # For anything undefined, we assume "" 346109998Smarkm my %variant; 347109998Smarkm my %variant_cnt; # To be able to allocate "name{n}" if "name" 348109998Smarkm # is the same name as the original. 34959191Skris my $cpp; 350109998Smarkm my %unknown_algorithms = (); 35155714Skris 35268651Skris foreach $file (split(/\s+/,$symhacksfile." ".$files)) 35355714Skris { 354109998Smarkm print STDERR "DEBUG: starting on $file:\n" if $debug; 35555714Skris open(IN,"<$file") || die "unable to open $file:$!\n"; 35659191Skris my $line = "", my $def= ""; 35755714Skris my %tag = ( 35868651Skris (map { $_ => 0 } @known_platforms), 359109998Smarkm (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 360109998Smarkm (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 36155714Skris NOPROTO => 0, 36255714Skris PERL5 => 0, 36355714Skris _WINDLL => 0, 36455714Skris CONST_STRICT => 0, 36555714Skris TRUE => 1, 36655714Skris ); 36768651Skris my $symhacking = $file eq $symhacksfile; 368109998Smarkm my @current_platforms = (); 369109998Smarkm my @current_algorithms = (); 370109998Smarkm 371109998Smarkm # params: symbol, alias, platforms, kind 372109998Smarkm # The reason to put this subroutine in a variable is that 373109998Smarkm # it will otherwise create it's own, unshared, version of 374109998Smarkm # %tag and %variant... 375109998Smarkm my $make_variant = sub 376109998Smarkm { 377109998Smarkm my ($s, $a, $p, $k) = @_; 378109998Smarkm my ($a1, $a2); 379109998Smarkm 380109998Smarkm print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 381109998Smarkm if (defined($p)) 382109998Smarkm { 383109998Smarkm $a1 = join(",",$p, 384109998Smarkm grep(!/^$/, 385109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 386109998Smarkm @known_platforms)); 387109998Smarkm } 388109998Smarkm else 389109998Smarkm { 390109998Smarkm $a1 = join(",", 391109998Smarkm grep(!/^$/, 392109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 393109998Smarkm @known_platforms)); 394109998Smarkm } 395109998Smarkm $a2 = join(",", 396109998Smarkm grep(!/^$/, 397109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 398109998Smarkm @known_ossl_platforms)); 399109998Smarkm print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 400109998Smarkm if ($a1 eq "") { $a1 = $a2; } 401109998Smarkm elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 402109998Smarkm if ($a eq $s) 403109998Smarkm { 404109998Smarkm if (!defined($variant_cnt{$s})) 405109998Smarkm { 406109998Smarkm $variant_cnt{$s} = 0; 407109998Smarkm } 408109998Smarkm $variant_cnt{$s}++; 409109998Smarkm $a .= "{$variant_cnt{$s}}"; 410109998Smarkm } 411109998Smarkm my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 412109998Smarkm my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 413109998Smarkm if (!grep(/^$togrep$/, 414109998Smarkm split(/;/, defined($variant{$s})?$variant{$s}:""))) { 415109998Smarkm if (defined($variant{$s})) { $variant{$s} .= ";"; } 416109998Smarkm $variant{$s} .= $toadd; 417109998Smarkm } 418109998Smarkm print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 419109998Smarkm }; 420109998Smarkm 421109998Smarkm print STDERR "DEBUG: parsing ----------\n" if $debug; 42255714Skris while(<IN>) { 423109998Smarkm last if (/\/\* Error codes for the \w+ functions\. \*\//); 42455714Skris if ($line ne '') { 42555714Skris $_ = $line . $_; 42655714Skris $line = ''; 42755714Skris } 42855714Skris 42955714Skris if (/\\$/) { 430109998Smarkm chomp; # remove eol 431109998Smarkm chop; # remove ending backslash 43255714Skris $line = $_; 43355714Skris next; 43455714Skris } 43555714Skris 43668651Skris $cpp = 1 if /^\#.*ifdef.*cplusplus/; 43755714Skris if ($cpp) { 43868651Skris $cpp = 0 if /^\#.*endif/; 43955714Skris next; 44055714Skris } 44155714Skris 44255714Skris s/\/\*.*?\*\///gs; # ignore comments 44355714Skris s/{[^{}]*}//gs; # ignore {} blocks 444109998Smarkm print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 445109998Smarkm if (/^\#\s*ifndef\s+(.*)/) { 446109998Smarkm push(@tag,"-"); 44755714Skris push(@tag,$1); 44855714Skris $tag{$1}=-1; 449109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 450109998Smarkm } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 451109998Smarkm push(@tag,"-"); 452109998Smarkm if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 453109998Smarkm my $tmp_1 = $1; 454109998Smarkm my $tmp_; 455109998Smarkm foreach $tmp_ (split '\&\&',$tmp_1) { 456109998Smarkm $tmp_ =~ /!defined\(([^\)]+)\)/; 457109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 458109998Smarkm push(@tag,$1); 459109998Smarkm $tag{$1}=-1; 460109998Smarkm } 461109998Smarkm } else { 462109998Smarkm print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 463109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 464109998Smarkm push(@tag,$1); 465109998Smarkm $tag{$1}=-1; 466109998Smarkm } 467109998Smarkm } elsif (/^\#\s*ifdef\s+(.*)/) { 468109998Smarkm push(@tag,"-"); 46955714Skris push(@tag,$1); 47055714Skris $tag{$1}=1; 471109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 472109998Smarkm } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 473109998Smarkm push(@tag,"-"); 474109998Smarkm if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 475109998Smarkm my $tmp_1 = $1; 476109998Smarkm my $tmp_; 477109998Smarkm foreach $tmp_ (split '\|\|',$tmp_1) { 478109998Smarkm $tmp_ =~ /defined\(([^\)]+)\)/; 479109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 480109998Smarkm push(@tag,$1); 481109998Smarkm $tag{$1}=1; 482109998Smarkm } 483109998Smarkm } else { 484109998Smarkm print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 485109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 486109998Smarkm push(@tag,$1); 487109998Smarkm $tag{$1}=1; 488109998Smarkm } 48968651Skris } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 490109998Smarkm my $tag_i = $#tag; 491109998Smarkm while($tag[$tag_i] ne "-") { 492109998Smarkm if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 493109998Smarkm $tag{$tag[$tag_i]}=2; 494109998Smarkm print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 495109998Smarkm } 496109998Smarkm $tag_i--; 49768651Skris } 49855714Skris } elsif (/^\#\s*endif/) { 499109998Smarkm my $tag_i = $#tag; 500109998Smarkm while($tag[$tag_i] ne "-") { 501109998Smarkm my $t=$tag[$tag_i]; 502109998Smarkm print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 503109998Smarkm if ($tag{$t}==2) { 504109998Smarkm $tag{$t}=-1; 505109998Smarkm } else { 506109998Smarkm $tag{$t}=0; 507109998Smarkm } 508109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 509109998Smarkm pop(@tag); 510109998Smarkm if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 511109998Smarkm $t=$1; 512109998Smarkm } else { 513109998Smarkm $t=""; 514109998Smarkm } 515109998Smarkm if ($t ne "" 516109998Smarkm && !grep(/^$t$/, @known_algorithms)) { 517109998Smarkm $unknown_algorithms{$t} = 1; 518109998Smarkm #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 519109998Smarkm } 520109998Smarkm $tag_i--; 52168651Skris } 52255714Skris pop(@tag); 52355714Skris } elsif (/^\#\s*else/) { 524109998Smarkm my $tag_i = $#tag; 525109998Smarkm while($tag[$tag_i] ne "-") { 526109998Smarkm my $t=$tag[$tag_i]; 527109998Smarkm $tag{$t}= -$tag{$t}; 528109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 529109998Smarkm $tag_i--; 530109998Smarkm } 53155714Skris } elsif (/^\#\s*if\s+1/) { 532109998Smarkm push(@tag,"-"); 53355714Skris # Dummy tag 53455714Skris push(@tag,"TRUE"); 53555714Skris $tag{"TRUE"}=1; 536109998Smarkm print STDERR "DEBUG: $file: found 1\n" if $debug; 53759191Skris } elsif (/^\#\s*if\s+0/) { 538109998Smarkm push(@tag,"-"); 53959191Skris # Dummy tag 54059191Skris push(@tag,"TRUE"); 54159191Skris $tag{"TRUE"}=-1; 542109998Smarkm print STDERR "DEBUG: $file: found 0\n" if $debug; 54368651Skris } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 544109998Smarkm && $symhacking && $tag{'TRUE'} != -1) { 545109998Smarkm # This is for aliasing. When we find an alias, 546109998Smarkm # we have to invert 547109998Smarkm &$make_variant($1,$2); 548109998Smarkm print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 54968651Skris } 55068651Skris if (/^\#/) { 551109998Smarkm @current_platforms = 552109998Smarkm grep(!/^$/, 553109998Smarkm map { $tag{$_} == 1 ? $_ : 554109998Smarkm $tag{$_} == -1 ? "!".$_ : "" } 555109998Smarkm @known_platforms); 556109998Smarkm push @current_platforms 557109998Smarkm , grep(!/^$/, 558109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 559109998Smarkm $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 560109998Smarkm @known_ossl_platforms); 561109998Smarkm @current_algorithms = 562109998Smarkm grep(!/^$/, 563109998Smarkm map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 564109998Smarkm @known_algorithms); 565109998Smarkm $def .= 566109998Smarkm "#INFO:" 567109998Smarkm .join(',',@current_platforms).":" 568109998Smarkm .join(',',@current_algorithms).";"; 56959191Skris next; 57068651Skris } 571109998Smarkm if ($tag{'TRUE'} != -1) { 572109998Smarkm if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 573109998Smarkm next; 574109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 575109998Smarkm $def .= "int d2i_$3(void);"; 576109998Smarkm $def .= "int i2d_$3(void);"; 577109998Smarkm # Variant for platforms that do not 578109998Smarkm # have to access globale variables 579109998Smarkm # in shared libraries through functions 580109998Smarkm $def .= 581109998Smarkm "#INFO:" 582109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 583109998Smarkm .join(',',@current_algorithms).";"; 584109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 585109998Smarkm $def .= 586109998Smarkm "#INFO:" 587109998Smarkm .join(',',@current_platforms).":" 588109998Smarkm .join(',',@current_algorithms).";"; 589109998Smarkm # Variant for platforms that have to 590109998Smarkm # access globale variables in shared 591109998Smarkm # libraries through functions 592109998Smarkm &$make_variant("$2_it","$2_it", 593109998Smarkm "EXPORT_VAR_AS_FUNCTION", 594109998Smarkm "FUNCTION"); 595109998Smarkm next; 596109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 597109998Smarkm $def .= "int d2i_$3(void);"; 598109998Smarkm $def .= "int i2d_$3(void);"; 599109998Smarkm $def .= "int $3_free(void);"; 600109998Smarkm $def .= "int $3_new(void);"; 601109998Smarkm # Variant for platforms that do not 602109998Smarkm # have to access globale variables 603109998Smarkm # in shared libraries through functions 604109998Smarkm $def .= 605109998Smarkm "#INFO:" 606109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 607109998Smarkm .join(',',@current_algorithms).";"; 608109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 609109998Smarkm $def .= 610109998Smarkm "#INFO:" 611109998Smarkm .join(',',@current_platforms).":" 612109998Smarkm .join(',',@current_algorithms).";"; 613109998Smarkm # Variant for platforms that have to 614109998Smarkm # access globale variables in shared 615109998Smarkm # libraries through functions 616109998Smarkm &$make_variant("$2_it","$2_it", 617109998Smarkm "EXPORT_VAR_AS_FUNCTION", 618109998Smarkm "FUNCTION"); 619109998Smarkm next; 620109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 621109998Smarkm /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 622109998Smarkm $def .= "int d2i_$1(void);"; 623109998Smarkm $def .= "int i2d_$1(void);"; 624109998Smarkm $def .= "int $1_free(void);"; 625109998Smarkm $def .= "int $1_new(void);"; 626109998Smarkm # Variant for platforms that do not 627109998Smarkm # have to access globale variables 628109998Smarkm # in shared libraries through functions 629109998Smarkm $def .= 630109998Smarkm "#INFO:" 631109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 632109998Smarkm .join(',',@current_algorithms).";"; 633109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 634109998Smarkm $def .= 635109998Smarkm "#INFO:" 636109998Smarkm .join(',',@current_platforms).":" 637109998Smarkm .join(',',@current_algorithms).";"; 638109998Smarkm # Variant for platforms that have to 639109998Smarkm # access globale variables in shared 640109998Smarkm # libraries through functions 641109998Smarkm &$make_variant("$1_it","$1_it", 642109998Smarkm "EXPORT_VAR_AS_FUNCTION", 643109998Smarkm "FUNCTION"); 644109998Smarkm next; 645109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 646109998Smarkm $def .= "int d2i_$2(void);"; 647109998Smarkm $def .= "int i2d_$2(void);"; 648109998Smarkm # Variant for platforms that do not 649109998Smarkm # have to access globale variables 650109998Smarkm # in shared libraries through functions 651109998Smarkm $def .= 652109998Smarkm "#INFO:" 653109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 654109998Smarkm .join(',',@current_algorithms).";"; 655109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 656109998Smarkm $def .= 657109998Smarkm "#INFO:" 658109998Smarkm .join(',',@current_platforms).":" 659109998Smarkm .join(',',@current_algorithms).";"; 660109998Smarkm # Variant for platforms that have to 661109998Smarkm # access globale variables in shared 662109998Smarkm # libraries through functions 663109998Smarkm &$make_variant("$2_it","$2_it", 664109998Smarkm "EXPORT_VAR_AS_FUNCTION", 665109998Smarkm "FUNCTION"); 666109998Smarkm next; 667109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 668109998Smarkm $def .= "int d2i_$2(void);"; 669109998Smarkm $def .= "int i2d_$2(void);"; 670109998Smarkm $def .= "int $2_free(void);"; 671109998Smarkm $def .= "int $2_new(void);"; 672109998Smarkm # Variant for platforms that do not 673109998Smarkm # have to access globale variables 674109998Smarkm # in shared libraries through functions 675109998Smarkm $def .= 676109998Smarkm "#INFO:" 677109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 678109998Smarkm .join(',',@current_algorithms).";"; 679109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 680109998Smarkm $def .= 681109998Smarkm "#INFO:" 682109998Smarkm .join(',',@current_platforms).":" 683109998Smarkm .join(',',@current_algorithms).";"; 684109998Smarkm # Variant for platforms that have to 685109998Smarkm # access globale variables in shared 686109998Smarkm # libraries through functions 687109998Smarkm &$make_variant("$2_it","$2_it", 688109998Smarkm "EXPORT_VAR_AS_FUNCTION", 689109998Smarkm "FUNCTION"); 690109998Smarkm next; 691109998Smarkm } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 692109998Smarkm # Variant for platforms that do not 693109998Smarkm # have to access globale variables 694109998Smarkm # in shared libraries through functions 695109998Smarkm $def .= 696109998Smarkm "#INFO:" 697109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 698109998Smarkm .join(',',@current_algorithms).";"; 699109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 700109998Smarkm $def .= 701109998Smarkm "#INFO:" 702109998Smarkm .join(',',@current_platforms).":" 703109998Smarkm .join(',',@current_algorithms).";"; 704109998Smarkm # Variant for platforms that have to 705109998Smarkm # access globale variables in shared 706109998Smarkm # libraries through functions 707109998Smarkm &$make_variant("$1_it","$1_it", 708109998Smarkm "EXPORT_VAR_AS_FUNCTION", 709109998Smarkm "FUNCTION"); 710109998Smarkm next; 711109998Smarkm } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 712109998Smarkm next; 713109998Smarkm } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 714109998Smarkm next; 715109998Smarkm } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 716109998Smarkm /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) { 717109998Smarkm # Things not in Win16 718109998Smarkm $def .= 719109998Smarkm "#INFO:" 720109998Smarkm .join(',',"!WIN16",@current_platforms).":" 721109998Smarkm .join(',',@current_algorithms).";"; 722109998Smarkm $def .= "int PEM_read_$1(void);"; 723109998Smarkm $def .= "int PEM_write_$1(void);"; 724109998Smarkm $def .= 725109998Smarkm "#INFO:" 726109998Smarkm .join(',',@current_platforms).":" 727109998Smarkm .join(',',@current_algorithms).";"; 728109998Smarkm # Things that are everywhere 729109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 730109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 731109998Smarkm next; 732109998Smarkm } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 733109998Smarkm /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 734109998Smarkm # Things not in Win16 735109998Smarkm $def .= 736109998Smarkm "#INFO:" 737109998Smarkm .join(',',"!WIN16",@current_platforms).":" 738109998Smarkm .join(',',@current_algorithms).";"; 739109998Smarkm $def .= "int PEM_write_$1(void);"; 740109998Smarkm $def .= 741109998Smarkm "#INFO:" 742109998Smarkm .join(',',@current_platforms).":" 743109998Smarkm .join(',',@current_algorithms).";"; 744109998Smarkm # Things that are everywhere 745109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 746109998Smarkm next; 747109998Smarkm } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 748109998Smarkm /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 749109998Smarkm # Things not in Win16 750109998Smarkm $def .= 751109998Smarkm "#INFO:" 752109998Smarkm .join(',',"!WIN16",@current_platforms).":" 753109998Smarkm .join(',',@current_algorithms).";"; 754109998Smarkm $def .= "int PEM_read_$1(void);"; 755109998Smarkm $def .= 756109998Smarkm "#INFO:" 757109998Smarkm .join(',',@current_platforms).":" 758109998Smarkm .join(',',@current_algorithms).";"; 759109998Smarkm # Things that are everywhere 760109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 761109998Smarkm next; 762109998Smarkm } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 763109998Smarkm # Variant for platforms that do not 764109998Smarkm # have to access globale variables 765109998Smarkm # in shared libraries through functions 766109998Smarkm $def .= 767109998Smarkm "#INFO:" 768109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 769109998Smarkm .join(',',@current_algorithms).";"; 770109998Smarkm $def .= "OPENSSL_EXTERN int _shadow_$2;"; 771109998Smarkm $def .= 772109998Smarkm "#INFO:" 773109998Smarkm .join(',',@current_platforms).":" 774109998Smarkm .join(',',@current_algorithms).";"; 775109998Smarkm # Variant for platforms that have to 776109998Smarkm # access globale variables in shared 777109998Smarkm # libraries through functions 778109998Smarkm &$make_variant("_shadow_$2","_shadow_$2", 779109998Smarkm "EXPORT_VAR_AS_FUNCTION", 780109998Smarkm "FUNCTION"); 781109998Smarkm } elsif ($tag{'CONST_STRICT'} != 1) { 78268651Skris if (/\{|\/\*|\([^\)]*$/) { 78355714Skris $line = $_; 78455714Skris } else { 78555714Skris $def .= $_; 78655714Skris } 78755714Skris } 78855714Skris } 789109998Smarkm } 79055714Skris close(IN); 79155714Skris 79268651Skris my $algs; 79368651Skris my $plays; 79468651Skris 795109998Smarkm print STDERR "DEBUG: postprocessing ----------\n" if $debug; 79655714Skris foreach (split /;/, $def) { 79768651Skris my $s; my $k = "FUNCTION"; my $p; my $a; 79855714Skris s/^[\n\s]*//g; 79955714Skris s/[\n\s]*$//g; 80068651Skris next if(/\#undef/); 80155714Skris next if(/typedef\W/); 80268651Skris next if(/\#define/); 80368651Skris 804109998Smarkm print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 80568651Skris if (/^\#INFO:([^:]*):(.*)$/) { 80668651Skris $plats = $1; 80768651Skris $algs = $2; 808109998Smarkm print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 80968651Skris next; 810109998Smarkm } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 81168651Skris $s = $1; 81268651Skris $k = "VARIABLE"; 813109998Smarkm print STDERR "DEBUG: found external variable $s\n" if $debug; 814109998Smarkm } elsif (/\(\*(\w*(\{[0-9]+\})?)\([^\)]+/) { 81568651Skris $s = $1; 816109998Smarkm print STDERR "DEBUG: found ANSI C function $s\n" if $debug; 81755714Skris } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) { 81855714Skris # K&R C 819109998Smarkm print STDERR "DEBUG: found K&R C function $s\n" if $debug; 82055714Skris next; 821109998Smarkm } elsif (/\w+\W+\w+(\{[0-9]+\})?\W*\(.*\)$/s) { 82255714Skris while (not /\(\)$/s) { 82355714Skris s/[^\(\)]*\)$/\)/s; 82455714Skris s/\([^\(\)]*\)\)$/\)/s; 82555714Skris } 82655714Skris s/\(void\)//; 827109998Smarkm /(\w+(\{[0-9]+\})?)\W*\(\)/s; 82868651Skris $s = $1; 829109998Smarkm print STDERR "DEBUG: found function $s\n" if $debug; 83055714Skris } elsif (/\(/ and not (/=/)) { 83155714Skris print STDERR "File $file: cannot parse: $_;\n"; 83268651Skris next; 83368651Skris } else { 83468651Skris next; 83555714Skris } 83668651Skris 83768651Skris $syms{$s} = 1; 83868651Skris $kind{$s} = $k; 83968651Skris 84068651Skris $p = $plats; 84168651Skris $a = $algs; 84268651Skris $a .= ",BF" if($s =~ /EVP_bf/); 84368651Skris $a .= ",CAST" if($s =~ /EVP_cast/); 84468651Skris $a .= ",DES" if($s =~ /EVP_des/); 84568651Skris $a .= ",DSA" if($s =~ /EVP_dss/); 84668651Skris $a .= ",IDEA" if($s =~ /EVP_idea/); 84768651Skris $a .= ",MD2" if($s =~ /EVP_md2/); 84868651Skris $a .= ",MD4" if($s =~ /EVP_md4/); 84968651Skris $a .= ",MD5" if($s =~ /EVP_md5/); 85068651Skris $a .= ",RC2" if($s =~ /EVP_rc2/); 85168651Skris $a .= ",RC4" if($s =~ /EVP_rc4/); 85268651Skris $a .= ",RC5" if($s =~ /EVP_rc5/); 85368651Skris $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 85468651Skris $a .= ",SHA" if($s =~ /EVP_sha/); 85568651Skris $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 85668651Skris $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 85768651Skris $a .= ",RSA" if($s =~ /RSAPrivateKey/); 85868651Skris $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 85968651Skris 860109998Smarkm $platform{$s} = 861109998Smarkm &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 86268651Skris $algorithm{$s} .= ','.$a; 86368651Skris 864109998Smarkm if (defined($variant{$s})) { 865109998Smarkm foreach $v (split /;/,$variant{$s}) { 866109998Smarkm (my $r, my $p, my $k) = split(/:/,$v); 867109998Smarkm my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 868109998Smarkm $syms{$r} = 1; 869109998Smarkm if (!defined($k)) { $k = $kind{$s}; } 870109998Smarkm $kind{$r} = $k."(".$s.")"; 871109998Smarkm $algorithm{$r} = $algorithm{$s}; 872109998Smarkm $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 873109998Smarkm $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 874109998Smarkm print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 875109998Smarkm } 87668651Skris } 877109998Smarkm print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 87855714Skris } 87955714Skris } 88055714Skris 88168651Skris # Prune the returned symbols 88255714Skris 88368651Skris delete $syms{"bn_dump1"}; 88468651Skris $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 88568651Skris 886109998Smarkm $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 887109998Smarkm $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 888109998Smarkm $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 889109998Smarkm $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 89068651Skris 89168651Skris # Info we know about 89268651Skris 89368651Skris push @ret, map { $_."\\".&info_string($_,"EXIST", 89468651Skris $platform{$_}, 89568651Skris $kind{$_}, 89668651Skris $algorithm{$_}) } keys %syms; 89768651Skris 898109998Smarkm if (keys %unknown_algorithms) { 899109998Smarkm print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 900109998Smarkm print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 901109998Smarkm } 90268651Skris return(@ret); 90368651Skris} 90468651Skris 905109998Smarkm# Param: string of comma-separated platform-specs. 906109998Smarkmsub reduce_platforms 907109998Smarkm{ 908109998Smarkm my ($platforms) = @_; 90968651Skris my $pl = defined($platforms) ? $platforms : ""; 91068651Skris my %p = map { $_ => 0 } split /,/, $pl; 91168651Skris my $ret; 91268651Skris 913109998Smarkm print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 914109998Smarkm if $debug; 91568651Skris # We do this, because if there's code like the following, it really 91668651Skris # means the function exists in all cases and should therefore be 91768651Skris # everywhere. By increasing and decreasing, we may attain 0: 91868651Skris # 91968651Skris # ifndef WIN16 92068651Skris # int foo(); 92168651Skris # else 92268651Skris # int _fat foo(); 92368651Skris # endif 92468651Skris foreach $platform (split /,/, $pl) { 92568651Skris if ($platform =~ /^!(.*)$/) { 92668651Skris $p{$1}--; 92768651Skris } else { 92868651Skris $p{$platform}++; 92955714Skris } 93055714Skris } 93168651Skris foreach $platform (keys %p) { 93268651Skris if ($p{$platform} == 0) { delete $p{$platform}; } 93355714Skris } 93455714Skris 93568651Skris delete $p{""}; 936109998Smarkm 937109998Smarkm $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 938109998Smarkm print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 939109998Smarkm if $debug; 940109998Smarkm return $ret; 941109998Smarkm} 942109998Smarkm 943109998Smarkmsub info_string { 944109998Smarkm (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 945109998Smarkm 946109998Smarkm my %a = defined($algorithms) ? 947109998Smarkm map { $_ => 1 } split /,/, $algorithms : (); 948109998Smarkm my $k = defined($kind) ? $kind : "FUNCTION"; 949109998Smarkm my $ret; 950109998Smarkm my $p = &reduce_platforms($platforms); 951109998Smarkm 95268651Skris delete $a{""}; 95355714Skris 95468651Skris $ret = $exist; 955109998Smarkm $ret .= ":".$p; 95668651Skris $ret .= ":".$k; 957109998Smarkm $ret .= ":".join(',',sort keys %a); 95868651Skris return $ret; 95955714Skris} 96055714Skris 96168651Skrissub maybe_add_info { 96268651Skris (my $name, *nums, my @symbols) = @_; 96368651Skris my $sym; 96468651Skris my $new_info = 0; 965109998Smarkm my %syms=(); 96668651Skris 96768651Skris print STDERR "Updating $name info\n"; 96868651Skris foreach $sym (@symbols) { 96968651Skris (my $s, my $i) = split /\\/, $sym; 97068651Skris if (defined($nums{$s})) { 971109998Smarkm $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 97268651Skris (my $n, my $dummy) = split /\\/, $nums{$s}; 97368651Skris if (!defined($dummy) || $i ne $dummy) { 97468651Skris $nums{$s} = $n."\\".$i; 97568651Skris $new_info++; 976109998Smarkm print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 97768651Skris } 97868651Skris } 979109998Smarkm $syms{$s} = 1; 98068651Skris } 981109998Smarkm 982109998Smarkm my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 983109998Smarkm foreach $sym (@s) { 984109998Smarkm (my $n, my $i) = split /\\/, $nums{$sym}; 985109998Smarkm if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 986109998Smarkm $new_info++; 987109998Smarkm print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 988109998Smarkm } 989109998Smarkm } 99068651Skris if ($new_info) { 99168651Skris print STDERR "$new_info old symbols got an info update\n"; 99268651Skris if (!$do_rewrite) { 99368651Skris print STDERR "You should do a rewrite to fix this.\n"; 99468651Skris } 99568651Skris } else { 99668651Skris print STDERR "No old symbols needed info update\n"; 99768651Skris } 99868651Skris} 99968651Skris 1000109998Smarkm# Param: string of comma-separated keywords, each possibly prefixed with a "!" 1001109998Smarkmsub is_valid 1002109998Smarkm{ 1003109998Smarkm my ($keywords_txt,$platforms) = @_; 1004109998Smarkm my (@keywords) = split /,/,$keywords_txt; 1005109998Smarkm my ($falsesum, $truesum) = (0, !grep(/^[^!]/,@keywords)); 1006109998Smarkm 1007109998Smarkm # Param: one keyword 1008109998Smarkm sub recognise 1009109998Smarkm { 1010109998Smarkm my ($keyword,$platforms) = @_; 1011109998Smarkm 1012109998Smarkm if ($platforms) { 1013109998Smarkm # platforms 1014109998Smarkm if ($keyword eq "VMS" && $VMS) { return 1; } 1015109998Smarkm if ($keyword eq "WIN32" && $W32) { return 1; } 1016109998Smarkm if ($keyword eq "WIN16" && $W16) { return 1; } 1017109998Smarkm if ($keyword eq "WINNT" && $NT) { return 1; } 1018109998Smarkm if ($keyword eq "OS2" && $OS2) { return 1; } 1019109998Smarkm # Special platforms: 1020109998Smarkm # EXPORT_VAR_AS_FUNCTION means that global variables 1021109998Smarkm # will be represented as functions. This currently 1022109998Smarkm # only happens on VMS-VAX. 1023109998Smarkm if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1024109998Smarkm return 1; 1025109998Smarkm } 1026109998Smarkm return 0; 1027109998Smarkm } else { 1028109998Smarkm # algorithms 1029109998Smarkm if ($keyword eq "RC2" && $no_rc2) { return 0; } 1030109998Smarkm if ($keyword eq "RC4" && $no_rc4) { return 0; } 1031109998Smarkm if ($keyword eq "RC5" && $no_rc5) { return 0; } 1032109998Smarkm if ($keyword eq "IDEA" && $no_idea) { return 0; } 1033109998Smarkm if ($keyword eq "DES" && $no_des) { return 0; } 1034109998Smarkm if ($keyword eq "BF" && $no_bf) { return 0; } 1035109998Smarkm if ($keyword eq "CAST" && $no_cast) { return 0; } 1036109998Smarkm if ($keyword eq "MD2" && $no_md2) { return 0; } 1037109998Smarkm if ($keyword eq "MD4" && $no_md4) { return 0; } 1038109998Smarkm if ($keyword eq "MD5" && $no_md5) { return 0; } 1039109998Smarkm if ($keyword eq "SHA" && $no_sha) { return 0; } 1040109998Smarkm if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1041109998Smarkm if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1042109998Smarkm if ($keyword eq "RSA" && $no_rsa) { return 0; } 1043109998Smarkm if ($keyword eq "DSA" && $no_dsa) { return 0; } 1044109998Smarkm if ($keyword eq "DH" && $no_dh) { return 0; } 1045109998Smarkm if ($keyword eq "EC" && $no_ec) { return 0; } 1046109998Smarkm if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1047109998Smarkm if ($keyword eq "AES" && $no_aes) { return 0; } 1048109998Smarkm if ($keyword eq "EVP" && $no_evp) { return 0; } 1049109998Smarkm if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1050109998Smarkm if ($keyword eq "STACK" && $no_stack) { return 0; } 1051109998Smarkm if ($keyword eq "ERR" && $no_err) { return 0; } 1052109998Smarkm if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1053109998Smarkm if ($keyword eq "BIO" && $no_bio) { return 0; } 1054109998Smarkm if ($keyword eq "COMP" && $no_comp) { return 0; } 1055109998Smarkm if ($keyword eq "DSO" && $no_dso) { return 0; } 1056109998Smarkm if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1057111147Snectar if ($keyword eq "ENGINE" && $no_engine) { return 0; } 1058111147Snectar if ($keyword eq "HW" && $no_hw) { return 0; } 1059109998Smarkm if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1060109998Smarkm 1061109998Smarkm # Nothing recognise as true 1062109998Smarkm return 1; 1063109998Smarkm } 1064109998Smarkm } 1065109998Smarkm 1066109998Smarkm foreach $k (@keywords) { 1067109998Smarkm if ($k =~ /^!(.*)$/) { 1068109998Smarkm $falsesum += &recognise($1,$platforms); 1069109998Smarkm } else { 1070109998Smarkm $truesum += &recognise($k,$platforms); 1071109998Smarkm } 1072109998Smarkm } 1073109998Smarkm print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1074109998Smarkm return (!$falsesum) && $truesum; 1075109998Smarkm} 1076109998Smarkm 107759191Skrissub print_test_file 107859191Skris{ 1079109998Smarkm (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 108059191Skris my $n = 1; my @e; my @r; 108168651Skris my $sym; my $prev = ""; my $prefSSLeay; 108259191Skris 1083109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1084109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 108568651Skris @symbols=((sort @e),(sort @r)); 108659191Skris 108768651Skris foreach $sym (@symbols) { 108868651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1089109998Smarkm my $v = 0; 1090109998Smarkm $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1091109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1092109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1093109998Smarkm if (!defined($nums{$s})) { 1094109998Smarkm print STDERR "Warning: $s does not have a number assigned\n" 1095109998Smarkm if(!$do_update); 1096109998Smarkm } elsif (is_valid($p,1) && is_valid($a,0)) { 1097109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1098109998Smarkm if ($prev eq $s2) { 1099109998Smarkm print OUT "\t/* The following has already appeared previously */\n"; 1100109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1101109998Smarkm } 1102109998Smarkm $prev = $s2; # To warn about duplicates... 1103109998Smarkm 1104109998Smarkm ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1105109998Smarkm if ($v) { 1106109998Smarkm print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 110768651Skris } else { 1108109998Smarkm print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 110968651Skris } 111059191Skris } 111159191Skris } 111259191Skris} 111359191Skris 111455714Skrissub print_def_file 111555714Skris{ 111668651Skris (*OUT,my $name,*nums,my @symbols)=@_; 1117109998Smarkm my $n = 1; my @e; my @r; my @v; my $prev=""; 1118109998Smarkm my $liboptions=""; 111955714Skris 112055714Skris if ($W32) 112155714Skris { $name.="32"; } 1122109998Smarkm elsif ($W16) 112355714Skris { $name.="16"; } 1124109998Smarkm elsif ($OS2) 1125109998Smarkm { $liboptions = "INITINSTANCE\nDATA NONSHARED"; } 112655714Skris 112755714Skris print OUT <<"EOF"; 112855714Skris; 112955714Skris; Definition file for the DLL version of the $name library from OpenSSL 113055714Skris; 113155714Skris 1132109998SmarkmLIBRARY $name $liboptions 113355714Skris 113455714SkrisDESCRIPTION 'OpenSSL $name - http://www.openssl.org/' 113555714Skris 113655714SkrisEOF 113755714Skris 1138109998Smarkm if ($W16) { 113955714Skris print <<"EOF"; 114055714SkrisCODE PRELOAD MOVEABLE 114155714SkrisDATA PRELOAD MOVEABLE SINGLE 114255714Skris 114355714SkrisEXETYPE WINDOWS 114455714Skris 114555714SkrisHEAPSIZE 4096 114655714SkrisSTACKSIZE 8192 114755714Skris 114855714SkrisEOF 114955714Skris } 115055714Skris 115155714Skris print "EXPORTS\n"; 115255714Skris 1153109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1154109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1155109998Smarkm (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1156109998Smarkm @symbols=((sort @e),(sort @r), (sort @v)); 115755714Skris 115855714Skris 115968651Skris foreach $sym (@symbols) { 116068651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1161109998Smarkm my $v = 0; 1162109998Smarkm $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 116368651Skris if (!defined($nums{$s})) { 116468651Skris printf STDERR "Warning: $s does not have a number assigned\n" 1165109998Smarkm if(!$do_update); 116655714Skris } else { 1167109998Smarkm (my $n, my $dummy) = split /\\/, $nums{$s}; 116868651Skris my %pf = (); 1169109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1170109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1171109998Smarkm if (is_valid($p,1) && is_valid($a,0)) { 1172109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1173109998Smarkm if ($prev eq $s2) { 1174109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1175109998Smarkm } 1176109998Smarkm $prev = $s2; # To warn about duplicates... 1177109998Smarkm if($v && !$OS2) { 1178109998Smarkm printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1179109998Smarkm } else { 1180109998Smarkm printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1181109998Smarkm } 118268651Skris } 118355714Skris } 118455714Skris } 118555714Skris printf OUT "\n"; 118655714Skris} 118755714Skris 118855714Skrissub load_numbers 118955714Skris{ 119055714Skris my($name)=@_; 119155714Skris my(@a,%ret); 119255714Skris 119355714Skris $max_num = 0; 119468651Skris $num_noinfo = 0; 119568651Skris $prev = ""; 1196109998Smarkm $prev_cnt = 0; 119755714Skris 119855714Skris open(IN,"<$name") || die "unable to open $name:$!\n"; 119955714Skris while (<IN>) { 120055714Skris chop; 120155714Skris s/#.*$//; 120255714Skris next if /^\s*$/; 120355714Skris @a=split; 120468651Skris if (defined $ret{$a[0]}) { 1205109998Smarkm # This is actually perfectly OK 1206109998Smarkm #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 120768651Skris } 120868651Skris if ($max_num > $a[1]) { 120968651Skris print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 121068651Skris } 1211109998Smarkm elsif ($max_num == $a[1]) { 121268651Skris # This is actually perfectly OK 121368651Skris #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1214109998Smarkm if ($a[0] eq $prev) { 1215109998Smarkm $prev_cnt++; 1216109998Smarkm $a[0] .= "{$prev_cnt}"; 1217109998Smarkm } 121868651Skris } 1219109998Smarkm else { 1220109998Smarkm $prev_cnt = 0; 1221109998Smarkm } 122268651Skris if ($#a < 2) { 122368651Skris # Existence will be proven later, in do_defs 122468651Skris $ret{$a[0]}=$a[1]; 122568651Skris $num_noinfo++; 122668651Skris } else { 122768651Skris $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 122868651Skris } 122955714Skris $max_num = $a[1] if $a[1] > $max_num; 123068651Skris $prev=$a[0]; 123155714Skris } 123268651Skris if ($num_noinfo) { 123368651Skris print STDERR "Warning: $num_noinfo symbols were without info."; 123468651Skris if ($do_rewrite) { 123568651Skris printf STDERR " The rewrite will fix this.\n"; 123668651Skris } else { 123768651Skris printf STDERR " You should do a rewrite to fix this.\n"; 123868651Skris } 123968651Skris } 124055714Skris close(IN); 124155714Skris return(%ret); 124255714Skris} 124355714Skris 124468651Skrissub parse_number 124568651Skris{ 124668651Skris (my $str, my $what) = @_; 124768651Skris (my $n, my $i) = split(/\\/,$str); 124868651Skris if ($what eq "n") { 124968651Skris return $n; 125068651Skris } else { 125168651Skris return $i; 125268651Skris } 125368651Skris} 125468651Skris 125568651Skrissub rewrite_numbers 125668651Skris{ 125768651Skris (*OUT,$name,*nums,@symbols)=@_; 125868651Skris my $thing; 125968651Skris 126068651Skris print STDERR "Rewriting $name\n"; 126168651Skris 1262109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 126368651Skris my $r; my %r; my %rsyms; 126468651Skris foreach $r (@r) { 126568651Skris (my $s, my $i) = split /\\/, $r; 126668651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 126768651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 126868651Skris $r{$a} = $s."\\".$i; 126968651Skris $rsyms{$s} = 1; 127068651Skris } 127168651Skris 1272109998Smarkm my %syms = (); 1273109998Smarkm foreach $_ (@symbols) { 1274109998Smarkm (my $n, my $i) = split /\\/; 1275109998Smarkm $syms{$n} = 1; 1276109998Smarkm } 1277109998Smarkm 1278109998Smarkm my @s=sort { 1279109998Smarkm &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1280109998Smarkm || $a cmp $b 1281109998Smarkm } keys %nums; 128268651Skris foreach $sym (@s) { 128368651Skris (my $n, my $i) = split /\\/, $nums{$sym}; 128468651Skris next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 128568651Skris next if defined($rsyms{$sym}); 1286109998Smarkm print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1287109998Smarkm $i="NOEXIST::FUNCTION:" 1288109998Smarkm if !defined($i) || $i eq "" || !defined($syms{$sym}); 1289109998Smarkm my $s2 = $sym; 1290109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1291109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 129268651Skris if (exists $r{$sym}) { 129368651Skris (my $s, $i) = split /\\/,$r{$sym}; 1294109998Smarkm my $s2 = $s; 1295109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1296109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 129768651Skris } 129868651Skris } 129968651Skris} 130068651Skris 130155714Skrissub update_numbers 130255714Skris{ 130368651Skris (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 130468651Skris my $new_syms = 0; 130568651Skris 130668651Skris print STDERR "Updating $name numbers\n"; 130768651Skris 1308109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 130968651Skris my $r; my %r; my %rsyms; 131068651Skris foreach $r (@r) { 131168651Skris (my $s, my $i) = split /\\/, $r; 131268651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 131368651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 131468651Skris $r{$a} = $s."\\".$i; 131568651Skris $rsyms{$s} = 1; 131668651Skris } 131768651Skris 131868651Skris foreach $sym (@symbols) { 131968651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 132068651Skris next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 132168651Skris next if defined($rsyms{$sym}); 132268651Skris die "ERROR: Symbol $sym had no info attached to it." 132368651Skris if $i eq ""; 132468651Skris if (!exists $nums{$s}) { 132568651Skris $new_syms++; 1326109998Smarkm my $s2 = $s; 1327109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1328109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 132968651Skris if (exists $r{$s}) { 133068651Skris ($s, $i) = split /\\/,$r{$s}; 1331109998Smarkm $s =~ s/\{[0-9]+\}$//; 1332109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 133368651Skris } 133455714Skris } 133555714Skris } 133668651Skris if($new_syms) { 133768651Skris print STDERR "$new_syms New symbols added\n"; 133855714Skris } else { 133968651Skris print STDERR "No New symbols Added\n"; 134055714Skris } 134155714Skris} 134268651Skris 134368651Skrissub check_existing 134468651Skris{ 134568651Skris (*nums, my @symbols)=@_; 134668651Skris my %existing; my @remaining; 134768651Skris @remaining=(); 134868651Skris foreach $sym (@symbols) { 134968651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 135068651Skris $existing{$s}=1; 135168651Skris } 135268651Skris foreach $sym (keys %nums) { 135368651Skris if (!exists $existing{$sym}) { 135468651Skris push @remaining, $sym; 135568651Skris } 135668651Skris } 135768651Skris if(@remaining) { 135868651Skris print STDERR "The following symbols do not seem to exist:\n"; 135968651Skris foreach $sym (@remaining) { 136068651Skris print STDERR "\t",$sym,"\n"; 136168651Skris } 136268651Skris } 136368651Skris} 136468651Skris 1365