/* * Concordance Programming Field Copy Program * * Copyright (c) 1994 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 2337 Roscomare Road, Suite 11 * Los Angeles, 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: * * Copyright (c) 1994 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1994 Dataflight Software, Inc. */ /* 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 db; text MenuItems[10]; int next, toField, fromField, key, keep; int appending; char string[128]; int eOffset,wOffset; text screen; cursor(0,0); cursoroff(); puts(0,0,pad("Append/prepend data to any text field.",'C',80),MenuHighlight_); Status(db,appending,toField,fromField,keep); MenuItems[0] = "APPEND FIELD MENU"; MenuItems[1] = "Open a database"; MenuItems[2] = "Search database"; MenuItems[3] = "Browse retrieved records"; MenuItems[4] = "Select field to copy FROM"; MenuItems[5] = "Select field to copy TO"; MenuItems[6] = "Append or prepend"; MenuItems[7] = "Keep/delete FROM field info"; MenuItems[8] = "Go - start adding"; while(TRUE) { Status(db,appending,toField,fromField,keep); switch(next = menu(6, 10, 17, 40, MenuItems, next,"OSBFTAG")) { case 0: if (Message("Quit Y/N?") == 'Y') return; 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 copy from. */ fromField = GetField(db, fromField); if ((fromField == toField) & (fromField <> 0) & (toField <> 0)){ Message("From and to fields cannot be the same! Hit any key."); fromField = 0; } break; case 5: /* Select field to copy to */ toField = GetField(db, toField); if ((fromField == toField) & (fromField <> 0) & (toField <> 0)){ Message("From and to fields cannot be the same! Hit any key."); toField = 0; } break; case 6: /* Appending or prepending. */ appending = not(appending); break; case 7: /* Keep or delete */ keep = not(keep); break; case 8: /* Go - Start adding data to field. */ Replace(db,appending,keep,fromField,toField); break; } } } /* main() */ /**************************************************************** * Name: Replace * * Synopsis: Appends or prepends data * ****************************************************************/ Replace(int db, appending, keep, fromField, toField) { float percent; int blocks = 23; int i; char addData[3000]; if ((fromField > db.fields) or (fromField < 1)) return(Message("Enter a FROM field first.")); if ((toField > db.fields) or (toField < 1)) return(Message("Enter a TO field first.")); if ((db.type[toField] <> 'T') & (db.type[toField] <> 'P')) return(Message("TO must be text or paragraph!")); if (db.documents < 0) return(Message("Open a database first.")); if (count(db) <= 0) return(Message("No documents were found in this search.")); cycle(db) { puts(14,59,str(i = docno(db),10,0,',')+" ",MenuColor_); puts(15,46,rep('~',blocks*((i*1.0)/count(db))),MenuColor_); if (appending) switch(db.type[fromField]) { case 'T': if (db.type[toField] == 'T') db->toField = trim(db->toField) + " " + trim(db->fromField); else db->toField = db->toField + " " + trim(db->fromField); break; case 'P': if (db.type[toField] == 'T') db->toField = trim(db->toField) + " " + db->fromField; else db->toField = db->toField + " " + db->fromField; break; case 'D': if (db.type[toField] == 'T') db->toField = trim(db->toField) + " " + dtoc(db->fromField); else db->toField = db->toField + " " + dtoc(db->fromField); break; case 'N': if (db.type[toField] == 'T') db->toField = trim(db->toField) + " " + str(db->fromField); else db->toField = db->toField + " " + str(db->fromField); break; } else switch(db.type[fromField]) { case 'T': if (db.type[toField] == 'T') db->toField = trim(db->fromField) + " " + trim(db->toField); else db->toField = trim(db->fromField) + " " + db->toField; break; case 'P': if (db.type[toField] == 'T') db->toField = db->fromField + " " + trim(db->toField); else db->toField = db->fromField + " " + db->toField; break; case 'D': if (db.type[toField] == 'T') db->toField = dtoc(db->fromField) + " " + trim(db->toField); else db->toField = dtoc(db->fromField) + " " + db->toField; break; case 'N': if (db.type[toField] == 'T') db->toField = str(db->fromField) + " " + trim(db->toField); else db->toField = str(db->fromField) + " " + trim(db->toField); break; } /* end switch */ while(keypress()) { if (getkey() == ESC) if (Message("Stop processing the database Y/N?") == 'Y') return; } /* end while keypress */ /* Erase from field if not keeping it. */ if (not(keep)) db->fromField = ""; } /* end cycle db */ Message("Done! Hit any key to continue"); } /* Replace() */ /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status(int db, appending, to, from, keep) { 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(5,44,18,73,"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," From Field "+pad(db.name[from],'R',11)+" ",MenuColor_); puts(11,45," To Field "+pad(db.name[to],'R',13)+" ",MenuColor_); puts(12,45," Mode "+pad(appending ? "Appending " : "Prepending ",'R',17),MenuColor_); puts(13,45," Keep/Delete "+pad(keep ? "Keep" : "Delete", 'R', 11),MenuColor_); puts(14,45," Processing 0 ",MenuColor_); puts(15,45," °°°°°°°°°°°°°°°°°°°°°°° ",MenuColor_); puts(16,45," - Press [Esc] to Quit - ",MenuColor_); } /* Status() */ /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[255]; 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() */