xref: /onnv-gate/usr/src/cmd/oawk/lib.c (revision 0)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright (c) 1996-1999 by Sun Microsystems, Inc.
28*0Sstevel@tonic-gate  * All rights reserved.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include "awk.def"
35*0Sstevel@tonic-gate #include "awk.h"
36*0Sstevel@tonic-gate #include <ctype.h>
37*0Sstevel@tonic-gate #include <wctype.h>
38*0Sstevel@tonic-gate #include "awktype.h"
39*0Sstevel@tonic-gate #include <stdlib.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate FILE	*infile	= NULL;
42*0Sstevel@tonic-gate wchar_t *file;
43*0Sstevel@tonic-gate #define	RECSIZE (5 * 512)
44*0Sstevel@tonic-gate wchar_t record[RECSIZE];
45*0Sstevel@tonic-gate wchar_t fields[RECSIZE];
46*0Sstevel@tonic-gate wchar_t L_NULL[] = L"";
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate #define	MAXFLD	100
50*0Sstevel@tonic-gate int	donefld;	/* 1 = implies rec broken into fields */
51*0Sstevel@tonic-gate int	donerec;	/* 1 = record is valid (no flds have changed) */
52*0Sstevel@tonic-gate int	mustfld;	/* 1 = NF seen, so always break */
53*0Sstevel@tonic-gate static wchar_t L_record[] = L"$record";
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate #define	FINIT	{ OCELL, CFLD, 0, L_NULL, 0.0, FLD|STR }
57*0Sstevel@tonic-gate CELL fldtab[MAXFLD] = {		/* room for fields */
58*0Sstevel@tonic-gate 	{ OCELL, CFLD, L_record, record, 0.0, STR|FLD},
59*0Sstevel@tonic-gate 		FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
60*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
61*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
62*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
63*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
64*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
65*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
66*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
67*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
68*0Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT
69*0Sstevel@tonic-gate };
70*0Sstevel@tonic-gate int	maxfld	= 0;	/* last used field */
71*0Sstevel@tonic-gate /* pointer to CELL for maximum field assigned to */
72*0Sstevel@tonic-gate CELL	*maxmfld = &fldtab[0];
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate getrec()
78*0Sstevel@tonic-gate {
79*0Sstevel@tonic-gate 	register wchar_t *rr, *er;
80*0Sstevel@tonic-gate 	register c, sep;
81*0Sstevel@tonic-gate 	register FILE *inf;
82*0Sstevel@tonic-gate 	extern int svargc;
83*0Sstevel@tonic-gate 	extern wchar_t **svargv;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL);
87*0Sstevel@tonic-gate 	donefld = 0;
88*0Sstevel@tonic-gate 	donerec = 1;
89*0Sstevel@tonic-gate 	record[0] = 0;
90*0Sstevel@tonic-gate 	er = record + RECSIZE;
91*0Sstevel@tonic-gate 	while (svargc > 0) {
92*0Sstevel@tonic-gate 		dprintf("svargc=%d, *svargv=%ws\n", svargc, *svargv, NULL);
93*0Sstevel@tonic-gate 		if (infile == NULL) {	/* have to open a new file */
94*0Sstevel@tonic-gate 			if (member('=', *svargv)) {
95*0Sstevel@tonic-gate 				/* it's a var=value argument */
96*0Sstevel@tonic-gate 				setclvar(*svargv);
97*0Sstevel@tonic-gate 				if (svargc > 1) {
98*0Sstevel@tonic-gate 					svargv++;
99*0Sstevel@tonic-gate 					svargc--;
100*0Sstevel@tonic-gate 					continue;
101*0Sstevel@tonic-gate 				}
102*0Sstevel@tonic-gate 				*svargv = L"-";
103*0Sstevel@tonic-gate 			}
104*0Sstevel@tonic-gate 			*FILENAME = file = *svargv;
105*0Sstevel@tonic-gate 			dprintf("opening file %ws\n", file, NULL, NULL);
106*0Sstevel@tonic-gate 			if (*file == (wchar_t)L'-')
107*0Sstevel@tonic-gate 				infile = stdin;
108*0Sstevel@tonic-gate 			else if ((infile = fopen(toeuccode(file), "r")) == NULL)
109*0Sstevel@tonic-gate 				error(FATAL, "can't open %ws", file);
110*0Sstevel@tonic-gate 		}
111*0Sstevel@tonic-gate 		if ((sep = **RS) == 0)
112*0Sstevel@tonic-gate 			sep = '\n';
113*0Sstevel@tonic-gate 		inf = infile;
114*0Sstevel@tonic-gate 		for (rr = record; /* dummy */; /* dummy */) {
115*0Sstevel@tonic-gate 			for (; (c = getwc(inf)) != sep && c != EOF && rr < er;
116*0Sstevel@tonic-gate 			    *rr++ = c)
117*0Sstevel@tonic-gate 				;
118*0Sstevel@tonic-gate 			if (rr >= er)
119*0Sstevel@tonic-gate 				error(FATAL, "record `%.20ws...' too long",
120*0Sstevel@tonic-gate 				    record);
121*0Sstevel@tonic-gate 			if (**RS == sep || c == EOF)
122*0Sstevel@tonic-gate 				break;
123*0Sstevel@tonic-gate 			if ((c = getwc(inf)) == '\n' || c == EOF)
124*0Sstevel@tonic-gate 			/* 2 in a row */
125*0Sstevel@tonic-gate 				break;
126*0Sstevel@tonic-gate 			*rr++ = '\n';
127*0Sstevel@tonic-gate 			*rr++ = c;
128*0Sstevel@tonic-gate 		}
129*0Sstevel@tonic-gate 		if (rr >= er)
130*0Sstevel@tonic-gate 			error(FATAL, "record `%.20ws...' too long", record);
131*0Sstevel@tonic-gate 		*rr = 0;
132*0Sstevel@tonic-gate 		if (mustfld)
133*0Sstevel@tonic-gate 			fldbld();
134*0Sstevel@tonic-gate 		if (c != EOF || rr > record) {	/* normal record */
135*0Sstevel@tonic-gate 			recloc->tval &= ~NUM;
136*0Sstevel@tonic-gate 			recloc->tval |= STR;
137*0Sstevel@tonic-gate 			++nrloc->fval;
138*0Sstevel@tonic-gate 			nrloc->tval &= ~STR;
139*0Sstevel@tonic-gate 			nrloc->tval |= NUM;
140*0Sstevel@tonic-gate 			return (1);
141*0Sstevel@tonic-gate 		}
142*0Sstevel@tonic-gate 		/* EOF arrived on this file; set up next */
143*0Sstevel@tonic-gate 		if (infile != stdin)
144*0Sstevel@tonic-gate 			fclose(infile);
145*0Sstevel@tonic-gate 		infile = NULL;
146*0Sstevel@tonic-gate 		svargc--;
147*0Sstevel@tonic-gate 		svargv++;
148*0Sstevel@tonic-gate 	}
149*0Sstevel@tonic-gate 	return (0);	/* true end of file */
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate setclvar(s)	/* set var=value from s */
154*0Sstevel@tonic-gate wchar_t *s;
155*0Sstevel@tonic-gate {
156*0Sstevel@tonic-gate 	wchar_t *p;
157*0Sstevel@tonic-gate 	CELL *q;
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	for (p = s; *p != '='; p++)
161*0Sstevel@tonic-gate 		;
162*0Sstevel@tonic-gate 	*p++ = 0;
163*0Sstevel@tonic-gate 	q = setsymtab(s, tostring(p), 0.0, STR, symtab);
164*0Sstevel@tonic-gate 	setsval(q, p);
165*0Sstevel@tonic-gate 	dprintf("command line set %ws to |%ws|\n", s, p, NULL);
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate fldbld()
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate 	register wchar_t *r, *fr, sep, c;
172*0Sstevel@tonic-gate 	static wchar_t L_NF[] = L"NF";
173*0Sstevel@tonic-gate 	CELL *p, *q;
174*0Sstevel@tonic-gate 	int i, j;
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate 	r = record;
178*0Sstevel@tonic-gate 	fr = fields;
179*0Sstevel@tonic-gate 	i = 0;	/* number of fields accumulated here */
180*0Sstevel@tonic-gate 	if ((sep = **FS) == ' ')
181*0Sstevel@tonic-gate 		for (i = 0; /* dummy */; /* dummy */) {
182*0Sstevel@tonic-gate 			c = *r;
183*0Sstevel@tonic-gate 			while (iswblank(c) || c == '\t' || c == '\n')
184*0Sstevel@tonic-gate 				c = *(++r);
185*0Sstevel@tonic-gate 			if (*r == 0)
186*0Sstevel@tonic-gate 				break;
187*0Sstevel@tonic-gate 			i++;
188*0Sstevel@tonic-gate 			if (i >= MAXFLD)
189*0Sstevel@tonic-gate 				error(FATAL,
190*0Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
191*0Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
192*0Sstevel@tonic-gate 				xfree(fldtab[i].sval);
193*0Sstevel@tonic-gate 			fldtab[i].sval = fr;
194*0Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
195*0Sstevel@tonic-gate 			do {
196*0Sstevel@tonic-gate 				*fr++ = *r++;
197*0Sstevel@tonic-gate 				c = *r;
198*0Sstevel@tonic-gate 			} while (! iswblank(c) && c != '\t' &&
199*0Sstevel@tonic-gate 				c != '\n' && c != '\0');
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 			*fr++ = 0;
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 	} else if (*r != 0)	/* if 0, it's a null field */
205*0Sstevel@tonic-gate 		for (;;) {
206*0Sstevel@tonic-gate 			i++;
207*0Sstevel@tonic-gate 			if (i >= MAXFLD)
208*0Sstevel@tonic-gate 				error(FATAL,
209*0Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
210*0Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
211*0Sstevel@tonic-gate 				xfree(fldtab[i].sval);
212*0Sstevel@tonic-gate 			fldtab[i].sval = fr;
213*0Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
214*0Sstevel@tonic-gate 			while ((c = *r) != sep && c != '\n' && c != '\0')
215*0Sstevel@tonic-gate 				/* \n always a separator */
216*0Sstevel@tonic-gate 				*fr++ = *r++;
217*0Sstevel@tonic-gate 			*fr++ = 0;
218*0Sstevel@tonic-gate 			if (*r++ == 0)
219*0Sstevel@tonic-gate 				break;
220*0Sstevel@tonic-gate 		}
221*0Sstevel@tonic-gate 	*fr = 0;
222*0Sstevel@tonic-gate 	/* clean out junk from previous record */
223*0Sstevel@tonic-gate 	for (p = maxmfld, q = &fldtab[i]; p > q; p--) {
224*0Sstevel@tonic-gate 		if (!(p->tval&FLD))
225*0Sstevel@tonic-gate 			xfree(p->sval);
226*0Sstevel@tonic-gate 		p->tval = STR | FLD;
227*0Sstevel@tonic-gate 		p->sval = L_NULL;
228*0Sstevel@tonic-gate 	}
229*0Sstevel@tonic-gate 	maxfld = i;
230*0Sstevel@tonic-gate 	maxmfld = &fldtab[i];
231*0Sstevel@tonic-gate 	donefld = 1;
232*0Sstevel@tonic-gate 	for (i = 1; i <= maxfld; i++)
233*0Sstevel@tonic-gate 		if (isanumber(fldtab[i].sval)) {
234*0Sstevel@tonic-gate 			fldtab[i].fval = watof(fldtab[i].sval);
235*0Sstevel@tonic-gate 			fldtab[i].tval |= NUM;
236*0Sstevel@tonic-gate 		}
237*0Sstevel@tonic-gate 	setfval(lookup(L_NF, symtab, 0), (awkfloat) maxfld);
238*0Sstevel@tonic-gate 	if (dbg)
239*0Sstevel@tonic-gate 		for (i = 0; i <= maxfld; i++)
240*0Sstevel@tonic-gate 			printf("field %d: |%ws|\n", i, fldtab[i].sval);
241*0Sstevel@tonic-gate }
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate recbld()
245*0Sstevel@tonic-gate {
246*0Sstevel@tonic-gate 	int i;
247*0Sstevel@tonic-gate 	register wchar_t *r, *p;
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate 	if (donefld == 0 || donerec == 1)
251*0Sstevel@tonic-gate 		return;
252*0Sstevel@tonic-gate 	r = record;
253*0Sstevel@tonic-gate 	for (i = 1; i <= *NF; i++) {
254*0Sstevel@tonic-gate 		p = getsval(&fldtab[i]);
255*0Sstevel@tonic-gate 		while (*r++ = *p++)
256*0Sstevel@tonic-gate 			;
257*0Sstevel@tonic-gate 		*(r-1) = **OFS;
258*0Sstevel@tonic-gate 	}
259*0Sstevel@tonic-gate 	*(r-1) = '\0';
260*0Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
261*0Sstevel@tonic-gate 	recloc->tval = STR | FLD;
262*0Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
263*0Sstevel@tonic-gate 	if (r > record+RECSIZE)
264*0Sstevel@tonic-gate 		error(FATAL, "built giant record `%.20ws...'", record);
265*0Sstevel@tonic-gate 	dprintf("recbld = |%ws|\n", record, NULL, NULL);
266*0Sstevel@tonic-gate }
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate CELL *
270*0Sstevel@tonic-gate fieldadr(n)
271*0Sstevel@tonic-gate {
272*0Sstevel@tonic-gate 	if (n < 0 || n >= MAXFLD)
273*0Sstevel@tonic-gate 		error(FATAL, "trying to access field %d", n);
274*0Sstevel@tonic-gate 	return (&fldtab[n]);
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 
278*0Sstevel@tonic-gate int	errorflag	= 0;
279*0Sstevel@tonic-gate 
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate yyerror(char *s)
282*0Sstevel@tonic-gate {
283*0Sstevel@tonic-gate 	fprintf(stderr,
284*0Sstevel@tonic-gate 		gettext("awk: %s near line %lld\n"), gettext(s), lineno);
285*0Sstevel@tonic-gate 	errorflag = 2;
286*0Sstevel@tonic-gate }
287*0Sstevel@tonic-gate 
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7)
290*0Sstevel@tonic-gate {
291*0Sstevel@tonic-gate 	fprintf(stderr, "awk: ");
292*0Sstevel@tonic-gate 	fprintf(stderr, gettext((char *)s), a1, a2, a3, a4, a5, a6, a7);
293*0Sstevel@tonic-gate 	fprintf(stderr, "\n");
294*0Sstevel@tonic-gate 	if (NR && *NR > 0)
295*0Sstevel@tonic-gate 		fprintf(stderr, gettext(" record number %g\n"), *NR);
296*0Sstevel@tonic-gate 	if (f)
297*0Sstevel@tonic-gate 		exit(2);
298*0Sstevel@tonic-gate }
299*0Sstevel@tonic-gate 
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate PUTS(s) char *s; {
302*0Sstevel@tonic-gate 	dprintf("%s\n", s, NULL, NULL);
303*0Sstevel@tonic-gate }
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate #define	MAXEXPON	38	/* maximum exponenet for fp number */
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate isanumber(s)
310*0Sstevel@tonic-gate register wchar_t *s;
311*0Sstevel@tonic-gate {
312*0Sstevel@tonic-gate 	register d1, d2;
313*0Sstevel@tonic-gate 	int point;
314*0Sstevel@tonic-gate 	wchar_t *es;
315*0Sstevel@tonic-gate 	extern wchar_t	radixpoint;
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	d1 = d2 = point = 0;
318*0Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
319*0Sstevel@tonic-gate 		s++;
320*0Sstevel@tonic-gate 	if (*s == '\0')
321*0Sstevel@tonic-gate 		return (0);	/* empty stuff isn't number */
322*0Sstevel@tonic-gate 	if (*s == '+' || *s == '-')
323*0Sstevel@tonic-gate 		s++;
324*0Sstevel@tonic-gate 	/*
325*0Sstevel@tonic-gate 	 * Since, iswdigit() will include digit from other than code set 0,
326*0Sstevel@tonic-gate 	 * we have to check it from code set 0 or not.
327*0Sstevel@tonic-gate 	 */
328*0Sstevel@tonic-gate 	if (!(iswdigit(*s) && iswascii(*s)) && *s != radixpoint)
329*0Sstevel@tonic-gate 		return (0);
330*0Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
331*0Sstevel@tonic-gate 		do {
332*0Sstevel@tonic-gate 			d1++;
333*0Sstevel@tonic-gate 			s++;
334*0Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
335*0Sstevel@tonic-gate 	}
336*0Sstevel@tonic-gate 	if (d1 >= MAXEXPON)
337*0Sstevel@tonic-gate 		return (0);	/* too many digits to convert */
338*0Sstevel@tonic-gate 	if (*s == radixpoint) {
339*0Sstevel@tonic-gate 		point++;
340*0Sstevel@tonic-gate 		s++;
341*0Sstevel@tonic-gate 	}
342*0Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
343*0Sstevel@tonic-gate 		d2++;
344*0Sstevel@tonic-gate 		do {
345*0Sstevel@tonic-gate 			s++;
346*0Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
347*0Sstevel@tonic-gate 	}
348*0Sstevel@tonic-gate 
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	if (!(d1 || point && d2))
351*0Sstevel@tonic-gate 		return (0);
352*0Sstevel@tonic-gate 	if (*s == 'e' || *s == 'E') {
353*0Sstevel@tonic-gate 		s++;
354*0Sstevel@tonic-gate 		if (*s == '+' || *s == '-')
355*0Sstevel@tonic-gate 			s++;
356*0Sstevel@tonic-gate 		if (!(iswdigit(*s) && iswascii(*s)))
357*0Sstevel@tonic-gate 			return (0);
358*0Sstevel@tonic-gate 		es = s;
359*0Sstevel@tonic-gate 		do {
360*0Sstevel@tonic-gate 			s++;
361*0Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 		if (s - es > 2)
365*0Sstevel@tonic-gate 			return (0);
366*0Sstevel@tonic-gate 		else if (s - es == 2 &&
367*0Sstevel@tonic-gate 			10 * (*es-'0') + *(es+1)-'0' >= MAXEXPON)
368*0Sstevel@tonic-gate 			return (0);
369*0Sstevel@tonic-gate 	}
370*0Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
371*0Sstevel@tonic-gate 		s++;
372*0Sstevel@tonic-gate 	if (*s == '\0')
373*0Sstevel@tonic-gate 		return (1);
374*0Sstevel@tonic-gate 	else
375*0Sstevel@tonic-gate 		return (0);
376*0Sstevel@tonic-gate }
377*0Sstevel@tonic-gate char *
378*0Sstevel@tonic-gate toeuccode(str)
379*0Sstevel@tonic-gate wchar_t *str;
380*0Sstevel@tonic-gate {
381*0Sstevel@tonic-gate 	static char euccode[RECSIZE];
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate 	(void) wcstombs(euccode, str, RECSIZE);
384*0Sstevel@tonic-gate 	return (euccode);
385*0Sstevel@tonic-gate }
386