//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// /* * * errorGen.as * * "errorGen" is an AS3 script which reads an * XML file containing all (localized) compiler * error messages and creates .cpp, .h and * .java files which describe the same data. * * Chris Nuuja * Jan 20, 2004 * */ import avmplus.* const CONFIG_FILE:String = "errorConfig.xml"; const SCRIPT_NAME:String = "errorGen"; var config:XML = XML(File.read(CONFIG_FILE)); var IFDEF:String = String(config.Ifdef); var XML_INPUT_BASE:String = String(config.InputFileBase); var XML_INPUT_FILE:String = String(config.XmlInputFile); var OUTPUT_CPP_FILE:String = String(config.OutputCppFile); var OUTPUT_JAVA_FILE:String = String(config.OutputJavaFile); var OUTPUT_H_FILE:String = String(config.OutputHFile); var ARRAY_NAME:String = String(config.ArrayName); var LANG_COUNT_NAME:String = String(config.LangCountName); var COUNT_NAME:String = String(config.CountName); var STRUCT_NAME:String = String(config.NamespaceName); var MAIN_INCLUDE:String = String(config.MainInclude); class LocalizedLanguage // one of these per localzed .xml file { public var language:String; // language name public var sourceXML:XML; // original .xml file public var messages:Array; // array of ErrorMessages, indexed by the ErrorMessage's id. } class ErrorMessage // one of these per message in the an .xml file { public var id:Number; public var label:String; public var message:String; public var language:String; } var localizedMessages:Object = new Object(); // holds all LocalizedLanguages, indexed by the LocalizedLanguage's language (i.e. localizedMessages["EN"] for english) var languageNames:Array = []; // holds all language names, indexed from 0 to numLanguages-1 var numLanguages:int; var numErrors:int; // The number of ErrorMessages in the master "EN" LocalizedLanguage var maxStringLength:int=0; // maximum length of any error string. Used when generating padding white space for pretty output function compare(a:Object, b:Object):Number { if (a.id < b.id) { return -1; } else if (a.id > b.id) { return 1; } else { return 0; } } for each ( var language:XML in config..Language ) { var languageRec:LocalizedLanguage = new LocalizedLanguage(); var languageName:String = String(language); languageRec.language = languageName; languageRec.sourceXML = XML(File.read(XML_INPUT_BASE + language + XML_INPUT_FILE)); languageRec.messages = []; for each (var error:XML in (languageRec.sourceXML)..error) { // Remove IMD's elements delete error.description; if (error.@removed == true) continue; var message:ErrorMessage = new ErrorMessage(); //print("About to dump id: " + error.@id + " = " + error); message.id = Number(error.@id); message.language= languageName; message.label = String(error.@label); message.message = String(error); languageRec.messages[message.id] = message; maxStringLength = Math.max(maxStringLength, message.label.length); // english is the reference language if (languageName == "EN") numErrors++; } //languageRec.messages = languageRec.messages.sort(compare); languageNames.push(languageName); localizedMessages[languageName] = languageRec; } numLanguages = languageNames.length; var s:String; s = "\ /*\n\ *\n\ * THIS FILE IS AUTO-GENERATED. DO NOT EDIT THIS FILE.\n\ * Use the script '" + SCRIPT_NAME + "' to generate this file.\n\ */\n\ \n\ /*\n\ *\n\ * Licensed to the Apache Software Foundation (ASF) under one or more\n\ * contributor license agreements. See the NOTICE file distributed with\n\ * this work for additional information regarding copyright ownership.\n\ * The ASF licenses this file to You under the Apache License, Version 2.0\n\ * (the \"License\"); you may not use this file except in compliance with\n\ * the License. You may obtain a copy of the License at\n\ *\n\ * http://www.apache.org/licenses/LICENSE-2.0\n\ *\n\ * Unless required by applicable law or agreed to in writing, software\n\ * distributed under the License is distributed on an \"AS IS\" BASIS,\n\ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\ * See the License for the specific language governing permissions and\n\ * limitations under the License.\n\ *\n\ \n\ /* \n\ * ErrorConstants.java defines the ID's of error messages output\n\ * by the compiler. Localized tables of strings exist for\n\ * each language supported. These ids are used to reference \n\ * the error message without regard to language \n\ */\n\ \n"; s += "package macromedia.asc.embedding;\n"; s += "public interface ErrorConstants\n"; s += "{\n"; s += " static final int " + LANG_COUNT_NAME + " = " + numLanguages + ";\n"; s += " static final int " + COUNT_NAME + " = " + numErrors + ";\n"; s += "\n"; s += "\n"; for each (var w:ErrorMessage in localizedMessages["EN"].messages) { s += " public static final int " + w.label + " = " + w.id + ";\n"; } s += " \n"; s += " public class AscError\n"; s += " {\n"; s += " public int code; // enum used to identify or lookup this message/problem\n"; s += " public String errorMsg; // a particular error message '\n"; s += " public AscError(int c, String s) { code = c; errorMsg = s; }\n"; s += " } ;\n"; s += " \n"; var englishMessages:Array = localizedMessages["EN"].messages; for ( i=0; i < languageNames.length; i++ ) { var thisLang:String = languageNames[i]; var messages:Array = localizedMessages[thisLang].messages; s += " public static final AscError[] errorConstants" + thisLang + " = { \n"; if (thisLang == "EN") { for (var j:int = 0; j