lib.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1996-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.13 */
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include "awk.h"
#include "y.tab.h"
#define getfval(p) \
#define getsval(p) \
int donefld; /* 1 = implies rec broken into fields */
int donerec; /* 1 = record is valid (no flds have changed) */
int maxfld = 0; /* last used field */
{
int i;
uchar *p;
for (i = 1; i < *ARGC; i++) {
return;
setclvar(p); /* a commandline assignment before filename */
argno++;
}
/* *FILENAME = file = (uchar*) "-"; */
}
{
int c;
static int firsttime = 1;
if (firsttime) {
firsttime = 0;
initgetrec();
}
dprintf(("RS=<%s>, FS=<%s>, ARGC=%f, FILENAME=%s\n",
donefld = 0;
donerec = 1;
buf[0] = 0;
argno++;
continue;
}
argno++;
continue;
}
}
}
}
return (1);
}
/* EOF arrived on this file; set up next */
argno++;
}
return (0); /* true end of file */
}
int bufsize;
{
register int sep, c;
int count;
sep = '\n';
/* skip leading \n's */
;
if (c != EOF)
}
count++;
ERROR "input record `%.20s...' too long",
*rr++ = c;
}
break;
break;
count += 2;
*rr++ = '\n';
*rr++ = c;
}
*rr = 0;
dprintf(("readrec saw <%s>, returns %d\n",
}
/* get ARGV[n] */
uchar *
getargv(n)
int n;
{
Cell *x;
s = getsval(x);
dprintf(("getargv(%d) returns |%s|\n", n, s));
return (s);
}
setclvar(s) /* set var=value from s */
uchar *s;
{
uchar *p;
Cell *q;
for (p = s; *p != '='; p++)
;
*p++ = 0;
p = qstring(p, '\0');
setsval(q, p);
}
dprintf(("command line set %s to |%s|\n", s, p));
}
fldbld()
{
Cell *p;
int i;
if (donefld)
return;
i = 0; /* number of fields accumulated here */
for (i = 0; ; ) {
while (*r == ' ' || *r == '\t' || *r == '\n')
r++;
if (*r == 0)
break;
i++;
if (i >= MAXFLD)
break;
do
*fr++ = *r++;
while (*r != ' ' && *r != '\t' && *r != '\n' &&
*r != '\0');
*fr++ = 0;
}
*fr = 0;
} else if (*r != 0) { /* if 0, it's a null field */
for (;;) {
i++;
if (i >= MAXFLD)
break;
/* \n always a separator */
*fr++ = *r++;
*fr++ = 0;
if (*r++ == 0)
break;
}
*fr = 0;
}
if (i >= MAXFLD)
/* clean out junk from previous record */
maxfld = i;
donefld = 1;
}
}
if (dbg)
}
{
register Cell *p, *q;
}
}
newfld(n) /* add field n (after end) */
{
if (n >= MAXFLD)
maxfld = n;
}
{
int i, tempstat;
*fr = '\0';
if (*rec == '\0')
return (0);
for (i = 1; i < MAXFLD; i++) {
dprintf(("refldbld: i=%d\n", i));
} else {
break;
}
}
return (i);
}
recbld()
{
int i;
register uchar *r, *p;
if (donerec == 1)
return;
r = rec;
for (i = 1; i <= *NF; i++) {
r++;
if (i < *NF)
r++;
}
*r = '\0';
donerec = 1;
}
Cell *
fieldadr(n)
{
if (n < 0 || n >= MAXFLD)
return (&fldtab[n]);
}
int errorflag = 0;
char errbuf[200];
yyerror(s)
uchar *s;
{
static int been_here = 0;
if (been_here++ > 2)
return;
errorflag = 2;
eprint();
}
fpecatch()
{
}
{
int c;
static int beenhere = 0;
if (beenhere++)
return;
bclass(c);
}
{
if (n == 1)
else if (n > 1)
else if (n == -1)
else if (n < -1)
}
error(f, s)
int f;
char *s;
{
}
eprint();
if (f) {
if (dbg)
abort();
exit(2);
}
}
eprint() /* try to print context around error */
{
uchar *p, *q;
int c;
static int been_here = 0;
return;
p = ep - 1;
if (p > ebuf && *p == '\n')
p--;
;
while (*p == '\n')
p++;
q--)
;
for (; p < q; p++)
if (*p)
for (; p < ep; p++)
if (*p)
if (*ep)
bclass(c);
}
}
bclass(c)
{
switch (c) {
case '{': bracecnt++; break;
case '}': bracecnt--; break;
case '[': brackcnt++; break;
case ']': brackcnt--; break;
case '(': parencnt++; break;
case ')': parencnt--; break;
}
}
double
errcheck(x, s)
double x;
uchar *s;
{
extern int errno;
errno = 0;
x = 1;
errno = 0;
x = 1;
}
return (x);
}
dprintf(("%s\n", s));
}
isclvar(s) /* is s of form var=something? */
char *s;
{
char *os = s;
for (; *s; s++)
if (!(isalnum(*s) || *s == '_'))
break;
}
isnumber(s)
register uchar *s;
{
int point;
extern char radixpoint;
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
if (*s == '\0')
return (0); /* empty stuff isn't number */
if (*s == '+' || *s == '-')
s++;
if (!isdigit(*s) && *s != radixpoint)
return (0);
if (isdigit(*s)) {
do {
d1++;
s++;
} while (isdigit(*s));
}
return (0); /* too many digits to convert */
if (*s == radixpoint) {
point++;
s++;
}
if (isdigit(*s)) {
d2++;
do {
s++;
} while (isdigit(*s));
}
return (0);
if (*s == 'e' || *s == 'E') {
s++;
if (*s == '+' || *s == '-')
s++;
if (!isdigit(*s))
return (0);
es = s;
do {
s++;
} while (isdigit(*s));
if (s - es > 2)
return (0);
else if (s - es == 2 &&
return (0);
}
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
if (*s == '\0')
return (1);
else
return (0);
}