Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRint.cxx
Go to the documentation of this file.
1// @(#)root/rint:$Id$
2// Author: Rene Brun 17/02/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// Rint //
15// //
16// Rint is the ROOT Interactive Interface. It allows interactive access //
17// to the ROOT system via the Cling C/C++ interpreter. //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TROOT.h"
22#include "TClass.h"
23#include "TClassEdit.h"
24#include "TVirtualX.h"
25#include "TObjectTable.h"
26#include "TClassTable.h"
27#include "TStopwatch.h"
28#include "TBenchmark.h"
29#include "TRint.h"
30#include "TSystem.h"
31#include "TEnv.h"
32#include "TSysEvtHandler.h"
33#include "TSystemDirectory.h"
34#include "TError.h"
35#include "TException.h"
36#include "TInterpreter.h"
37#include "TObjString.h"
38#include "TObjArray.h"
39#include "TStorage.h" // ROOT::Internal::gMmallocDesc
40#include "ThreadLocalStorage.h"
41#include "TTabCom.h"
42#include <cstdlib>
43#include <algorithm>
44#include <iostream>
45#include "Getline.h"
46#include "strlcpy.h"
47#include "snprintf.h"
48
49#ifdef R__UNIX
50#include <csignal>
51#include <unistd.h>
52#endif
53
54////////////////////////////////////////////////////////////////////////////////
55
57{
59 return 0;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63
65{
66 if (!gSystem) return 0;
67 gSystem->Beep();
68 return 1;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Restore terminal to non-raw mode.
73
74static void ResetTermAtExit()
75{
76 Getlinem(kCleanUp, nullptr);
77}
78
79
80//----- Interrupt signal handler -----------------------------------------------
81////////////////////////////////////////////////////////////////////////////////
82
88
89////////////////////////////////////////////////////////////////////////////////
90/// TRint interrupt handler.
91
93{
94 if (fDelay) {
95 fDelay++;
96 return kTRUE;
97 }
98
99 // make sure we use the sbrk heap (in case of mapped files)
101
102 if (TROOT::Initialized() && gROOT->IsLineProcessing()) {
103 Break("TInterruptHandler::Notify", "keyboard interrupt");
104 Getlinem(kInit, "Root > ");
105 gCling->Reset();
106#ifndef WIN32
107 if (gException)
108 Throw(GetSignal());
109#endif
110 } else {
111 // Reset input.
112 Getlinem(kClear, ((TRint*)gApplication)->GetPrompt());
113 }
114
115 return kTRUE;
116}
117
118//----- Terminal Input file handler --------------------------------------------
119////////////////////////////////////////////////////////////////////////////////
120
122public:
124 Bool_t Notify() override;
125 Bool_t ReadNotify() override { return Notify(); }
126};
127
128////////////////////////////////////////////////////////////////////////////////
129/// Notify implementation. Call the application interupt handler.
130
135
136
137
138
139namespace {
141{
142 bool forcePtrCheck = false;
143 if (argc != nullptr) {
144 for (int iarg = 1; iarg < *argc; ++iarg) {
145 if (!strcmp(argv[iarg], "--ptrcheck")) {
146 // Hide this, by moving all other args one down...
147 for (int jarg = iarg + 1; jarg < *argc; ++jarg)
148 argv[jarg - 1] = argv[jarg];
149 // ... and updating argc accordingly.
150 --*argc;
151 forcePtrCheck = true;
152 break;
153 }
154 }
155 }
156#ifdef R__UNIX
157 if (forcePtrCheck || isatty(0) || isatty(1))
158#endif
159 TROOT::AddExtraInterpreterArgs({"--ptrcheck"});
160 return 0;
161}
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Create an application environment. The TRint environment provides an
166/// interface to the WM manager functionality and eventloop via inheritance
167/// of TApplication and in addition provides interactive access to
168/// the Cling C++ interpreter via the command line.
169
170TRint::TRint(const char *appClassName, Int_t *argc, char **argv, void *options, Int_t numOptions, Bool_t noLogo,
173 fCaughtSignal(-1)
174{
175
176 if (exitOnUnknownArgs && argc != nullptr && *argc > 1) {
177 // Early exit if there are remaining unrecognized options
178 // This branch supposes that TRint is created as a result of using the `root` command
179 for (auto n = 1; n < *argc; n++) {
180 std::cerr << "root: unrecognized option '" << argv[n] << "'\n";
181 }
182 std::cerr << "Try 'root --help' for more information.\n";
184 }
185
186 fNcmd = 0;
187 fDefaultPrompt = "root [%d] ";
189
190 gBenchmark = new TBenchmark();
191
192 if (!noLogo && !NoLogoOpt()) {
193 Bool_t lite = (Bool_t) gEnv->GetValue("Rint.WelcomeLite", 0);
195 }
196
197#ifndef R__USE_CXXMODULES
198 // When modules are not used, and therefore rootmaps, freestanding functions
199 // cannot trigger autoloading. Therefore, given the widespread usage of the
200 // freestanding functions in MathCore, we load the library explicitly.
201 // When modules are used to condense the reflection information, this manual
202 // loading is not needed, and it can be skipped in order to save time and
203 // memory when starting the ROOT prompt.
204 if (!gClassTable->GetDict("TRandom"))
205 gSystem->Load("libMathCore");
206#endif
207
208 if (!gInterpreter->HasPCMForLibrary("std")) {
209 // Load some frequently used includes
210 Int_t includes = gEnv->GetValue("Rint.Includes", 1);
211 // When the interactive ROOT starts, it can automatically load some frequently
212 // used includes. However, this introduces several overheads
213 // -The initialisation takes more time
214 // -Memory overhead when including <vector>
215 // In $ROOTSYS/etc/system.rootrc, you can set the variable Rint.Includes to 0
216 // to disable the loading of these includes at startup.
217 // You can set the variable to 1 (default) to load only <iostream>, <string> and <DllImport.h>
218 // You can set it to 2 to load in addition <vector> and <utility>
219 // We strongly recommend setting the variable to 2 if your scripts include <vector>
220 // and you execute your scripts multiple times.
221 if (includes > 0) {
222 TString code;
223 code = "#include <iostream>\n"
224 "#include <string>\n" // for std::string std::iostream.
225 "#include <DllImport.h>\n";// Defined R__EXTERN
226 if (includes > 1) {
227 code += "#include <vector>\n"
228 "#include <utility>";
229 }
230 ProcessLine(code, kTRUE);
231 }
232 }
233
234 // Load user functions
235 const char *logon;
236 logon = gEnv->GetValue("Rint.Load", (char*)nullptr);
237 if (logon) {
239 if (mac)
240 ProcessLine(Form(".L %s",logon), kTRUE);
241 delete [] mac;
242 }
243
244 // Execute logon macro
245 ExecLogon();
246
247 // Save current interpreter context
250
251 // Install interrupt and terminal input handlers
253 ih->Add();
255
256 // Handle stdin events
259
260 // Goto into raw terminal input mode
261 char defhist[kMAXPATHLEN];
262 snprintf(defhist, sizeof(defhist), "%s/.root_hist", gSystem->HomeDirectory());
263 logon = gEnv->GetValue("Rint.History", defhist);
264 // In the code we had HistorySize and HistorySave, in the rootrc and doc
265 // we have HistSize and HistSave. Keep the doc as it is and check
266 // now also for HistSize and HistSave in case the user did not use
267 // the History versions
268 int hist_size = gEnv->GetValue("Rint.HistorySize", 500);
269 if (hist_size == 500)
270 hist_size = gEnv->GetValue("Rint.HistSize", 500);
271 int hist_save = gEnv->GetValue("Rint.HistorySave", 400);
272 if (hist_save == 400)
273 hist_save = gEnv->GetValue("Rint.HistSave", 400);
274 const char *envHist = gSystem->Getenv("ROOT_HIST");
275 if (envHist) {
276 hist_size = atoi(envHist);
277 envHist = strchr(envHist, ':');
278 if (envHist)
279 hist_save = atoi(envHist+1);
280 }
282 Gl_histinit((char *)logon);
283
284 // black on white or white on black?
285 static const char* defaultColorsBW[] = {
286 "bold blue", "magenta", "bold green", "bold red underlined", "default"
287 };
288 static const char* defaultColorsWB[] = {
289 "yellow", "magenta", "bold green", "bold red underlined", "default"
290 };
291
292 const char** defaultColors = defaultColorsBW;
293 TString revColor = gEnv->GetValue("Rint.ReverseColor", "no");
294 if (revColor.Contains("yes", TString::kIgnoreCase)) {
296 }
297 TString colorType = gEnv->GetValue("Rint.TypeColor", defaultColors[0]);
298 TString colorTabCom = gEnv->GetValue("Rint.TabComColor", defaultColors[1]);
299 TString colorBracket = gEnv->GetValue("Rint.BracketColor", defaultColors[2]);
300 TString colorBadBracket = gEnv->GetValue("Rint.BadBracketColor", defaultColors[3]);
301 TString colorPrompt = gEnv->GetValue("Rint.PromptColor", defaultColors[4]);
303
305
307
308 // Setup for tab completion
309 gTabCom = new TTabCom;
312
313 // tell Cling to use our getline
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Destructor.
319
321{
322 delete gTabCom;
323 gTabCom = nullptr;
324 Gl_in_key = nullptr;
325 Gl_beep_hook = nullptr;
327 delete fInputHandler;
328 // We can't know where the signal handler was changed since we started ...
329 // so for now let's not delete it.
330// TSignalHandler *ih = GetSignalHandler();
331// ih->Remove();
332// SetSignalHandler(0);
333// delete ih;
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Execute logon macro's. There are three levels of logon macros that
338/// will be executed: the system logon etc/system.rootlogon.C, the global
339/// user logon ~/.rootlogon.C and the local ./.rootlogon.C. For backward
340/// compatibility also the logon macro as specified by the Rint.Logon
341/// environment setting, by default ./rootlogon.C, will be executed.
342/// No logon macros will be executed when the system is started with
343/// the -n option.
344
346{
347 if (NoLogOpt()) return;
348
349 TString name = ".rootlogon.C";
350 TString sname = "system";
351 sname += name;
356 ProcessFile(s);
357 }
361 }
362 // avoid executing ~/.rootlogon.C twice
366 }
367
368 // execute also the logon macro specified by "Rint.Logon"
369 const char *logon = gEnv->GetValue("Rint.Logon", (char*)nullptr);
370 if (logon) {
372 if (mac)
374 delete [] mac;
375 }
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Main application eventloop. First process files given on the command
380/// line and then go into the main application event loop, unless the -q
381/// command line option was specified in which case the program terminates.
382/// When return is true this method returns even when -q was specified.
383///
384/// When QuitOpt is true and return is false, terminate the application with
385/// an error code equal to either the ProcessLine error (if any) or the
386/// return value of the command casted to a long.
387
389{
390 if (!QuitOpt()) {
391 // Prompt prompt only if we are expecting / allowing input.
392 Getlinem(kInit, GetPrompt());
393 }
394
395 Longptr_t retval = 0;
396 Int_t error = 0;
397 volatile Bool_t needGetlinemInit = kFALSE;
398
399 if (strlen(WorkingDirectory())) {
400 // if directory specified as argument make it the working directory
403 TObject *w = gROOT->GetListOfBrowsables()->FindObject("workdir");
404 TObjLink *lnk = gROOT->GetListOfBrowsables()->FirstLink();
405 while (lnk) {
406 if (lnk->GetObject() == w) {
407 lnk->SetObject(workdir);
408 lnk->SetOption(gSystem->WorkingDirectory());
409 break;
410 }
411 lnk = lnk->Next();
412 }
413 delete w;
414 }
415
416 // Process shell command line input files
417 if (InputFiles()) {
418 // Make sure that calls into the event loop
419 // ignore end-of-file on the terminal.
421 TIter next(InputFiles());
422 RETRY {
423 retval = 0; error = 0;
424 Int_t nfile = 0;
425 while (TObject *fileObj = next()) {
426 if (dynamic_cast<TNamed*>(fileObj)) {
427 // A file that TApplication did not find. Note the error.
428 retval = 1;
429 continue;
430 }
431 TObjString *file = (TObjString *)fileObj;
432 char cmd[kMAXPATHLEN+50];
433 // First print a newline before going over the inputs to separate
434 // printouts from the initial "root [0]" prompt. If root is run
435 // with "-q", there is no prompt and we don't need the newline.
436 if (!fNcmd && !QuitOpt())
437 printf("\n");
439
440 if (file->TestBit(kExpression)) {
441 snprintf(cmd, kMAXPATHLEN+50, "%s", (const char*)file->String());
442 } else {
443 if (file->String().EndsWith(".root") || file->String().BeginsWith("file:")) {
444 rootfile = kTRUE;
445 } else {
446 rootfile = gROOT->IsRootFile(file->String());
447 }
448 if (rootfile) {
449 // special trick to be able to open files using UNC path names
450 if (file->String().BeginsWith("\\\\"))
451 file->String().Prepend("\\\\");
452 file->String().ReplaceAll("\\","/");
453 const char *rfile = (const char*)file->String();
454 Printf("Attaching file %s as _file%d...", rfile, nfile);
455 snprintf(cmd, kMAXPATHLEN+50, "TFile *_file%d = TFile::Open(\"%s\")", nfile++, rfile);
456 } else {
457 Printf("Processing %s...", (const char*)file->String());
458 snprintf(cmd, kMAXPATHLEN+50, ".x %s", (const char*)file->String());
459 }
460 }
461 Getlinem(kCleanUp, nullptr);
463
464 // The ProcessLine might throw an 'exception'. In this case,
465 // GetLinem(kInit,"Root >") is called and we are jump back
466 // to RETRY ... and we have to avoid the Getlinem(kInit, GetPrompt());
468 retval = ProcessLineNr("ROOT_cli_", cmd, &error);
470 fNcmd++;
471
472 // The ProcessLine has successfully completed and we need
473 // to call Getlinem(kInit, GetPrompt());
475
476 if (error != 0 || fCaughtSignal != -1) break;
477 }
478 } ENDTRY;
479
480 if (QuitOpt()) {
481 if (retrn) return;
482 if (error) {
483 retval = error;
484 } else if (fCaughtSignal != -1) {
485 retval = fCaughtSignal + 128;
486 }
487 // Bring retval into sensible range, 0..255.
489 retval = 255;
491 }
492
493 // Allow end-of-file on the terminal to be noticed
494 // after we finish processing the command line input files.
496
498
499 if (needGetlinemInit) Getlinem(kInit, GetPrompt());
500 }
501
502 if (QuitOpt()) {
503 if (retrn) return;
504 Terminate(fCaughtSignal != -1 ? fCaughtSignal + 128 : 0);
505 }
506
508
509 // Reset to happiness.
510 fCaughtSignal = -1;
511
512 Getlinem(kCleanUp, nullptr);
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Print the ROOT logo on standard output.
517
519{
520 if (!lite) {
521 // Fancy formatting: the content of lines are format strings; their %s is
522 // replaced by spaces needed to make all lines as long as the longest line.
523 std::vector<TString> lines;
524 // Here, %%s results in %s after TString::Format():
525 lines.emplace_back(TString::Format("Welcome to ROOT %s%%shttps://root.cern",
526 gROOT->GetVersion()));
527 lines.emplace_back(TString::Format("(c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers%%s"));
528 lines.emplace_back(TString::Format("Built for %s on %s%%s", gSystem->GetBuildArch(), gROOT->GetGitDate()));
529 if (!strcmp(gROOT->GetGitBranch(), gROOT->GetGitCommit())) {
530 static const char *months[] = {"January","February","March","April","May",
531 "June","July","August","September","October",
532 "November","December"};
533 Int_t idatqq = gROOT->GetVersionDate();
534 Int_t iday = idatqq%100;
535 Int_t imonth = (idatqq/100)%100;
536 Int_t iyear = (idatqq/10000);
537
538 lines.emplace_back(TString::Format("From tag %s, %d %s %4d%%s",
539 gROOT->GetGitBranch(),
540 iday,months[imonth-1],iyear));
541 } else {
542 // If branch and commit are identical - e.g. "v5-34-18" - then we have
543 // a release build. Else specify the git hash this build was made from.
544 lines.emplace_back(TString::Format("From %s@%s %%s",
545 gROOT->GetGitBranch(),
546 gROOT->GetGitCommit()));
547 }
548 lines.emplace_back(TString::Format("With %s std%ld %%s",
550 lines.emplace_back(TString("Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'%s"));
551
552 // Find the longest line and its length:
553 auto itLongest = std::max_element(lines.begin(), lines.end(),
554 [](const TString& left, const TString& right) {
555 return left.Length() < right.Length(); });
556 Ssiz_t lenLongest = itLongest->Length();
557
558
559 Printf(" %s", TString('-', lenLongest).Data());
560 for (const auto& line: lines) {
561 // Print the line, expanded with the necessary spaces at %s, and
562 // surrounded by some ASCII art.
563 Printf(" | %s |",
564 TString::Format(line.Data(),
565 TString(' ', lenLongest - line.Length()).Data()).Data());
566 }
567 Printf(" %s\n", TString('-', lenLongest).Data());
568 }
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Get prompt from interpreter. Either "root [n]" or "end with '}'".
573
575{
576 char *s = gCling->GetPrompt();
577 if (s[0])
578 strlcpy(fPrompt, s, sizeof(fPrompt));
579 else
581
582 return fPrompt;
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// Set a new default prompt. It returns the previous prompt.
587/// The prompt may contain a %d which will be replaced by the commend
588/// number. The default prompt is "root [%d] ". The maximum length of
589/// the prompt is 55 characters. To set the prompt in an interactive
590/// session do:
591/// root [0] ((TRint*)gROOT->GetApplication())->SetPrompt("aap> ")
592/// aap>
593
594const char *TRint::SetPrompt(const char *newPrompt)
595{
596 static TString op;
598
599 if (newPrompt && strlen(newPrompt) <= 55)
601 else
602 Error("SetPrompt", "newPrompt too long (> 55 characters)");
603
604 return op.Data();
605}
606
607////////////////////////////////////////////////////////////////////////////////
608/// Handle input coming from terminal.
609
611{
612 static TStopwatch timer;
613 const char *line;
614
615 if ((line = Getlinem(kOneChar, nullptr))) {
616 if (line[0] == 0 && Gl_eof())
617 Terminate(0);
618
619 gVirtualX->SetKeyAutoRepeat(kTRUE);
620
622
624
625 // strip off '\n' and leading and trailing blanks
626 sline = sline.Chop();
627 sline = sline.Strip(TString::kBoth);
628 ReturnPressed((char*)sline.Data());
629
631
632 // prevent recursive calling of this input handler
634
635 if (gROOT->Timer()) timer.Start();
636
638 added = kFALSE; // reset on each call.
639
640 // This is needed when working with remote sessions
642
643 try {
644 TRY {
645 if (!sline.IsNull())
647 ProcessLineNr("ROOT_prompt_", sline);
648 } CATCH(excode) {
649 // enable again input handler
651 added = kTRUE;
652 Throw(excode);
653 } ENDTRY;
654 }
655 // handle every exception
656 catch (std::exception& e) {
657 // enable again intput handler
659
660 int err;
662 const char* demangledType = demangledType_c;
663 if (err) {
664 demangledType_c = nullptr;
665 demangledType = "<UNKNOWN>";
666 }
667 Error("HandleTermInput()", "%s caught: %s", demangledType, e.what());
669 }
670 catch (...) {
671 // enable again intput handler
673 Error("HandleTermInput()", "Exception caught!");
674 }
675
676 // `ProcessLineNr()` only prepends a `#line` directive if the previous
677 // input line was not terminated by a '\' (backslash-newline).
678 // Thus, to match source locations included in cling diagnostics, we only
679 // increment `fNcmd` if the next call to `ProcessLineNr()` will issue
680 // a new `#line`.
681 if (!fBackslashContinue && !sline.IsNull())
682 fNcmd++;
683
684 if (gROOT->Timer()) timer.Print("u");
685
686 // enable again intput handler
688
689 if (!sline.BeginsWith(".reset"))
691
692 gTabCom->ClearAll();
693 Getlinem(kInit, GetPrompt());
694 }
695 return kTRUE;
696}
697
698////////////////////////////////////////////////////////////////////////////////
699/// Handle signals (kSigBus, kSigSegmentationViolation,
700/// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
701/// Specific TApplication implementations may want something different here.
702
704{
705 fCaughtSignal = sig;
706 if (TROOT::Initialized()) {
707 if (gException) {
708 Getlinem(kCleanUp, nullptr);
709 Getlinem(kInit, "Root > ");
710 }
711 }
713}
714
715////////////////////////////////////////////////////////////////////////////////
716/// Terminate the application. Reset the terminal to sane mode and call
717/// the logoff macro defined via Rint.Logoff environment variable.
718/// @note The function does not return, unless the class has
719/// been told to return from Run(), by a call to SetReturnFromRun().
720
722{
723 Getlinem(kCleanUp, nullptr);
724
725 if (ReturnFromRun()) {
726 gSystem->ExitLoop();
727 } else {
728 delete gTabCom;
729 gTabCom = nullptr;
730
731 //Execute logoff macro
732 const char *logoff;
733 logoff = gEnv->GetValue("Rint.Logoff", (char*)nullptr);
734 if (logoff && !NoLogOpt()) {
736 if (mac)
738 delete [] mac;
739 }
740
742 }
743}
744
745////////////////////////////////////////////////////////////////////////////////
746/// Set console mode:
747///
748/// mode = kTRUE - echo input symbols
749/// mode = kFALSE - noecho input symbols
750
752{
753 Gl_config("noecho", mode ? 0 : 1);
754}
755
756////////////////////////////////////////////////////////////////////////////////
757/// Process the content of a line starting with ".R" (already stripped-off)
758/// The format is
759/// [user@]host[:dir] [-l user] [-d dbg] [script]
760/// The variable 'dir' is the remote directory to be used as working dir.
761/// The username can be specified in two ways, "-l" having the priority
762/// (as in ssh).
763/// A 'dbg' value > 0 gives increasing verbosity.
764/// The last argument 'script' allows to specify an alternative script to
765/// be executed remotely to startup the session.
766
768{
770
771 if (ret == 1) {
772 if (fAppRemote) {
773 TString prompt; prompt.Form("%s:root [%%d] ", fAppRemote->ApplicationName());
775 } else {
776 SetPrompt("root [%d] ");
777 }
778 }
779
780 return ret;
781}
782
783
784////////////////////////////////////////////////////////////////////////////////
785/// Calls TRint::ProcessLine() possibly prepending a `#line` directive for
786/// better diagnostics.
787/// The user is responsible for incrementing `fNcmd`, where appropriate, after
788/// a call to this function.
789
790Longptr_t TRint::ProcessLineNr(const char* filestem, const char *line, Int_t *error /*= 0*/)
791{
792 Int_t err;
793 if (!error)
794 error = &err;
795 if (line && line[0] != '.') {
798 input += TString::Format("#line 1 \"%s%d\"\n", filestem, fNcmd);
799 input += line;
800 int res = ProcessLine(input, kFALSE, error);
801 if (gCling->GetMore()) {
804 SetPrompt("root (cont'ed, cancel with .@) [%d]");
805 } else if (fNonContinuePrompt.Length()) {
808 }
809 std::string_view sv(line);
810 auto lastNonSpace = sv.find_last_not_of(" \t");
811 fBackslashContinue = (lastNonSpace != std::string_view::npos
812 && sv[lastNonSpace] == '\\');
813 return res;
814 }
815 if (line && line[0] == '.' && line[1] == '@') {
816 ProcessLine(line, kFALSE, error);
817 SetPrompt("root [%d] ");
818 }
819 return ProcessLine(line, kFALSE, error);
820}
821
822
823////////////////////////////////////////////////////////////////////////////////
824/// Forward tab completion request to our TTabCom::Hook().
825
826Int_t TRint::TabCompletionHook(char *buf, int *pLoc, std::ostream& out)
827{
828 if (gTabCom)
829 return gTabCom->Hook(buf, pLoc, out);
830
831 return -1;
832}
#define s1(x)
Definition RSha256.hxx:91
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kMAXPATHLEN
Definition Rtypes.h:61
R__EXTERN TApplication * gApplication
R__EXTERN TBenchmark * gBenchmark
Definition TBenchmark.h:59
R__EXTERN TClassTable * gClassTable
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
void Break(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:230
#define CATCH(n)
Definition TException.h:58
#define ENDTRY
Definition TException.h:64
#define RETRY
Definition TException.h:44
#define TRY
Definition TException.h:51
R__EXTERN ExceptionContext_t * gException
Definition TException.h:69
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
R__EXTERN TInterpreter * gCling
#define gInterpreter
#define gROOT
Definition TROOT.h:414
static void ResetTermAtExit()
Restore terminal to non-raw mode.
Definition TRint.cxx:74
static Int_t Key_Pressed(Int_t key)
Definition TRint.cxx:56
static Int_t BeepHook()
Definition TRint.cxx:64
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
@ kSigInterrupt
@ kReadPermission
Definition TSystem.h:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
R__EXTERN TTabCom * gTabCom
Definition TTabCom.h:229
#define gVirtualX
Definition TVirtualX.h:337
#define free
Definition civetweb.c:1578
#define snprintf
Definition civetweb.c:1579
const_iterator begin() const
const_iterator end() const
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void KeyPressed(Int_t key)
Emit signal when console keyboard key was pressed.
virtual Longptr_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=nullptr)
Process a single command line, either a C++ statement or an interpreter command starting with a "....
virtual Bool_t HandleTermInput()
TObjArray * InputFiles() const
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
Bool_t ReturnFromRun() const
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual const char * ApplicationName() const
virtual Longptr_t ProcessFile(const char *file, Int_t *error=nullptr, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
virtual void ReturnPressed(char *text)
Emit signal when return key was pressed.
Bool_t NoLogOpt() const
Bool_t NoLogoOpt() const
const char * WorkingDirectory() const
Bool_t QuitOpt() const
virtual Longptr_t ProcessRemote(const char *line, Int_t *error=nullptr)
Process the content of a line starting with ".R" (already stripped-off) The format is.
TApplication * fAppRemote
void SetSignalHandler(TSignalHandler *sh)
This class is a ROOT utility to help benchmarking applications.
Definition TBenchmark.h:29
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:503
void Remove() override
Remove file event handler from system file handler list.
void Add() override
Add file event handler to system file handler list.
virtual char * GetPrompt()=0
virtual void SaveGlobalsContext()=0
virtual void EndOfLineAction()=0
virtual void Reset()=0
virtual void SetGetline(const char *(*getlineFunc)(const char *prompt), void(*histaddFunc)(const char *line))=0
virtual void SaveContext()=0
virtual Int_t GetMore() const =0
Returns whether the interpreter is waiting for more input, i.e.
Bool_t Notify() override
TRint interrupt handler.
Definition TRint.cxx:92
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:881
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition TROOT.cxx:2767
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2917
static const std::vector< std::string > & AddExtraInterpreterArgs(const std::vector< std::string > &args)
Provide command line arguments to the interpreter construction.
Definition TROOT.cxx:2963
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition TROOT.cxx:3231
Definition TRint.h:31
void SetEchoMode(Bool_t mode) override
Set console mode:
Definition TRint.cxx:751
Bool_t HandleTermInput() override
Handle input coming from terminal.
Definition TRint.cxx:610
Bool_t fInterrupt
Definition TRint.h:38
void Run(Bool_t retrn=kFALSE) override
Main application eventloop.
Definition TRint.cxx:388
Longptr_t ProcessLineNr(const char *filestem, const char *line, Int_t *error=nullptr)
Calls TRint::ProcessLine() possibly prepending a #line directive for better diagnostics.
Definition TRint.cxx:790
virtual const char * SetPrompt(const char *newPrompt)
Set a new default prompt.
Definition TRint.cxx:594
virtual void Terminate(int status) override
Terminate the application.
Definition TRint.cxx:721
char fPrompt[64]
Definition TRint.h:37
Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out) override
Forward tab completion request to our TTabCom::Hook().
Definition TRint.cxx:826
virtual char * GetPrompt()
Get prompt from interpreter. Either "root [n]" or "end with '}'".
Definition TRint.cxx:574
void HandleException(Int_t sig) override
Handle signals (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingException)...
Definition TRint.cxx:703
virtual ~TRint()
Destructor.
Definition TRint.cxx:320
virtual void PrintLogo(Bool_t lite=kFALSE)
Print the ROOT logo on standard output.
Definition TRint.cxx:518
void ExecLogon()
Execute logon macro's.
Definition TRint.cxx:345
Longptr_t ProcessRemote(const char *line, Int_t *error=nullptr) override
Process the content of a line starting with ".R" (already stripped-off) The format is [user@]host[:di...
Definition TRint.cxx:767
Bool_t fBackslashContinue
Definition TRint.h:41
TString fDefaultPrompt
Definition TRint.h:35
TString fNonContinuePrompt
Definition TRint.h:36
Int_t fCaughtSignal
Definition TRint.h:39
Int_t fNcmd
Definition TRint.h:34
TRint(const TRint &)=delete
TFileHandler * fInputHandler
Definition TRint.h:40
ESignals GetSignal() const
Stopwatch class.
Definition TStopwatch.h:28
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2250
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1241
const char * Data() const
Definition TString.h:384
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:713
@ kBoth
Definition TString.h:284
@ kIgnoreCase
Definition TString.h:285
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:632
TString & Prepend(const char *cs)
Definition TString.h:682
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
void DeActivate()
De-activate a system event handler.
void Activate()
Activate a system event handler.
Describes an Operating System directory for the browser.
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
Definition TSystem.cxx:322
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1676
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1868
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1092
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1307
virtual void ExitLoop()
Exit from event loop.
Definition TSystem.cxx:390
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:872
virtual const char * GetBuildCompilerVersionStr() const
Return the build compiler version identifier string.
Definition TSystem.cxx:3930
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:881
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1559
virtual const char * GetBuildArch() const
Return the build architecture.
Definition TSystem.cxx:3906
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition TSystem.cxx:897
Int_t Hook(char *buf, int *pLoc, std::ostream &out)
[private]
Definition TTabCom.cxx:1572
void ClearAll()
clears all lists except for user names and system include files.
Definition TTabCom.cxx:318
TTermInputHandler(Int_t fd)
Definition TRint.cxx:123
Bool_t ReadNotify() override
Notify when something can be read from the descriptor associated with this handler.
Definition TRint.cxx:125
Bool_t Notify() override
Notify implementation. Call the application interupt handler.
Definition TRint.cxx:131
TLine * line
const Int_t n
Definition legend1.C:16
R__EXTERN void * gMmallocDesc
Definition TStorage.h:141
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.