/* DEF2CSV (SCM) -- Create Symbol Selection Database from .def Files */ /* DEF2CSV (SCM) -- Aus logischen Definitionen Symboldatenbank erzeugen */ /* // Copyright (c) 2005-2012 Oliver Bartels F+E, Muenchen // Author: Roman Ludwig // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (091020) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // rl (080625) ENHANCEMENT: // Added $gp gate mapping options. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (060613) ENHANCEMENT: // Added optional alternate part list split option. // rl (051015) ORIGINAL CODING. // // DESCRIPTION // // The def2csv User Language program scans the logical definition files // in a selectable folder and creates .csv and .map files suitable to create // a symbol selection database with the symattdb and symmapdb User Language // programs. The library name for a symbol is derived from the definition // file name, so def2csv is only suitable for definition files with the same // base name as the symbol library for the therein defined symbols. */ // Includes #include "pop.ulh" // User Language popup utilities // Enforce SCM caller type #pragma ULCALLERSCM // Disable undo state request #pragma ULCALLERNOUNDO // Messages string UPRABORT = M_UPRABORT(); string UPRPEXIT = M_UPRPEXIT(); string REPDONE = M("Es wurden keine Fehler festgestellt.", "Operation completed without errors."); string REPHEADSKIP = M("Ungueltige ignorierte Eintraege:", "Invalid Entries ignored:"); string REPREADINP = M("Lesen Eingabe-Datei (%s/%s)...", "Reading Input file (%s/%s)..."); string WRNNOLIBSYM = M("Symbol zu Definition '%s' nicht in Bibliothek '%s'!", "Symbol for Definition '%s' not in library '%s'!"); string UPRSDIR = M("Definitionsverzeichnis ? ", "Definition File Directory ? "); string UPRSELMODE = M("Gatterbearbeitungsmodus selektieren!", "Select Gate Process Mode!"); string UPRMODE1 = M("&Kein $gp","&No $gp"); string UPRMODE2 = M("$gp fuer &Einzelpingatter", "$gp for &single pin gates"); string UPRMODE3 = M("$gp fuer alle &Gatter","$gp for all &gates"); string UPRMODE4 = M("$gp wenn &Attributtext","$gp if &attribute text"); // INI file parameter name definitions #define PAR_SYMMAPPATH "SYMMAPPATH_SCM"// Symbol mapping default directory #define PAR_SMAPEXT "SYMMAPEXT_SCM" // Symbol mapping file ext. #define PAR_MAPLIB "MAPLIB_SCM" // Mapping library name #define PAR_SSELEXT "SSELEXT_SCM" // Input file extension #define PAR_CSVSYMTAB "CSVSYMTAB_SCM" // Symbol table column list #define PAR_CSVSPLITPL "CSVSPLITPL_SCM"// $plname split mode #define PAR_CSVMAINP "CSVMAINP_SCM" // mainpart output mode #define PAR_SYMIDBASE "SYMIDBASE_SCM" // Symbol ID base // Database structure definitions string DEFSTARTDIR = bae_inistrval(PAR_SYMMAPPATH,"") /* Default mapping root path */; string MAPEXT = bae_inistrval(PAR_SMAPEXT,".map") /* Mapping output file name ext. */; string MAPLIB = bae_inistrval(PAR_MAPLIB,"mehrfach") /* Mapping library name */; string CSVEXT = bae_inistrval(PAR_SSELEXT,".csv") /* Definition output file name ext. */; int SPLITPL = bae_iniintval(PAR_CSVSPLITPL,0) /* $plname split mode */; int MAINONLY = bae_iniintval(PAR_CSVMAINP,0) /* mainpart output only */; int SYMID = bae_iniintval(PAR_SYMIDBASE,1) /* Symbol ID base */; struct tabdesc { // Symbol table column descriptor string name /* Column name */; string src /* Primary data source */; string src2 /* Secondary data source */; }; struct tabdesc deftabl[] = { // Default table column list { M("Symbol","Symbol"), "SYMBOL", "" }, { M("Kommentar","Comment"),M("$commentge","$comment"),M("$comment","")}, { M("Gehaeuse","Package"), "FOOTPRINT", "" }, { M("Hersteller","Manufacturer"), "$manufacturer", "" }, { M("Bibliothek","Library"), "LIBRARY", "" } }; struct tabdesc tabl[] /* Table column list */; int tabn /* Table column list element count */; int procmode /* Process mode */; string deffname /* Definition file name string */; string libfname /* Library file name string */; string libname /* Library name string */; int mainflag /* Main part flag */; int subflag /* Sub part flag */; string attrnl[] /* Part attribute name list */; string attrvl[] /* Part attribute value list */; int attrn /* Part attribute count */; string curcomment /* Current comment */; string curpcomment /* Current part comment */; string curpname /* Current part name */; string curplname /* Current physical library name */; string curstr /* Current string */; string curname /* Current name */; string curpiece /* Current name piece */; string currngstart /* Current name range start */; string currngend /* Current name range end */; int currngstep /* Current name range step */; int curpinstate = (-1) /* Current pin process status */; string gpl[] /* $gp gate pin name list */; int gatecnt /* Current gate count */; int pincnt /* Current pin count */; int pinidx /* Current pin index */; int xlatidx /* Current xlat index */; int gpfound /* $gp text found flag */; int mfh /* Mapping file handle */; int cfh /* Selection data file handle */; STRINGS hl /* Report list */; int hn = 0 /* Report count */; STRINGS msgl /* Message list */; int msgn = 0 /* Message count */; // Main program void main() { string fname /* File name */; string startdir /* Start directory */; int len /* String length */; // Get the attribute list for (tabn=0;tabn<1000;tabn++) { if ((tabl[tabn].name=bae_inistrval( bae_inifieldvarname(PAR_CSVSYMTAB,tabn,0),""))=="") { // Check if list defined at all if (tabn==0) { // Use default attribute list tabl=deftabl; tabn=arylength(tabl); } break; } tabl[tabn].src= bae_inistrval(bae_inifieldvarname(PAR_CSVSYMTAB,tabn,1),""); tabl[tabn].src2= bae_inistrval(bae_inifieldvarname(PAR_CSVSYMTAB,tabn,2),""); } // Select source directory if (DEFSTARTDIR!="") { startdir=DEFSTARTDIR; } else { // Select source directory startdir=UINPOPABORT; if (bae_askdirname(startdir,getcwd(),UPRSDIR)!=0 || startdir==UINPOPABORT) error_abort(); } len=strlen(startdir)-1; if (startdir[len]=='/' || startdir[len]=='\\') startdir[len]='\0'; // Select process mode bae_promptdialog(UPRSELMODE); if ((procmode=bae_askmenu(5,UPRMODE1,UPRMODE2, UPRMODE3,UPRMODE4,UPRABORT))<0 || procmode>3) error_abort(); // Scan the directory fname=""; while (scandirfnames(startdir,".def",fname)==1) procfile(startdir+bae_swversion(4)+fname); // Test if any errors occurred if (msgn) { // Error(s) occurred hl[hn++]=REPHEADSKIP; hl[hn++]=""; // Display messages with popup menu bae_setintpar(16,3070); popupmenu(0,"",hl,hn,msgl,msgn, UINPOPABORT,0,-1,-1,hn+msgn+2,100,0,""); // Abort return; } bae_prtdialog(REPDONE); } void procfile(string fname) /* // Scan file for mapping definitions // Parameter : // string fname : Scan file name */ { int i /* Loop control variable */; deffname=fname; libname=convstring(fname,2); libfname=convstring(fname,0)+DDBEXT; // Create mapping file mfh=bae_fopen(convstring(fname,0)+MAPEXT,1); // Create selection data file cfh=bae_fopen(convstring(fname,0)+CSVEXT,1); for (i=0;i1 && (procmode==2 || (procmode==1 && pincnt==1) || (procmode==3 && symgpchk(libfname,curpname)))) { for (i=0;i1 || mainflag) { if (procmode==2 || (procmode==1 && pincnt==1) || (procmode==3 && symgpchk(libfname,curpname))) { for (i=0;i=sidx;eidx--) if (comment[eidx]!=' ' && comment[eidx]!='\t') break; curcomment=curpcomment=strextract(comment,sidx,eidx); // Return without errors return(0); } int p_attrname() /* // Receive an attribute name // Return value : // zero if done, or nonzero on error */ { // Store the current attribute name attrnl[attrn]=synscanstring(); // Return without errors return(0); } int p_attrval() /* // Receive an attribute value // Return value : // zero if done, or nonzero on error */ { // Store the current attribute value attrvl[attrn]=synscanstring(); attrn++; // Return without errors return(0); } int p_pinattr() /* // Receive a pin attribute list end // Return value : // zero if done, or nonzero on error */ { // Dismiss pin attributes attrn--; // Return without errors return(0); } int p_pname() /* // Receive a part name // Return value : // zero if done, or nonzero on error */ { string msg /* Message buffer */; // Store the part name curpname=curstr; gatecnt=0; mainflag=subflag=0; curplname=""; sprintf(msg,REPREADINP,deffname,curpname); bae_prtdialog(msg); curpinstate=(-1); // Return without errors return(0); } int p_plname() /* // Receive a physical library name // Return value : // zero if done, or nonzero on error */ { // Store the physical library name if (curplname=="") curplname=curstr; else if (curplname[0]=='[') curplname+=","+curstr; else curplname="["+curplname+","+curstr; // Return without errors return(0); } int p_namepiece() /* // Receive a name piece // Return value : // zero if done, or nonzero on error */ { // Abort program on request if (kbhit()) { getchr(); if (verify(UPRPEXIT,0)) error_abort(); } // Store the current scan string curpiece=synscanstring(); // Return without errors return(0); } int p_namepcpoint() /* // Receive a dot name piece // Return value : // zero if done, or nonzero on error */ { curpiece="."; // Return without errors return(0); } int p_namepcslash() /* // Receive a slash name piece // Return value : // zero if done, or nonzero on error */ { curpiece="/"; // Return without errors return(0); } int p_namepcfirst() /* // Receive a first name piece // Return value : // zero if done, or nonzero on error */ { // Abort program on request if (kbhit()) { getchr(); if (verify(UPRPEXIT,0)) error_abort(); } curname=curpiece; // Return without errors return(0); } int p_namepcnext() /* // Receive next name piece // Return value : // zero if done, or nonzero on error */ { // Abort program on request if (kbhit()) { getchr(); if (verify(UPRPEXIT,0)) error_abort(); } curname=curname+curpiece; // Return without errors return(0); } int p_rangestart() /* // Receive a name range start // Return value : // zero if done, or nonzero on error */ { // Store the current scan string currngstart=synscanstring(); currngstep=1; // Return without errors return(0); } int p_rangeend() /* // Receive a name range end // Return value : // zero if done, or nonzero on error */ { // Store the current scan string currngend=synscanstring(); // Return without errors return(0); } int p_rangestep() /* // Receive a name range step // Return value : // zero if done, or nonzero on error */ { // Store the current scan string currngstep=atoi(synscanstring()); // Return without errors return(0); } int p_pinrangeend() /* // Receive a name range definition end // Return value : // zero if done, or nonzero on error */ { // Return without errors return(0); } int p_ident() /* // Receive an identifier // Return value : // zero if done, or nonzero on error */ { // Abort program on request if (kbhit()) { getchr(); if (verify(UPRPEXIT,0)) error_abort(); } // Store the current scan string curstr=synscanstring(); // Return without errors return(0); } void outentry(string slibname,string plname,int plattr) /* // Handle the part store request // Parameters : // string slibname : Symbol library name // string plname : Physical library name // int plattr : Physical library name attribut ext. flag */ { string entry /* Table entry */; string src /* Table entry source */; int i, j /* Loop control variables */; for (i=0;i