*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. Important limitations are
* listed in the COPYING file that accompanies this software.
*
#include "modcmd.h"
#include "saxdb.h"
#include "timeq.h"
-#include <stdio.h>
+
+#ifdef HAVE_TGMATH_H
+#include <tgmath.h>
+#else
+#include <math.h>
+#include <complex.h>
+#endif
+
#include <ctype.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
#include <time.h>
#ifdef WIN32
int Index;
int OEndExpected;
+
+ /* This is a HACK to insert * before ( so multiplication takes place
+ * in things such as 3(3) instead of ignoring the first 3. Submitted
+ * by Osiris.
+ * I spent some time tlooking at calc.c and I didnt see an easy way
+ * to do this there... and that file gives me a headache.. so.. -Rubin
+ */
+ char newMath[MAXLEN];
+ char *ptr;
+ char lastNumber = false;
+ char lastBracket = false;
+
+
+ ptr = newMath;
+ while(*Math && ptr < newMath+MAXLEN-1)
+ {
+ switch(*Math)
+ {
+ case '1': case '2':
+ case '3': case '4':
+ case '5': case '6':
+ case '7': case '8':
+ case '9': case '0':
+ lastNumber = true;
+ if(lastBracket == true)
+ {
+ *ptr = '*';
+ ptr++;
+ }
+ *ptr = *Math;
+ lastBracket = false;
+ break;
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
+ case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
+ case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
+ case 'v': case 'w': case 'x': case 'y': case 'z':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
+ case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
+ case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
+ case 'V': case 'W': case 'X': case 'Y': case 'Z':
+ case ')': case ']': /* Support sin[12](3) also */
+ lastNumber = true;
+ lastBracket = true;
+ *ptr = *Math;
+ break;
+ case '(': case '[':
+ if (lastNumber == true)
+ {
+ *ptr = '*';
+ ptr++;
+ }
+ *ptr = *Math;
+ lastNumber = false;
+ lastBracket = false;
+ break;
+ default:
+ if(isalpha(*Math))
+ {
+ if(lastNumber == true)
+ {
+ *ptr = '*';
+ ptr++;
+ }
+ }
+ *ptr = *Math;
+ lastNumber = false;
+ lastBracket = false;
+ break;
+ }
+ Math++;
+ ptr++;
+ }
+ *ptr = '\0';
+ Math = newMath;
+
if (!(List = ListFirst = malloc(sizeof(struct MathToken)))) goto MemError;
if (!(Stack = StackFirst = malloc(sizeof(struct MathToken)))) goto MemError;
if (!(PostFix = PostFixFirst = malloc(sizeof(struct MathToken)))) goto MemError;