--- freem/src/operator.c 2025/03/09 19:50:47 1.5 +++ freem/src/operator.c 2025/05/05 23:02:39 1.10 @@ -1,5 +1,5 @@ /* - * $Id: operator.c,v 1.5 2025/03/09 19:50:47 snw Exp $ + * $Id: operator.c,v 1.10 2025/05/05 23:02:39 snw Exp $ * operators pattern-match, divide, multiply, add, power * * @@ -24,6 +24,21 @@ * along with FreeM. If not, see . * * $Log: operator.c,v $ + * Revision 1.10 2025/05/05 23:02:39 snw + * More fixes around E notation + * + * Revision 1.9 2025/05/05 22:52:32 snw + * Make E notation error message more appropriate + * + * Revision 1.8 2025/05/05 19:34:46 snw + * Fix E notation code to disallow more than one minus sign after the E + * + * Revision 1.7 2025/04/10 01:24:38 snw + * Remove C++ style comments + * + * Revision 1.6 2025/04/09 19:52:02 snw + * Eliminate as many warnings as possible while building with -Wall + * * Revision 1.5 2025/03/09 19:50:47 snw * Second phase of REUSE compliance and header reformat * @@ -35,6 +50,7 @@ #include "mpsdef.h" #include #include +#include int unit (char *str); extern void cond_round (char *a, int digits); /* defined in expr.c */ @@ -796,8 +812,8 @@ void add (char *a, char *b) /* string mi = 1; a[0] = ZERO; } - while (a[mi] == ZERO) { - stcpy (&a[mi], &a[mi + 1]); + while (a[(int) mi] == ZERO) { + stcpy (&a[(int) mi], &a[((int) mi) + 1]); dpa--; } if (dpa < 0) @@ -825,7 +841,7 @@ void add (char *a, char *b) /* string } a[0] = MINUS; } - if (a[mi] == EOL) { + if (a[(int) mi] == EOL) { a[0] = ZERO; a[1] = EOL; } @@ -1123,7 +1139,7 @@ void mdiv (char *uu, char *v, short typ) case '#': snprintf (uu, STRLEN - 1, "%ld\201", (((long) fp_uu) % ((long) fp_v))); - //snprintf (uu, STRLEN - 1, "%ld\201", ((long) fp_uu < 0 ? (((long) fp_uu % (long) fp_v) + (long) fp_v) % (long) fp_v : (long) fp_uu % (long) fp_v)); + /*snprintf (uu, STRLEN - 1, "%ld\201", ((long) fp_uu < 0 ? (((long) fp_uu % (long) fp_v) + (long) fp_v) % (long) fp_v : (long) fp_uu % (long) fp_v)); */ break; } @@ -1969,11 +1985,28 @@ int numlit (char *str) } if (expflg) { if (ch == MINUS) { + if (str[i + 1] == '-') { + merr_raise (INVEXPR); + return (0); + } + if (!isdigit (str[i + 1])) { + merr_raise (INVEXPR); + return (0); + } expflg = (-expflg); continue; } - if (ch == PLUS) + if (ch == PLUS) { + if (str[i + 1] == '+') { + merr_raise (INVEXPR); + return (0); + } + if (!isdigit (str[i + 1])) { + merr_raise (INVEXPR); + return (0); + } continue; + } } if ((result = unit (&str[i]))) ch = str[i] = EOL;