The R Project SVN R

Rev

Rev 35777 | Rev 36901 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35777 Rev 35821
Line 56... Line 56...
56
 
56
 
57
extern UImode  CharacterMode;
57
extern UImode  CharacterMode;
58
 
58
 
59
#ifdef SUPPORT_MBCS
59
#ifdef SUPPORT_MBCS
60
#define mbs_init(x) memset(x, 0, sizeof(mbstate_t))
60
#define mbs_init(x) memset(x, 0, sizeof(mbstate_t))
61
#if 0
-
 
62
static int wcwidth(wchar_t ucs)
-
 
63
{
-
 
64
  return 1 +
-
 
65
    (ucs >= 0x1100 &&
-
 
66
     (ucs <= 0x115f ||                    /* Hangul Jamo init. consonants */
-
 
67
      ucs == 0x2329 || ucs == 0x232a ||
-
 
68
      (ucs >= 0x2e80 && ucs <= 0xa4cf &&
-
 
69
       ucs != 0x303f) ||                  /* CJK ... Yi */
-
 
70
      (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
-
 
71
      (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
-
 
72
      (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
-
 
73
      (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
-
 
74
      (ucs >= 0xffe0 && ucs <= 0xffe6) /* ||
-
 
75
      (ucs >= 0x20000 && ucs <= 0x2fffd) ||
-
 
76
      (ucs >= 0x30000 && ucs <= 0x3fffd)*/));
-
 
77
}
-
 
78
#endif
-
 
79
 
61
 
80
static mbstate_t mb_st; /* use for char transpose as well */
62
static mbstate_t mb_st; /* use for char transpose as well */
81
 
63
 
82
/* This is input from the keyboard, so we do not do validity checks.
64
/* This is input from the keyboard, so we do not do validity checks.
83
   OTOH, we do allow stateful encodings, assuming the state is reset
65
   OTOH, we do allow stateful encodings, assuming the state is reset
Line 91... Line 73...
91
    for(i = 0; i <= clength; i += mb_len)
73
    for(i = 0; i <= clength; i += mb_len)
92
	mb_len = mbrtowc(NULL, buf+i, MB_CUR_MAX, &mb_st);
74
	mb_len = mbrtowc(NULL, buf+i, MB_CUR_MAX, &mb_st);
93
    return mb_len;
75
    return mb_len;
94
}
76
}
95
 
77
 
-
 
78
/* <FIXME> replace by Ri18n_wcswidth */
96
int mbswidth(char *buf)
79
int mbswidth(char *buf)
97
{
80
{
98
    char *p =buf;
81
    char *p =buf;
99
    int res = 0, used;
82
    int res = 0, used;
100
    wchar_t wc;
83
    wchar_t wc;
Line 102... Line 85...
102
    mbs_init(&mb_st);
85
    mbs_init(&mb_st);
103
    while(*p) {
86
    while(*p) {
104
	used = mbrtowc(&wc, p, MB_CUR_MAX, &mb_st);
87
	used = mbrtowc(&wc, p, MB_CUR_MAX, &mb_st);
105
	if(used < 0) return -1;
88
	if(used < 0) return -1;
106
	p += used;
89
	p += used;
107
	res += wcwidth(wc);
90
	res += Ri18n_wcwidth(wc);
108
    }
91
    }
109
    return res;
92
    return res;
110
}
93
}
111
#else
94
#else /* no SUPPORT_MBCS */
112
int inline mb_char_len(char *buf, int clength)
95
int inline mb_char_len(char *buf, int clength)
113
{
96
{
114
    return 1;
97
    return 1;
115
}
98
}
116
#endif
99
#endif
Line 124... Line 107...
124
	wchar_t wc;
107
	wchar_t wc;
125
	mbs_init(&mb_st);
108
	mbs_init(&mb_st);
126
	while (P < LINE(NUMLINES - 1) + prompt_len + cur_byte) {
109
	while (P < LINE(NUMLINES - 1) + prompt_len + cur_byte) {
127
	    used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
110
	    used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
128
	    if(used <= 0) break;
111
	    if(used <= 0) break;
129
	    w0 += wcwidth(wc);
112
	    w0 += Ri18n_wcwidth(wc);
130
	    P += used;
113
	    P += used;
131
	}
114
	}
132
	CURCOL = w0 + prompt_wid;
115
	CURCOL = w0 + prompt_wid;
133
    } else
116
    } else
134
#endif
117
#endif
Line 399... Line 382...
399
	    leftedge = FC && (fch == 0);
382
	    leftedge = FC && (fch == 0);
400
	    if(leftedge) fch++;
383
	    if(leftedge) fch++;
401
	    mbs_init(&mb_st);
384
	    mbs_init(&mb_st);
402
	    for (w0 = -FC; w0 < fch && *P; ) { /* should have enough ... */
385
	    for (w0 = -FC; w0 < fch && *P; ) { /* should have enough ... */
403
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
386
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
404
		w0 += wcwidth(wc);
387
		w0 += Ri18n_wcwidth(wc);
405
	    }
388
	    }
406
	    /* Now we have got to on or just after the left edge.
389
	    /* Now we have got to on or just after the left edge.
407
	       Possibly have a widechar hanging over.
390
	       Possibly have a widechar hanging over.
408
	       If so, fill with blanks.
391
	       If so, fill with blanks.
409
	    */
392
	    */
Line 412... Line 395...
412
	    if (leftedge) *q++ = '$';
395
	    if (leftedge) *q++ = '$';
413
 
396
 
414
	    while (w0 < lch) {
397
	    while (w0 < lch) {
415
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
398
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
416
		if(used <= 0) break;
399
		if(used <= 0) break;
417
		w0 += wcwidth(wc);
400
		w0 += Ri18n_wcwidth(wc);
418
		if(w0 > lch) break; /* char straddling the right edge
401
		if(w0 > lch) break; /* char straddling the right edge
419
				       is not displayed */
402
				       is not displayed */
420
		for(j = 0; j < used; j++) *q++ = *P++;
403
		for(j = 0; j < used; j++) *q++ = *P++;
421
	    }
404
	    }
422
	    *q = 0;
405
	    *q = 0;
Line 495... Line 478...
495
	    char *P = s, nn[10];
478
	    char *P = s, nn[10];
496
	    mbs_init(&mb_st);
479
	    mbs_init(&mb_st);
497
	    for (w0 = 0; w0 <= CURCOL; ) {
480
	    for (w0 = 0; w0 <= CURCOL; ) {
498
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
481
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
499
		if(used == 0) break;
482
		if(used == 0) break;
500
		w0 += wcwidth(wc);
483
		w0 += Ri18n_wcwidth(wc);
501
		P += used;
484
		P += used;
502
	    }
485
	    }
503
	    /* term string '\0' box width = 1 fix */
486
	    /* term string '\0' box width = 1 fix */
504
	    w0 = (wc == L'\0') ? 1 : wcwidth(wc); 
487
	    w0 = (wc == L'\0') ? 1 : Ri18n_wcwidth(wc); 
505
	    P -= used;
488
	    P -= used;
506
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH,
489
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH,
507
		     w0 * FW, FH);
490
		     w0 * FW, FH);
508
	    gfillrect(p->bm, p->ufg, r);
491
	    gfillrect(p->bm, p->ufg, r);
509
	    for(ii = 0; ii < used; ii++) nn[ii] = P[ii];
492
	    for(ii = 0; ii < used; ii++) nn[ii] = P[ii];
Line 533... Line 516...
533
	    char *P = s;
516
	    char *P = s;
534
	    mbs_init(&mb_st);
517
	    mbs_init(&mb_st);
535
	    for (w0 = 0; w0 < x0; ) {
518
	    for (w0 = 0; w0 < x0; ) {
536
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
519
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
537
		if(used == 0) break;
520
		if(used == 0) break;
538
		w1 = wcwidth(wc);
521
		w1 = Ri18n_wcwidth(wc);
539
		w0 += w1;
522
		w0 += w1;
540
		P += used;
523
		P += used;
541
	    }
524
	    }
542
	    if(w0 > x0) x0 = w0 - w1;
525
	    if(w0 > x0) x0 = w0 - w1;
543
	}
526
	}
Line 554... Line 537...
554
	    char *P = s;
537
	    char *P = s;
555
	    mbs_init(&mb_st);
538
	    mbs_init(&mb_st);
556
	    for (w0 = 0; w0 <= x1; ) {
539
	    for (w0 = 0; w0 <= x1; ) {
557
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
540
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
558
		if(used == 0) break;
541
		if(used == 0) break;
559
		wl = wcwidth(wc);
542
		wl = Ri18n_wcwidth(wc);
560
		w0 += wl;
543
		w0 += wl;
561
		P += used;
544
		P += used;
562
	    }
545
	    }
563
	    x1 = w0-1;
546
	    x1 = w0-1;
564
	}
547
	}
Line 944... Line 927...
944
	while (i <= y1) {
927
	while (i <= y1) {
945
	    P = LINE(i);
928
	    P = LINE(i);
946
	    mbs_init(&mb_st);
929
	    mbs_init(&mb_st);
947
	    for (w0 = 0; w0 < x00 && *P; ) {
930
	    for (w0 = 0; w0 < x00 && *P; ) {
948
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
931
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
949
		w0 += wcwidth(wc);
932
		w0 += Ri18n_wcwidth(wc);
950
	    }
933
	    }
951
	    x00 = 0;
934
	    x00 = 0;
952
	    if(i == y1) x11 = x1+1; /* cols are 0-based */
935
	    if(i == y1) x11 = x1+1; /* cols are 0-based */
953
	    while (w0 < x11 && *P) {
936
	    while (w0 < x11 && *P) {
954
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
937
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
955
		ll += used;
938
		ll += used;
956
		P += used;
939
		P += used;
957
		w0 += wcwidth(wc);
940
		w0 += Ri18n_wcwidth(wc);
958
	    }
941
	    }
959
	    if(w0 < x11) ll += 2;  /* \r\n */
942
	    if(w0 < x11) ll += 2;  /* \r\n */
960
	    i++;
943
	    i++;
961
	}
944
	}
962
    } else
945
    } else
Line 990... Line 973...
990
	while (i <= y1) {
973
	while (i <= y1) {
991
	    P = LINE(i);
974
	    P = LINE(i);
992
	    mbs_init(&mb_st);
975
	    mbs_init(&mb_st);
993
	    for (w0 = 0; w0 < x00 && *P; ) {
976
	    for (w0 = 0; w0 < x00 && *P; ) {
994
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
977
		P += mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
995
		w0 += wcwidth(wc);
978
		w0 += Ri18n_wcwidth(wc);
996
	    }
979
	    }
997
	    x00 = 0;
980
	    x00 = 0;
998
	    if(i == y1) x11 = x1+1;
981
	    if(i == y1) x11 = x1+1;
999
	    while (w0 < x11 && *P) {
982
	    while (w0 < x11 && *P) {
1000
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
983
		used = mbrtowc(&wc, P, MB_CUR_MAX, &mb_st);
1001
		w0 += wcwidth(wc);
984
		w0 += Ri18n_wcwidth(wc);
1002
		for(j = 0; j < used; j++) *s++ = *P++;
985
		for(j = 0; j < used; j++) *s++ = *P++;
1003
	    }
986
	    }
1004
	    if(w0 < x11) *s++ = '\r'; *s++ = '\n';
987
	    if(w0 < x11) *s++ = '\r'; *s++ = '\n';
1005
	    i++;
988
	    i++;
1006
	}
989
	}