X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=utf8.c;h=4efef6faf7c71f3201935f81611806af084c45d4;hb=e4cd6c7a20bfc776086817671d58e09060a8079a;hp=211e100b95fa7f4f943965dac3e74339869a9b03;hpb=2832114532d92bdd533f84fa520050c5de95c012;p=git.git diff --git a/utf8.c b/utf8.c index 211e100b9..4efef6faf 100644 --- a/utf8.c +++ b/utf8.c @@ -62,7 +62,7 @@ static int bisearch(ucs_char_t ucs, const struct interval *table, int max) { * in ISO 10646. */ -static int wcwidth(ucs_char_t ch) +static int git_wcwidth(ucs_char_t ch) { /* * Sorted list of non-overlapping intervals of non-spacing characters, @@ -207,7 +207,7 @@ invalid: return 0; } - return wcwidth(ch); + return git_wcwidth(ch); } int is_utf8(const char *text) @@ -237,12 +237,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)) { @@ -253,10 +260,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++; @@ -264,7 +270,7 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width) } else { putchar('\n'); - text = bol = space + 1; + text = bol = space + isspace(*space); space = NULL; w = indent = indent2; } @@ -277,6 +283,7 @@ void print_wrapped_text(const char *text, int indent, int indent2, int width) text++; } } + return w; } int is_encoding_utf8(const char *name) @@ -293,11 +300,17 @@ int is_encoding_utf8(const char *name) * with iconv. If the conversion fails, returns NULL. */ #ifndef NO_ICONV +#ifdef OLD_ICONV + typedef const char * iconv_ibp; +#else + typedef char * iconv_ibp; +#endif char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding) { iconv_t conv; size_t insz, outsz, outalloc; - char *out, *outpos, *cp; + char *out, *outpos; + iconv_ibp cp; if (!in_encoding) return NULL; @@ -309,7 +322,7 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e outalloc = outsz + 1; /* for terminating NUL */ out = xmalloc(outalloc); outpos = out; - cp = (char *)in; + cp = (iconv_ibp)in; while (1) { size_t cnt = iconv(conv, &cp, &insz, &outpos, &outsz);