/* ** Concordance Programming Language ** ** Copyright (c) 1995 - 1998 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Bel Air, CA 90077 ** http://www.dataflight.com ** ** Unauthorized distribution, adaptation or use may be ** subject to civil and criminal penalties. ** ** You may incorporate this program into your own programs ** ONLY if you incorporate the following copyright notice: ** ** ZEROFILL.CPL ** ** This program zero-pads the numeric section of production numbers ** for the user-specified field. Bates alpha prefixes are ignored. ** E.g., if a user specified a width of 9, ABC01 would be converted to ** ABC000001. ** ** CAUTION: This utility overwrites existing data in place. Please make ** a backup of your database prior to use. ** */ main() { int next, done, db, nWidth, nBatesField; text mymenu[5], menustring1, menustring2; /* Clear the screen */ Pcls("", TRUE); /* Return if no open database */ if (db.documents <= 0) return(Message("No documents in database. ", TRUE)); /* Setup the menu */ menustring1 = "[S] Select bates field : "; menustring2 = "[E] Enter bates width : "; mymenu[0] = "ZEROFILL.CPL"; mymenu[1] = menustring1; mymenu[2] = menustring2; mymenu[3] = "[G] Go!"; mymenu[4] = "[Q] Quit"; /* Keep displaying the menu until user quits */ while (done == FALSE) { /* Display the menu */ next = menu(5, 10, 12, 70, mymenu, next,"SEGQ"); /* Get the menu item */ switch(next) { /* Get bates field */ case 1: nBatesField = GetField(db, nBatesField); if (nBatesField > 0) { mymenu[1] = menustring1 + db.name[nBatesField]; next = 2; } else { mymenu[1] = menustring1; next = 1; } break; /* Get bates width */ case 2: nWidth = getNumber(nWidth, 8, 36, 20); mymenu[2] = menustring2 + str(nWidth); next = 3; break; /* Go */ case 3: BatesPad(db, nBatesField, nWidth); Pcls("", TRUE); break; /* Quit */ case 4: done = TRUE; break; } } } /**************************************************************** * Name: BatesPad * * Synopsis: Pad bates number to desired width * ****************************************************************/ BatesPad(int db, nBatesField, nWidth) { char szBates[256]; text pszPrefix, pszBates; int nNumeric, i; /* Make sure we have all info */ if (nBatesField <= 0) return(Message("Please enter a bates field. ", TRUE)); if (nWidth <= 0) return(Message("Width must be greater than 0. ", TRUE)); /* Place a message box */ Message("", FALSE); /* Cycle through the current query */ cycle(db) { /* Put up a status message */ puts( 8, 14, pad("Processing record " + str(docno(db)), 'C', 55 ), RGB(255,255,255), RGB(0,0,255)); /* Get the bates number */ szBates = db->nBatesField; /* Parse the alpha */ i = 0; while(isalpha(szBates[i])) i = i + 1; pszPrefix = substr(szBates, 1, i); nNumeric = num(substr(szBates, i+1)); /* Reconstruct the bates */ pszBates = pszPrefix + str(nNumeric, nWidth - len(pszPrefix), 0, 'Z'); /* Write to database */ db->nBatesField = pszBates; } } /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[101]; text screen; if (db.documents >= 0) { field[0] = "Field Type "; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : field[i] = pad(db.name[i],'L',13)+ "Text "; case 'P' : field[i] = pad(db.name[i],'L',13)+ "Paragraph"; case 'N' : field[i] = pad(db.name[i],'L',13)+ "Numeric "; case 'D' : field[i] = pad(db.name[i],'L',13)+ "Date "; } i = db.fields + 1; screen = save(11,30,21,57); while(i > db.fields) i = menu(11, 30, 21, 57, field, next,""); restore(11,30,screen); if (i) next = i; } return(next); } /* GetField() */ /**************************************************************** * Name: RGB * * Synopsis: Helper routine for Windows color creation. * ****************************************************************/ RGB(int red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); } /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message( text message; int wait ) { text screen; int key; cursoroff(); screen = save( 5, 13, 10, 69 ); box( 7, 13, 9, 69, "3U", RGB(0,0,150), RGB(0,0,255) ); puts( 8, 14, pad( message, 'C', 55 ), RGB(255,255,255), RGB(0,0,255)); if( wait ) { key = getkey(); restore( 5, 13, screen ); } if( islower( key )) key = key - ( 'a' - 'A' ); return( key ); } /* Message() */ /**************************************************************** * Name: Pcls * * Synopsis: Clears the screen to the pattern parameter. * * isWindows = TRUE if operating in Windows * * change the cls(RGB(170,0,170)) to desired RGB * ****************************************************************/ Pcls(text pattern; int isWindows) { int i; int oldBackground; if (isWindows) cls(RGB(170,0,170)); else { for(i = 0; i <= MaxRow_; i = i + 1) puts(i,0,pattern); } } /* Pcls() */ /*****************************************************/ /* Function: getNumber */ /* Purpose : Return the number at row, col, width */ /*****************************************************/ getNumber(int thenumber, row, col, width) { char key; while ((key <> CR) and (key <> ESC)) key = getnumber(row, col, thenumber, 0, 999999999, width, 0, MenuColor_); return(thenumber); } /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ int CTRLPGUP = 33792, F11 = 34048, F12 = 34304, EOF = -1; short LEFT = 19200, RIGHT = 19712, UP = 18432, DOWN = 20480, HOME = 18176, END = 20224, PGUP = 18688, PGDN = 20736, CTRLPGDN = 30208, F1 = 15104, F2 = 15360, F3 = 15616, F4 = 15872, F5 = 16128, F6 = 16384, F7 = 16640, F8 = 16896, F9 = 17152, F10 = 17408; char ESC = 27, CTRLP = 16, FALSE = 0, TRUE = 1, CR = 13, LF = 10;