sbsv1/abld/e32util/efreeze.pl
author Ross Qin <ross.qin@nokia.com>
Tue, 30 Nov 2010 13:59:58 +0800
changeset 712 df89378e9223
parent 606 30b30f9da0b7
permissions -rw-r--r--
Fix these errors: Some cases of PREQ1230 fail because of buildrom issue rombuild crashs when create ext-romimage readimage crashes on reading wk42 vasco_ui core image vc2008 compiling issues
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
#!/usr/bin/perl
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# all variables called *Path* are set up to end with a backslash
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
# all variables called *Path or *File are stored as absolute (file)paths
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
# all variables called UpPath* are stored as relative paths
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
use FindBin;		# for FindBin::Bin
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
use Getopt::Long;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
BEGIN {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
# check user has a version of perl that will cope
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	require 5.005_03;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
# establish the path to the Perl libraries: currently the same directory as this script
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
# do not convert slashes for linux
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
	if ($^O eq "MSWin32") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
		$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
		$PerlLibPath .= "\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
# Version
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
my $MajorVersion = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
my $MinorVersion = 1;
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    42
my $PatchVersion = 1;
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
use lib $PerlLibPath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
use Defutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
# THE MAIN PROGRAM SECTION
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
##########################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
	my %Options;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	# process the command-line
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	unless (GetOptions(\%Options, 'compare', 'remove')) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
		exit 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	unless (@ARGV==2) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
		&Usage;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
	my $FRZFILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	my $GENFILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
	($FRZFILE,$GENFILE)=(@ARGV);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
#	check the file exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
	unless (-e $FRZFILE) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
		warn "WARNING: $FRZFILE: File not found - OK if freezing for first time\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
	unless (-e $GENFILE) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
		die "EFREEZE ERROR: $GENFILE: File not found\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
#	Read the Frozen .DEF file if it exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	my @FrzDataStruct;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	my $FrzExportsOn=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	if (-e $FRZFILE) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
		eval { &Def_ReadFileL(\@FrzDataStruct, $FRZFILE, $FrzExportsOn); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
		die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
#	Read the New .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
	my @GenDataStruct;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	my $Dummy;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
	if ($GENFILE) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
		eval { &Def_ReadFileL(\@GenDataStruct, $GENFILE, $Dummy, ($Options{compare} or $Options{remove})); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
	die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
#	Compare the frozen .DEF data with the new .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
	my (@NewDataStruct, @MissingDataStruct, @BadDataStruct);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
	eval { &CompareFrzGenL (\@NewDataStruct, \@MissingDataStruct, \@BadDataStruct, \@FrzDataStruct, \@GenDataStruct, $Options{remove}); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
	die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
#	check for errors
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
	my $NumRemoved;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
	my $Ref;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
	my @Errors;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
	my $Title='EFREEZE ERROR:';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
	if ($Options{compare}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		$Title='EFREEZE:';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
	if (@MissingDataStruct and $Options{remove}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
#		Mark missing exports as ABSENT in DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
		$NumRemoved=@MissingDataStruct;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
		if ($Options{compare}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
			print "EFREEZE: Marking $NumRemoved Export(s) as ABSENT :\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
		} else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
			print "EFREEZE: Marking $NumRemoved Export(s) as ABSENT in $FRZFILE :\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
		foreach (@MissingDataStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
			$$_{Absent} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
			my $Comment='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
			if ($$_{Comment}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
				$Comment=" ; $$_{Comment}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
			my $r3unused = $$_{R3Unused} ? " R3UNUSED" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
			print "  $$_{Name} \@ $$_{Ordinal} NONAME$r3unused$Comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
	elsif (@MissingDataStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
		my $Num=@MissingDataStruct;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
		push @Errors, "$Title $FRZFILE: $Num Frozen Export(s) missing from $GENFILE (POSSIBLE COMPATIBILITY BREAK):\n"; 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
		foreach $Ref (@MissingDataStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
			my $r3unused = $$Ref{R3Unused} ? " R3UNUSED" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
			push @Errors, "  $$Ref{LineNum}: $$Ref{Name} \@ $$Ref{Ordinal} NONAME$r3unused\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
		push @Errors, "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
	if (@BadDataStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
		my $Num=@BadDataStruct;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
		push @Errors, "$Title $GENFILE: $Num function(s) exported at wrong ordinal:\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
		foreach $Ref (@BadDataStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
			my $r3unused = $$Ref{R3Unused} ? " R3UNUSED" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
			push @Errors, "  $$Ref{LineNum}: $$Ref{Name} \@ $$Ref{Ordinal} NONAME$r3unused\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
	if (@Errors) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
		unless ($Options{compare}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
			die @Errors;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
		else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
			print @Errors;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
#	Update the frozen .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
	eval { &UpdateFrzFileL(\@NewDataStruct, \@FrzDataStruct, $FRZFILE, $FrzExportsOn, $Options{compare}, $NumRemoved); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
	die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
	exit;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
#######################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
# SUBROUTINES
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
#######################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
sub Usage () {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
	print(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
		"\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
		"EFREEZE - .DEF file maintenance utility V$MajorVersion.$MinorVersion.$PatchVersion\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
		"\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
		"EFREEZE {options} [frozen .DEF file] [new .DEF file]\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
		"\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
		"options:   (case-insensitive)\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
		"  -Compare\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
		"  -Remove\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
		"\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
	);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
	exit 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
sub CompareFrzGenL ($$$$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
	my ($NewStructRef, $MissingStructRef, $BadStructRef, $FrzStructRef, $GenStructRef, $remove)=@_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
#	compare the input export data with the frozen data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
#	take a copy of the frozen .DEF file structure that we can trash
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
	my @TmpStruct=@$FrzStructRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
#	remove any entries not containing export data and get the highest ordinal value used
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
	my $LastOrdinal=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
	foreach (@TmpStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
		if ($$_{Name}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
			if ($LastOrdinal<$$_{Ordinal}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
				$LastOrdinal=$$_{Ordinal};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
		undef $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
	my $GenRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
	my $TmpRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
	GENLOOP: foreach $GenRef (@$GenStructRef) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
		next unless $$GenRef{Name};		# ignore lines in the .DEF file not containing an export
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
		foreach $TmpRef (@TmpStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
			next unless defined $TmpRef; # ignore nullified entries in the temporary array
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
#			does the function name match?
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
			if ($$GenRef{Name} eq $$TmpRef{Name}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
#				check the names have the same ordinals
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
				if ($remove or $$GenRef{Ordinal}==$$TmpRef{Ordinal}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
					undef $TmpRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
					next GENLOOP;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
#				store exports with the wrong ordinals
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
				push @$BadStructRef, $GenRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
				undef $TmpRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
				next GENLOOP;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
#			Absent export?
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
			if ($$TmpRef{Absent} and $$TmpRef{Ordinal}==$$GenRef{Ordinal}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
				next GENLOOP;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
#		store new exports not found in the frozen .DEF file with the right ordinal value
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
		$LastOrdinal++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
		$$GenRef{Ordinal}=$LastOrdinal;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
		push @$NewStructRef, $GenRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
#	all the exports left in the frozen .DEF file weren't found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
	foreach $TmpRef (@TmpStruct) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
		next unless defined $TmpRef; # ignore nullified entries in the temporary array
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
		next if $$TmpRef{Absent};	# skip entries marked as ABSENT in the DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
		push @$MissingStructRef, $TmpRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
sub UpdateFrzFileL ($$$$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
	my ($NewStructRef, $FrzStructRef, $FILE, $ExportsOn, $Compare, $NumRemoved)=@_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
#	add the exports to the frozen .DEF file text
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
	unless (@$NewStructRef or $NumRemoved) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
		print "EFREEZE: DEF file up to date\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
	my $NumNewExports=@$NewStructRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
	unless ($Compare) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
# 		abort the operation unless the frozen .DEF file is writeable
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
		if (-e $FILE and not -w $FILE) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
			die
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
				"EFREEZE ERROR: Can't append $NumNewExports New Export(s) to $FILE\n",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
				"  as file is not writeable.  Check source code control system.\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
			;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
		print "EFREEZE: Appending $NumNewExports New Export(s) to $FILE:\n" if ($NumNewExports);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
	else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
		print "EFREEZE: $NumNewExports New Export(s):\n" if ($NumNewExports);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
	my @Text;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
	my $ExportsDeclared;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
#	Process the frozen .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
	if (@$FrzStructRef) { # there is already a frozen .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
		my $FrzRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
#		get the lines of text from the frozen .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
		foreach $FrzRef (@$FrzStructRef) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
			next if (!$FrzRef);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   266
			if (!defined($$FrzRef{Ordinal})) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   267
				push @Text, $$FrzRef{Line};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   268
				$ExportsDeclared = 1 if ($$FrzRef{Line} =~ /^\s*EXPORTS\s*(\s+\S+.*)?$/io);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   269
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   270
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   271
			my $Comment='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   272
			if ($$FrzRef{Comment}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   273
				$Comment=" ; $$FrzRef{Comment}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   274
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   275
			my $r3unused = $$FrzRef{R3Unused} ? " R3UNUSED" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   276
			my $absent = $$FrzRef{Absent} ? " ABSENT" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   277
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   278
			my $data = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   279
			if( !($$FrzRef{Name} =~ /^(_ZTI|_ZTV|_ZTT)/))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   280
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   281
#				A symbol name with the above pattern indicates that it is a Data symbol.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   282
#				Mark symbols as DATA only when it cannot be found from the name alone (i.e.,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   283
#				explicitly exported data symbols).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   284
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   285
				if(($$FrzRef{Data}) and ($$FrzRef{Size}) ){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   286
				$data = " DATA $$FrzRef{Size}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   287
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   288
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   289
			push @Text, "\t$$FrzRef{Name} \@ $$FrzRef{Ordinal} NONAME$data$r3unused$absent$Comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   290
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   291
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   292
#		strip any blank lines at the end of the frozen .DEF file text
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   293
		foreach (reverse @Text) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   294
			if (/^\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   295
				$_='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   296
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   297
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   298
			last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   299
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   300
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   301
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   302
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   303
#	Add an EXPORTS section header if there aren't already exports
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   304
	unshift @Text, "EXPORTS\n" unless ($ExportsDeclared);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   305
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   306
	my $NewRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   307
	foreach $NewRef (@$NewStructRef) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   308
		my $Comment='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   309
		if ($$NewRef{Comment}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   310
			$Comment=" ; $$NewRef{Comment}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   311
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   312
		my $r3unused = $$NewRef{R3Unused} ? " R3UNUSED" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   313
		my $absent = $$NewRef{Absent} ? " ABSENT" : "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   314
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   315
		my $data = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   316
		if( !($$NewRef{Name} =~ /^(_ZTV|_ZTI|_ZTT)/)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   317
#				A symbol name with the above pattern indicates that it is a Data symbol.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   318
#				Mark symbols as DATA only when it cannot be found from the name alone (i.e.,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   319
#				explicitly exported data symbols).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   320
			if(($$NewRef{Data}) and ($$NewRef{Size}) ){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   321
			$data = " DATA $$NewRef{Size}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   322
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   323
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   324
		print "  $$NewRef{Name} \@ $$NewRef{Ordinal} NONAME$r3unused$Comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   325
		push @Text, "\t$$NewRef{Name} \@ $$NewRef{Ordinal} NONAME$data$r3unused$absent$Comment\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   326
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   327
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   328
#	add a terminating newline
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   329
	push @Text, "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   330
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   331
	unless ($Compare) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   332
#		write the new frozen .DEF file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   333
		eval { &Def_WriteFileL(\@Text, $FILE); };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   334
		die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   335
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   336
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   337