The R Project SVN R

Rev

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

Rev 43237 Rev 43238
Line 34... Line 34...
34
#endif
34
#endif
35
 
35
 
36
#include <Rinternals.h>
36
#include <Rinternals.h>
37
#include <R_ext/Parse.h>
37
#include <R_ext/Parse.h>
38
 
38
 
39
static int rcompgen_available = -1;
39
static int completion_available = -1;
40
 
40
 
41
static int gl_tab(char *buf, int offset, int *loc)
41
static int gl_tab(char *buf, int offset, int *loc)
42
/* default tab handler, acts like tabstops every 8 cols */
42
/* default tab handler, acts like tabstops every 8 cols */
43
{
43
{
44
    int i, count, len;
44
    int i, count, len;
Line 61... Line 61...
61
    const char *additional_text;
61
    const char *additional_text;
62
    char *pline, *cmd;
62
    char *pline, *cmd;
63
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
63
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
64
    ParseStatus status;
64
    ParseStatus status;
65
 
65
 
66
    if(!rcompgen_available) return gl_tab(buf, offset, loc);
66
    if(!completion_available) return gl_tab(buf, offset, loc);
67
    
67
    
68
    if(rcompgen_available < 0) {
68
    if(completion_available < 0) {
69
	char *p = getenv("R_COMPLETION");
69
	char *p = getenv("R_COMPLETION");
70
	if(p && strcmp(p, "FALSE") == 0) {
70
	if(p && strcmp(p, "FALSE") == 0) {
71
	    rcompgen_available = 0;
71
	    completion_available = 0;
72
	    return gl_tab(buf, offset, loc);   
72
	    return gl_tab(buf, offset, loc);   
73
	}
73
	}
74
	/* First check if namespace is loaded */
74
	/* First check if namespace is loaded */
75
	if(findVarInFrame(R_NamespaceRegistry, install("utils"))
75
	if(findVarInFrame(R_NamespaceRegistry, install("utils"))
76
	   != R_UnboundValue) rcompgen_available = 1;
76
	   != R_UnboundValue) completion_available = 1;
77
	else { /* Then try to load it */
77
	else { /* Then try to load it */
78
	    char *p = "try(loadNamespace('rcompgen'), silent=TRUE)";
78
	    char *p = "try(loadNamespace('utils'), silent=TRUE)";
79
	    PROTECT(cmdSexp = mkString(p));
79
	    PROTECT(cmdSexp = mkString(p));
80
	    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
80
	    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
81
	    if(status == PARSE_OK) {
81
	    if(status == PARSE_OK) {
82
		for(i = 0; i < length(cmdexpr); i++)
82
		for(i = 0; i < length(cmdexpr); i++)
83
		    eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
83
		    eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
84
	    }
84
	    }
85
	    UNPROTECT(2);
85
	    UNPROTECT(2);
86
	    if(findVarInFrame(R_NamespaceRegistry, install("utils"))
86
	    if(findVarInFrame(R_NamespaceRegistry, install("utils"))
87
	       != R_UnboundValue) rcompgen_available = 1;
87
	       != R_UnboundValue) completion_available = 1;
88
	    else {
88
	    else {
89
		rcompgen_available = 0;
89
		completion_available = 0;
90
		return -1; /* no change */
90
		return -1; /* no change */
91
	    }
91
	    }
92
	}
92
	}
93
    }
93
    }
94
 
94
 
Line 98... Line 98...
98
    /* poor attempt at escaping quotes that sort of works */
98
    /* poor attempt at escaping quotes that sort of works */
99
    alen = strlen(pline);
99
    alen = strlen(pline);
100
    for (i = 0; i < alen; i++) if (pline[i] == '"') pline[i] = '\'';
100
    for (i = 0; i < alen; i++) if (pline[i] == '"') pline[i] = '\'';
101
 
101
 
102
    cmd = alloca(strlen(pline) + 100);
102
    cmd = alloca(strlen(pline) + 100);
103
    sprintf(cmd, "rcompgen:::.win32consoleCompletion(\"%s\", %d)",
103
    sprintf(cmd, "utils:::.win32consoleCompletion(\"%s\", %d)",
104
	    pline, cursor_position);
104
	    pline, cursor_position);
105
    PROTECT(cmdSexp = mkString(cmd));
105
    PROTECT(cmdSexp = mkString(cmd));
106
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
106
    cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue));
107
    if (status != PARSE_OK) {
107
    if (status != PARSE_OK) {
108
	UNPROTECT(2);
108
	UNPROTECT(2);