The R Project SVN R

Rev

Rev 78769 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 78769 Rev 83796
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  file rt_complete.c
3
 *  file rt_complete.c
4
 *  Copyright (C) 2007-2017 The R Core Team.
4
 *  Copyright (C) 2007-2022 The R Core Team.
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
9
 *  (at your option) any later version.
Line 58... Line 58...
58
    int i, alen, cursor_position = *loc;
58
    int i, alen, cursor_position = *loc;
59
    char *partial_line = buf;
59
    char *partial_line = buf;
60
    const char *additional_text;
60
    const char *additional_text;
61
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
61
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
62
    ParseStatus status;
62
    ParseStatus status;
-
 
63
    const void *vmax = NULL;
63
 
64
 
64
    if(!completion_available) return gl_tab(buf, offset, loc);
65
    if(!completion_available) return gl_tab(buf, offset, loc);
65
 
66
 
66
    if(completion_available < 0) {
67
    if(completion_available < 0) {
67
	char *p = getenv("R_COMPLETION");
68
	char *p = getenv("R_COMPLETION");
Line 98... Line 99...
98
        achar = orig[i];
99
        achar = orig[i];
99
	if (achar == '"' || achar == '\\') *pchar++ = '\\';
100
	if (achar == '"' || achar == '\\') *pchar++ = '\\';
100
	*pchar++ = achar;
101
	*pchar++ = achar;
101
    }
102
    }
102
    *pchar = 0;
103
    *pchar = 0;
103
    size_t len = strlen(pline) + 100; 
104
    size_t plen = strlen(pline);
-
 
105
    size_t len = plen + 100; 
104
    char cmd[len];
106
    char cmd[len];
105
    snprintf(cmd, len,
107
    snprintf(cmd, len,
106
	     "utils:::.win32consoleCompletion(\"%s\", %d)",
108
	     "utils:::.win32consoleCompletion(\"%.*s\", %d)",
107
	     pline, cursor_position);
109
	     (int)plen, pline, cursor_position);
108
    PROTECT(cmdSexp = mkString(cmd));
110
    PROTECT(cmdSexp = mkString(cmd));
109
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
111
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
110
    if (status != PARSE_OK) {
112
    if (status != PARSE_OK) {
111
	UNPROTECT(2);
113
	UNPROTECT(2);
112
	/* Uncomment next line to debug */
114
	/* Uncomment next line to debug */
Line 116... Line 118...
116
    }
118
    }
117
    /* Loop is needed here as EXPRSEXP will be of length > 1 */
119
    /* Loop is needed here as EXPRSEXP will be of length > 1 */
118
    for(i = 0; i < length(cmdexpr); i++)
120
    for(i = 0; i < length(cmdexpr); i++)
119
	ans = eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
121
	ans = eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
120
    UNPROTECT(2);
122
    UNPROTECT(2);
-
 
123
    PROTECT(ans);
121
 
124
 
122
    /* ans has the form list(addition, possible), where 'addition' is
125
    /* ans has the form list(addition, possible), where 'addition' is
123
       unique additional text if any, and 'possible' is a character
126
       unique additional text if any, and 'possible' is a character
124
       vector holding possible completions if any (already formatted
127
       vector holding possible completions if any (already formatted
125
       for linewise printing in the current implementation).  If
128
       for linewise printing in the current implementation).  If
Line 128... Line 131...
128
       at the cursor */
131
       at the cursor */
129
 
132
 
130
#define ADDITION 0
133
#define ADDITION 0
131
#define POSSIBLE 1
134
#define POSSIBLE 1
132
 
135
 
-
 
136
    vmax = vmaxget();
133
    alen = length(VECTOR_ELT(ans, POSSIBLE));
137
    alen = length(VECTOR_ELT(ans, POSSIBLE));
134
    if (alen) {
138
    if (alen) {
135
	int max_show = 10;
139
	int max_show = 10;
136
	printf("\n"); /* finish current line */
140
	printf("\n"); /* finish current line */
137
	for (i = 0; i < min(alen, max_show); i++) {
141
	for (i = 0; i < min(alen, max_show); i++) {
138
	    printf("%s\n", CHAR(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
142
	    printf("%s\n", translateChar(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
139
	}
143
	}
140
	if (alen > max_show)
144
	if (alen > max_show)
141
	    printf("\n[...truncated]\n");
145
	    printf("\n[...truncated]\n");
142
	cursor_position = -2; /* Need to redisplay whole line */
146
	cursor_position = -2; /* Need to redisplay whole line */
143
    }
147
    }
144
    additional_text = CHAR(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
148
    additional_text = translateChar(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
145
    alen = strlen(additional_text);
149
    alen = strlen(additional_text);
146
    if (alen) {
150
    if (alen) {
147
	int cp = *loc;
151
	int cp = *loc;
148
	memcpy(buf+cp, additional_text, alen+1);
152
	memcpy(buf+cp, additional_text, alen+1);
149
	*loc = cp + alen;
153
	*loc = cp + alen;
150
    }
154
    }
-
 
155
    vmaxset(vmax);
-
 
156
    UNPROTECT(1); /* ans */
151
    return cursor_position;
157
    return cursor_position;
152
}
158
}
153
 
159
 
154
 
160
 
155
void R_gl_tab_set(void)
161
void R_gl_tab_set(void)