display charset

TAKAHASHI Motonobu monyo at samba.gr.jp
Wed Aug 15 13:24:41 GMT 2001

Andrew Tridgel wrote:
>> For example if we have a 6byte string of 3 2byte-characters and have
>> to call printf("%-5.5s\n",str), to call strncpy_fill(), we have a
>> 5byte string of 2 2byte-characters and 1 space. So the string is
>> correctly displayed with printf() and we line up columns, do not we?
>using your example, the %-5.5s means you want to consume 5 columns,


>which is 5 characters.

No, in Japanese all FULL-WIDTH characters included most characters
except ASCII consume 2 columns.
In Japanese we distinguished bytes, columns, characters.
Sorry at first I confused bytes and columns because under SJIS, number
of bytes and columns are same in most cases.

But some vendor defined characters are a half-width (which consumes
1columns) and 2byte characters.

>If you generate a 5 byte string of 2
>2byte-characters and 1 space then you only consume 3 columns, not 5.

Please replace 2byte-characters to 2 full-width characters,
2 full-width-characters and 1 space consume 5 columns.

You can examine this to run the following script like 
  "cscript.exe test.vbs" on Japanese Windows with WSH

wscript.echo chr(&H41) & chr(&h41) & chr(&H41) & chr(&H41) &_
   ": 4chars of half-width A"
wscript.echo chr(&H8260) & chr(&h8260) &_
   ": 2chars of full-width A"

Running with cscript.exe is important because in console Windows uses
*non-proportional* fonts like UNIX terminal.

>What you would want in this case is to print all 3 2byte-characters
>and 2 spaces, giving a total of 5 characters (ie. 5 columns) but 8

What I want is to print 5 columns, not 5 characters nor 8 bytes.

>btw, I have looked again at the number of places you currently call
>strncpy_fill() in the ja version, and it is really very small, so I
>now think your original suggstion of having a fill function is the
>correct solution. My idea of modifying printf() is not worth it for so
>few cases.


>What if we used something like this:
>/* format a unix string to be n bytes wide when displayed in the
>   display charset. Uses a static return array. Limited to sizeof(pstring) */
>char *str_format_width(const char *s, int n)
>	static pstring s2;
>	wpstring ws;
>	int i;
>	push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
>	ws[n] = 0;
>	for (i=strlen_w(ws); i<n; i++) {
>		ws[i] = UCS2_CHAR(' ');
>	}
>	pull_ucs2_pstring(s2, ws);
>	return s2;
>does that look ok? (totally untested ...)
>Then we'd use it like this:
>dprintf("This string in 7 columns [%s]\n", str_format_width(s, 7));
>We'd need to do a right-justified version as well.

As I explained, this cannot solve this problem.

Is there anything wrong?

TAKAHASHI, Motonobu(monyo)         monyo at samba.org
Personal - http://home.monyo.com/
Samba Team - http://samba.org/     Samba-JP - http://www.samba.gr.jp/  
JWNTUG - http://www.jwntug.or.jp/  Analog-JP - http://www.jp.analog.cx/

More information about the samba-technical mailing list