/* ** Concordance Programming Language ** ** Copyright (c) 1995 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: ** ** PRINTQRY.CPL ** Written by Paul Mitsui 10/08/96 ** Version 1.0 */ int isWindows, darkPurple, lightPurple, black; /*****************************************************/ /* Function: CalcPages */ /* Purpose : Calculates number of pages in doc */ /*****************************************************/ CalcPages(int btDir; text szImageBuffer) { int data, pages, error; text szKey; /* Initialize the key */ szKey = szImageBuffer; /* Locate the key in the DIR file */ btfind(btDir, szKey, data); /* Initialize page count (at least 1) */ pages = 1; /* Move to the next key */ error = btnext(btDir, szKey, data); /* Loop until next document break */ while (((data & DOCBIT) == 0) and (error <> -1)) { pages = pages + 1; error = btnext(btDir, szKey, data); } /* Go back to the original place */ btfind(btDir, szImageBuffer, data); return (pages); } /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { int db, fh, i, j, k, imageField, printPageCount, printImageKey, useDocBreaks, btDir, pageCount, pageNumber, data, startDoc, endDoc; text szFile, szImageKey, szPrintRedlines, szPageCount, szImageBuffer, string; char buffer[512]; /* Initialize variables and clear the screen */ ver(string); isWindows = match(upper(string),"WINDOWS" ,1); darkPurple = RGB(0,0,160); lightPurple = RGB(0,0,255); black = RGB(255,255,255); cursoroff(); cursor(0,0); Pcls(rep("ΔΕ", (MaxCol_ + 1) / 2)); /* Check to see if database is open */ if (db.documents <= 0) return(Message("Please open database first. ", TRUE)); /* Put a status */ puts(0,0,db.database); puts(1,0,"Number of active documents: " + str(count(db))); /* Open the dir file */ if ((btDir = btopen(db.database + ".DIR")) == EOF) return(Message("Could not open .DIR file. ", TRUE)); /* Create text file */ if (getfile("Save image file", "*.TXT", szFile) == CR) fh = open(szFile, "w+"); else return(Message("Operation cancelled. ", TRUE)); /* 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("No image field. ", TRUE)); /* Ask for the beginning range */ i = TRUE; while (i == TRUE) { puts(6,14,"Enter beginning docoument: "); startDoc = getNumber(6, 42, 9); puts(6,14,"Enter ending document : "); endDoc = getNumber(6, 42, 9); if ((startDoc > 0) and (endDoc > 0) and (endDoc >= startDoc) and (endDoc <= count(db))) { i = FALSE; if (Message("Print " + str(startDoc) + " to " + str(endDoc) + "? ", TRUE) <> 'Y') i = TRUE; } } /* Ask user to print redlines */ if (Message("Print redlines? ", TRUE) == 'Y') szPrintRedlines = "TRUE"; /* Ask user to print page count */ if (Message("Print page count? ", TRUE) == 'Y') printPageCount = TRUE; /* Ask user to print image key */ if (Message("Print image key? ", TRUE) == 'Y') printImageKey = TRUE; /* Ask user to use doc breaks */ if (Message("Use document breaks? ", TRUE) == 'Y') useDocBreaks = TRUE; /* Place a display box */ Message("", FALSE); /* Cycle through the current query */ for(k = goto(db, startDoc); ((k > 0) and (docno(db) <= endDoc)); k = next(db)) { /* Clear the buffer */ memset(buffer, 0, sizeof(buffer)); pageNumber = 1; /* Get the image key */ szImageKey = db->imageField; /* Search for the key */ btgte(btDir, szImageKey, szImageBuffer, data); /* Calculate how many pages in image */ if (useDocBreaks) pageCount = CalcPages(btDir, szImageBuffer); else pageCount = 1; /* Cycle for the number of pages */ for (i = 1; i <= pageCount; i = i + 1) { /* Just get the image key */ j = match(szImageBuffer, "|", 1); if (j > 0) szImageKey = substr(szImageBuffer, 1, j - 1); else { j = match(szImageBuffer, ".", 1); szImageKey = substr(szImageBuffer, 1, j - 1); } /* Set up page count string */ if (printPageCount) szPageCount = str(i) + " of " + str(pageCount); else szPageCount = ""; /* Set up buffer to write */ buffer = db.database + "," + szImageKey + "," + "1" + "," + szPrintRedlines + "," + "," + "," + szPageCount + "," + "," + (printImageKey ? szImageKey : ""); /* Write buffer to disk */ if (writeln(fh, buffer, len(buffer)) == EOF) { Message("Disk full. ", TRUE); break; } /* Move to the next page */ btnext(btDir, szImageBuffer, data); } /* What's the status? */ puts(6,14,pad("Processing document " + str(docno(db)) + " of " + str(count(db)),'C',55),black,lightPurple); } /* Close the files */ btclose(btDir); close(fh); } /**************************************************************** * Name: Pcls * * Synopsis: Clears the screen to the pattern parameter. * ****************************************************************/ Pcls(text pattern) { int i; int oldBackground; if (isWindows) cls(RGB(170,0,170)); else { for(i = 0; i <= MaxRow_; i = i + 1) puts(i,0,pattern); } } /* Pcls() */ /**************************************************************** * Name: RGB * * Synopsis: Helper routine for Windows color creation. * ****************************************************************/ 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) { 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_; } /* 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',55),black,lightPurple); if (wait) { key = getkey(); restore(4,12,screen); } return(asc(upper(chr(key)))); } /* Message() */ /*****************************************************/ /* Function: getNumber */ /* Purpose : Return the number at row, col, width */ /*****************************************************/ getNumber(int row, col, width) { char key; int thenumber; while ((key <> CR) and (key <> ESC)) key = getnumber(row, col, thenumber, 0, 999999999, width, 0, MenuColor_); return(thenumber); } /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ 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; /* Here are the bits, directly from Opticon. */ /* The volumeKey is low bits, pages are high bits. */ int VOLUMEBITS = 16383; int BOXBIT = 16384; int FOLDERBIT = 32768; int DOCBIT = 65536; int PAGEBITS = -131072; /* All page bits set on. */ int PAGEBIT = 131072; /* Single page set on. */