michael@0: #!/usr/bin/perl michael@0: michael@0: # usage: compile-et input.et michael@0: michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: sub header michael@0: { michael@0: local($filename, $comment) = @_; michael@0: michael@0: < 0x7fffff); michael@0: $base*256; michael@0: } michael@0: michael@0: sub code { michael@0: local($macro, $text) = @_; michael@0: $code = $table_base + $table_item_count; michael@0: michael@0: print H "\n"; michael@0: print H "/* ", $text, " */\n"; michael@0: printf H "#define %-40s (%dL)\n", $macro, $code; michael@0: michael@0: print C "\t{\"", $macro, "\", \"", $text, "\"},\n"; michael@0: michael@0: print PROPERTIES $macro, "=", $text, "\n"; michael@0: michael@0: $table_item_count++; michael@0: } michael@0: michael@0: michael@0: $filename = $ARGV[0]; michael@0: open(INPUT, "< $filename") || die "Can't read $filename: $!\n"; michael@0: michael@0: $base = "$filename"; michael@0: $base =~ s/\.et$//; michael@0: $base =~ s#.*/##; michael@0: michael@0: open(H, "> ${base}.h") || die "Can't write ${base}.h\n"; michael@0: open(C, "> ${base}.c") || die "Can't write ${base}.c\n"; michael@0: open(PROPERTIES, "> ${base}.properties") || die "Can't write ${base}.properties\n"; michael@0: michael@0: print H "/*\n", &header("${base}.h", " *"), " */\n"; michael@0: print C "/*\n", &header("${base}.c", " *"), " */\n"; michael@0: print PROPERTIES &header("${base}.properties", "#"); michael@0: michael@0: $skipone = 0; michael@0: michael@0: while ($_ = ) { michael@0: next if /^#/; michael@0: michael@0: if (/^[ \t]*(error_table|et)[ \t]+([a-zA-Z][a-zA-Z0-9_]+) *(-?[0-9]*)/) { michael@0: $table_name = $2; michael@0: if ($3) { michael@0: $table_base = $3; michael@0: } michael@0: else { michael@0: $table_base = &table_base($table_name); michael@0: } michael@0: $table_item_count = 0; michael@0: michael@0: print C "#include \"prerror.h\"\n"; michael@0: print C "static const struct PRErrorMessage text[] = {\n"; michael@0: } michael@0: elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*$/) { michael@0: $skipone = 1; michael@0: $macro = $2; michael@0: } michael@0: elsif (/^[ \t]*(error_code|ec)[ \t]+([A-Z_0-9]+),[ \t]*"(.*)"[ \t]*$/) { michael@0: &code($2, $3); michael@0: } michael@0: elsif ($skipone && /^[ \t]*"(.*)"[ \t]*$/) { michael@0: &code($macro, $1); michael@0: } michael@0: } michael@0: michael@0: print H "\n"; michael@0: print H "extern void ", $table_name, "_InitializePRErrorTable","(void);\n"; michael@0: printf H "#define ERROR_TABLE_BASE_%s (%dL)\n", $table_name, $table_base; michael@0: michael@0: print C "\t{0, 0}\n"; michael@0: print C "};\n\n"; michael@0: printf C "static const struct PRErrorTable et = { text, \"%s\", %dL, %d };\n", michael@0: $base, $table_base, $table_item_count; michael@0: print C "\n"; michael@0: print C "void ", $table_name, "_InitializePRErrorTable", "(void) {\n"; michael@0: print C " PR_ErrorInstallTable(&et);\n"; michael@0: print C "}\n"; michael@0: michael@0: 0;