os/kernelhwsrv/halservices/hal/halcfg.pl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
# All rights reserved.
sl@0
     3
# This component and the accompanying materials are made available
sl@0
     4
# under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
# which accompanies this distribution, and is available
sl@0
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
#
sl@0
     8
# Initial Contributors:
sl@0
     9
# Nokia Corporation - initial contribution.
sl@0
    10
#
sl@0
    11
# Contributors:
sl@0
    12
#
sl@0
    13
# Description:
sl@0
    14
# hal\halcfg.pl
sl@0
    15
# Check arguments and open files
sl@0
    16
# 
sl@0
    17
#
sl@0
    18
sl@0
    19
my $nargs=scalar(@ARGV);
sl@0
    20
my $xmode=0;
sl@0
    21
if ($nargs==0) {
sl@0
    22
	usage();
sl@0
    23
}
sl@0
    24
elsif ($nargs!=3 and $nargs!=4) {
sl@0
    25
	die "Invalid number of arguments.  Run with no arguments for help on usage.\n";
sl@0
    26
	exit;
sl@0
    27
}
sl@0
    28
my $arg=0;
sl@0
    29
if ($nargs==4) {
sl@0
    30
	if ($ARGV[$arg] eq '-x') {
sl@0
    31
		$xmode=1;
sl@0
    32
	} elsif ($ARGV[$arg] eq '-s') {
sl@0
    33
		$xmode=2;
sl@0
    34
	} elsif ($ARGV[$arg] eq '-h') {
sl@0
    35
		$xmode=3;
sl@0
    36
	} else {
sl@0
    37
		usage();
sl@0
    38
		die "Invalid 1st argument $ARGV[0]\n";
sl@0
    39
	}
sl@0
    40
	++$arg;
sl@0
    41
}
sl@0
    42
my $headerFileName=$ARGV[$arg++];
sl@0
    43
my @hdr = &read_file_strip_comments($headerFileName);
sl@0
    44
sl@0
    45
my $inputFileName=$ARGV[$arg++];
sl@0
    46
my @input = &read_file_strip_comments($inputFileName);
sl@0
    47
sl@0
    48
my $outputFileName=$ARGV[$arg++];
sl@0
    49
sl@0
    50
#
sl@0
    51
# Parse the header file
sl@0
    52
#
sl@0
    53
my $line=0;
sl@0
    54
my $state=0;
sl@0
    55
my $enumName;
sl@0
    56
my %enumValues=();
sl@0
    57
my $nextValue=0;
sl@0
    58
my $bitmask=0;
sl@0
    59
my %enumList=();
sl@0
    60
foreach (@hdr) {
sl@0
    61
	++$line;
sl@0
    62
	next if (/^\s*\#/);		# ignore preprocessor directives
sl@0
    63
	next if (/^\s*\/\//);	# ignore comments starting with //
sl@0
    64
	next if (/^\s*$/);		# ignore blank lines
sl@0
    65
	if ($state==0) {
sl@0
    66
		if (/^\s*class\s+HALData\s*$/) {
sl@0
    67
			$state=1;
sl@0
    68
		}
sl@0
    69
		if (/^\s*class\s+HALData\s*{/) {
sl@0
    70
			$state=2;
sl@0
    71
		}
sl@0
    72
		next;
sl@0
    73
	}
sl@0
    74
	if ($state==1) {
sl@0
    75
		if (/^\s*{/) {
sl@0
    76
			$state=2;
sl@0
    77
		}
sl@0
    78
		next;
sl@0
    79
	}
sl@0
    80
	if ($state==2) {
sl@0
    81
		if (/^\s*};/) {
sl@0
    82
			$state=3;
sl@0
    83
			last;
sl@0
    84
		}
sl@0
    85
		if (/^\s*enum\s+(\w+)(.*)/) {
sl@0
    86
			$enumName=$1;
sl@0
    87
			%enumValues=();
sl@0
    88
			$nextValue=0;
sl@0
    89
			$bitmask=0;
sl@0
    90
			if ($2=~/^\s+{/) {
sl@0
    91
				$state=5;
sl@0
    92
			} else {
sl@0
    93
				$state=4;
sl@0
    94
			}
sl@0
    95
		}
sl@0
    96
		if (/^\s*bitmask\s+(\w+)(.*)/) {
sl@0
    97
			$enumName=$1;
sl@0
    98
			%enumValues=();
sl@0
    99
			$nextValue=0;
sl@0
   100
			$bitmask=1;
sl@0
   101
			if ($2=~/^\s+{/) {
sl@0
   102
				$state=5;
sl@0
   103
			} else {
sl@0
   104
				$state=4;
sl@0
   105
			}
sl@0
   106
		}
sl@0
   107
		next;
sl@0
   108
	}
sl@0
   109
	if ($state==4) {
sl@0
   110
		if (/^\s*{/) {
sl@0
   111
			$state=5;
sl@0
   112
		}
sl@0
   113
		next;
sl@0
   114
	}
sl@0
   115
	if ($state==5) {
sl@0
   116
		if (/^\s*(\w+)(.*)/) {
sl@0
   117
			my $tag=$1;
sl@0
   118
			my $val=0;
sl@0
   119
			my $rest=$2;
sl@0
   120
#			print "$tag\n$rest\n";
sl@0
   121
			if ($rest=~/^\s*,/) {
sl@0
   122
				$val=$nextValue;
sl@0
   123
			} elsif ($rest=~/^\s*\=\s*(\d\w*)\s*\,/) {
sl@0
   124
				$val=$1;
sl@0
   125
				unless ($val=~/^\d*$/) {
sl@0
   126
					if ($val=~/^0x(\w+)$/i) {
sl@0
   127
						$val=hex $1;
sl@0
   128
					} else {
sl@0
   129
						undef $val;
sl@0
   130
					}
sl@0
   131
				}
sl@0
   132
			} elsif ($rest=~/^\s*$/) {	# ignore last one
sl@0
   133
				next;
sl@0
   134
			} else {
sl@0
   135
				undef $val;
sl@0
   136
			}
sl@0
   137
			unless (defined $val) {
sl@0
   138
				die "Syntax error at line $line in file $headerFileName\n";
sl@0
   139
			}
sl@0
   140
			$nextValue=$val+1;
sl@0
   141
			$enumValues{$tag}=$val;
sl@0
   142
#			print "$tag=$val\n";
sl@0
   143
		} elsif (/^\s*};/) {
sl@0
   144
			$state=2;
sl@0
   145
			if ($bitmask) {
sl@0
   146
				$enumValues{'__bitmask__'}=-1;
sl@0
   147
			}
sl@0
   148
			my %temp=%enumValues;
sl@0
   149
			$enumList{$enumName}=\%temp;
sl@0
   150
		}
sl@0
   151
		next;
sl@0
   152
	}
sl@0
   153
}
sl@0
   154
if ($state!=3) {
sl@0
   155
	die "Unexpected end of file in $headerFileName\n";
sl@0
   156
sl@0
   157
}
sl@0
   158
sl@0
   159
#	my @keys=keys %enumList;
sl@0
   160
#	foreach(@keys) {
sl@0
   161
#		print "enum $_\n\t{\n";
sl@0
   162
#		my $ref=$enumList{$_};
sl@0
   163
#		my @tags=keys(%$ref);
sl@0
   164
#		foreach(@tags) {
sl@0
   165
#			my $value=$$ref{$_};
sl@0
   166
#			print "\t$_=$value\n";
sl@0
   167
#		}
sl@0
   168
#		print "\t};\n";
sl@0
   169
#	}
sl@0
   170
sl@0
   171
#
sl@0
   172
# Build a list of properties for each attribute
sl@0
   173
#
sl@0
   174
my $attribref=$enumList{'TAttribute'};
sl@0
   175
unless ($attribref) {
sl@0
   176
	die "No TAttribute enum defined\n";
sl@0
   177
}
sl@0
   178
my @attribs=keys %$attribref;
sl@0
   179
my %attribList;
sl@0
   180
foreach (@attribs) {
sl@0
   181
	my %properties;
sl@0
   182
	$properties{'name'}=$_;
sl@0
   183
	$properties{'ordinal'}=$$attribref{$_};
sl@0
   184
	my $enum=$_;
sl@0
   185
	$enum=~s/^E/T/;			# change initial E to T
sl@0
   186
	if (defined $enumList{$enum}) {
sl@0
   187
		my $enumRef=$enumList{$enum};
sl@0
   188
		$properties{'enum'}=$enumRef;
sl@0
   189
		if (defined $$enumRef{'__bitmask__'}) {
sl@0
   190
			$properties{'bitmask'}=1;
sl@0
   191
		}
sl@0
   192
	}
sl@0
   193
	$attribList{$_}=\%properties;
sl@0
   194
}
sl@0
   195
sl@0
   196
my $attpropref=$enumList{'TAttributeProperty'};
sl@0
   197
my %PropTable;
sl@0
   198
if ($xmode) {
sl@0
   199
	unless ($attpropref) {
sl@0
   200
		die "No TAttributeProperty enum defined\n";
sl@0
   201
	}
sl@0
   202
sl@0
   203
	my @attprops=keys(%$attpropref);
sl@0
   204
	foreach (@attprops) {
sl@0
   205
		if (/^E(\w+)$/) {
sl@0
   206
			my $propname=lc $1;
sl@0
   207
			$PropTable{$propname}='HAL::'.$_;
sl@0
   208
		} else {
sl@0
   209
			die "Invalid attribute property $_\n";
sl@0
   210
		}
sl@0
   211
	}
sl@0
   212
}
sl@0
   213
my @PropTableKeys=keys %PropTable;
sl@0
   214
sl@0
   215
sl@0
   216
#
sl@0
   217
# Parse the input file
sl@0
   218
#
sl@0
   219
$line=0;
sl@0
   220
foreach (@input) {
sl@0
   221
	++$line;
sl@0
   222
	next if (/^\s*\/\//);	# ignore comments starting with //
sl@0
   223
	next if (/^\s*$/);		# ignore blank lines
sl@0
   224
	if (/^\s*(\w+)\s*(.*)/) {
sl@0
   225
		my $attrib=$1;
sl@0
   226
		my $rest=$2;
sl@0
   227
		my $propRef=$attribList{$attrib};
sl@0
   228
		unless (defined $propRef) {
sl@0
   229
			die "Unrecognised attribute at line $line in file $inputFileName\n";
sl@0
   230
		}
sl@0
   231
#		print "$rest\n";
sl@0
   232
		if ($rest=~/^\:\s*(.*)/) {	# attribute properties follow
sl@0
   233
			if (!$xmode) {
sl@0
   234
				die "Line $line: Properties not permitted without -x option\n";
sl@0
   235
			}
sl@0
   236
			$rest=$1;
sl@0
   237
#			print "$rest\n";
sl@0
   238
			while ($rest=~/^(\w+)\s*(.*)/) {
sl@0
   239
				my $prop=lc $1;
sl@0
   240
				$rest=$2;
sl@0
   241
#				print "$rest\n";
sl@0
   242
				my $error=matchabbrev(\$prop, \@PropTableKeys);
sl@0
   243
				if ($error) {
sl@0
   244
					die "$error property $prop at line $line in file $inputFileName\n";
sl@0
   245
				}
sl@0
   246
				$$propRef{$prop}=1;
sl@0
   247
				if ($rest=~/^,\s*(.*)/) {
sl@0
   248
					$rest=$1;
sl@0
   249
				} elsif ($rest=~/^=\s*(.*)/) {
sl@0
   250
					$rest=$1;
sl@0
   251
					last;
sl@0
   252
				} else {
sl@0
   253
					die "Syntax error at line $line in file $inputFileName\n";
sl@0
   254
				}
sl@0
   255
			}
sl@0
   256
		} elsif ($rest=~/^=\s*(.*)/) {
sl@0
   257
			$rest=$1				# attribute value follows
sl@0
   258
		} else {
sl@0
   259
			die "Invalid attribute specification at line $line in file $inputFileName\n";
sl@0
   260
		}
sl@0
   261
#		print "$rest\n";
sl@0
   262
		if ($xmode) {
sl@0
   263
#			print "$rest\n";
sl@0
   264
			if ($rest=~/^((\w|:)+)/) {
sl@0
   265
				$$propRef{'value'}=$1;
sl@0
   266
			} else {
sl@0
   267
				die "Invalid function name $rest at line $line in file $inputFileName\n";
sl@0
   268
			}
sl@0
   269
		} elsif (defined $$propRef{'bitmask'}) {		# bitmask value
sl@0
   270
			my $enumRef=$$propRef{'enum'};
sl@0
   271
			my @keys=keys %$enumRef;
sl@0
   272
			my $val=0;
sl@0
   273
			while ($rest=~/^(\w+)\s*(.*)/) {
sl@0
   274
				my $bitmaskKey=$1;
sl@0
   275
				$rest=$2;
sl@0
   276
				if ($bitmaskKey eq '0' or lc($bitmaskKey) eq 'none') {
sl@0
   277
					last if ($val==0);
sl@0
   278
					die "Inconsistent bit mask values at line $line in file $inputFileName\n";
sl@0
   279
				}
sl@0
   280
				my $error=matchabbrev(\$bitmaskKey,\@keys);
sl@0
   281
				if ($error) {
sl@0
   282
					die "$error bit value $bitmaskKey at line $line in file $inputFileName\n";
sl@0
   283
				}
sl@0
   284
				$val |= $$enumRef{$bitmaskKey};
sl@0
   285
				if ($rest=~/^\+\s*(.*)/) {
sl@0
   286
					$rest=$1;
sl@0
   287
				} elsif ($rest=~/^\s*$/) {
sl@0
   288
					last;
sl@0
   289
				} else {
sl@0
   290
					die "Syntax error at line $line in file $inputFileName\n";
sl@0
   291
				}
sl@0
   292
			}
sl@0
   293
			$$propRef{'value'}=$val;
sl@0
   294
		} elsif (defined $$propRef{'enum'} and $rest!~/^\d/) {	# enum value
sl@0
   295
			my $enumRef=$$propRef{'enum'};
sl@0
   296
			my @keys=keys %$enumRef;
sl@0
   297
			if ($rest=~/^(\w+)\s*$/) {
sl@0
   298
				my $enumKey=$1;
sl@0
   299
				my $error=matchabbrev(\$enumKey,\@keys);
sl@0
   300
				if ($error) {
sl@0
   301
					die "$error enumeration value $enumKey at line $line in file $inputFileName\n";
sl@0
   302
				}
sl@0
   303
				$$propRef{'value'}=$$enumRef{$enumKey};
sl@0
   304
			} else {
sl@0
   305
				die "Invalid enum value $rest at line $line in file $inputFileName\n";
sl@0
   306
			}
sl@0
   307
		} elsif ($rest=~/^(\-?\d\w*)\s*$/) {		# numeric value (decimal or hex) with optional -ve sign
sl@0
   308
			my $val=$1;
sl@0
   309
			unless ($val=~/^(\-?\d)\d*$/) {         # First character should be an optional -ve sign followed by only digits
sl@0
   310
				if ($val=~/^(\-?)0x(\w+)$/i) {       # First character should be an optional -ve sign followed by only alphanumerics 
sl@0
   311
					my $sign=$1;
sl@0
   312
					$val=hex $2;
sl@0
   313
					if ($sign  eq '-') {
sl@0
   314
					  $val=-$val;
sl@0
   315
					} 
sl@0
   316
				} else {
sl@0
   317
					undef $val;
sl@0
   318
				}
sl@0
   319
			}
sl@0
   320
			unless (defined $val) {
sl@0
   321
				die "Invalid attribute value $1 at line $line in file $inputFileName\n";
sl@0
   322
			}
sl@0
   323
			$$propRef{'value'}=$val;
sl@0
   324
		} else {								# invalid
sl@0
   325
			die "Invalid attribute value at line $line in file $inputFileName\n";
sl@0
   326
		}
sl@0
   327
	} else {
sl@0
   328
		die "Unrecognised attribute at line $line in file $inputFileName\n";
sl@0
   329
	}
sl@0
   330
}
sl@0
   331
sl@0
   332
#	foreach (@attribs) {
sl@0
   333
#		my $propRef=$attribList{$_};
sl@0
   334
#		if (defined $$propRef{'value'}) {
sl@0
   335
#			print "Attribute $_:\n";
sl@0
   336
#			my @keys=keys %$propRef;
sl@0
   337
#			foreach (@keys) {
sl@0
   338
#				print "\t$_=$$propRef{$_}\n";
sl@0
   339
#			}
sl@0
   340
#		}
sl@0
   341
#	}
sl@0
   342
sl@0
   343
#
sl@0
   344
# Sort attributes by ordinal
sl@0
   345
#
sl@0
   346
my @AttribsByOrdinal;
sl@0
   347
foreach (@attribs) {
sl@0
   348
	my $propRef=$attribList{$_};
sl@0
   349
	my $ordinal=$$propRef{'ordinal'};
sl@0
   350
	$AttribsByOrdinal[$ordinal]=$propRef;
sl@0
   351
}
sl@0
   352
my $nAttribs=scalar(@AttribsByOrdinal);
sl@0
   353
sl@0
   354
#
sl@0
   355
# Generate the output file
sl@0
   356
#
sl@0
   357
sl@0
   358
open OUT, ">$outputFileName" or die "Cannot open output file $outputFileName\n";
sl@0
   359
sl@0
   360
#	binmode OUT;
sl@0
   361
#	my $i=0;
sl@0
   362
#	while ($i<$nAttribs) {
sl@0
   363
#		my $value=0x80000000;
sl@0
   364
#		my $propRef=$AttribsByOrdinal[$i];
sl@0
   365
#		if (defined $$propRef{'value'}) {
sl@0
   366
#			$value=$$propRef{'value'};
sl@0
   367
#		}
sl@0
   368
#		++$i;
sl@0
   369
#		my $b3=($value>>24)&0xff;
sl@0
   370
#		my $b2=($value>>16)&0xff;
sl@0
   371
#		my $b1=($value>>8)&0xff;
sl@0
   372
#		my $b0=$value&0xff;
sl@0
   373
#		my $b0123=chr $b0;
sl@0
   374
#		$b0123.=chr $b1;
sl@0
   375
#		$b0123.=chr $b2;
sl@0
   376
#		$b0123.=chr $b3;
sl@0
   377
#		my $writeres=syswrite OUT, $b0123, 4;
sl@0
   378
#		if ($writeres != 4) {
sl@0
   379
#			die "Error writing output file $outputFileName\n";
sl@0
   380
#		}
sl@0
   381
#	}
sl@0
   382
#	exit;
sl@0
   383
sl@0
   384
my @splitName=split /(:|\\)/, $outputFileName;
sl@0
   385
my $rootName=pop @splitName;
sl@0
   386
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
sl@0
   387
#print "\n$hour:$min:$sec $mday-$mon-$year wday=$wday, yday=$yday, isdst=$isdst\n\n";
sl@0
   388
$year+=1900;
sl@0
   389
sl@0
   390
print OUT "// $rootName\n";
sl@0
   391
print OUT "//\n";
sl@0
   392
print OUT "// Copyright (c) 1999-$year Nokia Corporation and/or its subsidiary(-ies).";
sl@0
   393
print OUT "// All rights reserved.\n";
sl@0
   394
print OUT "//\n";
sl@0
   395
if ($xmode!=2) {
sl@0
   396
	print OUT "// GENERATED FILE - DO NOT EDIT\n";
sl@0
   397
	print OUT "//\n";
sl@0
   398
}
sl@0
   399
print OUT "\n";
sl@0
   400
print OUT "#include <kernel/hal_int.h>\n";
sl@0
   401
if ($xmode==0) {
sl@0
   402
	print OUT <<EOF;
sl@0
   403
#ifdef __CW32__
sl@0
   404
// CodeWarrior requires EXPORT_C on the definiton here, as well as the declaration (in hal_int.h)
sl@0
   405
EXPORT_C const TInt HalInternal::InitialValue[]=
sl@0
   406
#else
sl@0
   407
EXPORT_D const TInt HalInternal::InitialValue[]=
sl@0
   408
#endif
sl@0
   409
	{
sl@0
   410
EOF
sl@0
   411
sl@0
   412
	my $i=0;
sl@0
   413
	while ($i<$nAttribs) {
sl@0
   414
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   415
		++$i;
sl@0
   416
		my $separator=($i<$nAttribs)?',':'';
sl@0
   417
		my $name=$$propRef{'name'};
sl@0
   418
		my $value=0;
sl@0
   419
		if (defined $$propRef{'value'}) {
sl@0
   420
			$value=$$propRef{'value'};
sl@0
   421
		}
sl@0
   422
		print OUT "\t$value$separator\t\t// $name\n";
sl@0
   423
	}
sl@0
   424
	print OUT "\t};\n";
sl@0
   425
} elsif ($xmode==1) {
sl@0
   426
	print OUT "\n";
sl@0
   427
	my $i=0;
sl@0
   428
	while ($i<$nAttribs) {
sl@0
   429
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   430
		++$i;
sl@0
   431
		my $name=$$propRef{'name'};
sl@0
   432
		my $imp=$$propRef{'value'};
sl@0
   433
		if ($imp=~/^\s*0\s*$/) {
sl@0
   434
			undef $imp;
sl@0
   435
		}
sl@0
   436
		if (defined $imp) {
sl@0
   437
			print OUT "GLREF_C TInt $imp(TInt, TInt, TBool, TAny*);\t// $name\n";
sl@0
   438
		}
sl@0
   439
	}
sl@0
   440
	print OUT "\n";
sl@0
   441
	print OUT "const TUint8 HalInternal::Properties[]=\n";
sl@0
   442
	print OUT "\t{\n";
sl@0
   443
	$i=0;
sl@0
   444
	while ($i<$nAttribs) {
sl@0
   445
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   446
		++$i;
sl@0
   447
		my $separator=($i<$nAttribs)?',':'';
sl@0
   448
		my $properties="";
sl@0
   449
		my $name=$$propRef{'name'};
sl@0
   450
		if (defined $$propRef{'value'}) {
sl@0
   451
			$properties=$PropTable{'valid'};
sl@0
   452
			my @keys=keys(%$propRef);
sl@0
   453
			foreach (@keys) {
sl@0
   454
				my $pConst=$PropTable{$_};
sl@0
   455
				if (defined $pConst) {
sl@0
   456
					$properties.="|$pConst";
sl@0
   457
				}
sl@0
   458
			}
sl@0
   459
		}
sl@0
   460
		if ($properties=~/^\s*$/) {
sl@0
   461
			$properties='0';
sl@0
   462
		}
sl@0
   463
		print OUT "\t$properties$separator\t\t// $name\n";
sl@0
   464
	}
sl@0
   465
	print OUT "\t};\n";
sl@0
   466
	print OUT "\n#if 0\n";
sl@0
   467
	print OUT "const TInt HalInternal::Offset[]=\n";
sl@0
   468
	print OUT "\t{\n";
sl@0
   469
	my $memOffset=0;
sl@0
   470
	$i=0;
sl@0
   471
	while ($i<$nAttribs) {
sl@0
   472
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   473
		++$i;
sl@0
   474
		my $separator=($i<$nAttribs)?',':'';
sl@0
   475
		my $name=$$propRef{'name'};
sl@0
   476
		my $imp=$$propRef{'value'};
sl@0
   477
		if ($imp=~/^\s*0\s*$/) {
sl@0
   478
			print OUT "\t$memOffset$separator\t\t// $name\n";
sl@0
   479
			$memOffset+=4;
sl@0
   480
		} else {
sl@0
   481
			print OUT "\t-1$separator\t\t// $name\n";
sl@0
   482
		}
sl@0
   483
	}
sl@0
   484
	print OUT "\t};\n";
sl@0
   485
	print OUT "\n#endif\n";
sl@0
   486
	print OUT "const TInt HalInternal::HalDataSize=$memOffset;\n";
sl@0
   487
	print OUT "\n";
sl@0
   488
	print OUT "const THalImplementation HalInternal::Implementation[]=\n";
sl@0
   489
	print OUT "\t{\n";
sl@0
   490
	$i=0;
sl@0
   491
	while ($i<$nAttribs) {
sl@0
   492
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   493
		++$i;
sl@0
   494
		my $separator=($i<$nAttribs)?',':'';
sl@0
   495
		my $name=$$propRef{'name'};
sl@0
   496
		my $imp=$$propRef{'value'};
sl@0
   497
		if (!defined $imp or $imp=~/^\s*0\s*$/) {
sl@0
   498
			$imp='NULL';
sl@0
   499
		}
sl@0
   500
		print OUT "\t$imp$separator\t\t// $name\n";
sl@0
   501
	}
sl@0
   502
	print OUT "\t};\n";
sl@0
   503
} elsif ($xmode==2) {
sl@0
   504
	print OUT "\n";
sl@0
   505
	$i=0;
sl@0
   506
	while ($i<$nAttribs) {
sl@0
   507
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   508
		++$i;
sl@0
   509
		my $name=$$propRef{'name'};
sl@0
   510
		my $imp=$$propRef{'value'};
sl@0
   511
		if ($imp=~/^\s*0\s*$/) {
sl@0
   512
			undef $imp;
sl@0
   513
		}
sl@0
   514
		my $setarg=' /*aSet*/';
sl@0
   515
		if (defined $$propRef{'settable'}) {
sl@0
   516
			$setarg=' aSet';
sl@0
   517
		}
sl@0
   518
		if (defined $imp) {
sl@0
   519
			print OUT "// $name\n";
sl@0
   520
			print OUT "TInt $imp(TInt /*aDeviceNumber*/, TInt /*aAttrib*/, TBool$setarg, TAny* aInOut)\n";
sl@0
   521
			print OUT "\t{\n";
sl@0
   522
			print OUT "\treturn KErrNone;\n";
sl@0
   523
			print OUT "\t}\n";
sl@0
   524
			print OUT "\n";
sl@0
   525
		}
sl@0
   526
	}
sl@0
   527
	print OUT "\n";
sl@0
   528
} elsif ($xmode==3) {
sl@0
   529
	my $hdrprot='__'.uc $rootName.'__';
sl@0
   530
	$hdrprot=~s/\./_/;
sl@0
   531
	print OUT "\n";
sl@0
   532
	print OUT "#ifndef $hdrprot\n";
sl@0
   533
	print OUT "#define $hdrprot\n";
sl@0
   534
	$i=0;
sl@0
   535
	while ($i<$nAttribs) {
sl@0
   536
		my $propRef=$AttribsByOrdinal[$i];
sl@0
   537
		++$i;
sl@0
   538
		my $name=$$propRef{'name'};
sl@0
   539
		my $imp=$$propRef{'value'};
sl@0
   540
		if ($imp=~/^\s*0\s*$/) {
sl@0
   541
			undef $imp;
sl@0
   542
		}
sl@0
   543
		if (defined $imp) {
sl@0
   544
			print OUT "GLREF_C TInt $imp(TInt, TInt, TBool, TAny*);\t// $name\n";
sl@0
   545
		}
sl@0
   546
	}
sl@0
   547
	print OUT "\n";
sl@0
   548
	print OUT "#endif\n";
sl@0
   549
}
sl@0
   550
sl@0
   551
print OUT "\n";
sl@0
   552
sl@0
   553
exit;
sl@0
   554
sl@0
   555
# END OF MAIN
sl@0
   556
sl@0
   557
sub matchabbrev($$) {
sl@0
   558
	my ($inref, $lref)=@_;
sl@0
   559
	my @matches=grep(/$$inref/i,@$lref);
sl@0
   560
	my $nmatches=scalar(@matches);
sl@0
   561
	if ($nmatches==0) {
sl@0
   562
		return "Unknown";
sl@0
   563
	} elsif ($nmatches>1) {
sl@0
   564
		my @xmatches=grep(/^$$inref$/i,@matches);
sl@0
   565
		if (scalar(@xmatches)!=1) {
sl@0
   566
			return "Ambiguous";
sl@0
   567
		} else {
sl@0
   568
			$$inref=$xmatches[0];
sl@0
   569
			return undef;
sl@0
   570
		}
sl@0
   571
	} else {
sl@0
   572
		$$inref=$matches[0];
sl@0
   573
		return undef;
sl@0
   574
	}
sl@0
   575
}
sl@0
   576
sl@0
   577
sub read_file_strip_comments($) {
sl@0
   578
	my ($filename) = @_;
sl@0
   579
	open IN, $filename or die "Cannot read file $filename\n";
sl@0
   580
	my $in;
sl@0
   581
	while (<IN>) {
sl@0
   582
		$in .= $_;
sl@0
   583
	}
sl@0
   584
	close IN;
sl@0
   585
sl@0
   586
	# Strip comments
sl@0
   587
	$in =~ s/\/\*(.*?)\*\//\n/gms;
sl@0
   588
	$in =~ s/\/\/(.*?)\n/\n/gms;
sl@0
   589
sl@0
   590
	return split(/(\n)/, $in);
sl@0
   591
}
sl@0
   592
sl@0
   593
sub usage() {
sl@0
   594
	print
sl@0
   595
		"\n",
sl@0
   596
		"halcfg.pl is a perl script that is used by the build system to generate the\n",
sl@0
   597
		"C++ source files from the Config and Values files.\n",
sl@0
   598
		"\n",
sl@0
   599
		"There are four modes in which the Perl script halcfg.pl can be used.\n",
sl@0
   600
		"\n",
sl@0
   601
		"\"perl halcfg.pl hal_data.h values.hda values.cpp\"\n",
sl@0
   602
		"\n",
sl@0
   603
		"takes the values.hda text file and generates a table of initial values for\n",
sl@0
   604
		"items stored by the HAL.\n",
sl@0
   605
		"\n",
sl@0
   606
		"\"perl halcfg.pl -x hal_data.h config.hcf config.cpp\"\n",
sl@0
   607
		"\n",
sl@0
   608
		"generates three tables:\n",
sl@0
   609
		"\n",
sl@0
   610
		"  - the properties, i.e. whether valid and/or writable, for each item\n",
sl@0
   611
		"\n",
sl@0
   612
		"  - the offset of each item within the DllGlobal block\n",
sl@0
   613
		"\n",
sl@0
   614
		"  - the function implementing each item, for derived attributes. ie. those\n",
sl@0
   615
		"    attributes that are not simply stored by the HAL.\n",
sl@0
   616
		"\n",
sl@0
   617
		"\"perl halcfg.pl -s hal_data.h config.hcf source.cpp\"\n",
sl@0
   618
		"\n",
sl@0
   619
		"generates a source file containing skeleton code for the implementation of the\n",
sl@0
   620
		"accessor function for each derived attribute\n",
sl@0
   621
		"\n",
sl@0
   622
		"\"perl halcfg.pl -h hal_data.h config.hcf header.h\"\n",
sl@0
   623
		"\n",
sl@0
   624
		"generates a header file containing prototypes for the accessor functions for\n",
sl@0
   625
		"each derived attribute\n",
sl@0
   626
		"\n",
sl@0
   627
		"Note that the header file hal_data.h containing the attributes and values used\n",
sl@0
   628
		"by the HAL is passed on all calls to the perl script.\n";
sl@0
   629
sl@0
   630
	exit;
sl@0
   631
}