1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include "utility.h"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate /*
38*7c478bd9Sstevel@tonic-gate  *	TYPE_ALNUM
39*7c478bd9Sstevel@tonic-gate  *
40*7c478bd9Sstevel@tonic-gate  *	usage:
41*7c478bd9Sstevel@tonic-gate  *		set_field_type(f, TYPE_ALNUM, width);
42*7c478bd9Sstevel@tonic-gate  *
43*7c478bd9Sstevel@tonic-gate  *		int width;	minimum token width
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate static char * make_alnum(va_list *);
46*7c478bd9Sstevel@tonic-gate static char * copy_alnum(char *);
47*7c478bd9Sstevel@tonic-gate static void free_alnum(char *);
48*7c478bd9Sstevel@tonic-gate static int fcheck_alnum(FIELD *, char *);
49*7c478bd9Sstevel@tonic-gate static int ccheck_alnum(int, char *);
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate static FIELDTYPE typeALNUM =
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 				ARGS,			/* status	*/
54*7c478bd9Sstevel@tonic-gate 				1,			/* ref		*/
55*7c478bd9Sstevel@tonic-gate 				(FIELDTYPE *) 0,	/* left		*/
56*7c478bd9Sstevel@tonic-gate 				(FIELDTYPE *) 0,	/* right	*/
57*7c478bd9Sstevel@tonic-gate 				make_alnum,		/* makearg	*/
58*7c478bd9Sstevel@tonic-gate 				copy_alnum,		/* copyarg	*/
59*7c478bd9Sstevel@tonic-gate 				free_alnum,		/* freearg	*/
60*7c478bd9Sstevel@tonic-gate 				fcheck_alnum,		/* fcheck	*/
61*7c478bd9Sstevel@tonic-gate 				ccheck_alnum,		/* ccheck	*/
62*7c478bd9Sstevel@tonic-gate 				(PTF_int) 0,		/* next		*/
63*7c478bd9Sstevel@tonic-gate 				(PTF_int) 0,		/* prev		*/
64*7c478bd9Sstevel@tonic-gate };
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate FIELDTYPE * TYPE_ALNUM = &typeALNUM;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate static char *
make_alnum(va_list * ap)69*7c478bd9Sstevel@tonic-gate make_alnum(va_list *ap)
70*7c478bd9Sstevel@tonic-gate {
71*7c478bd9Sstevel@tonic-gate 	int * width;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	if (Alloc(width, int))
74*7c478bd9Sstevel@tonic-gate 		*width = va_arg(*ap, int);
75*7c478bd9Sstevel@tonic-gate 	return ((char *) width);
76*7c478bd9Sstevel@tonic-gate }
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate static char *
copy_alnum(char * arg)79*7c478bd9Sstevel@tonic-gate copy_alnum(char *arg)
80*7c478bd9Sstevel@tonic-gate {
81*7c478bd9Sstevel@tonic-gate 	int * width;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (Alloc(width, int))
84*7c478bd9Sstevel@tonic-gate 		*width = *((int *) arg);
85*7c478bd9Sstevel@tonic-gate 	return ((char *) width);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate static void
free_alnum(char * arg)89*7c478bd9Sstevel@tonic-gate free_alnum(char *arg)
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 	Free(arg);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate static int
fcheck_alnum(FIELD * f,char * arg)95*7c478bd9Sstevel@tonic-gate fcheck_alnum(FIELD *f, char *arg)
96*7c478bd9Sstevel@tonic-gate {
97*7c478bd9Sstevel@tonic-gate 	int	width	= *((int *) arg);
98*7c478bd9Sstevel@tonic-gate 	int	n	= 0;
99*7c478bd9Sstevel@tonic-gate 	char 	*v	= field_buffer(f, 0);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	while (*v && *v == ' ')
102*7c478bd9Sstevel@tonic-gate 		++v;
103*7c478bd9Sstevel@tonic-gate 	if (*v) {
104*7c478bd9Sstevel@tonic-gate 		char * vbeg = v;
105*7c478bd9Sstevel@tonic-gate 		while (*v && isalnum(*v))
106*7c478bd9Sstevel@tonic-gate 			++v;
107*7c478bd9Sstevel@tonic-gate 		n = (int) (v - vbeg);
108*7c478bd9Sstevel@tonic-gate 		while (*v && *v == ' ')
109*7c478bd9Sstevel@tonic-gate 			++v;
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate 	return (*v || n < width ? FALSE : TRUE);
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
115*7c478bd9Sstevel@tonic-gate static int
ccheck_alnum(int c,char * arg)116*7c478bd9Sstevel@tonic-gate ccheck_alnum(int c, char *arg)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate 	return (isalnum(c));
119*7c478bd9Sstevel@tonic-gate }
120