commit 3270a74590d4bfbbc9ae1fdc4c1d36eed943844f
parent 320676ca5bc1980c96f5e4bc14240a741be8f3be
Author: René Wagner <rwagner@rw-net.de>
Date: Tue, 5 Jan 2021 17:45:56 +0100
preserve all bytes except spaces when wrapping
When wrapping the new line should not start with a space.
All other bytes must be preserved to avoid breaking unicode chars.
fix for ~sircmpwn/gmni#21
Diffstat:
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/cgmnlm.c b/src/cgmnlm.c
@@ -733,9 +733,7 @@ wrap(FILE *f, char *s, struct winsize *ws, int *row, int *col)
// skip unicode continuation bytes
if ((s[i] & 0xc0) == 0x80) break;
- if (iscntrl(s[i])) {
- s[i] = '.';
- }
+ if (iscntrl(s[i])) s[i] = '.';
*col += 1;
break;
}
@@ -743,12 +741,10 @@ wrap(FILE *f, char *s, struct winsize *ws, int *row, int *col)
if (*col >= ws->ws_col) {
int j = i--;
while (&s[i] != s && !isspace(s[i])) --i;
- if (&s[i] == s) {
- i = j;
- }
+ if (&s[i] == s) i = j;
char c = s[i];
s[i] = 0;
- int n = fprintf(f, "%s\n", s);
+ int n = fprintf(f, "%s\n", s) - (isspace(c) ? 0 : 1);
s[i] = c;
*row += 1;
*col = 0;