mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-09 16:58:12 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user