Repository navigation
batch: truncate overlong ECHO lines instead of aborting the batch file - #197
Open
PerditionC wants to merge 1 commit into
Open
PerditionC wants to merge 1 commit into
PerditionC wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
🟡 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
| line = ltrimcl(line); | ||
| if (*line == '@') | ||
| line = ltrimcl(line + 1); | ||
| return strnicmp(line, "ECHO", 4) == 0 && !isalnum(line[4]); |
Comment on lines
+580
to
+581
| ip = textline + size - 2; | ||
| *ip = '\n'; |
Comment on lines
+580
to
+581
| ip = textline + size - 2; | ||
| *ip = '\n'; |
|
|
||
| if ((ip = textlineEnd(textline, size)) == 0) /* line too long */ | ||
| { | ||
| if (!isEchoLine(textline)) |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.