/* ** Concordance Programming Language ** ** Copyright (c) 1995 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 11/18/1998 ** Version 1.0 */ /**************************************************************** * Name: renumber.cpl * * Synopsis: Program to sequentially number fields. * * Note: This program assumes that a search has already * * been performed isolating the documents that * * need to be numbered. It will prompt for a field * * name, a starting numeric value, the width of * * number, and an optional alphameric prefix. * * It will assign the values to the database field * * for every document in the current query. * * Example: ABC00005 through ABC0949 * ****************************************************************/ int isWindows, darkPurple, lightPurple, black; int WIDTH = 0; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { text string, prefix, mymenu[7], menuString1, menuString2, menuString3, menuString4; int next, done, begBates, db, number; /* Initialize variables and clear the screen */ ver(string); isWindows = match(upper(string),"WINDOWS" ,1); darkPurple = RGB(0,0,160); lightPurple = RGB(0,0,255); black = RGB(255,255,255); cursoroff(); cursor(0,0); Pcls(rep("ΔΕ", (MaxCol_ + 1) / 2)); /* Make sure the database is open */ if (db.documents <= 0) return(Message("Please open a database first. ",TRUE)); /* Set up the menu */ menuString1 = "[1] Number prefix :"; menuString2 = "[2] Digit width of number :"; menuString3 = "[3] Beginning number :"; menuString4 = "[4] Number field :"; mymenu[0] = "RENUMBER.CPL"; mymenu[1] = menuString1; mymenu[2] = menuString2; mymenu[3] = menuString3; mymenu[4] = menuString4; mymenu[5] = "[G] Go!"; mymenu[6] = "[Q] Quit"; next = 1; /* Display the menu */ while (done == FALSE) { next = menu(5, 10, 14, 70, mymenu, next,"1234GQ"); switch(next) { case 1: prefix = getText(7, 45, 20); mymenu[1] = menuString1 + " " + prefix; next = 2; break; case 2: WIDTH = getNumber(8, 45, 10); if (WIDTH <= 0) { Message("Width must be greater than 0. ",TRUE); next = 2; } else { mymenu[2] = menuString2 + " " + str(WIDTH); next = 3; } break; case 3: number = getNumber(9, 45, WIDTH); mymenu[3] = menuString3 + " " + str(number, WIDTH, 0, 'Z'); next = 4; break; case 4: begBates = GetField(db, begBates); if ((db.type[begBates] == 'P') or (db.type[begBates] == 'T')) { mymenu[4] = menuString4 + " " + db.name[begBates]; next = 5; } else { Message("Field must be Text or Paragraph. ",TRUE); next = 4; } break; case 5 : goRenumber(prefix, db, number, begBates); Pcls(""); next = 6; break; case 6: done = TRUE; break; } } } /* main() */ /*****************************************************/ /* Function: goRenumber */ /* Purpose : the main function to renumber the query */ /*****************************************************/ goRenumber(text prefix; int db, number, begBates) { /* Check to see if all the variables are here */ if (WIDTH <= 0) return(Message("Width must be greater than 0. ",TRUE)); if (begBates == 0) return(Message("Please specify a begin bates field. ",TRUE)); /* Place a status box on the screen */ Message("",FALSE); /* Cycle through the database */ cycle(db) { puts(8,14,pad("Processing record " + str(docno(db)),'C',55),black,lightPurple); /* Renumber the field */ db->begBates = prefix + str(number, WIDTH, 0, 'Z'); /* increment the bates number */ number = number + 1; } } /* goProduce() */ /*****************************************************/ /* Function: getNumber */ /* Purpose : Return the number at row, col, width */ /*****************************************************/ getNumber(int row, col, width) { char key; int thenumber; while ((key <> CR) and (key <> ESC)) key = getnumber(row, col, thenumber, 0, 999999999, width, 0, MenuColor_); return(thenumber); } /*****************************************************/ /* Function: getText */ /* Purpose : Return the date entered at row, col */ /*****************************************************/ getText(int row, col, width) { char textstring[21], key; while ((key <> CR) and (key <> ESC)) key = getline(row, col, width, textstring, MenuColor_); return(textstring); } /**************************************************************** * 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: Pcls * * Synopsis: Clears the screen to the pattern parameter. * ****************************************************************/ Pcls(text pattern) { 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() */ /**************************************************************** * 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() */ /**************************************************************** * 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; /* Here are the bits, directly from Opticon. */ /* The volumeKey is low bits, pages are high bits. */ int VOLUMEBITS = 16383; int BOXBIT = 16384; int FOLDERBIT = 32768; int DOCBIT = 65536; int PAGEBITS = -131072; /* All page bits set on. */ int PAGEBIT = 131072; /* Single page set on. */