]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/slang-debian-utf8.patch
asterisk addon: update to 11.13.1
[people/pmueller/ipfire-2.x.git] / src / patches / slang-debian-utf8.patch
1 --- slang-1.4.4.orig/src/slinclud.h
2 +++ slang-1.4.4/src/slinclud.h
3 @@ -23,4 +23,12 @@
4 # include <memory.h>
5 #endif
6
7 +#define UTF8 1
8 +
9 +#ifdef UTF8
10 +#include <wchar.h>
11 +#include <limits.h>
12 +#endif /* UTF8 */
13 +
14 +
15 #endif /* _SLANG_INCLUDE_H_ */
16 --- slang-1.4.4.orig/src/slang.h
17 +++ slang-1.4.4/src/slang.h
18 @@ -1239,10 +1239,20 @@
19 extern int SLtt_Msdos_Cheap_Video;
20 #endif
21
22 +#define UTF8 1
23 +
24 +#ifdef UTF8
25 +typedef int SLsmg_Char_Type;
26 +#define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFFFFFF)
27 +#define SLSMG_EXTRACT_COLOR(x) (((x)>>24)&0xFF)
28 +#define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(wchar_t)(ch))|((color)<<24))
29 +#define SLSMG_NOCHAR 1
30 +#else
31 typedef unsigned short SLsmg_Char_Type;
32 #define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFF)
33 #define SLSMG_EXTRACT_COLOR(x) (((x)>>8)&0xFF)
34 #define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(unsigned char)(ch))|((color)<<8))
35 +#endif /* UTF8 */
36
37 extern int SLtt_flush_output (void);
38 extern void SLtt_set_scroll_region(int, int);
39 @@ -1334,7 +1342,11 @@
40
41 /*{{{ SLsmg Screen Management Functions */
42
43 +#ifdef UTF8
44 +extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, wchar_t);
45 +#else
46 extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, unsigned char);
47 +#endif /* UTF8 */
48 extern void SLsmg_set_char_set (int);
49 #ifndef IBMPC_SYSTEM
50 extern int SLsmg_Scroll_Hash_Border;
51 @@ -1351,7 +1363,12 @@
52 extern void SLsmg_vprintf (char *, va_list);
53 extern void SLsmg_write_string (char *);
54 extern void SLsmg_write_nstring (char *, unsigned int);
55 +#ifdef UTF8
56 +extern void SLsmg_write_char (wchar_t);
57 +extern void SLsmg_write_nwchars (wchar_t *, unsigned int);
58 +#else
59 extern void SLsmg_write_char (char);
60 +#endif /* UTF8 */
61 extern void SLsmg_write_nchars (char *, unsigned int);
62 extern void SLsmg_write_wrapped_string (char *, int, int, unsigned int, unsigned int, int);
63 extern void SLsmg_cls (void);
64 --- slang-1.4.4.orig/src/slcurses.c
65 +++ slang-1.4.4/src/slcurses.c
66 @@ -440,20 +440,130 @@
67
68 static int do_newline (SLcurses_Window_Type *w)
69 {
70 - w->_curx = 0;
71 + /* w->_curx = 0; */
72 w->_cury += 1;
73 if (w->_cury >= w->scroll_max)
74 {
75 w->_cury = w->scroll_max - 1;
76 - if (w->scroll_ok)
77 + if (w->scroll_ok) {
78 + w->_curx = 0;
79 SLcurses_wscrl (w, 1);
80 + }
81 }
82 + else
83 + w->_curx = 0;
84 +
85 + return 0;
86 +}
87 +
88 +#ifdef UTF8
89 +static int SLcurses_waddch1 (SLcurses_Window_Type *win,
90 + wchar_t ch, int color)
91 +{
92 + SLsmg_Char_Type *b, *bmin, *bmax, *c;
93 + int k;
94 +
95 + if (win == NULL) return -1;
96 +
97 + if (win->_cury >= win->nrows)
98 + {
99 + /* Curses seems to move current postion to top of window. */
100 + win->_cury = win->_curx = 0;
101 + return -1;
102 + }
103 +
104 + win->modified = 1;
105 +
106 + if (ch < ' ')
107 + {
108 + if (ch == '\n')
109 + {
110 + SLcurses_wclrtoeol (win);
111 + return do_newline (win);
112 + }
113 +
114 + if (ch == '\r')
115 + {
116 + win->_curx = 0;
117 + return 0;
118 + }
119 +
120 + if (ch == '\b')
121 + {
122 + if (win->_curx > 0)
123 + win->_curx--;
124 +
125 + return 0;
126 + }
127 +
128 + /* HACK HACK!!!! */
129 + if (ch == '\t') ch = ' ';
130 + }
131 +
132 + k = wcwidth(ch);
133 +
134 + if (!k)
135 + return 0; /* ignore combining characters for now */
136 +
137 + if (k > win->ncols)
138 + return 0; /* character wider than window */
139 +
140 + if (win->_curx + k > win->ncols) {
141 + if (win->_curx < win->ncols)
142 + SLcurses_wclrtoeol(win);
143 + do_newline (win);
144 + }
145 +
146 + bmin = win->lines[win->_cury];
147 + b = bmin + win->_curx;
148 + bmax = bmin + win->ncols;
149 +
150 + /* Remove overwritten chars to left */
151 + if (*b == SLSMG_NOCHAR) {
152 + for (c = b - 1; c >= bmin && *c == SLSMG_NOCHAR; c--)
153 + *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
154 + if (c >= bmin)
155 + *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
156 + }
157 +
158 + *b = SLSMG_BUILD_CHAR(ch,color);
159 + win->_curx += k;
160 + while (--k > 0)
161 + *++b = SLSMG_NOCHAR;
162 +
163 + /* Remove overwritten chars to right */
164 + for (c = b + 1; c < bmax && *c == SLSMG_NOCHAR; c++)
165 + *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
166
167 return 0;
168 }
169
170 int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
171 {
172 + SLsmg_Char_Type ch, color;
173 +
174 + if (win == NULL) return -1;
175 +
176 + ch = SLSMG_EXTRACT_CHAR(attr);
177 +
178 + if (attr == ch)
179 + color = win->color;
180 + else
181 + {
182 + /* hack to pick up the default color for graphics chars */
183 + if (((attr & A_COLOR) == 0) && ((attr & A_ALTCHARSET) != 0))
184 + {
185 + /* FIXME: priority=medium: Use SLSMG_?? instead of << */
186 + attr |= win->color << 8;
187 + }
188 + color = map_attr_to_object (attr);
189 + }
190 +
191 + return SLcurses_waddch1 (win, ch, color);
192 +}
193 +#else
194 +int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
195 +{
196 SLsmg_Char_Type *b, ch;
197 SLsmg_Char_Type color;
198
199 @@ -518,6 +628,7 @@
200
201 return 0;
202 }
203 +#endif /* UTF8 */
204
205 int SLcurses_wnoutrefresh (SLcurses_Window_Type *w)
206 {
207 @@ -577,7 +688,11 @@
208
209 int SLcurses_wclrtoeol (SLcurses_Window_Type *w)
210 {
211 +#ifdef UTF8
212 + SLsmg_Char_Type *b, *bmin, *bmax, *c;
213 +#else
214 SLsmg_Char_Type *b, *bmax;
215 +#endif /* UTF8 */
216 SLsmg_Char_Type blank;
217
218 if (w == NULL) return -1;
219 @@ -588,9 +703,23 @@
220
221 blank = SLSMG_BUILD_CHAR(' ',w->color);
222
223 +#ifdef UTF8
224 + bmin = w->lines[w->_cury];
225 + b = bmin + w->_curx;
226 + bmax = bmin + w->ncols;
227 +
228 + /* Remove overwritten chars to left */
229 + if (b < bmax && *b == SLSMG_NOCHAR) {
230 + for (c = b - 1; c >= bmin && *c == SLSMG_NOCHAR; c--)
231 + *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
232 + if (c >= bmin)
233 + *c = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*c));
234 + }
235 +#else
236 b = w->lines[w->_cury];
237 bmax = b + w->ncols;
238 b += w->_curx;
239 +#endif /* UTF8 */
240
241 while (b < bmax) *b++ = blank;
242 return 0;
243 @@ -677,6 +806,34 @@
244 return 0;
245 }
246
247 +#ifdef UTF8
248 +/* Note: if len is < 0, entire string will be used.
249 + */
250 +int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
251 +{
252 + size_t k;
253 + wchar_t wc;
254 + mbstate_t mbstate;
255 +
256 + if ((w == NULL)
257 + || (str == NULL))
258 + return -1;
259 +
260 + if (len < 0)
261 + len = (char *)(-1) - str;
262 +
263 + memset (&mbstate, 0, sizeof (mbstate));
264 + while ((k = mbrtowc (&wc, str, len, &mbstate)) &&
265 + k != (size_t)(-1) &&
266 + k != (size_t)(-2))
267 + {
268 + SLcurses_waddch1 (w, wc, w->color);
269 + str += k;
270 + len -= k;
271 + }
272 + return k;
273 +}
274 +#else
275 /* Note: if len is < 0, entire string will be used.
276 */
277 int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
278 @@ -758,6 +915,7 @@
279
280 return 0;
281 }
282 +#endif /* UTF8 */
283
284 /* This routine IS NOT CORRECT. It needs to compute the proper overlap
285 * and copy accordingly. Here, I just assume windows are same size.
286 @@ -852,12 +1010,36 @@
287
288 int SLcurses_wdelch (SLcurses_Window_Type *w)
289 {
290 +#ifdef UTF8
291 + SLsmg_Char_Type *p, *p1, *pmin, *pmax, *q;
292 +#else
293 SLsmg_Char_Type *p, *p1, *pmax;
294 +#endif /* UTF8 */
295
296 +#ifdef UTF8
297 + pmin = w->lines[w->_cury];
298 + p = pmin + w->_curx;
299 + pmax = pmin + w->ncols;
300 +
301 + /* Remove overwritten chars to left */
302 + if (p < pmax && *p == SLSMG_NOCHAR) {
303 + for (q = p - 1; q >= pmin && *q == SLSMG_NOCHAR; q--)
304 + *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
305 + if (q >= pmin)
306 + *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
307 + }
308 +
309 + /* Remove overwritten chars to right */
310 + for (q = p + 1; q < pmax && *q == SLSMG_NOCHAR; q++)
311 + *q = SLSMG_BUILD_CHAR(' ',SLSMG_EXTRACT_COLOR(*q));
312 +
313 + p1 = p + 1;
314 +#else
315 p = w->lines[w->_cury];
316 pmax = p + w->ncols;
317 p += w->_curx;
318 p1 = p + 1;
319 +#endif /* UTF8 */
320
321 while (p1 < pmax)
322 {
323 @@ -884,12 +1066,12 @@
324
325 while (pmax > p)
326 {
327 - *pmax = *p1;
328 + *pmax = *p1; /* Doesn't this assign beyond the end of the line? */
329 pmax = p1;
330 p1--;
331 }
332
333 - if (p < pmax)
334 + if (p < pmax) /* How could it be? */
335 *p = SLSMG_BUILD_CHAR(ch, w->color);
336
337 w->modified = 1;
338 --- slang-1.4.4.orig/src/slsmg.c
339 +++ slang-1.4.4/src/slsmg.c
340 @@ -225,6 +225,38 @@
341 SLsmg_write_nchars (str, strlen (str));
342 }
343
344 +#ifdef UTF8
345 +void SLsmg_write_nstring (char *str, unsigned int n)
346 +{
347 + char blank = ' ';
348 + mbstate_t mbstate;
349 +
350 + /* Avoid a problem if a user accidently passes a negative value */
351 + if ((int) n < 0)
352 + return;
353 +
354 + if (str != NULL)
355 + {
356 + wchar_t wc;
357 + size_t k;
358 + int w;
359 +
360 + memset (&mbstate, 0, sizeof (mbstate));
361 + while ((k = mbrtowc (&wc, str, MB_LEN_MAX, &mbstate)) &&
362 + k != (size_t)(-1) &&
363 + k != (size_t)(-2))
364 + {
365 + w = wcwidth(wc);
366 + if (w < 0 || w > n)
367 + break;
368 + SLsmg_write_nwchars (&wc, 1);
369 + str += k;
370 + n -= w;
371 + }
372 + }
373 + while (n-- > 0) SLsmg_write_nchars (&blank, 1);
374 +}
375 +#else
376 void SLsmg_write_nstring (char *str, unsigned int n)
377 {
378 unsigned int width;
379 @@ -243,7 +275,11 @@
380 }
381 while (width++ < n) SLsmg_write_nchars (&blank, 1);
382 }
383 +#endif /* UTF8 */
384
385 +#ifdef UTF8
386 +/* FIXME: This function not UTF8'd yet - Edmund */
387 +#endif /* UTF8 */
388 void SLsmg_write_wrapped_string (char *s, int r, int c,
389 unsigned int dr, unsigned int dc,
390 int fill)
391 @@ -302,6 +338,123 @@
392 int SLsmg_Display_Eight_Bit = 128;
393 #endif
394
395 +#ifdef UTF8
396 +void SLsmg_write_nwchars (wchar_t *str, unsigned int n)
397 +{
398 + SLsmg_Char_Type *p, *prev, *q;
399 + int len, max_len, w, i;
400 + wchar_t ch;
401 +
402 +#ifndef IBMPC_SYSTEM
403 + int alt_char_set_flag;
404 +
405 + alt_char_set_flag = ((This_Color & ALT_CHAR_FLAG)
406 + && ((tt_Use_Blink_For_ACS == NULL)
407 + || (*tt_Use_Blink_For_ACS == 0)));
408 +#endif
409 +
410 + if (Smg_Inited == 0)
411 + return;
412 + if (This_Row < Start_Row || This_Row >= Start_Row + Screen_Rows)
413 + return;
414 +
415 + max_len = Start_Col + Screen_Cols;
416 + len = This_Col;
417 + p = SL_Screen[This_Row - Start_Row].neew + len - Start_Col;
418 + prev = 0;
419 +
420 + for (i = 0; i < n; i++, str) {
421 + ch = *str++;
422 +#ifndef IBMPC_SYSTEM
423 + if (alt_char_set_flag)
424 + ch = Alt_Char_Set[ch & 0x7F];
425 +#endif
426 + w = wcwidth(ch);
427 +
428 + if (w > 0) {
429 + if (len + w <= max_len) {
430 + if (!prev) {
431 + for (q = p; *q == SLSMG_NOCHAR; q--)
432 + *q = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*q));
433 + *q = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*q));
434 + }
435 + prev = p;
436 + *p++ = SLSMG_BUILD_CHAR(ch, This_Color), ++len;
437 + for (; --w; len++, p++)
438 + *p = SLSMG_NOCHAR;
439 + }
440 + else if (len < max_len) {
441 + for (; len < max_len; len++, p++)
442 + *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
443 + prev = 0;
444 + }
445 + }
446 + else if (ch == '\n' &&
447 + SLsmg_Newline_Behavior != SLSMG_NEWLINE_PRINTABLE) {
448 + SL_Screen[This_Row - Start_Row].flags |= TOUCHED;
449 + for (; len < max_len && *p == SLSMG_NOCHAR; len++, p++)
450 + *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
451 + if (!SLsmg_Newline_Behavior)
452 + break;
453 + ++This_Row;
454 + len = 0;
455 + if (This_Row == Start_Row + Screen_Rows) {
456 + if (SLsmg_Newline_Behavior == SLSMG_NEWLINE_SCROLLS)
457 + scroll_up();
458 + else
459 + break;
460 + }
461 + p = SL_Screen[This_Row - Start_Row].neew;
462 + prev = 0;
463 + }
464 + else if (ch == '\t' && (SLsmg_Tab_Width > 0)) {
465 + while (len < max_len) {
466 + *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
467 + ++p, ++len;
468 + if (len % SLsmg_Tab_Width == 0)
469 + break;
470 + }
471 + }
472 + else if ((ch == 0x8) && SLsmg_Backspace_Moves) {
473 + /* not implemented */
474 + }
475 + else if (!w && ch) {
476 + /* we could handle combining characters here, using prev */
477 + }
478 + else {
479 + /* we should convert control characters to printable form here */
480 + }
481 + }
482 + This_Col = len;
483 + if (i == n) {
484 + SL_Screen[This_Row - Start_Row].flags |= TOUCHED;
485 + for (; len < max_len && *p == SLSMG_NOCHAR; len++, p++)
486 + *p = SLSMG_BUILD_CHAR(' ', SLSMG_EXTRACT_COLOR(*p));
487 + }
488 +}
489 +
490 +void SLsmg_write_char (wchar_t wc)
491 +{
492 + SLsmg_write_nwchars (&wc, 1);
493 +}
494 +
495 +void SLsmg_write_nchars (char *str, unsigned int n)
496 +{
497 + wchar_t wc;
498 + size_t k;
499 + mbstate_t mbstate;
500 +
501 + memset (&mbstate, 0, sizeof (mbstate));
502 + while ((k = mbrtowc (&wc, str, n, &mbstate)) &&
503 + k != (size_t)(-1) &&
504 + k != (size_t)(-2))
505 + {
506 + SLsmg_write_nwchars (&wc, 1);
507 + str += k;
508 + n -= k;
509 + }
510 +}
511 +#else
512 void SLsmg_write_nchars (char *str, unsigned int n)
513 {
514 register SLsmg_Char_Type *p, old, neew, color;
515 @@ -475,6 +628,7 @@
516 {
517 SLsmg_write_nchars (&ch, 1);
518 }
519 +#endif /* UTF8 */
520
521 static int Cls_Flag;
522
523 @@ -891,6 +1045,10 @@
524 This_Color = color;
525 }
526
527 +#ifdef UTF8
528 + /* FIXME: We should convert broken wide characters to spaces
529 + before calling smart_puts */
530 +#endif /* UTF8 */
531 SL_Screen[i].old[Screen_Cols] = 0;
532 SL_Screen[i].neew[Screen_Cols] = 0;
533
534 @@ -1334,9 +1492,16 @@
535 This_Row = r; This_Col = c;
536 }
537
538 +#ifdef UTF8
539 +void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, wchar_t ch)
540 +{
541 + static wchar_t hbuf[16];
542 + int i;
543 +#else
544 void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, unsigned char ch)
545 {
546 static unsigned char hbuf[16];
547 +#endif /* UTF8 */
548 int count;
549 int dcmax, rmax;
550
551 @@ -1357,16 +1522,30 @@
552 #if 0
553 ch = Alt_Char_Set[ch];
554 #endif
555 +#ifdef UTF8
556 + if (ch != hbuf[0])
557 + for (i = 0; i < 16; i++)
558 + hbuf[i] = ch;
559 +#else
560 if (ch != hbuf[0]) SLMEMSET ((char *) hbuf, (char) ch, 16);
561 +#endif /* UTF8 */
562
563 for (This_Row = r; This_Row < rmax; This_Row++)
564 {
565 This_Col = c;
566 count = dc / 16;
567 +#ifdef UTF8
568 + SLsmg_write_nwchars (hbuf, dc % 16);
569 +#else
570 SLsmg_write_nchars ((char *) hbuf, dc % 16);
571 +#endif /* UTF8 */
572 while (count-- > 0)
573 {
574 +#ifdef UTF8
575 + SLsmg_write_nwchars (hbuf, 16);
576 +#else
577 SLsmg_write_nchars ((char *) hbuf, 16);
578 +#endif /* UTF8 */
579 }
580 }
581
582 @@ -1381,14 +1560,22 @@
583 void SLsmg_write_color_chars (SLsmg_Char_Type *s, unsigned int len)
584 {
585 SLsmg_Char_Type *smax, sh;
586 +#ifdef UTF8
587 + wchar_t buf[32], *b, *bmax;
588 +#else
589 char buf[32], *b, *bmax;
590 +#endif /* UTF8 */
591 int color, save_color;
592
593 if (Smg_Inited == 0) return;
594
595 smax = s + len;
596 b = buf;
597 +#ifdef UTF8
598 + bmax = b + sizeof (buf) / sizeof (SLsmg_Char_Type);
599 +#else
600 bmax = b + sizeof (buf);
601 +#endif /* UTF8 */
602
603 save_color = This_Color;
604
605 @@ -1412,16 +1599,28 @@
606 {
607 if (b != buf)
608 {
609 +#ifdef UTF8
610 + SLsmg_write_nwchars (buf, (int) (b - buf));
611 +#else
612 SLsmg_write_nchars (buf, (int) (b - buf));
613 +#endif /* UTF8 */
614 b = buf;
615 }
616 This_Color = color;
617 }
618 +#ifdef UTF8
619 + *b++ = SLSMG_EXTRACT_CHAR(sh);
620 +#else
621 *b++ = (char) SLSMG_EXTRACT_CHAR(sh);
622 +#endif /* UTF8 */
623 }
624
625 if (b != buf)
626 +#ifdef UTF8
627 + SLsmg_write_nwchars (buf, (unsigned int) (b - buf));
628 +#else
629 SLsmg_write_nchars (buf, (unsigned int) (b - buf));
630 +#endif /* UTF8 */
631
632 This_Color = save_color;
633 }
634 @@ -1473,7 +1672,11 @@
635 SLsmg_set_color_in_region (int color, int r, int c, unsigned int dr, unsigned int dc)
636 {
637 int cmax, rmax;
638 +#ifdef UTF8
639 + int color_mask;
640 +#else
641 SLsmg_Char_Type char_mask;
642 +#endif /* UTF8 */
643
644 if (Smg_Inited == 0) return;
645
646 @@ -1498,14 +1701,22 @@
647 color = ((color & 0x7F) + Bce_Color_Offset) & 0x7F;
648 }
649 #endif
650 +#ifdef UTF8
651 + color_mask = 0;
652 +#else
653 color = color << 8;
654
655 char_mask = 0xFF;
656 +#endif /* UTF8 */
657
658 #ifndef IBMPC_SYSTEM
659 if ((tt_Use_Blink_For_ACS == NULL)
660 || (0 == *tt_Use_Blink_For_ACS))
661 +#ifdef UTF8
662 + color_mask = 0x80;
663 +#else
664 char_mask = 0x80FF;
665 +#endif /* UTF8 */
666 #endif
667
668 while (r < rmax)
669 @@ -1519,7 +1730,13 @@
670
671 while (s < smax)
672 {
673 +#ifdef UTF8
674 + *s = SLSMG_BUILD_CHAR(SLSMG_EXTRACT_CHAR(*s),
675 + (SLSMG_EXTRACT_COLOR(*s) & color_mask)
676 + | color);
677 +#else
678 *s = (*s & char_mask) | color;
679 +#endif /* UTF8 */
680 s++;
681 }
682 r++;
683 --- slang-1.4.5/src/Makefile.in.foo 2002-06-12 19:30:09.000000000 -0400
684 +++ slang-1.4.5/src/Makefile.in 2002-06-12 19:31:13.000000000 -0400
685 @@ -67,7 +67,7 @@
686 #---------------------------------------------------------------------------
687 # There should be no need to change anything below here.
688 #---------------------------------------------------------------------------
689 -THIS_LIB = slang#
690 +THIS_LIB = slang-utf8#
691 OTHERSTUFF =
692 THIS_LIB_DEFINES = -DSLANG
693 ELF_MAJOR_VERSION = @slang_major_version@#
694 --- slang-1.4.9/src/sldisply.c.orig 2003-10-27 17:24:15.000000000 -0500
695 +++ slang-1.4.9/src/sldisply.c 2003-10-27 17:56:25.000000000 -0500
696 @@ -9,6 +9,7 @@
697
698 #include <time.h>
699 #include <ctype.h>
700 +#include <limits.h>
701
702 #if !defined(VMS) || (__VMS_VER >= 70000000)
703 # include <sys/time.h>
704 @@ -1426,14 +1427,25 @@
705
706 /* Highest bit represents the character set. */
707 #define COLOR_MASK 0x7F00
708 +#ifdef UTF8
709 +# define COLOR_OF(x) (SLSMG_EXTRACT_COLOR(x) & 0x7F)
710 +#else
711 #define COLOR_OF(x) (((x)&COLOR_MASK)>>8)
712 +#endif
713 #define CHAR_OF(x) ((x)&0x80FF)
714
715 #if SLTT_HAS_NON_BCE_SUPPORT
716 +#ifdef UTF8
717 +static int bce_color_eqs (SLsmg_Char_Type a, SLsmg_Char_Type b)
718 +{
719 + a = SLSMG_EXTRACT_COLOR(a) & 0x7F;
720 + b = SLSMG_EXTRACT_COLOR(b) & 0x7F;
721 +#else
722 static int bce_color_eqs (unsigned int a, unsigned int b)
723 {
724 a = COLOR_OF(a);
725 b = COLOR_OF(b);
726 +#endif
727
728 if (a == b)
729 return 1;
730 @@ -1459,8 +1471,14 @@
731 : (Ansi_Color_Map[COLOR_OF(a)].mono == Ansi_Color_Map[COLOR_OF(b)].mono))
732 #endif
733
734 +#ifdef UTF8
735 +#define CHAR_EQS(a, b) ((a) == (b)\
736 + || (SLSMG_EXTRACT_CHAR(a) == SLSMG_EXTRACT_CHAR(b)\
737 + && COLOR_EQS((a), (b))))
738 +#else
739 #define CHAR_EQS(a, b) (((a) == (b))\
740 || ((CHAR_OF(a)==CHAR_OF(b)) && COLOR_EQS(a,b)))
741 +#endif
742
743 /* The whole point of this routine is to prevent writing to the last column
744 * and last row on terminals with automatic margins.
745 @@ -1488,9 +1506,58 @@
746 tt_write (str, len);
747 }
748
749 +#ifdef UTF8
750 +/* FIXME: This duplicates the function above
751 + */
752 +static void write_wstring_with_care (SLsmg_Char_Type *str, unsigned int len)
753 +{
754 + mbstate_t mbstate;
755 +
756 + if (str == NULL) return;
757 +
758 + if (Automatic_Margins && (Cursor_r + 1 == SLtt_Screen_Rows))
759 + {
760 + if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols)
761 + {
762 + /* For now, just do not write there. Later, something more
763 + * sophisticated will be implemented.
764 + */
765 + if (SLtt_Screen_Cols > Cursor_c)
766 + {
767 + len = SLtt_Screen_Cols - Cursor_c - 1;
768 + while (len > 0 && str[len] == SLSMG_NOCHAR)
769 + --len;
770 + }
771 + else len = 0;
772 + }
773 + }
774 +
775 + memset (&mbstate, 0, sizeof (mbstate));
776 + while (len--)
777 + {
778 + SLsmg_Char_Type c = *str++;
779 + char buf[MB_LEN_MAX];
780 + size_t n;
781 +
782 + if (c == SLSMG_NOCHAR)
783 + continue;
784 +
785 + n = wcrtomb (buf, c, &mbstate);
786 + if (n == (size_t)(-1))
787 + break;
788 +
789 + tt_write(buf, n);
790 + }
791 +}
792 +#endif /* UTF8 */
793 +
794 static void send_attr_str (SLsmg_Char_Type *s)
795 {
796 +#ifdef UTF8
797 + SLsmg_Char_Type out[SLTT_MAX_SCREEN_COLS], ch, *p;
798 +#else
799 unsigned char out[SLTT_MAX_SCREEN_COLS], ch, *p;
800 +#endif /* UTF8 */
801 register SLtt_Char_Type attr;
802 register SLsmg_Char_Type sh;
803 int color, last_color = -1;
804 @@ -1498,8 +1565,13 @@
805 p = out;
806 while (0 != (sh = *s++))
807 {
808 +#ifdef UTF8
809 + ch = SLSMG_EXTRACT_CHAR(sh);
810 + color = SLSMG_EXTRACT_COLOR(sh);
811 +#else
812 ch = sh & 0xFF;
813 color = ((int) sh & 0xFF00) >> 8;
814 +#endif
815
816 #if SLTT_HAS_NON_BCE_SUPPORT
817 if (Bce_Color_Offset
818 @@ -1511,8 +1583,12 @@
819 {
820 if (SLtt_Use_Ansi_Colors) attr = Ansi_Color_Map[color & 0x7F].fgbg;
821 else attr = Ansi_Color_Map[color & 0x7F].mono;
822 -
823 +
824 +#ifdef UTF8
825 + if (SLSMG_EXTRACT_COLOR(sh) & 0x80) /* alternate char set */
826 +#else
827 if (sh & 0x8000) /* alternate char set */
828 +#endif
829 {
830 if (SLtt_Use_Blink_For_ACS)
831 {
832 @@ -1534,8 +1610,12 @@
833 {
834 if (p != out)
835 {
836 +#ifdef UTF8
837 + write_wstring_with_care (out, p-out);
838 +#else
839 *p = 0;
840 write_string_with_care ((char *) out);
841 +#endif
842 Cursor_c += (int) (p - out);
843 p = out;
844 }
845 @@ -1558,8 +1638,12 @@
846 }
847 *p++ = ch;
848 }
849 +#ifdef UTF8
850 + if (p != out) write_wstring_with_care (out, p-out);
851 +#else
852 *p = 0;
853 if (p != out) write_string_with_care ((char *) out);
854 +#endif
855 Cursor_c += (int) (p - out);
856 }
857
858 @@ -1686,7 +1770,11 @@
859
860 while (qq < qmax)
861 {
862 +#ifdef UTF8
863 + if (SLSMG_EXTRACT_COLOR(*qq))
864 +#else
865 if (*qq & 0xFF00)
866 +#endif
867 {
868 SLtt_normal_video ();
869 SLtt_del_eol ();
870 @@ -1701,7 +1789,11 @@
871 /* Find where the last non-blank character on old/new screen is */
872
873 space_char = ' ';
874 +#ifdef UTF8
875 + if (SLSMG_EXTRACT_CHAR(*(pmax-1)) == ' ')
876 +#else
877 if (CHAR_EQS(*(pmax-1), ' '))
878 +#endif
879 {
880 /* If we get here, then we can erase to the end of the line to create
881 * the final space. However, this will only work _if_ erasing will
882 @@ -1752,7 +1844,11 @@
883 {
884 #endif
885 /* Try use use erase to bol if possible */
886 +#ifdef UTF8
887 + if ((Del_Bol_Str != NULL) && (SLSMG_EXTRACT_CHAR(*neww) == ' '))
888 +#else
889 if ((Del_Bol_Str != NULL) && (CHAR_OF(*neww) == ' '))
890 +#endif
891 {
892 SLsmg_Char_Type *p1;
893 SLsmg_Char_Type blank;
894 @@ -1781,7 +1877,11 @@
895 q = oldd + ofs;
896 p = p1;
897 SLtt_goto_rc (row, ofs - 1);
898 +#ifdef UTF8
899 + SLtt_reverse_video (SLSMG_EXTRACT_COLOR (blank));
900 +#else
901 SLtt_reverse_video (COLOR_OF(blank));
902 +#endif
903 tt_write_string (Del_Bol_Str);
904 tt_write (" ", 1);
905 Cursor_c += 1;
906 @@ -1978,7 +2078,11 @@
907
908 if (q < qmax)
909 {
910 +#ifdef UTF8
911 + SLtt_reverse_video (SLSMG_EXTRACT_COLOR (space_char));
912 +#else
913 SLtt_reverse_video (COLOR_OF(space_char));
914 +#endif
915 del_eol ();
916 }
917