diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-10-11 15:38:24 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-10-11 15:38:24 +0300 |
commit | 9092f50e0899fec4a8790f7ab2532b95f470e0a1 (patch) | |
tree | fd824851339a942b9caf7e67dd797af858ed276f | |
parent | 34aa44be5c903f5f5afbedd844be31b12f0cfa5b (diff) |
Added fileexists function
-rw-r--r-- | src/GCodes/GCodeBuffer/ExpressionParser.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/GCodes/GCodeBuffer/ExpressionParser.cpp b/src/GCodes/GCodeBuffer/ExpressionParser.cpp index fdc112dd..b41a8370 100644 --- a/src/GCodes/GCodeBuffer/ExpressionParser.cpp +++ b/src/GCodes/GCodeBuffer/ExpressionParser.cpp @@ -33,7 +33,7 @@ namespace StackUsage // These can't be declared locally inside ParseIdentifierExpression because NamedEnum includes static data NamedEnum(NamedConstant, unsigned int, _false, iterations, line, _null, pi, _result, _true, input); -NamedEnum(Function, unsigned int, abs, acos, asin, atan, atan2, cos, datetime, degrees, exists, floor, isnan, max, min, mod, radians, random, sin, sqrt, tan); +NamedEnum(Function, unsigned int, abs, acos, asin, atan, atan2, cos, datetime, degrees, fileexists, exists, floor, isnan, max, min, mod, radians, random, sin, sqrt, tan); const char * const InvalidExistsMessage = "invalid 'exists' expression"; @@ -1408,6 +1408,32 @@ void ExpressionParser::ParseIdentifierExpression(ExpressionValue& rslt, bool eva } break; + case Function::fileexists: + ConvertToString(rslt, evaluate); + { + bool b; + switch (rslt.GetType()) + { + case TypeCode::CString: + b = reprap.GetPlatform().SysFileExists(rslt.sVal); + break; + + case TypeCode::HeapString: + { + ReadLockedPointer<const char> p = rslt.shVal.Get(); + // We assume that calling SysFileExists doesn't need to use the heap, so we are OK keeping the lock around the call and we don't need to copy the string + b = reprap.GetPlatform().SysFileExists(p.Ptr()); + } + break; + + default: + b = false; + break; + } + rslt.SetBool(b); + } + break; + default: THROW_INTERNAL_ERROR; } |