The R Project SVN R

Rev

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

Rev 42572 Rev 43117
Line 36... Line 36...
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 rcompgen_available = -1;
40
 
40
 
-
 
41
static int gl_tab(char *buf, int offset, int *loc)
-
 
42
/* default tab handler, acts like tabstops every 8 cols */
-
 
43
{
-
 
44
    int i, count, len;
-
 
45
 
-
 
46
    len = strlen(buf);
-
 
47
    count = 8 - (offset + *loc) % 8;
-
 
48
    for (i=len; i >= *loc; i--)
-
 
49
        buf[i+count] = buf[i];
-
 
50
    for (i=0; i < count; i++)
-
 
51
        buf[*loc+i] = ' ';
-
 
52
    i = *loc;
-
 
53
    *loc = i + count;
-
 
54
    return i;
-
 
55
}
-
 
56
 
41
static int rt_completion(char *buf, int offset, int *loc)
57
static int rt_completion(char *buf, int offset, int *loc)
42
{
58
{
43
    int i, alen, cursor_position = *loc;
59
    int i, alen, cursor_position = *loc;
44
    char *partial_line = buf;
60
    char *partial_line = buf;
45
    const char *additional_text;
61
    const char *additional_text;
46
    char *pline, *cmd;
62
    char *pline, *cmd;
47
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
63
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
48
    ParseStatus status;
64
    ParseStatus status;
49
 
65
 
50
    if(!rcompgen_available) return *loc;
66
    if(!rcompgen_available) return gl_tab(buf, offset, loc);
51
    
67
    
52
    if(rcompgen_available < 0) {
68
    if(rcompgen_available < 0) {
53
	char *p = getenv("R_COMPLETION");
69
	char *p = getenv("R_COMPLETION");
54
	if(p && strcmp(p, "FALSE") == 0) {
70
	if(p && strcmp(p, "FALSE") == 0) {
55
	    rcompgen_available = 0;
71
	    rcompgen_available = 0;
56
	    return -1; /* no change */	    
72
	    return gl_tab(buf, offset, loc);   
57
	}
73
	}
58
	/* First check if namespace is loaded */
74
	/* First check if namespace is loaded */
59
	if(findVarInFrame(R_NamespaceRegistry, install("rcompgen"))
75
	if(findVarInFrame(R_NamespaceRegistry, install("rcompgen"))
60
	   != R_UnboundValue) rcompgen_available = 1;
76
	   != R_UnboundValue) rcompgen_available = 1;
61
	else { /* Then try to load it */
77
	else { /* Then try to load it */