/* * Concordance Programming Language Tags Management Program * * Copyright (c) 1994, 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) 1994 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1994 Dataflight Software, Inc. */ text namearray[102]; /* Holds the field names. */ int isWindows; /* TRUE if Windows version is running. */ int db; /* Database handle used by all functions. */ /**************************************************************** * Name: MAIN * ****************************************************************/ main() { text menulines[7], string; int finished, next; ver( string ); isWindows = match( upper( string ),"WINDOWS",1 ); menulines[0] = "Tag Saver Options"; menulines[1] = "Save tags"; menulines[2] = "Retrieve tags"; menulines[3] = "Print error log"; menulines[4] = "Open database"; menulines[5] = "Browse database"; menulines[6] = "Quit"; finished = 0; next = 1; cls(); Status( db ); while(finished == 0) { Status( db ); switch( next = menu( 0, 9, 9, 29, menulines, next, "SRPOBQX" )) { case 1 : if( db.documents < 0 ) { Message( "Open a database first.", 1 ); next = 4; break; } savetags(); next = 6; break; case 2 : if( db.documents < 0 ) { Message( "Open a database first.", 1 ); next = 4; break; } loadtags(); next = 5; break; case 3 : if( db.documents < 0 ) { Message( "Open a database first.", 1 ); next = 4; break; } CallWith( "Copy "+db.database+".ERR lpt1" ); next = 5; break; case 4 : /* Open a database if one isn't open. */ if( db.documents > 0 ) closedb( db ); if( getfile("Database", "*.DCB", string ) == 13 ) { db = opendb( string ); } Status( db ); next = 1; break; case 5 : if( db.documents < 0 ) { Message( "Open a database first.", 1 ); next = 4; break; } browse( db ); break; case 6 : finished = 1; break; case 'X' : default : ; } } } /** main() **/ /**************************************************************** * Name: InitMenu * * Synopsis: Initialize the field selection menu. * ****************************************************************/ InitMenu() { int i; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Text "; break; case 'P' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Full Text"; break; case 'N' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Numeric "; break; case 'D' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Date "; break; } /* Clear out the last menu item and set the menu title. */ namearray[i] = ""; namearray[0] = "Field Type "; } /** InitMenu() **/ /**************************************************************** * Name: RGB * * Synopsis: Convert red, green, blue values to a color. * ****************************************************************/ RGB(int 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) { messageBox(message, "Concordance Tag Saver Utility", 0); } /* Message() */ /**************************************************************** * Name: Normalize * * Synopsis: Remove underscores and capitalize field names. * * Return: Name of a field. * ****************************************************************/ normalize(text name) { char string[20]; int a, LastChar; string = name; for(a = 1; string[a]; a = a + 1) { if(string[a] == '_') string[a] = ' '; else if (LastChar <> ' ') string[a] = lower(string[a]); LastChar = string[a]; } return(string); } /** Normalize() **/ /**************************************************************** * Name: Status * * Synopsis: Displays data base and program name. * ****************************************************************/ Status( int db ) { cursoroff( ); 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: 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() **/ /**************************************************************** * 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: SAVETAGS * ****************************************************************/ savetags() { float percent; int i, tags, field, data, listFile, treeHandle; char string[256], key[200]; /* Open the Tag List */ treeHandle = btopen( string = db.database+".TAG" ); if( treeHandle < 0 ) return(Message("Error opening "+string,1)); if( btcount(treeHandle) < 0 ) return(Message("There are no TAGs in this database.",1)); /* Get the field name which can be used to find */ /* the record again. Must contain unique entries */ InitMenu(); field = menu( 5, 10, 20, 70, namearray, 1, "" ); /* option to test the field? */ cls(); Status( db ); /* Initialize the screen for status display */ /* while we are processing the data base. */ scroll(13,21,17,61,0,0,MenuColor_); box(13,21,18,63,"3D",MenuColor_); puts(14,23,"Processing tag",MenuColor_); puts(15,23,"Tag count",MenuColor_); puts(16,23,"Tags processed",MenuColor_); puts(16,59,"0%",MenuColor_); cursoroff(); listFile = open( db.database+".GAT", "w" ); writeln( listFile, db.name[field], len( db.name[field] ) ); writeln( listFile, str( btcount( treeHandle )), len( str( btcount( treeHandle )))); /* Cycle through the tags */ tags = 0; for( i = btfirst(treeHandle,key,data); i < btcount( treeHandle ); i = i + 1 ) { puts(14,50,str(data,10,0,','),MenuColor_); percent = (tags*1.0) / btcount( treeHandle ); puts(16,50,str(percent*100.0,10),MenuColor_); tags = tags + 1; puts(15,50,str( tags,10,0,','),MenuColor_); /* Must go to the accession number, not the record number. */ /* The tag file stores the accession number. */ gotoaccession(db, data); writeln( listFile, str(db->field), len( str(db->field ))); if( key ) writeln( listFile, str(key), len( str(key)) ); else writeln( listFile, "default", len( "default" )); btnext( treeHandle, key, data ); if (keypress()) { if (getkey() == 27 /*ESC*/) if (messageBox("Cancel processing?","Concordance Tag Saver", MB_YESNO) == IDYES) break; cursoroff(); } } cls(); btclose( treeHandle ); close( listFile ); query( db, -1 ); return; } /** savetags() **/ /**************************************************************** * Name: LOADTAGS * ****************************************************************/ loadtags() { float percent; int i, tags, field, total, listFile, type, errorLog; char string[200], stag[100]; /* Open the Tag List file */ close( listFile ); listFile = open( db.database+".GAT", "r" ); /* Open the tag file */ errorLog = open( db.database+".ERR", "w" ); /* Open the error log file */ if( listFile < 0 ) return(Message("Error opening TAG list file.",1)); /* Get the field name which can be used to find */ /* the record again. Must contain unique entries */ readln( listFile, string ); for( i = 1; i <= db.fields; i = i + 1 ) if( db.name[i] == string ) { field = i; type = db.type[i]; } /*zzz*/ if( field == 0 ) { string = string+" field does not exist."; writeln( errorLog, string, len( string ) ); i = messageBox(string+" Pick another?","Concordance Tag Saver", MB_YESNO); if( i == IDYES ) { /* Get the field name which can be used to find */ /* the record again. Must contain unique entries */ InitMenu(); field = menu( 5, 10, 20, 70, namearray, 1, "" ); type = db.type[field]; cls(); Status( db ); string = "Attempted to apply tags using the field "+db.name[field]; writeln( errorLog, string, len( string ) ); } else { string = "Aborted without applying any tags."; writeln( errorLog, string, len( string ) ); close( listFile ); close( errorLog ); return; } } readln( listFile, string ); total = num( string ); Status( db ); /* Initialize the screen for status display */ /* while we are processing the data base. */ scroll(13,21,17,61,0,0,MenuColor_); box(13,21,18,63,"3D",MenuColor_); puts(14,23,"Processing document",MenuColor_); puts(15,23,"Tag count",MenuColor_); puts(16,23,"Tags processed",MenuColor_); puts(16,59,"0%",MenuColor_); cursoroff(); /* Cycle through the tags and apply them to the database */ tags = 0; for( i = 0; i < total; i = i + 1 ) { tags = tags + 1; puts(14,50,str(recno(db),10,0,','),MenuColor_); percent = (tags*1.0) / total; puts(16,50,str(percent*100.0,10),MenuColor_); puts(15,50,str( tags,10,0,','),MenuColor_); query( db, -1 ); readln( listFile, string ); switch( type ) { case 'D' : case 'T' : case 'N' : search(db, db.name[field]+' = "'+string+ '" '); break; case 'P' : search( db, chr(34)+string+chr(34)+"."+db.name[field]+"." ); break; } readln( listFile, stag ); if( count( db ) > 0 ) { if( stag == "default" ) tag( db, 1 ); else tag( db, 1, stag ); } else { /* do error log (not found) stuff here */ /* make entry in the error log */ string = string+" not found."; writeln( errorLog, string, len( string ) ); } if( keypress() ) { if( getkey() == 27 /*ESC*/) if( messageBox("Cancel processing?","Concordance Tag Saver", MB_YESNO) == IDYES ) break; cursoroff(); } } cls(); close( listFile ); close( errorLog ); query( db, -1 ); return; } /** loadtags() **/ /**************************************************************** * Name: CallWith * * Synopsis: Uses either SYSTEM() for DOS, or SPAWN() for * Windows, to execute commands like REN and COPY * ****************************************************************/ CallWith( text string ) { if( isWindows ) { spawn( "command.com", "/C "+string+" > NUL" ); } else { system( string +" > NUL" ); } } /** CallWith() **/ /* 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; /* 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;