| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: drvctl.c,v 1.16 2012/01/17 08:22:09 wiz Exp $ */ | | 1 | /* $NetBSD: drvctl.c,v 1.16.18.1 2015/03/07 06:06:24 snj Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2004 | | 4 | * Copyright (c) 2004 |
5 | * Matthias Drochner. All rights reserved. | | 5 | * Matthias Drochner. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions, and the following disclaimer. | | 11 | * notice, this list of conditions, and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -216,41 +216,57 @@ main(int argc, char **argv) | | | @@ -216,41 +216,57 @@ main(int argc, char **argv) |
216 | break; | | 216 | break; |
217 | default: | | 217 | default: |
218 | errx(4, "unknown command"); | | 218 | errx(4, "unknown command"); |
219 | } | | 219 | } |
220 | | | 220 | |
221 | return (0); | | 221 | return (0); |
222 | } | | 222 | } |
223 | | | 223 | |
224 | static void | | 224 | static void |
225 | extract_property(prop_dictionary_t dict, const char *prop, bool nflag) | | 225 | extract_property(prop_dictionary_t dict, const char *prop, bool nflag) |
226 | { | | 226 | { |
227 | char *s, *p, *cur, *ep = NULL; | | 227 | char *s, *p, *cur, *ep = NULL; |
228 | prop_object_t obj; | | 228 | prop_object_t obj; |
| | | 229 | unsigned long ind; |
229 | | | 230 | |
| | | 231 | obj = dict; |
| | | 232 | cur = NULL; |
230 | s = strdup(prop); | | 233 | s = strdup(prop); |
231 | p = strtok_r(s, "/", &ep); | | 234 | p = strtok_r(s, "/", &ep); |
232 | while (p) { | | 235 | while (p) { |
233 | cur = p; | | 236 | cur = p; |
234 | p = strtok_r(NULL, "/", &ep); | | 237 | p = strtok_r(NULL, "/", &ep); |
235 | if (p) { | | 238 | |
236 | if (prop_dictionary_get_dict(dict, cur, &dict) == false) | | 239 | switch (prop_object_type(obj)) { |
| | | 240 | case PROP_TYPE_DICTIONARY: |
| | | 241 | obj = prop_dictionary_get(obj, cur); |
| | | 242 | if (obj == NULL) |
237 | exit(EXIT_FAILURE); | | 243 | exit(EXIT_FAILURE); |
238 | } else { | | 244 | break; |
239 | obj = prop_dictionary_get(dict, cur); | | 245 | case PROP_TYPE_ARRAY: |
240 | display_object(obj, nflag); | | 246 | ind = strtoul(cur, NULL, 0); |
| | | 247 | obj = prop_array_get(obj, ind); |
| | | 248 | if (obj == NULL) |
| | | 249 | exit(EXIT_FAILURE); |
| | | 250 | break; |
| | | 251 | default: |
| | | 252 | fprintf(stderr, "select neither dict nor array with '%s'\n", cur); |
| | | 253 | exit(EXIT_FAILURE); |
241 | } | | 254 | } |
242 | } | | 255 | } |
243 | | | 256 | |
| | | 257 | if (obj != NULL && cur != NULL) |
| | | 258 | display_object(obj, nflag); |
| | | 259 | |
244 | free(s); | | 260 | free(s); |
245 | } | | 261 | } |
246 | | | 262 | |
247 | static void | | 263 | static void |
248 | display_object(prop_object_t obj, bool nflag) | | 264 | display_object(prop_object_t obj, bool nflag) |
249 | { | | 265 | { |
250 | char *xml; | | 266 | char *xml; |
251 | prop_object_t next_obj; | | 267 | prop_object_t next_obj; |
252 | prop_object_iterator_t iter; | | 268 | prop_object_iterator_t iter; |
253 | | | 269 | |
254 | if (obj == NULL) | | 270 | if (obj == NULL) |
255 | exit(EXIT_FAILURE); | | 271 | exit(EXIT_FAILURE); |
256 | switch (prop_object_type(obj)) { | | 272 | switch (prop_object_type(obj)) { |