summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/awk_xpg4/awk.h107
-rw-r--r--usr/src/cmd/awk_xpg4/awk1.c184
-rw-r--r--usr/src/cmd/awk_xpg4/awk2.c9
-rw-r--r--usr/src/cmd/awk_xpg4/awk3.c286
4 files changed, 367 insertions, 219 deletions
diff --git a/usr/src/cmd/awk_xpg4/awk.h b/usr/src/cmd/awk_xpg4/awk.h
index 5f71bc0821..91e07c884c 100644
--- a/usr/src/cmd/awk_xpg4/awk.h
+++ b/usr/src/cmd/awk_xpg4/awk.h
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -60,15 +59,15 @@
#define NPFILE 32 /* Number of -[fl] options allowed */
#define NRECUR 3000 /* Maximum recursion depth */
-#define M_LDATA 1
+#define M_LDATA 1
#ifdef M_LDATA
-# define NLINE 20000 /* Longest input record */
-# define NFIELD 4000 /* Number of fields allowed */
-# define NBUCKET 1024 /* # of symtab buckets (power of 2) */
+#define NLINE 20000 /* Longest input record */
+#define NFIELD 4000 /* Number of fields allowed */
+#define NBUCKET 1024 /* # of symtab buckets (power of 2) */
#else
-# define NLINE 2048 /* Longest input record */
-# define NFIELD 1024 /* Number of fields allowed */
-# define NBUCKET 256 /* # of symtab buckets (power of 2) */
+#define NLINE 2048 /* Longest input record */
+#define NFIELD 1024 /* Number of fields allowed */
+#define NBUCKET 256 /* # of symtab buckets (power of 2) */
#endif
#define NSNODE 40 /* Number of cached nodes */
@@ -81,10 +80,10 @@
* return a value.
*/
int bcmp();
-#define memcmp(b1,b2,n) bcmp(b1,b2,n)
+#define memcmp(b1, b2, n) bcmp(b1, b2, n)
void bcopy();
-#define memcpy(b1,b2,n) bcopy(b2,b1,(int)n)
-#endif /*BSD*/
+#define memcpy(b1, b2, n) bcopy(b2, b1, (int)n)
+#endif /* BSD */
#define vlook(n) vlookup(n, 0)
/*
@@ -93,24 +92,24 @@ void bcopy();
typedef double REAL;
typedef long long INT;
typedef wchar_t *STRING;
-typedef struct NODE *(*FUNCTION)(struct NODE * np);
-typedef regex_t *REGEXP;
+typedef struct NODE *(*FUNCTION)(struct NODE *np);
+typedef void *REGEXP;
/*
* Node in the AWK interpreter expression tree.
*/
typedef struct NODE {
- ushort n_type;
+ ushort_t n_type;
struct NODE *n_next; /* Symbol table/PARM link */
- ushort n_flags; /* Node flags, type */
+ ushort_t n_flags; /* Node flags, type */
union {
struct {
- ushort N_hash; /* Full hash value */
- struct NODE *N_alink; /* Array link */
+ ushort_t N_hash; /* Full hash value */
+ struct NODE *N_alink; /* Array link */
union {
struct {
STRING N_string;
@@ -126,7 +125,7 @@ typedef struct NODE {
struct {
struct NODE *N_left;
struct NODE *N_right;
- ushort N_lineno;
+ ushort_t N_lineno;
} n_op;
struct {
struct NODE *N_left; /* Used for fliplist */
@@ -184,7 +183,7 @@ typedef struct NODE {
#define FNONTOK 0x200 /* Node has non-token type */
#define FVINT 0x400 /* Node looks like an integer */
#define FVREAL 0x800 /* Node looks like a real number */
-#define FLARRAY 0x1000 /* Local array node */
+#define FLARRAY 0x1000 /* Local array node */
/*
* n_flags macros
@@ -192,7 +191,7 @@ typedef struct NODE {
*/
#define isleaf(f) (!((f)&FNONTOK))
#define isstring(f) ((f)&FSTRING)
-#define isastring(f) (((f)&(FSTRING|FALLOC))==(FSTRING|FALLOC))
+#define isastring(f) (((f)&(FSTRING|FALLOC)) == (FSTRING|FALLOC))
#define isnumber(f) ((f)&(FINT|FVINT|FREAL|FVREAL))
#define isreal(f) ((f)&(FREAL|FVREAL))
#define isint(f) ((f)&(FINT|FVINT))
@@ -209,19 +208,19 @@ typedef struct NODE {
* Awkrun prototype default name
*/
#if defined(DOS)
-# if defined(__386__)
-# define AWK_PROTOTYPE M_ETCDIR(awkrunf.dos)
-# define AWK_LPROTOTYPE M_ETCDIR(awkrunf.dos)
-# else
-# define AWK_PROTOTYPE M_ETCDIR(awkrun.dos)
-# define AWK_LPROTOTYPE M_ETCDIR(awkrunl.dos)
-# endif
+#if defined(__386__)
+#define AWK_PROTOTYPE M_ETCDIR(awkrunf.dos)
+#define AWK_LPROTOTYPE M_ETCDIR(awkrunf.dos)
+#else
+#define AWK_PROTOTYPE M_ETCDIR(awkrun.dos)
+#define AWK_LPROTOTYPE M_ETCDIR(awkrunl.dos)
+#endif
#elif defined(OS2)
-# define AWK_PROTOTYPE M_ETCDIR(awkrun.os2)
+#define AWK_PROTOTYPE M_ETCDIR(awkrun.os2)
#elif defined(NT)
-# define AWK_PROTOTYPE M_ETCDIR(awkrun.nt)
+#define AWK_PROTOTYPE M_ETCDIR(awkrun.nt)
#else
-# define AWK_PROTOTYPE M_ETCDIR(awkrun.mod)
+#define AWK_PROTOTYPE M_ETCDIR(awkrun.mod)
#endif
/*
@@ -261,7 +260,7 @@ typedef struct RESFUNC {
* Structure holding list of open files.
*/
typedef struct OFILE {
- ushort f_mode; /* Open mode: WRITE, APPEND, PIPE */
+ ushort_t f_mode; /* Open mode: WRITE, APPEND, PIPE */
FILE *f_fp; /* File pointer if open */
char *f_name; /* Remembered file name */
} OFILE;
@@ -271,9 +270,9 @@ int yyparse(void);
/* Global functions -- awk1.c */
#ifdef __WATCOMC__
-# pragma aux yyerror aborts;
-# pragma aux awkerr aborts;
-# pragma aux awkperr aborts;
+#pragma aux yyerror aborts;
+#pragma aux awkerr aborts;
+#pragma aux awkperr aborts;
#endif
void yyerror(char *msg, ...);
void awkerr(char *fmt, ...);
@@ -400,8 +399,8 @@ extern uchar_t catterm;
extern uint_t lexlast;
extern uint_t lineno;
extern uchar_t needsplit, needenviron, doing_begin, begin_getline;
-extern ushort slevel;
-extern ushort loopexit;
+extern ushort_t slevel;
+extern ushort_t loopexit;
extern wchar_t radixpoint;
extern REGEXP resep;
extern RESERVED reserved[];
@@ -456,24 +455,22 @@ extern void awkerr(char *, ...);
* number of chars needed to hold the number.
*/
#ifdef M_NUMSIZE
-#define NUMSIZE M_NUMSIZE
+#define NUMSIZE M_NUMSIZE
#else
-#define NUMSIZE 30
+#define NUMSIZE 30
#endif
-#define M_MB_L(s) L##s
+#define M_MB_L(s) L##s
#ifdef __STDC__
-#define ANSI(x) x
-#define _VOID void /* Used in VOID *malloc() */
+#define ANSI(x) x
#else
-#define const
-#define signed
-#define volatile
-#define ANSI(x) ()
-#define _VOID char /* Used in _VOID *malloc() */
+#define const
+#define signed
+#define volatile
+#define ANSI(x) ()
#endif
-#define isWblank(x) (((x) == ' ' || (x) == '\t') ? 1 : 0 )
+#define isWblank(x) (((x) == ' ' || (x) == '\t') ? 1 : 0)
/*
@@ -482,6 +479,8 @@ extern void awkerr(char *, ...);
#define REGWMATCH_T int_regwmatch_t
#define REGWCOMP int_regwcomp
#define REGWEXEC int_regwexec
+#define REGWFREE int_regwfree
+#define REGWERROR int_regwerror
#define REGWDOSUBA int_regwdosuba
typedef struct {
@@ -489,8 +488,10 @@ typedef struct {
regoff_t rm_so, rm_eo;
} int_regwmatch_t;
-extern int int_regwcomp(regex_t *, const wchar_t *, int);
-extern int int_regwexec(const regex_t *, const wchar_t *, size_t,
+extern int int_regwcomp(REGEXP *, const wchar_t *);
+extern int int_regwexec(REGEXP, const wchar_t *, size_t,
int_regwmatch_t *, int);
-extern int int_regwdosuba(regex_t *, const wchar_t *,
+extern void int_regwfree(REGEXP);
+extern size_t int_regwerror(int, REGEXP, char *, size_t);
+extern int int_regwdosuba(REGEXP, const wchar_t *,
const wchar_t *, wchar_t **, int, int *);
diff --git a/usr/src/cmd/awk_xpg4/awk1.c b/usr/src/cmd/awk_xpg4/awk1.c
index e9407c2cea..c9d5df6478 100644
--- a/usr/src/cmd/awk_xpg4/awk1.c
+++ b/usr/src/cmd/awk_xpg4/awk1.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -41,6 +40,7 @@
#include <stdarg.h>
#include <unistd.h>
#include <locale.h>
+#include <search.h>
static char *progfiles[NPFILE]; /* Programmes files for yylex */
static char **progfilep = &progfiles[0]; /* Pointer to last file */
@@ -556,6 +556,7 @@ yyhex()
c = ';';
break;
}
+ /*FALLTHRU*/
case AND:
case OR:
case COMMA:
@@ -689,6 +690,7 @@ yyhex()
if (!catterm || lexlast != CONSTANT || wasfield)
break;
+ /*FALLTHRU*/
case UFUNC:
case FUNC:
case GETLINE:
@@ -705,8 +707,10 @@ yyhex()
/* { */ case '}':
if (nbrace == 0)
savetoken = ';';
+ /*FALLTHRU*/
case ';':
inprint = 0;
+ /*FALLTHRU*/
default:
if (c == DEFFUNC)
isfuncdef = 1;
@@ -834,6 +838,7 @@ do_funparm:
needsplit = 1;
} else if (np == varENVIRON)
needenviron = 1;
+ /*FALLTHRU*/
case PARM:
return (VAR);
@@ -842,6 +847,7 @@ do_funparm:
* It is ok to redefine functions as parameters
*/
if (funparm) goto do_funparm;
+ /*FALLTHRU*/
case FUNC:
case GETLINE:
/*
@@ -1058,14 +1064,13 @@ renode(wchar_t *s)
np = emptynode(RE, 0);
np->n_left = np->n_right = NNULL;
- np->n_regexp = (REGEXP)emalloc(sizeof (regex_t));
- if ((n = REGWCOMP(np->n_regexp, s, REG_EXTENDED)) != REG_OK) {
+ if ((n = REGWCOMP(&np->n_regexp, s)) != REG_OK) {
int m;
char *p;
- m = regerror(n, np->n_regexp, NULL, 0);
+ m = REGWERROR(n, np->n_regexp, NULL, 0);
p = (char *)emalloc(m);
- regerror(n, np->n_regexp, p, m);
+ REGWERROR(n, np->n_regexp, p, m);
awkerr("/%S/: %s", s, p);
}
return (np);
@@ -1303,7 +1308,7 @@ char *s;
if ((w = (wchar_t *)malloc(n * sizeof (wchar_t))) == NULL)
return (NULL);
- if (mbstowcs(w, s, n) == -1)
+ if (mbstowcs(w, s, n) == (size_t)-1)
return (NULL);
return (w);
@@ -1409,24 +1414,158 @@ wcoff(const wchar_t *astring, const int off)
return (s - astring);
}
+#define NREGHASH 64
+#define NREGHOLD 1024 /* max number unused entries */
+
+static int nregunref;
+
+struct reghashq {
+ struct qelem hq;
+ struct regcache *regcachep;
+};
+
+struct regcache {
+ struct qelem lq;
+ wchar_t *pattern;
+ regex_t re;
+ int refcnt;
+ struct reghashq hash;
+};
+
+static struct qelem reghash[NREGHASH], reglink;
+
+/*
+ * Generate a hash value of the given wchar string.
+ * The hashing method is similar to what Java does for strings.
+ */
+static uint_t
+regtxthash(const wchar_t *str)
+{
+ int k = 0;
+
+ while (*str != L'\0')
+ k = (31 * k) + *str++;
+
+ k += ~(k << 9);
+ k ^= (k >> 14);
+ k += (k << 4);
+ k ^= (k >> 10);
+
+ return (k % NREGHASH);
+}
+
int
-int_regwcomp(regex_t *r, const wchar_t *pattern, int uflags)
+int_regwcomp(REGEXP *r, const wchar_t *pattern)
{
+ regex_t re;
char *mbpattern;
int ret;
+ uint_t key;
+ struct qelem *qp;
+ struct regcache *rcp;
+
+ key = regtxthash(pattern);
+ for (qp = reghash[key].q_forw; qp != NULL; qp = qp->q_forw) {
+ rcp = ((struct reghashq *)qp)->regcachep;
+ if (*rcp->pattern == *pattern &&
+ wcscmp(rcp->pattern, pattern) == 0)
+ break;
+ }
+ if (qp != NULL) {
+ /* update link. put this one at the beginning */
+ if (rcp != (struct regcache *)reglink.q_forw) {
+ remque(&rcp->lq);
+ insque(&rcp->lq, &reglink);
+ }
+ if (rcp->refcnt == 0)
+ nregunref--; /* no longer unref'ed */
+ rcp->refcnt++;
+ *(struct regcache **)r = rcp;
+ return (REG_OK);
+ }
if ((mbpattern = wcstombsdup((wchar_t *)pattern)) == NULL)
return (REG_ESPACE);
- ret = regcomp(r, mbpattern, uflags);
+ ret = regcomp(&re, mbpattern, REG_EXTENDED);
free(mbpattern);
+ if (ret != REG_OK)
+ return (ret);
+
+ if ((rcp = malloc(sizeof (struct regcache))) == NULL)
+ return (REG_ESPACE);
+ rcp->re = re;
+ if ((rcp->pattern = wsdup(pattern)) == NULL) {
+ regfree(&re);
+ free(rcp);
+ return (REG_ESPACE);
+ }
+ rcp->refcnt = 1;
+ insque(&rcp->lq, &reglink);
+ insque(&rcp->hash.hq, &reghash[key]);
+ rcp->hash.regcachep = rcp;
+
+ *(struct regcache **)r = rcp;
return (ret);
}
+void
+int_regwfree(REGEXP r)
+{
+ int cnt;
+ struct qelem *qp, *nqp;
+ struct regcache *rcp;
+
+ rcp = (struct regcache *)r;
+
+ if (--rcp->refcnt != 0)
+ return;
+
+ /* this cache has no reference */
+ if (++nregunref < NREGHOLD)
+ return;
+
+ /*
+ * We've got too much unref'ed regex. Free half of least
+ * used regex.
+ */
+ cnt = 0;
+ for (qp = reglink.q_forw; qp != NULL; qp = nqp) {
+ nqp = qp->q_forw;
+ rcp = (struct regcache *)qp;
+ if (rcp->refcnt != 0)
+ continue;
+
+ /* free half of them */
+ if (++cnt < (NREGHOLD / 2))
+ continue;
+
+ /* detach and free */
+ remque(&rcp->lq);
+ remque(&rcp->hash.hq);
+
+ /* free up */
+ free(rcp->pattern);
+ regfree(&rcp->re);
+ free(rcp);
+
+ nregunref--;
+ }
+}
+
+size_t
+int_regwerror(int errcode, REGEXP r, char *errbuf, size_t bufsiz)
+{
+ struct regcache *rcp;
+
+ rcp = (struct regcache *)r;
+ return (regerror(errcode, &rcp->re, errbuf, bufsiz));
+}
+
int
-int_regwexec(const regex_t *r, /* compiled RE */
+int_regwexec(REGEXP r, /* compiled RE */
const wchar_t *astring, /* subject string */
size_t nsub, /* number of subexpressions */
int_regwmatch_t *sub, /* subexpression pointers */
@@ -1435,6 +1574,7 @@ int_regwexec(const regex_t *r, /* compiled RE */
char *mbs;
regmatch_t *mbsub = NULL;
int i;
+ struct regcache *rcp;
if ((mbs = wcstombsdup((wchar_t *)astring)) == NULL)
return (REG_ESPACE);
@@ -1444,7 +1584,9 @@ int_regwexec(const regex_t *r, /* compiled RE */
return (REG_ESPACE);
}
- i = regexec(r, mbs, nsub, mbsub, flags);
+ rcp = (struct regcache *)r;
+
+ i = regexec(&rcp->re, mbs, nsub, mbsub, flags);
/* Now, adjust the pointers/counts in sub */
if (i == REG_OK && nsub > 0 && mbsub) {
@@ -1472,7 +1614,7 @@ int_regwexec(const regex_t *r, /* compiled RE */
}
int
-int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
+int_regwdosuba(REGEXP rp, /* compiled RE: Pattern */
const wchar_t *rpl, /* replacement string: /rpl/ */
const wchar_t *src, /* source string */
wchar_t **dstp, /* destination string */
@@ -1494,7 +1636,7 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
/* handle overflow of dst. we need "i" more bytes */
#ifdef OVERFLOW
#undef OVERFLOW
-#define OVERFLOW(i) if (1) { \
+#define OVERFLOW(i) { \
int pos = op - dst; \
dst = (wchar_t *)realloc(odst = dst, \
(len += len + i) * sizeof (wchar_t)); \
@@ -1502,7 +1644,7 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
goto nospace; \
op = dst + pos; \
end = dst + len; \
- } else
+ }
#endif
*dstp = dst = (wchar_t *)malloc(len * sizeof (wchar_t));
@@ -1521,7 +1663,7 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
while ((regerr = int_regwexec(rp, ip, NSUB, rm, flags)) == REG_OK) {
/* Copy text preceding match */
if (op + (i = rm[0].rm_sp - ip) >= end)
- OVERFLOW(i);
+ OVERFLOW(i)
while (i--)
*op++ = *ip++;
@@ -1546,11 +1688,11 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
if (rmp == NULL) { /* Ordinary character. */
*op++ = c;
if (op >= end)
- OVERFLOW(1);
+ OVERFLOW(1)
} else if (rmp->rm_sp != NULL && rmp->rm_ep != NULL) {
ip = rmp->rm_sp;
if (op + (i = rmp->rm_ep - rmp->rm_sp) >= end)
- OVERFLOW(i);
+ OVERFLOW(i)
while (i--)
*op++ = *ip++;
}
@@ -1563,7 +1705,7 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
/* If empty match copy next char */
*op++ = *ip++;
if (op >= end)
- OVERFLOW(1);
+ OVERFLOW(1)
}
flags = REG_NOTBOL;
}
@@ -1573,7 +1715,7 @@ int_regwdosuba(regex_t *rp, /* compiled RE: Pattern */
/* Copy rest of text */
if (op + (i = wcslen(ip)) >= end)
- OVERFLOW(i);
+ OVERFLOW(i)
while (i--)
*op++ = *ip++;
*op++ = '\0';
diff --git a/usr/src/cmd/awk_xpg4/awk2.c b/usr/src/cmd/awk_xpg4/awk2.c
index 805755534e..ebf353af72 100644
--- a/usr/src/cmd/awk_xpg4/awk2.c
+++ b/usr/src/cmd/awk_xpg4/awk2.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -389,7 +388,7 @@ again:
*endpp = wcschr(cp, '\0');
break;
default:
- (void) regerror(result, resep, (char *)linebuf,
+ (void) REGWERROR(result, resep, (char *)linebuf,
sizeof (linebuf));
awkerr(gettext("error splitting record: %s"),
(char *)linebuf);
diff --git a/usr/src/cmd/awk_xpg4/awk3.c b/usr/src/cmd/awk_xpg4/awk3.c
index f980c2b8dd..584a54e561 100644
--- a/usr/src/cmd/awk_xpg4/awk3.c
+++ b/usr/src/cmd/awk_xpg4/awk3.c
@@ -2,9 +2,8 @@
* 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.
+ * Common Development and Distribution License (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
* or http://www.opensolaris.org/os/licensing.
@@ -22,7 +21,7 @@
/*
* awk -- executor
*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 1985, 1994 by Mortice Kern Systems Inc. All rights reserved.
@@ -75,12 +74,12 @@ static int exprtest(NODE *np);
/*
* These are portable to two's complement integer machines
*/
-#define addoverflow() if ((i1^i2)>=0 && (iresult^i1)<0) goto overflow
-#define suboverflow() if ((i1^i2)<0 && (iresult^i2)>=0) goto overflow
+#define addoverflow() if ((i1^i2) >= 0 && (iresult^i1) < 0) goto overflow
+#define suboverflow() if ((i1^i2) < 0 && (iresult^i2) >= 0) goto overflow
#endif
-#define muloverflow() if (((short)i1!=i1 || (short)i2!=i2) \
- && ((i2!=0 && iresult/i2!=i1) \
- || (i1==LONG_MIN && i2==-1))) goto overflow
+#define muloverflow() if (((short)i1 != i1 || (short)i2 != i2) && \
+ ((i2 != 0 && iresult/i2 != i1) || \
+ (i1 == LONG_MIN && i2 == -1))) goto overflow
static char notarray[] = "scalar \"%s\" cannot be used as array";
static char badarray[] = "array \"%s\" cannot be used as a scalar";
@@ -105,7 +104,7 @@ static NODE *retval; /* Last return value of a function */
* for-in loops. This needs to be global so that delete can check to see
* if it is deleting the next node to be used by a loop.
*/
-#define NFORINLOOP 10
+#define NFORINLOOP 10
static NODE* forindex[NFORINLOOP];
static NODE** next_forin = forindex;
@@ -123,14 +122,14 @@ strassign(NODE *np, STRING string, int flags, size_t length)
else if (np->n_type == GETLINE || np->n_type == KEYWORD)
awkerr(gettext("inadmissible use of reserved keyword"));
if (np->n_flags & FSPECIAL) {
- (void)nassign(np, stringnode(string, flags, length));
+ (void) nassign(np, stringnode(string, flags, length));
return;
}
if (isastring(np->n_flags))
free((wchar_t *)np->n_string);
np->n_strlen = length++;
if (flags & FALLOC) {
- length *= sizeof(wchar_t);
+ length *= sizeof (wchar_t);
np->n_string = (STRING) emalloc(length);
(void) memcpy((void *)np->n_string, string, length);
} else {
@@ -168,7 +167,7 @@ nassign(NODE *np, NODE *value)
if (np == varRS || np == varFS) {
if (isastring(np->n_flags))
free((void *)np->n_string);
- len = sizeof(wchar_t) * ((np->n_strlen =
+ len = sizeof (wchar_t) * ((np->n_strlen =
wcslen(cp = exprstring(value)))+1);
np->n_string = emalloc(len);
(void) memcpy((wchar_t *)np->n_string, cp, len);
@@ -182,7 +181,7 @@ nassign(NODE *np, NODE *value)
awkrecord = charrecord;
} else if (np == varFS) {
if (resep != (REGEXP)NULL) {
- regfree(resep);
+ REGWFREE(resep);
resep = (REGEXP)NULL;
}
if (wcslen((wchar_t *)np->n_string) > 1)
@@ -199,8 +198,8 @@ nassign(NODE *np, NODE *value)
free((wchar_t *)np->n_string);
if (isstring(value->n_flags)) {
np->n_strlen = value->n_strlen;
- if (value->n_flags&FALLOC || value->n_string!=_null) {
- len = (np->n_strlen+1) * sizeof(wchar_t);
+ if (value->n_flags&FALLOC || value->n_string != _null) {
+ len = (np->n_strlen+1) * sizeof (wchar_t);
np->n_string = emalloc(len);
(void) memcpy(np->n_string, value->n_string, len);
np->n_flags &= FSAVE;
@@ -224,15 +223,15 @@ nassign(NODE *np, NODE *value)
static void
setrefield(NODE *np)
{
- static regex_t re;
+ static REGEXP re;
int n;
- if ((n = REGWCOMP(&re, np->n_string, REG_EXTENDED)) != REG_OK) {
- regerror(n, &re, (char *)linebuf, sizeof(linebuf));
+ if ((n = REGWCOMP(&re, np->n_string)) != REG_OK) {
+ REGWERROR(n, &re, (char *)linebuf, sizeof (linebuf));
awkerr(gettext("syntax error \"%s\" in /%s/\n"),
(char *)linebuf, np->n_string);
}
- resep = &re;
+ resep = re;
awkfield = refield;
}
@@ -251,6 +250,7 @@ top:
switch (left->n_type) {
case INDEX:
left = exprreduce(left);
+ /*FALLTHRU*/
case VAR:
return (nassign(left, right));
@@ -331,7 +331,7 @@ stringnode(STRING s, int how, size_t length)
np = emptynode(CONSTANT, 0);
np->n_strlen = length;
if (how & FALLOC) {
- np->n_string = emalloc(length = (length+1) * sizeof(wchar_t));
+ np->n_string = emalloc(length = (length+1) * sizeof (wchar_t));
(void) memcpy(np->n_string, s, length);
} else {
np->n_string = s;
@@ -358,7 +358,7 @@ strsave(wchar_t *old)
STRING new;
register size_t len;
- new = (STRING)emalloc(len = (wcslen(old)+1) * sizeof(wchar_t));
+ new = (STRING)emalloc(len = (wcslen(old)+1) * sizeof (wchar_t));
(void) memcpy(new, old, len);
return (new);
}
@@ -372,11 +372,12 @@ emptynode(int type, size_t length)
{
register NODE *np;
- if (length==0 && running && fnodep < &nodes[NSNODE]) {
+ if (length == 0 && running && fnodep < &nodes[NSNODE]) {
np = fnodep++;
} else {
- np = (NODE *) emalloc(sizeof(NODE)+(length * sizeof(wchar_t)));
- if (running && type!=VAR && type!=ARRAY) {
+ np = (NODE *)emalloc(sizeof (NODE) +
+ (length * sizeof (wchar_t)));
+ if (running && type != VAR && type != ARRAY) {
np->n_next = freelist;
freelist = np;
}
@@ -397,8 +398,7 @@ freenode(NODE *np)
if (isastring(np->n_flags))
free((wchar_t *)np->n_string);
else if (np->n_type == RE) {
- regfree(np->n_regexp);
- free((wchar_t *)np->n_regexp);
+ REGWFREE(np->n_regexp);
}
free((wchar_t *)np);
}
@@ -415,7 +415,7 @@ kinstall(LOCCHARP name, int type)
l = wcslen(name);
np = emptynode(KEYWORD, l);
np->n_keywtype = type;
- (void) memcpy(np->n_name, name, (l+1) * sizeof(wchar_t));
+ (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t));
addsymtab(np);
}
@@ -431,9 +431,9 @@ finstall(LOCCHARP name, FUNCTION func, int type)
l = wcslen(name);
np = emptynode(type, l);
np->n_function = func;
- (void) memcpy(np->n_name, name, (l+1) * sizeof(wchar_t));
+ (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t));
addsymtab(np);
- return np;
+ return (np);
}
/*
@@ -445,12 +445,12 @@ finstall(LOCCHARP name, FUNCTION func, int type)
NODE *
vlookup(wchar_t *name, int nocreate)
{
- register ushort hash;
+ register ushort_t hash;
register NODE *np;
- np = symtab[hashbuck(hash = dohash((wchar_t*)name))];
+ np = symtab[hashbuck(hash = dohash((wchar_t *)name))];
while (np != NNULL) {
- if (np->n_hash==hash && wcscmp(name, np->n_name)==0)
+ if (np->n_hash == hash && wcscmp(name, np->n_name) == 0)
return (np);
np = np->n_next;
}
@@ -462,7 +462,7 @@ vlookup(wchar_t *name, int nocreate)
np->n_strlen = 0;
np->n_string = _null;
(void) memcpy(np->n_name, name,
- (hash+1) * sizeof(wchar_t));
+ (hash+1) * sizeof (wchar_t));
addsymtab(np);
}
return (np);
@@ -495,7 +495,7 @@ delsymtab(NODE *np, int fflag)
register NODE *rnp;
register NODE *prevp;
register NODE **sptr;
- register ushort h;
+ register ushort_t h;
@@ -588,7 +588,7 @@ execute(NODE *wp)
} else if (phase != 0) {
if (np->n_type != phase)
continue;
- } else if ((type = np->n_type)==BEGIN || type==END) {
+ } else if ((type = np->n_type) == BEGIN || type == END) {
continue;
} else if (type == COMMA) {
/*
@@ -630,8 +630,7 @@ freetemps()
if (isastring(np->n_flags)) {
free((wchar_t *)np->n_string);
} else if (np->n_type == RE) {
- regfree(np->n_regexp);
- free((wchar_t *)np->n_regexp);
+ REGWFREE(np->n_regexp);
}
}
fnodep = &nodes[0];
@@ -671,41 +670,42 @@ action(NODE *wp)
*/
switch (np->n_type) {
case ASG:
- (void)assign(np->n_left, np->n_right);
+ (void) assign(np->n_left, np->n_right);
continue;
case PRINT:
s_print(np);
continue;
-
+
case PRINTF:
s_prf(np);
continue;
-
+
case EXIT:
if (np->n_left != NNULL)
act = (int)exprint(np->n_left); else
act = 0;
doend(act);
/* NOTREACHED */
-
+
case RETURN:
if (slevel == 0)
awkerr(gettext("return outside of a function"));
- np = np->n_left!=NNULL
+ np = np->n_left != NNULL
? exprreduce(np->n_left)
: const0;
retval = emptynode(CONSTANT, 0);
retval->n_flags = FINT;
- (void)nassign(retval, np);
+ (void) nassign(retval, np);
return (RETURN);
case NEXT:
loopexit = NEXT;
+ /*FALLTHRU*/
case BREAK:
case CONTINUE:
return (np->n_type);
-
+
case DELETE:
if ((l = np->n_left)->n_type == PARM) {
l = l->n_next;
@@ -716,10 +716,10 @@ action(NODE *wp)
case ARRAY:
delarray(l);
break;
-
+
case INDEX:
if ((np = l->n_left)->n_type == PARM) {
- np = np->n_next;
+ np = np->n_next;
if (!(np->n_flags & FLARRAY))
np = np->n_alink;
}
@@ -743,9 +743,10 @@ action(NODE *wp)
}
delsymtab(l, 1);
break;
-
+
case VAR:
- if (isstring(l->n_flags) && l->n_string==_null)
+ if (isstring(l->n_flags) &&
+ l->n_string == _null)
break;
default:
awkerr(gettext(
@@ -753,30 +754,30 @@ action(NODE *wp)
break;
}
continue;
-
+
case WHILE:
case DO:
if ((act = s_while(np)) != 0)
break;
continue;
-
+
case FOR:
if ((act = s_for(np)) != 0)
break;
continue;
-
+
case FORIN:
if ((act = s_forin(np)) != 0)
break;
continue;
-
+
case IF:
if ((act = s_if(np)) != 0)
break;
continue;
default:
- (void)exprreduce(np);
+ (void) exprreduce(np);
if (loopexit != 0) {
act = loopexit;
break;
@@ -825,7 +826,7 @@ exprint(NODE *np)
return (np->n_int);
if (np->n_flags & FREAL)
return ((INT)np->n_real);
- return ((INT)watoll(np->n_string));
+ return ((INT)wcstoll(np->n_string, NULL, 10));
default:
awkerr(interr, "exprint");
@@ -841,7 +842,7 @@ REAL
exprreal(NODE *np)
{
if (loopexit)
- return (loopexit);
+ return ((REAL)loopexit);
if (isleaf(np->n_flags)) {
if (np->n_type == PARM)
np = np->n_next;
@@ -862,7 +863,7 @@ exprreal(NODE *np)
awkerr(interr, "exprreal");
}
/* NOTREACHED */
- return (0);
+ return ((REAL)0);
}
/*
@@ -889,9 +890,9 @@ exprstring(NODE *np)
char *tmp;
(void) wsprintf(numbuf,
(const char *) (tmp = wcstombsdup(exprstring(varCONVFMT))),
- (double) np->n_real);
+ (double)np->n_real);
if (tmp != NULL)
- free (tmp);
+ free(tmp);
}
return ((STRING)numbuf);
@@ -955,17 +956,17 @@ exprconcat(NODE *np, int len)
wchar_t *cp;
wchar_t rnumbuf[NUMSIZE];
- if (isleaf(rnp->n_flags) && rnp->n_type==PARM)
+ if (isleaf(rnp->n_flags) && rnp->n_type == PARM)
rnp = rnp->n_next;
if (isstring(rnp->n_flags)) {
rsp = rnp->n_string;
rlen = rnp->n_strlen;
} else
- rlen = wcslen((wchar_t*)(rsp = exprstring(rnp)));
+ rlen = wcslen((wchar_t *)(rsp = exprstring(rnp)));
if (rsp == numbuf) { /* static, so save a copy */
- (void) memcpy(rnumbuf, (wchar_t*)rsp,
- (rlen+1) * sizeof(wchar_t));
- rsp=rnumbuf;
+ (void) memcpy(rnumbuf, (wchar_t *)rsp,
+ (rlen+1) * sizeof (wchar_t));
+ rsp = rnumbuf;
}
len += rlen;
if (lnp->n_type == CONCAT) {
@@ -975,18 +976,18 @@ exprconcat(NODE *np, int len)
} else {
register STRING lsp;
- if (isleaf(lnp->n_flags) && lnp->n_type==PARM)
+ if (isleaf(lnp->n_flags) && lnp->n_type == PARM)
lnp = lnp->n_next;
if (isstring(lnp->n_flags)) {
lsp = lnp->n_string;
llen = lnp->n_strlen;
} else
- llen = wcslen((wchar_t*)(lsp = exprstring(lnp)));
- cp = emalloc((llen+len+1) * sizeof(wchar_t));
- (void) memcpy(cp, (wchar_t*)lsp, llen * sizeof(wchar_t));
+ llen = wcslen((wchar_t *)(lsp = exprstring(lnp)));
+ cp = emalloc((llen+len+1) * sizeof (wchar_t));
+ (void) memcpy(cp, (wchar_t *)lsp, llen * sizeof (wchar_t));
lnp = stringnode(cp, FNOALLOC, llen);
}
- (void) memcpy(cp+llen, (wchar_t*)rsp, (rlen+1) * sizeof(wchar_t));
+ (void) memcpy(cp+llen, (wchar_t *)rsp, (rlen+1) * sizeof (wchar_t));
lnp->n_strlen += rlen;
return (lnp);
}
@@ -1009,7 +1010,7 @@ exprreduce(NODE *np)
* a var or constant is a leaf-node (no further reduction required)
* so return immediately.
*/
- if ((t = np->n_type)==VAR || t==CONSTANT)
+ if ((t = np->n_type) == VAR || t == CONSTANT)
return (np);
/*
* If it's a parameter then it is probably a leaf node but it
@@ -1049,7 +1050,7 @@ exprreduce(NODE *np)
aname = tnp->n_name;
}
if (tnp->n_type != ARRAY) {
- if (!isstring(tnp->n_flags) || tnp->n_string!=_null)
+ if (!isstring(tnp->n_flags) || tnp->n_string != _null)
awkerr(notarray, fname);
else {
/* promotion to array */
@@ -1067,7 +1068,7 @@ exprreduce(NODE *np)
}
}
if (tnp == varSYMTAB) {
- if (np==NNULL || np->n_type==COMMA)
+ if (np == NNULL || np->n_type == COMMA)
awkerr(gettext(
"SYMTAB must have exactly one index"));
np = vlook(exprstring(np));
@@ -1082,7 +1083,7 @@ exprreduce(NODE *np)
np->n_flags |= FINARRAY;
}
} else
- np = vlookup(cp, 1)==NNULL ? const0 : const1;
+ np = vlookup(cp, 1) == NNULL ? const0 : const1;
if (cp != indexbuf)
free(cp);
return (np);
@@ -1094,29 +1095,30 @@ exprreduce(NODE *np)
return (np);
case NOT:
- return (intnode(exprtest(np->n_left)==0 ? (INT)1 : (INT)0));
+ return (intnode(exprtest(np->n_left) == 0 ? (INT)1 : (INT)0));
case AND:
- return ((exprtest(np->n_left) != 0
- && exprtest(np->n_right) != 0) ? const1 : const0);
+ return ((exprtest(np->n_left) != 0 &&
+ exprtest(np->n_right) != 0) ? const1 : const0);
case OR:
- return ((exprtest(np->n_left) != 0
- || exprtest(np->n_right) != 0) ? const1 : const0);
+ return ((exprtest(np->n_left) != 0 ||
+ exprtest(np->n_right) != 0) ? const1 : const0);
case EXP:
{
- double f1, f2;
-
- /* evaluate expressions in proper order before
+ double f1, f2;
+
+ /*
+ * evaluate expressions in proper order before
* calling pow().
* Can't guarantee that compiler will do this
* correctly for us if we put them inline.
*/
- f1 = (double)exprreal(np->n_left);
- f2 = (double)exprreal(np->n_right);
- return (realnode((REAL)pow(f1, f2)));
- }
+ f1 = (double)exprreal(np->n_left);
+ f2 = (double)exprreal(np->n_right);
+ return (realnode((REAL)pow(f1, f2)));
+ }
case QUEST:
if (np->n_right->n_type != COLON)
@@ -1154,7 +1156,7 @@ do_inc_op:
else
tnp = intnode(exprint(np));
inc_oper->n_left = np;
- (void)assign(np, inc_oper);
+ (void) assign(np, inc_oper);
return (tnp);
case PRE_DEC:
@@ -1191,7 +1193,7 @@ do_asn_op:
np = exprreduce(np);
asn_oper->n_left = np;
return (assign(np, asn_oper));
-
+
case GETLINE:
return (f_getline(np));
@@ -1222,9 +1224,11 @@ do_asn_op:
case ARRAY:
awkerr(badarray, np->n_name);
+ /*FALLTHRU*/
case UFUNC:
awkerr(varnotfunc, np->n_name);
+ /*FALLTHRU*/
default:
awkerr(gettext("panic: exprreduce(%d)"), t);
/* NOTREACHED */
@@ -1245,16 +1249,16 @@ arithmetic(NODE *np)
register REAL r1, r2;
left = exprreduce(np->n_left);
- if (isreal(left->n_flags)
- || (isstring(left->n_flags) && (type_of(left)&FVREAL))) {
+ if (isreal(left->n_flags) ||
+ (isstring(left->n_flags) && (type_of(left)&FVREAL))) {
type = FREAL;
r1 = exprreal(left);
r2 = exprreal(np->n_right);
} else {
i1 = exprint(left);
right = exprreduce(np->n_right);
- if (isreal(right->n_flags)
- || (isstring(right->n_flags) && (type_of(right)&FVREAL))) {
+ if (isreal(right->n_flags) ||
+ (isstring(right->n_flags) && (type_of(right)&FVREAL))) {
type = FREAL;
r1 = i1;
@@ -1326,7 +1330,7 @@ reswitch:
}
break;
}
- return (type==FINT ? intnode(iresult) : realnode(r1));
+ return (type == FINT ? intnode(iresult) : realnode(r1));
}
/*
@@ -1423,22 +1427,22 @@ do_strcmp:
#endif
switch (np->n_type) {
case EQ:
- return (cmp==0 ? const1 : const0);
+ return (cmp == 0 ? const1 : const0);
case NE:
- return (cmp!=0 ? const1 : const0);
+ return (cmp != 0 ? const1 : const0);
case GE:
- return (cmp>=0 ? const1 : const0);
+ return (cmp >= 0 ? const1 : const0);
case LE:
- return (cmp<=0 ? const1 : const0);
+ return (cmp <= 0 ? const1 : const0);
case GT:
- return (cmp>0 ? const1 : const0);
+ return (cmp > 0 ? const1 : const0);
case LT:
- return (cmp<0 ? const1 : const0);
+ return (cmp < 0 ? const1 : const0);
default:
awkerr(interr, "comparison");
@@ -1467,7 +1471,7 @@ type_of(NODE *np)
return (FSTRING|FVINT);
while (iswspace(*cp))
cp++;
- if (*cp=='-' || *cp=='+')
+ if (*cp == '-' || *cp == '+')
cp++;
while (*cp != '\0') {
switch (*cp) {
@@ -1534,7 +1538,7 @@ rfield(INT fieldno)
return (stringnode(linebuf, FSTATIC|FSENSE, lbuflen));
if (!splitdone)
fieldsplit();
- if (fieldno>nfield || fieldno<0)
+ if (fieldno > nfield || fieldno < 0)
return (stringnode(_null, FSTATIC, 0));
cp = fields[fieldno-1];
return (stringnode(cp, FSTATIC|FSENSE, wcslen(cp)));
@@ -1552,7 +1556,7 @@ fieldsplit()
wchar_t *ep;
if (fieldbuf == NULL)
- fieldbuf = emalloc(NLINE * sizeof(wchar_t));
+ fieldbuf = emalloc(NLINE * sizeof (wchar_t));
fcount = 0;
ep = linebuf;
op = fieldbuf;
@@ -1561,7 +1565,7 @@ fieldsplit()
if (fcount > NFIELD)
awkerr(tmfld, NFIELD);
n = ep-ip;
- (void) memcpy(op, ip, n * sizeof(wchar_t));
+ (void) memcpy(op, ip, n * sizeof (wchar_t));
op += n;
*op++ = '\0';
}
@@ -1569,7 +1573,7 @@ fieldsplit()
varNF->n_int = fcount;
else {
constant->n_int = fcount;
- (void)nassign(varNF, constant);
+ (void) nassign(varNF, constant);
}
nfield = fcount;
splitdone++;
@@ -1594,22 +1598,22 @@ lfield(INT fieldno, NODE *np)
newlen = wcslen(newval = (wchar_t *)exprstring(np));
if (fieldno == 0) {
splitdone = 0;
- (void) memcpy(linebuf, newval, (newlen+1) * sizeof(wchar_t));
+ (void) memcpy(linebuf, newval, (newlen+1) * sizeof (wchar_t));
lbuflen = newlen;
fieldsplit();
} else {
seplen = wcslen(sep = (wchar_t *)exprstring(varOFS));
if (!splitdone)
fieldsplit();
- if (--fieldno < nfield
- && (newlen <= wcslen(fields[fieldno]))) {
+ if (--fieldno < nfield &&
+ (newlen <= wcslen(fields[fieldno]))) {
(void) memcpy(fields[fieldno], newval,
- (newlen+1) * sizeof(wchar_t));
+ (newlen+1) * sizeof (wchar_t));
} else {
register wchar_t *buf;
buf = fieldbuf;
- fieldbuf = emalloc(NLINE * sizeof(wchar_t));
+ fieldbuf = emalloc(NLINE * sizeof (wchar_t));
if (fieldno >= nfield) {
if (fieldno >= NFIELD)
awkerr(tmfld, NFIELD);
@@ -1619,12 +1623,13 @@ lfield(INT fieldno, NODE *np)
}
fields[fieldno] = newval;
op = fieldbuf;
- for (i=0; i<nfield; i++) {
+ for (i = 0; i < nfield; i++) {
newlen = wcslen(cp = fields[i])+1;
fields[i] = op;
if (op+newlen >= fieldbuf+NLINE)
awkerr(toolong, NLINE);
- (void) memcpy(op, cp, newlen * sizeof(wchar_t));
+ (void) memcpy(op, cp,
+ newlen * sizeof (wchar_t));
op += newlen;
}
free(buf);
@@ -1636,11 +1641,11 @@ lfield(INT fieldno, NODE *np)
i = 0;
while (i < nfield) {
newlen = wcslen(cp = fields[i++]);
- (void) memcpy(op, cp, newlen * sizeof(wchar_t));
+ (void) memcpy(op, cp, newlen * sizeof (wchar_t));
op += newlen;
if (i < nfield) {
- (void) memcpy(op, sep,
- seplen * sizeof(wchar_t));
+ (void) memcpy(op, sep,
+ seplen * sizeof (wchar_t));
op += seplen;
}
if (op >= &linebuf[NLINE])
@@ -1652,7 +1657,7 @@ lfield(INT fieldno, NODE *np)
varNF->n_int = nfield;
else {
constant->n_int = nfield;
- (void)nassign(varNF, constant);
+ (void) nassign(varNF, constant);
}
}
return (np);
@@ -1671,9 +1676,9 @@ userfunc(NODE *np)
register NODE *temp;
NODE *fnp;
- if ((fnp = np->n_left)==NNULL)
+ if ((fnp = np->n_left) == NNULL)
awkerr(gettext("impossible function call"));
- if (fnp->n_type!=UFUNC)
+ if (fnp->n_type != UFUNC)
awkerr(varnotfunc, fnp->n_name);
#ifndef M_STKCHK
@@ -1695,7 +1700,8 @@ userfunc(NODE *np)
templist = temptail = NNULL;
actlist = np->n_right;
formlist = fnp->n_left;
- /* pass through formal list, setting up a list
+ /*
+ * pass through formal list, setting up a list
* (on templist) containing temps for the values
* of the actuals.
* If the actual list runs out before the formal
@@ -1732,14 +1738,14 @@ userfunc(NODE *np)
t = VAR;
break;
}
- temp = emptynode(t, len=wcslen(formal->n_name));
- (void) memcpy(temp->n_name,formal->n_name,
- (len+1) * sizeof(wchar_t));
+ temp = emptynode(t, len = wcslen(formal->n_name));
+ (void) memcpy(temp->n_name, formal->n_name,
+ (len+1) * sizeof (wchar_t));
temp->n_flags = FSTRING|FVINT;
temp->n_string = _null;
temp->n_strlen = 0;
if (t == VAR)
- (void)assign(temp, actual);
+ (void) assign(temp, actual);
if (t != ARRAY)
temp->n_flags |= FLARRAY;
temp->n_scope = scope_tag;
@@ -1906,7 +1912,7 @@ s_for(NODE *np)
testnp = getlist(&listp);
incnp = getlist(&listp);
if (initnp != NNULL)
- (void)exprreduce(initnp);
+ (void) exprreduce(initnp);
for (;;) {
if (exprtest(testnp) == 0)
break;
@@ -1924,7 +1930,7 @@ s_for(NODE *np)
}
clabel:
if (incnp != NNULL)
- (void)exprreduce(incnp);
+ (void) exprreduce(incnp);
}
return (act);
}
@@ -1962,14 +1968,14 @@ s_forin(NODE *np)
np = NNULL;
nbuck = 0;
} else {
- /*l
+ /*
* At this point if the node is not actually an array
* check to see if it has already been established as
* a scalar. If it is a scalar then flag an error. If
* not then promote the object to an array type.
*/
if (np->n_type != ARRAY) {
- if (!isstring(np->n_flags) || np->n_string!=_null)
+ if (!isstring(np->n_flags) || np->n_string != _null)
awkerr(notarray, np->n_name);
else {
/* promotion to array */
@@ -2050,8 +2056,8 @@ symwalk(int *buckp, NODE **npp)
return (*npp = NNULL);
np = symtab[(*buckp)++];
}
- if (np->n_type == VAR
- && (!isstring(np->n_flags) || np->n_string!=_null)) {
+ if (np->n_type == VAR &&
+ (!isstring(np->n_flags) || np->n_string != _null)) {
*npp = np->n_next;
return (np);
}
@@ -2095,11 +2101,11 @@ exprtest(NODE *np)
static wchar_t *
makeindex(NODE *np, wchar_t *array, int tag)
{
- static wchar_t tags[sizeof(int)];
+ static wchar_t tags[sizeof (int)];
static wchar_t tag_chars[] = M_MB_L("0123456789ABCDEF");
register wchar_t *cp;
register NODE *index;
- register uint n;
+ register uint_t n;
register int len;
register wchar_t *indstr;
register wchar_t *sep;
@@ -2119,7 +2125,7 @@ makeindex(NODE *np, wchar_t *array, int tag)
wchar_t *ocp;
size_t i;
- if (isleaf(np->n_flags) && np->n_type==PARM)
+ if (isleaf(np->n_flags) && np->n_type == PARM)
np = np->n_next;
if (isstring(np->n_flags)) {
indstr = np->n_string;
@@ -2132,8 +2138,8 @@ makeindex(NODE *np, wchar_t *array, int tag)
if (i < NINDEXBUF)
ocp = indexbuf;
else
- ocp = emalloc(i * sizeof(wchar_t));
- (void) memcpy(ocp, array, n * sizeof(wchar_t));
+ ocp = emalloc(i * sizeof (wchar_t));
+ (void) memcpy(ocp, array, n * sizeof (wchar_t));
cp = ocp+n;
if (taglen) {
*cp++ = '[';
@@ -2141,7 +2147,7 @@ makeindex(NODE *np, wchar_t *array, int tag)
*cp++ = tags[--taglen];
}
*cp++ = ']';
- (void) memcpy(cp, indstr, (len+1) * sizeof(wchar_t));
+ (void) memcpy(cp, indstr, (len+1) * sizeof (wchar_t));
return (ocp);
}
@@ -2151,9 +2157,9 @@ makeindex(NODE *np, wchar_t *array, int tag)
indstr = exprstring(index);
len = wcslen(indstr);
if (n == 0) {
- cp = emalloc(sizeof(wchar_t) * ((n = wcslen(array)) +
+ cp = emalloc(sizeof (wchar_t) * ((n = wcslen(array)) +
len + 3 + taglen));
- (void) memcpy(cp, array, n * sizeof(wchar_t));
+ (void) memcpy(cp, array, n * sizeof (wchar_t));
if (taglen) {
cp[n++] = '[';
while (taglen)
@@ -2161,11 +2167,11 @@ makeindex(NODE *np, wchar_t *array, int tag)
}
cp[n++] = ']';
} else {
- cp = erealloc(cp, (n+len+seplen+1) * sizeof(wchar_t));
- (void) memcpy(cp+n, sep, seplen * sizeof(wchar_t));
+ cp = erealloc(cp, (n+len+seplen+1) * sizeof (wchar_t));
+ (void) memcpy(cp+n, sep, seplen * sizeof (wchar_t));
n += seplen;
}
- (void) memcpy(cp+n, indstr, (len+1) * sizeof(wchar_t));
+ (void) memcpy(cp+n, indstr, (len+1) * sizeof (wchar_t));
n += len;
}
return (cp);
@@ -2213,8 +2219,8 @@ promote(NODE *n)
*/
while (prev != NNULL) {
prev->n_flags &= ~FLARRAY;
- next=prev->n_alink;
+ next = prev->n_alink;
prev->n_alink = n;
- prev=next;
+ prev = next;
}
}