xref: /titanic_44/usr/src/cmd/devmgmt/cmds/getdev.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /*        All Rights Reserved   */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  *  getdev.c
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  *  Contains
37*7c478bd9Sstevel@tonic-gate  *	getdev	Writes on the standard output stream a list of devices
38*7c478bd9Sstevel@tonic-gate  *		that match certain criteria.
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
41*7c478bd9Sstevel@tonic-gate #include	<stdio.h>
42*7c478bd9Sstevel@tonic-gate #include	<errno.h>
43*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
44*7c478bd9Sstevel@tonic-gate #include	<string.h>
45*7c478bd9Sstevel@tonic-gate #include	<fmtmsg.h>
46*7c478bd9Sstevel@tonic-gate #include	<devmgmt.h>
47*7c478bd9Sstevel@tonic-gate #include	<devtab.h>
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  *  Local Definitions
52*7c478bd9Sstevel@tonic-gate  *	TRUE		Boolean TRUE value
53*7c478bd9Sstevel@tonic-gate  *	FALSE		Boolean FALSE value
54*7c478bd9Sstevel@tonic-gate  *	EX_OK		Exit Value if all went well
55*7c478bd9Sstevel@tonic-gate  *	EX_ERROR	Exit Value if an error occurred
56*7c478bd9Sstevel@tonic-gate  *	EX_DEVTAB	Exit Value if the device table couldn't be opened
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #ifndef	TRUE
61*7c478bd9Sstevel@tonic-gate #define	TRUE		(1)
62*7c478bd9Sstevel@tonic-gate #endif
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #ifndef	FALSE
65*7c478bd9Sstevel@tonic-gate #define FALSE		(0)
66*7c478bd9Sstevel@tonic-gate #endif
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	EX_OK		0
69*7c478bd9Sstevel@tonic-gate #define	EX_ERROR	1
70*7c478bd9Sstevel@tonic-gate #define	EX_DEVTAB	2
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate  *  Messages:
75*7c478bd9Sstevel@tonic-gate  *	M_USAGE		Usage error
76*7c478bd9Sstevel@tonic-gate  *	M_DEVTAB	Can't open the device table
77*7c478bd9Sstevel@tonic-gate  *	M_NODEV		Device not found in the device table
78*7c478bd9Sstevel@tonic-gate  *	M_ERROR		Unexpected or internal error
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate #define	M_USAGE		"usage: getdev [-ae] [criterion [...]] [device [...]]"
82*7c478bd9Sstevel@tonic-gate #define	M_DEVTAB	"Cannot open the device table: %s"
83*7c478bd9Sstevel@tonic-gate #define	M_NODEV		"Device not found in the device table: %s"
84*7c478bd9Sstevel@tonic-gate #define	M_ERROR		"Internal error, errno=%d"
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /*
88*7c478bd9Sstevel@tonic-gate  *  Local (Static) Definitions and macros
89*7c478bd9Sstevel@tonic-gate  *	buildcriterialist()	Builds the criteria list from the command-line
90*7c478bd9Sstevel@tonic-gate  *	builddevlist()		Builds the device list from the command-line
91*7c478bd9Sstevel@tonic-gate  *	lbl			Buffer for the standard message label
92*7c478bd9Sstevel@tonic-gate  *	txt			Buffer for the standard message text
93*7c478bd9Sstevel@tonic-gate  *	stdmsg(r,l,s,t)		Write a standard message:
94*7c478bd9Sstevel@tonic-gate  *				    r	Recoverability flag
95*7c478bd9Sstevel@tonic-gate  *				    l	Standard label
96*7c478bd9Sstevel@tonic-gate  *				    s	Severity
97*7c478bd9Sstevel@tonic-gate  *				    t	Text
98*7c478bd9Sstevel@tonic-gate  */
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate static	char  **buildcriterialist();
101*7c478bd9Sstevel@tonic-gate static	char  **builddevlist();
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate static	char	lbl[MM_MXLABELLN+1];
104*7c478bd9Sstevel@tonic-gate static	char	txt[MM_MXTXTLN+1];
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate #define	stdmsg(r,l,s,t)	(void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /*
109*7c478bd9Sstevel@tonic-gate  *  getdev [-ae] [criterion [...]] [device [...]]
110*7c478bd9Sstevel@tonic-gate  *
111*7c478bd9Sstevel@tonic-gate  *	This command generates a list of devices that match the
112*7c478bd9Sstevel@tonic-gate  *	specified criteria.
113*7c478bd9Sstevel@tonic-gate  *
114*7c478bd9Sstevel@tonic-gate  *  Options:
115*7c478bd9Sstevel@tonic-gate  *	-a		A device must meet all of the criteria to be
116*7c478bd9Sstevel@tonic-gate  *			included in the generated list instead of just
117*7c478bd9Sstevel@tonic-gate  *			one of the criteria (the "and" flag)
118*7c478bd9Sstevel@tonic-gate  *	-e		Exclude the devices mentioned from the generated
119*7c478bd9Sstevel@tonic-gate  *			list.  If this flag is omitted, the devices in the
120*7c478bd9Sstevel@tonic-gate  *			list are selected from the devices mentioned.
121*7c478bd9Sstevel@tonic-gate  *
122*7c478bd9Sstevel@tonic-gate  *  Arguments:
123*7c478bd9Sstevel@tonic-gate  *	criterion	An <attr><op><value> expression that describes
124*7c478bd9Sstevel@tonic-gate  *			a device attribute.
125*7c478bd9Sstevel@tonic-gate  *			<attr>	is a device attribute
126*7c478bd9Sstevel@tonic-gate  *			<op> 	may be = != : !: indicating equals, does not
127*7c478bd9Sstevel@tonic-gate  *				equal, is defined, and is not defined
128*7c478bd9Sstevel@tonic-gate  *				respectively
129*7c478bd9Sstevel@tonic-gate  *			<value>	is the attribute value.  Currently, the only
130*7c478bd9Sstevel@tonic-gate  *				value supported for the : and !: operators
131*7c478bd9Sstevel@tonic-gate  *				is *
132*7c478bd9Sstevel@tonic-gate  *	device		A device to select for or exclude from the generated
133*7c478bd9Sstevel@tonic-gate  *			list
134*7c478bd9Sstevel@tonic-gate  *
135*7c478bd9Sstevel@tonic-gate  *  Exit values:
136*7c478bd9Sstevel@tonic-gate  *	EX_OK		All went well
137*7c478bd9Sstevel@tonic-gate  *	EX_ERROR	An error (syntax, internal, or resource) occurred
138*7c478bd9Sstevel@tonic-gate  *	EX_DEVTAB	The device-table could not be opened for reading
139*7c478bd9Sstevel@tonic-gate  */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate main(argc, argv)
142*7c478bd9Sstevel@tonic-gate 	int	argc;		/* Number of items on the command line */
143*7c478bd9Sstevel@tonic-gate 	char  **argv;		/* List of pointers to the arguments */
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	/*
147*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
148*7c478bd9Sstevel@tonic-gate 	 */
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 	char	      **arglist;	/* List of arguments */
151*7c478bd9Sstevel@tonic-gate 	char	      **criterialist;	/* List of criteria */
152*7c478bd9Sstevel@tonic-gate 	char	      **devicelist;	/* List of devices to search/ignore */
153*7c478bd9Sstevel@tonic-gate 	char	      **fitdevlist;	/* List of devices that fit criteria */
154*7c478bd9Sstevel@tonic-gate 	char	       *cmdname;	/* Simple command name */
155*7c478bd9Sstevel@tonic-gate 	char	       *device;		/* Device name in the list */
156*7c478bd9Sstevel@tonic-gate 	char	       *devtab;		/* The device table name */
157*7c478bd9Sstevel@tonic-gate 	int		exitcode;	/* Value to return to the caller */
158*7c478bd9Sstevel@tonic-gate 	int		sev;		/* Message severity */
159*7c478bd9Sstevel@tonic-gate 	int		optchar;	/* Option character (from getopt()) */
160*7c478bd9Sstevel@tonic-gate 	int		andflag;	/* TRUE if criteria are to be anded */
161*7c478bd9Sstevel@tonic-gate 	int		excludeflag;	/* TRUE if exclude "devices" lists */
162*7c478bd9Sstevel@tonic-gate 	int		options;	/* Options to pass to getdev() */
163*7c478bd9Sstevel@tonic-gate 	int		usageerr;	/* TRUE if syntax error */
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	/* Build the message label from the (simple) command name */
167*7c478bd9Sstevel@tonic-gate 	if ((cmdname = strrchr(argv[0], '/')) != (char *) NULL) cmdname++;
168*7c478bd9Sstevel@tonic-gate 	else cmdname = argv[0];
169*7c478bd9Sstevel@tonic-gate 	(void) strlcat(strcpy(lbl, "UX:"), cmdname, sizeof(lbl));
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 	/* Write text-component of messages only (goes away in SVR4.1) */
172*7c478bd9Sstevel@tonic-gate 	(void) putenv("MSGVERB=text");
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	/*
175*7c478bd9Sstevel@tonic-gate 	 *  Parse the command line:
176*7c478bd9Sstevel@tonic-gate 	 *	- Options
177*7c478bd9Sstevel@tonic-gate 	 *	- Selection criteria
178*7c478bd9Sstevel@tonic-gate 	 *	- Devices to include or exclude
179*7c478bd9Sstevel@tonic-gate 	 */
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 	/*
182*7c478bd9Sstevel@tonic-gate 	 *  Extract options from the command line
183*7c478bd9Sstevel@tonic-gate 	 */
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 	/* Initializations */
186*7c478bd9Sstevel@tonic-gate 	andflag = FALSE;	/* No -a -- Or criteria data */
187*7c478bd9Sstevel@tonic-gate 	excludeflag = FALSE;	/* No -e -- Include only mentioned devices */
188*7c478bd9Sstevel@tonic-gate 	usageerr = FALSE;	/* No errors on the command line (yet) */
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	/*
191*7c478bd9Sstevel@tonic-gate 	 *  Loop until all of the command line options have been parced
192*7c478bd9Sstevel@tonic-gate 	 */
193*7c478bd9Sstevel@tonic-gate 	opterr = FALSE;			/* Don't let getopt() write messages */
194*7c478bd9Sstevel@tonic-gate 	while ((optchar = getopt(argc, argv, "ae")) != EOF) switch (optchar) {
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 	/* -a  List devices that fit all of the criteria listed */
197*7c478bd9Sstevel@tonic-gate 	case 'a':
198*7c478bd9Sstevel@tonic-gate 	    if (andflag) usageerr = TRUE;
199*7c478bd9Sstevel@tonic-gate 	    else andflag = TRUE;
200*7c478bd9Sstevel@tonic-gate 	    break;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 	/* -e  Exclude those devices mentioned on the command line */
203*7c478bd9Sstevel@tonic-gate 	case 'e':
204*7c478bd9Sstevel@tonic-gate 	    if (excludeflag) usageerr = TRUE;
205*7c478bd9Sstevel@tonic-gate 	    else excludeflag = TRUE;
206*7c478bd9Sstevel@tonic-gate 	    break;
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	/* Default case -- command usage error */
209*7c478bd9Sstevel@tonic-gate 	case '?':
210*7c478bd9Sstevel@tonic-gate 	default:
211*7c478bd9Sstevel@tonic-gate 	    usageerr = TRUE;
212*7c478bd9Sstevel@tonic-gate 	    break;
213*7c478bd9Sstevel@tonic-gate 	}
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	/* If there is a usage error, write an appropriate message and exit */
216*7c478bd9Sstevel@tonic-gate 	if (usageerr) {
217*7c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, MM_ERROR, M_USAGE);
218*7c478bd9Sstevel@tonic-gate 	    exit(EX_ERROR);
219*7c478bd9Sstevel@tonic-gate 	}
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	/* Open the device file (if there's one to be opened) */
222*7c478bd9Sstevel@tonic-gate 	if (!_opendevtab("r")) {
223*7c478bd9Sstevel@tonic-gate 	    if (devtab = _devtabpath()) {
224*7c478bd9Sstevel@tonic-gate 		(void) snprintf(txt, sizeof(txt), M_DEVTAB, devtab);
225*7c478bd9Sstevel@tonic-gate 		sev = MM_ERROR;
226*7c478bd9Sstevel@tonic-gate 		exitcode = EX_DEVTAB;
227*7c478bd9Sstevel@tonic-gate 	    } else {
228*7c478bd9Sstevel@tonic-gate 		(void) sprintf(txt, M_ERROR, errno);
229*7c478bd9Sstevel@tonic-gate 		sev = MM_HALT;
230*7c478bd9Sstevel@tonic-gate 		exitcode = EX_ERROR;
231*7c478bd9Sstevel@tonic-gate 	    }
232*7c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, sev, txt);
233*7c478bd9Sstevel@tonic-gate 	    exit(exitcode);
234*7c478bd9Sstevel@tonic-gate 	}
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	/* Build the list of criteria and devices */
237*7c478bd9Sstevel@tonic-gate 	arglist = argv + optind;
238*7c478bd9Sstevel@tonic-gate 	criterialist = buildcriterialist(arglist);
239*7c478bd9Sstevel@tonic-gate 	devicelist = builddevlist(arglist);
240*7c478bd9Sstevel@tonic-gate 	options = (excludeflag?DTAB_EXCLUDEFLAG:0)|(andflag?DTAB_ANDCRITERIA:0);
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	/*
243*7c478bd9Sstevel@tonic-gate 	 *  Get the list of devices that meets the criteria requested.  If we
244*7c478bd9Sstevel@tonic-gate 	 *  got a list (that might be empty), write that list to the standard
245*7c478bd9Sstevel@tonic-gate 	 *  output file (stdout).
246*7c478bd9Sstevel@tonic-gate 	 */
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	exitcode = 0;
249*7c478bd9Sstevel@tonic-gate 	if (!(fitdevlist = getdev(devicelist, criterialist, options))) {
250*7c478bd9Sstevel@tonic-gate 	    exitcode = 1;
251*7c478bd9Sstevel@tonic-gate 	}
252*7c478bd9Sstevel@tonic-gate 	else for (device = *fitdevlist++ ; device ; device = *fitdevlist++)
253*7c478bd9Sstevel@tonic-gate 		(void) puts(device);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	/* Finished */
256*7c478bd9Sstevel@tonic-gate 	return(exitcode);
257*7c478bd9Sstevel@tonic-gate }
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate /*
260*7c478bd9Sstevel@tonic-gate  *  char **buildcriterialist(arglist)
261*7c478bd9Sstevel@tonic-gate  *	char  **arglist
262*7c478bd9Sstevel@tonic-gate  *
263*7c478bd9Sstevel@tonic-gate  *	Build a list of pointers to the criterion on the command-line
264*7c478bd9Sstevel@tonic-gate  *
265*7c478bd9Sstevel@tonic-gate  *  Arguments:
266*7c478bd9Sstevel@tonic-gate  *	arglist		The list of arguments on the command-line
267*7c478bd9Sstevel@tonic-gate  *
268*7c478bd9Sstevel@tonic-gate  *  Returns:  char **
269*7c478bd9Sstevel@tonic-gate  *	The address of the first item of the list of criterion on the
270*7c478bd9Sstevel@tonic-gate  *	command-line.  This is a pointer to malloc()ed space.
271*7c478bd9Sstevel@tonic-gate  */
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate static char  **
274*7c478bd9Sstevel@tonic-gate buildcriterialist(arglist)
275*7c478bd9Sstevel@tonic-gate 	char  **arglist;	/* Pointer to the list of argument pointers */
276*7c478bd9Sstevel@tonic-gate {
277*7c478bd9Sstevel@tonic-gate 	/*
278*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
279*7c478bd9Sstevel@tonic-gate 	 */
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 	char  **pp;			/* Pointer to a criteria */
282*7c478bd9Sstevel@tonic-gate 	char  **allocbuf;		/* Pointer to the allocated data */
283*7c478bd9Sstevel@tonic-gate 	int	ncriteria;		/* Number of criteria found */
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	/*
287*7c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or
288*7c478bd9Sstevel@tonic-gate 	 *  the first thing that's not a criteria.  (A criteria is a
289*7c478bd9Sstevel@tonic-gate 	 *  character-string that contains a colon (':') or an equal-sign ('=')
290*7c478bd9Sstevel@tonic-gate 	 */
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	pp = arglist;
293*7c478bd9Sstevel@tonic-gate 	ncriteria = 0;
294*7c478bd9Sstevel@tonic-gate 	while (*pp && (strchr(*pp, '=') || strchr(*pp, ':'))) {
295*7c478bd9Sstevel@tonic-gate 	    ncriteria++;
296*7c478bd9Sstevel@tonic-gate 	    pp++;
297*7c478bd9Sstevel@tonic-gate 	}
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 	if (ncriteria > 0) {
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	    /* Allocate space for the list of criteria pointers */
302*7c478bd9Sstevel@tonic-gate 	    allocbuf = (char **) malloc((ncriteria+1)*sizeof(char **));
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	    /*
305*7c478bd9Sstevel@tonic-gate 	     *  Build the list of criteria arguments
306*7c478bd9Sstevel@tonic-gate 	     */
307*7c478bd9Sstevel@tonic-gate 	    pp = allocbuf;	/* Beginning of the list */
308*7c478bd9Sstevel@tonic-gate 	    while (*arglist &&			/* If there's more to do ... */
309*7c478bd9Sstevel@tonic-gate 		   (strchr(*arglist, '=') ||	/* and it's a = criterion ... */
310*7c478bd9Sstevel@tonic-gate 		    strchr(*arglist, ':')))	/* or it's a : criterion ... */
311*7c478bd9Sstevel@tonic-gate 			*pp++ = *arglist++;	/* Include it in the list */
312*7c478bd9Sstevel@tonic-gate 	    *pp = (char *) NULL;	/* Terminate the list */
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	} else allocbuf = (char **) NULL;	/* NO criteria */
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate 	return (allocbuf);
318*7c478bd9Sstevel@tonic-gate }
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate /*
321*7c478bd9Sstevel@tonic-gate  *  char **builddevlist(arglist)
322*7c478bd9Sstevel@tonic-gate  *	char  **arglist
323*7c478bd9Sstevel@tonic-gate  *
324*7c478bd9Sstevel@tonic-gate  *	Builds a list of pointers to the devices mentioned on the command-
325*7c478bd9Sstevel@tonic-gate  *	line and returns the address of that list.
326*7c478bd9Sstevel@tonic-gate  *
327*7c478bd9Sstevel@tonic-gate  *  Arguments:
328*7c478bd9Sstevel@tonic-gate  *	arglist		The address of the list of arguments to the
329*7c478bd9Sstevel@tonic-gate  *			getdev command.
330*7c478bd9Sstevel@tonic-gate  *
331*7c478bd9Sstevel@tonic-gate  *  Returns:  char **
332*7c478bd9Sstevel@tonic-gate  *	A pointer to the first item in the list of pointers to devices
333*7c478bd9Sstevel@tonic-gate  *	specified on the command-line
334*7c478bd9Sstevel@tonic-gate  */
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate static char  **
337*7c478bd9Sstevel@tonic-gate builddevlist(arglist)
338*7c478bd9Sstevel@tonic-gate 	char  **arglist;	/* Pointer to the list of pointers to args */
339*7c478bd9Sstevel@tonic-gate {
340*7c478bd9Sstevel@tonic-gate 	/*
341*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
342*7c478bd9Sstevel@tonic-gate 	 */
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	/*
345*7c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or the
346*7c478bd9Sstevel@tonic-gate 	 *  first thing that's not a criteria.  It is the first device in the
347*7c478bd9Sstevel@tonic-gate 	 *  list of devices (if any).
348*7c478bd9Sstevel@tonic-gate 	 */
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate 	while (*arglist && (strchr(*arglist, '=') || strchr(*arglist, ':'))) arglist++;
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate 	/* Return a pointer to the argument list. */
353*7c478bd9Sstevel@tonic-gate 	return(*arglist?arglist:(char **) NULL);
354*7c478bd9Sstevel@tonic-gate }
355