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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/perl
     3 # usage: compile-et input.et
     5 # 
     6 # This Source Code Form is subject to the terms of the Mozilla Public
     7 # License, v. 2.0. If a copy of the MPL was not distributed with this
     8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
    10 sub header
    11 {
    12     local($filename, $comment) = @_;
    14 <<EOF
    15 $comment
    16 $comment $filename
    17 $comment This file is automatically generated; please do not edit it.
    18 EOF
    19 }
    21 sub table_base
    22 {
    23     local($name) = @_;
    24     local($base) = 0;
    26     for ($i = 0; $i < length($name); $i++) {
    27 	$base *= 64;
    28 	$base += index("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", substr($name, $i, 1)) + 1;
    29     }
    30     $base -= 0x1000000 if ($base > 0x7fffff);
    31     $base*256;
    32 }
    34 sub code {
    35     local($macro, $text) = @_;
    36     $code = $table_base + $table_item_count;
    38     print H "\n";
    39     print H "/* ", $text, " */\n";
    40     printf H "#define %-40s (%dL)\n", $macro, $code;
    42     print C "\t{\"", $macro, "\",    \"", $text, "\"},\n";
    44     print PROPERTIES $macro, "=", $text, "\n";
    46     $table_item_count++;
    47 }
    50 $filename = $ARGV[0];
    51 open(INPUT, "< $filename") || die "Can't read $filename: $!\n";
    53 $base = "$filename";
    54 $base =~ s/\.et$//;
    55 $base =~ s#.*/##;
    57 open(H, "> ${base}.h") || die "Can't write ${base}.h\n";
    58 open(C, "> ${base}.c") || die "Can't write ${base}.c\n";
    59 open(PROPERTIES, "> ${base}.properties") || die "Can't write ${base}.properties\n";
    61 print H "/*\n", &header("${base}.h", " *"), " */\n";
    62 print C "/*\n", &header("${base}.c", " *"), " */\n";
    63 print PROPERTIES &header("${base}.properties", "#");
    65 $skipone = 0;
    67 while ($_ = <INPUT>) {
    68     next if /^#/;
    70     if (/^[ \t]*(error_table|et)[ \t]+([a-zA-Z][a-zA-Z0-9_]+) *(-?[0-9]*)/) {
    71 	$table_name = $2;
    72 	if ($3) {
    73 	    $table_base = $3;
    74 	}
    75 	else {
    76 	    $table_base = &table_base($table_name);
    77 	}
    78 	$table_item_count = 0;
    80 	print C "#include \"prerror.h\"\n";
    81 	print C "static const struct PRErrorMessage text[] = {\n";
    82     }
    83     elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*$/) {
    84 	$skipone = 1;
    85 	$macro = $2;
    86     }
    87     elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*"(.*)"[ \t]*$/) {
    88 	&code($2, $3);
    89     }
    90     elsif ($skipone && /^[ \t]*"(.*)"[ \t]*$/) {
    91 	&code($macro, $1);
    92     }
    93 }
    95 print H "\n";
    96 print H "extern void ", $table_name, "_InitializePRErrorTable","(void);\n";
    97 printf H "#define ERROR_TABLE_BASE_%s (%dL)\n", $table_name, $table_base;
    99 print C "\t{0, 0}\n";
   100 print C "};\n\n";
   101 printf C "static const struct PRErrorTable et = { text, \"%s\", %dL, %d };\n",
   102     $base, $table_base, $table_item_count;
   103 print C "\n";
   104 print C "void ", $table_name, "_InitializePRErrorTable", "(void) {\n";
   105 print C "    PR_ErrorInstallTable(&et);\n";
   106 print C "}\n";
   108 0;

mercurial