string expansion is now able to support $readfile(filename.txt) syntax, right now this is only for simulator, this will read file content from LFS

This commit is contained in:
openshwprojects
2022-12-08 17:43:30 +01:00
parent cd1ebbc6f5
commit dd6b89b73a

View File

@@ -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);