/*
* 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) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
/*LINTLIBRARY*/
#include <stdlib.h>
#include "utility.h"
/*
* TYPE_ENUM standard type
*
* usage:
* set_field_type(f, TYPE_ENUM, list, checkcase, checkuniq);
*
* char ** list; list of acceptable strings
* int checkuniq; TRUE - unique match required
*
*/
typedef struct {
char ** list;
int checkcase;
int checkuniq;
int count;
} ENUM;
static char * copy_enum(char *);
static void free_enum(char *);
static int fcheck_enum(FIELD *, char *);
{
1, /* ref */
(FIELDTYPE *) 0, /* left */
(FIELDTYPE *) 0, /* right */
make_enum, /* makearg */
copy_enum, /* copyarg */
free_enum, /* freearg */
fcheck_enum, /* fcheck */
(PTF_int) 0, /* ccheck */
next_enum, /* next */
prev_enum, /* prev */
};
static char *
{
ENUM * n;
char ** v;
for (v = n -> list; *v; ++v)
;
}
return ((char *) n);
}
static char *
{
ENUM * n;
return ((char *) n);
}
static void
{
}
#define NO_MATCH 0
static int
{
while (*v && *v == ' ') /* remove leading blanks */
++v;
while (*x && *x == ' ') /* remove leading blanks */
++x;
if (*v == '\0')
if (checkcase) { /* case is significant */
while (*x++ == *v)
if (*v++ == '\0')
return (EXACT_MATCH);
} else { /* ignore case */
if (*v++ == '\0')
return (EXACT_MATCH);
}
while (*v && *v == ' ') /* remove trailing blanks */
++v;
if (*v)
return (NO_MATCH);
else
return (*--x ? PARTIAL_MATCH : EXACT_MATCH);
}
static int
{
int m;
char * v = field_buffer(f, 0);
char * x;
while (x = *list++)
char * value = x;
if (checkuniq && m != EXACT_MATCH)
while (x = *list++)
if (m == EXACT_MATCH) {
value = x;
break;
}
else
value = (char *) 0;
}
if (! value)
return (FALSE);
(void) set_field_buffer(f, 0, value);
return (TRUE);
}
return (FALSE);
}
static int
{
char * v = field_buffer(f, 0);
while (count--)
break;
if (count <= 0)
(void) set_field_buffer(f, 0, *list);
return (TRUE);
}
return (FALSE);
}
static int
{
char * v = field_buffer(f, 0);
while (count--)
break;
if (count <= 0)
(void) set_field_buffer(f, 0, *list);
return (TRUE);
}
return (FALSE);
}