Sat Mar 7 06:06:24 2015 UTC ()
Pull up following revision(s) (requested by mlelstv in ticket #562):
	sbin/drvctl/drvctl.8: revision 1.14
	sbin/drvctl/drvctl.c: revision 1.17
Let drvctl -p select elements from an array property by numeric index.


(snj)
diff -r1.13 -r1.13.18.1 src/sbin/drvctl/drvctl.8
diff -r1.16 -r1.16.18.1 src/sbin/drvctl/drvctl.c

cvs diff -r1.13 -r1.13.18.1 src/sbin/drvctl/drvctl.8 (expand / switch to unified diff)

--- src/sbin/drvctl/drvctl.8 2012/01/16 19:43:50 1.13
+++ src/sbin/drvctl/drvctl.8 2015/03/07 06:06:24 1.13.18.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: drvctl.8,v 1.13 2012/01/16 19:43:50 pgoyette Exp $ 1.\" $NetBSD: drvctl.8,v 1.13.18.1 2015/03/07 06:06:24 snj Exp $
2.\" 2.\"
3.\" Copyright (c) 2004 3.\" Copyright (c) 2004
4.\" Matthias Drochner. All rights reserved. 4.\" Matthias Drochner. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 14.\"
@@ -104,27 +104,29 @@ The second column is the child. @@ -104,27 +104,29 @@ The second column is the child.
104Suppress first column in 104Suppress first column in
105.Fl l 105.Fl l
106output. 106output.
107Suppress non-XML headers in 107Suppress non-XML headers in
108.Fl p 108.Fl p
109output. 109output.
110.It Fl p 110.It Fl p
111Get properties for the device specified by the 111Get properties for the device specified by the
112.Ar device 112.Ar device
113argument. 113argument.
114If 114If
115.Ar property 115.Ar property
116is specified, the value of that property is printed, otherwise 116is specified, the value of that property is printed, otherwise
117the properties are displayed as an XML property list. 117the properties are displayed as an XML property list. The
 118property can be given as a path of dictionary keys and numeric
 119array indexes separated by slashes.
118.It Fl Q 120.It Fl Q
119Resume the ancestors of 121Resume the ancestors of
120.Ar device , 122.Ar device ,
121.Ar device 123.Ar device
122itself, and all of its descendants. 124itself, and all of its descendants.
123.It Fl R 125.It Fl R
124Resume both the ancestors of 126Resume both the ancestors of
125.Ar device 127.Ar device
126and 128and
127.Ar device 129.Ar device
128itself. 130itself.
129.It Fl r 131.It Fl r
130Rescan the bus given by the 132Rescan the bus given by the

cvs diff -r1.16 -r1.16.18.1 src/sbin/drvctl/drvctl.c (expand / switch to unified diff)

--- src/sbin/drvctl/drvctl.c 2012/01/17 08:22:09 1.16
+++ src/sbin/drvctl/drvctl.c 2015/03/07 06:06:24 1.16.18.1
@@ -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
224static void 224static void
225extract_property(prop_dictionary_t dict, const char *prop, bool nflag) 225extract_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
247static void 263static void
248display_object(prop_object_t obj, bool nflag) 264display_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)) {