Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncritical ruler fixes #8

Merged
merged 4 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions smu.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,18 @@ 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);
if (end - p < l)
if (end - p + 1 < l)
continue;
if (strncmp(lineprefix[i].search, p, l))
continue;
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
8 changes: 8 additions & 0 deletions tests/ruler.correct.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<hr />

test
<hr />
<p>bar</p>
<hr />
<p>foo</p>
<hr />
9 changes: 9 additions & 0 deletions tests/ruler.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<hr />

test
<hr />
<p>bar</p>
<hr />
<p>foo
<hr />
</p>
11 changes: 11 additions & 0 deletions tests/ruler.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- - -
test
- - -

bar

- - -

foo
- - -