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