/* ** Concordance Programming Language Loads Opticon .DIR File to Concordance ** ** Copyright (c) 1994 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Bel Air, 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. */ /**************************************************************** * Name: optiload * * Synopsis: Loads an opticon image base to a Concodance * * database. This program looks for document breaks* * in Opticon's .DIR file and copies the image key * * to a Concordance record. It appends the record * * if it does not exist, no action is taken if the * * record exists. * ****************************************************************/ int isWindows; int darkPurple, lightPurple, black; main() { int db, i, rc, j, x, bt, fh, record, imageField, appended, cRecord; char string[256]; int tr = 8, tc = 13, tr = 3, tc = 56; int bk, fg; text pszImageKey; isWindows = match(upper(string),"WINDOWS" ,1); darkPurple = RGB(160,0,160); lightPurple = RGB(255,0,255); black = RGB(0,0,0); /* Must start with an opened database. */ if (db.documents < 0) return(Message("Please open your Concordance database first.",TRUE)); /* Verify that this is the correct database. */ if (Message("Use "+db.database+" for image keys? Y/N",TRUE) <> 'Y') return; /* Look for an image field. */ for (i = 1; i <= db.fields; i = i + 1) if (db.image[i]) { imageField = i; break; } if (imageField == 0) return(Message("Couldn't find an image field in "+db.database,TRUE)); /* Set the bit settings */ SetBitSettings(db.database + ".DIR"); if ((bt = btopen(db.database+".DIR")) < 0) return(Message("Couldn't open "+db.database+".dir",TRUE)); cursoroff(); box(4,12,8,70,"3D", darkPurple,lightPurple); box(5,13,7,69,"3U", darkPurple,lightPurple); j = 0; for(i = btfirst(bt, string, record); i == 0; i = btgt(bt, string, string, record)) { if (record & DOCBIT) { pszImageKey = string; if ((x = match(pszImageKey , chr(9), 1)) <> 0) pszImageKey = substr(pszImageKey , 1, x - 1); /* We have a document break, see if it is already in the database. */ j = db.query; rc = search(db, db.name[imageField] + " = "+ trim(pszImageKey)); if ((rc == 0) and (j <> db.query) and (count(db) == 0)) { /* This key does not exist in the database. */ /* Append it to the database. */ blank(db); db->imageField = trim(pszImageKey); append(db); appended = appended + 1; } query(db, -1); puts(6, 14, pad("Appended "+str(appended) + " in "+ str(cRecord = cRecord + 1)+"/"+str(btcount(bt)),'C',53), black, lightPurple); if (keypress()) { if (getkey() == ESC) rc = -1; } if (rc == -1) { if (Message("Cancel processing?",TRUE) == 'Y') break; cursoroff(); } } } } /* main() */ 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; cursoroff(); if (wait) screen = save(4,12,9,70); /* If this isn't the windows version of Concordance, */ /* the box() function will produce a drop shadowed box */ /* ignoring the background color parameters. */ if (isWindows == FALSE) { darkPurple = MenuColor_; black = MenuColor_; } /* IMPORTANT Note Regarding Boxes */ /* Windows introduces an new box() parameter */ /* to display raised and lowered boxes: "3D" */ /* or "3U". These display a 3-D looking box */ /* that either looks pushed down or up. */ /* Note that a drop shadowed box in DOS is */ /* always specified two columns wider and one */ /* row deeper to acommodate the shadow. This */ /* is not required for the Windows 3D mode. */ /* box() will use dark purple for the shadow, */ /* and light purple to fill and clear the box. */ /* Draw a large dropped box with a raised box */ /* displayed in its center. */ box(4,12,8,70,"3D", darkPurple,lightPurple); box(5,13,7,69,"3U", darkPurple,lightPurple); puts(6,14,pad(message,'C',53),black,lightPurple); while(keypress()) getkey(); if (wait) { key = getkey(); restore(4,12,screen); } return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: SetBitSettings() * * Synopsis: Sets the bit settings depending on DIR version. * ****************************************************************/ SetBitSettings(text pszFile) { int fhDir, nVersion; char szVersion[3]; /* Open the file */ if ((fhDir = open(pszFile, "r")) <> EOF) { /* Seek to the 24th byte */ lseek(fhDir, 24, 'B'); /* Read the next 2 bytes */ read(fhDir, szVersion, 2); nVersion = 1; if (szVersion[0] >= 3) nVersion = 3; else { if (szVersion[0] >= 2) nVersion = 2; else { if ((szVersion[0] == 1) and (szVersion[1] > 48)) nVersion = 2; } } /* Set the bit settings */ switch (nVersion) { case 1: VOLUMEBITS = 16383; BOXBIT = 16384; FOLDERBIT = 32768; DOCBIT = 65536; PAGEBITS = -131072; PAGEBIT = 131072; break; case 2: VOLUMEBITS = 131071; BOXBIT = 131072; FOLDERBIT = 262144; DOCBIT = 524288; PAGEBITS = -1048576; PAGEBIT = 1048576; break; case 3: VOLUMEBITS = 536870911; BOXBIT = 536870912; FOLDERBIT = 1073741824; DOCBIT = 2147483648; PAGEBITS = -4294967296; PAGEBIT = 4294967296; break; } /* Close the file */ close(fhDir); } return(nVersion); } /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ /* findfirst() file attributes. _A_NORMAL 00 Normal file - No read/write restrictions _A_RDONLY 01 Read only file _A_HIDDEN 02 Hidden file _A_SYSTEM 04 System file _A_VOLID 08 Volume ID file _A_SUBDIR 16 Subdirectory _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, CR = 13, LF = 10; int64 VOLUMEBITS; int64 BOXBIT; int64 FOLDERBIT; int64 DOCBIT; int64 PAGEBITS; int64 PAGEBIT;