/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004, 2009, 2010 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
* @APPLE_LICENSE_HEADER_END@
*/
*/
#include "scutil.h"
+#include "dictionary.h"
//#include <stdlib.h>
//#include <limits.h>
+__private_extern__
void
do_dictInit(int argc, char **argv)
{
}
+__private_extern__
void
do_dictShow(int argc, char **argv)
{
}
+__private_extern__
void
do_dictSetKey(int argc, char **argv)
{
- CFMutableArrayRef array = NULL;
- Boolean doArray = FALSE;
- Boolean doBoolean = FALSE;
- Boolean doNumeric = FALSE;
+ CFMutableArrayRef array = NULL;
+ Boolean doArray = FALSE;
+ Boolean doBoolean = FALSE;
+ Boolean doNumeric = FALSE;
CFStringRef key;
- CFTypeRef val;
+ CFMutableDictionaryRef newValue;
+ CFTypeRef val = NULL;
if (value == NULL) {
SCPrint(TRUE, stdout, CFSTR("d.add: dictionary must be initialized.\n"));
return;
}
- val = CFDictionaryCreateMutableCopy(NULL, 0, value);
- CFRelease(value);
- value = val;
-
- key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+ key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
argv++; argc--;
while (argc > 0) {
doArray = TRUE;
} else if (!doArray && (argc == 0)) {
SCPrint(TRUE, stdout, CFSTR("d.add: no values.\n"));
+ CFRelease(key);
return;
}
val = CFRetain(kCFBooleanFalse);
} else {
SCPrint(TRUE, stdout, CFSTR("d.add: invalid data.\n"));
- if (doArray) {
- CFRelease(array);
- }
+ if (doArray) CFRelease(array);
+ CFRelease(key);
return;
}
} else if (doNumeric) {
val = CFNumberCreate(NULL, kCFNumberIntType, &intValue);
} else {
SCPrint(TRUE, stdout, CFSTR("d.add: invalid data.\n"));
- if (doArray) {
- CFRelease(array);
- }
+ if (doArray) CFRelease(array);
+ CFRelease(key);
return;
}
} else {
- val = (CFPropertyListRef)CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+ val = (CFPropertyListRef)CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
}
if (doArray) {
CFArrayAppendValue(array, val);
+ CFRelease(val);
+ argv++; argc--;
+ } else {
+ break;
}
-
- argv++; argc--;
}
+ newValue = CFDictionaryCreateMutableCopy(NULL, 0, value);
if (doArray) {
- val = array;
+ CFDictionarySetValue(newValue, key, array);
+ CFRelease(array);
+ } else if (val != NULL) {
+ CFDictionarySetValue(newValue, key, val);
+ CFRelease(val);
}
-
- CFDictionarySetValue((CFMutableDictionaryRef)value, key, val);
- CFRelease(val);
CFRelease(key);
+ CFRelease(value);
+ value = newValue;
return;
}
+__private_extern__
void
do_dictRemoveKey(int argc, char **argv)
{
CFRelease(value);
value = val;
- key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+ key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
CFDictionaryRemoveValue((CFMutableDictionaryRef)value, key);
CFRelease(key);