fc_led_parse.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include <syslog.h>
#include "fcal_leds.h"
/*
* function templates for static functions
*/
/*
* Templates for functions which may be returned by get_token().
* These functions are all called with a pointer to the position just
* beyond the token being actioned.
*/
/*
* The table below is used to lookup .conf file keywords to yield either
* a corresponding enum or a function to process the keyword.
*/
};
/*
* length of longest string in table (with space for null terminator)
*/
#define MAX_FCAL_TOKEN_LEN 18
/*
* get_token
* Parses the current line of data and returns the next token.
* If there are no significant characters in the line, NO_TOKEN is returned.
* If a syntax error is encountered, TOKEN_ERROR is returned.
* Pointer to position in current line is updated to point to the terminator
* of the token, unless TOKEN_ERROR is returned.
*/
static token_t
char **pptr, /* pointer to pointer to position in current line */
/* *ptr is updated by the function */
int lineNo, /* current line number, used for syslog. If set to */
/* zero, syslogging is supressed */
/* pointer for the token found. NULL may be returned */
{
char *ptr;
char *token_start;
int toklen;
int i;
int ch;
/* strip leading white space */
do {
return (NO_TOKEN); /* empty line or comment */
}
if (lineNo != 0)
return (TOKEN_ERROR);
}
/*
* got token, now look it up
*/
for (i = 0; i < tab_len; i++) {
}
}
if (lineNo != 0)
return (TOKEN_ERROR);
}
static int
{
if (*(*p_str)++ != '.') {
return (-1);
}
return (-1);
}
return (-1);
}
return (0);
}
/*
* get space to hold white-space terminated string at *p_str
* advance *p_str to point to terminator
* return copy of string, null terminated
*/
static int
{
int ch;
int len;
char *ptr;
(*p_str)++;
do {
if (*p_cstr_res != NULL)
free((void *)(*p_cstr_res));
*p_cstr_res = ptr;
return (ENOMEM);
}
return (0);
}
static int
{
if (res == 0) {
return (-1);
}
}
return (res);
}
static int
{
if (res == 0) {
return (-1);
}
}
return (res);
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
/*
* A number of fields in the led_dtls_t structure have per-disk copies.
* This action routine creates the space for all such fields.
* Following any failure, an error is returned and the calling routine
* must handle the fact that only a subset of these fields are populated.
* In practice, this function is only called by get_token() on behalf of
* fc_led_parse(). fc_led_parse calls free_led_dtls() after any error.
*/
static int
{
int i;
return (-1);
}
return (-1);
}
return (-1);
}
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
return (ENOMEM);
}
for (i = 0; i < FCAL_LED_CNT; i++) {
return (ENOMEM);
sizeof (led_state_t));
return (ENOMEM);
}
return (0);
}
static int
{
return (-1);
}
if ((i != 0) && (i != 1)) {
return (-1);
}
*assert = i;
return (0);
}
static int
{
return (-1);
}
if (i < 1) {
return (-1);
}
*pnz = i;
return (0);
}
static int
{
}
static int
{
}
static int
{
}
static int
{
int i;
if (*(*p_str)++ != ',') {
return (-1);
}
if ((j < 0) || (j > n_disks)) {
return (-1);
}
return (-1);
}
p_intarray[j] = i;
return (0);
}
static int
{
}
static int
{
}
static int
{
int i;
if (*(*p_str)++ != ',') {
return (-1);
}
return (-1);
}
return (-1);
}
if (*(*p_str)++ != ',') {
return (-1);
}
return (-1);
}
return (0);
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
/*
* Create a led_dtls_t structure
* Parse configuration file and populate the led_dtls_t
* In the event of an error, free the structure and return an error
*/
int
{
int lineNo = 0;
int err = 0;
char linebuf[160];
char *ptr;
return (ENOMEM);
}
lineNo++;
continue;
if (tok == TOKEN_ERROR) {
err = -1;
break;
}
if (tok == FCAL_VERSION) {
break;
else
continue;
}
err = -1;
break;
}
err = -1;
break;
}
if (*ptr++ != ':') {
err = -1;
break;
}
break;
}
else
continue;
}
if (err == 0) {
} else
err = 0;
}
if (err != 0) {
/*
* clean up after error detected
*/
return (err);
}
/*
* set any unset timers to default time
*/
if (dtls->slow_poll_ticks == 0)
if (dtls->relax_time_ticks == 0)
if (dtls->led_test_time == 0)
/*
* set polling flag to avoid a start-up glitch
* it will be cleared again if the poll thread fails
*/
/*
* convert derived timers to multiples of fast poll time
*/
return (0);
}
void
{
int i;
return;
}
}
for (i = 0; i < FCAL_LED_CNT; i++) {
}
}