/**************************************************************** * Name: STAIRS72C * * Synopsis: Loads a STAIRS 72C format input file into a * * Concordance database. The 72C 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 an 72C data set, index, * * reindex, browse, and examine the Concordance to * * 72C field code matches. * * Notes: This program requires a file with the STAIRS to * * Concordance field code equivalents. The file is * * named database.72C and should be in the * * database's directory. These codes are used to * * match the incoming STAIRS data to the proper * * Concordance field. Below is a sample .72C file. * * * * 1 2 3 4 5 6 * * 123456789012345678901234567890123456789012345678901234567890 * * 0A0 DOCNO Text 18 * * REPORT Text 6 * * DATE Text 6 * * SIGNDATE Text 6 * * 100 TITLE Paragraph 16 * * 200 REPORT_ID Paragraph 16 * * 300 AUTHOR Paragraph 16 * * 400 KEYWORDS Paragraph 16 * * 500 ABSTRACTS Paragraph 16 * * 600 SIGNOUTS Paragraph 16 * * * * Aside from the field code considerations, the * * program makes the following assumptions about * * the 72C data set: * * o It has been converted to ASCII format. * * o Field codes are in columns 1, 2, and 3. * * o All field codes are three characters long. * * o Data starts in column 4. * * Data marked for STAIRS sub-paragraphs, (i.e., * * field 501 below which is stored in STAIRS field * * 500), will be stored in the corresponding field * * "500" in Concordance. This will only work for * * completely numeric field codes. * * * * Sample 72C Data Set * * 1 2 3 4 5 6 * * 123456789012345678901234567890123456789012345678901234567890 * * 0AADAL000245001 * * 00513-88-00309-CV * * 010I-492 * * 500INA FILE NO 580 L 3480070, PERSONAL INJURY, 3RD * * PARTY. ROBERT SHERIFF, PO BOX 5700, SAN ANTONIO, TX * * 524-1700. * * 501JOHN JONES AND ROBERT SMITH. * ****************************************************************/ main() { int db, finished, next; char string[80]; text MainMenu[8]; text STAIRSnames[101]; cls(); cursor(0,0); Status(db); /* Assign the main menu options. */ MainMenu[0] = "STAIRS/72C to Concordance Conversion Module"; MainMenu[1] = "Open a Concordance Database"; MainMenu[2] = "Examine Paragraph to Field Code Matches"; MainMenu[3] = "Browse the Database"; MainMenu[4] = "Load STAIRS/72C Data Set"; MainMenu[5] = "Index the Database"; MainMenu[6] = "Reindex the Database"; MainMenu[7] = "Concordance Information Retrieval System"; /* ** Initialize the 72C paragraph code array for ** paragraph code to Concordance field matches. */ if (db.documents >= 0) LoadNames(db,STAIRSnames); while(finished == FALSE) switch(next = menu(5, 14, 15, 62, MainMenu, next,"OEBLIRCZ")) { case 0: cls(); Status(db); break; /* 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); LoadNames(db,STAIRSnames); Status(db); next = 1; break; /* Display the STAIRS to Concordance field matches. */ case 2: EditParacodes(db,STAIRSnames); next = 2; break; case 3: query(db,0); browse(db); next = 3; break; case 4: Load72C(db,STAIRSnames); next = 4; break; case 5: index(db); next = 5; break; case 6: reindex(db); next = 6; break; case 'Z': if (Message("Zap the database Y/N?") == 'Y') zap(db); break; case 'M': /* Memory left in the system. */ case 8: string = "Memory available: "+trim(str(memavl(),9,0,',')); puts(0,80-len(string),string,MenuHighlight_); break; case F10: case 7: case -1: finished = TRUE; break; } } /* 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: Load72C * * Synopsis: Loads an 72C data set into a Concordance data * * base. The 72C file has been converted to ASCII * * and downloaded from the mainframe to PC. * ****************************************************************/ Load72C(int db; text STAIRSnames[]) { int key, line, field, i, total, file, start; int loaded; 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("72C 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) and (key <> 27)) { puts(13,61,str(line = line + 1,8,0,','),MenuColor_); if (string[0]) { if (substr(string,1,3) == "***") { if (loaded) append(db); blank(db); puts(14,50,"Documents: "+str(db.documents,8,0,','),MenuColor_); puts(15,50,"Loaded: "+str(total,8,0,','),MenuColor_); total = total + 1; } else { if (string[0] <> ' ') field = FindField(db, string, STAIRSnames, field); Store(db,field,substr(string,4)); loaded = TRUE; } while(keypress()) if ((key = getkey()) == ESC) key = AreYouSure(); } } /* 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(total = total + 1,8,0,','),MenuColor_); } /* Clean up and save statistics to 72CLOAD.LOG file. */ close(file); start = (clock() - start)/1000; SaveStats("72C load time: "+str(start,10,0,',')+" seconds."); restore(12,49,screen); } } /* Load72C() */ /**************************************************************** * Name: Store * * Synopsis: Stores the data in the proper field. Date and * * numeric data is converted before being stored. * ****************************************************************/ Store(int db, field; text string) { int value; switch(db.type[field]) { case 'P': db->field = db->field+string+CRLF; break; case 'T': db->field = trim(string); break; case 'N': db->field = num(string); break; case 'D': /* Convert YYMMDD format to CCYYMMDD format. */ if (len(string) < 8) string = "19" + string; memcpy(db->field,string,8); break; default: break; } } /* Store() */ /**************************************************************** * Name: FindField * * Synopsis: Scans through the list of field 72C/STAIRS * * field names to find a match for the field name * * in the string just read from file. * ****************************************************************/ FindField(int db; char line[]; text names[]; int field) { int i, code; char string[10]; string = upper(substr(line,1,3)); /* Scan through the list and find an exact match for */ /* the STAIRS field code with the Concordance name. */ for(i = field+1; i <= db.fields; i = i + 1) if (string == names[i]) return(i); for(i = 1; i <= field; i = i + 1) if (string == names[i]) return(i); /* No match was made. Scan through the list once more */ /* to see if the field code falls within a range. */ if ((code = num(string)) > 0) { /* This is a subfield, start it on the next line. */ line = substr(line,1,3)+chr(CR)+chr(LF)+addr(line,4); for(i = 1; i <= db.fields; i = i + 1) if (num(names[i]) and (code < num(names[i]))) return(i - 1); /* The range check will fail for the last field. */ /* If the field code fell through here, it must go */ /* into the last field, return that field's number. */ return(db.fields); } /* The item isn't a field code. Return a zero to indicate no match. */ return(0); } /* FindField() */ /**************************************************************** * Name: LoadNames * * Synopsis: Loads a text array with the STAIRS field names. * * These names are the last three characters of * * field Concordance data base field names. * ****************************************************************/ LoadNames(int db; text STAIRSname[]) { int i, error, fh; char string[256]; /* Initialize the array by clearing out the names. */ for(i = 0; i < sizeof(STAIRSname) / sizeof(STAIRSname[0]); i = i + 1) STAIRSname[i] = ""; if (db.documents < 0) Message("Please open a database first."); else { if ((fh = open(db.database+".72C","r")) == EOF) Message("Couldn't open "+db.database+".72C"); else { i = 0; while(readln(fh,string) <> EOF) STAIRSname[i = i + 1] = trim(substr(string,1,3)); close(fh); } } } /* LoadNames() */ /**************************************************************** * Name: AreYouSure * * Synopsis: Asks the user if they want to abort loading. * ****************************************************************/ AreYouSure() { int key; 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(5,13,8,69); box(5,13,8,69,"DS", MenuColor_); puts(6,14,pad(message,'C',53),MenuColor_); key = getkey(); restore(5,13,screen); return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: SaveStats * * Synopsis: Save statistics to file with time & date stamp. * ****************************************************************/ SaveStats(text line) { int file, h, m, s, i; char string[80]; if ((file = open("72Cload.log","a+")) <> EOF) { time(h,m,s); string = str(h,2)+":"+str(m,2)+":"+str(s,2); for(i = 0; string[i]; i = i + 1) if (string[i] == ' ') string[i] = '0'; string = dtoc(today())+" "+string+" "; write(file,string,len(string)); writeln(file,line,len(line)); close(file); } } /* SaveStats() */ /**************************************************************** * 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 DIRS Database","*.dcb",string)) <> ESC) db = opendb(string); return(db); } /* OpenDatabase() */ /**************************************************************** * Name: EditParacodes * * Synopsis: Displays STAIRS to Concordance field matches. * * Description: The fields are displayed using a Concordance * * menu. The paragraph codes could be edited here * * if the function was modified. Enhancements * * include the ability to save and retrieve field * * name to paragraph code correlation files. * ****************************************************************/ EditParacodes(int db; text STAIRSnames[]) { text names[db.fields+2], screen; int i, elements; screen = save(8,20,22,66); names[0] = "STAIRS/Concordance Field Correlation"; for(i = 1; i <= db.fields; i = i + 1) names[i] = pad(STAIRSnames[i],'L',5)+db.name[i]; i = 1; while(i > 0) i = menu(8, 20, 20, 63, names, i); restore(8,20,screen); } /* EditParacodes() */ /**************************************************************** * Name: initialize * * Synopsis: Set global variables to initial values * * Action: Global variables are set for system calls * ****************************************************************/ int CTRLPGUP = 33792, F11 = 34048, F12 = 34304; 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, EOF = -1; char ESC = 27, CTRLP = 16, FALSE = 0, TRUE = 1, CR = 13, LF = 10; text CRLF = chr(CR)+chr(LF);