[Tcladdressbook-commits] Source TclAddressBookUtils.c,1.7,1.8
Status: Alpha
Brought to you by:
bdesgraupes
|
From: <bde...@us...> - 2003-12-14 10:39:48
|
Update of /cvsroot/tcladdressbook/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv12781/Source
Modified Files:
TclAddressBookUtils.c
Log Message:
TclAB_PutValueInResult() builds keyed list
Index: TclAddressBookUtils.c
===================================================================
RCS file: /cvsroot/tcladdressbook/Source/TclAddressBookUtils.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- TclAddressBookUtils.c 13 Dec 2003 13:23:13 -0000 1.7
+++ TclAddressBookUtils.c 13 Dec 2003 17:27:56 -0000 1.8
@@ -27,8 +27,8 @@
* TclAB_GetAllValues --
*
* This function is invoked to return the property/values pairs in an array.
- * The "var" argument must not be NULL because the pairs are store in this
- * array variable.
+ * The "inVar" argument must not be NULL because this is the name of the
+ * variable in which the results are stored.
*
* Results:
* None.
@@ -41,7 +41,7 @@
void
TclAB_GetAllValues(Tcl_Interp *interp, ABAddressBookRef ab,
- ABRecordRef inRecord, CONST84 char * var,
+ ABRecordRef inRecord, CONST84 char * inVar,
int inRecordType)
{
CFIndex theCount;
@@ -65,11 +65,13 @@
if (!theValue) {
continue;
}
- TclAB_GetValue(interp, ab, theProperty, theValue, var, inRecordType);
+ TclAB_GetValue(interp, ab, theProperty, theValue, 1, inRecordType);
CFRelease(theValue);
}
}
CFRelease(allProps);
+ // Store the result in the variable
+ Tcl_SetVar2Ex(interp, inVar, NULL, Tcl_GetObjResult(interp), TCL_GLOBAL_ONLY);
}
@@ -79,8 +81,9 @@
* TclAB_GetValue --
*
* This function is invoked to return a specific property/value pair.
- * Unlike in TclAB_GetAllValues(), the "var" argument can be NULL: in that
- * case the value is stored in the resultPtr.
+ * If the "allValues" argument is 0, the value is stored in the resultPtr
+ * replacing anything existing there. Otherwise it is appended to the
+ * resultPtr.
*
* Results:
* None.
@@ -98,7 +101,7 @@
void
TclAB_GetValue(Tcl_Interp *interp, ABAddressBookRef ab,
CFStringRef inProperty, CFStringRef inValue,
- CONST84 char * var, int inRecordType)
+ Boolean allValues, int inRecordType)
{
CFStringRef theValue, subValue, subLabel;
CFStringRef localizedStr;
@@ -132,7 +135,7 @@
case kABStringProperty:
// Get the entry for the string property
if (CFStringGetCString(theValue, theStr, sizeof(theStr), theEncoding)) {
- TclAB_SetArrayOrResult(interp, var, thePropName, theStr);
+ TclAB_PutValueInResult(interp, thePropName, theStr, allValues);
}
CFRelease(theValue);
break;
@@ -147,7 +150,7 @@
// [clock format 978307200 -gmt 1] ---> Mon Jan 01 00:00:00 GMT 2001
theAbsTime += kCFAbsoluteTimeIntervalSince1970;
sprintf(theStr, "%.0f", theAbsTime);
- TclAB_SetArrayOrResult(interp, var, thePropName, theStr);
+ TclAB_PutValueInResult(interp, thePropName, theStr, allValues);
CFRelease(theValue);
break;
@@ -155,7 +158,7 @@
case kABIntegerProperty:
if (CFNumberGetValue(theValue, kCFNumberSInt32Type, &theSInt32)) {
sprintf(theStr, "%d", theSInt32);
- TclAB_SetArrayOrResult(interp, var, thePropName, theStr);
+ TclAB_PutValueInResult(interp, thePropName, theStr, allValues);
}
CFRelease(theValue);
break;
@@ -183,7 +186,7 @@
if (subLabel) CFRelease(subLabel);
if (subValue) CFRelease(subValue);
}
- TclAB_SetArrayOrResult(interp, var, thePropName, ds.string);
+ TclAB_PutValueInResult(interp, thePropName, ds.string, allValues);
Tcl_DStringFree(&ds);
CFRelease(multiValue);
break;
@@ -214,7 +217,7 @@
if (subLabel) CFRelease(subLabel);
if (subValue) CFRelease(subValue);
}
- TclAB_SetArrayOrResult(interp, var, thePropName, ds.string);
+ TclAB_PutValueInResult(interp, thePropName, ds.string, allValues);
Tcl_DStringFree(&ds);
CFRelease(multiValue);
break;
@@ -278,7 +281,7 @@
// Tcl_DStringEndSublist(&ds);
}
- TclAB_SetArrayOrResult(interp, var, thePropName, ds.string);
+ TclAB_PutValueInResult(interp, thePropName, ds.string, allValues);
Tcl_DStringFree(&ds);
// Don't CFRelease the multiValue: each dict is released one after the other
CFRelease(multiValue);
@@ -298,10 +301,9 @@
/*
*----------------------------------------------------------------------
*
- * TclAB_SetArrayOrResult --
+ * TclAB_PutValueInResult --
*
- * This function is invoked to determine the type (group or person)
- * corresponding to a particular UID.
+ * This function is invoked to
*
* Results:
* None.
@@ -313,10 +315,17 @@
*/
void
-TclAB_SetArrayOrResult(Tcl_Interp *interp, CONST84 char * inVar, char * inPropName, char * inStr)
+TclAB_PutValueInResult(Tcl_Interp *interp, char * inPropName, char * inStr, Boolean allValues)
{
- if (inVar) {
- Tcl_SetVar2(interp, inVar, inPropName, inStr, 0);
+ if (allValues) {
+ int length;
+ Tcl_Obj * listPtr;
+ Tcl_Obj * objs[2];
+
+ objs[0] = Tcl_NewStringObj(inPropName, strlen(inPropName));
+ objs[1] = Tcl_NewStringObj(inStr, strlen(inStr));
+ listPtr = Tcl_NewListObj(2, objs);
+ Tcl_AppendElement(interp, Tcl_GetStringFromObj(listPtr, &length));
} else {
Tcl_SetObjResult(interp, Tcl_NewStringObj(inStr, strlen(inStr)));
}
|