charconvfw/Charconv/ongoing/Group/SNMTOOL.PL
author Pat Downey <patd@symbian.org>
Fri, 04 Jun 2010 10:37:54 +0100
changeset 32 8b9155204a54
permissions -rw-r--r--
Revert last code drop.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
#
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
# Copyright (c) 1997-2000 Nokia Corporation and/or its subsidiary(-ies).
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
# All rights reserved.
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
#
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
#
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
# Contributors:
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
#
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
# Description:      
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
#
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
use strict;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
use integer;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
BEGIN
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
	{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
	my $perlScriptPath=$0;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
	$perlScriptPath=~s/\//\\/g; # replace any forward-slashes with back-slashes
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
	$perlScriptPath=~s/(\\?)[^\\]+$/$1/; # get rid of this Perl-script's file-name
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
	unshift(@INC, $perlScriptPath); # can't do "use lib $perlScriptPath" here as "use lib" only seems to work with *hard-coded* directory names
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
	}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
use PARSER;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
use WRITER;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
$|=1; # ensures that any progress information sent to the screen is displayed immediately and not buffered
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
if ((@ARGV==0) || ($ARGV[0]=~/\?/i) || ($ARGV[0]=~/-h/i) || ($ARGV[0]=~/\/h/i) || ($ARGV[0]=~/help/i))
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
	{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
	die("\nVersion 021\n\nCharacter-set standard-names and MIB-enums tool\nCopyright (c) 2000 Symbian Ltd\n\nUsage:\n\n\tsnmtool <input-file> <output-file>\n\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
	}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
my $inputFileName=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
my $outputFileName=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
print "Generating $outputFileName...\n";
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
open(INPUT_FILE, "< $inputFileName") or die("Error: could not open \"$inputFileName\" for reading\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
my %characerSets=();
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
&readInputFile(\*INPUT_FILE, $inputFileName, \%characerSets);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
close(INPUT_FILE) or die("Error: could not close \"$inputFileName\"\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
open(OUTPUT_FILE, "> $outputFileName") or die("Error: could not open \"$outputFileName\" for writing\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
binmode OUTPUT_FILE;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
&writeOutputFile(\*OUTPUT_FILE, \%characerSets);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
close(OUTPUT_FILE) or die("Error: could not close \"$outputFileName\"\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
print "complete\n\n";
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
sub readInputFile
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
	{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
	my $fileHandle=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
	my $fileName=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
	my $characerSets=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
	my $line;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
	my $strippedDownLine;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
	my $identifier="";
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
	for (;;)
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
		{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
		($line, $strippedDownLine)=&nextNonEmptyStrippedDownLine($fileHandle);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
		if ($strippedDownLine eq "")
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
			{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
			last;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
			}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
		if ($strippedDownLine=~/^CharacterSet\s+0x([0-9a-f]+)$/i)
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
			{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
			$identifier=lc($1);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
			$characerSets->{$identifier}=[[], []];
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
			}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
		else
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
			{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
			if ($identifier eq "")
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
				{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
				close($fileHandle);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
				die("Error: unexpected line in \"$fileName\":\n    $line\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
				}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
			if ($strippedDownLine=~/^StandardName\s+"(.*)"$/i)
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
				{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
				push @{$characerSets->{$identifier}->[0]}, $1;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
				}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
			elsif ($strippedDownLine=~/^MibEnum\s+([0-9]+)$/i)
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
				{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
				push @{$characerSets->{$identifier}->[1]}, $1;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
				}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
			else
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
				{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
				close($fileHandle);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
				die("Error: unexpected line in \"$fileName\":\n    $line\n");
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
				}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
			}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
		}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
	}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
sub writeOutputFile
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
	{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
	my $fileHandle=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
	my $characerSets=shift;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
	&writeUids($fileHandle, 0x1000589b, 0, 0);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
	my $characerSetIdentifier;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
	my $identifier;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
	my $data;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
	while (($identifier, $data)=each(%$characerSets))
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
		{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
		&write32($fileHandle, hex($identifier));
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
		&writePositiveIntegerCompacted15($fileHandle, scalar(@{$data->[0]}));
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
		&writePositiveIntegerCompacted15($fileHandle, scalar(@{$data->[1]}));
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
		my $standardName;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
		foreach $standardName (@{$data->[0]})
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
			{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
			&writePositiveIntegerCompacted15($fileHandle, length($standardName));
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
			&writeString($fileHandle, $standardName);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
			}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
		my $mibEnum;
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
		foreach $mibEnum (@{$data->[1]})
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
			{
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
			&writePositiveIntegerCompacted30($fileHandle, $mibEnum);
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
			}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
		}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
	}
8b9155204a54 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118