/* ** Concordance Programming Language EndNumber.cpl ** ** Copyright (c) 1999 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Bel Air, CA 90077 ** ** 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: ** ** Written by Paul Mitsui 2/24/99 ** Version 1.0 */ /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { int db, nNext, bDone, nBegBatesField, nEndBatesField; text pszMainMenu[5], pszMenu1, pszMenu2; /* Clear the screen */ Pcls(TRUE); /* Make sure the database is open */ if (db.documents <= 0) return(Message("Please open a database first. ",TRUE)); /* Set up the menu */ pszMenu1 = "[B] Select begin bates field : "; pszMenu2 = "[E] Select end bates field : "; pszMainMenu[0] = "End Number"; pszMainMenu[1] = pszMenu1; pszMainMenu[2] = pszMenu2; pszMainMenu[3] = "[G] Go"; pszMainMenu[4] = "[Q] Quit"; nNext = 1; /* Display the menu */ while (bDone == FALSE) { nNext = menu(5, 10, 12, 70, pszMainMenu, nNext,"BEGQ"); switch(nNext) { case 1: nBegBatesField = GetField(db, nBegBatesField); if (nBegBatesField > 0) { pszMainMenu[1] = pszMenu1 + db.name[nBegBatesField]; nNext = 2; } break; case 2: nEndBatesField = GetField(db, nEndBatesField); if (nEndBatesField > 0) { pszMainMenu[2] = pszMenu2 + db.name[nEndBatesField]; nNext = 3; } break; case 3: goNumber(db, nBegBatesField, nEndBatesField); Pcls(TRUE); nNext = 4; break; case 0: case 4: bDone = TRUE; break; } } } /*****************************************************/ /* Function: goNumber */ /* Purpose : Main function to number the end bates */ /*****************************************************/ goNumber(int db, nBegBatesField, nEndBatesField) { int i; text pszBegBates; /* Make sure all data is here */ if (nBegBatesField <= 0) return(Message("Please select a begin bates field. ", TRUE)); if (nEndBatesField <= 0) return(Message("Please select an end bates field. ", TRUE)); /* Put up a status box */ Message("", FALSE); /* Loop through the current query */ for (i = goto(db, 1); i > 0; i = next(db)) { /* Show a processing message */ puts( 8, 14, pad("Processing record " + str(docno(db)) + " of " + str(count(db)), 'C', 55 ), RGB(255,255,255), RGB(0,0,255)); /* Go to the next record temporarily */ if (next(db) > 0) { /* Get the begin bates field */ pszBegBates = db->nBegBatesField; /* Go back to the previous record */ prev(db); /* Set the end bates field */ db->nEndBatesField = GetBatesNumber(pszBegBates, -1); } } } /**************************************************************** * Name: GetBatesNumber * * Synopsis: Returns a bates number offset by a value * ****************************************************************/ GetBatesNumber(text pszBates; int nOffset) { int i; char szBates[256]; text pszPrefix, pszNumeric; /* Store the bates number in a local char array */ szBates = pszBates; /* Loop backwards until we find the first non-numeric character */ i = len(szBates) - 1; while (isdigit(szBates[i])) i = i - 1; /* Get the prefix and numeric portions */ pszPrefix = substr(szBates, 1, i + 1); pszNumeric = substr(szBates, i + 2); /* Construct the new bates number */ pszBates = pszPrefix + str(num(pszNumeric) + nOffset, len(pszNumeric), 0, 'Z'); return(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(int isWindows) { int i; int oldBackground; if (isWindows) cls(RGB(128, 128, 128)); else { for(i = 0; i <= MaxRow_; i = i + 1) puts(i,0,pattern); } } /* Pcls() */ /**************************************************************** * 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;