3 # usage: compile-et input.et
6 # ***** BEGIN LICENSE BLOCK *****
7 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 # The contents of this file are subject to the Mozilla Public License Version
10 # 1.1 (the "License"); you may not use this file except in compliance with
11 # the License. You may obtain a copy of the License at
12 # http://www.mozilla.org/MPL/
14 # Software distributed under the License is distributed on an "AS IS" basis,
15 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 # for the specific language governing rights and limitations under the
19 # The Original Code is the Netscape Portable Runtime (NSPR).
21 # The Initial Developer of the Original Code is
22 # Netscape Communications Corporation.
23 # Portions created by the Initial Developer are Copyright (C) 1998-2000
24 # the Initial Developer. All Rights Reserved.
28 # Alternatively, the contents of this file may be used under the terms of
29 # either the GNU General Public License Version 2 or later (the "GPL"), or
30 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 # in which case the provisions of the GPL or the LGPL are applicable instead
32 # of those above. If you wish to allow use of your version of this file only
33 # under the terms of either the GPL or the LGPL, and not to allow others to
34 # use your version of this file under the terms of the MPL, indicate your
35 # decision by deleting the provisions above and replace them with the notice
36 # and other provisions required by the GPL or the LGPL. If you do not delete
37 # the provisions above, a recipient may use your version of this file under
38 # the terms of any one of the MPL, the GPL or the LGPL.
40 # ***** END LICENSE BLOCK *****
44 local($filename, $comment) = @_;
49 $comment This file is automatically generated; please do not edit it.
58 for ($i = 0; $i < length($name); $i++) {
60 $base += index("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", substr($name, $i, 1)) + 1;
62 $base -= 0x1000000 if ($base > 0x7fffff);
67 local($macro, $text) = @_;
68 $code = $table_base + $table_item_count;
71 print H
"/* ", $text, " */\n";
72 printf H
"#define %-40s (%dL)\n", $macro, $code;
74 print C
"\t{\"", $macro, "\", \"", $text, "\"},\n";
76 print PROPERTIES
$macro, "=", $text, "\n";
83 open(INPUT
, "< $filename") || die "Can't read $filename: $!\n";
89 open(H
, "> ${base}.h") || die "Can't write ${base}.h\n";
90 open(C
, "> ${base}.c") || die "Can't write ${base}.c\n";
91 open(PROPERTIES
, "> ${base}.properties") || die "Can't write ${base}.properties\n";
93 print H
"/*\n", &header
("${base}.h", " *"), " */\n";
94 print C
"/*\n", &header
("${base}.c", " *"), " */\n";
95 print PROPERTIES
&header
("${base}.properties", "#");
99 while ($_ = <INPUT
>) {
102 if (/^[ \t]*(error_table|et)[ \t]+([a-zA-Z][a-zA-Z0-9_]+) *(-?[0-9]*)/) {
108 $table_base = &table_base
($table_name);
110 $table_item_count = 0;
112 print C
"#include \"prerror.h\"\n";
113 print C
"static const struct PRErrorMessage text[] = {\n";
115 elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*$/) {
119 elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*"(.*)"[ \t]*$/) {
122 elsif ($skipone && /^[ \t]*"(.*)"[ \t]*$/) {
128 print H
"extern void ", $table_name, "_InitializePRErrorTable","(void);\n";
129 printf H
"#define ERROR_TABLE_BASE_%s (%dL)\n", $table_name, $table_base;
131 print C
"\t{0, 0}\n";
133 printf C
"static const struct PRErrorTable et = { text, \"%s\", %dL, %d };\n",
134 $base, $table_base, $table_item_count;
136 print C
"void ", $table_name, "_InitializePRErrorTable", "(void) {\n";
137 print C
" PR_ErrorInstallTable(&et);\n";