The R Project SVN R

Rev

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

Rev 47854 Rev 52804
Line 25... Line 25...
25
 
25
 
26
#include <getline/getline.h>
26
#include <getline/getline.h>
27
#include <string.h>
27
#include <string.h>
28
#include <stdlib.h> /* for getenv */
28
#include <stdlib.h> /* for getenv */
29
 
29
 
30
#ifdef __GNUC__
-
 
31
# undef alloca
-
 
32
# define alloca(x) __builtin_alloca((x))
-
 
33
#endif
-
 
34
 
-
 
35
#ifndef min
30
#ifndef min
36
/* in stdlib.h in Win64 headers */
31
/* in stdlib.h in Win64 headers */
37
# define min(a, b) (a < b ? a : b)
32
# define min(a, b) (a < b ? a : b)
38
#endif
33
#endif
39
 
34
 
Line 61... Line 56...
61
static int rt_completion(char *buf, int offset, int *loc)
56
static int rt_completion(char *buf, int offset, int *loc)
62
{
57
{
63
    int i, alen, cursor_position = *loc;
58
    int i, alen, cursor_position = *loc;
64
    char *partial_line = buf;
59
    char *partial_line = buf;
65
    const char *additional_text;
60
    const char *additional_text;
66
    char *pline, *cmd;
-
 
67
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
61
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
68
    ParseStatus status;
62
    ParseStatus status;
69
 
63
 
70
    if(!completion_available) return gl_tab(buf, offset, loc);
64
    if(!completion_available) return gl_tab(buf, offset, loc);
71
 
65
 
Line 95... Line 89...
95
	    }
89
	    }
96
	}
90
	}
97
    }
91
    }
98
 
92
 
99
    /* FIXME: need to escape quotes properly */
93
    /* FIXME: need to escape quotes properly */
100
    pline = alloca(strlen(partial_line) + 1);
94
    char pline[strlen(partial_line) + 1];
101
    strcpy(pline, partial_line);
95
    strcpy(pline, partial_line);
102
    /* poor attempt at escaping quotes that sort of works */
96
    /* poor attempt at escaping quotes that sort of works */
103
    alen = strlen(pline);
97
    alen = strlen(pline);
104
    for (i = 0; i < alen; i++) if (pline[i] == '"') pline[i] = '\'';
98
    for (i = 0; i < alen; i++) if (pline[i] == '"') pline[i] = '\'';
105
 
99
 
106
    cmd = alloca(strlen(pline) + 100);
100
    char cmd[strlen(pline) + 100];
107
    sprintf(cmd, "utils:::.win32consoleCompletion(\"%s\", %d)",
101
    sprintf(cmd, "utils:::.win32consoleCompletion(\"%s\", %d)",
108
	    pline, cursor_position);
102
	    pline, cursor_position);
109
    PROTECT(cmdSexp = mkString(cmd));
103
    PROTECT(cmdSexp = mkString(cmd));
110
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
104
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
111
    if (status != PARSE_OK) {
105
    if (status != PARSE_OK) {