Module Name: src Committed By: mlelstv Date: Tue Feb 24 18:15:29 UTC 2015
Modified Files: src/sbin/drvctl: drvctl.8 drvctl.c Log Message: Let drvctl -p select elements from an array property by numeric index. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/drvctl/drvctl.8 cvs rdiff -u -r1.16 -r1.17 src/sbin/drvctl/drvctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/drvctl/drvctl.8 diff -u src/sbin/drvctl/drvctl.8:1.13 src/sbin/drvctl/drvctl.8:1.14 --- src/sbin/drvctl/drvctl.8:1.13 Mon Jan 16 19:43:50 2012 +++ src/sbin/drvctl/drvctl.8 Tue Feb 24 18:15:29 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: drvctl.8,v 1.13 2012/01/16 19:43:50 pgoyette Exp $ +.\" $NetBSD: drvctl.8,v 1.14 2015/02/24 18:15:29 mlelstv Exp $ .\" .\" Copyright (c) 2004 .\" Matthias Drochner. All rights reserved. @@ -114,7 +114,9 @@ argument. If .Ar property is specified, the value of that property is printed, otherwise -the properties are displayed as an XML property list. +the properties are displayed as an XML property list. The +property can be given as a path of dictionary keys and numeric +array indexes separated by slashes. .It Fl Q Resume the ancestors of .Ar device , Index: src/sbin/drvctl/drvctl.c diff -u src/sbin/drvctl/drvctl.c:1.16 src/sbin/drvctl/drvctl.c:1.17 --- src/sbin/drvctl/drvctl.c:1.16 Tue Jan 17 08:22:09 2012 +++ src/sbin/drvctl/drvctl.c Tue Feb 24 18:15:29 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: drvctl.c,v 1.16 2012/01/17 08:22:09 wiz Exp $ */ +/* $NetBSD: drvctl.c,v 1.17 2015/02/24 18:15:29 mlelstv Exp $ */ /* * Copyright (c) 2004 @@ -226,21 +226,37 @@ extract_property(prop_dictionary_t dict, { char *s, *p, *cur, *ep = NULL; prop_object_t obj; + unsigned long ind; + obj = dict; + cur = NULL; s = strdup(prop); p = strtok_r(s, "/", &ep); while (p) { cur = p; p = strtok_r(NULL, "/", &ep); - if (p) { - if (prop_dictionary_get_dict(dict, cur, &dict) == false) + + switch (prop_object_type(obj)) { + case PROP_TYPE_DICTIONARY: + obj = prop_dictionary_get(obj, cur); + if (obj == NULL) exit(EXIT_FAILURE); - } else { - obj = prop_dictionary_get(dict, cur); - display_object(obj, nflag); + break; + case PROP_TYPE_ARRAY: + ind = strtoul(cur, NULL, 0); + obj = prop_array_get(obj, ind); + if (obj == NULL) + exit(EXIT_FAILURE); + break; + default: + fprintf(stderr, "select neither dict nor array with '%s'\n", cur); + exit(EXIT_FAILURE); } } + if (obj != NULL && cur != NULL) + display_object(obj, nflag); + free(s); }