17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22cb4658fbSceastha /* 23*baaf2753Sceastha * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24cb4658fbSceastha * Use is subject to license terms. 25cb4658fbSceastha */ 26cb4658fbSceastha 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <stdio.h> 337c478bd9Sstevel@tonic-gate #include "awk.def" 347c478bd9Sstevel@tonic-gate #include "awk.h" 357c478bd9Sstevel@tonic-gate #include <ctype.h> 367c478bd9Sstevel@tonic-gate #include <wctype.h> 377c478bd9Sstevel@tonic-gate #include "awktype.h" 387c478bd9Sstevel@tonic-gate #include <stdlib.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate FILE *infile = NULL; 417c478bd9Sstevel@tonic-gate wchar_t *file; 427c478bd9Sstevel@tonic-gate #define RECSIZE (5 * 512) 437c478bd9Sstevel@tonic-gate wchar_t record[RECSIZE]; 447c478bd9Sstevel@tonic-gate wchar_t fields[RECSIZE]; 457c478bd9Sstevel@tonic-gate wchar_t L_NULL[] = L""; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #define MAXFLD 100 497c478bd9Sstevel@tonic-gate int donefld; /* 1 = implies rec broken into fields */ 507c478bd9Sstevel@tonic-gate int donerec; /* 1 = record is valid (no flds have changed) */ 517c478bd9Sstevel@tonic-gate int mustfld; /* 1 = NF seen, so always break */ 527c478bd9Sstevel@tonic-gate static wchar_t L_record[] = L"$record"; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define FINIT { OCELL, CFLD, 0, L_NULL, 0.0, FLD|STR } 567c478bd9Sstevel@tonic-gate CELL fldtab[MAXFLD] = { /* room for fields */ 577c478bd9Sstevel@tonic-gate { OCELL, CFLD, L_record, record, 0.0, STR|FLD}, 587c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 597c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 607c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 617c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 627c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 637c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 647c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 657c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 667c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, 677c478bd9Sstevel@tonic-gate FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT 687c478bd9Sstevel@tonic-gate }; 697c478bd9Sstevel@tonic-gate int maxfld = 0; /* last used field */ 707c478bd9Sstevel@tonic-gate /* pointer to CELL for maximum field assigned to */ 717c478bd9Sstevel@tonic-gate CELL *maxmfld = &fldtab[0]; 727c478bd9Sstevel@tonic-gate 73cb4658fbSceastha static int isclvar(wchar_t *); 74dc5a8425Srobbin static void setclvar(wchar_t *); 75dc5a8425Srobbin void fldbld(void); 767c478bd9Sstevel@tonic-gate 77dc5a8425Srobbin int 78dc5a8425Srobbin getrec(void) 797c478bd9Sstevel@tonic-gate { 80cb4658fbSceastha wchar_t *rr, *er; 81cb4658fbSceastha int c, sep; 82cb4658fbSceastha FILE *inf; 837c478bd9Sstevel@tonic-gate extern int svargc; 847c478bd9Sstevel@tonic-gate extern wchar_t **svargv; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL); 887c478bd9Sstevel@tonic-gate donefld = 0; 897c478bd9Sstevel@tonic-gate donerec = 1; 907c478bd9Sstevel@tonic-gate record[0] = 0; 917c478bd9Sstevel@tonic-gate er = record + RECSIZE; 927c478bd9Sstevel@tonic-gate while (svargc > 0) { 937c478bd9Sstevel@tonic-gate dprintf("svargc=%d, *svargv=%ws\n", svargc, *svargv, NULL); 947c478bd9Sstevel@tonic-gate if (infile == NULL) { /* have to open a new file */ 95cb4658fbSceastha /* 96cb4658fbSceastha * If the argument contains a '=', determine if the 97cb4658fbSceastha * argument needs to be treated as a variable assignment 98cb4658fbSceastha * or as the pathname of a file. 99cb4658fbSceastha */ 100cb4658fbSceastha if (isclvar(*svargv)) { 1017c478bd9Sstevel@tonic-gate /* it's a var=value argument */ 1027c478bd9Sstevel@tonic-gate setclvar(*svargv); 1037c478bd9Sstevel@tonic-gate if (svargc > 1) { 1047c478bd9Sstevel@tonic-gate svargv++; 1057c478bd9Sstevel@tonic-gate svargc--; 1067c478bd9Sstevel@tonic-gate continue; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate *svargv = L"-"; 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate *FILENAME = file = *svargv; 1117c478bd9Sstevel@tonic-gate dprintf("opening file %ws\n", file, NULL, NULL); 1127c478bd9Sstevel@tonic-gate if (*file == (wchar_t)L'-') 1137c478bd9Sstevel@tonic-gate infile = stdin; 1147c478bd9Sstevel@tonic-gate else if ((infile = fopen(toeuccode(file), "r")) == NULL) 1157c478bd9Sstevel@tonic-gate error(FATAL, "can't open %ws", file); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate if ((sep = **RS) == 0) 1187c478bd9Sstevel@tonic-gate sep = '\n'; 1197c478bd9Sstevel@tonic-gate inf = infile; 1207c478bd9Sstevel@tonic-gate for (rr = record; /* dummy */; /* dummy */) { 1217c478bd9Sstevel@tonic-gate for (; (c = getwc(inf)) != sep && c != EOF && rr < er; 1227c478bd9Sstevel@tonic-gate *rr++ = c) 1237c478bd9Sstevel@tonic-gate ; 1247c478bd9Sstevel@tonic-gate if (rr >= er) 1257c478bd9Sstevel@tonic-gate error(FATAL, "record `%.20ws...' too long", 1267c478bd9Sstevel@tonic-gate record); 1277c478bd9Sstevel@tonic-gate if (**RS == sep || c == EOF) 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate if ((c = getwc(inf)) == '\n' || c == EOF) 1307c478bd9Sstevel@tonic-gate /* 2 in a row */ 1317c478bd9Sstevel@tonic-gate break; 1327c478bd9Sstevel@tonic-gate *rr++ = '\n'; 1337c478bd9Sstevel@tonic-gate *rr++ = c; 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate if (rr >= er) 1367c478bd9Sstevel@tonic-gate error(FATAL, "record `%.20ws...' too long", record); 1377c478bd9Sstevel@tonic-gate *rr = 0; 1387c478bd9Sstevel@tonic-gate if (mustfld) 1397c478bd9Sstevel@tonic-gate fldbld(); 1407c478bd9Sstevel@tonic-gate if (c != EOF || rr > record) { /* normal record */ 1417c478bd9Sstevel@tonic-gate recloc->tval &= ~NUM; 1427c478bd9Sstevel@tonic-gate recloc->tval |= STR; 1437c478bd9Sstevel@tonic-gate ++nrloc->fval; 1447c478bd9Sstevel@tonic-gate nrloc->tval &= ~STR; 1457c478bd9Sstevel@tonic-gate nrloc->tval |= NUM; 1467c478bd9Sstevel@tonic-gate return (1); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate /* EOF arrived on this file; set up next */ 1497c478bd9Sstevel@tonic-gate if (infile != stdin) 1507c478bd9Sstevel@tonic-gate fclose(infile); 1517c478bd9Sstevel@tonic-gate infile = NULL; 1527c478bd9Sstevel@tonic-gate svargc--; 1537c478bd9Sstevel@tonic-gate svargv++; 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate return (0); /* true end of file */ 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate 158cb4658fbSceastha /* 159cb4658fbSceastha * isclvar() 160cb4658fbSceastha * 161cb4658fbSceastha * Returns 1 if the input string, arg, is a variable assignment, 162cb4658fbSceastha * otherwise returns 0. 163cb4658fbSceastha * 164cb4658fbSceastha * An argument to awk can be either a pathname of a file, or a variable 165cb4658fbSceastha * assignment. An operand that begins with an undersore or alphabetic 166cb4658fbSceastha * character from the portable character set, followed by a sequence of 167cb4658fbSceastha * underscores, digits, and alphabetics from the portable character set, 168cb4658fbSceastha * followed by the '=' character, shall specify a variable assignment 169cb4658fbSceastha * rather than a pathname. 170cb4658fbSceastha */ 171cb4658fbSceastha static int 172cb4658fbSceastha isclvar(wchar_t *arg) 173cb4658fbSceastha { 174cb4658fbSceastha wchar_t *tmpptr = arg; 175cb4658fbSceastha 176cb4658fbSceastha if (tmpptr != NULL) { 177cb4658fbSceastha 178cb4658fbSceastha /* Begins with an underscore or alphabetic character */ 179cb4658fbSceastha if (iswalpha(*tmpptr) || *tmpptr == '_') { 180cb4658fbSceastha 181cb4658fbSceastha /* 182cb4658fbSceastha * followed by a sequence of underscores, digits, 183cb4658fbSceastha * and alphabetics 184cb4658fbSceastha */ 185cb4658fbSceastha for (tmpptr++; *tmpptr; tmpptr++) { 186*baaf2753Sceastha if (!(iswalnum(*tmpptr) || (*tmpptr == '_'))) { 187cb4658fbSceastha break; 188cb4658fbSceastha } 189cb4658fbSceastha } 190cb4658fbSceastha return (*tmpptr == '='); 191cb4658fbSceastha } 192cb4658fbSceastha } 193cb4658fbSceastha 194cb4658fbSceastha return (0); 195cb4658fbSceastha } 1967c478bd9Sstevel@tonic-gate 197dc5a8425Srobbin static void 198dc5a8425Srobbin setclvar(wchar_t *s) /* set var=value from s */ 1997c478bd9Sstevel@tonic-gate { 2007c478bd9Sstevel@tonic-gate wchar_t *p; 2017c478bd9Sstevel@tonic-gate CELL *q; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate for (p = s; *p != '='; p++) 2057c478bd9Sstevel@tonic-gate ; 2067c478bd9Sstevel@tonic-gate *p++ = 0; 2077c478bd9Sstevel@tonic-gate q = setsymtab(s, tostring(p), 0.0, STR, symtab); 2087c478bd9Sstevel@tonic-gate setsval(q, p); 2097c478bd9Sstevel@tonic-gate dprintf("command line set %ws to |%ws|\n", s, p, NULL); 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate 213dc5a8425Srobbin void 214dc5a8425Srobbin fldbld(void) 2157c478bd9Sstevel@tonic-gate { 216cb4658fbSceastha wchar_t *r, *fr, sep, c; 2177c478bd9Sstevel@tonic-gate static wchar_t L_NF[] = L"NF"; 2187c478bd9Sstevel@tonic-gate CELL *p, *q; 2197c478bd9Sstevel@tonic-gate int i, j; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate r = record; 2237c478bd9Sstevel@tonic-gate fr = fields; 2247c478bd9Sstevel@tonic-gate i = 0; /* number of fields accumulated here */ 2257c478bd9Sstevel@tonic-gate if ((sep = **FS) == ' ') 2267c478bd9Sstevel@tonic-gate for (i = 0; /* dummy */; /* dummy */) { 2277c478bd9Sstevel@tonic-gate c = *r; 2287c478bd9Sstevel@tonic-gate while (iswblank(c) || c == '\t' || c == '\n') 2297c478bd9Sstevel@tonic-gate c = *(++r); 2307c478bd9Sstevel@tonic-gate if (*r == 0) 2317c478bd9Sstevel@tonic-gate break; 2327c478bd9Sstevel@tonic-gate i++; 2337c478bd9Sstevel@tonic-gate if (i >= MAXFLD) 2347c478bd9Sstevel@tonic-gate error(FATAL, 2357c478bd9Sstevel@tonic-gate "record `%.20ws...' has too many fields", record); 2367c478bd9Sstevel@tonic-gate if (!(fldtab[i].tval&FLD)) 2377c478bd9Sstevel@tonic-gate xfree(fldtab[i].sval); 2387c478bd9Sstevel@tonic-gate fldtab[i].sval = fr; 2397c478bd9Sstevel@tonic-gate fldtab[i].tval = FLD | STR; 2407c478bd9Sstevel@tonic-gate do { 2417c478bd9Sstevel@tonic-gate *fr++ = *r++; 2427c478bd9Sstevel@tonic-gate c = *r; 2437c478bd9Sstevel@tonic-gate } while (! iswblank(c) && c != '\t' && 2447c478bd9Sstevel@tonic-gate c != '\n' && c != '\0'); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate *fr++ = 0; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate } else if (*r != 0) /* if 0, it's a null field */ 2507c478bd9Sstevel@tonic-gate for (;;) { 2517c478bd9Sstevel@tonic-gate i++; 2527c478bd9Sstevel@tonic-gate if (i >= MAXFLD) 2537c478bd9Sstevel@tonic-gate error(FATAL, 2547c478bd9Sstevel@tonic-gate "record `%.20ws...' has too many fields", record); 2557c478bd9Sstevel@tonic-gate if (!(fldtab[i].tval&FLD)) 2567c478bd9Sstevel@tonic-gate xfree(fldtab[i].sval); 2577c478bd9Sstevel@tonic-gate fldtab[i].sval = fr; 2587c478bd9Sstevel@tonic-gate fldtab[i].tval = FLD | STR; 2597c478bd9Sstevel@tonic-gate while ((c = *r) != sep && c != '\n' && c != '\0') 2607c478bd9Sstevel@tonic-gate /* \n always a separator */ 2617c478bd9Sstevel@tonic-gate *fr++ = *r++; 2627c478bd9Sstevel@tonic-gate *fr++ = 0; 2637c478bd9Sstevel@tonic-gate if (*r++ == 0) 2647c478bd9Sstevel@tonic-gate break; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate *fr = 0; 2677c478bd9Sstevel@tonic-gate /* clean out junk from previous record */ 2687c478bd9Sstevel@tonic-gate for (p = maxmfld, q = &fldtab[i]; p > q; p--) { 2697c478bd9Sstevel@tonic-gate if (!(p->tval&FLD)) 2707c478bd9Sstevel@tonic-gate xfree(p->sval); 2717c478bd9Sstevel@tonic-gate p->tval = STR | FLD; 2727c478bd9Sstevel@tonic-gate p->sval = L_NULL; 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate maxfld = i; 2757c478bd9Sstevel@tonic-gate maxmfld = &fldtab[i]; 2767c478bd9Sstevel@tonic-gate donefld = 1; 2777c478bd9Sstevel@tonic-gate for (i = 1; i <= maxfld; i++) 2787c478bd9Sstevel@tonic-gate if (isanumber(fldtab[i].sval)) { 2797c478bd9Sstevel@tonic-gate fldtab[i].fval = watof(fldtab[i].sval); 2807c478bd9Sstevel@tonic-gate fldtab[i].tval |= NUM; 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate setfval(lookup(L_NF, symtab, 0), (awkfloat) maxfld); 2837c478bd9Sstevel@tonic-gate if (dbg) 2847c478bd9Sstevel@tonic-gate for (i = 0; i <= maxfld; i++) 2857c478bd9Sstevel@tonic-gate printf("field %d: |%ws|\n", i, fldtab[i].sval); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate 289dc5a8425Srobbin void 290dc5a8425Srobbin recbld(void) 2917c478bd9Sstevel@tonic-gate { 2927c478bd9Sstevel@tonic-gate int i; 293cb4658fbSceastha wchar_t *r, *p; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate if (donefld == 0 || donerec == 1) 2977c478bd9Sstevel@tonic-gate return; 2987c478bd9Sstevel@tonic-gate r = record; 2997c478bd9Sstevel@tonic-gate for (i = 1; i <= *NF; i++) { 3007c478bd9Sstevel@tonic-gate p = getsval(&fldtab[i]); 3017c478bd9Sstevel@tonic-gate while (*r++ = *p++) 3027c478bd9Sstevel@tonic-gate ; 3037c478bd9Sstevel@tonic-gate *(r-1) = **OFS; 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate *(r-1) = '\0'; 3067c478bd9Sstevel@tonic-gate dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL); 3077c478bd9Sstevel@tonic-gate recloc->tval = STR | FLD; 3087c478bd9Sstevel@tonic-gate dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL); 3097c478bd9Sstevel@tonic-gate if (r > record+RECSIZE) 3107c478bd9Sstevel@tonic-gate error(FATAL, "built giant record `%.20ws...'", record); 3117c478bd9Sstevel@tonic-gate dprintf("recbld = |%ws|\n", record, NULL, NULL); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate CELL * 3167c478bd9Sstevel@tonic-gate fieldadr(n) 3177c478bd9Sstevel@tonic-gate { 3187c478bd9Sstevel@tonic-gate if (n < 0 || n >= MAXFLD) 3197c478bd9Sstevel@tonic-gate error(FATAL, "trying to access field %d", n); 3207c478bd9Sstevel@tonic-gate return (&fldtab[n]); 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate int errorflag = 0; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate 327dc5a8425Srobbin int 3287c478bd9Sstevel@tonic-gate yyerror(char *s) 3297c478bd9Sstevel@tonic-gate { 3307c478bd9Sstevel@tonic-gate fprintf(stderr, 3317c478bd9Sstevel@tonic-gate gettext("awk: %s near line %lld\n"), gettext(s), lineno); 3327c478bd9Sstevel@tonic-gate errorflag = 2; 333dc5a8425Srobbin return (0); 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate 337dc5a8425Srobbin void 3387c478bd9Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7) 3397c478bd9Sstevel@tonic-gate { 3407c478bd9Sstevel@tonic-gate fprintf(stderr, "awk: "); 3417c478bd9Sstevel@tonic-gate fprintf(stderr, gettext((char *)s), a1, a2, a3, a4, a5, a6, a7); 3427c478bd9Sstevel@tonic-gate fprintf(stderr, "\n"); 3437c478bd9Sstevel@tonic-gate if (NR && *NR > 0) 3447c478bd9Sstevel@tonic-gate fprintf(stderr, gettext(" record number %g\n"), *NR); 3457c478bd9Sstevel@tonic-gate if (f) 3467c478bd9Sstevel@tonic-gate exit(2); 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate 350dc5a8425Srobbin void 351dc5a8425Srobbin PUTS(char *s) 352dc5a8425Srobbin { 3537c478bd9Sstevel@tonic-gate dprintf("%s\n", s, NULL, NULL); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate #define MAXEXPON 38 /* maximum exponenet for fp number */ 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate 360dc5a8425Srobbin int 361dc5a8425Srobbin isanumber(wchar_t *s) 3627c478bd9Sstevel@tonic-gate { 363cb4658fbSceastha int d1, d2; 3647c478bd9Sstevel@tonic-gate int point; 3657c478bd9Sstevel@tonic-gate wchar_t *es; 3667c478bd9Sstevel@tonic-gate extern wchar_t radixpoint; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate d1 = d2 = point = 0; 3697c478bd9Sstevel@tonic-gate while (*s == ' ' || *s == '\t' || *s == '\n') 3707c478bd9Sstevel@tonic-gate s++; 3717c478bd9Sstevel@tonic-gate if (*s == '\0') 3727c478bd9Sstevel@tonic-gate return (0); /* empty stuff isn't number */ 3737c478bd9Sstevel@tonic-gate if (*s == '+' || *s == '-') 3747c478bd9Sstevel@tonic-gate s++; 3757c478bd9Sstevel@tonic-gate /* 3767c478bd9Sstevel@tonic-gate * Since, iswdigit() will include digit from other than code set 0, 3777c478bd9Sstevel@tonic-gate * we have to check it from code set 0 or not. 3787c478bd9Sstevel@tonic-gate */ 3797c478bd9Sstevel@tonic-gate if (!(iswdigit(*s) && iswascii(*s)) && *s != radixpoint) 3807c478bd9Sstevel@tonic-gate return (0); 3817c478bd9Sstevel@tonic-gate if (iswdigit(*s) && iswascii(*s)) { 3827c478bd9Sstevel@tonic-gate do { 3837c478bd9Sstevel@tonic-gate d1++; 3847c478bd9Sstevel@tonic-gate s++; 3857c478bd9Sstevel@tonic-gate } while (iswdigit(*s) && iswascii(*s)); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate if (d1 >= MAXEXPON) 3887c478bd9Sstevel@tonic-gate return (0); /* too many digits to convert */ 3897c478bd9Sstevel@tonic-gate if (*s == radixpoint) { 3907c478bd9Sstevel@tonic-gate point++; 3917c478bd9Sstevel@tonic-gate s++; 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate if (iswdigit(*s) && iswascii(*s)) { 3947c478bd9Sstevel@tonic-gate d2++; 3957c478bd9Sstevel@tonic-gate do { 3967c478bd9Sstevel@tonic-gate s++; 3977c478bd9Sstevel@tonic-gate } while (iswdigit(*s) && iswascii(*s)); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate if (!(d1 || point && d2)) 4027c478bd9Sstevel@tonic-gate return (0); 4037c478bd9Sstevel@tonic-gate if (*s == 'e' || *s == 'E') { 4047c478bd9Sstevel@tonic-gate s++; 4057c478bd9Sstevel@tonic-gate if (*s == '+' || *s == '-') 4067c478bd9Sstevel@tonic-gate s++; 4077c478bd9Sstevel@tonic-gate if (!(iswdigit(*s) && iswascii(*s))) 4087c478bd9Sstevel@tonic-gate return (0); 4097c478bd9Sstevel@tonic-gate es = s; 4107c478bd9Sstevel@tonic-gate do { 4117c478bd9Sstevel@tonic-gate s++; 4127c478bd9Sstevel@tonic-gate } while (iswdigit(*s) && iswascii(*s)); 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate if (s - es > 2) 4167c478bd9Sstevel@tonic-gate return (0); 4177c478bd9Sstevel@tonic-gate else if (s - es == 2 && 4187c478bd9Sstevel@tonic-gate 10 * (*es-'0') + *(es+1)-'0' >= MAXEXPON) 4197c478bd9Sstevel@tonic-gate return (0); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate while (*s == ' ' || *s == '\t' || *s == '\n') 4227c478bd9Sstevel@tonic-gate s++; 4237c478bd9Sstevel@tonic-gate if (*s == '\0') 4247c478bd9Sstevel@tonic-gate return (1); 4257c478bd9Sstevel@tonic-gate else 4267c478bd9Sstevel@tonic-gate return (0); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate char * 4297c478bd9Sstevel@tonic-gate toeuccode(str) 4307c478bd9Sstevel@tonic-gate wchar_t *str; 4317c478bd9Sstevel@tonic-gate { 4327c478bd9Sstevel@tonic-gate static char euccode[RECSIZE]; 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate (void) wcstombs(euccode, str, RECSIZE); 4357c478bd9Sstevel@tonic-gate return (euccode); 4367c478bd9Sstevel@tonic-gate } 437