xref: /onnv-gate/usr/src/cmd/oawk/lib.c (revision 648)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*648Sceastha /*
23*648Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*648Sceastha  * Use is subject to license terms.
25*648Sceastha  */
26*648Sceastha 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <stdio.h>
330Sstevel@tonic-gate #include "awk.def"
340Sstevel@tonic-gate #include "awk.h"
350Sstevel@tonic-gate #include <ctype.h>
360Sstevel@tonic-gate #include <wctype.h>
370Sstevel@tonic-gate #include "awktype.h"
380Sstevel@tonic-gate #include <stdlib.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate FILE	*infile	= NULL;
410Sstevel@tonic-gate wchar_t *file;
420Sstevel@tonic-gate #define	RECSIZE (5 * 512)
430Sstevel@tonic-gate wchar_t record[RECSIZE];
440Sstevel@tonic-gate wchar_t fields[RECSIZE];
450Sstevel@tonic-gate wchar_t L_NULL[] = L"";
460Sstevel@tonic-gate 
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #define	MAXFLD	100
490Sstevel@tonic-gate int	donefld;	/* 1 = implies rec broken into fields */
500Sstevel@tonic-gate int	donerec;	/* 1 = record is valid (no flds have changed) */
510Sstevel@tonic-gate int	mustfld;	/* 1 = NF seen, so always break */
520Sstevel@tonic-gate static wchar_t L_record[] = L"$record";
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	FINIT	{ OCELL, CFLD, 0, L_NULL, 0.0, FLD|STR }
560Sstevel@tonic-gate CELL fldtab[MAXFLD] = {		/* room for fields */
570Sstevel@tonic-gate 	{ OCELL, CFLD, L_record, record, 0.0, STR|FLD},
580Sstevel@tonic-gate 		FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
590Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
600Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
610Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
620Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
630Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
640Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
650Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
660Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
670Sstevel@tonic-gate 	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT
680Sstevel@tonic-gate };
690Sstevel@tonic-gate int	maxfld	= 0;	/* last used field */
700Sstevel@tonic-gate /* pointer to CELL for maximum field assigned to */
710Sstevel@tonic-gate CELL	*maxmfld = &fldtab[0];
720Sstevel@tonic-gate 
73*648Sceastha static int isclvar(wchar_t *);
740Sstevel@tonic-gate 
750Sstevel@tonic-gate getrec()
760Sstevel@tonic-gate {
77*648Sceastha 	wchar_t *rr, *er;
78*648Sceastha 	int c, sep;
79*648Sceastha 	FILE *inf;
800Sstevel@tonic-gate 	extern int svargc;
810Sstevel@tonic-gate 	extern wchar_t **svargv;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL);
850Sstevel@tonic-gate 	donefld = 0;
860Sstevel@tonic-gate 	donerec = 1;
870Sstevel@tonic-gate 	record[0] = 0;
880Sstevel@tonic-gate 	er = record + RECSIZE;
890Sstevel@tonic-gate 	while (svargc > 0) {
900Sstevel@tonic-gate 		dprintf("svargc=%d, *svargv=%ws\n", svargc, *svargv, NULL);
910Sstevel@tonic-gate 		if (infile == NULL) {	/* have to open a new file */
92*648Sceastha 			/*
93*648Sceastha 			 * If the argument contains a '=', determine if the
94*648Sceastha 			 * argument needs to be treated as a variable assignment
95*648Sceastha 			 * or as the pathname of a file.
96*648Sceastha 			 */
97*648Sceastha 			if (isclvar(*svargv)) {
980Sstevel@tonic-gate 				/* it's a var=value argument */
990Sstevel@tonic-gate 				setclvar(*svargv);
1000Sstevel@tonic-gate 				if (svargc > 1) {
1010Sstevel@tonic-gate 					svargv++;
1020Sstevel@tonic-gate 					svargc--;
1030Sstevel@tonic-gate 					continue;
1040Sstevel@tonic-gate 				}
1050Sstevel@tonic-gate 				*svargv = L"-";
1060Sstevel@tonic-gate 			}
1070Sstevel@tonic-gate 			*FILENAME = file = *svargv;
1080Sstevel@tonic-gate 			dprintf("opening file %ws\n", file, NULL, NULL);
1090Sstevel@tonic-gate 			if (*file == (wchar_t)L'-')
1100Sstevel@tonic-gate 				infile = stdin;
1110Sstevel@tonic-gate 			else if ((infile = fopen(toeuccode(file), "r")) == NULL)
1120Sstevel@tonic-gate 				error(FATAL, "can't open %ws", file);
1130Sstevel@tonic-gate 		}
1140Sstevel@tonic-gate 		if ((sep = **RS) == 0)
1150Sstevel@tonic-gate 			sep = '\n';
1160Sstevel@tonic-gate 		inf = infile;
1170Sstevel@tonic-gate 		for (rr = record; /* dummy */; /* dummy */) {
1180Sstevel@tonic-gate 			for (; (c = getwc(inf)) != sep && c != EOF && rr < er;
1190Sstevel@tonic-gate 			    *rr++ = c)
1200Sstevel@tonic-gate 				;
1210Sstevel@tonic-gate 			if (rr >= er)
1220Sstevel@tonic-gate 				error(FATAL, "record `%.20ws...' too long",
1230Sstevel@tonic-gate 				    record);
1240Sstevel@tonic-gate 			if (**RS == sep || c == EOF)
1250Sstevel@tonic-gate 				break;
1260Sstevel@tonic-gate 			if ((c = getwc(inf)) == '\n' || c == EOF)
1270Sstevel@tonic-gate 			/* 2 in a row */
1280Sstevel@tonic-gate 				break;
1290Sstevel@tonic-gate 			*rr++ = '\n';
1300Sstevel@tonic-gate 			*rr++ = c;
1310Sstevel@tonic-gate 		}
1320Sstevel@tonic-gate 		if (rr >= er)
1330Sstevel@tonic-gate 			error(FATAL, "record `%.20ws...' too long", record);
1340Sstevel@tonic-gate 		*rr = 0;
1350Sstevel@tonic-gate 		if (mustfld)
1360Sstevel@tonic-gate 			fldbld();
1370Sstevel@tonic-gate 		if (c != EOF || rr > record) {	/* normal record */
1380Sstevel@tonic-gate 			recloc->tval &= ~NUM;
1390Sstevel@tonic-gate 			recloc->tval |= STR;
1400Sstevel@tonic-gate 			++nrloc->fval;
1410Sstevel@tonic-gate 			nrloc->tval &= ~STR;
1420Sstevel@tonic-gate 			nrloc->tval |= NUM;
1430Sstevel@tonic-gate 			return (1);
1440Sstevel@tonic-gate 		}
1450Sstevel@tonic-gate 		/* EOF arrived on this file; set up next */
1460Sstevel@tonic-gate 		if (infile != stdin)
1470Sstevel@tonic-gate 			fclose(infile);
1480Sstevel@tonic-gate 		infile = NULL;
1490Sstevel@tonic-gate 		svargc--;
1500Sstevel@tonic-gate 		svargv++;
1510Sstevel@tonic-gate 	}
1520Sstevel@tonic-gate 	return (0);	/* true end of file */
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate 
155*648Sceastha /*
156*648Sceastha  * isclvar()
157*648Sceastha  *
158*648Sceastha  * Returns 1 if the input string, arg, is a variable assignment,
159*648Sceastha  * otherwise returns 0.
160*648Sceastha  *
161*648Sceastha  * An argument to awk can be either a pathname of a file, or a variable
162*648Sceastha  * assignment.  An operand that begins with an undersore or alphabetic
163*648Sceastha  * character from the portable character set, followed by a sequence of
164*648Sceastha  * underscores, digits, and alphabetics from the portable character set,
165*648Sceastha  * followed by the '=' character, shall specify a variable assignment
166*648Sceastha  * rather than a pathname.
167*648Sceastha  */
168*648Sceastha static int
169*648Sceastha isclvar(wchar_t *arg)
170*648Sceastha {
171*648Sceastha 	wchar_t	*tmpptr = arg;
172*648Sceastha 
173*648Sceastha 	if (tmpptr != NULL) {
174*648Sceastha 
175*648Sceastha 		/* Begins with an underscore or alphabetic character */
176*648Sceastha 		if (iswalpha(*tmpptr) || *tmpptr == '_') {
177*648Sceastha 
178*648Sceastha 			/*
179*648Sceastha 			 * followed by a sequence of underscores, digits,
180*648Sceastha 			 * and alphabetics
181*648Sceastha 			 */
182*648Sceastha 			for (tmpptr++; *tmpptr; tmpptr++) {
183*648Sceastha 				if (!(isalnum(*tmpptr) || (*tmpptr == '_'))) {
184*648Sceastha 					break;
185*648Sceastha 				}
186*648Sceastha 			}
187*648Sceastha 			return (*tmpptr == '=');
188*648Sceastha 		}
189*648Sceastha 	}
190*648Sceastha 
191*648Sceastha 	return (0);
192*648Sceastha }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate setclvar(s)	/* set var=value from s */
1950Sstevel@tonic-gate wchar_t *s;
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate 	wchar_t *p;
1980Sstevel@tonic-gate 	CELL *q;
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	for (p = s; *p != '='; p++)
2020Sstevel@tonic-gate 		;
2030Sstevel@tonic-gate 	*p++ = 0;
2040Sstevel@tonic-gate 	q = setsymtab(s, tostring(p), 0.0, STR, symtab);
2050Sstevel@tonic-gate 	setsval(q, p);
2060Sstevel@tonic-gate 	dprintf("command line set %ws to |%ws|\n", s, p, NULL);
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate fldbld()
2110Sstevel@tonic-gate {
212*648Sceastha 	wchar_t *r, *fr, sep, c;
2130Sstevel@tonic-gate 	static wchar_t L_NF[] = L"NF";
2140Sstevel@tonic-gate 	CELL *p, *q;
2150Sstevel@tonic-gate 	int i, j;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	r = record;
2190Sstevel@tonic-gate 	fr = fields;
2200Sstevel@tonic-gate 	i = 0;	/* number of fields accumulated here */
2210Sstevel@tonic-gate 	if ((sep = **FS) == ' ')
2220Sstevel@tonic-gate 		for (i = 0; /* dummy */; /* dummy */) {
2230Sstevel@tonic-gate 			c = *r;
2240Sstevel@tonic-gate 			while (iswblank(c) || c == '\t' || c == '\n')
2250Sstevel@tonic-gate 				c = *(++r);
2260Sstevel@tonic-gate 			if (*r == 0)
2270Sstevel@tonic-gate 				break;
2280Sstevel@tonic-gate 			i++;
2290Sstevel@tonic-gate 			if (i >= MAXFLD)
2300Sstevel@tonic-gate 				error(FATAL,
2310Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
2320Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
2330Sstevel@tonic-gate 				xfree(fldtab[i].sval);
2340Sstevel@tonic-gate 			fldtab[i].sval = fr;
2350Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
2360Sstevel@tonic-gate 			do {
2370Sstevel@tonic-gate 				*fr++ = *r++;
2380Sstevel@tonic-gate 				c = *r;
2390Sstevel@tonic-gate 			} while (! iswblank(c) && c != '\t' &&
240*648Sceastha 			    c != '\n' && c != '\0');
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 			*fr++ = 0;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	} else if (*r != 0)	/* if 0, it's a null field */
2460Sstevel@tonic-gate 		for (;;) {
2470Sstevel@tonic-gate 			i++;
2480Sstevel@tonic-gate 			if (i >= MAXFLD)
2490Sstevel@tonic-gate 				error(FATAL,
2500Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
2510Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
2520Sstevel@tonic-gate 				xfree(fldtab[i].sval);
2530Sstevel@tonic-gate 			fldtab[i].sval = fr;
2540Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
2550Sstevel@tonic-gate 			while ((c = *r) != sep && c != '\n' && c != '\0')
2560Sstevel@tonic-gate 				/* \n always a separator */
2570Sstevel@tonic-gate 				*fr++ = *r++;
2580Sstevel@tonic-gate 			*fr++ = 0;
2590Sstevel@tonic-gate 			if (*r++ == 0)
2600Sstevel@tonic-gate 				break;
2610Sstevel@tonic-gate 		}
2620Sstevel@tonic-gate 	*fr = 0;
2630Sstevel@tonic-gate 	/* clean out junk from previous record */
2640Sstevel@tonic-gate 	for (p = maxmfld, q = &fldtab[i]; p > q; p--) {
2650Sstevel@tonic-gate 		if (!(p->tval&FLD))
2660Sstevel@tonic-gate 			xfree(p->sval);
2670Sstevel@tonic-gate 		p->tval = STR | FLD;
2680Sstevel@tonic-gate 		p->sval = L_NULL;
2690Sstevel@tonic-gate 	}
2700Sstevel@tonic-gate 	maxfld = i;
2710Sstevel@tonic-gate 	maxmfld = &fldtab[i];
2720Sstevel@tonic-gate 	donefld = 1;
2730Sstevel@tonic-gate 	for (i = 1; i <= maxfld; i++)
2740Sstevel@tonic-gate 		if (isanumber(fldtab[i].sval)) {
2750Sstevel@tonic-gate 			fldtab[i].fval = watof(fldtab[i].sval);
2760Sstevel@tonic-gate 			fldtab[i].tval |= NUM;
2770Sstevel@tonic-gate 		}
2780Sstevel@tonic-gate 	setfval(lookup(L_NF, symtab, 0), (awkfloat) maxfld);
2790Sstevel@tonic-gate 	if (dbg)
2800Sstevel@tonic-gate 		for (i = 0; i <= maxfld; i++)
2810Sstevel@tonic-gate 			printf("field %d: |%ws|\n", i, fldtab[i].sval);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate recbld()
2860Sstevel@tonic-gate {
2870Sstevel@tonic-gate 	int i;
288*648Sceastha 	wchar_t *r, *p;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 	if (donefld == 0 || donerec == 1)
2920Sstevel@tonic-gate 		return;
2930Sstevel@tonic-gate 	r = record;
2940Sstevel@tonic-gate 	for (i = 1; i <= *NF; i++) {
2950Sstevel@tonic-gate 		p = getsval(&fldtab[i]);
2960Sstevel@tonic-gate 		while (*r++ = *p++)
2970Sstevel@tonic-gate 			;
2980Sstevel@tonic-gate 		*(r-1) = **OFS;
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate 	*(r-1) = '\0';
3010Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
3020Sstevel@tonic-gate 	recloc->tval = STR | FLD;
3030Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
3040Sstevel@tonic-gate 	if (r > record+RECSIZE)
3050Sstevel@tonic-gate 		error(FATAL, "built giant record `%.20ws...'", record);
3060Sstevel@tonic-gate 	dprintf("recbld = |%ws|\n", record, NULL, NULL);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate CELL *
3110Sstevel@tonic-gate fieldadr(n)
3120Sstevel@tonic-gate {
3130Sstevel@tonic-gate 	if (n < 0 || n >= MAXFLD)
3140Sstevel@tonic-gate 		error(FATAL, "trying to access field %d", n);
3150Sstevel@tonic-gate 	return (&fldtab[n]);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate int	errorflag	= 0;
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate yyerror(char *s)
3230Sstevel@tonic-gate {
3240Sstevel@tonic-gate 	fprintf(stderr,
325*648Sceastha 	    gettext("awk: %s near line %lld\n"), gettext(s), lineno);
3260Sstevel@tonic-gate 	errorflag = 2;
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate 	fprintf(stderr, "awk: ");
3330Sstevel@tonic-gate 	fprintf(stderr, gettext((char *)s), a1, a2, a3, a4, a5, a6, a7);
3340Sstevel@tonic-gate 	fprintf(stderr, "\n");
3350Sstevel@tonic-gate 	if (NR && *NR > 0)
3360Sstevel@tonic-gate 		fprintf(stderr, gettext(" record number %g\n"), *NR);
3370Sstevel@tonic-gate 	if (f)
3380Sstevel@tonic-gate 		exit(2);
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate PUTS(s) char *s; {
3430Sstevel@tonic-gate 	dprintf("%s\n", s, NULL, NULL);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate #define	MAXEXPON	38	/* maximum exponenet for fp number */
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate isanumber(s)
351*648Sceastha wchar_t *s;
3520Sstevel@tonic-gate {
353*648Sceastha 	int d1, d2;
3540Sstevel@tonic-gate 	int point;
3550Sstevel@tonic-gate 	wchar_t *es;
3560Sstevel@tonic-gate 	extern wchar_t	radixpoint;
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	d1 = d2 = point = 0;
3590Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
3600Sstevel@tonic-gate 		s++;
3610Sstevel@tonic-gate 	if (*s == '\0')
3620Sstevel@tonic-gate 		return (0);	/* empty stuff isn't number */
3630Sstevel@tonic-gate 	if (*s == '+' || *s == '-')
3640Sstevel@tonic-gate 		s++;
3650Sstevel@tonic-gate 	/*
3660Sstevel@tonic-gate 	 * Since, iswdigit() will include digit from other than code set 0,
3670Sstevel@tonic-gate 	 * we have to check it from code set 0 or not.
3680Sstevel@tonic-gate 	 */
3690Sstevel@tonic-gate 	if (!(iswdigit(*s) && iswascii(*s)) && *s != radixpoint)
3700Sstevel@tonic-gate 		return (0);
3710Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
3720Sstevel@tonic-gate 		do {
3730Sstevel@tonic-gate 			d1++;
3740Sstevel@tonic-gate 			s++;
3750Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate 	if (d1 >= MAXEXPON)
3780Sstevel@tonic-gate 		return (0);	/* too many digits to convert */
3790Sstevel@tonic-gate 	if (*s == radixpoint) {
3800Sstevel@tonic-gate 		point++;
3810Sstevel@tonic-gate 		s++;
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
3840Sstevel@tonic-gate 		d2++;
3850Sstevel@tonic-gate 		do {
3860Sstevel@tonic-gate 			s++;
3870Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
3880Sstevel@tonic-gate 	}
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	if (!(d1 || point && d2))
3920Sstevel@tonic-gate 		return (0);
3930Sstevel@tonic-gate 	if (*s == 'e' || *s == 'E') {
3940Sstevel@tonic-gate 		s++;
3950Sstevel@tonic-gate 		if (*s == '+' || *s == '-')
3960Sstevel@tonic-gate 			s++;
3970Sstevel@tonic-gate 		if (!(iswdigit(*s) && iswascii(*s)))
3980Sstevel@tonic-gate 			return (0);
3990Sstevel@tonic-gate 		es = s;
4000Sstevel@tonic-gate 		do {
4010Sstevel@tonic-gate 			s++;
4020Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 		if (s - es > 2)
4060Sstevel@tonic-gate 			return (0);
4070Sstevel@tonic-gate 		else if (s - es == 2 &&
4080Sstevel@tonic-gate 			10 * (*es-'0') + *(es+1)-'0' >= MAXEXPON)
4090Sstevel@tonic-gate 			return (0);
4100Sstevel@tonic-gate 	}
4110Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
4120Sstevel@tonic-gate 		s++;
4130Sstevel@tonic-gate 	if (*s == '\0')
4140Sstevel@tonic-gate 		return (1);
4150Sstevel@tonic-gate 	else
4160Sstevel@tonic-gate 		return (0);
4170Sstevel@tonic-gate }
4180Sstevel@tonic-gate char *
4190Sstevel@tonic-gate toeuccode(str)
4200Sstevel@tonic-gate wchar_t *str;
4210Sstevel@tonic-gate {
4220Sstevel@tonic-gate 	static char euccode[RECSIZE];
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 	(void) wcstombs(euccode, str, RECSIZE);
4250Sstevel@tonic-gate 	return (euccode);
4260Sstevel@tonic-gate }
427