nsprpub/pr/src/misc/compile-et.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/misc/compile-et.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +# usage: compile-et input.et
     1.7 +
     1.8 +# 
     1.9 +# This Source Code Form is subject to the terms of the Mozilla Public
    1.10 +# License, v. 2.0. If a copy of the MPL was not distributed with this
    1.11 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    1.12 +
    1.13 +sub header
    1.14 +{
    1.15 +    local($filename, $comment) = @_;
    1.16 +
    1.17 +<<EOF
    1.18 +$comment
    1.19 +$comment $filename
    1.20 +$comment This file is automatically generated; please do not edit it.
    1.21 +EOF
    1.22 +}
    1.23 +
    1.24 +sub table_base
    1.25 +{
    1.26 +    local($name) = @_;
    1.27 +    local($base) = 0;
    1.28 +
    1.29 +    for ($i = 0; $i < length($name); $i++) {
    1.30 +	$base *= 64;
    1.31 +	$base += index("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", substr($name, $i, 1)) + 1;
    1.32 +    }
    1.33 +    $base -= 0x1000000 if ($base > 0x7fffff);
    1.34 +    $base*256;
    1.35 +}
    1.36 +
    1.37 +sub code {
    1.38 +    local($macro, $text) = @_;
    1.39 +    $code = $table_base + $table_item_count;
    1.40 +
    1.41 +    print H "\n";
    1.42 +    print H "/* ", $text, " */\n";
    1.43 +    printf H "#define %-40s (%dL)\n", $macro, $code;
    1.44 +
    1.45 +    print C "\t{\"", $macro, "\",    \"", $text, "\"},\n";
    1.46 +
    1.47 +    print PROPERTIES $macro, "=", $text, "\n";
    1.48 +
    1.49 +    $table_item_count++;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +$filename = $ARGV[0];
    1.54 +open(INPUT, "< $filename") || die "Can't read $filename: $!\n";
    1.55 +
    1.56 +$base = "$filename";
    1.57 +$base =~ s/\.et$//;
    1.58 +$base =~ s#.*/##;
    1.59 +
    1.60 +open(H, "> ${base}.h") || die "Can't write ${base}.h\n";
    1.61 +open(C, "> ${base}.c") || die "Can't write ${base}.c\n";
    1.62 +open(PROPERTIES, "> ${base}.properties") || die "Can't write ${base}.properties\n";
    1.63 +
    1.64 +print H "/*\n", &header("${base}.h", " *"), " */\n";
    1.65 +print C "/*\n", &header("${base}.c", " *"), " */\n";
    1.66 +print PROPERTIES &header("${base}.properties", "#");
    1.67 +
    1.68 +$skipone = 0;
    1.69 +
    1.70 +while ($_ = <INPUT>) {
    1.71 +    next if /^#/;
    1.72 +
    1.73 +    if (/^[ \t]*(error_table|et)[ \t]+([a-zA-Z][a-zA-Z0-9_]+) *(-?[0-9]*)/) {
    1.74 +	$table_name = $2;
    1.75 +	if ($3) {
    1.76 +	    $table_base = $3;
    1.77 +	}
    1.78 +	else {
    1.79 +	    $table_base = &table_base($table_name);
    1.80 +	}
    1.81 +	$table_item_count = 0;
    1.82 +
    1.83 +	print C "#include \"prerror.h\"\n";
    1.84 +	print C "static const struct PRErrorMessage text[] = {\n";
    1.85 +    }
    1.86 +    elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*$/) {
    1.87 +	$skipone = 1;
    1.88 +	$macro = $2;
    1.89 +    }
    1.90 +    elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*"(.*)"[ \t]*$/) {
    1.91 +	&code($2, $3);
    1.92 +    }
    1.93 +    elsif ($skipone && /^[ \t]*"(.*)"[ \t]*$/) {
    1.94 +	&code($macro, $1);
    1.95 +    }
    1.96 +}
    1.97 +
    1.98 +print H "\n";
    1.99 +print H "extern void ", $table_name, "_InitializePRErrorTable","(void);\n";
   1.100 +printf H "#define ERROR_TABLE_BASE_%s (%dL)\n", $table_name, $table_base;
   1.101 +
   1.102 +print C "\t{0, 0}\n";
   1.103 +print C "};\n\n";
   1.104 +printf C "static const struct PRErrorTable et = { text, \"%s\", %dL, %d };\n",
   1.105 +    $base, $table_base, $table_item_count;
   1.106 +print C "\n";
   1.107 +print C "void ", $table_name, "_InitializePRErrorTable", "(void) {\n";
   1.108 +print C "    PR_ErrorInstallTable(&et);\n";
   1.109 +print C "}\n";
   1.110 +
   1.111 +0;

mercurial