/* * Concordance Programming Language * * Copyright (c) 1995 Dataflight Software. * All Rights Reserved. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077 * * ALL RIGHTS RESERVED. * * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * * This program was revised on May 25, 2000. * */ text filePattern = "*.gap"; int EOF = -1, TRUE = 1, FALSE = 0, ESC = 27, CR = 13; /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status(int db, gapField; char szFilename[]) { cursoroff(); cursor(0,0); puts(MaxRow_,0,pad("Concordance Information Retrieval System",'L',80),RGB(0,0,0), RGB(160,160,160)); puts(MaxRow_,61,"Dataflight Software",RGB(0,0,0), RGB(160,160,160)); if (db.documents >= 0) puts(0,0,pad(db.database,'L',80), RGB(0,0,0), RGB(160,160,160)); else cls(); box(6,44,14,72,"3D", RGB(0,0,0), RGB(160,160,160)); puts(7,45,pad("Status",'C',25),RGB(0,0,0), RGB(160,160,160)); puts(8,45,rep('_',25),RGB(0,0,0), RGB(160,160,160)); puts(9,45," Gap field "+pad(db.name[gapField],'R',12)+" ",RGB(0,0,0), RGB(160,160,160)); puts(10,45," LogFile "+pad(FileName(szFilename),'R',15)+" ",RGB(0,0,0), RGB(160,160,160)); puts(11,45," Processing 0 ",RGB(0,0,0), RGB(160,160,160)); puts(12,45," °°°°°°°°°°°°°°°°°°°°°°° ",RGB(0,0,0), RGB(160,160,160)); puts(13,45," Press [Esc] to Quit ",RGB(0,0,0), RGB(160,160,160)); } /* Status() */ /**************************************************************** * Name: RGB * * Synopsis: Helper routine for Windows color creation. * ****************************************************************/ RGB(int red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); } /**************************************************************** * Name: Pcls * * Synopsis: Clears the screen to the pattern parameter. * ****************************************************************/ Pcls( text pattern ) { cls(); } /** Pcls() **/ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int wait) { text screen; int key, rc; int fg, bk, tr, tc; if (wait) { eval('rc = messageBox(message, "Concordance", MB_OK);', key); return(rc); } tr = 8; tc = 13; fg = RGB(0,0,0); cursoroff(); if (wait) screen = save(tr, tc, tr + 3, tc + 56); box(tr , tc , tr + 2, tc + 54,"3U", RGB(160,160,160), bk = RGB(200,200,200)); puts(tr + 1,tc + 1,pad(message,'C',53), fg, bk); if (wait) { while(keypress()) getkey(); key = getkey(); restore(tr,tc,screen); } return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * 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: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[251]; 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 "; break; case 'P' : field[i] = pad(db.name[i],'L',13)+ "Paragraph"; break; case 'N' : field[i] = pad(db.name[i],'L',13)+ "Numeric "; break; case 'D' : field[i] = pad(db.name[i],'L',13)+ "Date "; break; } i = db.fields + 1; screen = save(11,30,14+db.fields,57); while(i > db.fields) i = menu(11, 30, 14+db.fields, 57, field, next,""); restore(11,30,screen); if (i) next = i; } return(next); } /* GetField() */ /**************************************************************** * Name: GetNumber * * Synopsis: Gets number attached to Bates number * ****************************************************************/ GetNumber(text string) { int i, j, length; text ret; i = j = 0; length = len(string); /* Corrected version...now will correctly substring */ /* a text string using a text string instead of a */ /* char array. */ while (length > 0) { if (isdigit(substr(string,length,1)) == 0) break; ret = substr(string, length); j = j + 1; length = length - 1; } /* Limit the return value to the last 6 chars */ if (len(ret) > 6) ret = substr(ret, len(ret) - 6 + 1); return (ret); } /**************************************************************** * Name: main * * Synopsis: Entry point for all Concordance programs. * ****************************************************************/ main() { char szDb[ 80 ], /* Database name */ szGapFile[ 80 ]; /* Gap log file name */ text MenuItems[ 7 ]; /* Menu items array */ int next; /* Current menu item */ int db, /* Database handle */ file; /* Log file handle */ int gapField; /* Gap field */ int gapEnd; /* Ending gap field */ int finished; /* Finished flag */ MenuItems[0] = "GAP CHECK MENU"; MenuItems[1] = "Open a database"; MenuItems[2] = "Select gap begin field"; MenuItems[3] = "Select gap end field"; MenuItems[4] = "Select gap log file"; MenuItems[5] = "Go!"; MenuItems[6] = "QUIT"; file = -1; cls(); while(finished == FALSE) { Status(db,gapField,szGapFile); switch(next = menu(6, 10, 15, 44, MenuItems, next,"OBELGQ")) { case 0: /* Escape menu option */ if (messageBox("Quit Y/N?", program(), MB_ICONQUESTION | MB_YESNO) == IDYES) return; break; case 1: /* Open a database. */ if (getfile('Database',"*.DCB",szDb) == CR) { closedb(db); if ((db = opendb(szDb)) < 0) Message("Cannot open database.",TRUE); } next = 1; break; case 2: /* Select 'gap check' field */ gapField = GetField(db, gapField); next = 2; break; case 3: /* Select 'gap end' field */ gapEnd = GetField(db, gapEnd); next = 3; break; case 4: /* Select gap log file */ if (getfile("Open gap log file","*.gap",szGapFile) == CR) { if (file <> -1) { close(file); file = -1; } if ((file = open(szGapFile,"w")) <0) Message("Cannot open log file.",TRUE); } next = 4; break; case 5: /* Begin */ if (gapcheck(db, file, gapField, gapEnd) == TRUE) { close(file); file = -1; szGapFile = ""; } next = 5; case 6: /* Quit */ finished = TRUE; } } return; } /**************************************************************** * Name: gapcheck * * Synopsis: Starts the gap checking process. * ****************************************************************/ gapcheck(int db, file, gapField, gapEnd) { int i,j; int last; text lasttext; char line[150]; /* Check to make sure all elements are here */ if (db.documents < 0) return(Message("Open a database first.",TRUE)); if ((gapField > db.fields) or (gapField < 1)) return(Message("Select a start gap field.",TRUE)); if ((gapEnd > db.fields) or (gapEnd < 1)) return(Message("Select an end gap field.",TRUE)); if (file < 0) return(Message("Open a log file first.",TRUE)); /* Move to first document */ first( db ); /* Title the gap file */ line = "Gap Check for: " + FileName(db.database) + newline(); writeln(file, line, len(line)); /* Sort the database */ if( messageBox("Is the database already sorted? ", capitalize(program()), MB_ICONQUESTION | MB_YESNO ) <> IDYES) if (sort(db, db->gapField, 0, 75 ) == EOF) { Message("Sort Error",TRUE); return; } /* Switch depending on type of field */ switch(db.type[gapField]) { /* Numeric comparison */ case 'N': cycle( db ) { if (docno(db) == 1) { last = db->gapEnd; next(db); } puts(11,56,pad(str(docno(db)),'R',13), RGB(0,0,0), RGB(160, 160, 160)); i = db->gapField - last; if( i < 0 ) /* out of sequence */ GapError( "Number out of sequence. ", str(db->gapField), str(last), db, file); if( i == 0 ) /* same page number */ GapError( "Same number. ", str(db->gapField), str(last), db, file); if( i > 1 ) /* GAP in numbers */ GapError( "A GAP has been detected.", str(db->gapField), str(last), db, file); last = db->gapEnd; if (keypress()) if (getkey() == ESC) break; } break; /* Date comparison */ case 'D': cycle(db) { if (docno(db) == 1) { last = db->gapEnd; next(db); } puts(11,56,pad(str(docno(db)),'R',13),RGB(0,0,0), RGB(160, 160, 160)); i = db->gapField - last; if( i < 0 ) /* out of sequence */ GapError( "Date out of sequence. ", dtoc(db->gapField), dtoc(last), db, file); if( i == 0 ) /* same page number */ GapError( "Same date. ", dtoc(db->gapField), dtoc(last), db, file); if( i > 1 ) /* GAP in numbers */ GapError( "A GAP has been detected.", dtoc(db->gapField), dtoc(last), db, file); last = db->gapEnd; if (keypress()) if (getkey() == ESC) break; } break; /* Text comparison */ case 'P': case 'T': j = docno(db); while ((j <= db.documents) and (j > 0)) { if (docno(db) == 1) { lasttext = db->gapEnd; last = num(GetNumber(db->gapEnd)); next(db); } puts(11,56,pad(str(docno(db)),'R',13),RGB(0,0,0), RGB(160, 160, 160)); i = num(GetNumber(db->gapField)) - last; if( i < 0 ) /* out of sequence */ GapError( "Bates out of sequence. ", db->gapField, lasttext, db, file); if( i == 0 ) /* same page number */ GapError( "Same Bates number. ", db->gapField, lasttext, db, file); if( i > 1 ) /* GAP in numbers */ GapError( "A GAP has been detected.", db->gapField, lasttext, db, file); last = num(GetNumber(db->gapEnd)); lasttext = db->gapEnd; j = next(db); if (keypress()) if (getkey() == ESC) break; } break; } beep( 400, 50 ); beep( 500, 100 ); beep( 400, 50 ); return(TRUE); } /* gapcheck() */ /**************************************************************** * Name: GapError * * Synopsis: Prints the error according to type * ****************************************************************/ GapError(text string, current, last; int db, file) { char line[ 150 ]; writeln( file, string, len(string)); line = pad("Record number",'L',15) + pad(str(docno(db)) + " ["+str(recno(db))+"]",'L',20) + pad("Previous", 'L', 10) + pad(last,'L',25) + pad("Current", 'L', 10) + pad(current,'L',25); writeln( file, line, len( line ) ); /* line = pad(str(recno(db)),'L',20)+pad(last,'L',24)+pad(current,'L',24); writeln( file, line, len( line ) ); */ writeln( file, "", 0); } /* Standard dialog button return values. */ int IDOK = 1; int IDCANCEL = 2; int IDABORT = 3; int IDRETRY = 4; int IDIGNORE = 5; int IDYES = 6; int IDNO = 7; /* MessageBox() display options. */ int MB_OK = 0; int MB_OKCANCEL = 1; int MB_ABORTRETRYIGNORE = 2; int MB_YESNOCANCEL = 3; int MB_YESNO = 4; int MB_RETRYCANCEL = 5; int MB_ICONHAND = 16; int MB_ICONQUESTION = 32; int MB_ICONEXCLAMATION = 48; int MB_ICONASTERISK = 64; int MB_ICONINFORMATION = MB_ICONASTERISK; int MB_ICONSTOP = MB_ICONHAND; int MB_DEFBUTTON1 = 0; int MB_DEFBUTTON2 = 256; int MB_DEFBUTTON3 = 512; int MB_APPLMODAL = 0; int MB_SYSTEMMODAL = 4096; int MB_TASKMODAL = 8192; int MB_NOFOCUS = 32768;