2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * November 9, 2000 Allan Nathanson <ajn@apple.com>
37 #include "dictionary.h"
45 do_dictInit(int argc
, char **argv
)
51 value
= CFDictionaryCreateMutable(NULL
53 ,&kCFTypeDictionaryKeyCallBacks
54 ,&kCFTypeDictionaryValueCallBacks
62 do_dictShow(int argc
, char **argv
)
65 SCPrint(TRUE
, stdout
, CFSTR("d.show: dictionary must be initialized.\n"));
69 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), value
);
76 do_dictSetKey(int argc
, char **argv
)
78 CFMutableArrayRef array
= NULL
;
79 Boolean doArray
= FALSE
;
80 Boolean doBoolean
= FALSE
;
81 Boolean doNumeric
= FALSE
;
86 SCPrint(TRUE
, stdout
, CFSTR("d.add: dictionary must be initialized.\n"));
90 if (!isA_CFDictionary(value
)) {
91 SCPrint(TRUE
, stdout
, CFSTR("d.add: data (fetched from configuration server) is not a dictionary.\n"));
95 val
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
99 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
103 if (strcmp(argv
[0], "*") == 0) {
104 /* if array requested */
106 } else if (strcmp(argv
[0], "-") == 0) {
107 /* if string values requested */
108 } else if (strcmp(argv
[0], "?") == 0) {
109 /* if boolean values requested */
111 } else if (strcmp(argv
[0], "#") == 0) {
112 /* if numeric values requested */
115 /* it's not a special flag */
123 } else if (!doArray
&& (argc
== 0)) {
124 SCPrint(TRUE
, stdout
, CFSTR("d.add: no values.\n"));
129 array
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
134 if ((strcasecmp(argv
[0], "true") == 0) ||
135 (strcasecmp(argv
[0], "t" ) == 0) ||
136 (strcasecmp(argv
[0], "yes" ) == 0) ||
137 (strcasecmp(argv
[0], "y" ) == 0) ||
138 (strcmp (argv
[0], "1" ) == 0)) {
139 val
= CFRetain(kCFBooleanTrue
);
140 } else if ((strcasecmp(argv
[0], "false") == 0) ||
141 (strcasecmp(argv
[0], "f" ) == 0) ||
142 (strcasecmp(argv
[0], "no" ) == 0) ||
143 (strcasecmp(argv
[0], "n" ) == 0) ||
144 (strcmp (argv
[0], "0" ) == 0)) {
145 val
= CFRetain(kCFBooleanFalse
);
147 SCPrint(TRUE
, stdout
, CFSTR("d.add: invalid data.\n"));
153 } else if (doNumeric
) {
156 if (sscanf(argv
[0], "%d", &intValue
) == 1) {
157 val
= CFNumberCreate(NULL
, kCFNumberIntType
, &intValue
);
159 SCPrint(TRUE
, stdout
, CFSTR("d.add: invalid data.\n"));
166 val
= (CFPropertyListRef
)CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
170 CFArrayAppendValue(array
, val
);
180 CFDictionarySetValue((CFMutableDictionaryRef
)value
, key
, val
);
189 do_dictRemoveKey(int argc
, char **argv
)
192 CFMutableDictionaryRef val
;
195 SCPrint(TRUE
, stdout
, CFSTR("d.remove: dictionary must be initialized.\n"));
199 if (!isA_CFDictionary(value
)) {
200 SCPrint(TRUE
, stdout
, CFSTR("d.remove: data (fetched from configuration server) is not a dictionary.\n"));
204 val
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
208 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
209 CFDictionaryRemoveValue((CFMutableDictionaryRef
)value
, key
);