summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-02-27 16:20:31 +0100
committerJunio C Hamano <junkio@cox.net>2007-02-27 17:29:02 -0800
commit094e03b039aeaad759227540491c235b3a83b83a (patch)
tree97e748a42dc33cde1be07e0ce31737bf90fcd3a6 /utf8.c
parente52a5de45ab8b61bdddf48a466cb3388b38ad7a4 (diff)
downloadgit-094e03b039aeaad759227540491c235b3a83b83a.tar.gz
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>
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/utf8.c b/utf8.c
index 7c80eeccb4..ea23a6e5dc 100644
--- a/utf8.c
+++ b/utf8.c
@@ -235,12 +235,19 @@ static void print_spaces(int count)
/*
* Wrap the text, if necessary. The variable indent is the indent for the
* first line, indent2 is the indent for all other lines.
+ * If indent is negative, assume that already -indent columns have been
+ * consumed (and no extra indent is necessary for the first line).
*/
-void print_wrapped_text(const char *text, int indent, int indent2, int width)
+int print_wrapped_text(const char *text, int indent, int indent2, int width)
{
int w = indent, assume_utf8 = is_utf8(text);
const char *bol = text, *space = NULL;
+ if (indent < 0) {
+ w = -indent;
+ space = text;
+ }
+
for (;;) {
char c = *text;
if (!c || isspace(c)) {
@@ -251,10 +258,9 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)
else
print_spaces(indent);
fwrite(start, text - start, 1, stdout);
- if (!c) {
- putchar('\n');
- return;
- } else if (c == '\t')
+ if (!c)
+ return w;
+ else if (c == '\t')
w |= 0x07;
space = text;
w++;
@@ -275,6 +281,7 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)
text++;
}
}
+ return w;
}
int is_encoding_utf8(const char *name)