{"thread":{"id":"6992","subject":"[PATCH] Actually make print_wrapped_text() useful","startedAt":"2007-02-27T15:20:31Z","lastAt":"2007-02-27T15:20:31Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35623","messageId":"Pine.LNX.4.63.0702271619350.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6992","inReplyTo":null,"subject":"[PATCH] Actually make print_wrapped_text() useful","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-27T15:20:31Z","receivedAt":"2007-02-27T15:20:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nNow, it returns the current column, does not add a newline, and you can\npass a negative indent, to indicate that the indent was already printed.\n\nWith this, you can actually continue in the middle of a paragraph, not\nhaving to print everything into a buffer first.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n utf8.c |   17 ++++++++++++-----\n utf8.h |    2 +-\n 2 files changed, 13 insertions(+), 6 deletions(-)\n\ndiff --git a/utf8.c b/utf8.c\nindex 7c80eec..ea23a6e 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -235,12 +235,19 @@ static void print_spaces(int count)\n /*\n  * Wrap the text, if necessary. The variable indent is the indent for the\n  * first line, indent2 is the indent for all other lines.\n+ * If indent is negative, assume that already -indent columns have been\n+ * consumed (and no extra indent is necessary for the first line).\n  */\n-void print_wrapped_text(const char *text, int indent, int indent2, int width)\n+int print_wrapped_text(const char *text, int indent, int indent2, int width)\n {\n \tint w = indent, assume_utf8 = is_utf8(text);\n \tconst char *bol = text, *space = NULL;\n \n+\tif (indent < 0) {\n+\t\tw = -indent;\n+\t\tspace = text;\n+\t}\n+\n \tfor (;;) {\n \t\tchar c = *text;\n \t\tif (!c || isspace(c)) {\n@@ -251,10 +258,9 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)\n \t\t\t\telse\n \t\t\t\t\tprint_spaces(indent);\n \t\t\t\tfwrite(start, text - start, 1, stdout);\n-\t\t\t\tif (!c) {\n-\t\t\t\t\tputchar('\\n');\n-\t\t\t\t\treturn;\n-\t\t\t\t} else if (c == '\\t')\n+\t\t\t\tif (!c)\n+\t\t\t\t\treturn w;\n+\t\t\t\telse if (c == '\\t')\n \t\t\t\t\tw |= 0x07;\n \t\t\t\tspace = text;\n \t\t\t\tw++;\n@@ -275,6 +281,7 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width)\n \t\t\ttext++;\n \t\t}\n \t}\n+\treturn w;\n }\n \n int is_encoding_utf8(const char *name)\ndiff --git a/utf8.h b/utf8.h\nindex a07c5a8..15db6f1 100644\n--- a/utf8.h\n+++ b/utf8.h\n@@ -5,7 +5,7 @@ int utf8_width(const char **start);\n int is_utf8(const char *text);\n int is_encoding_utf8(const char *name);\n \n-void print_wrapped_text(const char *text, int indent, int indent2, int len);\n+int print_wrapped_text(const char *text, int indent, int indent2, int len);\n \n #ifndef NO_ICONV\n char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);\n-- \n1.5.0.2.2410.g737b\n"}]}