diff --git a/BUGS b/BUGS index 1898476..60d1fce 100644 --- a/BUGS +++ b/BUGS @@ -68,32 +68,6 @@ importantly, fixes (in the form of a context diff patch) to: Known bugs: - None. :-) - - We are sure some more bugs exist. When you find them, please let - us know! See the above for details on how to report and were to - EMail your bug reports and hopefully patches to fix them. - -=-= - -Calc Mis-features: - - * The following shell command (written in sh,ksh,bash-like form) works: - - calc '/* - * comment - */ - print 2+3;' - - However this (also written in sh,ksh,bash-like form) does not work: - - echo '/* - * comment - */ - print 2+3;' | calc - - The 2nd example will result in an 'Unterminated comment' error. - * Calc does not support the #! exec method. For example of the following is placed in an executable file (assume the path to calc is correct) called /tmp/xyzzy: @@ -107,3 +81,21 @@ Calc Mis-features: Will result in '"tmp" is undefined' and '"xyzzy" is undefined' error messages because calc considers $0 as an expression to evaluate. + + * The following file: + + /* this is bugdemo.cal */ + x = eval(prompt(">>> ")); + print x; + + when executed as: + + calc read bugdemo.cal + + will obtain a prompt from the terminal, print the value but leave + the terminal in a 'bad' state, as if stty -icanon -echo -echoe + had been executed. + + We are sure some more bugs exist. When you find them, please let + us know! See the above for details on how to report and were to + EMail your bug reports and hopefully patches to fix them. diff --git a/CHANGES b/CHANGES index 4cc50fe..c6ca8d2 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,45 @@ Following is the change from calc version 2.11.0t8.9.1 to date: run in non-interactively / without a TTY such as under Debian's build daemon. + The eval(str) builtin will return an error-value rather than cause + an execution error str has a scan-error. + + Declaration are permitted to end with EOF as well as a newline or ';'. + + When prompt() occurs in reading a file, it will take inout from + the terminal rather than taking it from a file. For example, + this script, when read, now works: + + /* This demonstrates the use of prompt() and some other things */ + config("verbose_quit", 0); + define getnumber() { + local x; + for (;;) { + x = eval(prompt(">>> ")); + if (isnum(x)) + return x; + print "Not a number! Try again"; + } + } + print "This will display the sqrt of each number you enter"; + print "Enter quit to stop"; + for (;;) { + print sqrt(getnumber()); + } + print "Good bye"; + + Comments entered at inputisterminal level may be spread over several + lines. For example: + + /* + * These commands work given the file: comment.cal + * + * cat comment.cal | calc + * calc < comment.cal + */ + print "Hello"; + + Following is the change from calc version 2.11.0t8 to 2.11.0t8.9: diff --git a/codegen.c b/codegen.c index 4528bd8..70361fd 100644 --- a/codegen.c +++ b/codegen.c @@ -409,6 +409,7 @@ getdeclarations(int symtype) case T_NEWLINE: case T_SEMICOLON: case T_RIGHTBRACE: + case T_EOF: rescantoken(); return; diff --git a/func.c b/func.c index 53cc83a..33b9d9d 100644 --- a/func.c +++ b/func.c @@ -155,6 +155,7 @@ f_eval(VALUE *vp) VALUE result; char *str; long num; + int temp; if (vp->v_type != V_STR) return error_value(E_EVAL2); @@ -168,7 +169,10 @@ f_eval(VALUE *vp) } oldfunc = curfunc; enterfilescope(); + temp = stoponerror; + stoponerror = -1; if (evaluate(TRUE)) { + stoponerror = temp; closeinput(); exitfilescope(); freevalue(stack--); @@ -181,6 +185,7 @@ f_eval(VALUE *vp) free(newfunc); return result; } + stoponerror = temp; closeinput(); exitfilescope(); newfunc = curfunc; @@ -203,11 +208,11 @@ f_prompt(VALUE *vp) unsigned int len; result.v_type = V_STR; - if (inputisterminal()) { - printvalue(vp, PRINT_SHORT); - math_flush(); - } + openterminal(); + printvalue(vp, PRINT_SHORT); + math_flush(); cp = nextline(); + closeinput(); if (cp == NULL) { math_error("End of file while prompting"); /*NOTREACHED*/ diff --git a/opcodes.c b/opcodes.c index 2f7a3ab..b163fd0 100644 --- a/opcodes.c +++ b/opcodes.c @@ -3128,8 +3128,7 @@ o_quit(FUNC *fp, long index) s = findstring(index); cp = s->s_str; } - if (inputisterminal() && (fp->f_name[0] == '*') - && (fp->f_name[1] == '\0')) { + if (inputisterminal() && !strcmp(fp->f_name, "*")) { if (cp) printf("%s\n", cp); hist_term(); @@ -3144,7 +3143,7 @@ o_quit(FUNC *fp, long index) printf("%s\n", cp); else if (conf->verbose_quit) printf("Quit or abort executed\n"); - if (!inputisterminal() && fp->f_name[0] == '*') + if (!inputisterminal() && !strcmp(fp->f_name, "*")) closeinput(); go = FALSE; } diff --git a/token.c b/token.c index 0c73fd6..141566b 100644 --- a/token.c +++ b/token.c @@ -335,22 +335,22 @@ static void eatcomment(void) { int ch; - + setprompt(conf->prompt2); for (;;) { ch = nextchar(); if (ch == '*') { ch = nextchar(); if (ch == '/') - return; + break; reread(); } - if ((ch == EOF) || (ch == '\0') || - (newlines && (ch == '\n') && inputisterminal())) { - reread(); - scanerror(T_NULL, "Unterminated comment"); - return; + if (ch == EOF || ch == '\0') { + fprintf(stderr, "Unterminated comment ignored\n"); + reread(); + break; } } + setprompt(conf->prompt1); } diff --git a/version.c b/version.c index a787800..3715f0f 100644 --- a/version.c +++ b/version.c @@ -12,7 +12,7 @@ #define MAJOR_VER 2 /* major version */ #define MINOR_VER 11 /* minor version */ #define MAJOR_PATCH 0 /* patch level or 0 if no patch */ -#define MINOR_PATCH "9" /* test number or empty string if no patch */ +#define MINOR_PATCH "9.1" /* test number or empty string if no patch */ /* * calc version constants