[Tcladdressbook-commits] Source TclAddressBookUtils.c,1.13,1.14
Status: Alpha
Brought to you by:
bdesgraupes
|
From: Bernard D. <bde...@us...> - 2004-07-29 09:12:27
|
Update of /cvsroot/tcladdressbook/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31373/Source Modified Files: TclAddressBookUtils.c Log Message: TclAB_CheckItem() function Index: TclAddressBookUtils.c =================================================================== RCS file: /cvsroot/tcladdressbook/Source/TclAddressBookUtils.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- TclAddressBookUtils.c 28 Dec 2003 07:49:56 -0000 1.13 +++ TclAddressBookUtils.c 29 Jul 2004 09:12:14 -0000 1.14 @@ -1,13 +1,13 @@ /* * File : "TclAddressBookUtils.c" * Created: 2003-12-05 10:08:03 - * Last modification: 2003-12-28 07:45:12 + * Last modification: 2004-07-29 11:07:23 * Author: Bernard Desgraupes * e-mail: <bde...@ea...> * * Utility functions called by the TclABCmd command functions * - * (c) Copyright : Bernard Desgraupes, 2003 + * (c) Copyright : Bernard Desgraupes, 2003-2004 * All rights reserved. * This software is free software with BSD licence. * Versions history: see the Changes.Log file. @@ -637,10 +637,11 @@ /* *---------------------------------------------------------------------- * - * TclAB_CheckGroup -- + * TclAB_CheckItem -- * - * This function is invoked to check the validity of an -ingroup/-fromgroup - * optional argument and return the corresponding record reference. + * This function is invoked to check the validity of an item's UID + * (person or group) and returns the corresponding record reference in + * the outItemRef argument. * * Results: * None. @@ -652,28 +653,32 @@ */ Boolean -TclAB_CheckGroup(Tcl_Interp *interp, ABAddressBookRef ab, CONST84 char * inGroupUID, - CONST84 char * option, ABRecordRef * outGroupRef) +TclAB_CheckItem(Tcl_Interp *interp, ABAddressBookRef ab, CONST84 char * inUID, + CONST84 char * option, ABRecordRef * outItemRef, int inRecordType) + { - CFStringRef groupCFStr; + CFStringRef theCFStr; int kind; Boolean result = true; - groupCFStr = CFStringCreateWithCString(NULL, inGroupUID, NULL); + theCFStr = CFStringCreateWithCString(NULL, inUID, NULL); + // Find the record corresponding to the UID - *outGroupRef = ABCopyRecordForUniqueId(ab, groupCFStr); - CFRelease(groupCFStr); - if (!*outGroupRef) { + *outItemRef = ABCopyRecordForUniqueId(ab, theCFStr); + CFRelease(theCFStr); + + if (!*outItemRef) { Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "Unrecognized record ID in ", option, " argument", (char *) NULL); result = false; } else { - // Is it really a group? - kind = TclAB_TypeFromRecord(ab, *outGroupRef); - if (kind != rec_group) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "Not a group ID in ", option, - " argument", (char *) NULL); - CFRelease(groupCFStr); + // Is it the expected type (person or group)? + kind = TclAB_TypeFromRecord(ab, *outItemRef); + + if (kind != inRecordType) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "Not a ", + inRecordType == rec_person ? "person":"group", + " ID in ", option, " argument", (char *) NULL); result = false; } } @@ -759,7 +764,7 @@ ab = ABGetSharedAddressBook(); if(lookingInGroup) { - if ( !TclAB_CheckGroup(interp, ab, inGroupUID, "-ingroup", &inGroup) ) { + if ( !TclAB_CheckItem(interp, ab, inGroupUID, "-ingroup", &inGroup, rec_group) ) { return TCL_ERROR; } if (inRecordType == rec_group) { @@ -964,7 +969,7 @@ // Handle the -ingroup optional argument if (result && addingToGroup) { - if ( !TclAB_CheckGroup(interp, ab, inGroupUID, "-ingroup", &inGroup) ) { + if ( !TclAB_CheckItem(interp, ab, inGroupUID, "-ingroup", &inGroup, rec_group) ) { result = TCL_ERROR; goto DONE; } |