summaryrefslogtreecommitdiff
path: root/gnu/usr.bin
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1993-07-02 23:56:52 +0000
committerjtc <jtc@NetBSD.org>1993-07-02 23:56:52 +0000
commitf4e00a39c236bf7481c72bcc6d215900040c7cdf (patch)
tree52e2aaed1a2ff6e364820a186cf85c4b792e5626 /gnu/usr.bin
parent8ebc845441169cc86d3f7c2b400125e254124a27 (diff)
Updated to mawk 1.1.4
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/awk/ACKNOWLEDGMENT14
-rw-r--r--gnu/usr.bin/awk/Makefile6
-rw-r--r--gnu/usr.bin/awk/PATCHES127
-rw-r--r--gnu/usr.bin/awk/array.c134
-rw-r--r--gnu/usr.bin/awk/awk.1185
-rw-r--r--gnu/usr.bin/awk/bi_funct.c79
-rw-r--r--gnu/usr.bin/awk/bi_funct.h8
-rw-r--r--gnu/usr.bin/awk/bi_vars.c15
-rw-r--r--gnu/usr.bin/awk/bi_vars.h13
-rw-r--r--gnu/usr.bin/awk/cast.c100
-rw-r--r--gnu/usr.bin/awk/code.c8
-rw-r--r--gnu/usr.bin/awk/code.h8
-rw-r--r--gnu/usr.bin/awk/config.h55
-rw-r--r--gnu/usr.bin/awk/config/Idefault.h225
-rw-r--r--gnu/usr.bin/awk/da.c16
-rw-r--r--gnu/usr.bin/awk/error.c217
-rw-r--r--gnu/usr.bin/awk/execute.c161
-rw-r--r--gnu/usr.bin/awk/fcall.c8
-rw-r--r--gnu/usr.bin/awk/field.c65
-rw-r--r--gnu/usr.bin/awk/field.h8
-rw-r--r--gnu/usr.bin/awk/files.c155
-rw-r--r--gnu/usr.bin/awk/files.h14
-rw-r--r--gnu/usr.bin/awk/fin.c79
-rw-r--r--gnu/usr.bin/awk/fin.h8
-rw-r--r--gnu/usr.bin/awk/hash.c8
-rw-r--r--gnu/usr.bin/awk/init.c36
-rw-r--r--gnu/usr.bin/awk/init.h8
-rw-r--r--gnu/usr.bin/awk/jmp.c8
-rw-r--r--gnu/usr.bin/awk/jmp.h8
-rw-r--r--gnu/usr.bin/awk/kw.c8
-rw-r--r--gnu/usr.bin/awk/main.c44
-rw-r--r--gnu/usr.bin/awk/makescan.c8
-rw-r--r--gnu/usr.bin/awk/matherr.c28
-rw-r--r--gnu/usr.bin/awk/mawk.h45
-rw-r--r--gnu/usr.bin/awk/memory.c8
-rw-r--r--gnu/usr.bin/awk/memory.h8
-rw-r--r--gnu/usr.bin/awk/parse.y48
-rw-r--r--gnu/usr.bin/awk/parse2.xc8
-rw-r--r--gnu/usr.bin/awk/patchlev.h5
-rw-r--r--gnu/usr.bin/awk/print.c194
-rw-r--r--gnu/usr.bin/awk/re_cmpl.c8
-rw-r--r--gnu/usr.bin/awk/regexp.h8
-rw-r--r--gnu/usr.bin/awk/repl.h8
-rw-r--r--gnu/usr.bin/awk/scan.c39
-rw-r--r--gnu/usr.bin/awk/scan.h8
-rw-r--r--gnu/usr.bin/awk/sizes.h33
-rw-r--r--gnu/usr.bin/awk/split.c21
-rw-r--r--gnu/usr.bin/awk/symtype.h23
-rw-r--r--gnu/usr.bin/awk/types.h8
-rw-r--r--gnu/usr.bin/awk/vargs.h59
-rw-r--r--gnu/usr.bin/awk/version.c128
-rw-r--r--gnu/usr.bin/awk/zmalloc.c42
-rw-r--r--gnu/usr.bin/awk/zmalloc.h8
53 files changed, 1689 insertions, 884 deletions
diff --git a/gnu/usr.bin/awk/ACKNOWLEDGMENT b/gnu/usr.bin/awk/ACKNOWLEDGMENT
index d214378b63a..493e61ab042 100644
--- a/gnu/usr.bin/awk/ACKNOWLEDGMENT
+++ b/gnu/usr.bin/awk/ACKNOWLEDGMENT
@@ -10,19 +10,25 @@ MSC and Mac ports and wrote .bat files for the tests.
Another or maybe the same reviewer did the Dynix port.
Ports to new systems:
- Layne Lommen ApolloSR10.3
Ed Ferguson MIPS M2000 C2.20 OS4.52
Jwahar R. Bammi Atari ST
Berry Kercheval SGI IRIX 4.0.1
- Andy Mason Next 2.1
+ Andy Newman Next 2.1
Mike Carlton Next 2.1
Elliot Jaffe AIX 3.1
+ Jeremy Martin Convex 9.1
+ Scott Hunziker Coherent 4.0
+ Ken Poulton Hpux
+ Onno van der Linden 386bsd 0.1
+ Bob Hutchinson Linux 0.98p14
The DOS version is a lot better thanks to suggestions and testing
from Ed Ferguson, Jack Fitts, Nadav Horesh, Michael Golan and
-Conny Ohstrom.
+Conny Ohstrom. The DOS additions for 1.1.2d are all ideas of
+Ben Myers; much of the code is his too.
Arnold Robbins kept me current on POSIX standards for AWK, and
explained some of the "dark corners".
-
+Thank you to everyone who reported bugs or offered encouragement,
+suggestions or criticism. (At least the bugs got fixed).
diff --git a/gnu/usr.bin/awk/Makefile b/gnu/usr.bin/awk/Makefile
index ce3a1055682..9e6cbf369ca 100644
--- a/gnu/usr.bin/awk/Makefile
+++ b/gnu/usr.bin/awk/Makefile
@@ -1,6 +1,5 @@
-
PROG= awk
-YACC= yacc -d
+YACC= yacc
CFLAGS+= -DMAWK -I. -I${.CURDIR} -I${.CURDIR}/rexp
SRCS= parse.c scan.c memory.c main.c hash.c execute.c code.c \
da.c error.c init.c bi_vars.c cast.c print.c bi_funct.c \
@@ -9,7 +8,7 @@ SRCS= parse.c scan.c memory.c main.c hash.c execute.c code.c \
SRCS+= rexp.c rexp0.c rexp1.c rexp2.c rexp3.c rexpdb.c
LDADD= -lm -ly
-DPADD= ${LIBMATH}
+DPADD= ${LIBMATH} ${LIB
CLEANFILES+=parse.c parse.h
.PATH: ${.CURDIR}/rexp
@@ -19,5 +18,4 @@ parse.h parse.c:
cat ${.CURDIR}/parse2.xc >> parse.c
mv y.tab.h parse.h
-
.include <bsd.prog.mk>
diff --git a/gnu/usr.bin/awk/PATCHES b/gnu/usr.bin/awk/PATCHES
new file mode 100644
index 00000000000..a51b30b27a1
--- /dev/null
+++ b/gnu/usr.bin/awk/PATCHES
@@ -0,0 +1,127 @@
+patch4: mawk1.1.3 -> mawk1.1.4 May 93
+
+fixed 2 bugs:
+1) length alone without () or ($0) sometimes core dumps due
+ to stupid oversight in parse.y
+
+2) numeric looking data fields that fpe overflow cause program
+ to halt -- should be treated as strings instead
+
+
+patch3: mawk1.1.2 -> mawk1.1.3 Jan 93
+
+1) New configurations:
+ hpux coherent 386bsd linux
+
+2) Changed some ints to longs so that Unix and Dos versions
+ give same output. E.g.,
+
+ printf "%d" and printf "%ld" are now the same on Dos.
+
+ msdos/examples directory with scripts by Ben Myers
+
+ Infinity+1 large model pointer bug caused by modulo 2^16
+ arithmetic fixed.
+
+3) Grossly surprised to discover (int) d causes a floating
+ point exception on hpux when d is a large double.
+ Integer casts are now done more carefully. Thanks to
+ Ken Poulton for finding this bug.
+
+4) Removed ApolloSR10.3 from working configurations. Mawk will
+ not work if compiled with CC6.8.
+
+
+patch2: mawk1.1.1 -> mawk1.1.2 26 Aug 92
+
+1) Comparisons are done as described the AWK book, which is the
+ same as mawk1.0. Evidently I lack the requisite mental facilities
+ to understand posix comparisons , i.e.
+
+ echo 0 | mawk '$0 == "0000" { print "true" }'
+ true
+
+ was a major bozo.
+
+2) If n = split(s, X, r) , then all elements other than
+ X[1..n] are now deleted from X. This behavior is
+ consistent with other awks.
+
+3) foo = "foo"
+ foo++ evaluates to 0 and value of foo is 1
+
+ old behavior was foo++ was "foo" and foo then set to 1
+
+4) Fixed two bugs in regular expression lexical scanner:
+
+ [c1-c2] did not work right if c2 was an escaped character.
+
+ function do_str() which collected runs of characters did
+ not work right if the last character was escaped and the run
+ ended with * + or ?.
+
+5) You can now read and write to the same file. E.g.
+
+ printf "Enter: " > "/dev/tty"
+ getline answer < "/dev/tty"
+
+6) Output to files which are ttys is now unbuffered.
+
+7) FILENAME and FNR retain their value from the last record in
+ the END section.
+
+8) man pages might groff.
+
+9) New configuration files
+ aix.h convex.h sysVr4i386.h
+
+10) Better error recovery for bungled function definitions
+ via new productions
+
+ program_block : outside_error block ;
+ error : outside_error ;
+
+11) If i > NF , then ++$i , $i++, g?sub(r,s,$i), now work
+ correctly.
+
+12) MsDOS, interactive input: terminating a line with ^Z
+ works correctly (at least with TC++ compiler).
+
+l3) string_buff had too many users which induced an error in
+ sprintf(). After parsing, string_buff is now only be used
+ by sprintf().
+ (Old fart seduced by subliminal common block).
+
+--------------------------------------------------
+patch1: mawk1.1 to mawk1.1.1 (mar 92)
+
+1) fixed bug which caused
+
+ mawk 'program' var=value
+
+without files on the command line to sporadically fail.
+
+2) fixed bug which caused
+
+ getline <=
+
+to be mistaken for input redirection.
+
+3) Changed rexp1.c to work around a bug in sun SC1.0 compiler.
+
+4) Minor improvements to build_mawk script.
+
+5) changed the name of ultrix42_mips.h to ultrix42mips.h so
+ the filename is 14 characters.
+
+6) printf() and sprintf() can now have more arguments than
+conversions in the format string. This allows a "poor man's" varargs
+functionality for user functions that do output.
+
+7) new configurations:
+
+ next, sgi, aix
+
+8) removed HAVE_PRINTF_HD define as too obscure to be useful.
+
+9) added missing config/apollo.h file.
diff --git a/gnu/usr.bin/awk/array.c b/gnu/usr.bin/awk/array.c
index 995be1c7ecb..08f1bd44a1b 100644
--- a/gnu/usr.bin/awk/array.c
+++ b/gnu/usr.bin/awk/array.c
@@ -1,7 +1,7 @@
/********************************************
array.c
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992. Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,9 +11,23 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: array.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:56:57 jtc
+/* Updated to mawk 1.1.4
/*
+ * Revision 5.3.1.1 1993/01/20 12:24:25 mike
+ * patch3: safer double to int conversions
+ *
+ * Revision 5.3 1992/11/28 23:48:42 mike
+ * For internal conversion numeric->string, when testing
+ * if integer, use longs instead of ints so 16 and 32 bit
+ * systems behave the same
+ *
+ * Revision 5.2 1992/04/07 17:17:31 brennan
+ * patch 2
+ * n = split(s,A,r)
+ * delete A[i] if i not in 1..n
+ * This is consistent with [ng]?awk
+ *
* Revision 5.1 91/12/05 07:55:32 brennan
* 1.1 pre-release
*
@@ -30,9 +44,10 @@ the GNU General Public License, version 2, 1991.
#define NO_IVAL (-1)
static ANODE *PROTO(find_by_sval, (ARRAY, STRING *, int) ) ;
-static ANODE *PROTO(find_by_index, (ARRAY, int,int,int) ) ;
+static ANODE *PROTO(find_by_index, (ARRAY, int,long,int) ) ;
static ANODE *PROTO(find_by_dval, (ARRAY, double, int)) ;
static void PROTO(load_array_ov, (ARRAY) ) ;
+static void PROTO(ilist_delete, (ARRAY, ANODE*)) ;
extern unsigned hash() ;
@@ -62,17 +77,19 @@ static ANODE *find_by_sval(A, sval, cflag)
register ANODE *p = A[h].link ;
ANODE *q = 0 ; /* holds first deleted ANODE */
- while ( p )
- {
+ while ( 1 )
+ if ( !p ) goto not_there ;
+ else
if ( p->sval )
- { if ( strcmp(s,p->sval->str) == 0 ) return p ; }
- else /* its deleted, mark with q */
- if ( ! q ) q = p ;
-
- p = p->link ;
- }
-
- /* not there */
+ if ( strcmp(s,p->sval->str) == 0 ) return p ;
+ else p = p->link ;
+ else { q = p ; p = p->link ; break ; }
+
+ while ( p ) /* q is now set */
+ if ( p->sval && strcmp(s,p->sval->str) == 0 ) return p ;
+ else p = p->link ;
+
+not_there :
if ( cflag )
{
if ( q ) p = q ; /* reuse the deleted node q */
@@ -91,9 +108,16 @@ static ANODE *find_by_sval(A, sval, cflag)
}
+/* find an array by (long) integer ival.
+ Caller has already computed the hash value index.
+ (This allows fast insertion for split())
+*/
+
static ANODE *find_by_index(A, index, ival, flag)
ARRAY A ;
- int index, ival, flag ;
+ int index;
+ long ival;
+ int flag ;
{
register ANODE *p = A[index].ilink ;
ANODE *q = 0 ; /* trails p */
@@ -109,10 +133,11 @@ static ANODE *find_by_index(A, index, ival, flag)
/* not there, still need to look by sval */
- { char xbuff[16] ;
+ { /* convert to string */
+ char xbuff[16] ;
STRING *sval ;
char *s = xbuff+14 ;
- int x = ival ;
+ long x = ival ;
xbuff[15] = 0 ;
@@ -136,19 +161,24 @@ found : /* put p at front */
static ANODE *find_by_dval(A, d, flag)
ARRAY A ;
double d ;
+ int flag ;
{
- int ival ;
+ long lval ;
ANODE *p ;
char xbuff[260] ;
STRING *sval ;
- if ( (double)(ival = (int)d) == d ) /* integer valued */
+ lval = d_to_l(d) ;
+ if ( (double)lval == d ) /* integer valued */
{
- if ( ival >= 0 )
- return find_by_index(A, ival%A_HASH_PRIME, ival, flag) ;
-
- (void) sprintf(xbuff, "%d", ival) ;
+ if ( lval >= 0 )
+ {
+ return
+ find_by_index(A, (int)(lval%A_HASH_PRIME), lval, flag) ;
+ }
+ else
+ (void) sprintf(xbuff, INT_FMT, lval) ;
}
else (void) sprintf(xbuff, string(CONVFMT)->str, d) ;
@@ -195,8 +225,9 @@ void array_delete(A, cp)
{
case C_DOUBLE :
ap = find_by_dval(A, cp->dval, NO_CREATE) ;
+ /* cut the ilink */
if ( ap && ap->ival >= 0 ) /* must be at front */
- A[ap->ival%A_HASH_PRIME].ilink = ap->ilink ;
+ A[(int)(ap->ival%A_HASH_PRIME)].ilink = ap->ilink ;
break ;
case C_NOINIT :
@@ -205,16 +236,13 @@ void array_delete(A, cp)
default :
ap = find_by_sval(A, string(cp), NO_CREATE) ;
- if ( ap && ap->ival >= 0 )
- {
- int index = ap->ival % A_HASH_PRIME ;
-
- ap = find_by_index(A, index, ap->ival, NO_CREATE) ;
- A[index].ilink = ap->ilink ;
- }
+ if ( ap && ap->ival >= 0 ) ilist_delete(A, ap) ;
break ;
}
+
+ /* delete -- leave the empty ANODE so for(i in A)
+ works */
if ( ap )
{ free_STRING(ap->sval) ; ap->sval = (STRING *) 0 ;
cell_destroy(ap->cp) ; zfree(ap->cp, sizeof(CELL)) ;
@@ -241,7 +269,7 @@ static void load_array_ov(A)
while( 1 )
{
- cp = find_by_index(A, index, cnt, NO_MOVE) ->cp ;
+ cp = find_by_index(A, index, (long)cnt, NO_MOVE) ->cp ;
cell_destroy(cp) ;
cp->type = C_MBSTRN ;
cp->ptr = (PTR) p->sval ;
@@ -254,6 +282,23 @@ static void load_array_ov(A)
}
}
+/* delete an ANODE from the ilist that is known
+ to be there */
+
+static void ilist_delete(A, d)
+ ARRAY A ;
+ ANODE *d ;
+{
+ int index = d->ival % A_HASH_PRIME ;
+ register ANODE *p = A[index].ilink ;
+ register ANODE *q = (ANODE *) 0 ;
+
+ while ( p != d ) { q = p ; p = p->ilink ; }
+
+ if ( q ) q->ilink = p->ilink ;
+ else A[index].ilink = p->ilink ;
+}
+
/* this is called by bi_split()
to load strings into an array
@@ -266,6 +311,28 @@ void load_array( A, cnt)
register CELL *cp ;
register int index ;
+ { /* clear A , leaving only A[1]..A[cnt] (if exist) */
+ int i ;
+ ANODE *p ;
+
+ for( i = 0 ; i < A_HASH_PRIME ; i++ )
+ {
+ p = A[i].link ;
+ while ( p )
+ {
+ if ( p->sval && (p->ival <= 0 || p->ival > cnt) )
+ {
+ if (p->ival >= 0) ilist_delete(A, p) ;
+
+ free_STRING(p->sval) ;
+ p->sval = (STRING *) 0 ;
+ cell_destroy(p->cp) ;
+ ZFREE(p->cp) ;
+ }
+ p = p->link ;
+ }
+ }
+ }
if ( cnt > MAX_SPLIT )
{
load_array_ov(A) ;
@@ -276,7 +343,7 @@ void load_array( A, cnt)
while ( cnt )
{
- cp = find_by_index(A, index, cnt, NO_MOVE) ->cp ;
+ cp = find_by_index(A, index, (long) cnt, NO_MOVE) ->cp ;
cell_destroy(cp) ;
cp->type = C_MBSTRN ;
cp->ptr = (PTR) split_buff[--cnt] ;
@@ -401,4 +468,3 @@ int inc_aloop_state( ap )
p = p->link ;
}
}
-
diff --git a/gnu/usr.bin/awk/awk.1 b/gnu/usr.bin/awk/awk.1
index 057c2428942..22135f7c6a8 100644
--- a/gnu/usr.bin/awk/awk.1
+++ b/gnu/usr.bin/awk/awk.1
@@ -1,9 +1,8 @@
-.TH MAWK 1 "Jan 22 1992" "Version 1.1" "USER COMMANDS"
+.TH MAWK 1 "Jul 13 1992" "Version 1.1.2" "USER COMMANDS"
.\" strings
.ds ex \fIexpr\fR
.SH NAME
mawk \- pattern scanning and text processing language
-
.SH SYNOPSIS
.B mawk
[\-\fBW
@@ -24,7 +23,6 @@ mawk \- pattern scanning and text processing language
[\-\fBf
.IR program-file ]
[\-\|\-] [file ...]
-
.SH DESCRIPTION
.B mawk
is an interpreter for the AWK Programming Language.
@@ -46,7 +44,7 @@ which contains a few features not described in the AWK
book, and
.B mawk
provides a small number of extensions.
-
+.PP
An AWK program is a sequence of \fIpattern {action}\fR pairs and
function definitions.
Short programs are entered on the command line
@@ -59,40 +57,40 @@ the command line or from standard input when the list is empty.
The input is broken into records as determined by the
record separator variable, \fBRS\fR. Initially,
.B RS
-= "\\n" and records are synonymous with lines.
+= "\en" and records are synonymous with lines.
Each record is compared against each
.I pattern
and if it matches, the program text for
.I "{action}"
is executed.
-
.SH OPTIONS
-
-.TP \w'\-\fBv'u+\w'\fIvar=value'u+2n
-\-\fBF \fIvalue
+.TP \w'\-\fBW'u+\w'\fRsprintf=\fInum\fR'u+2n
+\-\fBF \fIvalue\fP
sets the field separator, \fBFS\fR, to
.IR value .
-
-.IP "\-\fBf \fIfile"
+.TP
+\-\fBf \fIfile
Program text is read from \fIfile\fR instead of from the
-command line. Multiple \-f options are allowed.
-
-.IP "\-\fBv \fIvar=value"
+command line. Multiple
+.B \-f
+options are allowed.
+.TP
+\-\fBv \fIvar=value\fR
assigns
.I value
to program variable
.IR var .
-
-.IP "\-\|\-"
+.TP
+\-\|\-
indicates the unambiguous end of options.
.PP
The above options will be available with any Posix compatible
implementation of AWK, and implementation specific options are
-prefaced with \-W.
+prefaced with
+.BR \-W .
.B mawk
-provides three:
-
-.TP \w'\-\fBv'u+\w'\fIvar=value'u+2n
+provides four:
+.TP \w'\-\fBW'u+\w'\fRsprintf=\fInum\fR'u+2n
\-\fBW \fRversion
.B mawk
writes its version and copyright
@@ -103,7 +101,7 @@ stderr and exits 0.
writes an assembler like listing of the internal
representation of the program to stderr.
.TP
-\-\fBW \fRsprintf=\fInum
+\-\fBW \fRsprintf=\fInum\fR
adjusts the size of
.B mawk's
internal sprintf buffer to
@@ -115,8 +113,7 @@ should be recompiled.
\-\fBW \fRposix_space
forces
.B mawk
-not to consider '\\n' to be space.
-
+not to consider '\en' to be space.
.SH "THE AWK LANGUAGE"
.SS "\fB1. Program structure"
An AWK program is a sequence of
@@ -151,7 +148,7 @@ actions or loop bodies are blocked via { ... } as in C. The
last statement in a block doesn't need a terminator. Blank lines
have no meaning; an empty statement is terminated with a
semi-colon. Long statements
-can be continued with a backslash, \\\|. A statement can be broken
+can be continued with a backslash, \e\|. A statement can be broken
without a backslash after a comma, left brace, &&, ||,
.BR do ,
.BR else ,
@@ -217,26 +214,26 @@ is true and true is represented as 1.0.
String constants are enclosed in double quotes.
.sp
.ce
-"This is a string with a newline at the end.\\n"
+"This is a string with a newline at the end.\en"
.sp
-Strings can be continued across a line by escaping (\\) the newline.
+Strings can be continued across a line by escaping (\e) the newline.
The following escape sequences are recognized.
.nf
.sp
- \\\\ \\
- \\" "
- \\a alert, ascii 7
- \\b backspace, ascii 8
- \\t tab, ascii 9
- \\n newline, ascii 10
- \\v vertical tab, ascii 11
- \\f formfeed, ascii 12
- \\r carriage return, ascii 13
- \\ddd 1, 2 or 3 octal digits for ascii ddd
- \\xhh 1 or 2 hex digits for ascii hh
+ \e\e \e
+ \e" "
+ \ea alert, ascii 7
+ \eb backspace, ascii 8
+ \et tab, ascii 9
+ \en newline, ascii 10
+ \ev vertical tab, ascii 11
+ \ef formfeed, ascii 12
+ \er carriage return, ascii 13
+ \eddd 1, 2 or 3 octal digits for ascii ddd
+ \exhh 1 or 2 hex digits for ascii hh
.sp
.fi
-If you escape any other character \\c, you get \\c, i.e.,
+If you escape any other character \ec, you get \ec, i.e.,
.B mawk
ignores the escape.
.PP
@@ -295,13 +292,9 @@ is numeric.
To evaluate,
\*(ex\d1\u \fBrel-op \*(ex\d2\u,
if both operands are numeric or number and string then the comparison
-is numeric; if both operands are string the comparison is string.
-If exactly one operand is string and after trimming spaces and
-tabs from the front and back the remaining string is entirely
-numeric in form, then the string is converted to number and the
-comparison is numeric; otherwise, the numeric operand is converted
-to string and the comparison is string.
-The result of a comparison is numeric, 0 or 1.
+is numeric; if both operands are string the comparison is string;
+if one operand is string, the non-string operand is converted and
+the comparison is string. The result is numeric, 1 or 0.
.PP
In boolean contexts such as,
\fBif\fR ( \*(ex ) \fIstatement\fR,
@@ -359,15 +352,17 @@ Regular expressions are built up from characters as follows:
\fIc\fR
matches any non-metacharacter
.IR c .
-.IP "\e\fIc\fR"
+.TP
+"\e\fIc\fR"
matches a character defined by the same escape sequences used
in string constants or the literal
character
.I c
if
-\\\fIc\fR
+\e\fIc\fR
is not an escape sequence.
-.IP \.
+.TP
+\&\.
matches any character (including newline).
.TP
^
@@ -389,7 +384,7 @@ c\d1\uc\d2\uc\d3\u...
Regular expressions are built up from other regular expressions
as follows:
.RS
-.TP
+.TP \w'[^c\d1\uc\d2\uc\d3\u...]'u+1n
\fIr\fR\d1\u\fIr\fR\d2\u
matches
\fIr\fR\d1\u
@@ -424,7 +419,7 @@ For example,
.nf
.sp
/^[_a\-zA-Z][_a\-zA\-Z0\-9]*$/ and
- /^[\-+]?([0\-9]+\\\|.?|\\\|.[0\-9])[0\-9]*([eE][\-+]?[0\-9]+)?$/
+ /^[\-+]?([0\-9]+\e\|.?|\e\|.[0\-9])[0\-9]*([eE][\-+]?[0\-9]+)?$/
.sp
.fi
are matched by AWK identifiers and AWK numeric constants
@@ -512,7 +507,7 @@ For example,
.nf
echo 24 24E |
mawk '{ print($1>100, $1>"100", $2>100, $2>"100") }'
- 0 0 1 1
+ 0 1 1 1
.fi
.sp
.B $0
@@ -520,11 +515,10 @@ and
.B $2
are string and
.B $1
-is number and string. The first
-and second comparisons are numeric and the last
-two are string. In the second "100" is
-converted to 100, and in the third 100 is
-converted to "100".
+is number and string. The first comparison is numeric,
+the second is string, the third is string
+(100 is converted to "100"),
+and the last is string.
.\"
.SS "\fB5. Expressions and operators"
.PP
@@ -671,21 +665,21 @@ format for printing numbers; initially = "%.6g".
inserted between fields on output, initially = " ".
.TP
.B ORS
-terminates each record on output, initially = "\\n".
+terminates each record on output, initially = "\en".
.TP
.B RLENGTH
length set by the last call to the built-in function,
.BR match() .
.TP
.B RS
-input record separator, initially = "\\n".
+input record separator, initially = "\en".
.TP
.B RSTART
index set by the last call to
.BR match() .
.TP
.B SUBSEP
-used to build multiple array subscripts, initially = "\\034".
+used to build multiple array subscripts, initially = "\e034".
.RE
.\"
.SS "\fB8. Built-in functions"
@@ -708,7 +702,7 @@ is used. An & in the replacement string
.I s
is replaced by the matched substring of
.IR t .
-\\& puts a literal & in the replacement string.
+\e& puts a literal & in the replacement string.
.TP
index(\fIs,t\fR)
If
@@ -722,11 +716,9 @@ The first character of
.I s
is in position 1.
.TP
-length(\fIs\fR) length()
+length(\fIs\fR)
Returns the length of string
-.IR s ;
-without an argument, returns the length of
-.BR $0 .
+.IR s .
.TP
match(\fIs,r\fR)
Returns the index of the first longest match of regular expression
@@ -1035,20 +1027,20 @@ and
becomes <SPACE>.
.B mawk
defines <SPACE> as the regular expression
-/[\ \\t\\n]+/.
+/[\ \et\en]+/.
Otherwise
.I sep
is treated as a regular expression, except that meta-characters
are ignored for a string of length 1,
e.g.,
-split(x, A, "*") and split(x, A, /\\*/) are the same.
+split(x, A, "*") and split(x, A, /\e*/) are the same.
.TP
(3)
If \*(ex is not string, it is converted to string.
If \*(ex is then the empty string "", split() returns 0
and
.I A
-is unchanged.
+is set empty.
Otherwise,
all non-overlapping, non-null and longest matches of
.I sep
@@ -1118,7 +1110,7 @@ interprets
as a regular expression, multi-line
records are easy. Setting
.B RS
-= "\\n\\n+", makes one or more blank
+= "\en\en+", makes one or more blank
lines separate records. If
.B FS
= " " (the default), then single
@@ -1126,14 +1118,14 @@ newlines, by the rules for <SPACE> above, become space and
single newlines are field separators.
.RS
.PP
-For example, if a file is "a\ b\\nc\\n\\n",
+For example, if a file is "a\ b\enc\en\en",
.B RS
-= "\\n\\n+" and
+= "\en\en+" and
.B FS
-= "\ ", then there is one record "a\ b\\nc" with three
+= "\ ", then there is one record "a\ b\enc" with three
fields "a", "b" and "c". Changing
.B FS
-= "\\n", gives two
+= "\en", gives two
fields "a b" and "c"; changing
.B FS
= "", gives one field
@@ -1143,21 +1135,21 @@ identical to the record.
If you want lines with spaces or tabs to be considered blank,
set
.B RS
-= "\\n([\ \\t]*\\n)+".
+= "\en([\ \et]*\en)+".
For compatibility with other awks, setting
.B RS
= "" has the same
effect as if blank lines are stripped from the
front and back of files and then records are determined as if
.B RS
-= "\\n\\n+".
-Posix requires that "\\n" always separates records when
+= "\en\en+".
+Posix requires that "\en" always separates records when
.B RS
= "" regardless of the value of
.BR FS .
.B mawk
does not support this convention, because defining
-"\\n" as <SPACE> makes it unnecessary.
+"\en" as <SPACE> makes it unnecessary.
.\"
.PP
Most of the time when you change
@@ -1165,7 +1157,7 @@ Most of the time when you change
for multi-line records, you
will also want to change
.B ORS
-to "\\n\\n" so the record spacing is preserved on output.
+to "\en\en" so the record spacing is preserved on output.
.\"
.SS "\fB13. Program execution"
This section describes the order of program execution.
@@ -1197,7 +1189,7 @@ For example with
= "t=hello" and
.B ARGV[4]
= "B".
-
+.PP
Next, each
.B BEGIN
block is executed in order.
@@ -1325,7 +1317,6 @@ sets the exit value of the program unless overridden by
a later
.B exit
or subsequent error.
-
.SH EXAMPLES
.nf
1. emulate cat.
@@ -1334,7 +1325,7 @@ or subsequent error.
2. emulate wc.
- { chars += length($0) + 1 # add one for the \\n
+ { chars += length($0) + 1 # add one for the \en
words += NF
}
@@ -1384,7 +1375,6 @@ every record based on the first field.
}
.fi
-
.SH "COMPATIBILITY ISSUES"
The Posix 1003.2(draft 11.2) definition of the AWK language
is AWK as described in the AWK book with a few extensions
@@ -1404,13 +1394,13 @@ implementation options as arguments to \-W.
Posix AWK is oriented to operate on files a line at
a time.
.B RS
-can be changed from "\\n" to another single character,
+can be changed from "\en" to another single character,
but it
is hard to find any use for this \(em there are no
examples in the AWK book.
By convention, \fBRS\fR = "", makes one or more blank lines
separate records, allowing multi-line records. When
-\fBRS\fR = "", "\\n" is always a field separator
+\fBRS\fR = "", "\en" is always a field separator
regardless of the value in
.BR FS .
.PP
@@ -1419,7 +1409,7 @@ on the other hand,
allows
.B RS
to be a regular expression.
-When "\\n" appears in records, it is treated as space, and
+When "\en" appears in records, it is treated as space, and
.B FS
always determines fields.
.PP
@@ -1449,7 +1439,7 @@ a C program file,
.nf
.sp
BEGIN {
- RS = "/\|\\*([^*]\||\|\\*+[^/*])*\\*+/"
+ RS = "/\|\e*([^*]\||\|\e*+[^/*])*\e*+/"
# comment is record separator
ORS = " "
getline hold
@@ -1468,7 +1458,7 @@ With
the following are all equivalent,
.nf
.sp
- x ~ /a\\+b/ x ~ "a\\+b" x ~ "a\\\\+b"
+ x ~ /a\e+b/ x ~ "a\e+b" x ~ "a\e\e+b"
.sp
.fi
The strings get scanned twice, once as string and once as
@@ -1485,10 +1475,10 @@ Posix explicitly declines to define the behavior which passively
forces programs that must run under a variety of awks to use
the more portable but less readable, double escape.
.PP
-Posix AWK does not recognize "/dev/stderr" or \\x hex escape
+Posix AWK does not recognize "/dev/stderr" or \ex hex escape
sequences in strings. Unlike ANSI C,
.B mawk
-limits the number of digits that follows \\x to two.
+limits the number of digits that follows \ex to two.
.PP
Finally, here is how
.B mawk
@@ -1503,21 +1493,21 @@ of the closed interval [1, length(s)] and the half-open interval
[i, i+n). When this intersection is empty, the empty string is
returned; so substr("ABC", 1, 0) = "" and
substr("ABC", \-4, 6) = "A".
-
+.PP
Every string, including the empty string, matches the empty string
at the
front so, s ~ // and s ~ "", are always 1 as is match(s, //) and
match(s, ""). The last two set
.B RLENGTH
to 0.
-
+.PP
index(s, t) is always the same as match(s, t1) where t1 is the
same as t with metacharacters escaped. Hence consistency
with match requires that
index(s, "") always returns 1.
Also the condition, index(s,t) != 0 if and only t is a substring
of s, requires index("","") = 1.
-
+.PP
If getline encounters end of file, getline var, leaves var
unchanged. Similarly, on entry to the
.B END
@@ -1526,10 +1516,8 @@ actions,
the fields and
.B NF
have their value unaltered from the last record.
-
.SH SEE ALSO
-.I egrep
-(1)
+.IR egrep (1)
.PP
Aho, Kernighan and Weinberger,
.IR "The AWK Programming Language" ,
@@ -1546,14 +1534,12 @@ that does not attempt the depth of the AWK book
and assumes the reader may be a novice programmer.
The section on AWK arrays is excellent. It also
discusses Posix requirements for AWK.
-
-
.SH BUGS
.B mawk
-cannot handle ascii NUL \\0 in the source or data files. You
+cannot handle ascii NUL \e0 in the source or data files. You
can output NUL using printf with %c, and any other 8 bit
character is acceptable input.
-
+.PP
.B mawk
implements printf() and sprintf() using the C library functions,
printf and sprintf, so full ANSI compatibility requires an ANSI
@@ -1561,9 +1547,8 @@ C library. In practice this means the h conversion qualifier may
not be available. Also
.B mawk
inherits any bugs or limitations of the library functions.
-
+.PP
Implementors of the AWK language have shown a consistent lack
of imagination when naming their programs.
-
.SH AUTHOR
Mike Brennan (brennan@boeing.com).
diff --git a/gnu/usr.bin/awk/bi_funct.c b/gnu/usr.bin/awk/bi_funct.c
index 625571afd68..6d8c23715eb 100644
--- a/gnu/usr.bin/awk/bi_funct.c
+++ b/gnu/usr.bin/awk/bi_funct.c
@@ -11,12 +11,24 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: bi_funct.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:02 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:35 brennan
+ * Revision 5.3.1.2 1993/01/27 01:04:06 mike
+ * minor tuning to str_str()
+ *
+ * Revision 5.3.1.1 1993/01/15 03:33:35 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.3 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.2 1992/07/08 15:43:41 brennan
+ * patch2: length returns. I am a wimp
+ *
+ * Revision 5.1 1991/12/05 07:55:35 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -41,9 +53,9 @@ static void PROTO( fplib_err, (char *, double, char *) ) ;
/* global for the disassembler */
BI_REC bi_funct[] = { /* info to load builtins */
+"length" , bi_length, 0, 1, /* special must come first */
"index" , bi_index , 2, 2 ,
"substr" , bi_substr, 2, 3,
-"length" , bi_length, 0, 1,
"sprintf" , bi_sprintf, 1, 255,
"sin", bi_sin , 1, 1 ,
"cos", bi_cos , 1, 1 ,
@@ -62,16 +74,22 @@ BI_REC bi_funct[] = { /* info to load builtins */
(char *) 0, (PF_CP) 0, 0, 0 } ;
-
+/* load built-in functions in symbol table */
void bi_funct_init()
-{ register BI_REC *p = bi_funct ;
+{ register BI_REC *p ;
register SYMTAB *stp ;
- while ( p->name )
+ /* length is special (posix bozo) */
+ stp = insert(bi_funct->name) ;
+ stp->type = ST_LENGTH ;
+ stp->stval.bip = bi_funct ;
+
+ for( p = bi_funct + 1 ; p->name ; p++ )
{ stp = insert( p->name ) ;
stp->type = ST_BUILTIN ;
- stp->stval.bip = p++ ;
+ stp->stval.bip = p ;
}
+
/* seed rand() off the clock */
{ CELL c ;
@@ -102,23 +120,33 @@ CELL *bi_length(sp)
}
char *str_str(target, key , key_len)
- register char *target, *key ;
+ register char *target;
+ char *key ;
unsigned key_len ;
{
+ register int k = key[0] ;
+
switch( key_len )
- { case 0 : return (char *) 0 ;
- case 1 : return strchr( target, *key) ;
+ {
+ case 0 : return (char *) 0 ;
+ case 1 : return strchr( target, k) ;
case 2 :
- while ( target = strchr(target, *key) )
- if ( target[1] == key[1] ) return target ;
- else target++ ;
- /*failed*/
- return (char *) 0 ;
+ { int k1 = key[1] ;
+ while ( target = strchr(target, k) )
+ if ( target[1] == k1 ) return target ;
+ else target++ ;
+ /*failed*/
+ return (char *) 0 ;
+ }
}
+
key_len-- ;
- while ( target = strchr(target, *key) )
- if ( memcmp(target+1, key+1, SIZE_T(key_len)) == 0 ) return target ;
+ while ( target = strchr(target, k) )
+ {
+ if ( memcmp(target+1, key+1, SIZE_T(key_len)) == 0 )
+ return target ;
else target++ ;
+ }
/*failed*/
return (char *) 0 ;
}
@@ -178,9 +206,9 @@ CELL *bi_substr(sp)
}
else
{ if ( TEST2(sp+1) != TWO_DOUBLES ) cast2_to_d(sp+1) ;
- n = (int) sp[2].dval ;
+ n = d_to_i(sp[2].dval) ;
}
- i = (int) sp[1].dval - 1 ; /* i now indexes into string */
+ i = d_to_i(sp[1].dval) - 1 ; /* i now indexes into string */
if ( i < 0 ) { n += i ; i = 0 ; }
if ( n > len - i ) n = len - i ;
@@ -416,16 +444,11 @@ CELL *bi_sqrt(sp)
#endif
}
-#ifdef __TURBOC__
-long biostime(int, long) ;
-#define time(x) biostime(0,0L)
-#else
-#ifdef THINK_C
+#ifdef HAVE_TIME_H
#include <time.h>
#else
#include <sys/types.h>
#endif
-#endif
/* For portability, we'll use our own random number generator , taken
@@ -460,7 +483,7 @@ CELL *bi_srand(sp)
(void) cellcpy(&c, &cseed) ;
if ( c.type == C_NOINIT ) cast1_to_d(&c) ;
- seed = c.type == C_DOUBLE ? ((int)c.dval & M) % M + 1 :
+ seed = c.type == C_DOUBLE ? (d_to_i(c.dval) & M) % M + 1 :
hash(string(&c)->str) % M + 1 ;
cell_destroy(&c) ;
diff --git a/gnu/usr.bin/awk/bi_funct.h b/gnu/usr.bin/awk/bi_funct.h
index 0fda764884b..ef6bfd1ca53 100644
--- a/gnu/usr.bin/awk/bi_funct.h
+++ b/gnu/usr.bin/awk/bi_funct.h
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: bi_funct.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:03 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:03 brennan
+ * Revision 5.1 1991/12/05 07:59:03 brennan
* 1.1 pre-release
- *
+ *
*/
#ifndef BI_FUNCT_H
diff --git a/gnu/usr.bin/awk/bi_vars.c b/gnu/usr.bin/awk/bi_vars.c
index d1897aded99..cc5b302b15d 100644
--- a/gnu/usr.bin/awk/bi_vars.c
+++ b/gnu/usr.bin/awk/bi_vars.c
@@ -11,12 +11,15 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: bi_vars.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:04 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:38 brennan
+ * Revision 5.2 1992/07/10 16:17:10 brennan
+ * MsDOS: remove NO_BINMODE macro
+ *
+ * Revision 5.1 1991/12/05 07:55:38 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -44,7 +47,7 @@ static char *bi_var_names[NUM_BI_VAR] = {
"RLENGTH" ,
"RSTART" ,
"SUBSEP"
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
, "BINMODE"
#endif
} ;
@@ -83,7 +86,7 @@ void bi_vars_init()
NR->type = FNR->type = C_DOUBLE ;
/* dval is already 0.0 */
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
BINMODE->type = C_DOUBLE ;
#endif
}
diff --git a/gnu/usr.bin/awk/bi_vars.h b/gnu/usr.bin/awk/bi_vars.h
index 971a85704e9..5dc90fc7276 100644
--- a/gnu/usr.bin/awk/bi_vars.h
+++ b/gnu/usr.bin/awk/bi_vars.h
@@ -12,12 +12,15 @@ the GNU General Public License, version 2, 1991.
/* $Log: bi_vars.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:05 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:05 brennan
+ * Revision 5.2 1992/07/10 16:17:10 brennan
+ * MsDOS: remove NO_BINMODE macro
+ *
+ * Revision 5.1 1991/12/05 07:59:05 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -43,7 +46,7 @@ the GNU General Public License, version 2, 1991.
#define RSTART (bi_vars+7)
#define SUBSEP (bi_vars+8)
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
#define BINMODE (bi_vars+9)
#define NUM_BI_VAR 10
#else
diff --git a/gnu/usr.bin/awk/cast.c b/gnu/usr.bin/awk/cast.c
index 1156fff8c19..6f39e3c4c89 100644
--- a/gnu/usr.bin/awk/cast.c
+++ b/gnu/usr.bin/awk/cast.c
@@ -12,12 +12,35 @@ the GNU General Public License, version 2, 1991.
/* $Log: cast.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:06 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:41 brennan
+ * Revision 5.3.1.5 1993/05/05 00:11:22 mike
+ * patch4: overflow in check_strnum() implies pure string
+ *
+ * Revision 5.3.1.4 1993/01/22 15:05:19 mike
+ * pow2->mpow2 for linux
+ *
+ * Revision 5.3.1.3 1993/01/22 14:18:33 mike
+ * const for strtod and ansi picky compilers
+ *
+ * Revision 5.3.1.2 1993/01/20 12:53:06 mike
+ * d_to_l()
+ *
+ * Revision 5.3.1.1 1993/01/15 03:33:37 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.3 1992/11/28 23:48:42 mike
+ * For internal conversion numeric->string, when testing
+ * if integer, use longs instead of ints so 16 and 32 bit
+ * systems behave the same
+ *
+ * Revision 5.2 1992/08/17 14:19:45 brennan
+ * patch2: After parsing, only bi_sprintf() uses string_buff.
+ *
+ * Revision 5.1 1991/12/05 07:55:41 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -29,7 +52,7 @@ the GNU General Public License, version 2, 1991.
#include "scan.h"
#include "repl.h"
-int pow2[NUM_CELL_TYPES] = {1,2,4,8,16,32,64,128,256,512} ;
+int mpow2[NUM_CELL_TYPES] = {1,2,4,8,16,32,64,128,256,512} ;
void cast1_to_d( cp )
register CELL *cp ;
@@ -131,7 +154,9 @@ two: cp++ ;
void cast1_to_s( cp )
register CELL *cp ;
-{ register int ival ;
+{
+ register long lval ;
+ char xbuff[260] ;
switch( cp->type )
{ case C_NOINIT :
@@ -141,13 +166,13 @@ void cast1_to_s( cp )
case C_DOUBLE :
- if ( (double) (ival = (int) cp->dval) == cp->dval )
- (void) sprintf(string_buff, "%d", ival) ;
+ lval = d_to_l(cp->dval) ;
+ if ( lval == cp->dval )
+ (void) sprintf(xbuff, INT_FMT, lval) ;
else
- (void) sprintf(string_buff ,
- string(CONVFMT)->str, cp->dval) ;
+ (void) sprintf(xbuff , string(CONVFMT)->str, cp->dval) ;
- cp->ptr = (PTR) new_STRING(string_buff) ;
+ cp->ptr = (PTR) new_STRING(xbuff) ;
break ;
case C_STRING : return ;
@@ -162,7 +187,9 @@ void cast1_to_s( cp )
void cast2_to_s( cp )
register CELL *cp ;
-{ register int ival ;
+{
+ register long lval ;
+ char xbuff[260] ;
switch( cp->type )
{ case C_NOINIT :
@@ -171,13 +198,14 @@ void cast2_to_s( cp )
break ;
case C_DOUBLE :
- if ( (double) (ival = (int) cp->dval) == cp->dval )
- (void) sprintf(string_buff, "%d", ival) ;
+
+ lval = d_to_l(cp->dval) ;
+ if ( lval == cp->dval )
+ (void) sprintf(xbuff, INT_FMT, lval) ;
else
- (void) sprintf(string_buff ,
- string(CONVFMT)->str, cp->dval) ;
+ (void) sprintf(xbuff , string(CONVFMT)->str, cp->dval) ;
- cp->ptr = (PTR) new_STRING(string_buff) ;
+ cp->ptr = (PTR) new_STRING(xbuff) ;
break ;
case C_STRING : goto two ;
@@ -199,13 +227,14 @@ two:
break ;
case C_DOUBLE :
- if ( (double) (ival = (int) cp->dval) == cp->dval )
- (void) sprintf(string_buff, "%d", ival) ;
+
+ lval = d_to_l(cp->dval) ;
+ if ( lval == cp->dval )
+ (void) sprintf(xbuff, INT_FMT, lval) ;
else
- (void) sprintf(string_buff ,
- string(CONVFMT)->str, cp->dval) ;
+ (void) sprintf(xbuff , string(CONVFMT)->str, cp->dval) ;
- cp->ptr = (PTR) new_STRING(string_buff) ;
+ cp->ptr = (PTR) new_STRING(xbuff) ;
break ;
case C_STRING : return ;
@@ -295,9 +324,8 @@ void check_strnum( cp )
#if FPE_TRAPS_ON
errno = 0 ;
cp->dval = strtod((char *)s, &test) ;
- if ( errno && cp->dval != 0.0 )
- rt_error(
- "overflow converting %s to double" , s) ;
+ /* treat overflow as pure string */
+ if ( errno && cp->dval != 0.0 ) return ;
#else
cp->dval = strtod((char *)s, &test) ;
#endif
@@ -322,6 +350,21 @@ void cast_to_REPL( cp )
}
+/* convert a double to long (this is not as simple as a
+ cast because the results are undefined if it won't fit).
+ Truncate large values to +MAX__LONG or -MAX__LONG
+ Send nans to -MAX__LONG
+*/
+
+long
+d_to_l(d)
+ double d ;
+{
+ if ( d >= MAX__LONG ) return MAX__LONG ;
+ if ( d > -MAX__LONG ) return (int) d ;
+ return -MAX__LONG ;
+}
+
#if HAVE_STRTOD==0
/* don't use this unless you really don't have strtod() because
@@ -329,8 +372,13 @@ void cast_to_REPL( cp )
(2) atof() may call the real strtod()
*/
+#if __STDC__ == 0
+#define const
+#endif
+
double strtod(s, endptr)
- char *s , **endptr ;
+ const char *s ;
+ char **endptr ;
{
register unsigned char *p ;
int flag ;
diff --git a/gnu/usr.bin/awk/code.c b/gnu/usr.bin/awk/code.c
index 9d830e803c9..2fb4ca537c9 100644
--- a/gnu/usr.bin/awk/code.c
+++ b/gnu/usr.bin/awk/code.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: code.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:08 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:43 brennan
+ * Revision 5.1 1991/12/05 07:55:43 brennan
* 1.1 pre-release
- *
+ *
*/
/* code.c */
diff --git a/gnu/usr.bin/awk/code.h b/gnu/usr.bin/awk/code.h
index ca15052813f..b45647b50b7 100644
--- a/gnu/usr.bin/awk/code.h
+++ b/gnu/usr.bin/awk/code.h
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: code.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:09 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:07 brennan
+ * Revision 5.1 1991/12/05 07:59:07 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/config.h b/gnu/usr.bin/awk/config.h
index 30067c878b9..f2c5681df7c 100644
--- a/gnu/usr.bin/awk/config.h
+++ b/gnu/usr.bin/awk/config.h
@@ -1,7 +1,6 @@
-
/********************************************
-bsd43_vax.h
-copyright 1991, Michael D. Brennan
+386bsd.h
+copyright 1993, Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,59 +10,29 @@ the GNU General Public License, version 2, 1991.
********************************************/
-/* $Log: config.h,v $
-/* Revision 1.2 1993/03/21 18:04:42 cgd
-/* after 0.2.2 "stable" patches applied
/*
- * Revision 1.1.1.1 93/03/21 09:54:09 cgd
- * initial import of 386bsd-0.1 sources
- *
- * Revision 1.2 1992/06/02 05:07:35 rich
- * Ported to 386bsd. Changes from vax BSD4.3 include usage of
- * fmod in libm.a, usage of void pointers, and usage of vfprintf
- * in libc.a. Floating point exceptions are not raised when
- * they should be, which causes the last fpe test to fail.
+ * $Log: config.h,v $
+ * Revision 1.3 1993/07/02 23:57:10 jtc
+ * Updated to mawk 1.1.4
*
- * Revision 1.1 1992/06/02 03:45:42 rich
+ * Revision 1.1 1993/02/05 02:20:10 mike
* Initial revision
*
- * Revision 4.1 91/09/25 11:41:07 brennan
- * VERSION 1.0
- *
- * Revision 3.2 91/08/13 09:04:09 brennan
- * VERSION .9994
- *
- * Revision 3.1 91/06/07 10:39:33 brennan
- * VERSION 0.995
- *
- *
- * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
- * -------------------- ----- ----------------------
- * CURRENT PATCH LEVEL: 1 00089
- * -------------------- ----- ----------------------
- *
- * 01 Mar 93 Chris Demetriou Adjust to life with strtod in libc
- *
*/
-/* BSD UNIX on 386BSD */
-
#ifndef CONFIG_H
-#define CONFIG_H 1
-
-#define BSD43_VAX
+#define CONFIG_H 1
-#define FPE_TRAPS_ON 1
-#define FPE_ZERODIVIDE FPE_FLTDIV_FAULT
-#define FPE_OVERFLOW FPE_FLTOVF_FAULT
+#define FPE_TRAPS_ON 1
+#define FPE_ZERODIVIDE FPE_FLTDIV_TRAP
+#define FPE_OVERFLOW FPE_FLTOVF_TRAP
#define HAVE_STRTOD 1
+
#define HAVE_MATHERR 0
-#define HAVE_FMOD 1
-#define HAVE_VOID_PTR 1
+#define DONT_PROTO_OPEN
#include "config/Idefault.h"
-
#endif /* CONFIG_H */
diff --git a/gnu/usr.bin/awk/config/Idefault.h b/gnu/usr.bin/awk/config/Idefault.h
index 76db198c6bf..1cb351093fa 100644
--- a/gnu/usr.bin/awk/config/Idefault.h
+++ b/gnu/usr.bin/awk/config/Idefault.h
@@ -12,55 +12,85 @@ the GNU General Public License, version 2, 1991.
/* $Log: Idefault.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:58:21 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 3.13 92/03/03 16:40:56 brennan
- * remove HAVE_PRINTF_HD
- *
- * Revision 3.12 91/11/16 15:37:29 brennan
- * add NO_BINMODE
- *
- * Revision 3.11 91/10/29 10:48:40 brennan
- * version 1.09
- *
- * Revision 3.10 91/10/23 10:46:34 brennan
- * MSDOS LM and SM
- *
- * Revision 3.9 91/10/14 09:52:48 brennan
- * added HAVE_PRINTF_HD
- *
- * Revision 3.8 91/09/30 08:11:22 brennan
- * added MAX__INT
- *
- * Revision 3.7 91/08/16 08:49:51 brennan
- * Carl's addition of SW_FP_CHECK for XNX23A
- *
- * Revision 3.6 91/08/13 09:04:05 brennan
- * VERSION .9994
- *
- * Revision 3.5 91/08/03 06:10:46 brennan
- * changed CHECK_DIVZERO macro
- *
- * Revision 3.4 91/08/03 05:35:59 brennan
- * changed name to Idefault.h
- *
- * Revision 3.3 91/06/28 04:36:28 brennan
- * adjustments with __STDC__
- *
- * Revision 3.3 91/06/19 10:21:37 brennan
- * changes for xenix_r2.h and gcc
- *
- * Revision 3.2 91/06/15 09:24:34 brennan
- * Carl's diffs for V7
- *
- * 06/11/91 C. Mascott add default D2BOOL
+ * Revision 3.18.1.1 1993/01/15 03:33:52 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 3.18 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 3.17 1992/11/26 15:35:52 mike
+ * don't assume __STDC__ implies HAVE_STRERROR
+ *
+ * Revision 3.16 1992/11/22 19:00:43 mike
+ * allow STDC assumptions to be overridden
+ *
+ * Revision 3.15 1992/07/08 16:16:08 brennan
+ * don't attempt any #def or #undef with __STDC__
*
- * Revision 3.1 91/06/07 10:38:46 brennan
- * VERSION 0.995
- *
*/
+
+#ifdef __STDC__
+#if __STDC__
+
+#undef HAVE_PROTOS
+#define HAVE_PROTOS 1
+#undef HAVE_VOID_PTR
+#define HAVE_VOID_PTR 1
+
+/* these can be overidden */
+
+#ifndef HAVE_STDARG_H
+#define HAVE_STDARG_H 1
+#endif
+
+#ifndef HAVE_STRING_H
+#define HAVE_STRING_H 1
+#endif
+
+#ifndef HAVE_STDLIB_H
+#define HAVE_STDLIB_H 1
+#endif
+
+#endif
+#endif
+
+#ifdef MSDOS
+
+#ifndef HAVE_REARGV
+#define HAVE_REARGV 0
+#endif
+
+#if HAVE_REARGV
+#define SET_PROGNAME() reargv(&argc,&argv) ; progname = argv[0]
+#else
+#define SET_PROGNAME() progname = "mawk"
+#endif
+
+#define MAX__INT 0x7fff
+
+#if HAVE_SMALL_MEMORY==0
+#define LM_DOS 1
+#else
+#define LM_DOS 0
+#endif
+
+#define SM_DOS (!LM_DOS)
+
+#define HAVE_REAL_PIPES 0
+#define HAVE_FAKE_PIPES 1
+
+#else /* not defined MSDOS */
+#define MSDOS 0
+#define LM_DOS 0
+#define SM_DOS 0
+
+#endif /* MSDOS */
+
+
/* The most common configuration is defined here:
no function prototypes
@@ -117,6 +147,10 @@ the GNU General Public License, version 2, 1991.
#define HAVE_FMOD 1
#endif
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR 0
+#endif
+
/* uses <varargs.h> instead of <stdarg.h> */
#ifndef HAVE_STDARG_H
#define HAVE_STDARG_H 0
@@ -148,13 +182,37 @@ the GNU General Public License, version 2, 1991.
#define HAVE_FAKE_PIPES 0
#endif
+/* don't have strerror() */
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR 0
+#endif
+
+#ifndef SET_PROGNAME
+#define SET_PROGNAME() { char *strrchr() , *p ;\
+ p = strrchr(argv[0],'/') ;\
+ progname = p ? p+1 : argv[0] ; }
+#endif
+
+
+
/*------------- machine ------------------------*/
/* ints are 32bits, two complement */
#ifndef MAX__INT
#define MAX__INT 0x7fffffff
+#define INT_FMT "%d"
+#endif
+
+#ifndef MAX__LONG
+#define MAX__LONG 0x7fffffff
+#endif
+
+#if MAX__INT <= 0x7fff
+#define SHORT_INTS
+#define INT_FMT "%ld"
#endif
+
/* default is IEEE754 and data space is not scarce */
#ifndef FPE_TRAPS_ON
@@ -188,6 +246,10 @@ the GNU General Public License, version 2, 1991.
#define TURN_OFF_FPE_TRAPS() /* nothing */
#endif
+#ifndef TURN_ON_FPE_TRAPS
+#define TURN_ON_FPE_TRAPS() /* nothing */
+#endif
+
#ifndef HAVE_SMALL_MEMORY
#define HAVE_SMALL_MEMORY 0
#endif
@@ -196,29 +258,6 @@ the GNU General Public License, version 2, 1991.
/*------------------------------------------------*/
-#ifndef __STDC__
-#define __STDC__ 0
-#endif
-
-#if __STDC__
-
-#undef HAVE_PROTOS
-#define HAVE_PROTOS 1
-#undef HAVE_VOID_PTR
-#define HAVE_VOID_PTR 1
-#undef HAVE_STDARG_H
-#define HAVE_STDARG_H 1
-#undef HAVE_STRING_H
-#define HAVE_STRING_H 1
-#endif
-
-#if __STDC__ && ! __GNUC__
-/* with gcc __STDC__ can be defined, but stdlib.h is missing */
-#undef HAVE_STDLIB_H
-#define HAVE_STDLIB_H 1
-#endif
-
-
/* the painfull case: we need to catch fpe's and look at errno
@@ -226,49 +265,6 @@ the GNU General Public License, version 2, 1991.
#define STDC_MATHERR ((SW_FP_CHECK || FPE_TRAPS_ON) && HAVE_MATHERR==0)
-/*-------------------MSDOS---------------------------------*/
-
-#ifdef MSDOS
-
-#ifndef HAVE_REARGV
-#define HAVE_REARGV 0
-#endif
-
-#undef MAX__INT
-#define MAX__INT 0x7fff
-
-#if HAVE_SMALL_MEMORY==0
-#define LM_DOS 1
-#else
-#define LM_DOS 0
-#endif
-
-#define SM_DOS (!LM_DOS)
-
-#undef HAVE_REAL_PIPES
-#define HAVE_REAL_PIPES 0
-#undef HAVE_FAKE_PIPES
-#define HAVE_FAKE_PIPES 1
-
-#if SM_DOS
-#ifdef NO_BINMODE
-#undef NO_BINMODE
-#define NO_BINMODE 1 /* hopefully no one needs this */
-#else
-#define NO_BINMODE 0
-#endif
-#else
-#define NO_BINMODE 0
-#endif /* SM_DOS */
-
-#else /* not defined MSDOS */
-#define MSDOS 0
-#define LM_DOS 0
-#define SM_DOS 0
-
-#endif /* MSDOS */
-
-/*----------------------------------------------------------*/
#if HAVE_PROTOS
@@ -277,13 +273,6 @@ the GNU General Public License, version 2, 1991.
#define PROTO(name, args) name()
#endif
-/* ultrix pukes if __STDC__ is defined 0 */
-/* SCO UNIX's cc (from Microsoft) sneezes if __STDC__ is re-#define-d */
-#if (__STDC__ == 0)
-#ifndef M_I386
-#undef __STDC__
-#endif
-#endif
/* for Think C on the Macintosh, sizeof(size_t) != sizeof(unsigned
* Rather than unilaterally imposing size_t, when not all compilers would
diff --git a/gnu/usr.bin/awk/da.c b/gnu/usr.bin/awk/da.c
index 61ac694aef6..07d84fd179a 100644
--- a/gnu/usr.bin/awk/da.c
+++ b/gnu/usr.bin/awk/da.c
@@ -12,12 +12,16 @@ the GNU General Public License, version 2, 1991.
/* $Log: da.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:11 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:45 brennan
+ * Revision 5.2 1992/07/25 21:35:25 brennan
+ * patch2
+ * fixed small typo on da of _PRE_DEC
+ *
+ * Revision 5.1 1991/12/05 07:55:45 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -79,11 +83,11 @@ F_POW_ASG, "f_pow_asg",
_POST_INC, "post_inc",
_POST_DEC, "post_dec",
_PRE_INC, "pre_inc",
-_PRE_INC, "pre_dec",
+_PRE_DEC, "pre_dec",
F_POST_INC, "f_post_inc",
F_POST_DEC, "f_post_dec",
F_PRE_INC, "f_pre_inc",
-F_PRE_INC, "f_pre_dec",
+F_PRE_DEC, "f_pre_dec",
_EQ, "eq",
_NEQ, "neq",
_LT, "lt",
diff --git a/gnu/usr.bin/awk/error.c b/gnu/usr.bin/awk/error.c
index bc43466e2cf..bbbf3ab9e78 100644
--- a/gnu/usr.bin/awk/error.c
+++ b/gnu/usr.bin/awk/error.c
@@ -1,7 +1,7 @@
/********************************************
error.c
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992 Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -12,29 +12,48 @@ the GNU General Public License, version 2, 1991.
/* $Log: error.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:12 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:48 brennan
+ * Revision 5.3 1993/01/22 14:55:46 mike
+ * trivial change for unexpected_char()
+ *
+ * Revision 5.2 1992/10/02 23:26:04 mike
+ * using vargs.h
+ *
+ * Revision 5.1 1991/12/05 07:55:48 brennan
* 1.1 pre-release
- *
+ *
*/
#include "mawk.h"
#include "scan.h"
#include "bi_vars.h"
+#include "vargs.h"
+
#ifndef EOF
#define EOF (-1)
#endif
-/* statics */
static void PROTO( rt_where, (void) ) ;
static void PROTO( unexpected_char, (void) ) ;
static void PROTO( missing, (int, char *, int) ) ;
static char *PROTO( type_to_str, (int) ) ;
+#if HAVE_STRERROR == 0
+#define strerror(n) ((n)>0&&(n)<sys_nerr?sys_errlist[n]:(char*)0)
+extern int sys_nerr ;
+extern char *sys_errlist[];
+#endif
+
+
+#ifdef USE_SIMPLE_VFPRINTF
+#define vfprintf simple_vfprintf
+#endif
+
+
extern int NR_flag ; /* on if tracking NR */
@@ -178,39 +197,26 @@ done :
if ( ++compile_error_count == MAX_COMPILE_ERRORS ) mawk_exit(1) ;
}
-/* system provided errnos and messages */
-#ifndef MSDOS_MSC /* don't need the declarations */
-#ifndef THINK_C /* don't WANT the declarations */
-extern int sys_nerr ;
-extern char *sys_errlist[] ;
-#endif
-#endif
-
-#if HAVE_STDARG_H
-#include <stdarg.h>
/* generic error message with a hook into the system error
messages if errnum > 0 */
-void errmsg(int errnum, char *format, ...)
-{ va_list args ;
+void errmsg VA_ALIST2(int , errnum, char *, format)
+ va_list args ;
fprintf(stderr, "%s: " , progname) ;
- va_start(args, format) ;
+
+ VA_START2(args, int, errnum, char *, format) ;
(void) vfprintf(stderr, format, args) ;
va_end(args) ;
-#ifdef THINK_C
- if ( errnum > 0 )
- fprintf(stderr, " (%s)" , strerror(errnum) ) ;
-#else
- if ( errnum > 0 && errnum < sys_nerr )
- fprintf(stderr, " (%s)" , sys_errlist[errnum]) ;
-#endif
+
+ if ( errnum > 0 ) fprintf(stderr, " (%s)" , strerror(errnum) ) ;
+
fprintf( stderr, "\n") ;
}
-void compile_error(char *format, ...)
-{ va_list args ;
+void compile_error VA_ALIST(char *, format)
+ va_list args ;
char *s0, *s1 ;
/* with multiple program files put program name in
@@ -221,79 +227,18 @@ void compile_error(char *format, ...)
{ s0 = s1 = "" ; }
fprintf(stderr, "%s: %s%sline %u: " , progname, s0, s1,token_lineno) ;
- va_start(args, format) ;
- vfprintf(stderr, format, args) ;
- va_end(args) ;
- fprintf(stderr, "\n") ;
- if ( ++compile_error_count == MAX_COMPILE_ERRORS ) mawk_exit(1) ;
-}
-
-void rt_error( char *format, ...)
-{ va_list args ;
-
- fprintf(stderr, "%s: run time error: " , progname ) ;
- va_start(args, format) ;
- vfprintf(stderr, format, args) ;
- va_end(args) ;
- putc('\n',stderr) ;
- rt_where() ;
- mawk_exit(1) ;
-}
-
-#else
-
-#include <varargs.h>
-
-/* void errmsg(errnum, format, ...) */
-
-void errmsg( va_alist)
- va_dcl
-{ va_list ap ;
- int errnum ;
- char *format ;
-
- fprintf(stderr, "%s: " , progname) ;
- va_start(ap) ;
- errnum = va_arg(ap, int) ;
- format = va_arg(ap, char *) ;
- (void) vfprintf(stderr, format, ap) ;
-#ifdef THINK_C
- if ( errnum > 0 )
- fprintf(stderr, " (%s)" , strerror(errnum) ) ;
-#else
- if ( errnum > 0 && errnum < sys_nerr )
- fprintf(stderr, " (%s)" , sys_errlist[errnum]) ;
-#endif
- fprintf( stderr, "\n") ;
-}
-
-void compile_error( va_alist )
- va_dcl
-{ va_list args ;
- char *format ;
- char *s0, *s1 ;
-
- if ( pfile_name ) /* print program filename too */
- { s0 = pfile_name ; s1 = ": " ; }
- else s0 = s1 = "" ;
-
- fprintf(stderr, "%s: %s%sline %u: " , progname, s0, s1,token_lineno) ;
- va_start(args) ;
- format = va_arg(args, char *) ;
+ VA_START(args, char *, format) ;
vfprintf(stderr, format, args) ;
va_end(args) ;
fprintf(stderr, "\n") ;
if ( ++compile_error_count == MAX_COMPILE_ERRORS ) mawk_exit(1) ;
}
-void rt_error( va_alist )
- va_dcl
-{ va_list args ;
- char *format ;
+void rt_error VA_ALIST( char *, format)
+ va_list args ;
fprintf(stderr, "%s: run time error: " , progname ) ;
- va_start(args) ;
- format = va_arg(args, char *) ;
+ VA_START(args, char *, format) ;
vfprintf(stderr, format, args) ;
va_end(args) ;
putc('\n',stderr) ;
@@ -301,16 +246,20 @@ void rt_error( va_alist )
mawk_exit(1) ;
}
-#endif
void bozo(s)
char *s ;
-{ errmsg(0, "bozo: %s" , s) ; mawk_exit(1) ; }
+{
+ errmsg(0, "bozo: %s" , s) ;
+ mawk_exit(1) ;
+}
void overflow(s, size)
char *s ; unsigned size ;
-{ errmsg(0 , "program limit exceeded: %s size=%u", s, size) ;
- mawk_exit(1) ; }
+{
+ errmsg(0 , "program limit exceeded: %s size=%u", s, size) ;
+ mawk_exit(1) ;
+}
/* print as much as we know about where a rt error occured */
@@ -340,7 +289,7 @@ static void unexpected_char()
{ int c = yylval.ival ;
fprintf(stderr, "%s: %u: ", progname, token_lineno) ;
- if ( c > ' ')
+ if ( c > ' ' && c < 127 )
fprintf(stderr, "unexpected character '%c'\n" , c) ;
else
fprintf(stderr, "unexpected character 0x%02x\n" , c) ;
@@ -370,3 +319,75 @@ void type_error(p)
}
+
+
+#ifdef USE_SIMPLE_VFPRINTF
+
+/* a minimal vfprintf */
+int simple_vfprintf( fp, format, argp)
+ FILE *fp ;
+ char *format ;
+ va_list argp ;
+{
+ char *q , *p, *t ;
+ int l_flag ;
+ char xbuff[64] ;
+
+ q = format ;
+ xbuff[0] = '%' ;
+
+ while ( *q != 0 )
+ {
+ if ( *q != '%' )
+ {
+ putc(*q, fp) ; q++ ; continue ;
+ }
+
+ /* mark the start with p */
+ p = ++q ; t = xbuff + 1 ;
+
+ if ( *q == '-' ) *t++ = *q++ ;
+ while ( scan_code[*(unsigned char*)q] == SC_DIGIT ) *t++ = *q++ ;
+ if ( *q == '.' )
+ { *t++ = *q++ ;
+ while ( scan_code[*(unsigned char*)q] == SC_DIGIT ) *t++ = *q++ ;
+ }
+
+ if ( *q == 'l' ) { l_flag = 1 ; *t++ = *q++ ; }
+ else l_flag = 0 ;
+
+
+ *t = *q++ ; t[1] = 0 ;
+
+ switch( *t )
+ {
+ case 'c' :
+ case 'd' :
+ case 'o' :
+ case 'x' :
+ case 'u' :
+ if ( l_flag ) fprintf(fp, xbuff, va_arg(argp,long) ) ;
+ else fprintf(fp, xbuff, va_arg(argp, int)) ;
+ break ;
+
+ case 's' :
+ fprintf(fp, xbuff, va_arg(argp, char*)) ;
+ break ;
+
+ case 'g' :
+ case 'f' :
+ fprintf(fp, xbuff, va_arg(argp, double)) ;
+ break ;
+
+ default:
+ putc('%', fp) ;
+ q = p ;
+ break ;
+ }
+ }
+ return 0 ; /* shut up */
+}
+
+#endif /* USE_SIMPLE_VFPRINTF */
+
+
diff --git a/gnu/usr.bin/awk/execute.c b/gnu/usr.bin/awk/execute.c
index cd2995020b8..61106b64b16 100644
--- a/gnu/usr.bin/awk/execute.c
+++ b/gnu/usr.bin/awk/execute.c
@@ -11,12 +11,40 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: execute.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:14 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:50 brennan
+ * Revision 5.7.1.1 1993/01/15 03:33:39 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.7 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.6 1992/11/29 18:57:50 mike
+ * field expressions convert to long so 16 bit and 32 bit
+ * systems behave the same
+ *
+ * Revision 5.5 1992/08/11 15:24:55 brennan
+ * patch2: F_PUSHA and FE_PUSHA
+ * If this is preparation for g?sub(r,s,$expr) or (++|--) on $expr,
+ * then if expr > NF, make sure $expr is set to ""
+ *
+ * Revision 5.4 1992/08/11 14:51:54 brennan
+ * patch2: $expr++ is numeric even if $expr is string.
+ * I forgot to do this earlier when handling x++ case.
+ *
+ * Revision 5.3 1992/07/08 17:03:30 brennan
+ * patch 2
+ * revert to version 1.0 comparisons, i.e.
+ * page 44-45 of AWK book
+ *
+ * Revision 5.2 1992/04/20 21:40:40 brennan
+ * patch 2
+ * x++ is numeric, even if x is string
+ *
+ * Revision 5.1 1991/12/05 07:55:50 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -32,16 +60,16 @@ the GNU General Public License, version 2, 1991.
#include "fin.h"
#include <math.h>
-/* static functions */
static int PROTO( compare, (CELL *) ) ;
-static void PROTO( eval_overflow, (void) ) ;
-
+static int PROTO( d_to_index, (double)) ;
#if NOINFO_SIGFPE
static char dz_msg[] = "division by zero" ;
#endif
#ifdef DEBUG
+static void PROTO( eval_overflow, (void) ) ;
+
#define inc_sp() if( ++sp == eval_stack+EVAL_STACK_SIZE )\
eval_overflow()
#else
@@ -140,7 +168,32 @@ void execute(cdp, sp, fp)
break ;
case F_PUSHA :
- if ( (CELL*)cdp->ptr != field && nf < 0 ) split_field0() ;
+ cp = (CELL*)cdp->ptr ;
+ if ( cp != field )
+ {
+ if ( nf < 0 ) split_field0() ;
+
+ if ( ! (
+#if LM_DOS
+ SAMESEG(cp,field) &&
+#endif
+ cp >= NF && cp <= LAST_PFIELD ) )
+ {
+ /* its a real field $1, $2 ...
+ If its greater than $NF, we have to
+ make sure its set to "" so that
+ (++|--) and g?sub() work right
+ */
+ t = field_addr_to_index(cp) ;
+ if ( t > nf )
+ {
+ cell_destroy(cp) ;
+ cp->type = C_STRING ;
+ cp->ptr = (PTR) &null_str ;
+ null_str.ref_cnt++ ;
+ }
+ }
+ }
/* fall thru */
case _PUSHA :
@@ -194,18 +247,28 @@ void execute(cdp, sp, fp)
break ;
case FE_PUSHA :
+
if ( sp->type != C_DOUBLE ) cast1_to_d(sp) ;
- if ( (t = (int) sp->dval) < 0 )
- rt_error( "negative field index $%d", t) ;
+
+ t = d_to_index(sp->dval) ;
if ( t && nf < 0 ) split_field0() ;
sp->ptr = (PTR) field_ptr(t) ;
+ if ( t > nf )
+ {
+ /* make sure its set to "" */
+ cp = sp->ptr ;
+ cell_destroy(cp) ;
+ cp->type = C_STRING ;
+ cp->ptr = (PTR) &null_str ;
+ null_str.ref_cnt++ ;
+ }
break ;
case FE_PUSHI :
+
if ( sp->type != C_DOUBLE ) cast1_to_d(sp) ;
- if ( (t = (int) sp->dval) < 0 )
- rt_error( "negative field index $%d", t) ;
+ t = d_to_index(sp->dval) ;
if ( nf < 0) split_field0() ;
if ( t <= nf ) (void) cellcpy(sp, field_ptr(t)) ;
@@ -673,14 +736,18 @@ void execute(cdp, sp, fp)
break ;
case _POST_INC :
- (void) cellcpy(sp, cp = (CELL *)sp->ptr) ;
+ cp = (CELL *)sp->ptr ;
if ( cp->type != C_DOUBLE ) cast1_to_d(cp) ;
+ sp->type = C_DOUBLE ;
+ sp->dval = cp->dval ;
cp->dval += 1.0 ;
break ;
case _POST_DEC :
- (void) cellcpy(sp, cp = (CELL *)sp->ptr) ;
+ cp = (CELL *)sp->ptr ;
if ( cp->type != C_DOUBLE ) cast1_to_d(cp) ;
+ sp->type = C_DOUBLE ;
+ sp->dval = cp->dval ;
cp->dval -= 1.0 ;
break ;
@@ -701,33 +768,35 @@ void execute(cdp, sp, fp)
case F_POST_INC :
cp = (CELL *) sp->ptr ;
- (void) cellcpy(sp, cellcpy(&tc, cp) ) ;
- cast1_to_d(&tc) ;
- tc.dval += 1.0 ;
+ (void) cellcpy(&tc, cp) ;
+ cast1_to_d(&tc) ;
+ sp->type = C_DOUBLE ;
+ sp->dval = tc.dval ;
+ tc.dval += 1.0 ;
field_assign(cp, &tc) ;
break ;
case F_POST_DEC :
cp = (CELL *) sp->ptr ;
- (void) cellcpy(sp, cellcpy(&tc, cp) ) ;
- cast1_to_d(&tc) ;
- tc.dval -= 1.0 ;
+ (void) cellcpy(&tc, cp) ;
+ cast1_to_d(&tc) ;
+ sp->type = C_DOUBLE ;
+ sp->dval = tc.dval ;
+ tc.dval -= 1.0 ;
field_assign(cp, &tc) ;
break ;
case F_PRE_INC :
cp = (CELL *) sp->ptr ;
- cast1_to_d(cellcpy(&tc, cp)) ;
- sp->dval = tc.dval += 1.0 ;
- sp->type = C_DOUBLE ;
+ cast1_to_d(cellcpy(sp, cp)) ;
+ sp->dval += 1.0 ;
field_assign(cp, sp) ;
break ;
case F_PRE_DEC :
cp = (CELL *) sp->ptr ;
- cast1_to_d(cellcpy(&tc, cp)) ;
- sp->dval = tc.dval -= 1.0 ;
- sp->type = C_DOUBLE ;
+ cast1_to_d(cellcpy(sp, cp)) ;
+ sp->dval -= 1.0 ;
field_assign(cp, sp) ;
break ;
@@ -859,7 +928,8 @@ void execute(cdp, sp, fp)
case _EXIT :
if ( sp->type != C_DOUBLE ) cast1_to_d(sp) ;
- exit_code = (int) sp-- -> dval ;
+ exit_code = d_to_i(sp->dval) ;
+ sp-- ;
/* fall thru */
case _EXIT0 :
@@ -1056,6 +1126,7 @@ reswitch :
default :
bozo("bad cell type in call to test") ;
}
+ return 0 ; /*can't get here: shutup */
}
/* compare cells at cp and cp+1 and
@@ -1064,7 +1135,6 @@ reswitch :
static int compare(cp)
register CELL *cp ;
{ int k ;
- CELL *dp, *sp ;
reswitch :
@@ -1077,28 +1147,22 @@ reswitch :
cp->dval < (cp+1)->dval ? -1 : 0 ;
case TWO_STRINGS :
+ case STRING_AND_STRNUM :
+ two_s:
k = strcmp(string(cp)->str, string(cp+1)->str) ;
free_STRING( string(cp) ) ;
free_STRING( string(cp+1) ) ;
return k ;
- case STRING_AND_STRNUM : /* posix numeric string bozosity */
- case NOINIT_AND_STRING :
- case DOUBLE_AND_STRING :
- if ( cp->type == C_STRING ) { sp = cp ; dp = cp+1 ; }
- else { dp = cp ; sp = cp+1 ; }
-
- check_strnum(sp) ;
- if ( sp->type == C_STRING ) cast1_to_s(dp) ;
- goto reswitch ;
-
-
case NOINIT_AND_DOUBLE :
case NOINIT_AND_STRNUM :
case DOUBLE_AND_STRNUM :
case TWO_STRNUMS :
cast2_to_d(cp) ; goto two_d ;
+ case NOINIT_AND_STRING :
+ case DOUBLE_AND_STRING :
+ cast2_to_s(cp) ; goto two_s ;
case TWO_MBSTRNS :
check_strnum(cp) ; check_strnum(cp+1) ;
@@ -1114,6 +1178,7 @@ reswitch :
default : /* there are no default cases */
bozo("bad cell type passed to compare") ;
}
+ return 0 ; /* shut up */
}
/* does not assume target was a cell, if so
@@ -1181,3 +1246,21 @@ void DB_cell_destroy(cp) /* HANGOVER time */
}
#endif
+
+
+
+/* convert a double d to a field index $d -> $i */
+static int
+d_to_index( d )
+ double d ;
+{
+
+ if ( d > MAX_FIELD )
+ rt_overflow("maximum number of fields", MAX_FIELD) ;
+
+ if ( d >= 0.0 ) return (int) d ;
+
+ /* might include nan */
+ rt_error("negative field index $%.6g", d) ;
+ return 0 ; /* shutup */
+}
diff --git a/gnu/usr.bin/awk/fcall.c b/gnu/usr.bin/awk/fcall.c
index 9e7f67425f6..d8aee53d696 100644
--- a/gnu/usr.bin/awk/fcall.c
+++ b/gnu/usr.bin/awk/fcall.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/*$Log: fcall.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:16 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:54 brennan
+ * Revision 5.1 1991/12/05 07:55:54 brennan
* 1.1 pre-release
- *
+ *
*/
#include "mawk.h"
diff --git a/gnu/usr.bin/awk/field.c b/gnu/usr.bin/awk/field.c
index a42fb7ac543..918b5416a68 100644
--- a/gnu/usr.bin/awk/field.c
+++ b/gnu/usr.bin/awk/field.c
@@ -11,12 +11,29 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: field.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:17 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:55:57 brennan
+ * Revision 5.4.1.2 1993/01/20 12:53:08 mike
+ * d_to_l()
+ *
+ * Revision 5.4.1.1 1993/01/15 03:33:42 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.4 1992/11/29 22:52:11 mike
+ * double->string conversions uses long ints for 16/32 bit
+ * compatibility.
+ * Fixed small LM_DOS bozo.
+ *
+ * Revision 5.3 1992/08/17 14:21:10 brennan
+ * patch2: After parsing, only bi_sprintf() uses string_buff.
+ *
+ * Revision 5.2 1992/07/10 16:17:10 brennan
+ * MsDOS: remove NO_BINMODE macro
+ *
+ * Revision 5.1 1991/12/05 07:55:57 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -254,7 +271,11 @@ void field_assign( fp, cp)
if ( nf < 0 ) split_field0() ;
#if LM_DOS
- if ( !SAMESEG(fp,field) ) goto lm_dos_label ;
+ if ( !SAMESEG(fp,field) )
+ {
+ i = -1 ;
+ goto lm_dos_label ;
+ }
#endif
switch( i = (fp - field) )
@@ -266,7 +287,7 @@ void field_assign( fp, cp)
(void) cellcpy(NF, cellcpy(&c,cp) ) ;
if ( c.type != C_DOUBLE ) cast1_to_d(&c) ;
- if ( (j = (int) c.dval) < 0 )
+ if ( (j = d_to_i(c.dval)) < 0 )
rt_error("negative value assigned to NF") ;
if ( j > nf )
@@ -315,11 +336,12 @@ void field_assign( fp, cp)
/* It's a string, but if it's really goofy and CONVFMT,
it could still damage us. Test it .
*/
- string_buff[256] = 0 ;
- (void) sprintf(string_buff,
- string(fp)->str, 3.1459) ;
- if ( string_buff[256] )
- rt_error("CONVFMT assigned unusable value") ;
+ char xbuff[512] ;
+
+ xbuff[256] = 0 ;
+ (void) sprintf( xbuff, string(fp)->str, 3.1459) ;
+ if ( xbuff[256] )
+ rt_error("CONVFMT assigned unusable value") ;
}
break ;
@@ -403,19 +425,22 @@ static void build_field0()
if ( cp->type < C_STRING )
{ /* use the string field temporarily */
if ( cp->type == C_NOINIT )
- { cp->ptr = (PTR) &null_str ;
+ {
+ cp->ptr = (PTR) &null_str ;
null_str.ref_cnt++ ;
}
else /* its a double */
- { int ival ;
+ {
+ long ival ;
+ char xbuff[260] ;
- if ( (double)(ival = (int)cp->dval) == cp->dval )
- (void) sprintf(string_buff, "%d", ival) ;
+ ival = d_to_l(cp->dval) ;
+ if ( ival == cp->dval )
+ (void) sprintf(xbuff, INT_FMT, ival) ;
else
- (void) sprintf(string_buff,
- string(CONVFMT)->str, cp->dval) ;
+ (void) sprintf(xbuff, string(CONVFMT)->str, cp->dval) ;
- cp->ptr = (PTR) new_STRING(string_buff) ;
+ cp->ptr = (PTR) new_STRING(xbuff) ;
}
}
@@ -572,13 +597,13 @@ static void load_field_ov()
}
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
int binmode() /* read current value of BINMODE */
{ CELL c ;
cast1_to_d(cellcpy(&c, BINMODE)) ;
- return (int) c.dval ;
+ return d_to_i(c.dval) ;
}
/* set BINMODE and RS and ORS
diff --git a/gnu/usr.bin/awk/field.h b/gnu/usr.bin/awk/field.h
index 5efbb3a8c1e..4bd08251143 100644
--- a/gnu/usr.bin/awk/field.h
+++ b/gnu/usr.bin/awk/field.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: field.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:19 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.2 92/01/06 08:10:24 brennan
+ * Revision 5.2 1992/01/06 08:10:24 brennan
* set_binmode() proto for MSDOS
- *
+ *
* Revision 5.1 91/12/05 07:59:16 brennan
* 1.1 pre-release
*
diff --git a/gnu/usr.bin/awk/files.c b/gnu/usr.bin/awk/files.c
index de85e2ef5f6..95b716337f6 100644
--- a/gnu/usr.bin/awk/files.c
+++ b/gnu/usr.bin/awk/files.c
@@ -1,7 +1,7 @@
/********************************************
files.c
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992. Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,9 +11,26 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: files.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:20 jtc
+/*Updated to mawk 1.1.4
/*
+ * Revision 5.5 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.4 1992/07/10 16:10:30 brennan
+ * patch2
+ * MsDOS: remove useless NO_BINMODE macro
+ * get process exit code on in pipes
+ *
+ * Revision 5.3 1992/04/07 20:21:17 brennan
+ * patch 2
+ * unbuffered output to a tty
+ *
+ * Revision 5.2 1992/04/07 16:03:08 brennan
+ * patch 2
+ * allow same filename for output and input, but use different descriptors
+ * E.g. < "/dev/tty" and > "/dev/tty"
+ *
* Revision 5.1 91/12/05 07:56:00 brennan
* 1.1 pre-release
*
@@ -26,6 +43,10 @@ the GNU General Public License, version 2, 1991.
#include "memory.h"
#include "fin.h"
+static FILE *PROTO(tfopen, (char*,char*)) ;
+static void PROTO(add_to_child_list, (int,int)) ;
+static struct child *PROTO(remove_from_child_list, (int)) ;
+extern int PROTO(isatty, (int)) ;
#ifdef V7
#include <sgtty.h> /* defines FIOCLEX */
@@ -49,22 +70,20 @@ typedef struct file {
struct file *link ;
STRING *name ;
short type ;
-int pid ; /* we need to wait() when we close an out pipe */
+int pid ; /* we need to wait() when we close a pipe */
/* holds temp file index under MSDOS */
+
+#if HAVE_FAKE_PIPES
+int inpipe_exit ;
+#endif
+
PTR ptr ; /* FIN* or FILE* */
} FILE_NODE ;
static FILE_NODE *file_list ;
-void set_stderr()
-{
- file_list = ZMALLOC(FILE_NODE) ;
- file_list->link = (FILE_NODE*) 0 ;
- file_list->type = F_TRUNC ;
- file_list->name = new_STRING("/dev/stderr") ;
- file_list->ptr = (PTR) stderr ;
-}
+/* find a file on file_list */
PTR file_find( sval, type )
STRING *sval ;
int type ;
@@ -77,26 +96,26 @@ PTR file_find( sval, type )
{
if ( !p ) /* open a new one */
{
- p = (FILE_NODE*) zmalloc(sizeof(FILE_NODE)) ;
+ p = ZMALLOC(FILE_NODE) ;
switch( p->type = type )
{
case F_TRUNC :
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
ostr = (binmode()&2) ? "wb" : "w" ;
#else
ostr = "w" ;
#endif
- if ( !(p->ptr = (PTR) fopen(name, ostr)) )
+ if ( !(p->ptr = (PTR) tfopen(name, ostr)) )
goto out_failure ;
break ;
case F_APPEND :
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
ostr = (binmode()&2) ? "ab" : "a" ;
#else
ostr = "a" ;
#endif
- if ( !(p->ptr = (PTR) fopen(name, ostr)) )
+ if ( !(p->ptr = (PTR) tfopen(name, ostr)) )
goto out_failure ;
break ;
@@ -132,18 +151,21 @@ PTR file_find( sval, type )
break ; /* while loop */
}
- if ( strcmp(name, p->name->str) == 0 )
- { /* no distinction between F_APPEND and F_TRUNC here */
- if ( p->type != type &&
- (p->type < F_APPEND || type < F_APPEND)) goto type_failure ;
+ /* search is by name and type */
+ if ( strcmp(name, p->name->str) == 0 &&
+ ( p->type == type ||
+ /* no distinction between F_APPEND and F_TRUNC here */
+ p->type >= F_APPEND && type >= F_APPEND ))
+
+ { /* found */
if ( !q ) /*at front of list */
return p->ptr ;
/* delete from list for move to front */
q->link = p->link ;
- break ;
+ break ; /* while loop */
}
q = p ; p = p->link ;
- }
+ } /* end while loop */
/* put p at the front of the list */
p->link = file_list ;
@@ -153,20 +175,21 @@ out_failure:
errmsg(errno, "cannot open \"%s\" for output", name) ;
mawk_exit(1) ;
-type_failure :
- rt_error("use of file \"%s\"\n\tis inconsistent with previous use",
- name) ;
}
-/* close a file and delete it's node from the file_list */
+/* Close a file and delete it's node from the file_list.
+ Walk the whole list, in case a name has two nodes,
+ e.g. < "/dev/tty" and > "/dev/tty"
+*/
int file_close( sval )
STRING *sval ;
{ register FILE_NODE *p = file_list ;
FILE_NODE *q = (FILE_NODE *) 0 ; /* trails p */
+ FILE_NODE *hold ;
char *name = sval->str ;
- int retval = 0 ;
+ int retval = -1 ;
while ( p )
if ( strcmp(name,p->name->str) == 0 ) /* found */
@@ -176,6 +199,7 @@ int file_close( sval )
case F_TRUNC :
case F_APPEND :
(void) fclose((FILE *) p->ptr) ;
+ retval = 0 ;
break ;
case PIPE_OUT :
@@ -191,6 +215,7 @@ int file_close( sval )
case F_IN :
FINclose((FIN *) p->ptr) ;
+ retval = 0 ;
break ;
case PIPE_IN :
@@ -200,22 +225,25 @@ int file_close( sval )
retval = wait_for(p->pid) ;
#endif
#if HAVE_FAKE_PIPES
- (void) unlink(tmp_file_name(p->pid)) ;
+ {
+ char xbuff[100] ;
+ (void) unlink(tmp_file_name(p->pid,xbuff)) ;
+ retval = p->inpipe_exit ;
+ }
#endif
break ;
}
free_STRING(p->name) ;
- if ( q ) q->link = p->link ;
- else file_list = p->link ;
+ hold = p ;
+ if ( q ) q->link = p = p->link ;
+ else file_list = p = p->link ;
- zfree(p, sizeof(FILE_NODE)) ;
- return retval ;
+ ZFREE(hold) ;
}
else { q = p ; p = p->link ; }
- /* its not on the list */
- return -1 ;
+ return retval ;
}
/* When we exit, we need to close and wait for all output pipes */
@@ -238,13 +266,14 @@ void close_out_pipes()
void close_fake_pipes()
{ register FILE_NODE *p = file_list ;
+ char xbuff[100] ;
/* close input pipes first to free descriptors for children */
while ( p )
{
if ( p->type == PIPE_IN )
{ FINclose((FIN *) p->ptr) ;
- (void) unlink(tmp_file_name(p->pid)) ;
+ (void) unlink(tmp_file_name(p->pid,xbuff)) ;
}
p = p->link ;
}
@@ -260,8 +289,8 @@ void close_fake_pipes()
p = p->link ;
}
}
-#endif
-#endif
+#endif /* HAVE_FAKE_PIPES */
+#endif /* ! HAVE_REAL_PIPES */
/* hardwire to /bin/sh for portability of programs */
char *shell = "/bin/sh" ;
@@ -390,3 +419,53 @@ int wait_for(pid)
}
#endif /* HAVE_REAL_PIPES */
+void set_stderr()
+{
+ file_list = ZMALLOC(FILE_NODE) ;
+ file_list->link = (FILE_NODE*) 0 ;
+ file_list->type = F_TRUNC ;
+ file_list->name = new_STRING("/dev/stderr") ;
+ file_list->ptr = (PTR) stderr ;
+}
+
+/* fopen() but no buffering to ttys */
+static FILE *tfopen(name, mode)
+ char *name, *mode ;
+{
+ FILE *retval = fopen(name,mode) ;
+
+ if ( retval )
+ {
+ if ( isatty(fileno(retval)) ) setbuf(retval, (char*)0) ;
+ else
+ {
+#if LM_DOS
+ enlarge_output_buffer(retval) ;
+#endif
+ }
+ }
+ return retval ;
+}
+
+#if LM_DOS
+void enlarge_output_buffer( fp )
+ FILE *fp ;
+{
+ if ( setvbuf(fp, (char*) 0, _IOFBF, BUFFSZ) < 0 )
+ {
+ errmsg(errno, "setvbuf failed on fileno %d", fileno(fp)) ;
+ mawk_exit(1) ;
+ }
+}
+#endif
+
+#if MSDOS
+void
+stdout_init()
+{
+#if LM_DOS
+ if ( ! isatty(1) ) enlarge_output_buffer(stdout) ;
+#endif
+ if ( binmode() & 2 ) { setmode(1,O_BINARY) ; setmode(2,O_BINARY) ; }
+}
+#endif /* MSDOS */
diff --git a/gnu/usr.bin/awk/files.h b/gnu/usr.bin/awk/files.h
index b24d0945fcf..022a8b49e23 100644
--- a/gnu/usr.bin/awk/files.h
+++ b/gnu/usr.bin/awk/files.h
@@ -11,12 +11,15 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: files.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:22 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:18 brennan
+ * Revision 5.2 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.1 1991/12/05 07:59:18 brennan
* 1.1 pre-release
- *
+ *
*/
#ifndef FILES_H
@@ -40,13 +43,14 @@ void PROTO( close_out_pipes, (void) ) ;
#if HAVE_FAKE_PIPES
void PROTO(close_fake_pipes, (void)) ;
int PROTO(close_fake_outpipe, (char *,int)) ;
-char *PROTO(tmp_file_name, (int)) ;
+char *PROTO(tmp_file_name, (int, char*)) ;
#endif
#if MSDOS
int PROTO(DOSexec, (char *)) ;
int PROTO(binmode, (void)) ;
void PROTO(set_binmode, (int)) ;
+void PROTO(enlarge_output_buffer, (FILE*)) ;
#endif
diff --git a/gnu/usr.bin/awk/fin.c b/gnu/usr.bin/awk/fin.c
index 16ab1b85ccc..48decc652a6 100644
--- a/gnu/usr.bin/awk/fin.c
+++ b/gnu/usr.bin/awk/fin.c
@@ -1,7 +1,7 @@
/********************************************
fin.c
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992. Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,13 +11,26 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: fin.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:23 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.2 92/02/21 13:30:08 brennan
- * fixed bug that free'd FILENAME twice if
+ * Revision 5.6 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.5 1992/07/28 15:11:30 brennan
+ * minor change in finding eol, needed for MsDOS
+ *
+ * Revision 5.4 1992/07/10 16:17:10 brennan
+ * MsDOS: remove NO_BINMODE macro
+ *
+ * Revision 5.3 1992/07/08 16:14:27 brennan
+ * FILENAME and FNR retain last values in the
+ * END block.
+ *
+ * Revision 5.2 1992/02/21 13:30:08 brennan
+ * fixed bug that free'd FILENAME twice if
* command line was var=value only
- *
+ *
* Revision 5.1 91/12/05 07:56:02 brennan
* 1.1 pre-release
*
@@ -37,7 +50,10 @@ the GNU General Public License, version 2, 1991.
#include <fcntl.h>
#endif
-/* This file handles input buffering */
+/* This file handles input files. Opening, closing,
+ buffering and (most important) splitting files into
+ records, FINgets().
+*/
#ifndef MSDOS_MSC
extern int errno ;
@@ -79,14 +95,14 @@ FIN *FINopen( filename, main_flag )
{ int fd ;
int oflag = O_RDONLY ;
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
int bm = binmode() & 1 ;
if ( bm ) oflag |= O_BINARY ;
#endif
if ( filename[0] == '-' && filename[1] == 0 )
{
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
if ( bm ) setmode(0, O_BINARY) ;
#endif
return FINdopen(0, main_flag) ;
@@ -162,8 +178,9 @@ restart :
}
else /* return this line */
{
- if ( !(p = strchr(fin->buff, '\n')) )
- p = fin->buff + BUFFSZ + 1 ; /* unlikely to occur */
+ /* find eol */
+ p = fin->buff ;
+ while ( *p != '\n' && *p != 0 ) p++ ;
*p = 0 ; *len_p = p - fin->buff ;
fin->buffp = p ;
@@ -273,6 +290,16 @@ static char *enlarge_fin_buffer(fin)
unsigned r ;
unsigned oldsize = fin->nbuffs*BUFFSZ+1 ;
+#if LM_DOS
+ /* I'm not sure this can really happen:
+ avoid "16bit wrap" */
+ if ( fin->nbuffs == MAX_BUFFS )
+ {
+ errmsg(0, "out of input buffer space") ;
+ mawk_exit(1) ;
+ }
+#endif
+
fin->buffp =
fin->buff = (char *) zrealloc(fin->buff, oldsize, oldsize+BUFFSZ);
fin->nbuffs++ ;
@@ -342,14 +369,21 @@ static void set_main_to_stdin()
cell_destroy( FILENAME ) ;
FILENAME->type = C_STRING ;
FILENAME->ptr = (PTR) new_STRING( "-") ;
+ cell_destroy(FNR) ;
+ FNR->type = C_DOUBLE ;
+ FNR->dval = 0.0 ;
main_fin = FINdopen(0, 1) ;
}
+/* this gets called once to get the input stream going.
+ It is called after the execution of the BEGIN block
+ unless there is a getline inside BEGIN {}
+*/
void open_main()
{ CELL argc ;
-#if MSDOS && NO_BINMODE==0 /* set input modes */
+#if MSDOS
int k = binmode() ;
if ( k & 1 ) setmode(0, O_BINARY) ;
@@ -363,6 +397,7 @@ void open_main()
else (void) next_main(1) ;
}
+/* get the next command line file open */
static FIN *next_main(open_flag)
int open_flag ; /* called by open_main() if on */
{
@@ -376,13 +411,10 @@ static FIN *next_main(open_flag)
c_argi.type = C_DOUBLE ;
if ( main_fin ) FINclose(main_fin) ;
- cell_destroy( FILENAME ) ;
- FILENAME->type = C_NOINIT ;
- /* so don't free again if we go to set_main_to_stdin() */
- cell_destroy( FNR ) ;
- FNR->type = C_DOUBLE ;
- FNR->dval = 0.0 ;
+ /* FILENAME and FNR don't change unless we really open
+ a new file */
+ /* make a copy of ARGC to avoid side effect */
if ( cellcpy(&argc, ARGC)->type != C_DOUBLE )
cast1_to_d(&argc) ;
@@ -399,6 +431,7 @@ static FIN *next_main(open_flag)
cp = cellcpy(&argval, cp) ;
if ( cp->type < C_STRING ) cast1_to_s(cp) ;
if ( string(cp)->len == 0 ) continue ;
+ /* file argument is "" */
/* it might be a command line assignment */
if ( is_cmdline_assign(string(cp)->str) ) continue ;
@@ -407,9 +440,14 @@ static FIN *next_main(open_flag)
but posix says we should quit */
if ( ! (main_fin = FINopen( string(cp)->str, 1 )) ) mawk_exit(1) ;
- /* success */
+ /* success -- set FILENAME and FNR */
+ cell_destroy(FILENAME) ;
(void) cellcpy(FILENAME , cp ) ;
free_STRING( string(cp) ) ;
+ cell_destroy(FNR) ;
+ FNR->type = C_DOUBLE ;
+ FNR->dval = 0.0 ;
+
return main_fin ;
}
/* failure */
@@ -419,9 +457,6 @@ static FIN *next_main(open_flag)
{ set_main_to_stdin() ; return main_fin ; }
/* real failure */
- FILENAME->type = C_STRING ;
- FILENAME->ptr = (PTR) new_STRING( "" ) ;
-
{ /* this is how we mark EOF on main_fin */
static char dead_buff = 0 ;
static FIN dead_main = {0, (FILE*)0, &dead_buff, &dead_buff,
diff --git a/gnu/usr.bin/awk/fin.h b/gnu/usr.bin/awk/fin.h
index e3da7209691..4cb9564bf60 100644
--- a/gnu/usr.bin/awk/fin.h
+++ b/gnu/usr.bin/awk/fin.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: fin.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:24 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.2 92/01/06 08:16:24 brennan
+ * Revision 5.2 1992/01/06 08:16:24 brennan
* setmode() proto for MSDOS
- *
+ *
* Revision 5.1 91/12/05 07:59:20 brennan
* 1.1 pre-release
*
diff --git a/gnu/usr.bin/awk/hash.c b/gnu/usr.bin/awk/hash.c
index 09e40cf6afc..30073ad318f 100644
--- a/gnu/usr.bin/awk/hash.c
+++ b/gnu/usr.bin/awk/hash.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: hash.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:26 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:05 brennan
+ * Revision 5.1 1991/12/05 07:56:05 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/init.c b/gnu/usr.bin/awk/init.c
index a7c05f31e96..7bf7336a197 100644
--- a/gnu/usr.bin/awk/init.c
+++ b/gnu/usr.bin/awk/init.c
@@ -12,12 +12,18 @@ the GNU General Public License, version 2, 1991.
/* $Log: init.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:29 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.2 92/01/09 08:46:14 brennan
+ * Revision 5.4 1992/12/24 01:58:19 mike
+ * 1.1.2d changes for MsDOS
+ *
+ * Revision 5.3 1992/07/10 16:17:10 brennan
+ * MsDOS: remove NO_BINMODE macro
+ *
+ * Revision 5.2 1992/01/09 08:46:14 brennan
* small change for MSC
- *
+ *
* Revision 5.1 91/12/05 07:56:07 brennan
* 1.1 pre-release
*
@@ -37,6 +43,9 @@ the GNU General Public License, version 2, 1991.
#include <console.h>
#endif
+#if MSDOS
+#include <fcntl.h>
+#endif
static void PROTO( process_cmdline , (int, char **) ) ;
static void PROTO( set_ARGV, (int, char **, int)) ;
@@ -45,17 +54,20 @@ static void PROTO( bad_option, (char *)) ;
extern void PROTO( print_version, (void) ) ;
extern int PROTO( is_cmdline_assign, (char*)) ;
-#if 0
-#if MSDOS && ! HAVE_REARGV
-#include <fcntl.h>
-static void PROTO(emit_prompt, (void) ) ;
+#if MSDOS
+void PROTO(stdout_init,(void)) ;
+#if HAVE_REARGV
+void PROTO(reargv, (int*,char***)) ;
#endif
#endif
+char *progname ;
void initialize(argc, argv)
int argc ; char **argv ;
{
+ SET_PROGNAME() ;
+
bi_vars_init() ; /* load the builtin variables */
bi_funct_init() ; /* load the builtin functions */
kw_init() ; /* load the keywords */
@@ -67,7 +79,7 @@ void initialize(argc, argv)
argc = ccommand(&argv);
#endif
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
{ char *p = getenv("MAWKBINMODE") ;
if ( p ) set_binmode( atoi(p) ) ;
@@ -80,6 +92,10 @@ void initialize(argc, argv)
code_init() ;
fpe_init() ;
set_stderr() ;
+
+#if MSDOS
+ stdout_init() ;
+#endif
}
void compile_cleanup()
@@ -169,7 +185,7 @@ static void process_cmdline(argc, argv)
sprintf_limit = sprintf_buff + x ;
}
}
-#if MSDOS && NO_BINMODE==0
+#if MSDOS
else
if ( optarg[0] == 'B' )
{
diff --git a/gnu/usr.bin/awk/init.h b/gnu/usr.bin/awk/init.h
index 0dde871f294..81e4362e78b 100644
--- a/gnu/usr.bin/awk/init.h
+++ b/gnu/usr.bin/awk/init.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: init.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:30 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:22 brennan
+ * Revision 5.1 1991/12/05 07:59:22 brennan
* 1.1 pre-release
- *
+ *
*/
/* init.h */
diff --git a/gnu/usr.bin/awk/jmp.c b/gnu/usr.bin/awk/jmp.c
index 753f20acf0e..5d354727449 100644
--- a/gnu/usr.bin/awk/jmp.c
+++ b/gnu/usr.bin/awk/jmp.c
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: jmp.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:31 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:10 brennan
+ * Revision 5.1 1991/12/05 07:56:10 brennan
* 1.1 pre-release
- *
+ *
*/
/* this module deals with back patching jumps, breaks and continues,
diff --git a/gnu/usr.bin/awk/jmp.h b/gnu/usr.bin/awk/jmp.h
index 147c4e34890..ac1c4806548 100644
--- a/gnu/usr.bin/awk/jmp.h
+++ b/gnu/usr.bin/awk/jmp.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: jmp.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:32 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:24 brennan
+ * Revision 5.1 1991/12/05 07:59:24 brennan
* 1.1 pre-release
- *
+ *
*/
#ifndef JMP_H
diff --git a/gnu/usr.bin/awk/kw.c b/gnu/usr.bin/awk/kw.c
index 5cab58ae07d..09ec59379c2 100644
--- a/gnu/usr.bin/awk/kw.c
+++ b/gnu/usr.bin/awk/kw.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: kw.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:33 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:12 brennan
+ * Revision 5.1 1991/12/05 07:56:12 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/main.c b/gnu/usr.bin/awk/main.c
index aca5e362d9f..00dd6fcb942 100644
--- a/gnu/usr.bin/awk/main.c
+++ b/gnu/usr.bin/awk/main.c
@@ -11,12 +11,18 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: main.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:35 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:14 brennan
+ * Revision 5.2.1.1 1993/01/15 03:33:44 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.2 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.1 1991/12/05 07:56:14 brennan
* 1.1 pre-release
- *
+ *
*/
@@ -32,43 +38,15 @@ the GNU General Public License, version 2, 1991.
#include "files.h"
#include <stdio.h>
-#if MSDOS
-void reargv(int *, char ***) ;
-#endif
-
-#if LM_DOS && __TURBOC__
-extern unsigned _stklen = 16 * 1024U ;
- /* 4K of stack is enough for a user function call
- nesting depth of 75 so this is enough for 300 */
-#endif
-
-
-extern int program_fd ;
-char *progname ;
short mawk_state ; /* 0 is compiling */
int exit_code ;
-
+int
main(argc , argv )
int argc ; char **argv ;
{
-#if MSDOS
- progname = "mawk" ;
-#if HAVE_REARGV
- reargv(&argc, &argv) ;
-#endif
-#else /* MSDOS */
-#ifdef THINK_C
- progname = "MacMAWK";
-#else /* THINK_C */
- { char *strrchr() ;
- char *p = strrchr(argv[0], '/') ;
- progname = p ? p+1 : argv[0] ; }
-#endif
-#endif
-
initialize(argc, argv) ;
if ( parse() || compile_error_count ) mawk_exit(1) ;
diff --git a/gnu/usr.bin/awk/makescan.c b/gnu/usr.bin/awk/makescan.c
index 0ba7cf69036..80276a93117 100644
--- a/gnu/usr.bin/awk/makescan.c
+++ b/gnu/usr.bin/awk/makescan.c
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: makescan.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:38 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:16 brennan
+ * Revision 5.1 1991/12/05 07:56:16 brennan
* 1.1 pre-release
- *
+ *
*/
/* source for makescan.exe which builds the scancode[]
diff --git a/gnu/usr.bin/awk/matherr.c b/gnu/usr.bin/awk/matherr.c
index b7b526e4621..5849b36b736 100644
--- a/gnu/usr.bin/awk/matherr.c
+++ b/gnu/usr.bin/awk/matherr.c
@@ -11,14 +11,13 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: matherr.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:39 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 1.2 1992/06/02 05:07:35 rich
- * Ported to 386bsd. Changes from vax BSD4.3 include usage of
- * fmod in libm.a, usage of void pointers, and usage of vfprintf
- * in libc.a. Floating point exceptions are not raised when
- * they should be, which causes the last fpe test to fail.
+ * Revision 5.2 1992/03/31 16:14:44 brennan
+ * patch2:
+ * TURN_ON_FPE_TRAPS() macro
+ * USE_IEEEFP_H macro
*
* Revision 5.1 91/12/05 07:56:18 brennan
* 1.1 pre-release
@@ -28,6 +27,10 @@ the GNU General Public License, version 2, 1991.
#include "mawk.h"
#include <math.h>
+#ifdef USE_IEEEFP_H
+#include <ieeefp.h>
+#endif
+
#if FPE_TRAPS_ON
#include <signal.h>
@@ -48,12 +51,10 @@ static void fpe_catch( signal, why)
switch(why)
{
- case FPE_INTDIV_TRAP :
- case FPE_FLTDIV_TRAP :
+ case FPE_ZERODIVIDE :
rt_error("division by zero") ;
- case FPE_INTOVF_TRAP :
- case FPE_FLTOVF_TRAP :
+ case FPE_OVERFLOW :
rt_error("floating point overflow") ;
default :
@@ -63,7 +64,10 @@ static void fpe_catch( signal, why)
}
void fpe_init()
-{ (void) signal(SIGFPE, fpe_catch) ; }
+{
+ TURN_ON_FPE_TRAPS() ;
+ (void) signal(SIGFPE, fpe_catch) ;
+}
#else /* FPE_TRAPS_ON==0 */
diff --git a/gnu/usr.bin/awk/mawk.h b/gnu/usr.bin/awk/mawk.h
index 702feee54da..a56b40c83e0 100644
--- a/gnu/usr.bin/awk/mawk.h
+++ b/gnu/usr.bin/awk/mawk.h
@@ -1,7 +1,7 @@
/********************************************
mawk.h
-copyright 1991, Michael D. Brennan
+copyright 1991 1992, Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -12,18 +12,24 @@ the GNU General Public License, version 2, 1991.
/* $Log: mawk.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:40 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 1.2 1992/06/02 05:07:35 rich
- * Ported to 386bsd. Changes from vax BSD4.3 include usage of
- * fmod in libm.a, usage of void pointers, and usage of vfprintf
- * in libc.a. Floating point exceptions are not raised when
- * they should be, which causes the last fpe test to fail.
+ * Revision 5.5.1.3 1993/01/22 15:04:50 mike
+ * pow2->mpow2 for linux
*
- * Revision 5.4 92/03/03 16:34:41 brennan
+ * Revision 5.5.1.2 1993/01/20 12:53:10 mike
+ * d_to_l()
+ *
+ * Revision 5.5.1.1 1993/01/15 03:33:46 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.5 1992/07/06 20:15:49 brennan
+ * DONT_PROTO_OPEN macro
+ *
+ * Revision 5.4 1992/03/03 16:34:41 brennan
* conditional around open() proto
- *
+ *
* Revision 5.3 92/01/09 08:46:58 brennan
* cell destroy macro
*
@@ -68,6 +74,8 @@ char *strrchr() ;
#include "types.h"
+
+
/*----------------
* GLOBAL VARIABLES
*----------------*/
@@ -94,7 +102,7 @@ char _string_buff[MIN_SPRINTF] ;
#define SPRINTF_SZ sizeof(tempbuff)
/* help with casts */
-extern int pow2[] ;
+extern int mpow2[] ;
/* these are used by the parser, scanner and error messages
@@ -117,7 +125,7 @@ extern int errno ;
extern char *progname ; /* for error messages */
/* macro to test the type of two adjacent cells */
-#define TEST2(cp) (pow2[(cp)->type]+pow2[((cp)+1)->type])
+#define TEST2(cp) (mpow2[(cp)->type]+mpow2[((cp)+1)->type])
/* macro to get at the string part of a CELL */
#define string(cp) ((STRING *)(cp)->ptr)
@@ -141,6 +149,9 @@ void PROTO( cast_to_RE, (CELL *) ) ;
void PROTO( cast_for_split, (CELL *) ) ;
void PROTO( check_strnum, (CELL *) ) ;
void PROTO( cast_to_REPL, (CELL *) ) ;
+long PROTO( d_to_l, (double)) ;
+
+#define d_to_i(d) ((int)d_to_l(d))
int PROTO( test, (CELL *) ) ; /* test for null non-null */
CELL *PROTO( cellcpy, (CELL *, CELL *) ) ;
@@ -165,14 +176,13 @@ void PROTO( exit, (int) ) ;
int PROTO( close, (int) ) ;
/* ANSI compilers won't like open() if they've ever seen open as
- int open(char *,int, ...). If so remove it.
+ int open(char *,int, ...). If so ,
+ #define DONT_PROTO_OPEN
*/
-#ifndef _IBMR2 /* AIX */
-#ifndef __386BSD__
+#ifndef DONT_PROTO_OPEN
int PROTO( open, (char *,int, int) ) ;
#endif
-#endif
int PROTO( read, (int , PTR, unsigned) ) ;
#endif
@@ -189,10 +199,7 @@ void PROTO( compile_error, ( char *, ...) ) ;
void PROTO( execute, (INST *, CELL *, CELL *) ) ;
char *PROTO( find_kw_str, (int) ) ;
-#if ! HAVE_STDLIB_H
double strtod() ;
-#endif
-
double fmod() ;
#endif /* MAWK_H */
diff --git a/gnu/usr.bin/awk/memory.c b/gnu/usr.bin/awk/memory.c
index 8a1b5820276..1793341cb3e 100644
--- a/gnu/usr.bin/awk/memory.c
+++ b/gnu/usr.bin/awk/memory.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: memory.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:41 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:21 brennan
+ * Revision 5.1 1991/12/05 07:56:21 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/memory.h b/gnu/usr.bin/awk/memory.h
index 967e2b45405..f9cd9eaac86 100644
--- a/gnu/usr.bin/awk/memory.h
+++ b/gnu/usr.bin/awk/memory.h
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: memory.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:42 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:28 brennan
+ * Revision 5.1 1991/12/05 07:59:28 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/parse.y b/gnu/usr.bin/awk/parse.y
index 124a16f45f9..ca8aa49aeb8 100644
--- a/gnu/usr.bin/awk/parse.y
+++ b/gnu/usr.bin/awk/parse.y
@@ -11,12 +11,22 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: parse.y,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:44 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.2 92/01/08 16:11:42 brennan
+ * Revision 5.4.1.1 1993/05/05 00:08:26 mike
+ * patch4: forgot to set $$ in LENGTH alone production
+ *
+ * Revision 5.4 1992/08/08 17:17:20 brennan
+ * patch 2: improved timing of error recovery in
+ * bungled function definitions. Fixes a core dump
+ *
+ * Revision 5.3 1992/07/08 15:43:41 brennan
+ * patch2: length returns. I am a wimp
+ *
+ * Revision 5.2 1992/01/08 16:11:42 brennan
* code FE_PUSHA carefully for MSDOS large mode
- *
+ *
* Revision 5.1 91/12/05 07:50:22 brennan
* 1.1 pre-release
*
@@ -113,7 +123,7 @@ PTR ptr ;
%token <ptr> DOUBLE STRING_ RE
%token <stp> ID D_ID
%token <fbp> FUNCT_ID
-%token <bip> BUILTIN
+%token <bip> BUILTIN LENGTH
%token <cp> FIELD
%token PRINT PRINTF SPLIT MATCH_FUNC SUB GSUB
@@ -149,11 +159,7 @@ program : program_block
program_block : PA_block /* pattern-action */
| function_def
- | error block
- { if (scope == SCOPE_FUNCT)
- { restore_ids() ; scope = SCOPE_MAIN ; }
- code_ptr = main_code_ptr ;
- }
+ | outside_error block
;
PA_block : block
@@ -419,6 +425,11 @@ builtin :
{ code1(_PUSHINT) ; code1($4) ; }
code2(_BUILTIN , p->fp) ;
}
+ | LENGTH /* this is an irritation */
+ { $$ = code_ptr ;
+ code1(_PUSHINT) ; code1(0) ;
+ code2(_BUILTIN, $1->fp) ;
+ }
;
/* an empty production to store the code_ptr */
@@ -978,6 +989,23 @@ f_args : ID
}
;
+outside_error : error
+ { /* we may have to recover from a bungled function
+ definition */
+
+ /* can have local ids, before code scope
+ changes */
+ restore_ids() ;
+
+ if (scope == SCOPE_FUNCT)
+ { scope = SCOPE_MAIN ;
+ active_funct = (FBLOCK*) 0 ;
+ }
+
+ code_ptr = main_code_ptr ;
+ }
+ ;
+
/* a call to a user defined function */
p_expr : FUNCT_ID mark call_args
diff --git a/gnu/usr.bin/awk/parse2.xc b/gnu/usr.bin/awk/parse2.xc
index f98658d89ab..95bc446b4bc 100644
--- a/gnu/usr.bin/awk/parse2.xc
+++ b/gnu/usr.bin/awk/parse2.xc
@@ -10,14 +10,6 @@ Mawk is distributed without warranty under the terms of
the GNU General Public License, version 2, 1991.
********************************************/
-/* $Log: parse2.xc,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
-/*
-Revision 5.1 91/12/05 07:52:38 brennan
-1.1 pre-release
-
-*/
/* If using Berkeley yacc, we can put the parser table
memory to the zmalloc pool. This is kind of ugly and
diff --git a/gnu/usr.bin/awk/patchlev.h b/gnu/usr.bin/awk/patchlev.h
index cbcd2feb192..afceea0be3a 100644
--- a/gnu/usr.bin/awk/patchlev.h
+++ b/gnu/usr.bin/awk/patchlev.h
@@ -1,3 +1,4 @@
/* mawk 1.1 */
-#define PATCHLEVEL 1
-#define PATCH_STRING ".1"
+#define PATCHLEVEL 4
+#define PATCH_STRING ".4"
+#define DATE_STRING "May 1993"
diff --git a/gnu/usr.bin/awk/print.c b/gnu/usr.bin/awk/print.c
index 9f20639a662..503c12c3eb9 100644
--- a/gnu/usr.bin/awk/print.c
+++ b/gnu/usr.bin/awk/print.c
@@ -11,13 +11,26 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: print.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:48 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.2 92/02/24 10:52:16 brennan
+ * Revision 5.4.1.2 1993/01/20 12:53:11 mike
+ * d_to_l()
+ *
+ * Revision 5.4.1.1 1993/01/15 03:33:47 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.4 1992/11/29 18:03:11 mike
+ * when printing integers, convert doubles to
+ * longs so output is the same on 16bit systems as 32bit systems
+ *
+ * Revision 5.3 1992/08/17 14:23:21 brennan
+ * patch2: After parsing, only bi_sprintf() uses string_buff.
+ *
+ * Revision 5.2 1992/02/24 10:52:16 brennan
* printf and sprintf() can now have more args than % conversions
* removed HAVE_PRINTF_HD -- it was too obscure
- *
+ *
* Revision 5.1 91/12/05 07:56:22 brennan
* 1.1 pre-release
*
@@ -41,10 +54,14 @@ static void PROTO( bad_conversion, (int, char *, char *)) ;
char *sprintf_buff = string_buff ;
char *sprintf_limit = string_buff + SPRINTF_SZ ;
+/* Once execute() starts the sprintf code is (belatedly) the only
+ code allowed to use string_buff */
+
static void print_cell(p, fp)
register CELL *p ;
register FILE *fp ;
-{ register int len ;
+{
+ int len ;
switch( p->type )
{
@@ -65,10 +82,15 @@ static void print_cell(p, fp)
break ;
case C_DOUBLE :
- if ( (double)(len = (int) p->dval) == p->dval )
- fprintf(fp, "%d", len) ;
- else
- fprintf(fp, string(OFMT)->str, p->dval) ;
+ {
+ long ival = d_to_l(p->dval) ;
+
+ /* integers print as "%[l]d" */
+ if ( (double) ival == p->dval )
+ fprintf(fp, INT_FMT, ival) ;
+ else
+ fprintf(fp, string(OFMT)->str, p->dval) ;
+ }
break ;
default :
@@ -88,44 +110,56 @@ static void print_cell(p, fp)
CELL *bi_print(sp)
CELL *sp ; /* stack ptr passed in */
-{ register CELL *p ;
+{
+ register CELL *p ;
register int k ;
FILE *fp ;
- if ( (k = sp->type) < 0 )
- { if ( (--sp)->type < C_STRING ) cast1_to_s(sp) ;
+ k = sp->type ;
+ if ( k < 0 )
+ {
+ /* k holds redirection */
+ if ( (--sp)->type < C_STRING ) cast1_to_s(sp) ;
fp = (FILE *) file_find( string(sp), k ) ;
free_STRING(string(sp)) ;
k = (--sp)->type ;
+ /* k now has number of arguments */
}
else fp = stdout ;
if ( k )
- { p = sp - k ; /* clear k variables off the stack */
+ {
+ p = sp - k ; /* clear k variables off the stack */
sp = p - 1 ;
- while ( k-- > 1 )
- { print_cell(p,fp) ; print_cell(OFS,fp) ;
- cell_destroy(p) ; p++ ; }
+ k-- ;
+
+ while ( k > 0 )
+ {
+ print_cell(p,fp) ; print_cell(OFS,fp) ;
+ cell_destroy(p) ;
+ p++ ; k-- ;
+ }
print_cell(p, fp) ; cell_destroy(p) ;
}
else
- { sp-- ;
- print_cell( &field[0], fp ) ; }
+ { /* print $0 */
+ sp-- ;
+ print_cell( &field[0], fp ) ;
+ }
print_cell(ORS , fp) ;
return sp ;
}
/*---------- types and defs for doing printf and sprintf----*/
-#define PF_C 0
-#define PF_S 1
+#define PF_C 0 /* %c */
+#define PF_S 1 /* %s */
#define PF_D 2 /* int conversion */
-#define PF_LD 3 /* long int */
-#define PF_F 4 /* float conversion */
+#define PF_F 3 /* float conversion */
/* for switch on number of '*' and type */
-#define AST(num,type) (5*(num)+(type))
+#define AST(num,type) ((PF_F+1)*(num)+(type))
/* some picky ANSI compilers go berserk without this */
#if HAVE_PROTOS
@@ -162,13 +196,16 @@ static STRING *do_printf( fp, format, argcnt, cp)
int l_flag , h_flag ; /* seen %ld or %hd */
int ast_cnt ;
int ast[2] ;
- long lval ;
- int ival ; /* caters to MSDOS */
+ long lval ; /* hold integer values */
int num_conversion = 0 ; /* for error messages */
char *who ; /*ditto*/
int pf_type ; /* conversion type */
PRINTER printer ; /* pts at fprintf() or sprintf() */
+#ifdef SHORT_INTS
+ char xbuff[256] ; /* splice in l qualifier here */
+#endif
+
if ( fp == (FILE *) 0 ) /* doing sprintf */
{
target = sprintf_buff ;
@@ -216,6 +253,7 @@ static STRING *do_printf( fp, format, argcnt, cp)
}
+ /* *q == '%' */
num_conversion++ ;
if ( * ++q == '%' ) /* %% */
@@ -237,7 +275,7 @@ static STRING *do_printf( fp, format, argcnt, cp)
if ( *q == '*' )
{
if ( cp->type != C_DOUBLE ) cast1_to_d(cp) ;
- ast[ast_cnt++] = (int) cp++ ->dval ;
+ ast[ast_cnt++] = d_to_i(cp++ ->dval) ;
argcnt-- ; q++ ;
}
else
@@ -249,7 +287,7 @@ static STRING *do_printf( fp, format, argcnt, cp)
if ( *q == '*' )
{
if ( cp->type != C_DOUBLE ) cast1_to_d(cp) ;
- ast[ast_cnt++] = (int) cp++ ->dval ;
+ ast[ast_cnt++] = d_to_i(cp++ ->dval) ;
argcnt-- ; q++ ;
}
else
@@ -282,22 +320,22 @@ static STRING *do_printf( fp, format, argcnt, cp)
switch( cp->type )
{
case C_NOINIT :
- ival = 0 ;
+ lval = 0 ;
break ;
case C_STRNUM :
case C_DOUBLE :
- ival = (int) cp->dval ;
+ lval = (long) d_to_i(cp->dval) ;
break ;
case C_STRING :
- ival = string(cp)->str[0] ;
+ lval = string(cp)->str[0] ;
break ;
case C_MBSTRN :
check_strnum(cp) ;
- ival = cp->type == C_STRING ?
- string(cp)->str[0] : (int) cp->dval ;
+ lval = cp->type == C_STRING ?
+ string(cp)->str[0] : (long) d_to_i(cp->dval) ;
break ;
default :
@@ -314,10 +352,12 @@ static STRING *do_printf( fp, format, argcnt, cp)
case 'i' :
case 'u' :
if ( cp->type != C_DOUBLE ) cast1_to_d(cp) ;
- lval = (long) cp->dval ;
- if ( h_flag ) lval &= 0xffff ;
+ if ( cp->dval > MAX__LONG ) lval = MAX__LONG ;
+ else
+ if ( cp->dval > -MAX__LONG ) lval = (long) cp->dval ;
+ else lval = -MAX__LONG ;
- pf_type = l_flag ? PF_LD : PF_D ;
+ pf_type = PF_D ;
break ;
case 'e' :
@@ -337,19 +377,48 @@ static STRING *do_printf( fp, format, argcnt, cp)
save = *q ;
*q = 0 ;
+#ifdef SHORT_INTS
+ if ( pf_type == PF_D )
+ {
+ /* need to splice in long modifier */
+ strcpy(xbuff, p) ;
+
+ if ( l_flag ) /* do nothing */ ;
+ else
+ {
+ int k = q - p ;
+
+ if ( h_flag )
+ {
+ lval = (short) lval ;
+ /* replace the 'h' with 'l' (really!) */
+ xbuff[k-2] = 'l' ;
+ if ( xbuff[k-1] != 'd' && xbuff[k-1] != 'i' ) lval &= 0xffff ;
+ }
+ else
+ {
+ /* the usual case */
+ xbuff[k] = xbuff[k-1] ;
+ xbuff[k-1] = 'l' ;
+ xbuff[k+1] = 0 ;
+ }
+ }
+ }
+#endif
+
/* ready to call printf() */
switch( AST(ast_cnt, pf_type ) )
{
case AST(0, PF_C ) :
- (*printer)((PTR) target, p, ival) ;
+ (*printer)((PTR) target, p, (int) lval) ;
break ;
case AST(1, PF_C ) :
- (*printer)((PTR) target, p, ast[0], ival) ;
+ (*printer)((PTR) target, p, ast[0], (int) lval) ;
break ;
case AST(2, PF_C ) :
- (*printer)((PTR) target, p, ast[0], ast[1], ival) ;
+ (*printer)((PTR) target, p, ast[0], ast[1], (int)lval) ;
break ;
case AST(0, PF_S) :
@@ -361,32 +430,28 @@ static STRING *do_printf( fp, format, argcnt, cp)
break ;
case AST(2, PF_S) :
- (*printer)((PTR) target, p, ast[0], ast[1], string(cp)->str) ;
+ (*printer)((PTR) target,p,ast[0],ast[1],string(cp)->str) ;
break ;
+#ifdef SHORT_INTS
+#define FMT xbuff /* format in xbuff */
+#else
+#define FMT p /* p -> format */
+#endif
case AST(0, PF_D) :
- (*printer)((PTR) target, p, (int) lval) ;
+ (*printer)((PTR) target, FMT, lval) ;
break ;
case AST(1, PF_D) :
- (*printer)((PTR) target, p, ast[0], (int) lval) ;
+ (*printer)((PTR) target, FMT, ast[0], lval) ;
break ;
case AST(2, PF_D) :
- (*printer)((PTR) target, p, ast[0], ast[1], (int) lval) ;
- break ;
-
- case AST(0, PF_LD) :
- (*printer)((PTR) target, p, lval) ;
+ (*printer)((PTR) target, FMT, ast[0], ast[1], lval) ;
break ;
- case AST(1, PF_LD) :
- (*printer)((PTR) target, p, ast[0], lval) ;
- break ;
+#undef FMT
- case AST(2, PF_LD) :
- (*printer)((PTR) target, p, ast[0], ast[1], lval) ;
- break ;
case AST(0, PF_F) :
(*printer)((PTR) target, p, cp->dval) ;
@@ -411,20 +476,27 @@ CELL *bi_printf(sp)
register CELL *p ;
FILE *fp ;
- if ( (k = sp->type) < 0 )
- { if ( (--sp)->type < C_STRING ) cast1_to_s(sp) ;
+ k = sp->type ;
+ if ( k < 0 )
+ {
+ /* k has redirection */
+ if ( (--sp)->type < C_STRING ) cast1_to_s(sp) ;
fp = (FILE *) file_find( string(sp), k ) ;
free_STRING(string(sp)) ;
k = (--sp)->type ;
+ /* k is now number of args including format */
}
else fp = stdout ;
- sp -= k-- ; /* sp points at the format string */
+ sp -= k ; /* sp points at the format string */
+ k-- ;
+
if ( sp->type < C_STRING ) cast1_to_s(sp) ;
do_printf(fp, string(sp)->str, k, sp+1) ;
-
free_STRING(string(sp)) ;
- for ( p = sp+1 ; k-- ; p++ ) cell_destroy(p) ;
+
+ /* cleanup arguments on eval stack */
+ for ( p = sp+1 ; k ; k--, p++ ) cell_destroy(p) ;
return --sp ;
}
@@ -434,14 +506,16 @@ CELL *bi_sprintf(sp)
int argcnt = sp->type ;
STRING *sval ;
- sp -= argcnt-- ; /* sp points at the format string */
- if ( sp->type != C_STRING ) cast1_to_s(sp) ;
+ sp -= argcnt ; /* sp points at the format string */
+ argcnt-- ;
+ if ( sp->type != C_STRING ) cast1_to_s(sp) ;
sval = do_printf((FILE *)0, string(sp)->str, argcnt, sp+1) ;
free_STRING(string(sp)) ;
sp->ptr = (PTR) sval ;
- for ( p = sp+1 ; argcnt-- ; p++ ) cell_destroy(p) ;
+ /* cleanup */
+ for (p = sp+1 ; argcnt ; argcnt--, p++ ) cell_destroy(p) ;
return sp ;
}
diff --git a/gnu/usr.bin/awk/re_cmpl.c b/gnu/usr.bin/awk/re_cmpl.c
index c5cb6d48553..89e0f094b21 100644
--- a/gnu/usr.bin/awk/re_cmpl.c
+++ b/gnu/usr.bin/awk/re_cmpl.c
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: re_cmpl.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:49 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:25 brennan
+ * Revision 5.1 1991/12/05 07:56:25 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/regexp.h b/gnu/usr.bin/awk/regexp.h
index 2dfb9f75fad..ec96ca477dc 100644
--- a/gnu/usr.bin/awk/regexp.h
+++ b/gnu/usr.bin/awk/regexp.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: regexp.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:51 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:30 brennan
+ * Revision 5.1 1991/12/05 07:59:30 brennan
* 1.1 pre-release
- *
+ *
*/
#include <stdio.h>
diff --git a/gnu/usr.bin/awk/repl.h b/gnu/usr.bin/awk/repl.h
index 36a6bffd602..afc4eb95fa6 100644
--- a/gnu/usr.bin/awk/repl.h
+++ b/gnu/usr.bin/awk/repl.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: repl.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:52 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:32 brennan
+ * Revision 5.1 1991/12/05 07:59:32 brennan
* 1.1 pre-release
- *
+ *
*/
/* repl.h */
diff --git a/gnu/usr.bin/awk/scan.c b/gnu/usr.bin/awk/scan.c
index ac9f35260e4..66d134bc21d 100644
--- a/gnu/usr.bin/awk/scan.c
+++ b/gnu/usr.bin/awk/scan.c
@@ -12,12 +12,22 @@ the GNU General Public License, version 2, 1991.
/* $Log: scan.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:54 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.2 92/02/21 14:16:53 brennan
+ * Revision 5.4.1.1 1993/01/15 03:33:50 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.4 1992/11/29 18:57:50 mike
+ * field expressions convert to long so 16 bit and 32 bit
+ * systems behave the same
+ *
+ * Revision 5.3 1992/07/08 15:43:41 brennan
+ * patch2: length returns. I am a wimp
+ *
+ * Revision 5.2 1992/02/21 14:16:53 brennan
* fix: getline <=
- *
+ *
* Revision 5.1 91/12/05 07:56:27 brennan
* 1.1 pre-release
*
@@ -470,14 +480,13 @@ reswitch:
if ( flag ) ct_ret(flag) ; /* an error */
else yylval.cp = &field[0] ;
else
- { int k = (int) d ;
-
- if ( k > MAX_FIELD )
+ {
+ if ( d > MAX_FIELD )
{ compile_error(
"$%g exceeds maximum field(%d)" , d, MAX_FIELD) ;
- k = MAX_FIELD ;
+ d = MAX_FIELD ;
}
- yylval.cp = field_ptr(k) ;
+ yylval.cp = field_ptr((int)d) ;
}
ct_ret(FIELD) ;
@@ -558,6 +567,18 @@ reswitch:
current_token = BUILTIN ;
break ;
+ case ST_LENGTH :
+
+ yylval.bip = stp->stval.bip ;
+
+ /* check for length alone, this is an ugly
+ hack */
+ while ( scan_code[ c = next() ] == SC_SPACE ) ;
+ un_next() ;
+
+ current_token = c == '(' ? BUILTIN : LENGTH ;
+ break ;
+
case ST_FIELD :
yylval.cp = stp->stval.cp ;
current_token = FIELD ;
diff --git a/gnu/usr.bin/awk/scan.h b/gnu/usr.bin/awk/scan.h
index e522d9faf03..2a0c6459a31 100644
--- a/gnu/usr.bin/awk/scan.h
+++ b/gnu/usr.bin/awk/scan.h
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: scan.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:55 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:33 brennan
+ * Revision 5.1 1991/12/05 07:59:33 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/sizes.h b/gnu/usr.bin/awk/sizes.h
index 8e0eb31a3b8..03f4f311d14 100644
--- a/gnu/usr.bin/awk/sizes.h
+++ b/gnu/usr.bin/awk/sizes.h
@@ -1,7 +1,7 @@
/********************************************
sizes.h
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992. Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,12 +11,18 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: sizes.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:56 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:35 brennan
+ * Revision 5.3 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.2 1992/08/27 03:20:08 mike
+ * patch2: increase A_HASH_PRIME
+ *
+ * Revision 5.1 1991/12/05 07:59:35 brennan
* 1.1 pre-release
- *
+ *
*/
/* sizes.h */
@@ -25,7 +31,7 @@ the GNU General Public License, version 2, 1991.
#define SIZES_H
#if ! HAVE_SMALL_MEMORY
-#define EVAL_STACK_SIZE 256 /* limit on recursion */
+#define EVAL_STACK_SIZE 256 /* initial size , can grow */
/* number of fields at startup, must be a power of 2
and FBANK_SZ-1 must be divisible by 3! */
#define FBANK_SZ 256
@@ -51,8 +57,21 @@ the GNU General Public License, version 2, 1991.
/* starting buffer size for input files, grows if
necessary */
+#if LM_DOS
+/* trade some space for IO speed */
+#undef BUFFSZ
+#define BUFFSZ 8192
+/* maximum input buffers that will fit in 64K */
+#define MAX_BUFFS ((int)(0x10000L/BUFFSZ) - 1)
+#endif
+
#define HASH_PRIME 53
-#define A_HASH_PRIME 37
+
+#if ! HAVE_SMALL_MEMORY
+#define A_HASH_PRIME 199
+#else
+#define A_HASH_PRIME 37
+#endif
#define MAX_COMPILE_ERRORS 5 /* quit if more than 4 errors */
diff --git a/gnu/usr.bin/awk/split.c b/gnu/usr.bin/awk/split.c
index e62d1807dd4..52892db1ea3 100644
--- a/gnu/usr.bin/awk/split.c
+++ b/gnu/usr.bin/awk/split.c
@@ -11,12 +11,18 @@ the GNU General Public License, version 2, 1991.
********************************************/
/* $Log: split.c,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:57:57 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:31 brennan
+ * Revision 5.2 1992/07/08 21:19:09 brennan
+ * patch2
+ * change in split() requires that
+ * bi_split() call load_array() even
+ * when cnt is 0.
+ *
+ * Revision 5.1 1991/12/05 07:56:31 brennan
* 1.1 pre-release
- *
+ *
*/
/* split.c */
@@ -221,11 +227,8 @@ CELL *bi_split(sp)
if ( sp->type < C_STRING ) cast1_to_s(sp) ;
if ( string(sp)->len == 0 ) /* nothing to split */
- { free_STRING( string(sp) ) ;
- sp->type = C_DOUBLE ; sp->dval = 0.0 ;
- return sp ;
- }
-
+ cnt = 0 ;
+ else
switch ( (sp+2)->type )
{
case C_RE :
diff --git a/gnu/usr.bin/awk/symtype.h b/gnu/usr.bin/awk/symtype.h
index f068a59b92c..cd61f5c115d 100644
--- a/gnu/usr.bin/awk/symtype.h
+++ b/gnu/usr.bin/awk/symtype.h
@@ -11,12 +11,18 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: symtype.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:57:58 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:37 brennan
+ * Revision 5.3 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.2 1992/07/08 15:44:44 brennan
+ * patch2: length returns. I am a wimp
+ *
+ * Revision 5.1 1991/12/05 07:59:37 brennan
* 1.1 pre-release
- *
+ *
*/
/* types related to symbols are defined here */
@@ -43,7 +49,7 @@ unsigned char min_args, max_args ;
typedef struct anode {
struct anode *link , *ilink ;
STRING *sval ;
-int ival ;
+long ival ;
CELL *cp ;
} ANODE ;
@@ -113,9 +119,10 @@ void PROTO( fdump, (void) ) ;
#define ST_FUNCT 6
#define ST_NR 7 /* NR is special */
#define ST_ENV 8 /* and so is ENVIRON */
-#define ST_LOCAL_NONE 9
-#define ST_LOCAL_VAR 10
-#define ST_LOCAL_ARRAY 11
+#define ST_LENGTH 9 /* ditto and bozo */
+#define ST_LOCAL_NONE 10
+#define ST_LOCAL_VAR 11
+#define ST_LOCAL_ARRAY 12
#define is_local(stp) ((stp)->type>=ST_LOCAL_NONE)
diff --git a/gnu/usr.bin/awk/types.h b/gnu/usr.bin/awk/types.h
index 05a33fa03bf..8b959eb4ddd 100644
--- a/gnu/usr.bin/awk/types.h
+++ b/gnu/usr.bin/awk/types.h
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/* $Log: types.h,v $
-/* Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/* initial import of 386bsd-0.1 sources
+/* Revision 1.2 1993/07/02 23:58:00 jtc
+/* Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:39 brennan
+ * Revision 5.1 1991/12/05 07:59:39 brennan
* 1.1 pre-release
- *
+ *
*/
diff --git a/gnu/usr.bin/awk/vargs.h b/gnu/usr.bin/awk/vargs.h
new file mode 100644
index 00000000000..a623b83d67a
--- /dev/null
+++ b/gnu/usr.bin/awk/vargs.h
@@ -0,0 +1,59 @@
+
+/********************************************
+vargs.h
+copyright 1992 Michael D. Brennan
+
+This is a source file for mawk, an implementation of
+the AWK programming language.
+
+Mawk is distributed without warranty under the terms of
+the GNU General Public License, version 2, 1991.
+********************************************/
+
+/*
+$Log: vargs.h,v $
+Revision 1.1 1993/07/02 23:58:01 jtc
+Updated to mawk 1.1.4
+
+ * Revision 1.1 1992/10/02 23:23:41 mike
+ * Initial revision
+ *
+*/
+
+/* provides common interface to <stdarg.h> or <varargs.h>
+ only used for error messages
+*/
+
+
+#if HAVE_STDARG_H == 0
+#include <varargs.h>
+
+#ifndef VA_ALIST
+
+#define VA_ALIST(type, arg) (va_alist) va_dcl { type arg ;
+#define VA_ALIST2(t1,a1,t2,a2) (va_alist) va_dcl { t1 a1 ; t2 a2 ;
+
+#endif
+
+#define VA_START(p,type, last) va_start(p) ;\
+ last = va_arg(p,type)
+
+
+#define VA_START2(p,t1,a1,t2,a2) va_start(p) ;\
+ a1 = va_arg(p,t1);\
+ a2 = va_arg(p,t2)
+
+#else /* HAVE_STDARG_H */
+#include <stdarg.h>
+
+#ifndef VA_ALIST
+#define VA_ALIST(type, arg) (type arg, ...) {
+#define VA_ALIST2(t1,a1,t2,a2) (t1 a1,t2 a2,...) {
+#endif
+
+#define VA_START(p,type,last) va_start(p,last)
+
+#define VA_START2(p,t1,a1,t2,a2) va_start(p,a2)
+
+#endif
+
diff --git a/gnu/usr.bin/awk/version.c b/gnu/usr.bin/awk/version.c
index a06ea186040..6aaee40cde6 100644
--- a/gnu/usr.bin/awk/version.c
+++ b/gnu/usr.bin/awk/version.c
@@ -1,7 +1,7 @@
/********************************************
version.c
-copyright 1991, Michael D. Brennan
+copyright 1991, 1992. Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
@@ -11,12 +11,30 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: version.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:02 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.3 92/03/03 16:42:23 brennan
+ * Revision 5.6.1.3 1993/05/05 00:02:18 mike
+ * patch4
+ *
+ * Revision 5.6.1.2 1993/01/20 12:53:13 mike
+ * d_to_l()
+ *
+ * Revision 5.6.1.1 1993/01/15 03:33:54 mike
+ * patch3: safer double to int conversion
+ *
+ * Revision 5.6 1992/12/17 02:48:01 mike
+ * 1.1.2d changes for DOS
+ *
+ * Revision 5.5 1992/12/02 03:18:12 mike
+ * coherent patch
+ *
+ * Revision 5.4 1992/08/27 11:50:38 mike
+ * patch2
+ *
+ * Revision 5.3 1992/03/03 16:42:23 brennan
* patch 1
- *
+ *
* Revision 5.2 92/01/22 05:34:10 brennan
* version 1.1
*
@@ -28,8 +46,11 @@ the GNU General Public License, version 2, 1991.
#include "mawk.h"
#include "patchlev.h"
+static char rcsid[] =
+"@(#) $Id: version.c,v 1.2 1993/07/02 23:58:02 jtc Exp $" ;
+
#define VERSION_STRING \
- "mawk 1.1%s%s Feb 1992, Copyright (C) Michael D. Brennan\n\n"
+ "mawk 1.1%s%s %s, Copyright (C) Michael D. Brennan\n\n"
#define DOS_STRING ""
@@ -63,14 +84,101 @@ the GNU General Public License, version 2, 1991.
#define DOS_STRING ":Mac"
#endif
+static char fmt[] = "%-14s%10lu\n" ;
+
/* print VERSION and exit */
void print_version()
-{ static char fmt[] = "%-14s%10u\n" ;
+{
- printf(VERSION_STRING, PATCH_STRING, DOS_STRING) ;
+ printf(VERSION_STRING, PATCH_STRING, DOS_STRING, DATE_STRING) ;
fflush(stdout) ;
+
+ print_compiler_id() ;
fprintf(stderr, "compiled limits:\n") ;
- fprintf(stderr, fmt, "largest field", MAX_FIELD) ;
- fprintf(stderr, fmt, "sprintf buffer",SPRINTF_SZ) ;
+ fprintf(stderr, fmt, "largest field", (long)MAX_FIELD) ;
+ fprintf(stderr, fmt, "sprintf buffer", (long)SPRINTF_SZ) ;
+ print_aux_limits() ;
exit(0) ;
}
+
+
+/*
+ Extra info for MSDOS. This code contributed by
+ Ben Myers
+*/
+
+#ifdef __TURBOC__
+#include <alloc.h> /* coreleft() */
+#define BORL
+#endif
+
+#ifdef __BORLANDC__
+#include <alloc.h> /* coreleft() */
+#define BORL
+#endif
+
+#ifdef BORL
+#if LM_DOS
+extern unsigned _stklen = 16 * 1024U ;
+ /* 4K of stack is enough for a user function call
+ nesting depth of 75 so this is enough for 300 */
+#endif
+#endif
+
+#ifdef _MSC_VER
+#include <malloc.h>
+#endif
+
+#ifdef __ZTC__
+#include <dos.h> /* _chkstack */
+#endif
+
+
+int print_compiler_id()
+{
+
+#ifdef __TURBOC__
+ fprintf(stderr, "MsDOS Turbo C++ %d.%d\n",
+ __TURBOC__>>8, __TURBOC__&0xff) ;
+#endif
+
+#ifdef __BORLANDC__
+ fprintf (stderr, "MS-DOS Borland C++ __BORLANDC__ %x\n",
+ __BORLANDC__ );
+#endif
+
+#ifdef _MSC_VER
+ fprintf (stderr, "MS-DOS Microsoft C/C++ _MSC_VER %u\n", _MSC_VER );
+#endif
+
+#ifdef __ZTC__
+ fprintf (stderr, "MS-DOS Zortech C++ __ZTC__ %x\n", __ZTC__ );
+#endif
+
+ return 0 ; /*shut up */
+}
+
+
+int print_aux_limits()
+{
+#ifdef BORL
+ extern unsigned _stklen ;
+ fprintf(stderr, fmt, "stack size", (unsigned long)_stklen) ;
+ fprintf(stderr, fmt, "heap size", (unsigned long) coreleft()) ;
+#endif
+
+#ifdef _MSC_VER
+ fprintf(stderr, fmt, "stack size", (unsigned long)_stackavail()) ;
+#if SM_DOS
+ fprintf(stderr, fmt, "heap size", (unsigned long) _memavl()) ;
+#endif
+#endif
+
+#ifdef __ZTC__
+/* large memory model only with ztc */
+ fprintf(stderr, fmt, "stack size??", (unsigned long)_chkstack()) ;
+ fprintf(stderr, fmt, "heap size", farcoreleft()) ;
+#endif
+
+ return 0 ;
+}
diff --git a/gnu/usr.bin/awk/zmalloc.c b/gnu/usr.bin/awk/zmalloc.c
index 7315e372804..1a38d9c50e6 100644
--- a/gnu/usr.bin/awk/zmalloc.c
+++ b/gnu/usr.bin/awk/zmalloc.c
@@ -11,12 +11,16 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: zmalloc.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:03 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:56:35 brennan
+ * Revision 5.1.1.1 1993/02/06 11:12:19 mike
+ * fix bug in reuse of parser table memory
+ * for most users ifdef the mess out
+ *
+ * Revision 5.1 1991/12/05 07:56:35 brennan
* 1.1 pre-release
- *
+ *
*/
/* zmalloc.c */
@@ -86,20 +90,36 @@ PTR bmalloc( blocks )
{ pool[blocks-1] = p->link ; return (PTR) p ; }
if ( blocks > amt_avail )
- { if ( amt_avail ) /* free avail */
- { avail->link = pool[--amt_avail] ; pool[amt_avail] = avail ; }
+ {
+ if ( amt_avail != 0 ) /* free avail */
+ {
+ avail->link = pool[--amt_avail] ;
+ pool[amt_avail] = avail ;
+ }
+#if MSDOS || HAVE_SMALL_MEMORY
+/* this hack is dangerous (I've blown it twice), not portable,
+ and counts on byacc not changing, but it is a big win on
+ DOS. On paged vmem systems it is a nop so ifdef it out.
+*/
/* use parser tables first */
- if ( yacc_memp->zblocks >= blocks )
- { avail = (ZBLOCK *) yacc_memp->mem ;
+ if ( yacc_memp->zblocks > blocks )
+ {
+ avail = (ZBLOCK *) yacc_memp->mem ;
amt_avail = yacc_memp++ -> zblocks ;
/* make sure its -- aligned */
- if ( (int) avail & 7 )
- { avail = (ZBLOCK*)((char *)avail + 8 - ((int)avail&7)) ;
- amt_avail-- ;
+ {
+ int k = (int) avail & 7 ;
+ if ( k )
+ {
+ avail = (ZBLOCK*)((char *)avail + (8-k)) ;
+ amt_avail-- ;
+ }
}
}
else
+#endif
+
if ( !(avail = (ZBLOCK *) malloc(SIZE_T(CHUNK*ZBLOCKSZ))) )
{ /* if we get here, almost out of memory */
amt_avail = 0 ;
diff --git a/gnu/usr.bin/awk/zmalloc.h b/gnu/usr.bin/awk/zmalloc.h
index 20ad74608b3..9d9d90c8abb 100644
--- a/gnu/usr.bin/awk/zmalloc.h
+++ b/gnu/usr.bin/awk/zmalloc.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: zmalloc.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:04 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 5.1 91/12/05 07:59:41 brennan
+ * Revision 5.1 1991/12/05 07:59:41 brennan
* 1.1 pre-release
- *
+ *
*/
/* zmalloc.h */