Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/drvctl Let drvctl -p select elements from an array prop...
details: https://anonhg.NetBSD.org/src/rev/004c6a71bd55
branches: trunk
changeset: 336294:004c6a71bd55
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Tue Feb 24 18:15:29 2015 +0000
description:
Let drvctl -p select elements from an array property by numeric index.
diffstat:
sbin/drvctl/drvctl.8 | 6 ++++--
sbin/drvctl/drvctl.c | 28 ++++++++++++++++++++++------
2 files changed, 26 insertions(+), 8 deletions(-)
diffs (72 lines):
diff -r 79a3bb62d127 -r 004c6a71bd55 sbin/drvctl/drvctl.8
--- a/sbin/drvctl/drvctl.8 Tue Feb 24 17:56:20 2015 +0000
+++ b/sbin/drvctl/drvctl.8 Tue Feb 24 18:15:29 2015 +0000
@@ -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 @@
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 ,
diff -r 79a3bb62d127 -r 004c6a71bd55 sbin/drvctl/drvctl.c
--- a/sbin/drvctl/drvctl.c Tue Feb 24 17:56:20 2015 +0000
+++ b/sbin/drvctl/drvctl.c Tue Feb 24 18:15:29 2015 +0000
@@ -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 @@
{
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);
}
Home |
Main Index |
Thread Index |
Old Index