Commit fa7ac605 fa7ac6058b528897684ec2eed9f396da159d856d by Sergey Poznyakoff

Minor fix in wordwrapper stream

* libmailutils/stream/wordwrap.c (set_margin): Flush the stream
if the new margin equals the current offset.
(_wordwrap_write): Fix conditional
1 parent f52ed2c7
...@@ -132,7 +132,8 @@ _wordwrap_write (mu_stream_t stream, const char *iptr, size_t isize, ...@@ -132,7 +132,8 @@ _wordwrap_write (mu_stream_t stream, const char *iptr, size_t isize,
132 for (n = 0; n < isize; n++) 132 for (n = 0; n < isize; n++)
133 { 133 {
134 if (str->offset == str->right_margin 134 if (str->offset == str->right_margin
135 || (str->offset > 0 && str->buffer[str->offset - 1] == '\n')) 135 || (str->offset > str->left_margin
136 && str->buffer[str->offset - 1] == '\n'))
136 _wordwrap_flush_line (str, iptr[n]); 137 _wordwrap_flush_line (str, iptr[n]);
137 if (str->offset == str->left_margin && mu_isblank (iptr[n])) 138 if (str->offset == str->left_margin && mu_isblank (iptr[n]))
138 continue; 139 continue;
...@@ -178,19 +179,20 @@ set_margin (mu_stream_t stream, unsigned lmargin, int off) ...@@ -178,19 +179,20 @@ set_margin (mu_stream_t stream, unsigned lmargin, int off)
178 if (lmargin >= str->right_margin) 179 if (lmargin >= str->right_margin)
179 return EINVAL; 180 return EINVAL;
180 181
182 /* Flush the stream if the new margin is set to the left of the current
183 column, or it equals the current column and the character in previous
184 column is a word constituent, or the last character on line is a newline.
185 */
181 if (str->offset > str->left_margin 186 if (str->offset > str->left_margin
182 && (lmargin < str->offset || str->buffer[str->offset - 1] == '\n')) 187 && (lmargin < str->offset
183 { 188 || (lmargin == str->offset && is_word (str->buffer[str->offset - 1]))
184 str->left_margin = lmargin; 189 || str->buffer[str->offset - 1] == '\n'))
185 _wordwrap_flush (stream); 190 _wordwrap_flush (stream);
186 } 191
187 else 192 if (lmargin > str->offset)
188 { 193 memset (str->buffer + str->offset, ' ', lmargin - str->offset);
189 if (lmargin > str->offset) 194 str->left_margin = lmargin;
190 memset (str->buffer + str->offset, ' ', lmargin - str->offset); 195 str->offset = lmargin;
191 str->left_margin = lmargin;
192 str->offset = lmargin;
193 }
194 196
195 return 0; 197 return 0;
196 } 198 }
......