Logo ROOT  
Reference Guide
TRCompletion.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 2013-2014, Omar Andres Zapata Mesa *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8#include"TRCompletion.h"
9namespace ROOT {
10 namespace R {
11
19
21 }
22}
23
24char *ROOT::R::R_completion_generator(const char *text, int state)
25{
26 // If this is a new word to complete, initialize now. This
27 // involves saving 'text' to somewhere R can get it, calling
28 // completeToken(), and retrieving the completions.
29 //NOTE: R based code and ajusted to Rcpp
30 static int list_index, ncomp;
31 static char **compstrings;
32
33
34 if (!state) {
35 int i;
36 SEXP completions,
37 assignCall = PROTECT(Rf_lang2(ROOT::R::RComp_assignTokenSym, Rf_mkString(text))),
38 completionCall = PROTECT(Rf_lang1(ROOT::R::RComp_completeTokenSym)),
39 retrieveCall = PROTECT(Rf_lang1(ROOT::R::RComp_retrieveCompsSym));
40 const void *vmax = vmaxget();
41
42 Rf_eval(assignCall, ROOT::R::rcompgen_rho);
43 Rf_eval(completionCall, ROOT::R::rcompgen_rho);
44 PROTECT(completions = Rf_eval(retrieveCall, ROOT::R::rcompgen_rho));
45 list_index = 0;
46 ncomp = Rf_length(completions);
47 if (ncomp > 0) {
48 compstrings = (char **) malloc(ncomp * sizeof(char *));
49 if (!compstrings) return (char *)NULL;
50 for (i = 0; i < ncomp; i++)
51 compstrings[i] = strdup(Rf_translateChar(STRING_ELT(completions, i)));
52 }
53 UNPROTECT(4);
54 vmaxset(vmax);
55 }
56
57 if (list_index < ncomp)
58 return compstrings[list_index++];
59 else {
60 /* nothing matched or remaining, returns NULL. */
61 if (ncomp > 0) free(compstrings);
62 }
63 return (char *)NULL;
64}
65
66
67char **ROOT::R::R_custom_completion(const char *text, int start, int end)
68{
69 //NOTE: R based code and ajusted to Rcpp
70 char **matches = (char **)NULL;
71 SEXP infile,
72 linebufferCall = PROTECT(Rf_lang2(ROOT::R::RComp_assignBufferSym,
73 Rf_mkString(rl_line_buffer))),
74 startCall = PROTECT(Rf_lang2(ROOT::R::RComp_assignStartSym, Rf_ScalarInteger(start))),
75 endCall = PROTECT(Rf_lang2(ROOT::R::RComp_assignEndSym, Rf_ScalarInteger(end)));
76 SEXP filecompCall;
77
78 // We don't want spaces appended at the end. It's nedded everytime
79 // since readline>=6 resets it to ' '
81
82 Rf_eval(linebufferCall, ROOT::R::rcompgen_rho);
83 Rf_eval(startCall, ROOT::R::rcompgen_rho);
84 Rf_eval(endCall, ROOT::R::rcompgen_rho);
85 UNPROTECT(3);
86 matches = rl_completion_matches(text, ROOT::R::R_completion_generator);
87 filecompCall = PROTECT(Rf_lang1(ROOT::R::RComp_getFileCompSym));
88 infile = PROTECT(Rf_eval(filecompCall, ROOT::R::rcompgen_rho));
89 if (!Rf_asLogical(infile)) rl_attempted_completion_over = 1;
90 UNPROTECT(2);
91 return matches;
92}
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:110
int rl_attempted_completion_over
int rl_completion_append_character
char * rl_line_buffer
#define free
Definition: civetweb.c:1539
#define malloc
Definition: civetweb.c:1536
TText * text
SEXP RComp_assignBufferSym
char * R_completion_generator(const char *text, int state)
SEXP RComp_completeTokenSym
SEXP RComp_retrieveCompsSym
SEXP rcompgen_rho
SEXP RComp_assignStartSym
SEXP RComp_assignTokenSym
SEXP RComp_getFileCompSym
char ** R_custom_completion(const char *text, int start, int end)
SEXP RComp_assignEndSym
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: RNumpyDS.hxx:30