diff --git a/src/cmnds/cmd_if.c b/src/cmnds/cmd_if.c index c9ba1da2e..0bd7b962f 100644 --- a/src/cmnds/cmd_if.c +++ b/src/cmnds/cmd_if.c @@ -271,6 +271,7 @@ void SIM_GenerateChannelStatesDesc(char *o, int outLen) { const char *CMD_ExpandConstantString(const char *s, const char *stop, char *out, int outLen) { int idx; const char *ret; + char tmp[32]; ret = strCompareBound(s, "$autoexec.bat", stop, false); if (ret) { @@ -281,6 +282,31 @@ const char *CMD_ExpandConstantString(const char *s, const char *stop, char *out, free(data); return ret; } + ret = strCompareBound(s, "$readfile(", stop, false); + if (ret) { + const char *opening = ret; + const char *closingBrace = ret; + while (1) { + if (*closingBrace == 0) + return false; // fail + if (*closingBrace == ')') { + break; + } + closingBrace++; + } + ret = closingBrace + 1; + idx = closingBrace - opening; + if (idx >= sizeof(tmp) - 1) + idx = sizeof(tmp) - 2; + strncpy(tmp, opening, idx); + tmp[idx] = 0; + byte* data = LFS_ReadFile(tmp); + if (data == 0) + return false; + strcpy_safe(out, (char*)data, outLen); + free(data); + return ret; + } ret = strCompareBound(s, "$pinstates", stop, false); if (ret) { SIM_GeneratePinStatesDesc(out, outLen);