X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/23475fc6e820f19c3fcdf8a6ba38ebbcb6275ee8..8536ac6b661fa261bad7de981045401f514fb6b7:/src/math.c diff --git a/src/math.c b/src/math.c index bac9820..bf7ae8c 100644 --- a/src/math.c +++ b/src/math.c @@ -2,7 +2,7 @@ * * 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. * @@ -24,11 +24,11 @@ #include "saxdb.h" #include "timeq.h" -#ifdef HAVE_TGMATH_H -#include +#ifndef HAVE_MATH_H + #include + #include #else -#include -#include + #include #endif #include @@ -125,6 +125,81 @@ void do_math(char *Buffer, char *Math) 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;