2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * November 9, 2000 Allan Nathanson <ajn@apple.com>
41 do_dictInit(int argc
, char **argv
)
47 value
= CFDictionaryCreateMutable(NULL
49 ,&kCFTypeDictionaryKeyCallBacks
50 ,&kCFTypeDictionaryValueCallBacks
58 do_dictShow(int argc
, char **argv
)
61 SCPrint(TRUE
, stdout
, CFSTR("d.show: dictionary must be initialized.\n"));
65 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), value
);
72 do_dictSetKey(int argc
, char **argv
)
74 CFMutableArrayRef array
= NULL
;
75 Boolean doArray
= FALSE
;
76 Boolean doBoolean
= FALSE
;
77 Boolean doNumeric
= FALSE
;
82 SCPrint(TRUE
, stdout
, CFSTR("d.add: dictionary must be initialized.\n"));
86 if (CFGetTypeID(value
) != CFDictionaryGetTypeID()) {
87 SCPrint(TRUE
, stdout
, CFSTR("d.add: data (fetched from configuration server) is not a dictionary.\n"));
91 val
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
95 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
99 if (strcmp(argv
[0], "*") == 0) {
100 /* if array requested */
102 } else if (strcmp(argv
[0], "-") == 0) {
103 /* if string values requested */
104 } else if (strcmp(argv
[0], "?") == 0) {
105 /* if boolean values requested */
107 } else if (strcmp(argv
[0], "#") == 0) {
108 /* if numeric values requested */
111 /* it's not a special flag */
119 } else if (!doArray
&& (argc
== 0)) {
120 SCPrint(TRUE
, stdout
, CFSTR("d.add: no values.\n"));
125 array
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
130 if ((strcasecmp(argv
[0], "true") == 0) ||
131 (strcasecmp(argv
[0], "t" ) == 0) ||
132 (strcasecmp(argv
[0], "yes" ) == 0) ||
133 (strcasecmp(argv
[0], "y" ) == 0) ||
134 (strcmp (argv
[0], "1" ) == 0)) {
135 val
= CFRetain(kCFBooleanTrue
);
136 } else if ((strcasecmp(argv
[0], "false") == 0) ||
137 (strcasecmp(argv
[0], "f" ) == 0) ||
138 (strcasecmp(argv
[0], "no" ) == 0) ||
139 (strcasecmp(argv
[0], "n" ) == 0) ||
140 (strcmp (argv
[0], "0" ) == 0)) {
141 val
= CFRetain(kCFBooleanFalse
);
143 SCPrint(TRUE
, stdout
, CFSTR("d.add: invalid data.\n"));
149 } else if (doNumeric
) {
152 if (sscanf(argv
[0], "%d", &intValue
) == 1) {
153 val
= CFNumberCreate(NULL
, kCFNumberIntType
, &intValue
);
155 SCPrint(TRUE
, stdout
, CFSTR("d.add: invalid data.\n"));
162 val
= (CFPropertyListRef
)CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
166 CFArrayAppendValue(array
, val
);
176 CFDictionarySetValue((CFMutableDictionaryRef
)value
, key
, val
);
185 do_dictRemoveKey(int argc
, char **argv
)
188 CFMutableDictionaryRef val
;
191 SCPrint(TRUE
, stdout
, CFSTR("d.remove: dictionary must be initialized.\n"));
195 if (CFGetTypeID(value
) != CFDictionaryGetTypeID()) {
196 SCPrint(TRUE
, stdout
, CFSTR("d.remove: data (fetched from configuration server) is not a dictionary.\n"));
200 val
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
204 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
205 CFDictionaryRemoveValue((CFMutableDictionaryRef
)value
, key
);