diff options
author | Petr Machata <pmachata@redhat.com> | 2013-11-11 16:08:42 +0100 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-08-22 20:38:24 +0900 |
commit | 033821594643772e1bd1dddaead845ddd5ad41b8 (patch) | |
tree | 77688b48952262c5572774ddec74264b0ed221ed | |
parent | 0b7fca255e51804426056355cfc28458b35cc86a (diff) | |
download | ltrace-033821594643772e1bd1dddaead845ddd5ad41b8.tar.gz ltrace-033821594643772e1bd1dddaead845ddd5ad41b8.tar.bz2 ltrace-033821594643772e1bd1dddaead845ddd5ad41b8.zip |
Use wcwidth to exactly determine how much space a character took
- So far we assumed it's one character worth of screen real-estaty per
character written, but combining and wide characters can change
this.
-rw-r--r-- | lens_default.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lens_default.c b/lens_default.c index 1e57587..958114f 100644 --- a/lens_default.c +++ b/lens_default.c @@ -21,6 +21,8 @@ * 02110-1301 USA */ +#define _XOPEN_SOURCE /* For wcwidth from wchar.h. */ + #include <ctype.h> #include <stdlib.h> #include <assert.h> @@ -28,14 +30,15 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <wchar.h> #include "bits.h" -#include "proc.h" -#include "lens_default.h" -#include "value.h" #include "expr.h" +#include "lens_default.h" +#include "options.h" +#include "output.h" #include "type.h" -#include "common.h" +#include "value.h" #include "zero.h" #define READER(NAME, TYPE) \ @@ -587,7 +590,11 @@ format_wchar(FILE *stream, struct value *value, struct value_dict *arguments) return print_char(stream, buf[0]); buf[c] = 0; - return fprintf(stream, "%s", buf) >= 0 ? 1 : -1; + if (fprintf(stream, "%s", buf) < 0) + return -1; + + c = wcwidth(wc); + return c >= 0 ? c : 0; } static int |