--- ray/src/cal/calc.c 2003/06/08 12:03:09 1.2 +++ ray/src/cal/calc.c 2003/12/09 15:55:46 1.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: calc.c,v 1.2 2003/06/08 12:03:09 schorsch Exp $"; +static const char RCSid[] = "$Id: calc.c,v 1.6 2003/12/09 15:55:46 greg Exp $"; #endif /* * calc.c - simple algebraic desk calculator program. @@ -13,27 +13,25 @@ static const char RCSid[] = "$Id: calc.c,v 1.2 2003/06 #include #include +#include "rterror.h" #include "calcomp.h" - #define MAXRES 100 double result[MAXRES]; int nres = 0; -#ifndef BSD -#define index strchr -#endif - jmp_buf env; int recover = 0; +int main(argc, argv) int argc; char *argv[]; { - char expr[512]; + char expr[2048]; + char *epos; FILE *fp; int i; register char *cp; @@ -52,10 +50,16 @@ char *argv[]; recover = 1; eclock++; - while (fgets(expr, sizeof(expr), stdin) != NULL) { - for (cp = expr; *cp && *cp != '\n'; cp++) - ; - *cp = '\0'; + epos = expr; + while (fgets(epos, sizeof(expr)-(epos-expr), stdin) != NULL) { + while (*epos && *epos != '\n') + epos++; + if (*epos && epos > expr && epos[-1] == '\\') { + epos[-1] = ' '; + continue; /* escaped newline */ + } + *epos = '\0'; + epos = expr; switch (expr[0]) { case '\0': continue; @@ -93,8 +97,8 @@ char *argv[]; eclock++; continue; } - if ((cp = index(expr, '=')) != NULL || - (cp = index(expr, ':')) != NULL) { + if ((cp = strchr(expr, '=')) != NULL || + (cp = strchr(expr, ':')) != NULL) { if (cp[1]) scompile(expr, NULL, 0); else if (*cp == '=') { @@ -120,6 +124,7 @@ char *argv[]; recover = 0; quit(0); + return 0; /* pro forma exit */ }