intl/icu/source/tools/genren/genren.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/genren/genren.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,263 @@
     1.4 +#!/usr/bin/perl 
     1.5 +#*
     1.6 +#*******************************************************************************
     1.7 +#*   Copyright (C) 2001-2012, International Business Machines
     1.8 +#*   Corporation and others.  All Rights Reserved.
     1.9 +#*******************************************************************************
    1.10 +#*
    1.11 +#*   file name:  genren.pl
    1.12 +#*   encoding:   US-ASCII
    1.13 +#*   tab size:   8 (not used)
    1.14 +#*   indentation:4
    1.15 +#*
    1.16 +#*   Created by: Vladimir Weinstein
    1.17 +#*   07/19/2001
    1.18 +#*
    1.19 +#*  Used to generate renaming headers.
    1.20 +#*  Run on UNIX platforms (linux) in order to catch all the exports
    1.21 +
    1.22 +use POSIX qw(strftime);
    1.23 +
    1.24 +$headername = 'urename.h';
    1.25 +
    1.26 +$path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h";
    1.27 +
    1.28 +$nmopts = '-Cg -f s';
    1.29 +$post = '';
    1.30 +
    1.31 +$mode = 'POSIX';
    1.32 +
    1.33 +(-e $path) || die "Cannot find uversion.h";
    1.34 +
    1.35 +open(UVERSION, $path);
    1.36 +
    1.37 +while(<UVERSION>) {
    1.38 +    if(/\#define U_ICU_VERSION_SUFFIX/) {
    1.39 +        chop;
    1.40 +        s/\#define U_ICU_VERSION_SUFFIX //;
    1.41 +        $U_ICU_VERSION_SUFFIX = "$_";
    1.42 +        last;
    1.43 +    }
    1.44 +}
    1.45 +
    1.46 +while($ARGV[0] =~ /^-/) { # detects whether there are any arguments
    1.47 +    $_ = shift @ARGV;      # extracts the argument for processing
    1.48 +    /^-v/ && ($VERBOSE++, next);                      # verbose
    1.49 +    /^-h/ && (&printHelpMsgAndExit, next);               # help
    1.50 +    /^-o/ && (($headername = shift (@ARGV)), next);   # output file
    1.51 +    /^-n/ && (($nmopts = shift (@ARGV)), next);   # nm opts
    1.52 +    /^-p/ && (($post = shift (@ARGV)), next);   # nm opts
    1.53 +    /^-x/ && (($mode = shift (@ARGV)), next);   # nm opts
    1.54 +    /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix
    1.55 +    warn("Invalid option $_\n");
    1.56 +    &printHelpMsgAndExit;
    1.57 +}
    1.58 +
    1.59 +unless(@ARGV > 0) {
    1.60 +    warn "No libraries, exiting...\n";
    1.61 +    &printHelpMsgAndExit;
    1.62 +}
    1.63 +
    1.64 +#$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h";
    1.65 +    
    1.66 +$HEADERDEF = uc($headername);  # this is building the constant for #define
    1.67 +$HEADERDEF =~ s/\./_/;
    1.68 +
    1.69 +    
    1.70 +    open HEADER, ">$headername"; # opening a header file
    1.71 +
    1.72 +#We will print our copyright here + warnings
    1.73 +
    1.74 +$YEAR = strftime "%Y",localtime;
    1.75 +
    1.76 +print HEADER <<"EndOfHeaderComment";
    1.77 +/*
    1.78 +*******************************************************************************
    1.79 +*   Copyright (C) 2002-$YEAR, International Business Machines
    1.80 +*   Corporation and others.  All Rights Reserved.
    1.81 +*******************************************************************************
    1.82 +*
    1.83 +*   file name:  $headername
    1.84 +*   encoding:   US-ASCII
    1.85 +*   tab size:   8 (not used)
    1.86 +*   indentation:4
    1.87 +*
    1.88 +*   Created by: Perl script tools/genren.pl written by Vladimir Weinstein
    1.89 +*
    1.90 +*  Contains data for renaming ICU exports.
    1.91 +*  Gets included by umachine.h
    1.92 +*
    1.93 +*  THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT
    1.94 +*  YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN!
    1.95 +*/
    1.96 +
    1.97 +#ifndef $HEADERDEF
    1.98 +#define $HEADERDEF
    1.99 +
   1.100 +/* U_DISABLE_RENAMING can be defined in the following ways:
   1.101 + *   - when running configure, e.g.
   1.102 + *        runConfigureICU Linux --disable-renaming
   1.103 + *   - by changing the default setting of U_DISABLE_RENAMING in uconfig.h
   1.104 + */
   1.105 +
   1.106 +#include "unicode/uconfig.h"
   1.107 +
   1.108 +#if !U_DISABLE_RENAMING
   1.109 +
   1.110 +/* We need the U_ICU_ENTRY_POINT_RENAME definition. There's a default one in unicode/uvernum.h we can use, but we will give
   1.111 +   the platform a chance to define it first.
   1.112 +   Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined.
   1.113 + */
   1.114 +
   1.115 +#ifndef U_ICU_ENTRY_POINT_RENAME
   1.116 +#include "unicode/umachine.h"
   1.117 +#endif
   1.118 +
   1.119 +/* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */
   1.120 +#ifndef U_ICU_ENTRY_POINT_RENAME
   1.121 +#include "unicode/uvernum.h"
   1.122 +#endif
   1.123 +
   1.124 +/* Error out before the following defines cause very strange and unexpected code breakage */
   1.125 +#ifndef U_ICU_ENTRY_POINT_RENAME
   1.126 +#error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used.
   1.127 +#endif
   1.128 +
   1.129 +EndOfHeaderComment
   1.130 +
   1.131 +$fileCount = 0;
   1.132 +$itemCount = 0;
   1.133 +$symbolCount = 0;
   1.134 +
   1.135 +for(;@ARGV; shift(@ARGV)) {
   1.136 +    $fileCount++;
   1.137 +    @NMRESULT = `nm $nmopts $ARGV[0] $post`;
   1.138 +    if($?) {
   1.139 +        warn "Couldn't do 'nm' for $ARGV[0], continuing...\n";
   1.140 +        next; # Couldn't do nm for the file
   1.141 +    }
   1.142 +    if($mode =~ /POSIX/) {
   1.143 +        splice @NMRESULT, 0, 6;
   1.144 +    } elsif ($mode =~ /Mach-O/) {
   1.145 +#        splice @NMRESULT, 0, 10;
   1.146 +    }
   1.147 +    foreach (@NMRESULT) { # Process every line of result and stuff it in $_
   1.148 +        $itemCount++;
   1.149 +        if($mode =~ /POSIX/) {
   1.150 +            &verbose("  $_");
   1.151 +            ($_, $address, $type) = split(/\|/);
   1.152 +            chop $qtype;
   1.153 +        } elsif ($mode =~ /Mach-O/) {
   1.154 +            ($address, $type, $_) = split(/ /);
   1.155 +            if(/^_(.*)$/) {
   1.156 +                $_ = $1;
   1.157 +            } else {
   1.158 +                next;
   1.159 +            }
   1.160 +        } else {
   1.161 +            die "Unknown mode $mode";
   1.162 +        }
   1.163 +        &verbose( "type: \"$type\" ");
   1.164 +        if(!($type =~ /[UAwW?]/)) {
   1.165 +            if(/@@/) { # These would be imports
   1.166 +                &verbose( "Import: $_ \"$type\"\n");
   1.167 +                &verbose( "C++ method: $_\n");
   1.168 +            } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array
   1.169 +	        ##  DON'T match    ...  (   foo::bar ...   want :: to be to the left of paren
   1.170 +                ## icu::CharString::~CharString(void) -> CharString
   1.171 +                @CppName = split(/::/); ## remove scope stuff
   1.172 +                
   1.173 +                if(@CppName>1) {
   1.174 +                    ## MessageFormat virtual table -> MessageFormat
   1.175 +                    if(! ($CppName[0] =~ /icu/ )) {
   1.176 +                        # *** WARNING Bad namespace (not 'icu') on ShoeSize::ShoeSize()
   1.177 +                        warn "*** WARNING Bad namespace (not 'icu') on $_\n";
   1.178 +                        next;
   1.179 +                    }
   1.180 +                    &verbose ( "(Chopping scope $CppName[0] )");
   1.181 +                    @CppName = split(/ /, $CppName[1]); ## remove debug stuff
   1.182 +                }
   1.183 +                ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex
   1.184 +                @CppName = split(/\(/, $CppName[0]); ## remove function args
   1.185 +                if($CppName[0] =~ /^operator/) {
   1.186 +                    &verbose ("Skipping C++ function: $_\n");
   1.187 +                } elsif($CppName[0] =~ /^~/) {
   1.188 +                    &verbose ("Skipping C++ destructor: $_\n");
   1.189 +                } else {
   1.190 +                    &verbose( "Skipping C++ class: '$CppName[0]': $_ \n");
   1.191 +                    # $CppClasses{$CppName[0]}++;
   1.192 +                    # $symbolCount++;
   1.193 +                }
   1.194 +	    } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) {
   1.195 +		&verbose ( "$ARGV[0]:  got global C++ function  $cfn with '$_'\n" );
   1.196 +                $CFuncs{$cfn}++;
   1.197 +		$symbolCount++;
   1.198 +            } elsif ( /\(/) { # These are strange functions
   1.199 +                print STDERR "$ARGV[0]: Not sure what to do with '$_'\n";
   1.200 +	    } elsif ( /^_init/ ) {
   1.201 +		&verbose( "$ARGV[0]: Skipped initializer $_\n" );
   1.202 +	    } elsif ( /^_fini/ ) {
   1.203 +		&verbose( "$ARGV[0]: Skipped finilizer $_\n" );
   1.204 +            } elsif ( /icu_/) {
   1.205 +                print STDERR "$ARGV[0]: Skipped strange mangled function $_\n";
   1.206 +            } elsif ( /^vtable for /) {
   1.207 +                print STDERR "$ARGV[0]: Skipped vtable $_\n";
   1.208 +            } elsif ( /^typeinfo/) {
   1.209 +                print STDERR "$ARGV[0]: Skipped typeinfo $_\n";
   1.210 +            } elsif ( /operator\+/ ) {
   1.211 +                print STDERR "$ARGV[0]: Skipped ignored function $_\n";
   1.212 +            } else { # This is regular C function 
   1.213 +                &verbose( "C func: $_\n");
   1.214 +                @funcname = split(/[\(\s+]/);
   1.215 +                $CFuncs{$funcname[0]}++;
   1.216 +		$symbolCount++;
   1.217 +            }
   1.218 +        } else {
   1.219 +            &verbose( "Skipped: $_ $1\n");
   1.220 +        }
   1.221 +    }
   1.222 +}
   1.223 +
   1.224 +if( $fileCount == 0 ) {
   1.225 +  die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
   1.226 +}
   1.227 +
   1.228 +if( $symbolCount == 0 ) {
   1.229 +  die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
   1.230 +}
   1.231 +
   1.232 +print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n";
   1.233 +
   1.234 +print HEADER "\n/* C exports renaming data */\n\n";
   1.235 +foreach(sort keys(%CFuncs)) {
   1.236 +    print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n";
   1.237 +#    print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n";
   1.238 +}
   1.239 +
   1.240 +print HEADER "\n#endif\n";
   1.241 +print HEADER "\n#endif\n";
   1.242 +
   1.243 +close HEADER;
   1.244 +
   1.245 +sub verbose {
   1.246 +    if($VERBOSE) {
   1.247 +        print STDERR @_;
   1.248 +    }
   1.249 +}
   1.250 +
   1.251 +
   1.252 +sub printHelpMsgAndExit {
   1.253 +    print STDERR <<"EndHelpText";
   1.254 +Usage: $0 [OPTIONS] LIBRARY_FILES
   1.255 +  Options: 
   1.256 +    -v - verbose
   1.257 +    -h - help
   1.258 +    -o - output file name (defaults to 'urename.h'
   1.259 +    -S - suffix (defaults to _MAJOR_MINOR of current ICU version)
   1.260 +Will produce a renaming .h file
   1.261 +
   1.262 +EndHelpText
   1.263 +
   1.264 +    exit 0;
   1.265 +
   1.266 +}

mercurial