util.c revision 34e485807cef99a975f8962a04f4b7d1aa3529fe
/*
* 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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <unistd.h>
#include "extern.h"
#include "misc.h"
#include <sac.h>
#include "structs.h"
#ifdef SAC
#include "msgs.h"
#endif
/*
* nexttok - return next token, essentially a strtok, but it can
* deal with null fields and strtok can not
*
* args: str - the string to be examined, NULL if we should
* examine the remembered string
* delim - the list of valid delimiters
* ros - rest of string flag (1 for rest of string, 0 for
* normal processing)
*/
char *
char *str;
register char *delim;
int ros;
{
static char *savep; /* the remembered string */
register char *p; /* pointer to start of token */
register char *ep; /* pointer to end of token */
if (ros)
return(p);
if (p == NULL)
return(NULL);
return(p);
}
*ep = '\0';
return(p);
}
/*
* parse - parse a line from _sactab. This routine will return if the parse
* was successful, otherwise it will output an error and exit.
*
* args: p - pointer to the data read from the file
* sp - pointer to a structure in which the separated fields
* are placed
*
* A line in the file has the following format:
*
* tag:type:flags:restart_count:command_string #comment
*/
void
register char *p;
{
/*
* get the PM tag
*/
if (p == NULL) {
# ifdef SAC
# else
error("_sactab file is corrupt");
# endif
}
p[PMTAGSIZE] = '\0';
# ifdef SAC
# else
# endif
}
/*
* get the PM type
*/
if (p == NULL) {
# ifdef SAC
# else
error("_sactab file is corrupt");
# endif
}
if (strlen(p) > PMTYPESIZE) {
p[PMTYPESIZE] = '\0';
# ifdef SAC
# else
# endif
}
/*
* get the flags
*/
if (p == NULL) {
# ifdef SAC
# else
error("_sactab file is corrupt");
# endif
}
while (*p) {
switch (*p++) {
case 'd':
break;
case 'x':
break;
default:
# ifdef SAC
# else
# endif
break;
}
}
/*
* get the restart count
*/
if (p == NULL) {
# ifdef SAC
# else
error("_sactab file is corrupt");
# endif
}
/*
* get the command string
*/
if (p == NULL) {
# ifdef SAC
# else
error("_sactab file is corrupt");
# endif
}
# ifdef SAC
# else
error("malloc failed");
# endif
}
/*
* remember the comment string
*/
# ifdef SAC
# else
error("malloc failed");
# endif
}
}
/*
* trim - remove comments, trim off trailing white space, done in place
* args: p - string to be acted upon
*/
char *
trim(p)
register char *p;
{
register char *tp; /* temp pointer */
/*
* remove comments, if any, but remember them for later
*/
Comment[0] = '\0';
if (tp) {
*tp = '\0';
if (tp)
*tp ='\0';
}
/*
* remove trailing whitespace, if any
*/
*tp = '\0';
return(p);
}
/*
* pstate - put port monitor state into intelligible form for output
* SSTATE is only used by sacadm
*
* args: state - binary representation of state
*/
char *
{
switch (state) {
case NOTRUNNING:
return("NOTRUNNING");
case STARTING:
return("STARTING");
case ENABLED:
return("ENABLED");
case DISABLED:
return("DISABLED");
case STOPPING:
return("STOPPING");
case FAILED:
return("FAILED");
case UNKNOWN:
return("UNKNOWN");
# ifndef SAC
case SSTATE:
return("NO_SAC");
# endif
default:
# ifdef SAC
# else
error("Improper message from SAC\n");
# endif
}
/* NOTREACHED */
return (NULL);
}