/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Implements the main body of the "getdgrp" command.
*/
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <devmgmt.h>
#include <devtab.h>
#include <fmtmsg.h>
/*
* Local Definitions
* TRUE Boolean TRUE value
* FALSE Boolean FALSE value
* NULL Null address
*/
#ifndef TRUE
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
* Exit codes:
* EX_OK All's well that ends well
* EX_ERROR Some other error occurred
* EX_DTAB Device table couldn't be opened
* EX_DGRP Device-group table couldn't be open.
*/
#define EX_OK 0
/*
* Messages:
* M_USAGE Command usage error
* M_ERROR Some unexpected error
* M_DEVTAB Device table couldn't be opened
* M_DGROUP Device-group table couldn't be opened
*/
/*
* Internal References
* buildcriterialist() Builds a list of the criteria on the
* command line
* buildgrouplist() Builds a list of the device-groups mentioned
* on the command line
*/
static char **buildcriterialist(); /* Builds criteria list from command line */
static char **builddgrouplist(); /* Builds dgroup list from command line */
/*
* Macros
* stdmsg(r,l,s,t) Generate a standard message
* r Recoverability flag
* l Standard label
* s Severity
* t Text
* isacriterion(p) Returns TRUE if *p is a criterion, FALSE otherwise
*/
/*
* Static Variables
* lbl Buffer for standard message label
* txt Buffer for standard message text
*/
/*
* getdgrp [-ael] [criterion [...]] [dgroup [...]]
*
* This function gets the device groups that contain as members devices
* that match the given criteria.
*
* Options:
* -a A device must meet all criteria before the device-group in
* which it is a member can be selected for inclusion in the
* generated list. If this option is missing, a device must
* meet at least one criterion before it's group can be
* selected. This option has no affect if there are no criterion
* on the command-line.
* -e The list of device groups specifies groups to exclude from
* the generated list. If this option is omitted, the list
* of groups is the set of groups that can be selected. This
* option has no effect if there are no device-groups on the
* command-line.
* -l List all device groups, even those that have no valid
* members (this option has no effect if criterion are specified
*
* Arguments:
* criterion A device criterion of the form <attr><op><val> where
* <attr> is the name of an attribute, <op> is "=", "!=",
* ":", or "!:" for "is equal to", "is not equal to",
* "is defined," or "is not defined." <val> is the value
* that the attribute must be equal to or not equal to.
* (<val> must be "*" if <op> is ":" or "!:").
* dgroup A device group that is to be exclude selected for the
* generated list or excluded from the the generated
* list.
*
* Exit values:
* 0 Success
* 1 Usage or an internal error
* 2 The device table or the device-group table could not be
* opened for reading
*/
int
{
/*
* Automatic data
*/
/* Build the message label from the (simple) command name */
/* Only write the text-component of messages (this goes away in SVR4.1) */
(void) putenv("MSGVERB=text");
/*
* Parse the command line:
* - Options
* - Selection criteria
* - Device groups to include or exclude
*/
/*
* Extract options from the command line
*/
/* Initializations */
/*
* Loop until all of the command line options have been parced
*/
/* -a List device groups that fit all of the criteria listed */
case 'a':
break;
/* -e Exclude those device groups mentioned on the command line */
case 'e':
else excludeflag = TRUE;
break;
/* -l List all device groups (if no criteria is specified) */
case 'l':
break;
/* Default case -- command usage error */
case '?':
default:
break;
}
/* If there is a usage error, write an appropriate message and exit */
if (usageerr) {
}
/* Open the device file (if there's one to be opened) */
if (!_opendevtab("r")) {
if (filename = _devtabpath()) {
} else {
}
}
/* Open the device file (if there's one to be opened) */
if (!_opendgrptab("r")) {
if (filename = _dgrptabpath()) {
} else {
}
}
/* Build the list of criteria and device groups */
(andflag ? DTAB_ANDCRITERIA : 0) |
(allflag ? DTAB_LISTALL : 0) ;
/*
* Get the list of device groups that meets the criteria requested.
* If we got a list (that might be empty), write that list to the
* standard output file (stdout).
*/
}
/* Finished */
return(exitcode);
}
/*
* char **buildcriterialist(arglist)
* char **arglist
*
* This function builds a list of criteria descriptions from the
* list of arguments given. The list returned is in malloc()ed
* space.
*
* Arguments:
* arglist The address of the first element in the list
* of arguments (possibly) containing criterion
*
* Returns: char **
* A pointer to the first element in the list of criterion.
* If there was a problem, the function returns (char **) NULL.
* If there are no criteria in the list, the function returns
* an empty list.
*/
static char **
char **arglist; /* Pointer to the list of argument pointers */
{
/*
* Automatic data
*/
/*
* Search the argument list, looking for the end of the list or
* the first thing that's not a criteria. (A criteria is a
* character-string that contains a colon (':') or an equal-sign ('=')
*/
ncriteria = 1;
ncriteria++;
pp++;
}
/* Allocate space for the list of criteria pointers */
/* Build the list of criteria arguments */
}
return ((char **) allocbuf);
}
/*
* char **builddgrouplist(arglist)
* char **arglist
*
* This function returns a pointer to the first element in a list of
* device-groups (i.e. not criteria) specified in the list of arguments
* whose first element is pointed to by <arglist>.
*
* Arguments:
* arglist The address of the first element in the list of
* arguments to be searched for non-criteria
*
* Returns: char **
* The address of the first item in the list of arguments that are
* not criteria. If none, the function returns a pointer to a
* null list.
*
* Note:
* - The current implementation returns a pointer to an element in
* <arglist>.
*/
static char **
char **arglist; /* First item in the list of arguments */
{
/*
* Automatic data
*/
/*
* Search the argument list, looking for the end of the list or
* the first thing that's not a criteria. It is the first device
* group in the list of device groups (if any).
*/
/* Return a pointer to the argument list. */
return(arglist);
}