[Tcladdressbook-commits] Source TclAddressBook.c,1.26,1.27
Status: Alpha
Brought to you by:
bdesgraupes
|
From: Bernard D. <bde...@us...> - 2004-07-29 13:30:34
|
Update of /cvsroot/tcladdressbook/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5166/Source Modified Files: TclAddressBook.c Log Message: Debugging return values Index: TclAddressBook.c =================================================================== RCS file: /cvsroot/tcladdressbook/Source/TclAddressBook.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- TclAddressBook.c 29 Jul 2004 09:11:34 -0000 1.26 +++ TclAddressBook.c 29 Jul 2004 13:30:21 -0000 1.27 @@ -286,7 +286,7 @@ Tcl_Obj *CONST objv[], /* Argument values. */ Tcl_Obj *resultPtr) /* Pointer to store the result. */ { - int kind, length, result; + int kind, length, result = TCL_OK, success; CONST84 char * groupID; CFStringRef strRef; ABAddressBookRef ab; @@ -303,9 +303,9 @@ // Second argument is a person or a group ID strRef = CFStringCreateWithCString(NULL, Tcl_GetStringFromObj(objv[2], &length), NULL); // Find the record corresponding to the UID - result = TclAB_RecordFromUID(ab, strRef, resultPtr, &objRecord); + success = TclAB_RecordFromUID(ab, strRef, resultPtr, &objRecord); CFRelease(strRef); - if (!result) {return TCL_ERROR;} + if (!success) {return TCL_ERROR;} // Third argument is a group ID groupID = Tcl_GetStringFromObj(objv[3], &length); @@ -707,8 +707,12 @@ { ABAddressBookRef ab; - if (objc != 2) { - Tcl_WrongNumArgs(interp, 2, objv, ""); + static CONST char *getmeSwitches[] = { + "-id", (char *) NULL + }; + + if (objc != 2 && objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "?-id?"); return TCL_ERROR; } @@ -717,8 +721,22 @@ // Get the address book ab = ABGetSharedAddressBook(); - // Store the record's data in the result object - TclAB_GetAllValues(interp, ab, ABGetMe(ab), rec_person); + if (objc == 3) { + char theUID[256]; + CFStringRef uniqueId; + int index; + + if (Tcl_GetIndexFromObj(interp, objv[2], getmeSwitches, "option", 0, &index) != TCL_OK) { + return TCL_ERROR; + } + uniqueId = ABRecordCopyUniqueId(ABGetMe(ab)); + CFStringGetCString(uniqueId, theUID, sizeof(theUID), NULL); + CFRelease(uniqueId); + Tcl_SetObjResult(interp, Tcl_NewStringObj(theUID, strlen(theUID))); + } else { + // Store the record's data in the result object + TclAB_GetAllValues(interp, ab, ABGetMe(ab), rec_person); + } return TCL_OK; } @@ -808,25 +826,7 @@ thePersonUID = Tcl_GetStringFromObj(objv[2], &length); theGroupUID = Tcl_GetStringFromObj(objv[3], &length); - theProperty = Tcl_GetStringFromObj(objv[4], &length); - - if (objc == 6) { - theNewVal = Tcl_GetStringFromObj(objv[5], &length); - if (length == 0) { - valueRef = NULL; - } else { - valueRef = CFStringCreateWithCString(NULL, theNewVal, kCFStringEncodingUTF8); - } - setIt = true; - } - // Make CFString object for property - propertyRef = CFStringCreateWithCString(NULL, theProperty, kCFStringEncodingUTF8); - if (!propertyRef) { - Tcl_AppendStringsToObj(resultPtr, "Problem getting CFString for property", (char *) NULL); - return TCL_ERROR; - } - // Get the address book ab = ABGetSharedAddressBook(); @@ -837,10 +837,21 @@ // Check if third argument is a group and get the corresponding record if ( !TclAB_CheckItem(interp, ab, theGroupUID, "third", &groupRecord, rec_group) ) { + CFRelease(personRecord); + return TCL_ERROR; + } + + Tcl_IncrRefCount(objv[4]); + theProperty = Tcl_GetStringFromObj(objv[4], &length); + + // Make CFString object for property + propertyRef = CFStringCreateWithCString(NULL, theProperty, kCFStringEncodingUTF8); + if (!propertyRef) { + Tcl_AppendStringsToObj(resultPtr, "Problem getting CFString for property", (char *) NULL); result = TCL_ERROR; goto DONE; } - + // Find the property type (string, date, multivalue...) thePropType = ABTypeOfProperty(ab, kABPersonRecordType, propertyRef); if (thePropType == kABErrorInProperty) { @@ -851,6 +862,16 @@ goto DONE; } + if (objc == 6) { + theNewVal = Tcl_GetStringFromObj(objv[5], &length); + if (length == 0) { + valueRef = NULL; + } else { + valueRef = CFStringCreateWithCString(NULL, theNewVal, kCFStringEncodingUTF8); + } + setIt = true; + } + if (setIt) { // ABGroupSetDistributionIdentifier(groupRecord, personRecord, propertyRef, valueRef) // ABGroupSetDistributionIdentifier(groupRecord, personRecord, kABAddressProperty, kABAddressHomeLabel) @@ -883,6 +904,7 @@ CFRelease(propertyRef); DONE: + Tcl_DecrRefCount(objv[4]); CFRelease(groupRecord); CFRelease(personRecord); return result; @@ -1247,7 +1269,7 @@ Tcl_Obj *CONST objv[], /* Argument values. */ Tcl_Obj *resultPtr) /* Pointer to store the result. */ { - int result, index, kind; + int result = TCL_ERROR, index, kind; static CONST char *propSubcmdSwitches[] = { "add", "names", "remove", "type", (char *) NULL @@ -1274,7 +1296,13 @@ if (Tcl_GetIndexFromObj(interp, objv[3], propertySwitches, "option", 0, &kind) != TCL_OK) { - return TCL_ERROR; + if (index != TCLAB_PROPERTY_REMOVE) { + return TCL_ERROR; + } else { + // For the [remove] subcommand, the third argument + // can also be a record ID. Pass rec_undefined in that case. + kind = rec_undefined; + } } switch (index) { @@ -1394,7 +1422,7 @@ Tcl_Obj *CONST objv[], /* Argument values. */ Tcl_Obj *resultPtr) /* Pointer to store the result. */ { - int kind, length, result; + int kind, length, result = TCL_OK, success; CONST84 char * groupID; CFStringRef strRef; ABAddressBookRef ab; @@ -1411,9 +1439,9 @@ // Second argument is a person or a group ID strRef = CFStringCreateWithCString(NULL, Tcl_GetStringFromObj(objv[2], &length), NULL); // Find the record corresponding to the UID - result = TclAB_RecordFromUID(ab, strRef, resultPtr, &objRecord); + success = TclAB_RecordFromUID(ab, strRef, resultPtr, &objRecord); CFRelease(strRef); - if (!result) {return TCL_ERROR;} + if (!success) {return TCL_ERROR;} // Third argument is a group ID groupID = Tcl_GetStringFromObj(objv[3], &length); |