lib.c revision cb4658fbb85e4290093c4fea0eb396a7d98de1fb
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include "awk.def"
#include "awk.h"
#include <ctype.h>
#include <wctype.h>
#include "awktype.h"
#include <stdlib.h>
#define MAXFLD 100
int donefld; /* 1 = implies rec broken into fields */
int donerec; /* 1 = record is valid (no flds have changed) */
int mustfld; /* 1 = NF seen, so always break */
};
int maxfld = 0; /* last used field */
/* pointer to CELL for maximum field assigned to */
getrec()
{
int c, sep;
extern int svargc;
donefld = 0;
donerec = 1;
record[0] = 0;
while (svargc > 0) {
/*
* If the argument contains a '=', determine if the
* argument needs to be treated as a variable assignment
* or as the pathname of a file.
*/
/* it's a var=value argument */
if (svargc > 1) {
svargv++;
svargc--;
continue;
}
*svargv = L"-";
}
}
sep = '\n';
*rr++ = c)
;
record);
break;
/* 2 in a row */
break;
*rr++ = '\n';
*rr++ = c;
}
*rr = 0;
if (mustfld)
fldbld();
return (1);
}
/* EOF arrived on this file; set up next */
svargc--;
svargv++;
}
return (0); /* true end of file */
}
/*
* isclvar()
*
* Returns 1 if the input string, arg, is a variable assignment,
* otherwise returns 0.
*
* An argument to awk can be either a pathname of a file, or a variable
* assignment. An operand that begins with an undersore or alphabetic
* character from the portable character set, followed by a sequence of
* underscores, digits, and alphabetics from the portable character set,
* followed by the '=' character, shall specify a variable assignment
* rather than a pathname.
*/
static int
{
/* Begins with an underscore or alphabetic character */
/*
* followed by a sequence of underscores, digits,
* and alphabetics
*/
break;
}
}
return (*tmpptr == '=');
}
}
return (0);
}
setclvar(s) /* set var=value from s */
wchar_t *s;
{
wchar_t *p;
CELL *q;
for (p = s; *p != '='; p++)
;
*p++ = 0;
setsval(q, p);
}
fldbld()
{
CELL *p, *q;
int i, j;
r = record;
i = 0; /* number of fields accumulated here */
for (i = 0; /* dummy */; /* dummy */) {
c = *r;
c = *(++r);
if (*r == 0)
break;
i++;
if (i >= MAXFLD)
"record `%.20ws...' has too many fields", record);
do {
*fr++ = *r++;
c = *r;
} while (! iswblank(c) && c != '\t' &&
c != '\n' && c != '\0');
*fr++ = 0;
} else if (*r != 0) /* if 0, it's a null field */
for (;;) {
i++;
if (i >= MAXFLD)
"record `%.20ws...' has too many fields", record);
/* \n always a separator */
*fr++ = *r++;
*fr++ = 0;
if (*r++ == 0)
break;
}
*fr = 0;
/* clean out junk from previous record */
}
maxfld = i;
donefld = 1;
for (i = 1; i <= maxfld; i++)
}
if (dbg)
for (i = 0; i <= maxfld; i++)
}
recbld()
{
int i;
wchar_t *r, *p;
return;
r = record;
for (i = 1; i <= *NF; i++) {
while (*r++ = *p++)
;
*(r-1) = **OFS;
}
*(r-1) = '\0';
}
CELL *
fieldadr(n)
{
if (n < 0 || n >= MAXFLD)
return (&fldtab[n]);
}
int errorflag = 0;
yyerror(char *s)
{
errorflag = 2;
}
{
if (f)
exit(2);
}
PUTS(s) char *s; {
}
isanumber(s)
wchar_t *s;
{
int point;
extern wchar_t radixpoint;
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
if (*s == '\0')
return (0); /* empty stuff isn't number */
if (*s == '+' || *s == '-')
s++;
/*
* Since, iswdigit() will include digit from other than code set 0,
* we have to check it from code set 0 or not.
*/
return (0);
do {
d1++;
s++;
}
return (0); /* too many digits to convert */
if (*s == radixpoint) {
point++;
s++;
}
d2++;
do {
s++;
}
return (0);
if (*s == 'e' || *s == 'E') {
s++;
if (*s == '+' || *s == '-')
s++;
return (0);
es = s;
do {
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);
}
char *
{
return (euccode);
}