/* ** Concordance Programming Language ** ** Copyright (c) 2002 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: ** ** Issue2Tag.cpl */ text gszIssue2Tag = "Issue2Tag.cpl"; /************************************************************************** * Function: Main * Purpose : Entry point for all programs **************************************************************************/ main() { int db, nError, bCancelProcessing, btIssues, nCurrentAnnotation, nTotalAnnotations, btNotesTag, nData, bDeleteEmptyNotes; text pszOldDatabase, pszIssuesBtree, pszIssue; /* Tell the user what this CPL will do */ messageBox("This CPL will convert all issues from the current query into tags. Any existing issues will be deleted." + newline() + "Please make a backup copy of your database first.", gszIssue2Tag, MB_OK); /* Ask the user if they want to delete empty notes */ if (messageBox("Do you want delete any empty notes?", gszIssue2Tag, MB_ICONQUESTION | MB_YESNO) == IDYES) bDeleteEmptyNotes = TRUE; /* Initialize variables. Unnecessary, but good to do. */ nError = 0; bCancelProcessing = FALSE; btIssues = EOF; /* Cycle through the current query */ cycle(db) { /* Put up a status message */ puts(0, 0, "Processing record " + str(docno(db)) + " of " + str(count(db))); /* Check to see if the database changed */ if (db.database <> pszOldDatabase) { /* Close the old temp b-tree */ if (btIssues <> EOF) { btclose(btIssues); erase(pszIssuesBtree); btIssues = EOF; } /* Create a new temporary b-tree containing all */ /* issues for the current notes database. */ pszIssuesBtree = db.database + "-temp issues.lst"; if ((btIssues = btcreate(pszIssuesBtree, FALSE)) <> EOF) { /* Copy the tags from the notes file */ if (CopyIssues(db, btIssues)) bCancelProcessing = TRUE; } else { /* Tell the user there was an error creating the file and exit */ messageBox("There was an error while trying to create the following temporary file." + newline() + newline() + pszIssuesBtree + newline() + newline() + "Please check to make sure this file does not already exist and then re-run this program.", gszIssue2Tag, MB_ICONEXCLAMATION | MB_OK); bCancelProcessing = TRUE; } /* Save the old database */ pszOldDatabase = db.database; } /* Get the annotation count */ nCurrentAnnotation = nTotalAnnotations = annotationCount(db); /* Cycle backwards through the annotations. This is so we can delete an annotation if necessary. */ for (nError = annotationGoto(db, nCurrentAnnotation); (nError == 0) and (bCancelProcessing == FALSE) and (nCurrentAnnotation > 0); nError = annotationGoto(db, nCurrentAnnotation)) { /* Cycle through the list of issues */ for (nError = btfirst(btIssues, pszIssue, nData); nError == 0; nError = btnext(btIssues, pszIssue, nData)) { /* See if the current annotation is tagged with this issue */ if (annotationIsTagged(db, pszIssue)) { /* Untag the issue */ annotationTag(db, FALSE, pszIssue); /* Tag the issue to the document */ tag(db, TRUE, pszIssue); } } /* Delete empty notes or scan backwards to the previous annotation */ if (bDeleteEmptyNotes) { /* Check to see if there is text or an attachment */ if ((annotationRetrieve(db, "NOTETEXT") == "") and (annotationRetrieve(db, "NOTEATTACHED") == "")) { /* Delete the annotation */ annotationDelete(db); /* Reset the count */ if (nCurrentAnnotation == nTotalAnnotations) nCurrentAnnotation = nTotalAnnotations = annotationCount(db); else nCurrentAnnotation = nCurrentAnnotation - 1; } else nCurrentAnnotation = nCurrentAnnotation - 1; } else nCurrentAnnotation = nCurrentAnnotation - 1; } /* If we exited prematurely, or the user hit Cancel, exit the program */ if (bCancelProcessing == TRUE) break; if (keypress()) { if (getkey() == ESC) break; } } /* Close and delete any temporary files */ if (btIssues <> EOF) { btclose(btIssues); erase(pszIssuesBtree); btIssues = EOF; } } /************************************************************************** * Function: CopyIssues * Purpose : Copies issues from the tag file into a destination list file. **************************************************************************/ CopyIssues(int db, btDestination) { int btIssues, nError, nData; text pszIssue; /* Try and open the notes tag file */ if ((btIssues = btopen(db.database + "-notes.tag")) <> EOF) { /* Cycle through the tag file */ for (nError = btfirst(btIssues, pszIssue, nData); nError == 0; nError = btgte(btIssues, pszIssue, pszIssue, nData)) { /* Insert the tag into the file */ btinsert(btDestination, pszIssue, nData); /* Concatenate a space to skip over all tags to the next tag */ pszIssue = pszIssue + " "; } /* Close the notes tag file */ btclose(btIssues); nError = FALSE; } else { /* Tell the user we were unable to open the notes tag file */ messageBox("Unable to open the notes tag (issue) file. Most likely there are no issues attached to this database.", gszIssue2Tag, MB_ICONEXCLAMATION | MB_OK); nError = TRUE; } return(nError); }