/* ** Concordance Programming Language ** ** Copyright (c) 2001 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: ** ** ImageCheck.cpl */ text gszImageCheck = "ImageCheck.cpl"; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { text pszMenu[7], pszMenu1, pszMenu2, pszMenu3, pszMenu4, pszDatabase, pszLogFile; int db, nImageKey, nEndImageKey, nNext, i, bDone = FALSE; /* Set up the menus */ pszMenu1 = "[1] Open database : "; pszMenu2 = "[2] Begin image key : "; pszMenu3 = "[3] End image key : "; pszMenu4 = "[4] Open log file : "; pszMenu[0] = gszImageCheck; pszMenu[3] = pszMenu3; pszMenu[4] = pszMenu4; pszMenu[5] = "[G] Go!"; pszMenu[6] = "[Q] Quit"; if (db.documents > 0) { /* Set the menu */ pszMenu[1] = pszMenu1 + FileName(db.database); /* Locate the image key */ nImageKey = 0; for (i = 1; i <= db.fields; i = i + 1) { if (db.image[i]) { nImageKey = i; break; } } /* Set the menu */ if (nImageKey <> 0) { pszMenu[2] = pszMenu2 + db.name[nImageKey]; nNext = 3; } else { pszMenu[2] = pszMenu2; nNext = 2; } } else { /* Set the menus */ pszMenu[1] = pszMenu1; pszMenu[2] = pszMenu2; nNext = 1; } /* Display the menu */ while (bDone == FALSE) { nNext = menu(5, 10, 14, 70, pszMenu, nNext,"1234GQ"); switch(nNext) { /* Quit */ case 0: bDone = TRUE; break; /* Open database */ case 1: /* Close the previous database */ closedb(db); db = EOF; /* Get the file name of the new database */ if (getfile("Open database", "*.DCB", pszDatabase) == CR) { /* Open the database */ if ((db = opendb(pszDatabase)) <> EOF) { /* Set the menu item */ pszMenu[1] = pszMenu1 + FileName(db.database); nNext = 2; nImageKey = 0; nEndImageKey = 0; pszMenu[2] = pszMenu2; pszMenu[3] = pszMenu3; /* Locate the image key */ nImageKey = 0; for (i = 1; i <= db.fields; i = i + 1) { if (db.image[i]) { nImageKey = i; break; } } /* Set the menu */ if (nImageKey <> 0) { pszMenu[2] = pszMenu2 + db.name[nImageKey]; nNext = 3; } else { pszMenu[2] = pszMenu2; nNext = 2; } } } break; /* Get image key */ case 2: if ((nImageKey = GetField(db, nImageKey)) <> 0) { pszMenu[2] = pszMenu2 + db.name[nImageKey]; nNext = 3; } else { pszMenu[2] = pszMenu2; nNext = 2; } break; /* Get end image key */ case 3: if ((nEndImageKey = GetField(db, nEndImageKey)) <> 0) { pszMenu[3] = pszMenu3 + db.name[nEndImageKey]; nNext = 4; } else { pszMenu[3] = pszMenu3; nNext = 3; } break; /* Get log file */ case 4: if (getfile("Open log file", "*.TXT", pszLogFile) == CR) { pszMenu[4] = pszMenu4 + FileName(pszLogFile); nNext = 5; } break; /* Go! */ case 5: ImageCheck(db, nImageKey, nEndImageKey, pszLogFile); break; /* Quit */ case 6: bDone = TRUE; break; } } } /**************************************************************** * Name: ImageCheck * * Synopsis: Main processing routine for this CPL * ****************************************************************/ ImageCheck(int db, nImageKey, nEndImageKey; text pszLogFile) { int fhLog, nPageCount, nPage, btDir = EOF, nData, nKey, bFoundImage, nErrorCount = 0; text pszBuffer, pszImageKey, pszPreviousDatabase, pszImagebase, pszFoundKey; /* Check to see if we have all the information */ if ((db == EOF) or (db.documents <= 0)) { messageBox("Please open a database first.", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); return; } if (nImageKey == 0) { messageBox("Please select an image key.", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); return; } if (nEndImageKey == 0) { messageBox("Please select an end image key.", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); return; } if (pszLogFile == "") { messageBox("Please select a log file.", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); return; } /* Open the log file */ if ((fhLog = open(pszLogFile, "w+")) <> EOF) { /* Write the header */ pszBuffer = "/* Image check - " + dtoc(today(), 'L') + " */"; writeln(fhLog, pszBuffer, len(pszBuffer)); writeln(fhLog, "", 0); writeln(fhLog, "", 0); /* Cycle through the database */ cycle(db) { /* Put up a status message */ puts(0,0,"Processing record " + str(docno(db)) + " of " + str(count(db))); if (db.database <> pszPreviousDatabase) { /* Close any previous imagebase */ if (btDir <> EOF) { btclose(btDir); btDir = EOF; } /* Construct the imagebase name */ pszImagebase = db.database + ".DIR"; /* Open the imagebase */ if ((btDir = btopen(pszImagebase)) == EOF) { messageBox("Unable to open imagebase (.DIR) file", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); break; } /* Set the new previous database */ pszPreviousDatabase = db.database; } /* Make sure both the bates end in a number */ if ((isdigit(substr(db->nImageKey, len(db->nImageKey), 1))) and (isdigit(substr(db->nEndImageKey, len(db->nEndImageKey), 1)))) { /* Get the page count */ nPageCount = GetNumberFromBates(db->nEndImageKey) - GetNumberFromBates(db->nImageKey) + 1; /* Cycle through the pages */ for (nPage = 0; nPage < nPageCount; nPage = nPage + 1) { /* Reset the flag */ bFoundImage = FALSE; /* Construct the image key */ pszImageKey = AddToBates(db->nImageKey, nPage); /* Locate the bates number in the imagebase */ if (btgte(btDir, pszImageKey, pszFoundKey, nData) <> -1) { /* See if the image key is part of the found key */ if (match(pszFoundKey, pszImageKey, 1) == 1) { /* Check to see if the image was immediately followed */ /* by a delimiter and started at the beginning. */ pszBuffer = substr(pszFoundKey, len(pszImageKey) + 1, 1); if ((pszBuffer == chr(9)) or (pszBuffer == "|")) bFoundImage = TRUE; } } if (bFoundImage == FALSE) { pszBuffer = "Unable to find the following image key in the imagebase: " + pszImageKey; writeln(fhLog, pszBuffer, len(pszBuffer)); nErrorCount = nErrorCount + 1; } } } /* Make sure the user didn't hit ESC */ if (nKey = keypress()) { getkey(); if (nKey == ESC) break; } } /* Close any open imagebase */ btclose(btDir); /* Write the count of errors */ writeln(fhLog, "", 0); pszBuffer = str(nErrorCount) + " error(s) found."; writeln(fhLog, pszBuffer, len(pszBuffer)); writeln(fhLog, "", 0); pszBuffer = "/* End of check */"; writeln(fhLog, pszBuffer, len(pszBuffer)); /* Close the log file */ close(fhLog); } else { /* Tell the user we were unable to open a log file */ messageBox("Unable to open or create the log file.", gszImageCheck, MB_OK | MB_ICONEXCLAMATION); } } /**************************************************************** * Name: GetNumberFromBates * * Synopsis: Gets the number * ****************************************************************/ GetNumberFromBates(text pszBates) { int i; char szBates[128]; szBates = pszBates; while ((i < len(pszBates)) and (isdigit(szBates[i]) == 0)) i = i + 1; return(num(substr(pszBates, i + 1))); } /**************************************************************** * Name: AddToBates * * Synopsis: Adds a number to the current bates number * ****************************************************************/ AddToBates(text pszBates; int nIndex) { int i, nLength; char szBates[128]; /* Get the length of the string */ szBates = pszBates; nLength = len(szBates); /* Loop backwards through the string and find the first non digit */ for (i = nLength - 1; i >= 0; i = i - 1) { if (isdigit(szBates[i]) == 0) break; } /* Construct the return value */ return(substr(szBates, 1, i + 1) + str(num(substr(szBates, i + 2)) + nIndex, nLength - i - 1, 0, 'Z')); } /**************************************************************** * 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: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[101]; text screen; if (db.documents >= 0) { field[0] = "Field Type "; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : field[i] = pad(db.name[i],'L',13)+ "Text "; case 'P' : field[i] = pad(db.name[i],'L',13)+ "Paragraph"; case 'N' : field[i] = pad(db.name[i],'L',13)+ "Numeric "; case 'D' : field[i] = pad(db.name[i],'L',13)+ "Date "; } i = db.fields + 1; screen = save(11,30,21,57); while(i > db.fields) i = menu(11, 30, 21, 57, field, next,""); restore(11,30,screen); if (i) next = i; } return(next); } /* GetField() */