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