/* ** Concordance Programming Language BRS Load Module ** ** Copyright (c) 1990 Dataflight Software, Inc. All Rights Reserved. ** Dataflight Software, Inc. ** 3200 Airport Avenue, Suite 19 ** Santa Monica, CA 90230 ** */ /**************************************************************** * Name: BRS.cpl * * Synopsis: Loads a text data set into a Concordance data * * base. The text file has been converted to ASCII * * and downloaded from the mainframe to PC. * * Description: The main menu presents the user with options to * * open a data base, load a text data set, index, * * reindex, browse. Input data must be in the * * following format: * * * * o It has been converted to ASCII format. * * o Field codes are in columns 0-3. * * o All field codes match field names. * * o Data starts in column 5. * * * * Sample Data Set * * 1 2 3 4 5 6 * * 0123456789012345678901234567890123456789012345678901234567890 * * *** * * AAAA DAL000245001 * * RECD 13-88-00309-CV * * SOEF I-492 * * SURP INA FILE NO 580 L 3480070, PERSONAL INJURY, 3RD * * PARTY. ROBERT SHERIFF, PO BOX 5700, SAN ANTONIO, TX * * SUNK 524-1700. * * NICI JOHN JONES AND ROBERT SMITH. * ****************************************************************/ main() { int db, finished, next; char string[256]; text MainMenu[8]; cls(); cursor(0,0); Status(db); /* Assign the main menu options. */ MainMenu[0] = "BRS to Concordance Conversion Module"; MainMenu[1] = "Open a Concordance Database"; MainMenu[2] = "Nothing Option"; MainMenu[3] = "Browse the Database"; MainMenu[4] = "Load Tagged Plain Text Data Set"; MainMenu[5] = "Index the Database"; MainMenu[6] = "Reindex the Database"; MainMenu[7] = "Concordance Information Retrieval System"; while(finished == FALSE) switch(next = menu(5, 12, 15, 63, MainMenu, next,"ONBLIRCM")) { case 0: cls(); Status(db); /* Open a database. Save the current database's name, */ case 1: /* then close it. If the user cancels the open, then */ /* reopen the same one. */ if (db.documents >= 0) string = db.database+".dcb"; else string = ""; closedb(db); if ((db = OpenDatabase()) < 0) db = opendb(string); Status(db); next = 1; case 2: Message("This option does nothing."); next = 2; case 3: query(db,-1); browse(db); next = 3; case 4: LoadTagged(db); /* Close and reopen database to flush files. */ string = db.database; closedb(db); db = opendb(string); next = 4; case 5: index(db); next = 5; case 6: reindex(db); next = 6; /* Memory left in the system. */ case 'M': string = "Memory available: "+trim(str(memavl(),9,0,',')); puts(0,80-len(string),string,MenuHighlight_); /* Return to Concordance. */ case 7: case -1: finished = TRUE; } } /* main() */ /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status(int db) { 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_); } /* Status() */ /**************************************************************** * Name: LoadTagged * * Synopsis: Loads a tagged data set into Concordance. * ****************************************************************/ LoadTagged(int db) { int key, line, field, i, count, file, start; char string[256]; text screen; file = EOF; /* Check to see if we have an open data base. */ if (db.documents < 0) Message("Please open a database first."); else if (getfile("Tagged Input File","*.*",string) == CR) if ((file = open(string,"r")) == EOF) Message("Error opening input file."); if (file <> EOF) { /* Set up for the processing loop. */ screen = save(12,49,16,69); scroll(12,49,16, 69,0,0,MenuColor_); box(12,49,16,69,'S',MenuColor_); blank(db); puts(13,50,"Line:",MenuColor_); /* ** Here is the entire processing loop. Read ** and process one line at a time until the ** file ends or an error is encountered. */ start = clock(); while(readln(file,string) >= 0) if (string[0] == TAB) break; while((readln(file,string) >= 0) and (key <> ESC) and (string[0] <> CTRLZ)) { if (((line = line + 1) mod 5) == 0) puts(13,58,str(line,11,0,','),MenuColor_); if (string[1]) { if (string[0] == TAB) { if (line > 1) key = New(db,count = count + 1); } else { field = FindField(db, string, field); field = Store(db, field, string); } while(keypress()) if ((key = getkey()) == ESC) key = AreYouSure(); memset(string,0,sizeof(string)); } } /* Last document still needs to be saved. */ if (len(trim(db->1)) and (key <> ESC)) { append(db); puts(14,50,"Documents: "+str(db.documents,8,0,','),MenuColor_); puts(15,50,"Loaded: "+str(count,8,0,','),MenuColor_); } close(file); restore(12,49,screen); } } /* LoadTagged() */ /**************************************************************** * Name: New * * Synopsis: Appends the document to the data base and shows * * the record count on the screen. Returns ESC if * * an error is encountered storing the record. * ****************************************************************/ New(int db,i) { int error; int j; for(j = 1; j <= db.fields; j = j + 1) if (db.type[j] == 'P') db->j = trim(db->j); /* Store the document, clear a new one, display statistics. */ if (append(db) < 0) { error = ESC; Message("The disk is full, cannot continue loading."); } blank(db); puts(14,50,"Documents: "+str(db.documents,8,0,','),MenuColor_); puts(15,50,"Loaded: "+str(i,8,0,','),MenuColor_); return(error); } /* New() */ /**************************************************************** * Name: Store * * Synopsis: Stores the data in the proper field. Date and * * numeric data is converted before being stored. * ****************************************************************/ int warned; Store(int db, field; char string[]) { int value, j; char szField[25]; switch(db.type[field]) { case 'P': db->field = db->field + string + newline(); /* Advance to the next field if this one is full and the */ /* next one has the same name, excluding the last character. */ if ((len(db->field) > 64000) and (field < db.fields)) { szField = db.name[field]; for(j = 0; szField[j]; j = j + 1) if (isdigit(szField[j])) { szField[j] = 0; break; } j = len(szField); if (substr(db.name[field + 1], 1, j) == szField) field = field + 1; } break; case 'T': db->field = trim(string); break; case 'N': db->field = num(string); break; case 'D': /* Convert YYYYMMDD format to MM/DD/YY format. */ if (len(string) == 6) string = "19" + string; memcpy(db->field, string, 8); break; default: break; } return(field); } /* Store() */ /**************************************************************** * Name: FindField * * Synopsis: Scans through the list of field text/STAIRS * * field names to find a match for the field name * * in the string just read from file. * ****************************************************************/ FindField(int db; char line[]; int field) { int i, code; char string[10]; if (isalpha(line[0]) == 0) { line = substr(line, 6); return(field); } /* Isolate the first four characters to determine the code. */ string = trim(upper(substr(line,1,4))); /* Scan through the list and find an exact match for */ /* the field code with the Concordance name. */ if (i = isfield(db, string)) { line = substr(line, 6); return(i); } /* The item isn't a field code. Return the last field code ** to use over again. Pad it with three spaces to force the ** unknown characters to be used in the field. */ line = substr(line, 6) + newline(); return(field); } /* FindField() */ /**************************************************************** * Name: AreYouSure * * Synopsis: Asks the user if they want to abort loading. * ****************************************************************/ AreYouSure() { int key; while(keypress()) getkey(); key = Message("Abort Loading Y/N?"); if ((key == 'Y') or (key == 'y')) key = ESC; else key = 0; return(key); } /* AreYouSure() */ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message) { text screen; int key; cursoroff(); screen = save(7,5,9,75); scroll(7,5, 9, 75, 0, 0,TextColor_); box(7,5,9,75,'d',TextColor_); puts(8,6,pad(message,'C',69),TextHighlight_); key = getkey(); restore(7,5,screen); return(key); } /* Message() */ /**************************************************************** * Name: OpenDatabase * * Synopsis: Prompts the user for a database and opens it. * ****************************************************************/ OpenDatabase() { int key, db; char string[80]; db = EOF; while((db == EOF) and (key <> ESC)) if ((key = getfile("Open Database","*.dcb",string)) <> ESC) db = opendb(string); return(db); } /* OpenDatabase() */ /**************************************************************** * Name: initialize * * Synopsis: Set global variables to initial values * * Action: Global variables are set for system calls * ****************************************************************/ int ESC = 27, EOF = -1, CR = 13, LF = 10, FALSE = 0, TRUE = 1, CTRLZ = 26, TAB = 9;