From f39f29a316ed25bbcd0789098e97998ec3b1685d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 16 Feb 2021 15:25:16 +0100 Subject: [PATCH] Better handle command file comment lines --- tasmota/xdrv_50_filesystem.ino | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index f38261118..cfea1788d 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -358,39 +358,43 @@ bool FileRunReady(void) { } void FileRunLoop(void) { - if (FileRunReady()) { return; } - if (!ffs_type) { return; } + if (FileRunReady() || !ffs_type) { return; } if (strlen(UfsData.run_file) && !UfsData.run_file_mutex) { File file = ffsp->open(UfsData.run_file, "r"); - if (!file) { return; } - if (!file.seek(UfsData.run_file_pos)) { return; } + if (!file || !file.seek(UfsData.run_file_pos)) { + UfsData.run_file_pos = -1; + return; + } UfsData.run_file_mutex = true; char cmd_line[512]; - cmd_line[0] = '\0'; // Clear in case of re-entry + cmd_line[0] = '\0'; // Clear in case of re-entry while (file.available()) { uint16_t index = 0; + bool comment = false; while (file.available()) { uint8_t buf[1]; file.read(buf, 1); if ((buf[0] == '\n') || (buf[0] == '\r')) { - break; // Line terminated with linefeed or carriage return + break; // End of command with linefeed or carriage return } - else if (index && (buf[0] == ';')) { - break; // End of multi command line + else if (index && !comment && (buf[0] == ';')) { + break; // End of command on multi command line } else if ((0 == index) && isspace(buf[0])) { - // Skip leading spaces (' ','\t','\n','\v','\f','\r') + // Skip leading spaces (' ','\t','\n','\v','\f','\r') } - else if (index < sizeof(cmd_line) - 2) { - cmd_line[index++] = buf[0]; + else if ((0 == index) && (buf[0] == ';')) { + comment = true; // Ignore comment lines until linefeed or carriage return + } + else if (!comment && (index < sizeof(cmd_line) - 2)) { + cmd_line[index++] = buf[0]; // Build command } } - if ((index > 0) && (index < sizeof(cmd_line) - 1) && (cmd_line[0] != ';')) { - // No comment so try to execute command - cmd_line[index] = '\0'; + if ((index > 0) && (index < sizeof(cmd_line) - 1)) { + cmd_line[index] = '\0'; // Valid command received break; } }