xref: /illumos-gate/usr/src/cmd/devmgmt/cmds/getdgrp.c (revision 113f4232)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*113f4232Sakaplan  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  *  Implements the main body of the "getdgrp" command.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate #include	<sys/types.h>
367c478bd9Sstevel@tonic-gate #include	<stdio.h>
377c478bd9Sstevel@tonic-gate #include	<errno.h>
387c478bd9Sstevel@tonic-gate #include	<stdlib.h>
397c478bd9Sstevel@tonic-gate #include	<string.h>
407c478bd9Sstevel@tonic-gate #include	<devmgmt.h>
417c478bd9Sstevel@tonic-gate #include	<devtab.h>
427c478bd9Sstevel@tonic-gate #include	<fmtmsg.h>
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  *  Local Definitions
477c478bd9Sstevel@tonic-gate  *	TRUE		Boolean TRUE value
487c478bd9Sstevel@tonic-gate  *	FALSE		Boolean FALSE value
497c478bd9Sstevel@tonic-gate  *	NULL		Null address
507c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #ifndef	TRUE
537c478bd9Sstevel@tonic-gate #define	TRUE	1
547c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate #ifndef	FALSE
577c478bd9Sstevel@tonic-gate #define FALSE	0
587c478bd9Sstevel@tonic-gate #endif
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Exit codes:
637c478bd9Sstevel@tonic-gate  *	EX_OK		All's well that ends well
647c478bd9Sstevel@tonic-gate  *	EX_ERROR	Some other error occurred
657c478bd9Sstevel@tonic-gate  *	EX_DTAB		Device table couldn't be opened
667c478bd9Sstevel@tonic-gate  *	EX_DGRP		Device-group table couldn't be open.
677c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate #define	EX_OK		0
707c478bd9Sstevel@tonic-gate #define	EX_ERROR	1
717c478bd9Sstevel@tonic-gate #define	EX_DTAB		2
727c478bd9Sstevel@tonic-gate #define	EX_DGRP		2
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  *  Messages:
777c478bd9Sstevel@tonic-gate  *	M_USAGE		Command usage error
787c478bd9Sstevel@tonic-gate  *	M_ERROR		Some unexpected error
797c478bd9Sstevel@tonic-gate  *	M_DEVTAB	Device table couldn't be opened
807c478bd9Sstevel@tonic-gate  *	M_DGROUP	Device-group table couldn't be opened
817c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define	M_USAGE		"usage: getdgrp [-ael] [criterion [...]] [dgroup [...]]"
847c478bd9Sstevel@tonic-gate #define	M_ERROR		"Internal error, errno=%d"
857c478bd9Sstevel@tonic-gate #define	M_DEVTAB	"Cannot open the device table: %s"
867c478bd9Sstevel@tonic-gate #define	M_DGROUP	"Cannot open the device-group table: %s"
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  *  Internal References
917c478bd9Sstevel@tonic-gate  *	buildcriterialist()	Builds a list of the criteria on the
927c478bd9Sstevel@tonic-gate  *				command line
937c478bd9Sstevel@tonic-gate  *	buildgrouplist()	Builds a list of the device-groups mentioned
947c478bd9Sstevel@tonic-gate  *				on the command line
957c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate static	char  **buildcriterialist();	/* Builds criteria list from command line */
987c478bd9Sstevel@tonic-gate static	char  **builddgrouplist();	/* Builds dgroup list from command line */
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  *  Macros
1037c478bd9Sstevel@tonic-gate  *	stdmsg(r,l,s,t)	    Generate a standard message
1047c478bd9Sstevel@tonic-gate  *				r	Recoverability flag
1057c478bd9Sstevel@tonic-gate  *				l	Standard label
1067c478bd9Sstevel@tonic-gate  *				s	Severity
1077c478bd9Sstevel@tonic-gate  *				t	Text
1087c478bd9Sstevel@tonic-gate  *	isacriterion(p)	    Returns TRUE if *p is a criterion, FALSE otherwise
1097c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	stdmsg(r,l,s,t)	(void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
1127c478bd9Sstevel@tonic-gate #define	isacriterion(p)	(strchr(*arglist,'=')||strchr(*arglist,':'))
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  *  Static Variables
1177c478bd9Sstevel@tonic-gate  *	lbl		Buffer for standard message label
1187c478bd9Sstevel@tonic-gate  *	txt		Buffer for standard message text
1197c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate static	char	lbl[MM_MXLABELLN+1];
1227c478bd9Sstevel@tonic-gate static	char	txt[MM_MXTXTLN+1];
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  *  getdgrp [-ael] [criterion [...]] [dgroup [...]]
1267c478bd9Sstevel@tonic-gate  *
1277c478bd9Sstevel@tonic-gate  *	This function gets the device groups that contain as members devices
1287c478bd9Sstevel@tonic-gate  *	that match the given criteria.
1297c478bd9Sstevel@tonic-gate  *
1307c478bd9Sstevel@tonic-gate  *  Options:
1317c478bd9Sstevel@tonic-gate  *	-a	A device must meet all criteria before the device-group in
1327c478bd9Sstevel@tonic-gate  *		which it is a member can be selected for inclusion in the
1337c478bd9Sstevel@tonic-gate  *		generated list.  If this option is missing, a device must
1347c478bd9Sstevel@tonic-gate  *		meet at least one criterion before it's group can be
1357c478bd9Sstevel@tonic-gate  *		selected.  This option has no affect if there are no criterion
1367c478bd9Sstevel@tonic-gate  *		on the command-line.
1377c478bd9Sstevel@tonic-gate  *	-e	The list of device groups specifies groups to exclude from
1387c478bd9Sstevel@tonic-gate  *		the generated list.  If this option is omitted, the list
1397c478bd9Sstevel@tonic-gate  *		of groups is the set of groups that can be selected.  This
1407c478bd9Sstevel@tonic-gate  *		option has no effect if there are no device-groups on the
1417c478bd9Sstevel@tonic-gate  *		command-line.
1427c478bd9Sstevel@tonic-gate  *	-l	List all device groups, even those that have no valid
1437c478bd9Sstevel@tonic-gate  *		members (this option has no effect if criterion are specified
1447c478bd9Sstevel@tonic-gate  *
1457c478bd9Sstevel@tonic-gate  *  Arguments:
1467c478bd9Sstevel@tonic-gate  *	criterion	A device criterion of the form <attr><op><val> where
1477c478bd9Sstevel@tonic-gate  *			<attr> is the name of an attribute, <op> is "=", "!=",
1487c478bd9Sstevel@tonic-gate  *			":", or "!:" for "is equal to", "is not equal to",
1497c478bd9Sstevel@tonic-gate  *			"is defined," or "is not defined."  <val> is the value
1507c478bd9Sstevel@tonic-gate  *			that the attribute must be equal to or not equal to.
1517c478bd9Sstevel@tonic-gate  *			(<val> must be "*" if <op> is ":" or "!:").
1527c478bd9Sstevel@tonic-gate  *	dgroup		A device group that is to be exclude selected for the
1537c478bd9Sstevel@tonic-gate  *			generated list or excluded from the the generated
1547c478bd9Sstevel@tonic-gate  *			list.
1557c478bd9Sstevel@tonic-gate  *
1567c478bd9Sstevel@tonic-gate  *  Exit values:
1577c478bd9Sstevel@tonic-gate  *	0	Success
1587c478bd9Sstevel@tonic-gate  *	1	Usage or an internal error
1597c478bd9Sstevel@tonic-gate  *	2	The device table or the device-group table could not be
1607c478bd9Sstevel@tonic-gate  *		opened for reading
1617c478bd9Sstevel@tonic-gate  */
163*113f4232Sakaplan int
164*113f4232Sakaplan main(int argc, char **argv)
1657c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 *  Automatic data
1697c478bd9Sstevel@tonic-gate 	 */
1717c478bd9Sstevel@tonic-gate 	char  **arglist;	/* List of arguments (subset of argv) */
1727c478bd9Sstevel@tonic-gate 	char  **criterialist;	/* List of criteria */
1737c478bd9Sstevel@tonic-gate 	char  **dgrouplist;	/* List of device groups to search or ignore */
1747c478bd9Sstevel@tonic-gate 	char  **fitgrouplist;	/* List of device groups that fit criteria */
1757c478bd9Sstevel@tonic-gate 	char   *cmdname;	/* Simple command name */
1767c478bd9Sstevel@tonic-gate 	char   *dgroup;		/* Pointer to device group name in list */
1777c478bd9Sstevel@tonic-gate 	char   *filename;	/* Pointer to filename in "error" */
1787c478bd9Sstevel@tonic-gate 	int	exitcode;	/* Value to return to the caller */
1797c478bd9Sstevel@tonic-gate 	int	sev;		/* Message severity */
1807c478bd9Sstevel@tonic-gate 	int	optchar;	/* Option character (returned by getopt()) */
1817c478bd9Sstevel@tonic-gate 	int	andflag;	/* TRUE if anding criteria, FALSE if or'ed */
1827c478bd9Sstevel@tonic-gate 	int	excludeflag;	/* TRUE if the dgroups list those to exclude */
1837c478bd9Sstevel@tonic-gate 	int	allflag;	/* TRUE if all device grps are to be displayed */
1847c478bd9Sstevel@tonic-gate 	int	options;	/* Options to pass to getdgrp() */
1857c478bd9Sstevel@tonic-gate 	int	usageerr;	/* TRUE if syntax error */
1887c478bd9Sstevel@tonic-gate 	/* Build the message label from the (simple) command name */
1897c478bd9Sstevel@tonic-gate 	if (cmdname = strrchr(argv[0], '/')) cmdname++;
1907c478bd9Sstevel@tonic-gate 	else cmdname = argv[0];
1917c478bd9Sstevel@tonic-gate 	(void) strlcat(strcpy(lbl, "UX:"), cmdname, sizeof(lbl));
1937c478bd9Sstevel@tonic-gate 	/* Only write the text-component of messages (this goes away in SVR4.1) */
1947c478bd9Sstevel@tonic-gate 	(void) putenv("MSGVERB=text");
1967c478bd9Sstevel@tonic-gate 	/*
1977c478bd9Sstevel@tonic-gate 	 *  Parse the command line:
1987c478bd9Sstevel@tonic-gate 	 *	- Options
1997c478bd9Sstevel@tonic-gate 	 *	- Selection criteria
2007c478bd9Sstevel@tonic-gate 	 *	- Device groups to include or exclude
2017c478bd9Sstevel@tonic-gate 	 */
2037c478bd9Sstevel@tonic-gate 	/*
2047c478bd9Sstevel@tonic-gate 	 *  Extract options from the command line
2057c478bd9Sstevel@tonic-gate 	 */
2077c478bd9Sstevel@tonic-gate 	/* Initializations */
2087c478bd9Sstevel@tonic-gate 	andflag = FALSE;		/* No -a */
2097c478bd9Sstevel@tonic-gate 	excludeflag = FALSE;		/* No -e */
2107c478bd9Sstevel@tonic-gate 	allflag = FALSE;		/* No -l */
2117c478bd9Sstevel@tonic-gate 	usageerr = FALSE;		/* No errors yet */
2137c478bd9Sstevel@tonic-gate 	/*
2147c478bd9Sstevel@tonic-gate 	 *  Loop until all of the command line options have been parced
2157c478bd9Sstevel@tonic-gate 	 */
2167c478bd9Sstevel@tonic-gate 	opterr = FALSE;			/* Don't let getopt() write messages */
2177c478bd9Sstevel@tonic-gate 	while ((optchar = getopt(argc, argv, "ael")) != EOF) switch (optchar) {
2197c478bd9Sstevel@tonic-gate 	/* -a  List device groups that fit all of the criteria listed */
2207c478bd9Sstevel@tonic-gate 	case 'a':
2217c478bd9Sstevel@tonic-gate 	    if (andflag) usageerr = TRUE;
2227c478bd9Sstevel@tonic-gate 	    else andflag = TRUE;
2237c478bd9Sstevel@tonic-gate 	    break;
2257c478bd9Sstevel@tonic-gate 	/* -e  Exclude those device groups mentioned on the command line */
2267c478bd9Sstevel@tonic-gate 	case 'e':
2277c478bd9Sstevel@tonic-gate 	    if (excludeflag) usageerr = TRUE;
2287c478bd9Sstevel@tonic-gate 	    else excludeflag = TRUE;
2297c478bd9Sstevel@tonic-gate 	    break;
2317c478bd9Sstevel@tonic-gate 	/* -l  List all device groups (if no criteria is specified) */
2327c478bd9Sstevel@tonic-gate 	case 'l':
2337c478bd9Sstevel@tonic-gate 	    if (allflag) usageerr = TRUE;
2347c478bd9Sstevel@tonic-gate 	    else allflag = TRUE;
2357c478bd9Sstevel@tonic-gate 	    break;
2377c478bd9Sstevel@tonic-gate 	/* Default case -- command usage error */
2387c478bd9Sstevel@tonic-gate 	case '?':
2397c478bd9Sstevel@tonic-gate 	default:
2407c478bd9Sstevel@tonic-gate 	    usageerr = TRUE;
2417c478bd9Sstevel@tonic-gate 	    break;
2427c478bd9Sstevel@tonic-gate 	}
2447c478bd9Sstevel@tonic-gate 	/* If there is a usage error, write an appropriate message and exit */
2457c478bd9Sstevel@tonic-gate 	if (usageerr) {
2467c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, MM_ERROR, M_USAGE);
2477c478bd9Sstevel@tonic-gate 	    exit(EX_ERROR);
2487c478bd9Sstevel@tonic-gate 	}
2507c478bd9Sstevel@tonic-gate 	/* Open the device file (if there's one to be opened) */
2517c478bd9Sstevel@tonic-gate 	if (!_opendevtab("r")) {
2527c478bd9Sstevel@tonic-gate 	    if (filename = _devtabpath()) {
2537c478bd9Sstevel@tonic-gate 		(void) snprintf(txt, sizeof(txt), M_DEVTAB, filename);
2547c478bd9Sstevel@tonic-gate 		exitcode = EX_DTAB;
2557c478bd9Sstevel@tonic-gate 		sev = MM_ERROR;
2567c478bd9Sstevel@tonic-gate 	    } else {
2577c478bd9Sstevel@tonic-gate 		(void) sprintf(txt, M_ERROR, errno);
2587c478bd9Sstevel@tonic-gate 		exitcode = EX_ERROR;
2597c478bd9Sstevel@tonic-gate 		sev = MM_HALT;
2607c478bd9Sstevel@tonic-gate 	    }
2617c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, sev, txt);
2627c478bd9Sstevel@tonic-gate 	    exit(exitcode);
2637c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 	/* Open the device file (if there's one to be opened) */
2667c478bd9Sstevel@tonic-gate 	if (!_opendgrptab("r")) {
2677c478bd9Sstevel@tonic-gate 	    if (filename = _dgrptabpath()) {
2687c478bd9Sstevel@tonic-gate 		(void) snprintf(txt, sizeof(txt), M_DGROUP, filename);
2697c478bd9Sstevel@tonic-gate 		exitcode = EX_DGRP;
2707c478bd9Sstevel@tonic-gate 		sev = MM_ERROR;
2717c478bd9Sstevel@tonic-gate 	    } else {
2727c478bd9Sstevel@tonic-gate 		(void) sprintf(txt, M_ERROR, errno);
2737c478bd9Sstevel@tonic-gate 		exitcode = EX_ERROR;
2747c478bd9Sstevel@tonic-gate 		sev = MM_HALT;
2757c478bd9Sstevel@tonic-gate 	    }
2767c478bd9Sstevel@tonic-gate 	    stdmsg(MM_NRECOV, lbl, sev, txt);
2777c478bd9Sstevel@tonic-gate 	    exit(exitcode);
2787c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 	/* Build the list of criteria and device groups */
2817c478bd9Sstevel@tonic-gate 	arglist = argv + optind;
2827c478bd9Sstevel@tonic-gate 	criterialist = buildcriterialist(arglist);
2837c478bd9Sstevel@tonic-gate 	dgrouplist = builddgrouplist(arglist);
2847c478bd9Sstevel@tonic-gate 	options = (excludeflag ? DTAB_EXCLUDEFLAG : 0) |
2857c478bd9Sstevel@tonic-gate 		  (andflag ? DTAB_ANDCRITERIA : 0) |
2867c478bd9Sstevel@tonic-gate 		  (allflag ? DTAB_LISTALL : 0) ;
2887c478bd9Sstevel@tonic-gate 	/*
2897c478bd9Sstevel@tonic-gate 	 *  Get the list of device groups that meets the criteria requested.
2907c478bd9Sstevel@tonic-gate 	 *  If we got a list (that might be empty), write that list to the
2917c478bd9Sstevel@tonic-gate 	 *  standard output file (stdout).
2927c478bd9Sstevel@tonic-gate 	 */
2947c478bd9Sstevel@tonic-gate 	exitcode = EX_OK;
2957c478bd9Sstevel@tonic-gate 	if (!(fitgrouplist = getdgrp(dgrouplist, criterialist, options))) {
2967c478bd9Sstevel@tonic-gate 	    exitcode = EX_ERROR;
2977c478bd9Sstevel@tonic-gate 	}
2987c478bd9Sstevel@tonic-gate 	else for (dgroup = *fitgrouplist++ ; dgroup ; dgroup = *fitgrouplist++)
2997c478bd9Sstevel@tonic-gate 		(void) puts(dgroup);
3017c478bd9Sstevel@tonic-gate 	/* Finished */
3027c478bd9Sstevel@tonic-gate 	return(exitcode);
3037c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate  *  char **buildcriterialist(arglist)
3077c478bd9Sstevel@tonic-gate  *	char **arglist
3087c478bd9Sstevel@tonic-gate  *
3097c478bd9Sstevel@tonic-gate  *	This function builds a list of criteria descriptions from the
3107c478bd9Sstevel@tonic-gate  *	list of arguments given.  The list returned is in malloc()ed
3117c478bd9Sstevel@tonic-gate  *	space.
3127c478bd9Sstevel@tonic-gate  *
3137c478bd9Sstevel@tonic-gate  *  Arguments:
3147c478bd9Sstevel@tonic-gate  *	arglist		The address of the first element in the list
3157c478bd9Sstevel@tonic-gate  *			of arguments (possibly) containing criterion
3167c478bd9Sstevel@tonic-gate  *
3177c478bd9Sstevel@tonic-gate  *  Returns:  char **
3187c478bd9Sstevel@tonic-gate  *	A pointer to the first element in the list of criterion.
3197c478bd9Sstevel@tonic-gate  *	If there was a problem, the function returns (char **) NULL.
3207c478bd9Sstevel@tonic-gate  *	If there are no criteria in the list, the function returns
3217c478bd9Sstevel@tonic-gate  *	an empty list.
3227c478bd9Sstevel@tonic-gate  */
3247c478bd9Sstevel@tonic-gate static char  **
3257c478bd9Sstevel@tonic-gate buildcriterialist(arglist)
3267c478bd9Sstevel@tonic-gate 	char  **arglist;	/* Pointer to the list of argument pointers */
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	/*
3297c478bd9Sstevel@tonic-gate 	 *  Automatic data
3307c478bd9Sstevel@tonic-gate 	 */
3327c478bd9Sstevel@tonic-gate 	char	      **pp; 		/* Pointer to a criteria */
3337c478bd9Sstevel@tonic-gate 	void	       *allocbuf;	/* Pointer to the allocated data */
3347c478bd9Sstevel@tonic-gate 	int		ncriteria;	/* Number of criteria found */
3377c478bd9Sstevel@tonic-gate 	/*
3387c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or
3397c478bd9Sstevel@tonic-gate 	 *  the first thing that's not a criteria.  (A criteria is a
3407c478bd9Sstevel@tonic-gate 	 *  character-string that contains a colon (':') or an equal-sign ('=')
3417c478bd9Sstevel@tonic-gate 	 */
3437c478bd9Sstevel@tonic-gate 	pp = arglist;
3447c478bd9Sstevel@tonic-gate 	ncriteria = 1;
3457c478bd9Sstevel@tonic-gate 	while (*pp && (strchr(*pp, '=') || strchr(*pp, ':'))) {
3467c478bd9Sstevel@tonic-gate 	    ncriteria++;
3477c478bd9Sstevel@tonic-gate 	    pp++;
3487c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 	/* Allocate space for the list of criteria pointers */
3517c478bd9Sstevel@tonic-gate 	if (allocbuf = malloc(ncriteria*sizeof(char **))) {
3537c478bd9Sstevel@tonic-gate 	    /* Build the list of criteria arguments */
3547c478bd9Sstevel@tonic-gate 	    pp = (char **) allocbuf;
3557c478bd9Sstevel@tonic-gate 	    while ((*arglist != (char *) NULL) && isacriterion(*arglist)) *pp++ = *arglist++;
3567c478bd9Sstevel@tonic-gate 	    *pp = (char *) NULL;
3577c478bd9Sstevel@tonic-gate 	}
3597c478bd9Sstevel@tonic-gate 	return ((char **) allocbuf);
3607c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate  *  char **builddgrouplist(arglist)
3647c478bd9Sstevel@tonic-gate  *	char  **arglist
3657c478bd9Sstevel@tonic-gate  *
3667c478bd9Sstevel@tonic-gate  *	This function returns a pointer to the first element in a list of
3677c478bd9Sstevel@tonic-gate  *	device-groups (i.e. not criteria) specified in the list of arguments
3687c478bd9Sstevel@tonic-gate  *	whose first element is pointed to by <arglist>.
3697c478bd9Sstevel@tonic-gate  *
3707c478bd9Sstevel@tonic-gate  *  Arguments:
3717c478bd9Sstevel@tonic-gate  *	arglist		The address of the first element in the list of
3727c478bd9Sstevel@tonic-gate  *			arguments to be searched for non-criteria
3737c478bd9Sstevel@tonic-gate  *
3747c478bd9Sstevel@tonic-gate  *  Returns:  char **
3757c478bd9Sstevel@tonic-gate  *	The address of the first item in the list of arguments that are
3767c478bd9Sstevel@tonic-gate  *	not criteria.  If none, the function returns a pointer to a
3777c478bd9Sstevel@tonic-gate  *	null list.
3787c478bd9Sstevel@tonic-gate  *
3797c478bd9Sstevel@tonic-gate  *  Note:
3807c478bd9Sstevel@tonic-gate  *	- The current implementation returns a pointer to an element in
3817c478bd9Sstevel@tonic-gate  *	  <arglist>.
3827c478bd9Sstevel@tonic-gate  */
3847c478bd9Sstevel@tonic-gate static char  **
3857c478bd9Sstevel@tonic-gate builddgrouplist(arglist)
3867c478bd9Sstevel@tonic-gate 	char  **arglist;	/* First item in the list of arguments */
3877c478bd9Sstevel@tonic-gate {
3887c478bd9Sstevel@tonic-gate 	/*
3897c478bd9Sstevel@tonic-gate 	 *  Automatic data
3907c478bd9Sstevel@tonic-gate 	 */
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 *  Search the argument list, looking for the end of the list or
3947c478bd9Sstevel@tonic-gate 	 *  the first thing that's not a criteria.  It is the first device
3957c478bd9Sstevel@tonic-gate 	 *  group in the list of device groups (if any).
3967c478bd9Sstevel@tonic-gate 	 */
3987c478bd9Sstevel@tonic-gate 	while (*arglist && isacriterion(*arglist)) arglist++;
4007c478bd9Sstevel@tonic-gate 	/* Return a pointer to the argument list. */
4017c478bd9Sstevel@tonic-gate 	return(arglist);
4027c478bd9Sstevel@tonic-gate }