/* * Concordance Programming Language Phrase (hitlist) Report. * * Copyright (c) 1999 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077 * * 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) 1999 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1991 Dataflight Software, Inc. */ /*************************************************************** * Name: Phrase reporting. * * Synopsis: Creates a database with a hit list of phrases. * ***************************************************************/ main() { int finished, next, i, key; char string[256]; cls(); cursor(0,0); PhraseReport(0); } /* main() */ /**************************************************************** * Name: PhraseReport * * Synopsis: Creates a database with the exploded sort field.* ****************************************************************/ PhraseReport(int db) { int field, delimiter; int i, phrases; float total; char string[256]; text fields[101]; text screen; /* Make sure this database is the one the user wants. */ if (db.documents >= 0) if (Message("Use "+FileName(db.database)+" as the database?", MB_ICONQUESTION | MB_YESNO) <> IDYES) closedb(db); /* Make sure a database is open and ready for use. */ if (db.documents < 0) if (getfile("Database","*.DCB",string) == CR) db = opendb(string); /* Return if no database has been opened for use. */ if (db.documents < 0) return; /* Copy all the field names to a list for display. */ for(i = 1; i <= db.fields; i = i + 1) { fields[i] = pad(db.name[i],'L',18); switch(db.type[i]) { case 'D': fields[i] = fields[i]+"Date"; case 'P': fields[i] = fields[i]+"Paragraph"; case 'N': fields[i] = fields[i]+"Numeric"; case 'T': fields[i] = fields[i]+"Text"; } } /* Now get the field number to explode. */ /* Display them in a menu() and ask the user. */ fields[0] = "Select Authority Field"; field = db.fields + 1; screen = save(7,24,18,55); /* Prompt in a loop to value check. Ignore LEFT, ** RIGHT, and function keys that the user may type. */ while(field > db.fields) { if ((field = menu(7, 24, 18, 55, fields, 1)) <= db.fields) { /* if statement added in the concordw version */ if ((field <> 0) and (db.type[field] <> 'P') and (db.type[field] <> 'T') and (field <= db.fields)) { Message("Please select a paragraph or text field.", MB_ICONEXCLAMATION); field = db.fields + 1; } } } restore(7,24,screen); /* Quit if the user pressed the [Esc] key. */ if (field == 0) return; /* Now get the delimiter to use. Show the first record ** in the data base and allow the user to move between ** records with the cursor control keys. */ box(5,0,MaxRow_-1,79,'3D',MenuColor_); puts(4,1,db.name[field],MenuColor_); puts(MaxRow_,0,pad("[PgDn]Next [PgUp]Previous [Home]First [End]Last",'L',80),MenuColor_); puts(0,0,pad("Select the delimiter:",'L',80)); while(delimiter == 0) { i = TextColor_; TextColor_ = MenuColor_; show(db->field, 5,1,MaxRow_-3,76,1); TextColor_ = i; cursor(0,11); cursoron(); switch(i = getkey()) { case HOME:first(db); break; case END: last(db); break; case PGUP:prev(db); break; case PGDN:next(db); break; case ESC: delimiter = i; break; default: /* Here's where we check for a valid delimiter character. */ /* Extended ASCII and alphanumeric values are illegal, beep. */ if (((delimiter = i & 255) == 0) or isalnum(delimiter)) { beep(0,0); delimiter = 0; } else { /* Valid delimiter was typed, display it and confirm with user. */ puts(0,11,chr(delimiter),MenuColor_); if (Message("Use "+chr(delimiter)+" in field "+db.name[field]+"?", MB_ICONQUESTION | MB_YESNO) <> IDYES) delimiter = 0; } break; } } cls(); if (delimiter == ESC) return; /* We have all of the information, create the list. */ cursoroff(); total = count(db); box(5, 1, 7, 20,"3D", RGB(160,160,160), RGB(190, 190, 190)); puts(6, 3,"Processing % ", RGB(0,0,0), RGB(190,190, 190)); phrases = CreatePhraseDB(db, field); if (phrases < 0) messageBox("Couldn't open or create the phrase database.", "Phrases.cpl", MB_ICONSTOP | MB_OK); else { cycle(db) { puts( 6,15,str(docno(db)*100/total,3), RGB(0,0,0), RGB(190, 190, 190)); query(phrases, -1, string); if ((i = insert(db,field,delimiter, phrases)) == ESC) break; } close(phrases); } return(i); } /* btExplode() */ /**************************************************************** * Name: CreatePhraseDB * ****************************************************************/ CreatePhraseDB(int db, field) { text n[15]; /* Name of field in database. */ char t[15], /* Field type indicator. */ l[15], /* Field length value. */ p[15], /* Number of places in numbers. */ f[15], /* Format of numeric fields. */ k[15]; /* Key field indicator. */ char string[256]; int pdb, rc; string = capitalize(db.database + "-Phrases for " + db.name[field]); rc = IDYES; pdb = EOF; if ((pdb = opendb(string)) > EOF) { rc = messageBox("The phrase database "+string+ " already exists."+newline() + newline() + "I need to delete it so that I can proceed."+ newline() + "Can I delete it?", "Phrases", MB_ICONQUESTION | MB_YESNO); if (rc == IDYES) zap(pdb); else { closedb(pdb); pdb = EOF; } } else { n[0] = "PHRASE"; t[0] = 'P'; l[0] = 16; p[0] = 0; f[0] = 0; k[0] = TRUE; n[1] = "HITS"; t[1] = 'N'; l[1] = 10; p[1] = 0; f[1] = 'C'; k[1] = TRUE; n[2] = "DOCUMENTS"; t[2] = 'N'; l[2] = 10; p[2] = 0; f[2] = 'C'; k[2] = TRUE; n[3] = "LASTDOCUMENT"; t[3] = 'N'; l[3] = 10; p[3] = 0; f[3] = 'C'; k[3] = FALSE; createdb(string,n,t,l,p,f,k); pdb = opendb(string); } return(pdb); } /* CreatePhraseDB() */ /**************************************************************** * Name: insert * * Synopsis: Parses the field, inserting each entry into the * * b+tree file. Stores the document number as the * * key's data element. * * Returns: Watches for the user pressing the Escape key. * * Returns value of key pressed. Returns ESC to * * signal a disk full condition. * ****************************************************************/ insert(int db,field,delimiter, database) { int i, j, k; char string[200]; text ch; ch = chr(delimiter); if (len(trim(db->field))) { /* Loop through the field storing the substrings. */ wrap(db->field,31000); i = 1; while(j = match(db->field,ch,i)) { string = trim(substr(db->field,i,j-i)); search(database, 'PHRASE = "'+string+'" '); if (count(database) == 0) { blank(database); database->PHRASE = string; } database->HITS = database->HITS + 1; if (database->LASTDOCUMENT <> accession(db)) { database->LASTDOCUMENT = accession(db); database->DOCUMENTS = database->DOCUMENTS + 1; } if (count(database) == 0) append(database); i = j + 1; while(isspace(addr(db->field,i))) i = i + 1; } /* The parsing loop ended, store the field's last entry. */ string = trim(substr(db->field,i)); if (len(string)) { search(database, 'PHRASE = "'+string+'" '); if (count(database) == 0) { blank(database); database->PHRASE = string; } database->HITS = database->HITS + 1; if (database->LASTDOCUMENT <> accession(db)) { database->LASTDOCUMENT = accession(db); database->DOCUMENTS = database->DOCUMENTS + 1; } if (count(database) == 0) append(database); } } /* Check for a user cancellation with the ESCape key. */ i = 0; while(keypress()) if (getkey() == ESC) if (Message("Cancel processing?", MB_ICONQUESTION | MB_YESNO) == IDYES) i = ESC; return(i); } /* insert() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; if (i = match(name,":",1)) name = substr(name,i+1); while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /**************************************************************** * Name: Path * * Synopsis: Returns the path up to the last \ and without * * the file's name. * ****************************************************************/ Path(text dosPath) { int i, j; if ((i = match(dosPath,":",1)) == 0) i = match(dosPath,"\",1); while(j = match(dosPath,"\",i+1)) i = j; return(substr(dosPath,1,i)); } /* Path() */ RGB(char red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); } /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int wait) { text screen; int key; int fg, bk, tr, tc; if (wait) { eval('fg = messageBox(message, "Concordance", wait);', key); if (key == 0) return(fg); } tr = 8; tc = 13; bk = RGB(255,0,255); fg = RGB(160,0,160); cursoroff(); if (wait) screen = save(tr, tc, tr + 3, tc + 56); box(tr , tc , tr + 2, tc + 54,"3U", fg, bk); puts(tr + 1,tc + 1,pad(message,'C',53), RGB(255,255,255) ,bk); if (wait) { while(keypress()) getkey(); key = getkey(); restore(tr,tc,screen); } return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ /* findfirst() file attributes. */ int A_NORMAL = 00; /* Normal file - No read/write restrictions */ int A_RDONLY = 01; /* Read only file */ int A_HIDDEN = 02; /* Hidden file */ int A_SYSTEM = 04; /* System file */ int A_VOLID = 08; /* Volume ID file */ int A_SUBDIR = 16; /* Subdirectory */ int 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, TAB = 9, CR = 13, LF = 10; /* 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; /**********************************************************/ /* The first byte of every entry in the database.TRK file */ /* indicates the type of log entry and the type of event. */ /**********************************************************/ int LOGDELETION = 'D'; int LOGDELETION_OLD = 1 ; int LOGFIELDEDITED = 2 ; int LOGTAGADDED = 4 ; int LOGTAGDELETED = 8 ; int LOGEVENTSDELETED = 'P'; int LOGREINDEX = 'R'; int LOGSECURITYDELETION = 'S';