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