/* ** 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: ** ** Issue2Field.cpl */ text gszIssue2Field = "Issue2Field.cpl"; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { text pszMenu[6], pszMenu1, pszMenu2, pszMenu3, pszDatabase, pszDelimiter; int db, nField, nNext, bDone; /* Set up the menus */ pszMenu1 = "[1] Open database : "; pszMenu2 = "[2] Issue field : "; pszMenu3 = "[3] Delimiter : "; pszMenu[0] = gszIssue2Field; pszMenu[1] = pszMenu1; pszMenu[2] = pszMenu2; pszMenu[3] = pszMenu3; pszMenu[4] = "[G] Go!"; pszMenu[5] = "[Q] Quit"; if (db.documents > 0) { pszMenu[1] = pszMenu1 + FileName(db.database); nNext = 2; } /* Display the menu */ while (bDone == FALSE) { nNext = menu(5, 10, 13, 70, pszMenu, nNext,"123GQ"); switch(nNext) { /* Quit */ case 0: bDone = TRUE; break; /* Open database */ case 1: /* Get the file name of the new database */ if (getfile("Open database", "*.DCB", pszDatabase) == CR) { /* Close the previous database */ closedb(db); db = EOF; /* Open the database */ if ((db = opendb(pszDatabase)) <> EOF) { /* Set the menu item */ pszMenu[1] = pszMenu1 + FileName(db.database); pszMenu[2] = pszMenu2; nNext = 2; nField = 0; } } break; /* Get the field */ case 2: if ((nField = GetField(db, nField)) <> 0) { if (db.type[nField] == 'P') { pszMenu[2] = pszMenu2 + db.name[nField]; nNext = 3; } else { messageBox("Please select a Paragraph field.", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); pszMenu[2] = pszMenu2; nField = 0; nNext = 2; } } else { pszMenu[2] = pszMenu2; nNext = 2; } break; /* Get the delimiter */ case 3: if ((pszDelimiter = GetDelimiter()) <> "") { if (pszDelimiter == "; ") pszMenu[3] = pszMenu3 + ""; else { if (pszDelimiter == " ") pszMenu[3] = pszMenu3 + ""; else { if (pszDelimiter == ", ") pszMenu[3] = pszMenu3 + ""; else pszMenu[3] = pszMenu3 + ""; } } nNext = 4; } break; /* Process the tag file */ case 4: if ((db == EOF) or (db.documents <= 0)) { messageBox("There are no documents in the current query or there is no open database." + newline() + "Please open a database to continue", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); nNext = 1; } else { if (nField == 0) { messageBox("Please specify a field to place the issues.", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); nNext = 2; } else { if (pszDelimiter == "") { messageBox("Please specify a delimiter.", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); nNext = 3; } else { if (messageBox("All contents of the " + db.name[nField] + " field will be replaced. Do you wish to continue?", gszIssue2Field, MB_YESNOCANCEL) == IDYES) { ProcessIssues(db, nField, pszDelimiter); nNext = 5; } } } } break; /* Quit */ case 5: bDone = TRUE; break; } } } /**************************************************************** * Name: ProcessIssues * * Synopsis: Main function to insert tags into a field. * ****************************************************************/ ProcessIssues(int db, nField; text pszDelimiter) { int btTag = EOF, btList = EOF, nData, bError, i, nCurrentAnnotation, nTotalAnnotations; text pszKey, pszList; if ((db <> EOF) and (nField <> 0) and (pszDelimiter <> "")) { /* Try and open the tag file */ if ((btTag = btopen(db.database + "-Notes.tag")) <> EOF) { /* Create a temp list of the tags */ pszList = db.database + " tag list.tmp"; if ((btList = btcreate(pszList, FALSE)) <> EOF) { /* Cycle through the tag file */ for (i = btfirst(btTag, pszKey, nData); i == 0; i = btgt(btTag, pszKey, pszKey, nData)) { /* Add the key to the list */ i = btinsert(btList, pszKey, 0); /* Add a space to jump to the next tag */ pszKey = pszKey + " "; } } else { /* We were unable to create a temp list file */ messageBox("Unable to create a temporary file in the database directory." + newline() + "Please check your permissions.", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); bError = TRUE; } /* Close the tag file */ btclose(btTag); } else { /* There was an error opening the tag file */ messageBox("There was an error opening the notes tag file or there were no issues present for this database.", gszIssue2Field, MB_OK | MB_ICONEXCLAMATION); bError = TRUE; } /* Process the list */ if (bError == FALSE) { /* Cycle through the database */ cycle(db) { /* Put up a status message */ puts(0, 0, "Processing record " + str(docno(db)) + " of " + str(count(db)) + ". "); /* Erase any previous contents of the field */ db->nField = ""; /* Get the total number of annotations */ if ((nTotalAnnotations = annotationCount(db)) > 0) { /* Cycle through the annotations */ nCurrentAnnotation = 1; for (bError = annotationGoto(db, 1); (bError == 0) and (nCurrentAnnotation <= nTotalAnnotations); bError = annotationGoto(db, nCurrentAnnotation)) { /* Cycle through the list */ for (i = btfirst(btList, pszKey, nData); i == 0; i = btgt(btList, pszKey, pszKey, nData)) { /* If it is tagged then add it to the field */ if (annotationIsTagged(db, pszKey)) { if (db->nField <> "") db->nField = db->nField + pszDelimiter; db->nField = db->nField + pszKey; } } /* Increment to the next annotation */ nCurrentAnnotation = nCurrentAnnotation + 1; } } } } /* Close the list file */ if (btList <> EOF) { btclose(btList); erase(pszList); } } } /**************************************************************** * 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: GetDelimiter * * Synopsis: Gets the delimiter from a file.. * ****************************************************************/ GetDelimiter() { text pszDelimiterMenu[5], screen; int i; char szDelimiter[3]; pszDelimiterMenu[0] = "Delimiter"; pszDelimiterMenu[1] = ""; pszDelimiterMenu[2] = ""; pszDelimiterMenu[3] = ""; pszDelimiterMenu[4] = ""; screen = save(11, 30, 18, 50); while (i == 0) i = menu(11, 30, 18, 50, pszDelimiterMenu, i, ""); restore(11, 30, screen); /* Set the delimiter */ switch(i) { case 1: szDelimiter[0] = ','; szDelimiter[1] = ' '; szDelimiter[2] = 0; break; case 2: szDelimiter[0] = ';'; szDelimiter[1] = ' '; szDelimiter[2] = 0; break; case 3: szDelimiter[0] = ' '; szDelimiter[1] = 0; break; case 4: szDelimiter[0] = 13; szDelimiter[1] = 10; szDelimiter[2] = 0; break; } return(szDelimiter); } /**************************************************************** * 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() */