xref: /onnv-gate/usr/src/cmd/oawk/lib.c (revision 1212:2f4b19e8dcff)
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  */
22648Sceastha /*
23*1212Sceastha  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24648Sceastha  * Use is subject to license terms.
25648Sceastha  */
26648Sceastha 
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 
73648Sceastha static int isclvar(wchar_t *);
74731Srobbin static void setclvar(wchar_t *);
75731Srobbin void fldbld(void);
760Sstevel@tonic-gate 
77731Srobbin int
getrec(void)78731Srobbin getrec(void)
790Sstevel@tonic-gate {
80648Sceastha 	wchar_t *rr, *er;
81648Sceastha 	int c, sep;
82648Sceastha 	FILE *inf;
830Sstevel@tonic-gate 	extern int svargc;
840Sstevel@tonic-gate 	extern wchar_t **svargv;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL);
880Sstevel@tonic-gate 	donefld = 0;
890Sstevel@tonic-gate 	donerec = 1;
900Sstevel@tonic-gate 	record[0] = 0;
910Sstevel@tonic-gate 	er = record + RECSIZE;
920Sstevel@tonic-gate 	while (svargc > 0) {
930Sstevel@tonic-gate 		dprintf("svargc=%d, *svargv=%ws\n", svargc, *svargv, NULL);
940Sstevel@tonic-gate 		if (infile == NULL) {	/* have to open a new file */
95648Sceastha 			/*
96648Sceastha 			 * If the argument contains a '=', determine if the
97648Sceastha 			 * argument needs to be treated as a variable assignment
98648Sceastha 			 * or as the pathname of a file.
99648Sceastha 			 */
100648Sceastha 			if (isclvar(*svargv)) {
1010Sstevel@tonic-gate 				/* it's a var=value argument */
1020Sstevel@tonic-gate 				setclvar(*svargv);
1030Sstevel@tonic-gate 				if (svargc > 1) {
1040Sstevel@tonic-gate 					svargv++;
1050Sstevel@tonic-gate 					svargc--;
1060Sstevel@tonic-gate 					continue;
1070Sstevel@tonic-gate 				}
1080Sstevel@tonic-gate 				*svargv = L"-";
1090Sstevel@tonic-gate 			}
1100Sstevel@tonic-gate 			*FILENAME = file = *svargv;
1110Sstevel@tonic-gate 			dprintf("opening file %ws\n", file, NULL, NULL);
1120Sstevel@tonic-gate 			if (*file == (wchar_t)L'-')
1130Sstevel@tonic-gate 				infile = stdin;
1140Sstevel@tonic-gate 			else if ((infile = fopen(toeuccode(file), "r")) == NULL)
1150Sstevel@tonic-gate 				error(FATAL, "can't open %ws", file);
1160Sstevel@tonic-gate 		}
1170Sstevel@tonic-gate 		if ((sep = **RS) == 0)
1180Sstevel@tonic-gate 			sep = '\n';
1190Sstevel@tonic-gate 		inf = infile;
1200Sstevel@tonic-gate 		for (rr = record; /* dummy */; /* dummy */) {
1210Sstevel@tonic-gate 			for (; (c = getwc(inf)) != sep && c != EOF && rr < er;
1220Sstevel@tonic-gate 			    *rr++ = c)
1230Sstevel@tonic-gate 				;
1240Sstevel@tonic-gate 			if (rr >= er)
1250Sstevel@tonic-gate 				error(FATAL, "record `%.20ws...' too long",
1260Sstevel@tonic-gate 				    record);
1270Sstevel@tonic-gate 			if (**RS == sep || c == EOF)
1280Sstevel@tonic-gate 				break;
1290Sstevel@tonic-gate 			if ((c = getwc(inf)) == '\n' || c == EOF)
1300Sstevel@tonic-gate 			/* 2 in a row */
1310Sstevel@tonic-gate 				break;
1320Sstevel@tonic-gate 			*rr++ = '\n';
1330Sstevel@tonic-gate 			*rr++ = c;
1340Sstevel@tonic-gate 		}
1350Sstevel@tonic-gate 		if (rr >= er)
1360Sstevel@tonic-gate 			error(FATAL, "record `%.20ws...' too long", record);
1370Sstevel@tonic-gate 		*rr = 0;
1380Sstevel@tonic-gate 		if (mustfld)
1390Sstevel@tonic-gate 			fldbld();
1400Sstevel@tonic-gate 		if (c != EOF || rr > record) {	/* normal record */
1410Sstevel@tonic-gate 			recloc->tval &= ~NUM;
1420Sstevel@tonic-gate 			recloc->tval |= STR;
1430Sstevel@tonic-gate 			++nrloc->fval;
1440Sstevel@tonic-gate 			nrloc->tval &= ~STR;
1450Sstevel@tonic-gate 			nrloc->tval |= NUM;
1460Sstevel@tonic-gate 			return (1);
1470Sstevel@tonic-gate 		}
1480Sstevel@tonic-gate 		/* EOF arrived on this file; set up next */
1490Sstevel@tonic-gate 		if (infile != stdin)
1500Sstevel@tonic-gate 			fclose(infile);
1510Sstevel@tonic-gate 		infile = NULL;
1520Sstevel@tonic-gate 		svargc--;
1530Sstevel@tonic-gate 		svargv++;
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 	return (0);	/* true end of file */
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate 
158648Sceastha /*
159648Sceastha  * isclvar()
160648Sceastha  *
161648Sceastha  * Returns 1 if the input string, arg, is a variable assignment,
162648Sceastha  * otherwise returns 0.
163648Sceastha  *
164648Sceastha  * An argument to awk can be either a pathname of a file, or a variable
165648Sceastha  * assignment.  An operand that begins with an undersore or alphabetic
166648Sceastha  * character from the portable character set, followed by a sequence of
167648Sceastha  * underscores, digits, and alphabetics from the portable character set,
168648Sceastha  * followed by the '=' character, shall specify a variable assignment
169648Sceastha  * rather than a pathname.
170648Sceastha  */
171648Sceastha static int
isclvar(wchar_t * arg)172648Sceastha isclvar(wchar_t *arg)
173648Sceastha {
174648Sceastha 	wchar_t	*tmpptr = arg;
175648Sceastha 
176648Sceastha 	if (tmpptr != NULL) {
177648Sceastha 
178648Sceastha 		/* Begins with an underscore or alphabetic character */
179648Sceastha 		if (iswalpha(*tmpptr) || *tmpptr == '_') {
180648Sceastha 
181648Sceastha 			/*
182648Sceastha 			 * followed by a sequence of underscores, digits,
183648Sceastha 			 * and alphabetics
184648Sceastha 			 */
185648Sceastha 			for (tmpptr++; *tmpptr; tmpptr++) {
186*1212Sceastha 				if (!(iswalnum(*tmpptr) || (*tmpptr == '_'))) {
187648Sceastha 					break;
188648Sceastha 				}
189648Sceastha 			}
190648Sceastha 			return (*tmpptr == '=');
191648Sceastha 		}
192648Sceastha 	}
193648Sceastha 
194648Sceastha 	return (0);
195648Sceastha }
1960Sstevel@tonic-gate 
197731Srobbin static void
setclvar(wchar_t * s)198731Srobbin setclvar(wchar_t *s)	/* set var=value from s */
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate 	wchar_t *p;
2010Sstevel@tonic-gate 	CELL *q;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	for (p = s; *p != '='; p++)
2050Sstevel@tonic-gate 		;
2060Sstevel@tonic-gate 	*p++ = 0;
2070Sstevel@tonic-gate 	q = setsymtab(s, tostring(p), 0.0, STR, symtab);
2080Sstevel@tonic-gate 	setsval(q, p);
2090Sstevel@tonic-gate 	dprintf("command line set %ws to |%ws|\n", s, p, NULL);
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 
213731Srobbin void
fldbld(void)214731Srobbin fldbld(void)
2150Sstevel@tonic-gate {
216648Sceastha 	wchar_t *r, *fr, sep, c;
2170Sstevel@tonic-gate 	static wchar_t L_NF[] = L"NF";
2180Sstevel@tonic-gate 	CELL *p, *q;
2190Sstevel@tonic-gate 	int i, j;
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	r = record;
2230Sstevel@tonic-gate 	fr = fields;
2240Sstevel@tonic-gate 	i = 0;	/* number of fields accumulated here */
2250Sstevel@tonic-gate 	if ((sep = **FS) == ' ')
2260Sstevel@tonic-gate 		for (i = 0; /* dummy */; /* dummy */) {
2270Sstevel@tonic-gate 			c = *r;
2280Sstevel@tonic-gate 			while (iswblank(c) || c == '\t' || c == '\n')
2290Sstevel@tonic-gate 				c = *(++r);
2300Sstevel@tonic-gate 			if (*r == 0)
2310Sstevel@tonic-gate 				break;
2320Sstevel@tonic-gate 			i++;
2330Sstevel@tonic-gate 			if (i >= MAXFLD)
2340Sstevel@tonic-gate 				error(FATAL,
2350Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
2360Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
2370Sstevel@tonic-gate 				xfree(fldtab[i].sval);
2380Sstevel@tonic-gate 			fldtab[i].sval = fr;
2390Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
2400Sstevel@tonic-gate 			do {
2410Sstevel@tonic-gate 				*fr++ = *r++;
2420Sstevel@tonic-gate 				c = *r;
2430Sstevel@tonic-gate 			} while (! iswblank(c) && c != '\t' &&
244648Sceastha 			    c != '\n' && c != '\0');
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 			*fr++ = 0;
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	} else if (*r != 0)	/* if 0, it's a null field */
2500Sstevel@tonic-gate 		for (;;) {
2510Sstevel@tonic-gate 			i++;
2520Sstevel@tonic-gate 			if (i >= MAXFLD)
2530Sstevel@tonic-gate 				error(FATAL,
2540Sstevel@tonic-gate 			"record `%.20ws...' has too many fields", record);
2550Sstevel@tonic-gate 			if (!(fldtab[i].tval&FLD))
2560Sstevel@tonic-gate 				xfree(fldtab[i].sval);
2570Sstevel@tonic-gate 			fldtab[i].sval = fr;
2580Sstevel@tonic-gate 			fldtab[i].tval = FLD | STR;
2590Sstevel@tonic-gate 			while ((c = *r) != sep && c != '\n' && c != '\0')
2600Sstevel@tonic-gate 				/* \n always a separator */
2610Sstevel@tonic-gate 				*fr++ = *r++;
2620Sstevel@tonic-gate 			*fr++ = 0;
2630Sstevel@tonic-gate 			if (*r++ == 0)
2640Sstevel@tonic-gate 				break;
2650Sstevel@tonic-gate 		}
2660Sstevel@tonic-gate 	*fr = 0;
2670Sstevel@tonic-gate 	/* clean out junk from previous record */
2680Sstevel@tonic-gate 	for (p = maxmfld, q = &fldtab[i]; p > q; p--) {
2690Sstevel@tonic-gate 		if (!(p->tval&FLD))
2700Sstevel@tonic-gate 			xfree(p->sval);
2710Sstevel@tonic-gate 		p->tval = STR | FLD;
2720Sstevel@tonic-gate 		p->sval = L_NULL;
2730Sstevel@tonic-gate 	}
2740Sstevel@tonic-gate 	maxfld = i;
2750Sstevel@tonic-gate 	maxmfld = &fldtab[i];
2760Sstevel@tonic-gate 	donefld = 1;
2770Sstevel@tonic-gate 	for (i = 1; i <= maxfld; i++)
2780Sstevel@tonic-gate 		if (isanumber(fldtab[i].sval)) {
2790Sstevel@tonic-gate 			fldtab[i].fval = watof(fldtab[i].sval);
2800Sstevel@tonic-gate 			fldtab[i].tval |= NUM;
2810Sstevel@tonic-gate 		}
2820Sstevel@tonic-gate 	setfval(lookup(L_NF, symtab, 0), (awkfloat) maxfld);
2830Sstevel@tonic-gate 	if (dbg)
2840Sstevel@tonic-gate 		for (i = 0; i <= maxfld; i++)
2850Sstevel@tonic-gate 			printf("field %d: |%ws|\n", i, fldtab[i].sval);
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 
289731Srobbin void
recbld(void)290731Srobbin recbld(void)
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate 	int i;
293648Sceastha 	wchar_t *r, *p;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	if (donefld == 0 || donerec == 1)
2970Sstevel@tonic-gate 		return;
2980Sstevel@tonic-gate 	r = record;
2990Sstevel@tonic-gate 	for (i = 1; i <= *NF; i++) {
3000Sstevel@tonic-gate 		p = getsval(&fldtab[i]);
3010Sstevel@tonic-gate 		while (*r++ = *p++)
3020Sstevel@tonic-gate 			;
3030Sstevel@tonic-gate 		*(r-1) = **OFS;
3040Sstevel@tonic-gate 	}
3050Sstevel@tonic-gate 	*(r-1) = '\0';
3060Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
3070Sstevel@tonic-gate 	recloc->tval = STR | FLD;
3080Sstevel@tonic-gate 	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
3090Sstevel@tonic-gate 	if (r > record+RECSIZE)
3100Sstevel@tonic-gate 		error(FATAL, "built giant record `%.20ws...'", record);
3110Sstevel@tonic-gate 	dprintf("recbld = |%ws|\n", record, NULL, NULL);
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate CELL *
fieldadr(n)3160Sstevel@tonic-gate fieldadr(n)
3170Sstevel@tonic-gate {
3180Sstevel@tonic-gate 	if (n < 0 || n >= MAXFLD)
3190Sstevel@tonic-gate 		error(FATAL, "trying to access field %d", n);
3200Sstevel@tonic-gate 	return (&fldtab[n]);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate int	errorflag	= 0;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 
327731Srobbin int
yyerror(char * s)3280Sstevel@tonic-gate yyerror(char *s)
3290Sstevel@tonic-gate {
3300Sstevel@tonic-gate 	fprintf(stderr,
331648Sceastha 	    gettext("awk: %s near line %lld\n"), gettext(s), lineno);
3320Sstevel@tonic-gate 	errorflag = 2;
333731Srobbin 	return (0);
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 
337731Srobbin void
error(f,s,a1,a2,a3,a4,a5,a6,a7)3380Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7)
3390Sstevel@tonic-gate {
3400Sstevel@tonic-gate 	fprintf(stderr, "awk: ");
3410Sstevel@tonic-gate 	fprintf(stderr, gettext((char *)s), a1, a2, a3, a4, a5, a6, a7);
3420Sstevel@tonic-gate 	fprintf(stderr, "\n");
3430Sstevel@tonic-gate 	if (NR && *NR > 0)
3440Sstevel@tonic-gate 		fprintf(stderr, gettext(" record number %g\n"), *NR);
3450Sstevel@tonic-gate 	if (f)
3460Sstevel@tonic-gate 		exit(2);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 
350731Srobbin void
PUTS(char * s)351731Srobbin PUTS(char *s)
352731Srobbin {
3530Sstevel@tonic-gate 	dprintf("%s\n", s, NULL, NULL);
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate #define	MAXEXPON	38	/* maximum exponenet for fp number */
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 
360731Srobbin int
isanumber(wchar_t * s)361731Srobbin isanumber(wchar_t *s)
3620Sstevel@tonic-gate {
363648Sceastha 	int d1, d2;
3640Sstevel@tonic-gate 	int point;
3650Sstevel@tonic-gate 	wchar_t *es;
3660Sstevel@tonic-gate 	extern wchar_t	radixpoint;
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	d1 = d2 = point = 0;
3690Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
3700Sstevel@tonic-gate 		s++;
3710Sstevel@tonic-gate 	if (*s == '\0')
3720Sstevel@tonic-gate 		return (0);	/* empty stuff isn't number */
3730Sstevel@tonic-gate 	if (*s == '+' || *s == '-')
3740Sstevel@tonic-gate 		s++;
3750Sstevel@tonic-gate 	/*
3760Sstevel@tonic-gate 	 * Since, iswdigit() will include digit from other than code set 0,
3770Sstevel@tonic-gate 	 * we have to check it from code set 0 or not.
3780Sstevel@tonic-gate 	 */
3790Sstevel@tonic-gate 	if (!(iswdigit(*s) && iswascii(*s)) && *s != radixpoint)
3800Sstevel@tonic-gate 		return (0);
3810Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
3820Sstevel@tonic-gate 		do {
3830Sstevel@tonic-gate 			d1++;
3840Sstevel@tonic-gate 			s++;
3850Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
3860Sstevel@tonic-gate 	}
3870Sstevel@tonic-gate 	if (d1 >= MAXEXPON)
3880Sstevel@tonic-gate 		return (0);	/* too many digits to convert */
3890Sstevel@tonic-gate 	if (*s == radixpoint) {
3900Sstevel@tonic-gate 		point++;
3910Sstevel@tonic-gate 		s++;
3920Sstevel@tonic-gate 	}
3930Sstevel@tonic-gate 	if (iswdigit(*s) && iswascii(*s)) {
3940Sstevel@tonic-gate 		d2++;
3950Sstevel@tonic-gate 		do {
3960Sstevel@tonic-gate 			s++;
3970Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
3980Sstevel@tonic-gate 	}
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	if (!(d1 || point && d2))
4020Sstevel@tonic-gate 		return (0);
4030Sstevel@tonic-gate 	if (*s == 'e' || *s == 'E') {
4040Sstevel@tonic-gate 		s++;
4050Sstevel@tonic-gate 		if (*s == '+' || *s == '-')
4060Sstevel@tonic-gate 			s++;
4070Sstevel@tonic-gate 		if (!(iswdigit(*s) && iswascii(*s)))
4080Sstevel@tonic-gate 			return (0);
4090Sstevel@tonic-gate 		es = s;
4100Sstevel@tonic-gate 		do {
4110Sstevel@tonic-gate 			s++;
4120Sstevel@tonic-gate 		} while (iswdigit(*s) && iswascii(*s));
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate 		if (s - es > 2)
4160Sstevel@tonic-gate 			return (0);
4170Sstevel@tonic-gate 		else if (s - es == 2 &&
418*1212Sceastha 		    10 * (*es-'0') + *(es+1)-'0' >= MAXEXPON)
4190Sstevel@tonic-gate 			return (0);
4200Sstevel@tonic-gate 	}
4210Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
4220Sstevel@tonic-gate 		s++;
4230Sstevel@tonic-gate 	if (*s == '\0')
4240Sstevel@tonic-gate 		return (1);
4250Sstevel@tonic-gate 	else
4260Sstevel@tonic-gate 		return (0);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate char *
toeuccode(str)4290Sstevel@tonic-gate toeuccode(str)
4300Sstevel@tonic-gate wchar_t *str;
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate 	static char euccode[RECSIZE];
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	(void) wcstombs(euccode, str, RECSIZE);
4350Sstevel@tonic-gate 	return (euccode);
4360Sstevel@tonic-gate }
437