The R Project SVN R

Rev

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

Rev 52012 Rev 52804
Line 61... Line 61...
61
#define IsSurrogatePairsHi(_h)  (SURROGATE_PAIRS_HI_MIN == \
61
#define IsSurrogatePairsHi(_h)  (SURROGATE_PAIRS_HI_MIN == \
62
		      ((uint16_t)(_h) &~ (uint16_t)SURROGATE_PAIRS_MASK ))
62
		      ((uint16_t)(_h) &~ (uint16_t)SURROGATE_PAIRS_MASK ))
63
#define IsSurrogatePairsLo(_l)  (SURROGATE_PAIRS_LO_MIN == \
63
#define IsSurrogatePairsLo(_l)  (SURROGATE_PAIRS_LO_MIN == \
64
		      ((uint16_t)(_l) &~ (uint16_t)SURROGATE_PAIRS_MASK ))
64
		      ((uint16_t)(_l) &~ (uint16_t)SURROGATE_PAIRS_MASK ))
65
 
65
 
66
#ifdef __GNUC__
-
 
67
# undef alloca
-
 
68
# define alloca(x) __builtin_alloca((x))
-
 
69
#endif
-
 
70
 
-
 
71
extern UImode  CharacterMode;
66
extern UImode  CharacterMode;
72
 
67
 
73
static void performCompletion(control c);
68
static void performCompletion(control c);
74
 
69
 
75
 
70
 
Line 276... Line 271...
276
}
271
}
277
 
272
 
278
static void xbufadds(xbuf p, const char *s, int user)
273
static void xbufadds(xbuf p, const char *s, int user)
279
{
274
{
280
    int n = strlen(s) + 1; /* UCS-2 must be shorter */
275
    int n = strlen(s) + 1; /* UCS-2 must be shorter */
281
    wchar_t *tmp;
276
    wchar_t tmp[n];
282
 
277
 
283
    tmp = (wchar_t *) alloca(n * sizeof(wchar_t));
-
 
284
    enctowcs(tmp, (char *) s, n);
278
    enctowcs(tmp, (char *) s, n);
285
    xbufaddxs(p, tmp, user);
279
    xbufaddxs(p, tmp, user);
286
}
280
}
287
 
281
 
288
static void xbuffixl(xbuf p)
282
static void xbuffixl(xbuf p)
Line 425... Line 419...
425
 
419
 
426
    if (len > FC+fch) {
420
    if (len > FC+fch) {
427
	/* Some of the string is visible: */
421
	/* Some of the string is visible: */
428
	if(mbcslocale) {
422
	if(mbcslocale) {
429
	    int i, w0, nc;
423
	    int i, w0, nc;
430
	    wchar_t *buff, *P = s, *q;
424
	    wchar_t *P = s, *q;
431
	    Rboolean leftedge;
425
	    Rboolean leftedge;
432
 
426
 
433
	    nc = (wcslen(s) + 1) * sizeof(wchar_t); /* overkill */
427
	    nc = (wcslen(s) + 1) * sizeof(wchar_t); /* overkill */
434
	    q = buff = (wchar_t *) alloca(nc);
428
	    wchar_t buff[nc];
-
 
429
	    q = buff;
435
	    leftedge = FC && (fch == 0);
430
	    leftedge = FC && (fch == 0);
436
	    if(leftedge) fch++;
431
	    if(leftedge) fch++;
437
	    for (w0 = -FC; w0 < fch && *P; P++) /* should have enough ... */
432
	    for (w0 = -FC; w0 < fch && *P; P++) /* should have enough ... */
438
		w0 += Ri18n_wcwidth(*P);
433
		w0 += Ri18n_wcwidth(*P);
439
	    /* Now we have got to on or just after the left edge.
434
	    /* Now we have got to on or just after the left edge.
Line 498... Line 493...
498
    len = wcswidth(stmp);
493
    len = wcswidth(stmp);
499
    /* If there is a \r in the line, we need to preprocess it */
494
    /* If there is a \r in the line, we need to preprocess it */
500
    if((p0 = wcschr(s, L'\r'))) {
495
    if((p0 = wcschr(s, L'\r'))) {
501
	int l, l1;
496
	int l, l1;
502
	stmp = LINE(i);
497
	stmp = LINE(i);
503
	s = (wchar_t *) alloca((wcslen(stmp) + 1) * sizeof(wchar_t));
498
	wchar_t s0[wcslen(stmp) +1];
-
 
499
	s = s0;
504
	l = p0 - stmp;
500
	l = p0 - stmp;
505
	wcsncpy(s, stmp, l);
501
	wcsncpy(s, stmp, l);
506
	stmp = p0 + 1;
502
	stmp = p0 + 1;
507
	while((p0 = wcschr(stmp, L'\r'))) {
503
	while((p0 = wcschr(stmp, L'\r'))) {
508
	    l1 = p0 - stmp;
504
	    l1 = p0 - stmp;
Line 893... Line 889...
893
{
889
{
894
    ConsoleData p = getdata(c);
890
    ConsoleData p = getdata(c);
895
    int i, alen, alen2, max_show = 10, cursor_position = p->c - prompt_wid;
891
    int i, alen, alen2, max_show = 10, cursor_position = p->c - prompt_wid;
896
    wchar_t *partial_line = LINE(NUMLINES - 1) + prompt_wid;
892
    wchar_t *partial_line = LINE(NUMLINES - 1) + prompt_wid;
897
    const char *additional_text;
893
    const char *additional_text;
898
    wchar_t *pline;
-
 
899
    char *cmd;
-
 
900
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
894
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
901
    ParseStatus status;
895
    ParseStatus status;
902
 
896
 
903
    if(!completion_available) {
897
    if(!completion_available) {
904
	storetab(c);
898
	storetab(c);
Line 932... Line 926...
932
	    }
926
	    }
933
	}
927
	}
934
    }
928
    }
935
 
929
 
936
    /* FIXME: need to escape quotes properly */
930
    /* FIXME: need to escape quotes properly */
937
    pline = (wchar_t *) alloca((wcslen(partial_line) + 1) * sizeof(wchar_t));
931
    wchar_t pline[wcslen(partial_line) + 1];
938
    wcscpy(pline, partial_line);
932
    wcscpy(pline, partial_line);
939
    /* poor attempt at escaping quotes that sort of works */
933
    /* poor attempt at escaping quotes that sort of works */
940
    alen = wcslen(pline);
934
    alen = wcslen(pline);
941
    for (i = 0; i < alen; i++)
935
    for (i = 0; i < alen; i++)
942
	if (pline[i] == '"') pline[i] = L'\'';
936
	if (pline[i] == '"') pline[i] = L'\'';
943
 
937
 
944
    cmd = alloca((wcslen(pline) + 100));
938
    char cmd[wcslen(pline) + 100];
945
    sprintf(cmd, "utils:::.win32consoleCompletion(\"%ls\", %d)",
939
    sprintf(cmd, "utils:::.win32consoleCompletion(\"%ls\", %d)",
946
	    pline, cursor_position);
940
	    pline, cursor_position);
947
    PROTECT(cmdSexp = mkString(cmd));
941
    PROTECT(cmdSexp = mkString(cmd));
948
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
942
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
949
    if (status != PARSE_OK) {
943
    if (status != PARSE_OK) {
Line 972... Line 966...
972
    alen = length(VECTOR_ELT(ans, POSSIBLE));
966
    alen = length(VECTOR_ELT(ans, POSSIBLE));
973
    additional_text = CHAR(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
967
    additional_text = CHAR(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
974
    alen2 = strlen(additional_text);
968
    alen2 = strlen(additional_text);
975
    if (alen) {
969
    if (alen) {
976
	/* make a copy of the current string first */
970
	/* make a copy of the current string first */
977
	char *buf1;
-
 
978
	wchar_t *p1 = LINE(NUMLINES - 1);
971
	wchar_t *p1 = LINE(NUMLINES - 1);
979
	checkpointpos(p->lbuf, 1);
972
	checkpointpos(p->lbuf, 1);
980
	buf1 = alloca(MB_CUR_MAX * wcslen(p1) + 1);
973
	char buf1[MB_CUR_MAX * wcslen(p1) + 1];
981
	sprintf(buf1,"%ls\n", p1);
974
	sprintf(buf1,"%ls\n", p1);
982
	consolewrites(c, buf1);
975
	consolewrites(c, buf1);
983
 
976
 
984
	for (i = 0; i < min(alen, max_show); i++) {
977
	for (i = 0; i < min(alen, max_show); i++) {
985
	    consolewrites(c, CHAR(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
978
	    consolewrites(c, CHAR(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
Line 1032... Line 1025...
1032
    }
1025
    }
1033
    storekey(c, BEGINLINE);
1026
    storekey(c, BEGINLINE);
1034
    storekey(c, KILLRESTOFLINE);
1027
    storekey(c, KILLRESTOFLINE);
1035
    if(isUnicodeWindow(c)) {
1028
    if(isUnicodeWindow(c)) {
1036
	size_t sz = (strlen(cmd) + 1) * sizeof(wchar_t);
1029
	size_t sz = (strlen(cmd) + 1) * sizeof(wchar_t);
1037
	wchar_t *wcs = (wchar_t *) alloca(sz);
1030
	wchar_t wcs[strlen(cmd) + 1];
1038
	memset(wcs, 0, sz);
1031
	memset(wcs, 0, sz);
1039
	mbstowcs(wcs, cmd, sz-1);
1032
	mbstowcs(wcs, cmd, sz-1);
1040
	for(i = 0; wcs[i]; i++) storekey(c, wcs[i]);
1033
	for(i = 0; wcs[i]; i++) storekey(c, wcs[i]);
1041
    } else {
1034
    } else {
1042
	const char *ch;
1035
	const char *ch;