Skip to content

batch: truncate overlong ECHO lines instead of aborting the batch file - #197

Open
PerditionC wants to merge 1 commit into
masterfrom
batch-long-echo
Open

PerditionC wants to merge 1 commit into
masterfrom
batch-long-echo

Conversation

@PerditionC

Copy link
Copy Markdown
Contributor

A batch file line longer than the line buffer (254 characters) made FreeCOM print Line ... too long and exit the batch file. Instead we want to ignore the rest of the line so a batch file with long ECHO comments or menus continues truncating the long ECHOs.

Only for ECHO lines (optionally with '@') keep what fits in the buffer, skip the rest of the line in the file and carry on. Other overlong lines still give the error and end the batch file, so a truncated command is never executed.

A batch file line longer than the line buffer (254 characters) made
FreeCOM print Line ... too long and exit the batch file.  Instead we
want to ignore the rest of the line so a batch file with long ECHO
comments or menus continues truncating the long ECHOs.

Only for ECHO lines (optionally with '@') keep what fits in the buffer, skip
the rest of the line in the file and carry on.  Other overlong lines
still give the error and end the batch file, so a truncated command is
never executed.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Overlong-line truncation can misclassify commands or alter executable pipes and redirections, risking unintended file deletion or overwrites.

4 open issues
What changed in this PR

Updates FreeCOM’s batch reader to truncate overlong ECHO lines and continue processing, while preserving errors for other overlong commands.

Changes:

  • Recognizes ECHO lines, including those prefixed with @, and skips their excess text.
  • Adds batch examples covering continuation, label searches, and long menu output.
File Description
tests/​longline.bat Exercises truncation, continuation, label searches, and @echo.
tests/​longecho.bat Adds a long menu-style ECHO example.
shell/​batch.c Implements ECHO detection, truncation, and remainder skipping.

Review effort: Balanced

Comment thread shell/batch.c
line = ltrimcl(line);
if (*line == '@')
line = ltrimcl(line + 1);
return strnicmp(line, "ECHO", 4) == 0 && !isalnum(line[4]);
Comment thread shell/batch.c
Comment on lines +580 to +581
ip = textline + size - 2;
*ip = '\n';
Comment thread shell/batch.c
Comment on lines +580 to +581
ip = textline + size - 2;
*ip = '\n';
Comment thread shell/batch.c

if ((ip = textlineEnd(textline, size)) == 0) /* line too long */
{
if (!isEchoLine(textline))
@PerditionC

Copy link
Copy Markdown
Contributor Author

Copilot review unexpected, will need to look into disabling it unless requested. but since its there may update patch before committing, this was a cleaned hack/test from a while back sitting in my tree locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants