void DefaultExtension (FString &path, const char *extension) { const char *src = &path[int(path.Len())-1]; while (src != &path[0] && !IsSeperator(*src)) { if (*src == '.') return; // it has an extension src--; } path += extension; }
FString ExtractFilePath (const char *path) { const char *src; src = path + strlen(path) - 1; // // back up until a \ or the start // while (src != path && !IsSeperator(*(src-1))) src--; return FString(path, src - path); }
void DefaultExtension (char *path, const char *extension) { char *src; // // if path doesn't have a .EXT, append extension // (extension should include the .) // src = path + strlen(path) - 1; while (src != path && !IsSeperator(*src)) { if (*src == '.') return; // it has an extension src--; } strcat (path, extension); }
FString ExtractFileBase (const char *path, bool include_extension) { const char *src, *dot; src = path + strlen(path) - 1; if (src >= path) { // back up until a / or the start while (src != path && !IsSeperator(*(src-1))) src--; // Check for files with drive specification but no path #if defined(_WIN32) || defined(DOS) if (src == path && src[0] != 0) { if (src[1] == ':') src += 2; } #endif if (!include_extension) { dot = src; while (*dot && *dot != '.') { dot++; } return FString(src, dot - src); } else { return FString(src); } } return FString(); }
class Symbol* Interpreter::GetSymbol(int& position, const char* inputString) { if (IsNumber(inputString[position])) { char buffer[strlen(inputString) +1 ]; int i=0; while (IsNumber(inputString[position]) ) { buffer[i++] = inputString[position++]; } buffer[i] = '\0'; return new Number(strtod(buffer, NULL)); } int i=0, numParens=0; bool done=false; char buffer[ strlen(inputString) + 1 ]; int commandStartIndex=position; if ( inputString[position] == '\0' ) return NULL; while ( ! done) { buffer[i]=inputString[position]; i++; /*error checking? < kMaxInputLength */ if ( IsSeperator(inputString[position]) ) { buffer[i]='\0'; done=true; } else { if ( inputString[position] == '(' ) { buffer[ i ] = '\0'; done=true; numParens++; while (numParens != 0) { position++; if (inputString[position] == '(' ) numParens++; if (inputString[position] == ')' ) numParens--; } } if ( IsSeperator(inputString[position+1]) ) { buffer[i] = '\0'; done=true; } } position++; if ( inputString[position] =='\0' ) { buffer[i] = '\0'; done=true; } } if ( strcmp( buffer, "+") == 0 ) return new Add; if ( strcmp( buffer, "-") == 0 ) return new Subtract; if ( strcmp( buffer, "*") == 0 ) return new Multiply; if ( strcmp( buffer, "/") == 0 ) return new Divide; if ( strcmp( buffer, "^") == 0 ) return new Exponent; if ( strcmp( buffer, "(") == 0 ) { class Paren* symbol= new Paren; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "sqrt(" ) == 0 ) { class SquareRoot* symbol = new SquareRoot; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "cos(" ) == 0 ) { class Cosine* symbol= new Cosine; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "sin(" ) == 0 ) { class Sine* symbol= new Sine; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "tan(" ) == 0 ) { class Tangent* symbol= new Tangent; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "asin(" ) == 0 ) { class Arcsine* symbol= new Arcsine; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "acos(" ) == 0 ) { class Arccosine* symbol= new Arccosine; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "atan(" ) == 0 ) { class Arctangent* symbol= new Arctangent; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "ln(" ) == 0 ) { class NaturalLog* symbol= new NaturalLog; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "log(" ) == 0 ) { class Log* symbol= new Log; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "sinh(" ) == 0 ) { class SineH* symbol= new SineH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "cosh(" ) == 0 ) { class CosineH* symbol= new CosineH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "tanh(" ) == 0 ) { class TangentH* symbol= new TangentH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "asinh(" ) == 0 ) { class ArcsineH* symbol= new ArcsineH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "acosh(" ) == 0 ) { class ArccosineH* symbol= new ArccosineH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "atanh(" ) == 0 ) { class ArctangentH* symbol= new ArctangentH; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "abs(" ) == 0) { class AbsoluteValue* symbol= new AbsoluteValue; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "erf(" ) == 0) { class Erf* symbol= new Erf; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "erfc(" ) == 0) { class Erfc* symbol= new Erfc; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "gamma(" ) == 0) { class Gamma* symbol= new Gamma; ParseExpressionArg(symbol,inputString,commandStartIndex); return symbol; } if ( strcmp( buffer, "j(" ) == 0) { class BesselOne* symbol = new BesselOne; ParseIntArg(symbol,inputString,commandStartIndex,1); ParseExpressionArg(symbol, inputString, commandStartIndex,2); return symbol; } if ( strcmp( buffer, "y(" ) == 0) { class BesselTwo* symbol = new BesselTwo; ParseIntArg(symbol,inputString,commandStartIndex,1); ParseExpressionArg(symbol, inputString, commandStartIndex,2); return symbol; } if ( strcmp( buffer, "pi" ) == 0 ) return new Pi; if ( strcmp( buffer, "e" ) == 0 ) return new ETheNumber; if ( strcmp( buffer, "x" ) == 0 ) return new XTheVariable(&x); if ( strcmp( buffer, "t" ) == 0 ) return new TTheVariable(&x); if ( strcmp( buffer, "theta") == 0 ) return new ThetaTheVariable(&x); errorState=syntax_error; return NULL; }
int ReadInLine(FILE* pFile, REC_INFO* pLineInfo) { char* pLine = NULL; int ret = 0; unsigned int readPos = 0; unsigned int eleLen = 0; size_t lineLen = 0; REC_INFO* pEleEnd = pLineInfo; enum ELE_SEPERATOR_TYPE sepType = SEP_END; pLine = (char*)malloc(MAX_LINE_CHAR_COUNT); OutString(DBG_RES, "Malloc Local pLine\n"); if(pLine == NULL) { return -1; } memset(pLine, 0, MAX_LINE_CHAR_COUNT); ret = -2; while(fgets(pLine, MAX_LINE_CHAR_COUNT, pFile) != NULL) { lineLen = strlen(pLine); for(readPos = 0, eleLen = 0; readPos < lineLen; ++readPos) { if(IsSeperator(pLine[readPos],&sepType)) { if(eleLen > 0) { pEleEnd = PushEleEnd(pEleEnd, ELE_TEXT, pLine + readPos - eleLen, eleLen); if(pEleEnd == NULL) { ret = -3; goto FREE_AND_RETURN; } eleLen = 0; } pEleEnd = PushEleEnd(pEleEnd, ELE_SEPERATOR, &sepType, 0); if(pEleEnd == NULL) { ret = -3; goto FREE_AND_RETURN; } } else { ++eleLen; } } if(eleLen != 0) { pEleEnd = PushEleEnd(pEleEnd, ELE_TEXT, pLine + readPos - eleLen, eleLen); if(pEleEnd == NULL) { ret = -3; goto FREE_AND_RETURN; } eleLen = 0; } if(lineLen == 0) { ret = -4; goto FREE_AND_RETURN; } if(IsLineEnd(pLine[lineLen - 1])) { ret = 0; goto FREE_AND_RETURN; } } FREE_AND_RETURN: free(pLine); OutString(DBG_RES, "FREE Local pLine\n"); return ret; }