summaryrefslogtreecommitdiff
path: root/lang/nawk
diff options
context:
space:
mode:
authorjoerg <joerg>2008-08-26 14:46:21 +0000
committerjoerg <joerg>2008-08-26 14:46:21 +0000
commit7c969fd5e7979bf11b598d36e2cfb352f3475c2a (patch)
tree37a76f034102c9ad296e39a6bab29f92381fd050 /lang/nawk
parent92cd4a885be34000cdba3ede8c4376074aa57ea0 (diff)
downloadpkgsrc-7c969fd5e7979bf11b598d36e2cfb352f3475c2a.tar.gz
Remove hard-coded limit on FS. Merge minor performance improvements.
Bump revision.
Diffstat (limited to 'lang/nawk')
-rw-r--r--lang/nawk/Makefile3
-rw-r--r--lang/nawk/files/awk.h3
-rw-r--r--lang/nawk/files/lib.c23
-rw-r--r--lang/nawk/files/tran.c3
4 files changed, 20 insertions, 12 deletions
diff --git a/lang/nawk/Makefile b/lang/nawk/Makefile
index 167454d2ede..611b509cc35 100644
--- a/lang/nawk/Makefile
+++ b/lang/nawk/Makefile
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.32 2008/06/19 18:36:51 joerg Exp $
+# $NetBSD: Makefile,v 1.33 2008/08/26 14:46:21 joerg Exp $
DISTNAME= nawk-20050424
+PKGREVISION= 1
CATEGORIES= lang
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/lang/nawk/files/awk.h b/lang/nawk/files/awk.h
index 3a516ed5025..a15f74623bf 100644
--- a/lang/nawk/files/awk.h
+++ b/lang/nawk/files/awk.h
@@ -1,4 +1,4 @@
-/* $NetBSD: awk.h,v 1.1 2006/07/14 14:23:06 jlam Exp $ */
+/* $NetBSD: awk.h,v 1.2 2008/08/26 14:46:21 joerg Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
@@ -68,7 +68,6 @@ extern int lineno; /* line number in awk program */
extern int errorflag; /* 1 if error has occurred */
extern int donefld; /* 1 if record broken into fields */
extern int donerec; /* 1 if record is valid (no fld has changed */
-extern char inputFS[]; /* FS at time of input, for field splitting */
extern int dbg;
diff --git a/lang/nawk/files/lib.c b/lang/nawk/files/lib.c
index f0ced66e85d..8fc16c2932d 100644
--- a/lang/nawk/files/lib.c
+++ b/lang/nawk/files/lib.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.c,v 1.1 2006/07/14 14:23:06 jlam Exp $ */
+/* $NetBSD: lib.c,v 1.2 2008/08/26 14:46:21 joerg Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
@@ -42,7 +42,9 @@ char *fields;
int fieldssize = RECSIZE;
Cell **fldtab; /* pointers to Cells */
-char inputFS[100] = " ";
+char static_inputFS[16] = " ";
+size_t len_inputFS = sizeof(static_inputFS) - 1;
+char *inputFS = static_inputFS;
#define MAXFLD 200
int nfields = MAXFLD; /* last allocated slot for $i */
@@ -186,10 +188,17 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf *
int sep, c;
char *rr, *buf = *pbuf;
int bufsize = *pbufsize;
-
- if (strlen(*FS) >= sizeof(inputFS))
- FATAL("field separator %.10s... is too long", *FS);
- strcpy(inputFS, *FS); /* for subsequent field splitting */
+ size_t len;
+
+ if ((len = strlen(*FS)) <= len_inputFS) {
+ strcpy(inputFS, *FS); /* for subsequent field splitting */
+ } else {
+ inputFS = malloc(len + 1);
+ if (inputFS == NULL)
+ FATAL("field separator %.10s... is too long", *FS);
+ len_inputFS = len;
+ memcpy(inputFS, *FS, len + 1);
+ }
if ((sep = **RS) == 0) {
sep = '\n';
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */
@@ -276,7 +285,7 @@ void fldbld(void) /* create fields from current record */
}
fr = fields;
i = 0; /* number of fields accumulated here */
- if (strlen(inputFS) > 1) { /* it's a regular expression */
+ if (inputFS[0] && inputFS[1]) { /* it's a regular expression */
i = refldbld(r, inputFS);
} else if ((sep = *inputFS) == ' ') { /* default whitespace */
for (i = 0; ; ) {
diff --git a/lang/nawk/files/tran.c b/lang/nawk/files/tran.c
index fcbea3fe753..5d3041488fb 100644
--- a/lang/nawk/files/tran.c
+++ b/lang/nawk/files/tran.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tran.c,v 1.1 2006/07/14 14:23:06 jlam Exp $ */
+/* $NetBSD: tran.c,v 1.2 2008/08/26 14:46:21 joerg Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
@@ -405,7 +405,6 @@ char *tostring(const char *s) /* make a copy of string s */
p = (char *) malloc(strlen(s)+1);
if (p == NULL)
FATAL("out of space in tostring on %s", s);
- strcpy(p, s);
return(p);
}