Skip to content

Commit

Permalink
Fix wrong consumed input counter in dolineprefix
Browse files Browse the repository at this point in the history
Closes Gottox#22.
  • Loading branch information
karlb committed Jul 17, 2022
1 parent 1e57d4c commit 08cb817
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions smu.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ dolineprefix(const char *begin, const char *end, int newblock) {
unsigned int i, j, l;
char *buffer;
const char *p;
int consumed_input = 0;

if (newblock)
p = begin;
else if (*begin == '\n')
else if (*begin == '\n') {
p = begin + 1;
else
consumed_input += 1;
} else
return 0;
for (i = 0; i < LENGTH(lineprefix); i++) {
l = strlen(lineprefix[i].search);
Expand All @@ -244,7 +246,7 @@ dolineprefix(const char *begin, const char *end, int newblock) {
fputs(lineprefix[i].before, stdout);
if (lineprefix[i].search[l-1] == '\n') {
fputc('\n', stdout);
return l - 1;
return l - 1 + consumed_input;
}
if (!(buffer = malloc(BUFSIZ)))
eprint("Malloc failed.");
Expand Down

0 comments on commit 08cb817

Please sign in to comment.