/* XML.ULH (STD) -- User Language XML Utilities */ /* XML.ULH (STD) -- User Language XML-Utilities */ /* // Copyright (c) 2013 Bartels System GmbH, Muenchen // Author: Roman Ludwig // Changes History: // rl (131029) RELEASED FOR BAE V8.0. // rl (130814) ORIGINAL CODING. // // DESCRIPTION // // The definitions and declarations from include file xml.ulh are // compatible with all User Language interpreter environments of // the Bartels AutoEngineer (i.e. Schematic Editor, Layout Editor, // Autoplacement, Neural Autorouter, CAM Processor, CAM View, and // Chip Editor, respectively). xml.ulh provides a series of useful // XML (Extendable Markup Language) file import/export functions. // // FUNCTIONS // // XML File handling: // xml_open -- Open XMl data file // xml_close -- Close XMl data file // // XML Export: // xmlw_attrib -- Write attribute definition // xmlw_attribdim -- Write dimension value attribute definition // xmlw_attribint -- Write integer value attribute definition // xmlw_data -- Write data // xmlw_cdata -- Write CDATA entry // xmlw_publicdoctype -- Write public DOCTYPE definition // xmlw_element -- Write full closed element string // xmlw_elementstart -- Write element start // xmlw_elementend -- Write element end // xmlw_elementtag -- Write element tag start // xmlw_tagclose -- Write tag close // xmlw_emptyelementend -- Write empty element end // xmlw_pistart -- Write processing instruction start // xmlw_piend -- Write processing instruction end // xmlw_comment -- Write comment string // // XML Import: // // XML Data conversion: // xml_setconv -- Set XML coordinate conversion factor // xml_dim -- Build dimension value string */ // Avoid multiple inclusion #ifndef INCLUDE_XML #define INCLUDE_XML // Includes #include "std.ulh" // User Language standard utilities // XML public definitions type names //__________________________________________________________________ // Start library-specific source code #ifndef USELIB #ifndef LIBXML // Globals static int xmlfh = (-1); // XML file handle static int xmlfname = ""; // XML file name static int xmlmode; // XML file access mode static STRINGS xmltagl; // XML element tag stack static int xmltagn = 0; // XML element tag stack count static double xmlconv = cvtlength(1.0,0,2); // XML dimension conversion static int xmlprec = 3; // XML output precision //__________________________________________________________________ // XML File handling void xml_open(string fname,int mode) /* // Open XML file // Parameters : // string fname : XML file name // int mode : File access mode, 0: read, 1: write */ { string msg; // Message buffer // Check if multiple files open if (xmlfh!=(-1)) { sprintf(msg, M("Nur eine offene XML-Datei erlaubt '%s'/'%s'!", "Only one XML file may be opened at a time '%s'/'%s'!"), xmlfname,fname); error(msg); } // Open file fseterrmode(1); xmlfh=fopen(fname,mode); // Store file data xmlfname=fname; xmlmode=mode; xmltagn=0; // Check if XML file creation if (xmlmode) { // Write prolog xmlw_pistart("xml"); xmlw_attrib("version","1.0"); xmlw_attrib("encoding","ISO-8859-1"); xmlw_piend(); } } void xml_close() /* // Close current XML file */ { // Check if file opened if (xmlfh==(-1)) error(M("Es ist keine XML-Datei geoeffnet!", "No open XML file!")); // Close file fclose(xmlfh); // Clear file data xmlfh=(-1); xmlfname=""; } //__________________________________________________________________ // XML Export utility functions void xmlw_publicdoctype(string typ,string pubid,string sysid) /* // Write document type definition to current XML file // Parameters : // string type : Document type string // string pubid : Public ID tring // string sysid : System ID tring */ { fprintf(xmlfh,"\n",typ,pubid,sysid); } void xmlw_data(string data) /* // Write data to current XML file // Parameters : // string data : Data string */ { fprintf(xmlfh,"%s",data); } void xmlw_cdata(string data) /* // Write data as CDATA entry to current XML file // Parameters : // string data : Data string */ { fprintf(xmlfh,"",data); } void xmlw_attrib(string name,string val) /* // Write attribute definition to current XML file // Parameters : // string name : Attribute name string // string val : Attribute value string */ { fprintf(xmlfh," %s=\"%s\"",name,val); } void xmlw_attribdim(string name,double val) /* // Write dimension value attribute definition to current XML file // Parameters : // string name : Attribute name string // double val : Attribute value */ { fprintf(xmlfh," %s=\"%s\"",name,xml_dim(val)); } void xmlw_attribint(string name,int val) /* // Write integer value attribute definition to current XML file // Parameters : // string name : Attribute name string // int val : Attribute value */ { fprintf(xmlfh," %s=\"%d\"",name,val); } void xmlw_element(string name,string data,int newline) /* // Write tagged entry string to current XML file // Parameters : // string name : Name string // string data : Data string // int newline : Newline flag */ { fprintf(xmlfh,"<%s>%s",name,data,name); if (newline) fprintf(xmlfh,"\n"); } void xmlw_elementstart(string name) /* // Write element open tag to current XML file // Parameter : // string name : Entry name string */ { fprintf(xmlfh,"<%s>\n",name); xmltagl[xmltagn]=name; xmltagn++; } void xmlw_elementtag(string name) /* // Write element open tag start to current XML file // Parameter : // string name : Entry name string */ { fprintf(xmlfh,"<%s",name); xmltagl[xmltagn]=name; xmltagn++; } void xmlw_tagclose(string name) /* // Write element tag close to current XML file // Parameter : // string name : Entry name string */ { string msg; // Message buffer if (name!=xmltagl[xmltagn-1]) { sprintf(msg, M("Ungueltige Verschachtelung '%s'/'%s'!", "Invalid nesting '%s'/'%s'!"),name,xmltagl[xmltagn]); error(msg); } fprintf(xmlfh,">\n"); } void xmlw_elementend(string name) /* // Write element end tag to current XML file // Parameter : // string name : Entry name string */ { string msg; // Message buffer xmltagn--; if (name!=xmltagl[xmltagn]) { sprintf(msg, M("Ungueltige Verschachtelung '%s'/'%s'!", "Invalid nesting '%s'/'%s'!"),name,xmltagl[xmltagn]); error(msg); } fprintf(xmlfh,"\n",xmltagl[xmltagn]); } void xmlw_emptyelementend(string name) /* // Write empty element end tag to current XML file // Parameter : // string name : Entry name string */ { string msg; // Message buffer xmltagn--; if (name!=xmltagl[xmltagn]) { sprintf(msg, M("Ungueltige Verschachtelung '%s'/'%s'!", "Invalid nesting '%s'/'%s'!"),name,xmltagl[xmltagn]); error(msg); } fprintf(xmlfh," />\n"); } void xmlw_pistart(string target) /* // Write processing instruction start to current XML file // Parameter : // string target : Target name string */ { fprintf(xmlfh,"\n"); } void xmlw_comment(string comment,int newline) /* // Write string to current XML file // Parameters : // string comment : Comment string // int newline : Newline flag */ { fprintf(xmlfh,"",comment); if (newline) fprintf(xmlfh,"\n"); } //__________________________________________________________________ // XML Import utility functions //__________________________________________________________________ // XML Data conversion functions void xml_setconv(double convfac) /* // Set XML output dimension conversion factor // Parameters : // double convfac : Conversion factor */ { xmlconv=convfac; } string xml_dim(double val) /* // Get string representation of dimension value // Returns: // dimension string // Parameters : // double val : Dimension value // string val : Attribute value string */ { return(bae_numstring(val*xmlconv,xmlprec)); } //__________________________________________________________________ // End library-specific source code #endif // LIBXML #endif // USELIB // Conditional file inclusion end #endif // INCLUDE_XML // User Language include file end