Article View: comp.bugs.4bsd
Article #554negative numbers in expr
From: amos
Date: Tue, 24 Feb 1987 14:59
Date: Tue, 24 Feb 1987 14:59
57 lines
2144 bytes
2144 bytes
Index: <source directory>/<source file> 4.2BSD
Description:
Expr doesn't recognize negative numbers as numeric arguments,
except as the 1st argument to a relational operation (this is
even more bogous, since non-numeric arguments are compared
lexically, without warning).
Repeat-By:
Try: expr -1 + 2; or expr -1 \> -01
This is most annoying when expr-ing the output of another expr.
Fix:
Apply the following patch. (This is from the vanilla 4.3 sources,
but other versions - maybe even sysV? - are similar).
*** /usr/src/bin/expr.y Mon Mar 3 16:42:15 1986
--- /tmp/expr.y Tue Feb 24 16:30:24 1987
***************
*** 94,100
char *rel(op, r1, r2) register char *r1, *r2; {
register long i;
! if(ematch(r1, "-*[0-9]*$") && ematch(r2, "-*[0-9]*$"))
i = atol(r1) - atol(r2);
else
i = strcmp(r1, r2);
--- 94,100 -----
char *rel(op, r1, r2) register char *r1, *r2; {
register long i;
! if(ematch(r1, "-*[0-9]*$") && ematch(r2, "[0-9]*$"))
i = atol(r1) - atol(r2);
else
i = strcmp(r1, r2);
***************
*** 113,119
long i1, i2;
register char *rv;
! if(!(ematch(r1, "-*[0-9]*$") && ematch(r2, "-*[0-9]*$")))
yyerror("non-numeric argument");
i1 = atol(r1);
i2 = atol(r2);
--- 113,119 -----
long i1, i2;
register char *rv;
! if(!(ematch(r1, "[0-9]*$") && ematch(r2, "[0-9]*$")))
yyerror("non-numeric argument");
i1 = atol(r1);
i2 = atol(r2);
--
Amos Shapir
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel
(011-972) 52-522261 amos%nsta@nsc.com 34.48'E 32.10'N
Technical Details
Message-ID:
<702@instable.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!nsc!nsta!instable!amosShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!nsc!nsta!instable!amos From: amos@instable.UUCP Newsgroups: comp.bugs.4bsd Subject: negative numbers in expr Message-ID: <702@instable.UUCP> Date: Tue, 24-Feb-87 09:59:24 EST Article-I.D.: instable.702 Posted: Tue Feb 24 09:59:24 1987 Date-Received: Thu, 26-Feb-87 23:31:07 EST Organization: National Semiconductor (Israel) Ltd. Lines: 57 Keywords: expr