xref: /illumos-gate/usr/src/cmd/devmgmt/cmds/getdgrp.c (revision 7c478bd9)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  *  Implements the main body of the "getdgrp" command.
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include	<stdio.h>
37*7c478bd9Sstevel@tonic-gate #include	<errno.h>
38*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
39*7c478bd9Sstevel@tonic-gate #include	<string.h>
40*7c478bd9Sstevel@tonic-gate #include	<devmgmt.h>
41*7c478bd9Sstevel@tonic-gate #include	<devtab.h>
42*7c478bd9Sstevel@tonic-gate #include	<fmtmsg.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  *  Local Definitions
47*7c478bd9Sstevel@tonic-gate  *	TRUE		Boolean TRUE value
48*7c478bd9Sstevel@tonic-gate  *	FALSE		Boolean FALSE value
49*7c478bd9Sstevel@tonic-gate  *	NULL		Null address
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #ifndef	TRUE
53*7c478bd9Sstevel@tonic-gate #define	TRUE	1
54*7c478bd9Sstevel@tonic-gate #endif
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #ifndef	FALSE
57*7c478bd9Sstevel@tonic-gate #define FALSE	0
58*7c478bd9Sstevel@tonic-gate #endif
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Exit codes:
63*7c478bd9Sstevel@tonic-gate  *	EX_OK		All's well that ends well
64*7c478bd9Sstevel@tonic-gate  *	EX_ERROR	Some other error occurred
65*7c478bd9Sstevel@tonic-gate  *	EX_DTAB		Device table couldn't be opened
66*7c478bd9Sstevel@tonic-gate  *	EX_DGRP		Device-group table couldn't be open.
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #define	EX_OK		0
70*7c478bd9Sstevel@tonic-gate #define	EX_ERROR	1
71*7c478bd9Sstevel@tonic-gate #define	EX_DTAB		2
72*7c478bd9Sstevel@tonic-gate #define	EX_DGRP		2
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  *  Messages:
77*7c478bd9Sstevel@tonic-gate  *	M_USAGE		Command usage error
78*7c478bd9Sstevel@tonic-gate  *	M_ERROR		Some unexpected error
79*7c478bd9Sstevel@tonic-gate  *	M_DEVTAB	Device table couldn't be opened
80*7c478bd9Sstevel@tonic-gate  *	M_DGROUP	Device-group table couldn't be opened
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate #define	M_USAGE		"usage: getdgrp [-ael] [criterion [...]] [dgroup [...]]"
84*7c478bd9Sstevel@tonic-gate #define	M_ERROR		"Internal error, errno=%d"
85*7c478bd9Sstevel@tonic-gate #define	M_DEVTAB	"Cannot open the device table: %s"
86*7c478bd9Sstevel@tonic-gate #define	M_DGROUP	"Cannot open the device-group table: %s"
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  *  Internal References
91*7c478bd9Sstevel@tonic-gate  *	buildcriterialist()	Builds a list of the criteria on the
92*7c478bd9Sstevel@tonic-gate  *				command line
93*7c478bd9Sstevel@tonic-gate  *	buildgrouplist()	Builds a list of the device-groups mentioned
94*7c478bd9Sstevel@tonic-gate  *				on the command line
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate static	char  **buildcriterialist();	/* Builds criteria list from command line */
98*7c478bd9Sstevel@tonic-gate static	char  **builddgrouplist();	/* Builds dgroup list from command line */
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  *  Macros
103*7c478bd9Sstevel@tonic-gate  *	stdmsg(r,l,s,t)	    Generate a standard message
104*7c478bd9Sstevel@tonic-gate  *				r	Recoverability flag
105*7c478bd9Sstevel@tonic-gate  *				l	Standard label
106*7c478bd9Sstevel@tonic-gate  *				s	Severity
107*7c478bd9Sstevel@tonic-gate  *				t	Text
108*7c478bd9Sstevel@tonic-gate  *	isacriterion(p)	    Returns TRUE if *p is a criterion, FALSE otherwise
109*7c478bd9Sstevel@tonic-gate  */
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate #define	stdmsg(r,l,s,t)	(void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
112*7c478bd9Sstevel@tonic-gate #define	isacriterion(p)	(strchr(*arglist,'=')||strchr(*arglist,':'))
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  *  Static Variables
117*7c478bd9Sstevel@tonic-gate  *	lbl		Buffer for standard message label
118*7c478bd9Sstevel@tonic-gate  *	txt		Buffer for standard message text
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate static	char	lbl[MM_MXLABELLN+1];
122*7c478bd9Sstevel@tonic-gate static	char	txt[MM_MXTXTLN+1];
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate  *  getdgrp [-ael] [criterion [...]] [dgroup [...]]
126*7c478bd9Sstevel@tonic-gate  *
127*7c478bd9Sstevel@tonic-gate  *	This function gets the device groups that contain as members devices
128*7c478bd9Sstevel@tonic-gate  *	that match the given criteria.
129*7c478bd9Sstevel@tonic-gate  *
130*7c478bd9Sstevel@tonic-gate  *  Options:
131*7c478bd9Sstevel@tonic-gate  *	-a	A device must meet all criteria before the device-group in
132*7c478bd9Sstevel@tonic-gate  *		which it is a member can be selected for inclusion in the
133*7c478bd9Sstevel@tonic-gate  *		generated list.  If this option is missing, a device must
134*7c478bd9Sstevel@tonic-gate  *		meet at least one criterion before it's group can be
135*7c478bd9Sstevel@tonic-gate  *		selected.  This option has no affect if there are no criterion
136*7c478bd9Sstevel@tonic-gate  *		on the command-line.
137*7c478bd9Sstevel@tonic-gate  *	-e	The list of device groups specifies groups to exclude from
138*7c478bd9Sstevel@tonic-gate  *		the generated list.  If this option is omitted, the list
139*7c478bd9Sstevel@tonic-gate  *		of groups is the set of groups that can be selected.  This
140*7c478bd9Sstevel@tonic-gate  *		option has no effect if there are no device-groups on the
141*7c478bd9Sstevel@tonic-gate  *		command-line.
142*7c478bd9Sstevel@tonic-gate  *	-l	List all device groups, even those that have no valid
143*7c478bd9Sstevel@tonic-gate  *		members (this option has no effect if criterion are specified
144*7c478bd9Sstevel@tonic-gate  *
145*7c478bd9Sstevel@tonic-gate  *  Arguments:
146*7c478bd9Sstevel@tonic-gate  *	criterion	A device criterion of the form <attr><op><val> where
147*7c478bd9Sstevel@tonic-gate  *			<attr> is the name of an attribute, <op> is "=", "!=",
148*7c478bd9Sstevel@tonic-gate  *			":", or "!:" for "is equal to", "is not equal to",
149*7c478bd9Sstevel@tonic-gate  *			"is defined," or "is not defined."  <val> is the value
150*7c478bd9Sstevel@tonic-gate  *			that the attribute must be equal to or not equal to.
151*7c478bd9Sstevel@tonic-gate  *			(<val> must be "*" if <op> is ":" or "!:").
152*7c478bd9Sstevel@tonic-gate  *	dgroup		A device group that is to be exclude selected for the
153*7c478bd9Sstevel@tonic-gate  *			generated list or excluded from the the generated
154*7c478bd9Sstevel@tonic-gate  *			list.
155*7c478bd9Sstevel@tonic-gate  *
156*7c478bd9Sstevel@tonic-gate  *  Exit values:
157*7c478bd9Sstevel@tonic-gate  *	0	Success
158*7c478bd9Sstevel@tonic-gate  *	1	Usage or an internal error
159*7c478bd9Sstevel@tonic-gate  *	2	The device table or the device-group table could not be
160*7c478bd9Sstevel@tonic-gate  *		opened for reading
161*7c478bd9Sstevel@tonic-gate  */
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate main(argc, argv)
164*7c478bd9Sstevel@tonic-gate 	int	argc;		/* Number of items on the command line */
165*7c478bd9Sstevel@tonic-gate 	char  **argv;		/* List of pointers to the arguments */
166*7c478bd9Sstevel@tonic-gate {
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	/*
169*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
170*7c478bd9Sstevel@tonic-gate 	 */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 	char  **arglist;	/* List of arguments (subset of argv) */
173*7c478bd9Sstevel@tonic-gate 	char  **criterialist;	/* List of criteria */
174*7c478bd9Sstevel@tonic-gate 	char  **dgrouplist;	/* List of device groups to search or ignore */
175*7c478bd9Sstevel@tonic-gate 	char  **fitgrouplist;	/* List of device groups that fit criteria */
176*7c478bd9Sstevel@tonic-gate 	char   *cmdname;	/* Simple command name */
177*7c478bd9Sstevel@tonic-gate 	char   *dgroup;		/* Pointer to device group name in list */
178*7c478bd9Sstevel@tonic-gate 	char   *filename;	/* Pointer to filename in "error" */
179*7c478bd9Sstevel@tonic-gate 	int	exitcode;	/* Value to return to the caller */
180*7c478bd9Sstevel@tonic-gate 	int	sev;		/* Message severity */
181*7c478bd9Sstevel@tonic-gate 	int	optchar;	/* Option character (returned by getopt()) */
182*7c478bd9Sstevel@tonic-gate 	int	andflag;	/* TRUE if anding criteria, FALSE if or'ed */
183*7c478bd9Sstevel@tonic-gate 	int	excludeflag;	/* TRUE if the dgroups list those to exclude */
184*7c478bd9Sstevel@tonic-gate 	int	allflag;	/* TRUE if all device grps are to be displayed */
185*7c478bd9Sstevel@tonic-gate 	int	options;	/* Options to pass to getdgrp() */
186*7c478bd9Sstevel@tonic-gate 	int	usageerr;	/* TRUE if syntax error */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate 	/* Build the message label from the (simple) command name */
190*7c478bd9Sstevel@tonic-gate 	if (cmdname = strrchr(argv[0], '/')) cmdname++;
191*7c478bd9Sstevel@tonic-gate 	else cmdname = argv[0];
192*7c478bd9Sstevel@tonic-gate 	(void) strlcat(strcpy(lbl, "UX:"), cmdname, sizeof(lbl));
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 	/* Only write the text-component of messages (this goes away in SVR4.1) */
195*7c478bd9Sstevel@tonic-gate 	(void) putenv("MSGVERB=text");
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	/*
198*7c478bd9Sstevel@tonic-gate 	 *  Parse the command line:
199*7c478bd9Sstevel@tonic-gate 	 *	- Options
200*7c478bd9Sstevel@tonic-gate 	 *	- Selection criteria
201*7c478bd9Sstevel@tonic-gate 	 *	- Device groups to include or exclude
202*7c478bd9Sstevel@tonic-gate 	 */
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	/*
205*7c478bd9Sstevel@tonic-gate 	 *  Extract options from the command line
206*7c478bd9Sstevel@tonic-gate 	 */
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	/* Initializations */
209*7c478bd9Sstevel@tonic-gate 	andflag = FALSE;		/* No -a */
210*7c478bd9Sstevel@tonic-gate 	excludeflag = FALSE;		/* No -e */
211*7c478bd9Sstevel@tonic-gate 	allflag = FALSE;		/* No -l */
212*7c478bd9Sstevel@tonic-gate 	usageerr = FALSE;		/* No errors yet */
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	/*
215*7c478bd9Sstevel@tonic-gate 	 *  Loop until all of the command line options have been parced
216*7c478bd9Sstevel@tonic-gate 	 */
217*7c478bd9Sstevel@tonic-gate 	opterr = FALSE;			/* Don't let getopt() write messages */
218*7c478bd9Sstevel@tonic-gate 	while ((optchar = getopt(argc, argv, "ael")) != EOF) switch (optchar) {
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 	/* -a  List device groups that fit all of the criteria listed */
221*7c478bd9Sstevel@tonic-gate 	case 'a':
222*7c478bd9Sstevel@tonic-gate 	    if (andflag) usageerr = TRUE;
223*7c478bd9Sstevel@tonic-gate 	    else andflag = TRUE;
224*7c478bd9Sstevel@tonic-gate 	    break;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 	/* -e  Exclude those device groups mentioned on the command line */
227*7c478bd9Sstevel@tonic-gate 	case 'e':
228*7c478bd9Sstevel@tonic-gate 	    if (excludeflag) usageerr = TRUE;
229*7c478bd9Sstevel@tonic-gate 	    else excludeflag = TRUE;
230*7c478bd9Sstevel@tonic-gate 	    break;
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	/* -l  List all device groups (if no criteria is specified) */
233*7c478bd9Sstevel@tonic-gate 	case 'l':
234*7c478bd9Sstevel@tonic-gate 	    if (allflag) usageerr = TRUE;
235*7c478bd9Sstevel@tonic-gate 	    else allflag = TRUE;
236*7c478bd9Sstevel@tonic-gate 	    break;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 	/* Default case -- command usage error */
239*7c478bd9Sstevel@tonic-gate 	case '?':
240*7c478bd9Sstevel@tonic-gate 	default:
241*7c478bd9Sstevel@tonic-gate 	    usageerr = TRUE;
242*7c478bd9Sstevel@tonic-gate 	    break;
243*7c478bd9Sstevel@tonic-gate 	}
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	/* If there is a usage error, write an appropriate message and exit */
246*7c478bd9Sstevel@tonic-gate 	if (usageerr) {
247*7c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, MM_ERROR, M_USAGE);
248*7c478bd9Sstevel@tonic-gate 	    exit(EX_ERROR);
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	/* Open the device file (if there's one to be opened) */
252*7c478bd9Sstevel@tonic-gate 	if (!_opendevtab("r")) {
253*7c478bd9Sstevel@tonic-gate 	    if (filename = _devtabpath()) {
254*7c478bd9Sstevel@tonic-gate 		(void) snprintf(txt, sizeof(txt), M_DEVTAB, filename);
255*7c478bd9Sstevel@tonic-gate 		exitcode = EX_DTAB;
256*7c478bd9Sstevel@tonic-gate 		sev = MM_ERROR;
257*7c478bd9Sstevel@tonic-gate 	    } else {
258*7c478bd9Sstevel@tonic-gate 		(void) sprintf(txt, M_ERROR, errno);
259*7c478bd9Sstevel@tonic-gate 		exitcode = EX_ERROR;
260*7c478bd9Sstevel@tonic-gate 		sev = MM_HALT;
261*7c478bd9Sstevel@tonic-gate 	    }
262*7c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, sev, txt);
263*7c478bd9Sstevel@tonic-gate 	    exit(exitcode);
264*7c478bd9Sstevel@tonic-gate 	}
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 	/* Open the device file (if there's one to be opened) */
267*7c478bd9Sstevel@tonic-gate 	if (!_opendgrptab("r")) {
268*7c478bd9Sstevel@tonic-gate 	    if (filename = _dgrptabpath()) {
269*7c478bd9Sstevel@tonic-gate 		(void) snprintf(txt, sizeof(txt), M_DGROUP, filename);
270*7c478bd9Sstevel@tonic-gate 		exitcode = EX_DGRP;
271*7c478bd9Sstevel@tonic-gate 		sev = MM_ERROR;
272*7c478bd9Sstevel@tonic-gate 	    } else {
273*7c478bd9Sstevel@tonic-gate 		(void) sprintf(txt, M_ERROR, errno);
274*7c478bd9Sstevel@tonic-gate 		exitcode = EX_ERROR;
275*7c478bd9Sstevel@tonic-gate 		sev = MM_HALT;
276*7c478bd9Sstevel@tonic-gate 	    }
277*7c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, sev, txt);
278*7c478bd9Sstevel@tonic-gate 	    exit(exitcode);
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 	/* Build the list of criteria and device groups */
282*7c478bd9Sstevel@tonic-gate 	arglist = argv + optind;
283*7c478bd9Sstevel@tonic-gate 	criterialist = buildcriterialist(arglist);
284*7c478bd9Sstevel@tonic-gate 	dgrouplist = builddgrouplist(arglist);
285*7c478bd9Sstevel@tonic-gate 	options = (excludeflag ? DTAB_EXCLUDEFLAG : 0) |
286*7c478bd9Sstevel@tonic-gate 		  (andflag ? DTAB_ANDCRITERIA : 0) |
287*7c478bd9Sstevel@tonic-gate 		  (allflag ? DTAB_LISTALL : 0) ;
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	/*
290*7c478bd9Sstevel@tonic-gate 	 *  Get the list of device groups that meets the criteria requested.
291*7c478bd9Sstevel@tonic-gate 	 *  If we got a list (that might be empty), write that list to the
292*7c478bd9Sstevel@tonic-gate 	 *  standard output file (stdout).
293*7c478bd9Sstevel@tonic-gate 	 */
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	exitcode = EX_OK;
296*7c478bd9Sstevel@tonic-gate 	if (!(fitgrouplist = getdgrp(dgrouplist, criterialist, options))) {
297*7c478bd9Sstevel@tonic-gate 	    exitcode = EX_ERROR;
298*7c478bd9Sstevel@tonic-gate 	}
299*7c478bd9Sstevel@tonic-gate 	else for (dgroup = *fitgrouplist++ ; dgroup ; dgroup = *fitgrouplist++)
300*7c478bd9Sstevel@tonic-gate 		(void) puts(dgroup);
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 	/* Finished */
303*7c478bd9Sstevel@tonic-gate 	return(exitcode);
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate  *  char **buildcriterialist(arglist)
308*7c478bd9Sstevel@tonic-gate  *	char **arglist
309*7c478bd9Sstevel@tonic-gate  *
310*7c478bd9Sstevel@tonic-gate  *	This function builds a list of criteria descriptions from the
311*7c478bd9Sstevel@tonic-gate  *	list of arguments given.  The list returned is in malloc()ed
312*7c478bd9Sstevel@tonic-gate  *	space.
313*7c478bd9Sstevel@tonic-gate  *
314*7c478bd9Sstevel@tonic-gate  *  Arguments:
315*7c478bd9Sstevel@tonic-gate  *	arglist		The address of the first element in the list
316*7c478bd9Sstevel@tonic-gate  *			of arguments (possibly) containing criterion
317*7c478bd9Sstevel@tonic-gate  *
318*7c478bd9Sstevel@tonic-gate  *  Returns:  char **
319*7c478bd9Sstevel@tonic-gate  *	A pointer to the first element in the list of criterion.
320*7c478bd9Sstevel@tonic-gate  *	If there was a problem, the function returns (char **) NULL.
321*7c478bd9Sstevel@tonic-gate  *	If there are no criteria in the list, the function returns
322*7c478bd9Sstevel@tonic-gate  *	an empty list.
323*7c478bd9Sstevel@tonic-gate  */
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate static char  **
326*7c478bd9Sstevel@tonic-gate buildcriterialist(arglist)
327*7c478bd9Sstevel@tonic-gate 	char  **arglist;	/* Pointer to the list of argument pointers */
328*7c478bd9Sstevel@tonic-gate {
329*7c478bd9Sstevel@tonic-gate 	/*
330*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
331*7c478bd9Sstevel@tonic-gate 	 */
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	char	      **pp; 		/* Pointer to a criteria */
334*7c478bd9Sstevel@tonic-gate 	void	       *allocbuf;	/* Pointer to the allocated data */
335*7c478bd9Sstevel@tonic-gate 	int		ncriteria;	/* Number of criteria found */
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	/*
339*7c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or
340*7c478bd9Sstevel@tonic-gate 	 *  the first thing that's not a criteria.  (A criteria is a
341*7c478bd9Sstevel@tonic-gate 	 *  character-string that contains a colon (':') or an equal-sign ('=')
342*7c478bd9Sstevel@tonic-gate 	 */
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	pp = arglist;
345*7c478bd9Sstevel@tonic-gate 	ncriteria = 1;
346*7c478bd9Sstevel@tonic-gate 	while (*pp && (strchr(*pp, '=') || strchr(*pp, ':'))) {
347*7c478bd9Sstevel@tonic-gate 	    ncriteria++;
348*7c478bd9Sstevel@tonic-gate 	    pp++;
349*7c478bd9Sstevel@tonic-gate 	}
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	/* Allocate space for the list of criteria pointers */
352*7c478bd9Sstevel@tonic-gate 	if (allocbuf = malloc(ncriteria*sizeof(char **))) {
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	    /* Build the list of criteria arguments */
355*7c478bd9Sstevel@tonic-gate 	    pp = (char **) allocbuf;
356*7c478bd9Sstevel@tonic-gate 	    while ((*arglist != (char *) NULL) && isacriterion(*arglist)) *pp++ = *arglist++;
357*7c478bd9Sstevel@tonic-gate 	    *pp = (char *) NULL;
358*7c478bd9Sstevel@tonic-gate 	}
359*7c478bd9Sstevel@tonic-gate 
360*7c478bd9Sstevel@tonic-gate 	return ((char **) allocbuf);
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate /*
364*7c478bd9Sstevel@tonic-gate  *  char **builddgrouplist(arglist)
365*7c478bd9Sstevel@tonic-gate  *	char  **arglist
366*7c478bd9Sstevel@tonic-gate  *
367*7c478bd9Sstevel@tonic-gate  *	This function returns a pointer to the first element in a list of
368*7c478bd9Sstevel@tonic-gate  *	device-groups (i.e. not criteria) specified in the list of arguments
369*7c478bd9Sstevel@tonic-gate  *	whose first element is pointed to by <arglist>.
370*7c478bd9Sstevel@tonic-gate  *
371*7c478bd9Sstevel@tonic-gate  *  Arguments:
372*7c478bd9Sstevel@tonic-gate  *	arglist		The address of the first element in the list of
373*7c478bd9Sstevel@tonic-gate  *			arguments to be searched for non-criteria
374*7c478bd9Sstevel@tonic-gate  *
375*7c478bd9Sstevel@tonic-gate  *  Returns:  char **
376*7c478bd9Sstevel@tonic-gate  *	The address of the first item in the list of arguments that are
377*7c478bd9Sstevel@tonic-gate  *	not criteria.  If none, the function returns a pointer to a
378*7c478bd9Sstevel@tonic-gate  *	null list.
379*7c478bd9Sstevel@tonic-gate  *
380*7c478bd9Sstevel@tonic-gate  *  Note:
381*7c478bd9Sstevel@tonic-gate  *	- The current implementation returns a pointer to an element in
382*7c478bd9Sstevel@tonic-gate  *	  <arglist>.
383*7c478bd9Sstevel@tonic-gate  */
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate static char  **
386*7c478bd9Sstevel@tonic-gate builddgrouplist(arglist)
387*7c478bd9Sstevel@tonic-gate 	char  **arglist;	/* First item in the list of arguments */
388*7c478bd9Sstevel@tonic-gate {
389*7c478bd9Sstevel@tonic-gate 	/*
390*7c478bd9Sstevel@tonic-gate 	 *  Automatic data
391*7c478bd9Sstevel@tonic-gate 	 */
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate 	/*
394*7c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or
395*7c478bd9Sstevel@tonic-gate 	 *  the first thing that's not a criteria.  It is the first device
396*7c478bd9Sstevel@tonic-gate 	 *  group in the list of device groups (if any).
397*7c478bd9Sstevel@tonic-gate 	 */
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	while (*arglist && isacriterion(*arglist)) arglist++;
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate 	/* Return a pointer to the argument list. */
402*7c478bd9Sstevel@tonic-gate 	return(arglist);
403*7c478bd9Sstevel@tonic-gate }
404