Oops, patch attached :-)
--
Eugeniy Meshcheryakov
Kyiv National Taras Shevchenko University
Information and Computing Centre
http://icc.univ.kiev.ua
Index: slangui.c
===================================================================
--- slangui.c (revision 409)
+++ slangui.c (working copy)
@@ -239,7 +239,7 @@
_("Debian Task Installer v%s - (c) 1999-2004 SPI and others"),
VERSION);
SLsmg_gotorc(0, 0);
- SLsmg_write_nstring(buf, strlen(buf));
+ SLsmg_write_string(buf);
_resizing = 0;
switch (_chooserinfo.whichwindow) {
@@ -350,7 +350,7 @@
void ui_shadow(int y, int x, unsigned int dy, unsigned int dx)
{
int c;
- unsigned short ch;
+ SLsmg_Char_Type ch;
if (SLtt_Use_Ansi_Colors) {
for (c=0;c<dy-1;c++) {
@@ -360,13 +360,13 @@
* character plus alternate character set attribute. -- JED
*/
ch = SLsmg_char_at();
- ch = (ch & 0x80FF) | (0x02 << 8);
+ ch = SLSMG_BUILD_CHAR(SLSMG_EXTRACT_CHAR(ch), 0x2);
SLsmg_write_raw(&ch, 1);
}
for (c=0;c<dx;c++) {
SLsmg_gotorc(y+dy, x+1+c);
ch = SLsmg_char_at();
- ch = (ch & 0x80FF) | (0x02 << 8);
+ ch = SLSMG_BUILD_CHAR(SLSMG_EXTRACT_CHAR(ch), 0x2);
SLsmg_write_raw(&ch, 1);
}
}
@@ -398,12 +398,12 @@
* of the other buttons into account.
*/
ui_button(_chooserinfo.rowoffset + _chooserinfo.height + 1,
- _chooserinfo.coloffset + (_chooserinfo.width - strlen(_("Task ^Info")) + 1) / 2,
+ _chooserinfo.coloffset + (_chooserinfo.width - ts_mbstrwidth(_("Task ^Info")) + 1) / 2,
_("Task ^Info"), issel);
break;
case BUTTON_HELP: // Right justified
ui_button(_chooserinfo.rowoffset + _chooserinfo.height + 1,
- _chooserinfo.coloffset + _chooserinfo.width - 5 - strlen(_("^Help")) + 1,
+ _chooserinfo.coloffset + _chooserinfo.width - 5 - ts_mbstrwidth(_("^Help")) + 1,
_("^Help"), issel);
break;
}
@@ -512,18 +512,24 @@
SLsmg_gotorc(row, col);
SLsmg_write_char('<');
/* Anything following a ^ in txt is highlighted, and the ^ removed. */
- p = strchr(txt, '^');
+ p = ts_mbstrchr(txt, L'^');
if (p) {
+ wchar_t w;
+ int ret;
+
if (p > txt) {
- SLsmg_write_nstring(txt, p - txt);
+ SLsmg_write_nchars(txt, p - txt);
}
p++;
if (selected)
SLsmg_set_color(SELHIGHLIGHT);
else
SLsmg_set_color(HIGHLIGHT);
- SLsmg_write_char(p[0]);
- p++;
+ ret = mbtowc(&w, p, MB_CUR_MAX);
+ if (ret <=0)
+ return;
+ SLsmg_write_char(w);
+ p += ret;
if (selected)
SLsmg_set_color(SELBUTTONOBJ);
else
@@ -537,7 +543,7 @@
void ui_title(int row, int col, int width, char *title)
{
- int pos = col + (width - strlen(title))/2;
+ int pos = col + (width - ts_mbstrwidth(title))/2;
SLsmg_gotorc(row, pos - 1);
SLsmg_set_char_set(1);
SLsmg_write_char(SLSMG_RTEE_CHAR);
@@ -564,7 +570,7 @@
SLsmg_fill_region(row+1, col+1, height-2, width-2, ' ');
for (ri = topline; ri < numlines && ri - topline < height - hoffset; ri++) {
SLsmg_gotorc(row + 1 + ri-topline, col + 1);
- if (strlen(buf[ri]) > leftcol)
+ if (ts_mbstrwidth(buf[ri]) > leftcol)
SLsmg_write_nstring(buf[ri]+leftcol, width - woffset);
}
if (scroll & SCROLLBAR_VERT && numlines > height-hoffset)
@@ -671,7 +677,7 @@
SLsmg_gotorc(row, _chooserinfo.coloffset + 1 + 2);
snprintf(buf, 1024, " %s ", getsectiondesc(TASK_SECTION(_tasksary[index])));
SLsmg_write_nstring(buf, _chooserinfo.width - 1 - 2);
- spot = 1 + 2 + strlen(buf);
+ spot = 1 + 2 + ts_mbstrwidth(buf);
if (spot > _chooserinfo.width / 2 - 3) spot = _chooserinfo.width / 2 - 3;
SLsmg_gotorc(row, _chooserinfo.coloffset + spot);
SLsmg_draw_hline( _chooserinfo.width / 2 - spot );
Index: strutl.h
===================================================================
--- strutl.h (revision 409)
+++ strutl.h (working copy)
@@ -1,7 +1,10 @@
/* $Id: strutl.h,v 1.1 1999/11/21 22:01:04 tausq Rel $ */
#ifndef _STRUTL_H
#define _STRUTL_H
+#include <wchar.h>
char *reflowtext(int width, char *txt);
+char *ts_mbstrchr(char *, wchar_t);
+int ts_mbstrwidth(const char *);
#endif
Index: Makefile
===================================================================
--- Makefile (revision 409)
+++ Makefile (working copy)
@@ -8,10 +8,10 @@
CFLAGS=-g -Wall #-Os
DEBUG=1
ifeq (0,$(DEBUG))
-DEFS=-DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\"/usr/share/locale\" \
+DEFS=-DUTF8 -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\"/usr/share/locale\" \
-DTASKDIR=\"$(TASKDIR)\"
else
-DEFS=-DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\"/usr/share/locale\" \
+DEFS=-DUTF8 -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\"/usr/share/locale\" \
-DTASKDIR=\".\" -DDEBUG
endif
VERSION=$(shell expr "`dpkg-parsechangelog 2>/dev/null |grep Version:`" : '.*Version: \(.*\)' | cut -d - -f 1)
Index: strutl.c
===================================================================
--- strutl.c (revision 409)
+++ strutl.c (working copy)
@@ -17,3 +17,39 @@
return textwrap(&t, ptxt);
}
+char *ts_mbstrchr(char *s, wchar_t c)
+{
+ char *p = s;
+
+ while (*p) {
+ wchar_t w;
+ int ret;
+
+ ret = mbtowc(&w, p, MB_CUR_MAX);
+ if (ret <= 0)
+ return NULL;
+ if (w == c)
+ return p;
+ p += ret;
+ }
+ return NULL;
+}
+
+int ts_mbstrwidth(const char *s)
+{
+ const char *p = s;
+ int width = 0;
+
+ while (*p) {
+ wchar_t w;
+ int ret;
+
+ ret = mbtowc(&w, p, MB_CUR_MAX);
+ if (ret < 0) return 0;
+ if (ret == 0) break;
+ width += wcwidth(w);
+ p += ret;
+ }
+ return width;
+}
+