diff --git a/CHANGES b/CHANGES index 6d41f4f..31939b0 100644 --- a/CHANGES +++ b/CHANGES @@ -96,6 +96,13 @@ Following is the change from calc version 2.11.0t7 to date: A call of errmax(-1) will prevent errcount from aborting calc. + Add the function stoponerror(n) which, as the name implies, controls + if calc stop on an error based on the value of n: + + n > 0 stop on error even if -c was given on the command line + n == 0 if -c, continue, without -c, stop + n < 0 continue on error, even if -c was given on the command line + Following is the change from calc version 2.11.0t1 to 2.11.0t6.3: diff --git a/calc.c b/calc.c index 79df6cf..b050010 100644 --- a/calc.c +++ b/calc.c @@ -50,6 +50,7 @@ extern int p_flag; /* TRUE => pipe mode */ extern int q_flag; /* TRUE => don't execute rc files */ extern int u_flag; /* TRUE => unbuffer stdin and stdout */ extern int d_flag; /* TRUE => disable heading, lib_debug == 0 */ +extern int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ extern char *pager; /* $PAGER or default */ extern int stdin_tty; /* TRUE if stdin is a tty */ @@ -268,9 +269,17 @@ main(int argc, char **argv) } if (start_done == 1) { fprintf(stderr, "Execution error in rcfiles\n"); - if (c_flag) + if ((c_flag && !stoponerror) || stoponerror < 0) { getcommands(FALSE); - start_done = 2; + start_done = 2; + } else { + if ((havecommands && !i_flag) || !stdin_tty) + start_done = 7; + else if (havecommands) + start_done = 4; + else + start_done = 2; + } } if (start_done == 2) { if (havecommands) { @@ -282,11 +291,17 @@ main(int argc, char **argv) } if (start_done == 3) { fprintf(stderr, "Execution error in commands\n"); - if (c_flag) + if ((c_flag && !stoponerror) || stoponerror < 0) { getcommands(FALSE); - else + start_done = 4; + } + else { closeinput(); - start_done = 4; + if (!stdin_tty || !i_flag) + start_done = 7; + else + start_done = 4; + } } if (start_done == 4) { if (stdin_tty && ((havecommands && !i_flag) || p_flag)) @@ -295,10 +310,13 @@ main(int argc, char **argv) openterminal(); } else if (start_done == 5) { - if (!stdin_tty && !c_flag) { - start_done = 6; + if (!stdin_tty && (!c_flag || stoponerror) && stoponerror >= 0) { + start_done = 7; } - reinitialize(); + else if ((c_flag && !stoponerror) || stoponerror < 0) + getcommands(FALSE); + else + reinitialize(); } if (start_done < 6) { diff --git a/codegen.c b/codegen.c index 2aa52f1..b20b390 100644 --- a/codegen.c +++ b/codegen.c @@ -829,6 +829,8 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d printeol = TRUE; for (;;) { switch (gettoken()) { + case T_RIGHTPAREN: + case T_RIGHTBRACKET: case T_RIGHTBRACE: case T_NEWLINE: case T_EOF: diff --git a/func.c b/func.c index b309fac..1e2906c 100644 --- a/func.c +++ b/func.c @@ -84,6 +84,8 @@ extern void matrandperm(MATRIX *M); extern void listrandperm(LIST *lp); extern int idungetc(FILEID id, int ch); +extern int stoponerror; + /* * if HZ & CLK_TCK are not defined, pick typical values, hope for the best @@ -4476,6 +4478,30 @@ f_errmax(int count, VALUE **vals) } +static VALUE +f_stoponerror(int count, VALUE **vals) +{ + int oldval; + VALUE *vp; + VALUE result; + + oldval = stoponerror; + if (count > 0) { + vp = vals[0]; + + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || + zge31b(vp->v_num->num)) + fprintf(stderr, + "Out-of-range arg for stoponerror ignored\n"); + else + stoponerror = (int) ztoi(vp->v_num->num); + } + + result.v_type = V_NUM; + result.v_num = itoq((long) oldval); + return result; +} + static VALUE f_fclose(int count, VALUE **vals) { @@ -7206,6 +7232,8 @@ static CONST struct builtin builtins[] = { "seed the random() function"}, {"ssq", 1, IN, 0, OP_NOP, 0, f_ssq, "sum of squares of values"}, + {"stoponerror", 0, 1, 0, OP_NOP, 0, f_stoponerror, + "assign value to stoponerror flag"}, {"str", 1, 1, 0, OP_NOP, 0, f_str, "simple value converted to string"}, {"strcat", 1,IN, 0, OP_NOP, 0, f_strcat, diff --git a/lib_calc.c b/lib_calc.c index afdba64..e6b41c4 100644 --- a/lib_calc.c +++ b/lib_calc.c @@ -84,6 +84,7 @@ int q_flag = FALSE; /* TRUE => don't execute rc files */ int u_flag = FALSE; /* TRUE => unbuffer stdin and stdout */ int d_flag = FALSE; /* TRUE => disable heading, lib_debug == 0 */ +int stoponerror = FALSE; /* >0 => stop, <0 => continue on error */ /* * global values diff --git a/version.c b/version.c index 2657d4a..7f12936 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 "7" /* test number or empty string if no patch */ +#define MINOR_PATCH "7.1" /* test number or empty string if no patch */ /* * calc version constants @@ -80,7 +80,3 @@ version(void) */ return stored_version; } - - - -/* END CODE */