/* PROGRAM NAME: APPEND.CPL ------------- Program Source Code File (.CPL) Concordance(tm) Information Retrieval System, Professional Edition COPYRIGHT: ---------- (C) Copyright Dataflight Software, Inc. 1990, 1991. All Rights Reserved. 2337 Roscomare Road, Suite 11 Los Angeles, CA 90077 SYNOPSIS: Appends or Prepends data to a field, leaving existing data intact. --------- */ /* Global variables are capitalized in this program. Local variables are in lower or mixed case. Variable names in all upper case, i.e., LEFT, are initialized once and should not be changed afterwards. */ int CTRLPGUP = 33792; short LEFT = 19200, RIGHT = 19712, UP = 18432, DOWN = 20480, HOME = 18176, END = 20224, PGUP = 18688, PGDN = 20736, CTRLPGDN = 30208, F2 = 15360, F3 = 15616, F4 = 15872, F5 = 16128, F6 = 16384, F7 = 16640, F8 = 16896, F9 = 17152, F10 = 17408; char ESC = 27, CTRLP = 16, EOF = -1, FALSE = 0, TRUE = 1, CR = 13, LF = 10; main() { int error, line, i; /* Make sure version 5.0 or later is running. */ if (ver() < 5.06) return(Message("Concordance version 5.06 or later required.")); /* Begin error recovery loop. It catches any runtime bugs. */ while(1) { eval("start()",error,line); while(keypress()) getkey(); /* Exit the program if no error was encountered, or ** if the exit() function was used. exit() produces ** an error code 124, "Program stopped." */ if (error == 124) exit(); if (error == 0) break; /* Notify the user of error recovery, close all files, rerun program. */ if (Message("Recover from error "+str(error)+" on line "+str(line)+" Y/N?") <> 'Y') break; for(i = 0; i <= 16; i = i + 1) { closedb(i); btclose(i); close(i); } } } /* main() */ start() { int db; text MenuItems[10]; int next, field, key; int appending; char string[128]; char addData[129]; int eOffset,wOffset; text screen; cursor(0,0); cursoroff(); Pcls(rep("-+",40)); puts(0,0,pad("Append/prepend data to any text field.",'C',80),MenuHighlight_); next = clock() + 1000; while(next > clock()) ; Status(db,appending,field,addData); MenuItems[0] = "Append/prepend menu"; MenuItems[1] = "Open a database"; MenuItems[2] = "Search database"; MenuItems[3] = "Browse retrieved records"; MenuItems[4] = "Select field to edit"; MenuItems[5] = "Append or prepend"; MenuItems[6] = "Data to add"; MenuItems[7] = "Go - start adding"; while(TRUE) { Status(db,appending,field,addData); switch(next = menu(6, 10, 17, 40, MenuItems, next,"OSBSADG")) { case 0: if (Message("Quit Y/N?") == 'Y') return; Pcls(rep("-+",40)); break; case 1: /* Open a database. */ if (getfile('Database',"*.DCB",string) == CR) { closedb(db); first(db = opendb(string)); } break; case 2: /* Full text searching. */ searchfs(db,""); break; case 3: /* Browse retrieved records. */ browse(db); break; case 4: /* Select field to edit. */ field = GetField(db, field); break; case 5: /* Appending or prepending. */ appending = not(appending); break; case 6: /* Data to add. */ screen = save(11,5,15,75); box(11,5,14,75,"3D", MenuColor_); puts(11,6,"Data",MenuColor_); key = 0; while((key <> CR) and (key <> ESC)) key = edit(addData,12,6,12,72,1|4|8,MenuColor_); restore(11,5,screen); break; case 7: /* Go - Start adding data to field. */ Replace(db,appending,field,addData); break; } } } /* start() */ /**************************************************************** * Name: Replace * * Synopsis: Appends or prepends data to a selected field. * ****************************************************************/ Replace(int db, appending, field; char addData[]) { float percent; int blocks = 23; int i; if (addData[0] == 0) return(Message("Enter some data to append/prepend first.")); if (db.documents < 0) return(Message("Open a database first.")); if (count(db) <= 0) return(Message("No documents were found in this search.")); if ((field > db.fields) or (field < 1)) return(Message("Select a field to edit.")); if ((db.type[field] <> 'P') and (db.type[field] <> 'T')) return(Message("The field must be a Paragraph or Text field.")); cycle(db) { puts(13,59,str(i = docno(db),10,0,',')+" ",MenuColor_); puts(14,46,rep('.',blocks*((i*1.0)/count(db))),MenuColor_); /* If there is no data in the field already, then just replace */ if (db->field == "") db->field = addData; else { if (appending) { if (db.type[field] == 'T') db->field = trim(db->field) + "; " + addData; else db->field = db->field + "; " + addData; } else { if (db.type[field] == 'T') db->field = addData + "; " + trim(db->field); else db->field = addData + "; " + db->field; } } while(keypress()) { if (getkey() == ESC) if (Message("Stop processing the database Y/N?") == 'Y') return; } } } /* Replace() */ /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status(int db, appending, field; char addData[]) { cursoroff(); cursor(0,0); puts(MaxRow_,0,pad("Concordance Information Retrieval System",'L',80),MenuHighlight_); puts(MaxRow_,61,"Dataflight Software",MenuHighlight_); if (db.documents >= 0) puts(0,0,pad(db.database,'L',80),MenuHighlight_); else scroll(0,0,0, 80,0,0,MenuHighlight_); box(6,44,17,72,"3D", MenuColor_); puts(06,45,pad("Status",'C',25),MenuHighlight_); puts(07,45,rep('_',25),MenuColor_); puts(08,45," Query "+str(max(0,db.query),16)+" ",MenuColor_); puts(09,45," Documents "+str(max(0,count(db)),13)+" ",MenuColor_); puts(10,45," Field "+pad(db.name[field],'R',16)+" ",MenuColor_); puts(11,45," Mode "+pad(appending ? "Appending " : "Prepending ",'R',17),MenuColor_); puts(12,45," Data "+pad(addData,'R',16)+" ",MenuColor_); puts(13,45," Processing 0 ",MenuColor_); puts(14,45," °°°°°°°°°°°°°°°°°°°°°°° ",MenuColor_); puts(15,45," Press [Esc] to Quit ",MenuColor_); } /* Status() */ /**************************************************************** * Name: Pcls * * Synopsis: Clears the screen to the pattern parameter. * ****************************************************************/ Pcls(text pattern) { int i; for(i = 0; i <= MaxRow_; i = i + 1) puts(i,0,pattern); } /* Pcls() */ /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[256]; 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: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message) { text screen; int key; cursoroff(); screen = save(8,13,11,69); box(8,13,11,69,"3D", MenuColor_); puts(9,14,pad(message,'C',53),MenuColor_); key = getkey(); restore(8,13,screen); return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; if (i = match(name,":",1)) name = substr(name,i+1); while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /**************************************************************** * Name: Path * * Synopsis: Returns the path up to the last \ and without * * the file's name. * ****************************************************************/ Path(text dosPath) { int i, j; if ((i = match(dosPath,":",1)) == 0) i = match(dosPath,"\",1); while(j = match(dosPath,"\",i+1)) i = j; return(substr(dosPath,1,i)); } /* Path() */