/* ** 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: ** ** Note2Field.cpl */ text gszNote2Field = "Note2Field.cpl"; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { text pszMenu[6], pszMenu1, pszMenu2, pszDatabase, pszDelimiter; int db, nField, nNext, bDone; /* Set up the menus */ pszMenu1 = "[1] Open database : "; pszMenu2 = "[2] Note field : "; pszMenu[0] = gszNote2Field ; pszMenu[1] = pszMenu1; pszMenu[2] = pszMenu2; pszMenu[3] = "[G] Go!"; pszMenu[4] = "[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.", gszNote2Field, MB_OK | MB_ICONEXCLAMATION); pszMenu[2] = pszMenu2; nField = 0; nNext = 2; } } else { pszMenu[2] = pszMenu2; nNext = 2; } break; /* Process the tag file */ case 3: 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", gszNote2Field, MB_OK | MB_ICONEXCLAMATION); nNext = 1; } else { if (nField == 0) { messageBox("Please specify a field to place the notes.", gszNote2Field, MB_OK | MB_ICONEXCLAMATION); nNext = 2; } else { if (messageBox("All contents of the " + db.name[nField] + " field will be replaced. Do you wish to continue?", gszNote2Field, MB_YESNOCANCEL) == IDYES) { ProcessNotes(db, nField); nNext = 4; } } } break; /* Quit */ case 4: bDone = TRUE; break; } } } /**************************************************************** * Name: ProcessNotes * * Synopsis: Main function to insert notes into a field. * ****************************************************************/ ProcessNotes(int db, nField) { int nTotalAnnotations, nError, nCurrentAnnotation; text pszAnnotationText, pszAnnotationField; if ((db <> EOF) and (nField <> 0)) { /* Cycle through the database */ cycle(db) { /* Put up a status message */ puts(0, 0, "Processing record " + str(docno(db)) + "..."); /* Clear the notes field */ db->nField = ""; /* Get the annotation count for this record */ if ((nTotalAnnotations = annotationCount(db)) > 0) { /* Cycle through the annotations on this record */ nCurrentAnnotation = 1; for (nError = annotationGoto(db, nCurrentAnnotation); (nError == 0) and (nCurrentAnnotation <= nTotalAnnotations); annotationGoto(db, nCurrentAnnotation)) { /* Get the text of the annotation */ pszAnnotationText = annotationRetrieve(db, "NOTETEXT"); /* Get the field of the annotation */ pszAnnotationField = annotationRetrieve(db, "LINKFIELD"); /* Write the note header */ if (db->nField <> "") db->nField = db->nField + newline() + newline(); db->nField = db->nField + "*** Note " + str(nCurrentAnnotation) + " (" + pszAnnotationField+ ") ***" + newline() + newline(); /* Write the annotation text to the note field */ db->nField = db->nField + pszAnnotationText; /* Increment the annotation count */ nCurrentAnnotation = nCurrentAnnotation + 1; } } } } } /**************************************************************** * 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() */