/* Program copyright Dataflight Software, Inc. 1994. ALL RIGHTS RESERVED. */ /**************************************************************** * Name: LOAD64K * * Synopsis: Loads a marked plain text file to a Concordance * * database exactly as detailed in the Concordance * * manual for the Convert utility, except that it * * will flow any text over the 64K field limit to * * the next Paragraph field. This will only happen * * if the next field is a Paragraph field. * * Notes: With the above exception, see the description * * of the Convert utility in the Concordance * * manual. * ****************************************************************/ char szDelimiter[60]; main() { int db, finished, next; char string[80]; text MainMenu[8]; szDelimiter = "***"; cls(); cursor(0,0); Status(db); /* Assign the main menu options. */ MainMenu[0] = "Load 64K+ Marked Text Files"; MainMenu[1] = "Open a Concordance Database"; MainMenu[2] = "Browse the Database"; MainMenu[3] = "Enter a New Delimiter"; MainMenu[4] = "Load Marked Text File"; MainMenu[5] = "Help on the Load 64K Program"; MainMenu[6] = "Return to Concordance"; while(finished == FALSE) switch(next = menu(5, 14, 14, 62, MainMenu, next,"OBELHRZM")) { 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); Status(db); next = 1; break; case 2: query(db,0); browse(db); next = 2; break; case 3: GetInfo( 7, 12, 9, 12 + sizeof(szDelimiter), "Delimiter: ", szDelimiter); next = 3; break; case 4: Load64K(db); next = 4; break; case 'Z': if (Message("Zap the database Y/N?") == 'Y') zap(db); break; case 'M': /* Memory left in the system. */ string = "Memory available: "+trim(str(memavl(),9,0,',')); puts(0,80-len(string),string,MenuHighlight_); break; case F1: case 5: help(db); next = 5; break; case F10: case 6: case -1: finished = TRUE; break; } } /* main() */ /**************************************************************** * Name: help * * Synopsis: Displays some help information about program. * ****************************************************************/ help(int db) { box( 9, 9, 17, 59,'DD',MenuColor_,MenuBackground_); puts(10,10,"Loads a marked plain text file to a Concordance",MenuColor_,MenuBackground_); puts(11,10,"database exactly as detailed in the Concordance",MenuColor_,MenuBackground_); puts(12,10,"manual for the Convert utility, except that it ",MenuColor_,MenuBackground_); puts(13,10,"will flow any text over the 64K field limit to ",MenuColor_,MenuBackground_); puts(14,10,"the next Paragraph field. This will only happen",MenuColor_,MenuBackground_); puts(15,10,"if the next field IS a Paragraph field. ",MenuColor_,MenuBackground_); getkey(); cls(); Status(db); } /* help() */ /**************************************************************** * Name: GetInfo * * Synopsis: Helper routine to prompt user for information. * ****************************************************************/ GetInfo(int trow,tcol,brow,bcol; text prompt; char string[]) { text screen; int key; char oldstring[sizeof(string)]; screen = save(trow,tcol,brow,bcol); scroll(trow,tcol,brow,bcol,0,0,TextHighlight_); box(trow,tcol,brow,bcol,'s',TextHighlight_); key = 0; puts(trow,tcol+1,prompt,TextHighlight_); oldstring = string; while((key <> CR) and (key <> ESC)) key = getline(trow+1,tcol+1,sizeof(oldstring),oldstring,TextHighlight_); if (key <> ESC) string = oldstring; restore(trow,tcol,screen); } /* GetInfo() */ /**************************************************************** * 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: FindField * * Synopsis: Scans through the fields in the database to find* * a match for the passed parameter. * * Returns: Returns the field number for the matching field * * or the last field number used if no match was * * found. * ****************************************************************/ FindField( int db; char line[], field ) { int i, old; old = field; if (i = match(line,":",1)) { if (field = isfield(db, upper(substr(line,1, i - 1)))) { /* Skip past ": " or ":" as necessary. */ if (asc(addr(line,i + 2)) == ' ') line = substr(line,i + 2); else line = substr(line,i + 1); } else field = old; } return( field ); } /* FindField() */ /**************************************************************** * 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("64Kload.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 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 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); /**************************************************************** * Name: Load64K * * Synopsis: Loads an 64K marked text file into a Concordance* * database. The conforms to the format described * * in the manual for the Concordance Convert * * utility. * ****************************************************************/ Load64K(int db) { 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("64K+ 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_); /* post line # */ if (string[0]) { if (substr(string,1,3) == szDelimiter) { 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 (isalpha(string[0])) field = FindField(db, string, field); field = Store(db, field, string); 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 64KLOAD.LOG file. */ close(file); start = (clock() - start)/1000; SaveStats("64K load time: "+str(start,10,0,',')+" seconds."); restore(12,49,screen); } } /* Load64K() */ /**************************************************************** * 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) { if (field) { switch(db.type[field]) { case 'P': if (len(db->field) >= 62500) { /* This field is almost full, see if we should flow */ /* the text in to the next available paragraph field. */ if (field + 1 <= db.fields) { if (db.type[field + 1] == 'P') { field = field + 1; string = CRLF + string; } } } 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. */ db->field = ctod(string); break; default: break; } } return(field); } /* Store() */