/* PLANSORT (SCM) -- SCM Sheet Sort */ /* PLANSORT (SCM) -- SCM-Plan sortieren/nummerieren */ /* // Copyright (c) 1993-2012 Oliver Bartels F+E, Muenchen // Author: Manfred Baumeister // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (091021) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (050906) RELEASED FOR BAE V6.6. // rl (040811) RELEASED FOR BAE V6.4. // rl (030904) RELEASED FOR BAE V6.2. // rl (021209) RELEASED FOR BAE V6.0. // rl (020618) RELEASED FOR BAE V5.4. // rl (010626) RELEASED FOR BAE V5.0. // rl (000509) RELEASED FOR BAE V4.6. // rl (990625) RELEASED FOR BAE V4.4. // rl (980910) RELEASED FOR BAE V4.2. // mb (980711) ENHANCEMENT: // Dynamic multi-language support introduced. // rl (970929) RELEASED FOR BAE V4.0. // mb (960919) RELEASED FOR BAE V3.4. // mb (95) RELEASED FOR BAE V3.2. // mb (94) RELEASED FOR BAE V3.0. // mb (93) RELEASED FOR BAE V2.6. // mb (93) ORIGINAL CODING. // // DESCRIPTION // // The plansort User Language program performs an automatic SCM // sheet name numbering for selectable DDB files of the current // directory. */ // Includes #include "pop.ulh" // User Language popup utilities #include "scm.ulh" // User Language SCM utilities // Enforce SCM caller type #pragma ULCALLERSCM // Disable undo state request #pragma ULCALLERNOUNDO // Messages string REPDDBDONE = M("Job-Datei aktualisiert.","Job file updated."); string REPDONE = M("Es wurden keine Fehler festgestellt.", "No error occurred."); string REPSORTED = M("Plaene sind bereits sortiert!", "Sheets are sorted already!"); string REPSORTH = M("DDB-Datei '%s' - SCM Plaene:\n\n", "DDB File '%s' - SCM Sheets\n\n"); string REPRPLH = M("Umsetzung regulaerer Plan-Namen (Prefix '%s'): %s\n\n", "Regular sheet name translation (prefix '%s'): %s\n\n"); string REPIPLH = M("\nIrregulaere Plan-Namen (keine Aenderung): %s\n\n", "\nIrregular sheet names (no change): %s\n\n"); string UPRSELFILE = M("SCM-Jobdatei ? ","SCM Job File ? "); string UPRDDBUPD = M("DDB-Datei aktualisieren ? ", "Update Job File ? "); string UPRALLSORT = M("Alle Plaene sortieren ? ", "Sort All Sheet Names ? "); string UPRPNPREFIX = M("Prefix fuer regulaere Plan-Namen ? ", "Regular Sheet Name Prefix ? "); string ERRLDFAULT = M("Fehler beim Laden des Planes!", "Error loading sheet!"); string ERRCPFAULT = M("Fehler beim Kopieren des Planes!", "Error copying sheet!"); string ERRMULPLAN = M("Mehrfach definierter Plan (interner Fehler)!", "Multiple defined sheet (internal error)!"); string ERRDELSCM = M("Fehler beim Loeschen von SCM-Plan '%s' aus DDB-Datei!", "Error deleting SCM sheet '%s' from DDB file!"); #define REPRPLF "\t'%s'\t-> '%s%s'\n" #define REPIPLF "\t'%s'\n" // Globals int ALLSORT = 0 /* All plan sheet sort flag */; string PNPREFIX = "" /* Regular sheet name prefix */; struct plandes { // Plan descriptor int planno /* Plan number */; int change /* Change stage */; string sn /* Source name */; } rplanl[] /* Regular plan list */; int rplann /* Regular plan count */; STRINGS iplanl /* Irregular plan list */; int iplann /* Irregular plan count */; // Main program void main() { string fname /* Current DDB file name */; string ename /* Current element name */; // Abort if not in Schematic Editor if (!(uliptype() & ULIPSCM)) error_class(); // Save current element with verification on request verifysave(); // Repetively ask for DDB file name while ((fname=askddbfile(UPRSELFILE,DDBCLSCM))) { // Init the text screen bae_inittextscreen(); // Print the plan sort list header printf(REPSORTH,fname); // Print the plan list ename=""; while (scanddbenames(fname,DDBCLSCM,ename)==1) printf(REPIPLF,ename); // Init the plan name prefix PNPREFIX=""; // Ask if all plan sort is required if (!(ALLSORT=verify(UPRALLSORT,1))) { // Ask for regular plan name prefix PNPREFIX= bae_readedittext(UPRPNPREFIX,PNPREFIX,MAXKEYLEN); strdelchr(PNPREFIX," ",1,MAXPNLEN); // Check if abort request if (PNPREFIX==UINPOPABORT) error_abort(); } // Get the DDB file definitions plansort(fname); // DDB file prompt bae_inittextscreen(); } // Print the global done message bae_prtdialog(REPDONE); } // Data retrieval and plan manipulation routines void plansort(string fn) /* // Build the plan list // Parameters : // string fn : File name */ { int idx,insidx /* Search inidices */; int fchg,lchg /* First and last change index */; int plansort /* Plan sort stage count */; string ename = "" /* Element name */; int i,j /* Loop control variables */; // Init the plan count rplann=iplann=0; // Build the plan list while (scanddbenames(fn,DDBCLSCM,ename)==1) // Create a new plan list entry create_plan(ename); // Init the sort range fchg=rplann; lchg=(-1); // Update the change flag for (i=0;ilchg) lchg=i; } } // Init the plan sort stage count plansort=0; // Loop thru the changeable plan list for (i=fchg;i<=lchg;i++) { // Check if plan not yet sorted if (rplanl[i].change<0) { // Init the plan change stage rplanl[i].change=1; // Check if plan can be sorted now if ((idx=find_plan(i+1,insidx))>=0 && idx!=i) { // Update the plan change stage if (rplanl[idx].change>=0) rplanl[i].change=rplanl[idx].change+1; else rplanl[i].change=(-1); } } // Check if plan is sorted now if (rplanl[i].change>=0) { // Update the plan sort stage count if (rplanl[i].change>plansort) plansort=rplanl[i].change; // Update the sort range if (i==fchg) fchg++; if (i==lchg) lchg--; } // Rewind to first change if at last change if (i>=lchg) i=fchg-1; } // Init the text screen bae_inittextscreen(); // Print the plan sort list header printf(REPSORTH,fn); // Print the regular plan name change list printf(REPRPLH,PNPREFIX,rplann>0?"":"---"); for (i=0;i0?"":"---"); for (i=0;i0)) { // Abort bae_msgbox(0,REPSORTED,""); return; } // Verify if plans should be updated if (!verify(UPRDDBUPD,1)) return; // Loop thru all plan sort stages for (j=1;j<=plansort;j++) { // Re-sort the plans for (i=0;i=0) // Error; multiple defined plan error(ERRMULPLAN); // Insert the new plan entry to the plan list iplann++; for (i=iplann-2;i>=idx;i--) iplanl[i+1]=iplanl[i]; iplanl[idx]=pn; return; } // Try to find the plan if (find_plan(planno,idx)>=0) // Error; multiple defined plan error(ERRMULPLAN); // Insert the new plan entry to the plan list rplann++; for (i=rplann-2;i>=idx;i--) rplanl[i+1]=rplanl[i]; rplanl[idx].sn=pn; rplanl[idx].planno=planno; rplanl[idx].change=0; } int find_plan(int planno,int insidx=(-1)) /* // Binary search a plan name in the regular plan name list // Return value: // plan name list index, or (-1) if not found // Parameters : // int planno : Plan number // int insidx : Insert index */ { int slb = 0 /* Search lower boundary */; int sub = rplann-1 /* Search upper boundary */; int idx /* Search index */; int compres /* Compare result */; // Loop until search area empty while (slb<=sub) { // Get the search index idx=(slb+sub)>>1; // Get and test the compare result if ((compres=planno-rplanl[idx].planno)==0) // Plan found return(idx); // Update the search area if (compres<0) sub=idx-1; else slb=idx+1; } // Set the insert index insidx=slb; // Return the not found code return(-1); } int find_iplan(string pn,int insidx) /* // Binary search a plan name in the irregular plan name list // Return value: // plan name list index, or (-1) if not found // Parameters : // string pn : Plan name // int insidx : Insert index */ { int slb = 0 /* Search lower boundary */; int sub = iplann-1 /* Search upper boundary */; int idx /* Search index */; int compres /* Compare result */; // Init the insert index insidx=(-1); // Loop until search area empty while (slb<=sub) { // Get the search index idx=(slb+sub)>>1; // Get and test the compare result if ((compres=numstrcmp(pn,iplanl[idx]))==0) // Plan found return(idx); // Update the search area if (compres<0) sub=idx-1; else slb=idx+1; } // Set the insert index insidx=slb; // Return the not found code return(-1); } // Data conversion routines int regplanname(string pn,string prefix,int planno) /* // Test if regular plan name // Return value: // nonzero if plan name regular, or zero else // Parameters : // string pn : Plan name // string prefix : Regular plan name prefix // int planno : Resulting plan number */ { int pl = strlen(prefix)/* Prefix length */; string pnb /* Plan name buffer */; // Check if regular name match if (pl>0 && !strmatch(pn,prefix+"*")) { // Not a regular plan name planno=0; return(0); } // Store prefix-less plan name to plan name buffer pnb=(pl==0)?pn:strextract(pn,pl,strlen(pn)); // Test if regular plan name, get plan number, return result return(itoa(planno=atoi(pnb))==pnb && planno>0); } // User Language program end