Update contrib.
1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
3 # This component and the accompanying materials are made available
4 # under the terms of "Eclipse Public License v1.0"
5 # which accompanies this distribution, and is available
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 # Initial Contributors:
9 # Nokia Corporation - initial contribution.
14 # stringtable.pl - Makes a string table .cpp and .h file from a .st file
15 # This tool takes a valid .st file as an input parameter and converts it into a .h and a .cpp file
21 # Removes the extension from the filename
22 $ARGV[0] =~ m/(.*)\..*/;
24 $root =~ m/(.*[\\\/])([^\\\/]*)$/;
26 my $path_to_file = ("$1");
27 my $filename = lc("$2");
28 my $header_to_include = lc("$filename.h");
30 # Open the input filename
31 open (IN, "<$ARGV[0]" ) or die ("Error: $ARGV[0] $!");
33 # Parse header comments
36 while ($input = <IN>) {
37 # Comments starting with '#' not to be included in header file
38 next if ($input =~ /^\s*\#/);
42 # Save comments containing '!' or stop looking if something else is found
43 if ($input =~ /\!(.*)/) {
44 push(@comments, "$1\n");
51 # Check that line is of the right format and get the table name.
52 $input =~ m/(f*stringtable) ([A-Za-z0-9_]+)/ or die ("Error: $ARGV[0] is not a stringtable file");
54 if ($1 eq "stringtable") {
60 # Open the output filenames
61 open (CPP, ">"."$path_to_file"."$filename".".cpp" ) or die ("Error: $ARGV[0] Can't open cpp file");
62 open (HEADER, ">"."$path_to_file"."$filename".".h" ) or die ("Error: $ARGV[0] Can't open header file");
64 my $sourcename = $ARGV[0];
65 $sourcename =~ s/^(.*epoc32)/epoc32/i;
67 # Output the preambles
69 // Autogenerated from $sourcename by the stringtable tool - Do not edit
71 #include <stringpool.h>
72 #include <stringtablesupport.h>
73 #include "$header_to_include"
81 // Autogenerated from $sourcename by the stringtable tool - Do not edit
83 #ifndef STRINGTABLE_$name
84 #define STRINGTABLE_$name
86 #include <stringpool.h>
92 # If there are no header comments, use the default comment, otherwise, add the header comments
94 print HEADER "/** A String table */\n";
96 print HEADER @comments;
113 # Treat lines with a '#' as the first character as comments and skip them, ignoring 0 or more whitespaces before it.
114 # If # is not the first character, then treat them as part of the string.
117 $input = readline (*IN);
119 } while ($input =~ m/^\s*\#/);
121 if ($input =~ m/\!(.*)/) {
122 # Save lines that start with '!' to print later
123 push(@commentlines, "\t\t$1\n");
126 $input =~ m/([A-Za-z0-9]+)\s*(.*)/ or die ("Error: $ARGV[0] badly formed at \"$input\"");
128 # If a comma needs to be printed, print it
129 if ($outputcomma == 1) {
133 # Print pending comments and clear the comments array
134 if (@commentlines > 0) {
135 print HEADER @commentlines;
139 # Form a version of the string that can go in a comment. This
140 # can't contain /* or */
143 $string =~ s/\s+$//; # remove any trailing whitespace
144 my $comment = $string;
145 $comment =~ s|/\*|/ \*|g;
146 $comment =~ s|\*/|\* /|g;
148 # Increment the count
150 print HEADER "\t\t/** $comment */\n";
151 print HEADER "\t\t$enum";
152 print CPP "_STLIT8(K$count, \"$string\");\n";
157 # Print closing comments
158 if (@commentlines > 0) {
160 print HEADER @commentlines;
166 #Output intermediate boilerplate in the cpp
170 const void * const KStringPointers[] =
174 # And the end of the headers
177 static const TStringTable Table;
180 #endif // STRINGTABLE_$name
184 #Output the table of pointers to the cpp file
187 for ($count = 1; $count <= $total ; $count++) {
191 print CPP "\t(const void*)&K$count";
194 #The last of the boilerplate
199 const TStringTable ${name}::Table = {$total, KStringPointers, $folding};