#!/bin/sh if [ "$1" != "" ]; then LD_PRELOAD=$1 export LD_PRELOAD fi whiptail --menu test 20 50 5 2 'sdasdsd' 3 'dfdfdsfds' 4 'dfdsfsdfdsfdfds' 1 '日本語' 2 'one more line' 3 'other line' 4 'and other more'
#include <slang.h> #include <stdio.h> int main(void) { SLuchar_Type string[] = "\xE4"; unsigned int dnum; SLutf8_skip_chars(string, string+1, 1, &dnum, 1); printf("%d\n", dnum); return 0; }
slsmg.c contains: void SLsmg_write_nstring (char *str, unsigned int n) { ... if (UTF8_Mode) umax = SLutf8_skip_chars (u, u+width, n, &width, 0); ... SLsmg_write_chars (u, umax); } while (width++ < n) SLsmg_write_chars (blank, blank+1); } from last line: 'n' is string width. Let's look at SLutf8_skip_chars, in slutf8.c: SLuchar_Type *SLutf8_skip_chars (SLuchar_Type *s, SLuchar_Type *smax, unsigned int num, unsigned int *dnum, int ignore_combining) { unsigned int n; n = 0; while ((n < num) && (s < smax)) { ... /* here code that modifies n always adds 1, nothing depends on * character width */ ... So here num, aka n in previous function, is used as number of characters and not as string width.
#include <slang.h> #include <stdio.h> int main(void) { SLuchar_Type string[] = "\xE3\x82\xA6\xE3\x82\xA7\xE3\x83\x96\xE3"; unsigned int dnum; SLutf8_skip_chars(string, string+9, 1, &dnum, 1); printf("%d\n", dnum); return 0; }
#
diff -ruN slang-2.0.4-old/src/slutf8.c slang-2.0.4/src/slutf8.c --- slang-2.0.4-old/src/slutf8.c 2005-06-20 18:56:22.000000000 +0300 +++ slang-2.0.4/src/slutf8.c 2005-07-14 18:23:07.456402952 +0300 @@ -148,19 +148,15 @@ continue; } - if (ignore_combining) - { + int wi; SLwchar_Type w = fast_utf8_decode (s, len); - if (0 != SLwchar_wcwidth (w)) - n++; + wi = SLwchar_wcwidth (w); + n+=wi; s += len; continue; - } - - n++; - s += len; } - +#if 0 + /* XXX how this should work???? */ if (ignore_combining) { while (s < smax) @@ -176,7 +172,7 @@ s += nconsumed; } } - +#endif if (dnum != NULL) *dnum = n; return s;