/* ** Concordance Programming Language ** ** Copyright (c) 2003 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Los Angeles, 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: ** */ text gszMoveFileName = "Import-Move_File_Name.cpl"; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { int db, nNext, bDone, nSourceField, nDestinationField; text menuString1, menuString2, myMenu[5]; /* Make sure the database is open */ if (db.documents <= 0) return(messageBox("Please open a database first.", gszPageRenumber, MB_OK | MB_ICONEXCLAMATION)); /* Set up the menu */ menuString1 = "[1] Select the original import field : "; menuString2 = "[2] Select destination file name field : "; myMenu[0] = gszMoveFileName; myMenu[1] = menuString1; myMenu[2] = menuString2; myMenu[3] = "[G] Go"; myMenu[4] = "[Q] Quit"; /* Display the menu */ while (bDone == FALSE) { nNext = menu(5, 10, 12, 70, myMenu, nNext,"12GQ"); switch(nNext) { case 0: case 4: bDone = TRUE; break; case 1: nSourceField = GetField(db, nSourceField); if ((db.type[nSourceField] == 'P') or (db.type[nSourceField] == 'T')) { myMenu[1] = menuString1 + db.name[nSourceField]; nNext = 2; } else { messageBox("Field must be text or paragraph.", gszMoveFileName, MB_OK | MB_ICONEXCLAMATION); nNext = 1; } break; case 2: nDestinationField = GetField(db, nDestinationField ); if ((db.type[nDestinationField ] == 'P') or (db.type[nDestinationField ] == 'T')) { myMenu[2] = menuString2 + db.name[nDestinationField ]; nNext = 3; messageBox("Remember, this field will be overwritten!", gszMoveFileName, MB_OK | MB_ICONEXCLAMATION); } else { messageBox("Field must be text or paragraph.", gszMoveFileName, MB_OK | MB_ICONEXCLAMATION); nNext = 2; } break; case 3: if ((nNext = MoveFileNames(db, nSourceField, nDestinationField, TRUE)) == 0) nNext = 4; cls(); break; } } } /**************************************************************** * Name: MoveFileNames * * Synopsis: Main function to move file names * ****************************************************************/ MoveFileNames(int db, nSourceField, nDestinationField, bDeleteOriginal) { int nEndOffset; if (nSourceField <= 0) { messageBox("Please specify the original import field.", gszMoveFileName, MB_OK | MB_ICONEXCLAMATION); return(1); } if (nDestinationField<= 0) { messageBox("Please specify the destination file name field.", gszMoveFileName, MB_OK | MB_ICONEXCLAMATION); return(2); } cycle(db) { /* Display a status message */ puts(0, 0, "Processing record " + str(docno(db)) + " of " + str(count(db))); /* Is the first character an open paren? */ if (substr(db->nSourceField, 1, 1) == "(") { /* Find the matching end paren */ if ((nEndOffset = match(db->nSourceField, ")", 1)) <> 0) { /* Set the destination field */ db->nDestinationField = substr(db->nSourceField, 2, nEndOffset - 2); /* Delete the original */ if (bDeleteOriginal) { db->nSourceField = substr(db->nSourceField, nEndOffset + 1); db->nSourceField = trim(db->nSourceField); } } } } } /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[255]; 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() */