sbsv1/abld/e32util/defutl.pm
author jascui
Wed, 17 Nov 2010 13:39:15 +0800
changeset 687 da9e6195bd8d
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Updating release text and product version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# this module requires Pathutl module to have been 'used' by the main program
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# General Def file utilities
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
package Defutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
require Exporter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
@ISA=qw(Exporter);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
@EXPORT=qw(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
	Def_ReadFileL Def_WriteFileL
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
use File::Path;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
use File::Basename;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
sub Def_ReadFileL ($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
#	this function reads a .DEF file, putting the export information into a data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
#	structure
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
	my ($DataStructRef, $FILE, $ExportsOn, $IgnoreSequence)=@_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
#	initialisation
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
	@$DataStructRef=();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
#	this function expects all statements to appear on separate lines - though MSVC doesn't
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
	open (FILE, "<$FILE") or die "could not open $FILE: $!";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
	my $PreviousOrdinal=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
	my $MultiLineStatement='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
	my $NAMEorLIBRARYallowed=1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
	my $LineNum=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
	while (<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
		$LineNum++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
		my %Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
		$Data{Line}=$_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
		$Data{LineNum}=$LineNum;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
#		blank lines and comment lines
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
		if (/^\s*(;.*)?$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
			push @$DataStructRef, \%Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
			next;
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
		if (/^\s*(EXPORTS|SECTIONS|IMPORTS)\s*(\s+\S+.*)?$/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
#			check for multi-line sections starting
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
			$MultiLineStatement=uc $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
			$NAMEorLIBRARYallowed=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
			unless ($2) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
				push @$DataStructRef, \%Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
			$_=$2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
		elsif (/^\s*(NAME|LIBRARY|DESCRIPTION|STACKSIZE|VERSION)\s*(\s+\S+.*)?$/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
#			set MULTI-LINE statement to OFF
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
			$MultiLineStatement='';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
#			check single-line statements are specified correctly
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
			$_=uc $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
#			check NAME or LIBRARY statements aren't supplied incorrectly
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
			if (/^(NAME|LIBRARY)$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
				unless ($NAMEorLIBRARYallowed) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
					die "$FILE($LineNum) : DEFFILE ERROR: NAME or LIBRARY statements must precede all other statements\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
				push @$DataStructRef, \%Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
			$NAMEorLIBRARYallowed=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
			push @$DataStructRef, \%Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
		else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
			unless ($MultiLineStatement) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
				chomp $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
				die "$FILE($LineNum) : DEFFILE ERROR: Unrecognised Syntax \"$_\"\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
		if ($MultiLineStatement eq 'EXPORTS') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
#			get export data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
			if (/^\s*(\S+)\s+\@\s*(\d+)\s*(NONAME)?\s*((DATA)\s*(\d+))?\s*(R3UNUSED)?\s*(ABSENT)?\s*(;\s*(.*))?$/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
				$Data{Name}=$1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
				$Data{Ordinal}=$2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
				if ($4) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
#					Mark the data symbols and retain the size.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
					$Data{Data} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
					if($6){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
					$Data{Size} = $6;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
				if ($7) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
					$Data{R3Unused} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
				if ($8) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
					$Data{Absent} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
				if ($10) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
					$Data{Comment}=$10;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
				if ($Data{Name} =~ /^(\S+?)=(\S+)$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
# 					rename this export
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
					$Data{ExportName}=$1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
					$Data{Name}=$2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
					if ($Data{Name} =~ /=/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
						die "$FILE($LineNum) : DEFFILE ERROR: $Data{Name} Invalid rename syntax\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
				else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
					$Data{ExportName}=$Data{Name};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
#				test the export - this is probably too slow to bother with
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
				my $ExportRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
				unless ($IgnoreSequence) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
#					check ordinal specified in sequence - this check is a style matter
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
#					rather the a .DEF file syntax matter, so maybe it shouldn't be applied
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
					unless ($Data{Ordinal}==($PreviousOrdinal+1)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
						die "$FILE($LineNum) : DEFFILE ERROR: Ordinal not specified in sequence\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
				$PreviousOrdinal=$Data{Ordinal};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
				push @$DataStructRef, \%Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
			if (/^\s*_E32Startup(\s*\=\s*__E32Startup)?\s+(;\s*(.*))?$/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
#				Emulator's special entrypoint ordinal
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
			if (/^\s*_E32Dll(\s*\=\s*__E32Dll)?\s+(;\s*(.*))?$/io) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
#				Emulator's special entrypoint ordinal
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
				next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
			die "$FILE($LineNum) : DEFFILE ERROR: Incorrect EXPORTS statement syntax\n";
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
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
#	decide whether we've ended up with an EXPORTS section specified
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
	if ($MultiLineStatement eq 'EXPORTS') {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
		$_[2]=1; # $ExportsOn
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
	else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
		$_[2]=0; # $ExportsOn
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
	close FILE or die "DEFFILE ERROR: Can't close file $FILE: $!\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
sub Def_WriteFileL ($$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
#	Writes an array of text to a file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
	my ($TextArrayRef, $FILE)=@_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
	# make sure path exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
	my($filename, $directories, $suffix) = fileparse($FILE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
	unless (-d $directories) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
		eval { mkpath[$directories] };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
		die $@ if $@;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
	} 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
	open (FILE, ">$FILE") or die "DEFFILE ERROR: Could not open $FILE: $!\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
	print FILE @$TextArrayRef or die "DEFFILE ERROR: Can't write output to $FILE: $!\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
	close FILE or die "DEFFILE ERROR: Can't close file $FILE: $!\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
1;