/* * Concordance Programming Language Text File Recovery Program * * Copyright (c) 1994, 1996 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 2337 Roscomare Road, Suite 11 * Bel Air, CA 90077 USA * * 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. */ int isWindows; main() { int db, i, fh, record; char string[4096]; float dVal; /* Dummy floating point value. */ int lrecl; /* Logical record length of .NDX file. */ int NULL; /* Empty pointer to text file, .TEX. */ text greeting; char szDatabase[256]; /* Determine if we are running under windows. */ ver(string); isWindows = match(upper(string),"WINDOWS" ,1); greeting = newline() + pad("Purge Program",'C',60) + newline() + pad("THIS PROGRAM IS DESTRUCTIVE",'C',60) + newline() + newline() + " It is designed to recover a database that consistently" + " displays" + ' an "Error on Text File" message on the same record(s).' + " This program deletes the contents of the Paragraph fields" + " from the problem record. After deletion, the record can be" + " edited and used normally, except that it will be blank the" + " next time it is accessed." + newline() + " " + newline() + pad("Press [Enter] to continue or [Esc] to quit", 'C', 60); if (isWindows) box(5, 9, 19, 71,"3U", RGB(190,190,190), RGB(128,128,128)); else box(5, 9, 19, 71,"S",MenuColor_,MenuColor_); edit(greeting ,6, 10, 18, 70,"@" ,1,"" ,0,0,MenuColor_); if (getkey() <> CR) return; if (db.documents > 0) if (Message("Use "+ FileName(db.database) + " database? Y/N",TRUE) <> 'Y') { closedb(db); db = EOF; } /* Open a database if one isn't available. */ if (db.documents < 0) { if (getfile("Open Database","*.DCB",string) == CR) { if ((db = opendb(string)) < 0) Message("Couldn't open "+string,TRUE); } } if (db.documents < 0) return; /* Show the database name on the top line. */ puts(0,0,db.database); /* Set the minimum length of an .NDX entry. */ /* Then calculate the length of all fields. */ lrecl = 6; for(i = 1; i <= db.fields; i = i + 1) switch(db.type[i]) { case 'P': break; case 'N': lrecl = lrecl + sizeof(dVal); break; case 'D': lrecl = lrecl + 8; break; case 'T': lrecl = lrecl + db.length[i] + 1; break; } /* Prompt the user for the record number to delete. */ record = GetNInfo(5, 27, 7, 44, "Purge record: ", docno(db), count(db)); /* Add 4 bytes for the accession number in v6.x databases. */ szDatabase = db.database; closedb(db); i = checkVersion(szDatabase+".DCB"); if (i == 0) return; if (i == 6) lrecl = lrecl + 4; if (i > 6) return(Message("Can't fix databases above V6", TRUE)); /* for(record = 2; record <= 76; record = record + 1) */ if (record > 0) { if (Message("Purge record " + str(record) + "? Are you sure? Y/N",TRUE) == 'Y') { string = szDatabase + ".NDX"; if ((fh = open(string,"r+")) == EOF) Message("Couldn't open "+string,TRUE); else { seek(fh,lrecl * (record - 1), 'B'); read(fh,string,lrecl); /* memcpy(string,NULL,sizeof(NULL)); */ memset(string, 0, sizeof(string)); string[4] = 0; seek(fh,lrecl * (record - 1), 'B'); write(fh,string,lrecl); close(fh); Message("Record "+str(record) + " has been purged.",TRUE); } } } db = opendb(szDatabase); goto(db, record); return; } /* main() */ /**************************************************************** * Name: RGB * * Synopsis: Helper routine for windows colors. * ****************************************************************/ RGB(char red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); } /**************************************************************** * Name: GetNInfo * * Synopsis: Helper routine to prompt user for numeric info. * ****************************************************************/ GetNInfo(int trow, tcol, brow, bcol; text prompt; int number, max) { text screen; int key; int oldnumber; screen = save(trow,tcol,brow,bcol); scroll(trow,tcol,brow,bcol,0,0,TextHighlight_); box(trow,tcol,brow,bcol,'3d',TextHighlight_); key = 0; puts(trow,tcol+1,prompt,TextHighlight_, TextBackground_); oldnumber = number; while((key <> CR) and (key <> ESC)) key = getnumber(trow+1,tcol+1,number,0,max,15,0,TextHighlight_); if (key == ESC) number = 0; restore(trow,tcol,screen); return(number); } /* GetNInfo() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /* FileName() */ /**************************************************************** * Name: checkVersion * * Synopsis: Gets version number from *.DCB file * ****************************************************************/ checkVersion(text dcbFilename) { int VERSOFFSET = 32; int fh; /* File handle */ char versMajor; char versMinor; /* Open file *.DCB */ if ((fh = open(dcbFilename, "r")) < 0) { Message("Couldn't open "+dcbFilename, TRUE); return(FALSE); } /* Seek to dbmajor and read the version*/ if (seek(fh,VERSOFFSET,'B') == -1) { Message("Seek error on "+ dcbFilename, TRUE); return (FALSE); } if (read(fh, versMajor, sizeof(versMajor)) <> sizeof(versMajor)) { Message("Error reading "+ dcbFilename,TRUE); return (FALSE); } if (read(fh, versMinor, sizeof(versMinor)) <> sizeof(versMinor)) { Message("Error reading "+ dcbFilename,TRUE); return (FALSE); } close(fh); return(versMajor); } /* checkVersion() */ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int wait) { text screen; int key, tr, tc; int bk, fg; bk = RGB(255,0,255); fg = isWindows ? RGB(160,0,160) : MenuColor_; cursoroff(); screen = save(tr = 8,tc = 13, tr + 3, tc + 56); box(tr, tc, tr + 2, tc + 54,"3U", fg, bk); puts(tr + 1,tc + 1,pad(message,'C',53),isWindows ? RGB(255,255,255) : fg,bk); if (wait) key = getkey(); restore(tr,tc,screen); return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ /* findfirst() file attributes. _A_NORMAL 00 Normal file - No read/write restrictions _A_RDONLY 01 Read only file _A_HIDDEN 02 Hidden file _A_SYSTEM 04 System file _A_VOLID 08 Volume ID file _A_SUBDIR 16 Subdirectory _A_ARCH 32 Archive file edit() mode attributes. A // Alpha only mode. U // Upper case conversion. N // Numeric only mode. Y // Y mode for dates. M // M mode for dates. D // D mode for dates. C // Cut and paste mode. S // Scroll field left and right, no wordwrapping. E // Return on [Enter], no CR in data. T // Always edit from the top. B // Always edit from the bottom. @ // Display only this field. ! // Return when this field is entered, don't edit. N:99.99 */ 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;