Actually make print_wrapped_text() useful
Now, it returns the current column, does not add a newline, and you can pass a negative indent, to indicate that the indent was already printed. With this, you can actually continue in the middle of a paragraph, not having to print everything into a buffer first. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Feb 27, 2007 at 16:20 UTC
094e03b039aeaad759227540491c235b3a83b83a
2 files changed
+13
-6
utf8.c
+12
-5
@@ -235,12 +235,19 @@ static void print_spaces(int count)
235
/*
236
* Wrap the text, if necessary. The variable indent is the indent for the
237
* first line, indent2 is the indent for all other lines.
238
+ * If indent is negative, assume that already -indent columns have been
239
+ * consumed (and no extra indent is necessary for the first line).
240
*/
239
-void print_wrapped_text(const char *text, int indent, int indent2, int width)
241
+int print_wrapped_text(const char *text, int indent, int indent2, int width)
242
{
243
int w = indent, assume_utf8 = is_utf8(text);
244
const char *bol = text, *space = NULL;
245
246
+ if (indent < 0) {
247
+ w = -indent;
248
+ space = text;
249
+ }
250
+
251
for (;;) {
252
char c = *text;
253
if (!c || isspace(c)) {
@@ -251,10 +258,9 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)
258
else
259
print_spaces(indent);
260
fwrite(start, text - start, 1, stdout);
254
- if (!c) {
255
- putchar('\n');
256
- return;
257
- } else if (c == '\t')
261
+ if (!c)
262
+ return w;
263
+ else if (c == '\t')
264
w |= 0x07;
265
space = text;
266
w++;
@@ -275,6 +281,7 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)
281
text++;
282
}
283
}
284
+ return w;
285
}
286
287
int is_encoding_utf8(const char *name)
utf8.h
+1
-1
@@ -5,7 +5,7 @@ int utf8_width(const char **start);
5
int is_utf8(const char *text);
6
int is_encoding_utf8(const char *name);
7
8
-void print_wrapped_text(const char *text, int indent, int indent2, int len);
8
+int print_wrapped_text(const char *text, int indent, int indent2, int len);
9
10
#ifndef NO_ICONV
11
char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);