Logo ROOT  
Reference Guide
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 <signal.h>
51#endif
52
53////////////////////////////////////////////////////////////////////////////////
54
56{
58 return 0;
59}
60
61////////////////////////////////////////////////////////////////////////////////
62
64{
65 if (!gSystem) return 0;
66 gSystem->Beep();
67 return 1;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Restore terminal to non-raw mode.
72
73static void ResetTermAtExit()
74{
75 Getlinem(kCleanUp, 0);
76}
77
78
79//----- Interrupt signal handler -----------------------------------------------
80////////////////////////////////////////////////////////////////////////////////
81
83public:
85 Bool_t Notify();
86};
87
88////////////////////////////////////////////////////////////////////////////////
89/// TRint interrupt handler.
90
92{
93 if (fDelay) {
94 fDelay++;
95 return kTRUE;
96 }
97
98 // make sure we use the sbrk heap (in case of mapped files)
100
101 if (TROOT::Initialized() && gROOT->IsLineProcessing()) {
102 Break("TInterruptHandler::Notify", "keyboard interrupt");
103 Getlinem(kInit, "Root > ");
104 gCling->Reset();
105#ifndef WIN32
106 if (gException)
107 Throw(GetSignal());
108#endif
109 } else {
110 // Reset input.
111 Getlinem(kClear, ((TRint*)gApplication)->GetPrompt());
112 }
113
114 return kTRUE;
115}
116
117//----- Terminal Input file handler --------------------------------------------
118////////////////////////////////////////////////////////////////////////////////
119
121public:
123 Bool_t Notify();
124 Bool_t ReadNotify() { return Notify(); }
125};
126
127////////////////////////////////////////////////////////////////////////////////
128/// Notify implementation. Call the application interupt handler.
129
131{
133}
134
135
137
138////////////////////////////////////////////////////////////////////////////////
139/// Create an application environment. The TRint environment provides an
140/// interface to the WM manager functionality and eventloop via inheritance
141/// of TApplication and in addition provides interactive access to
142/// the Cling C++ interpreter via the command line.
143
144TRint::TRint(const char *appClassName, Int_t *argc, char **argv, void *options,
145 Int_t numOptions, Bool_t noLogo):
146 TApplication(appClassName, argc, argv, options, numOptions),
147 fCaughtSignal(-1)
148{
149
150 if (*argc > 1) {
151 // Early exit if there are remaining unrecognized options
152 for (auto n = 1; n < *argc; n++) {
153 std::cerr << "root: unrecognized option '" << argv[n] << "'\n";
154 }
155 std::cerr << "Try 'root --help' for more information.\n";
157 }
158
159 fNcmd = 0;
160 fDefaultPrompt = "root [%d] ";
162
163 gBenchmark = new TBenchmark();
164
165 if (!noLogo && !NoLogoOpt()) {
166 Bool_t lite = (Bool_t) gEnv->GetValue("Rint.WelcomeLite", 0);
167 PrintLogo(lite);
168 }
169
170 // Explicitly load libMathCore it cannot be auto-loaded it when using one
171 // of its freestanding functions. Once functions can trigger autoloading we
172 // can get rid of this.
173 if (!gClassTable->GetDict("TRandom"))
174 gSystem->Load("libMathCore");
175
176 if (!gInterpreter->HasPCMForLibrary("std")) {
177 // Load some frequently used includes
178 Int_t includes = gEnv->GetValue("Rint.Includes", 1);
179 // When the interactive ROOT starts, it can automatically load some frequently
180 // used includes. However, this introduces several overheads
181 // -The initialisation takes more time
182 // -Memory overhead when including <vector>
183 // In $ROOTSYS/etc/system.rootrc, you can set the variable Rint.Includes to 0
184 // to disable the loading of these includes at startup.
185 // You can set the variable to 1 (default) to load only <iostream>, <string> and <DllImport.h>
186 // You can set it to 2 to load in addition <vector> and <utility>
187 // We strongly recommend setting the variable to 2 if your scripts include <vector>
188 // and you execute your scripts multiple times.
189 if (includes > 0) {
190 TString code;
191 code = "#include <iostream>\n"
192 "#include <string>\n" // for std::string std::iostream.
193 "#include <DllImport.h>\n";// Defined R__EXTERN
194 if (includes > 1) {
195 code += "#include <vector>\n"
196 "#include <utility>";
197 }
198 ProcessLine(code, kTRUE);
199 }
200 }
201
202 // Load user functions
203 const char *logon;
204 logon = gEnv->GetValue("Rint.Load", (char*)0);
205 if (logon) {
206 char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
207 if (mac)
208 ProcessLine(Form(".L %s",logon), kTRUE);
209 delete [] mac;
210 }
211
212 // Execute logon macro
213 ExecLogon();
214
215 // Save current interpreter context
218
219 // Install interrupt and terminal input handlers
221 ih->Add();
223
224 // Handle stdin events
227
228 // Goto into raw terminal input mode
229 char defhist[kMAXPATHLEN];
230 snprintf(defhist, sizeof(defhist), "%s/.root_hist", gSystem->HomeDirectory());
231 logon = gEnv->GetValue("Rint.History", defhist);
232 // In the code we had HistorySize and HistorySave, in the rootrc and doc
233 // we have HistSize and HistSave. Keep the doc as it is and check
234 // now also for HistSize and HistSave in case the user did not use
235 // the History versions
236 int hist_size = gEnv->GetValue("Rint.HistorySize", 500);
237 if (hist_size == 500)
238 hist_size = gEnv->GetValue("Rint.HistSize", 500);
239 int hist_save = gEnv->GetValue("Rint.HistorySave", 400);
240 if (hist_save == 400)
241 hist_save = gEnv->GetValue("Rint.HistSave", 400);
242 const char *envHist = gSystem->Getenv("ROOT_HIST");
243 if (envHist) {
244 hist_size = atoi(envHist);
245 envHist = strchr(envHist, ':');
246 if (envHist)
247 hist_save = atoi(envHist+1);
248 }
249 Gl_histsize(hist_size, hist_save);
250 Gl_histinit((char *)logon);
251
252 // black on white or white on black?
253 static const char* defaultColorsBW[] = {
254 "bold blue", "magenta", "bold green", "bold red underlined", "default"
255 };
256 static const char* defaultColorsWB[] = {
257 "yellow", "magenta", "bold green", "bold red underlined", "default"
258 };
259
260 const char** defaultColors = defaultColorsBW;
261 TString revColor = gEnv->GetValue("Rint.ReverseColor", "no");
262 if (revColor.Contains("yes", TString::kIgnoreCase)) {
263 defaultColors = defaultColorsWB;
264 }
265 TString colorType = gEnv->GetValue("Rint.TypeColor", defaultColors[0]);
266 TString colorTabCom = gEnv->GetValue("Rint.TabComColor", defaultColors[1]);
267 TString colorBracket = gEnv->GetValue("Rint.BracketColor", defaultColors[2]);
268 TString colorBadBracket = gEnv->GetValue("Rint.BadBracketColor", defaultColors[3]);
269 TString colorPrompt = gEnv->GetValue("Rint.PromptColor", defaultColors[4]);
270 Gl_setColors(colorType, colorTabCom, colorBracket, colorBadBracket, colorPrompt);
271
272 Gl_windowchanged();
273
274 atexit(ResetTermAtExit);
275
276 // Setup for tab completion
277 gTabCom = new TTabCom;
278 Gl_in_key = &Key_Pressed;
279 Gl_beep_hook = &BeepHook;
280
281 // tell Cling to use our getline
282 gCling->SetGetline(Getline, Gl_histadd);
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Destructor.
287
289{
290 delete gTabCom;
291 gTabCom = 0;
292 Gl_in_key = 0;
293 Gl_beep_hook = 0;
295 delete fInputHandler;
296 // We can't know where the signal handler was changed since we started ...
297 // so for now let's not delete it.
298// TSignalHandler *ih = GetSignalHandler();
299// ih->Remove();
300// SetSignalHandler(0);
301// delete ih;
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// Execute logon macro's. There are three levels of logon macros that
306/// will be executed: the system logon etc/system.rootlogon.C, the global
307/// user logon ~/.rootlogon.C and the local ./.rootlogon.C. For backward
308/// compatibility also the logon macro as specified by the Rint.Logon
309/// environment setting, by default ./rootlogon.C, will be executed.
310/// No logon macros will be executed when the system is started with
311/// the -n option.
312
314{
315 if (NoLogOpt()) return;
316
317 TString name = ".rootlogon.C";
318 TString sname = "system";
319 sname += name;
320 char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
322 ProcessFile(s);
323 }
324 delete [] s;
327 ProcessFile(s);
328 }
329 delete [] s;
330 // avoid executing ~/.rootlogon.C twice
331 if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
334 }
335
336 // execute also the logon macro specified by "Rint.Logon"
337 const char *logon = gEnv->GetValue("Rint.Logon", (char*)0);
338 if (logon) {
339 char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
340 if (mac)
341 ProcessFile(logon);
342 delete [] mac;
343 }
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Main application eventloop. First process files given on the command
348/// line and then go into the main application event loop, unless the -q
349/// command line option was specified in which case the program terminates.
350/// When return is true this method returns even when -q was specified.
351///
352/// When QuitOpt is true and return is false, terminate the application with
353/// an error code equal to either the ProcessLine error (if any) or the
354/// return value of the command casted to a long.
355
357{
358 if (!QuitOpt()) {
359 // Promt prompt only if we are expecting / allowing input.
360 Getlinem(kInit, GetPrompt());
361 }
362
363 Longptr_t retval = 0;
364 Int_t error = 0;
365 volatile Bool_t needGetlinemInit = kFALSE;
366
367 if (strlen(WorkingDirectory())) {
368 // if directory specified as argument make it the working directory
370 TSystemDirectory *workdir = new TSystemDirectory("workdir", gSystem->WorkingDirectory());
371 TObject *w = gROOT->GetListOfBrowsables()->FindObject("workdir");
372 TObjLink *lnk = gROOT->GetListOfBrowsables()->FirstLink();
373 while (lnk) {
374 if (lnk->GetObject() == w) {
375 lnk->SetObject(workdir);
377 break;
378 }
379 lnk = lnk->Next();
380 }
381 delete w;
382 }
383
384 // Process shell command line input files
385 if (InputFiles()) {
386 // Make sure that calls into the event loop
387 // ignore end-of-file on the terminal.
389 TIter next(InputFiles());
390 RETRY {
391 retval = 0; error = 0;
392 Int_t nfile = 0;
393 while (TObject *fileObj = next()) {
394 if (dynamic_cast<TNamed*>(fileObj)) {
395 // A file that TApplication did not find. Note the error.
396 retval = 1;
397 continue;
398 }
399 TObjString *file = (TObjString *)fileObj;
400 char cmd[kMAXPATHLEN+50];
401 if (!fNcmd)
402 printf("\n");
403 Bool_t rootfile = kFALSE;
404
405 if (file->TestBit(kExpression)) {
406 snprintf(cmd, kMAXPATHLEN+50, "%s", (const char*)file->String());
407 } else {
408 if (file->String().EndsWith(".root") || file->String().BeginsWith("file:")) {
409 rootfile = kTRUE;
410 } else {
411 rootfile = gROOT->IsRootFile(file->String());
412 }
413 if (rootfile) {
414 // special trick to be able to open files using UNC path names
415 if (file->String().BeginsWith("\\\\"))
416 file->String().Prepend("\\\\");
417 file->String().ReplaceAll("\\","/");
418 const char *rfile = (const char*)file->String();
419 Printf("Attaching file %s as _file%d...", rfile, nfile);
420 snprintf(cmd, kMAXPATHLEN+50, "TFile *_file%d = TFile::Open(\"%s\")", nfile++, rfile);
421 } else {
422 Printf("Processing %s...", (const char*)file->String());
423 snprintf(cmd, kMAXPATHLEN+50, ".x %s", (const char*)file->String());
424 }
425 }
426 Getlinem(kCleanUp, 0);
427 Gl_histadd(cmd);
428 fNcmd++;
429
430 // The ProcessLine might throw an 'exception'. In this case,
431 // GetLinem(kInit,"Root >") is called and we are jump back
432 // to RETRY ... and we have to avoid the Getlinem(kInit, GetPrompt());
433 needGetlinemInit = kFALSE;
434 retval = ProcessLineNr("ROOT_cli_", cmd, &error);
436
437 // The ProcessLine has successfully completed and we need
438 // to call Getlinem(kInit, GetPrompt());
439 needGetlinemInit = kTRUE;
440
441 if (error != 0 || fCaughtSignal != -1) break;
442 }
443 } ENDTRY;
444
445 if (QuitOpt()) {
446 if (retrn) return;
447 if (error) {
448 retval = error;
449 } else if (fCaughtSignal != -1) {
450 retval = fCaughtSignal + 128;
451 }
452 // Bring retval into sensible range, 0..255.
453 if (retval < 0 || retval > 255)
454 retval = 255;
455 Terminate(retval);
456 }
457
458 // Allow end-of-file on the terminal to be noticed
459 // after we finish processing the command line input files.
461
463
464 if (needGetlinemInit) Getlinem(kInit, GetPrompt());
465 }
466
467 if (QuitOpt()) {
468 printf("\n");
469 if (retrn) return;
470 Terminate(fCaughtSignal != -1 ? fCaughtSignal + 128 : 0);
471 }
472
473 TApplication::Run(retrn);
474
475 // Reset to happiness.
476 fCaughtSignal = -1;
477
478 Getlinem(kCleanUp, 0);
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Print the ROOT logo on standard output.
483
485{
486 if (!lite) {
487 // Fancy formatting: the content of lines are format strings; their %s is
488 // replaced by spaces needed to make all lines as long as the longest line.
489 std::vector<TString> lines;
490 // Here, %%s results in %s after TString::Format():
491 lines.emplace_back(TString::Format("Welcome to ROOT %s%%shttps://root.cern",
492 gROOT->GetVersion()));
493 lines.emplace_back(TString::Format("(c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers%%s"));
494 lines.emplace_back(TString::Format("Built for %s on %s%%s", gSystem->GetBuildArch(), gROOT->GetGitDate()));
495 if (!strcmp(gROOT->GetGitBranch(), gROOT->GetGitCommit())) {
496 static const char *months[] = {"January","February","March","April","May",
497 "June","July","August","September","October",
498 "November","December"};
499 Int_t idatqq = gROOT->GetVersionDate();
500 Int_t iday = idatqq%100;
501 Int_t imonth = (idatqq/100)%100;
502 Int_t iyear = (idatqq/10000);
503
504 lines.emplace_back(TString::Format("From tag %s, %d %s %4d%%s",
505 gROOT->GetGitBranch(),
506 iday,months[imonth-1],iyear));
507 } else {
508 // If branch and commit are identical - e.g. "v5-34-18" - then we have
509 // a release build. Else specify the git hash this build was made from.
510 lines.emplace_back(TString::Format("From %s@%s %%s",
511 gROOT->GetGitBranch(),
512 gROOT->GetGitCommit()));
513 }
514 lines.emplace_back(TString::Format("With %s %%s",
516 lines.emplace_back(TString("Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'%s"));
517
518 // Find the longest line and its length:
519 auto itLongest = std::max_element(lines.begin(), lines.end(),
520 [](const TString& left, const TString& right) {
521 return left.Length() < right.Length(); });
522 Ssiz_t lenLongest = itLongest->Length();
523
524
525 Printf(" %s", TString('-', lenLongest).Data());
526 for (const auto& line: lines) {
527 // Print the line, expanded with the necessary spaces at %s, and
528 // surrounded by some ASCII art.
529 Printf(" | %s |",
530 TString::Format(line.Data(),
531 TString(' ', lenLongest - line.Length()).Data()).Data());
532 }
533 Printf(" %s\n", TString('-', lenLongest).Data());
534 }
535
536#ifdef R__UNIX
537 // Popdown X logo, only if started with -splash option
538 for (int i = 0; i < Argc(); i++)
539 if (!strcmp(Argv(i), "-splash"))
540 kill(getppid(), SIGUSR1);
541#endif
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// Get prompt from interpreter. Either "root [n]" or "end with '}'".
546
548{
549 char *s = gCling->GetPrompt();
550 if (s[0])
551 strlcpy(fPrompt, s, sizeof(fPrompt));
552 else
554
555 return fPrompt;
556}
557
558////////////////////////////////////////////////////////////////////////////////
559/// Set a new default prompt. It returns the previous prompt.
560/// The prompt may contain a %d which will be replaced by the commend
561/// number. The default prompt is "root [%d] ". The maximum length of
562/// the prompt is 55 characters. To set the prompt in an interactive
563/// session do:
564/// root [0] ((TRint*)gROOT->GetApplication())->SetPrompt("aap> ")
565/// aap>
566
567const char *TRint::SetPrompt(const char *newPrompt)
568{
569 static TString op;
570 op = fDefaultPrompt;
571
572 if (newPrompt && strlen(newPrompt) <= 55)
573 fDefaultPrompt = newPrompt;
574 else
575 Error("SetPrompt", "newPrompt too long (> 55 characters)");
576
577 return op.Data();
578}
579
580////////////////////////////////////////////////////////////////////////////////
581/// Handle input coming from terminal.
582
584{
585 static TStopwatch timer;
586 const char *line;
587
588 if ((line = Getlinem(kOneChar, 0))) {
589 if (line[0] == 0 && Gl_eof())
590 Terminate(0);
591
592 gVirtualX->SetKeyAutoRepeat(kTRUE);
593
594 Gl_histadd(line);
595
596 TString sline = line;
597
598 // strip off '\n' and leading and trailing blanks
599 sline = sline.Chop();
600 sline = sline.Strip(TString::kBoth);
601 ReturnPressed((char*)sline.Data());
602
604
605 if (!gCling->GetMore() && !sline.IsNull()) fNcmd++;
606
607 // prevent recursive calling of this input handler
609
610 if (gROOT->Timer()) timer.Start();
611
612 TTHREAD_TLS(Bool_t) added;
613 added = kFALSE; // reset on each call.
614
615 // This is needed when working with remote sessions
617
618 try {
619 TRY {
620 if (!sline.IsNull())
621 LineProcessed(sline);
622 ProcessLineNr("ROOT_prompt_", sline);
623 } CATCH(excode) {
624 // enable again input handler
626 added = kTRUE;
627 Throw(excode);
628 } ENDTRY;
629 }
630 // handle every exception
631 catch (std::exception& e) {
632 // enable again intput handler
633 if (!added) fInputHandler->Activate();
634
635 int err;
636 char *demangledType_c = TClassEdit::DemangleTypeIdName(typeid(e), err);
637 const char* demangledType = demangledType_c;
638 if (err) {
639 demangledType_c = nullptr;
640 demangledType = "<UNKNOWN>";
641 }
642 Error("HandleTermInput()", "%s caught: %s", demangledType, e.what());
643 free(demangledType_c);
644 }
645 catch (...) {
646 // enable again intput handler
647 if (!added) fInputHandler->Activate();
648 Error("HandleTermInput()", "Exception caught!");
649 }
650
651 if (gROOT->Timer()) timer.Print("u");
652
653 // enable again intput handler
655
656 if (!sline.BeginsWith(".reset"))
658
659 gTabCom->ClearAll();
660 Getlinem(kInit, GetPrompt());
661 }
662 return kTRUE;
663}
664
665////////////////////////////////////////////////////////////////////////////////
666/// Handle signals (kSigBus, kSigSegmentationViolation,
667/// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
668/// Specific TApplication implementations may want something different here.
669
671{
672 fCaughtSignal = sig;
673 if (TROOT::Initialized()) {
674 if (gException) {
675 Getlinem(kCleanUp, 0);
676 Getlinem(kInit, "Root > ");
677 }
678 }
680}
681
682////////////////////////////////////////////////////////////////////////////////
683/// Terminate the application. Reset the terminal to sane mode and call
684/// the logoff macro defined via Rint.Logoff environment variable.
685
687{
688 Getlinem(kCleanUp, 0);
689
690 if (ReturnFromRun()) {
691 gSystem->ExitLoop();
692 } else {
693 delete gTabCom;
694 gTabCom = 0;
695
696 //Execute logoff macro
697 const char *logoff;
698 logoff = gEnv->GetValue("Rint.Logoff", (char*)0);
699 if (logoff && !NoLogOpt()) {
700 char *mac = gSystem->Which(TROOT::GetMacroPath(), logoff, kReadPermission);
701 if (mac)
702 ProcessFile(logoff);
703 delete [] mac;
704 }
705
707 }
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Set console mode:
712///
713/// mode = kTRUE - echo input symbols
714/// mode = kFALSE - noecho input symbols
715
717{
718 Gl_config("noecho", mode ? 0 : 1);
719}
720
721////////////////////////////////////////////////////////////////////////////////
722/// Process the content of a line starting with ".R" (already stripped-off)
723/// The format is
724/// [user@]host[:dir] [-l user] [-d dbg] [script]
725/// The variable 'dir' is the remote directory to be used as working dir.
726/// The username can be specified in two ways, "-l" having the priority
727/// (as in ssh).
728/// A 'dbg' value > 0 gives increasing verbosity.
729/// The last argument 'script' allows to specify an alternative script to
730/// be executed remotely to startup the session.
731
733{
735
736 if (ret == 1) {
737 if (fAppRemote) {
738 TString prompt; prompt.Form("%s:root [%%d] ", fAppRemote->ApplicationName());
739 SetPrompt(prompt);
740 } else {
741 SetPrompt("root [%d] ");
742 }
743 }
744
745 return ret;
746}
747
748
749////////////////////////////////////////////////////////////////////////////////
750/// Calls ProcessLine() possibly prepending a #line directive for
751/// better diagnostics. Must be called after fNcmd has been increased for
752/// the next line.
753
754Longptr_t TRint::ProcessLineNr(const char* filestem, const char *line, Int_t *error /*= 0*/)
755{
756 Int_t err;
757 if (!error)
758 error = &err;
759 if (line && line[0] != '.') {
760 TString input;
762 input += TString::Format("#line 1 \"%s%d\"\n", filestem, fNcmd - 1);
763 input += line;
764 int res = ProcessLine(input, kFALSE, error);
765 if (*error == TInterpreter::kProcessing) {
768 SetPrompt("root (cont'ed, cancel with .@) [%d]");
769 } else if (fNonContinuePrompt.Length()) {
772 }
774 auto lastNonSpace = sv.find_last_not_of(" \t");
775 fBackslashContinue = (lastNonSpace != std::string_view::npos
776 && sv[lastNonSpace] == '\\');
777 return res;
778 }
779 if (line && line[0] == '.' && line[1] == '@') {
780 ProcessLine(line, kFALSE, error);
781 SetPrompt("root [%d] ");
782 }
783 return ProcessLine(line, kFALSE, error);
784}
785
786
787////////////////////////////////////////////////////////////////////////////////
788/// Forward tab completion request to our TTabCom::Hook().
789
790Int_t TRint::TabCompletionHook(char *buf, int *pLoc, std::ostream& out)
791{
792 if (gTabCom)
793 return gTabCom->Hook(buf, pLoc, out);
794
795 return -1;
796}
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:45
long Longptr_t
Definition: RtypesCore.h:82
int Ssiz_t
Definition: RtypesCore.h:67
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
@ kMAXPATHLEN
Definition: Rtypes.h:60
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:59
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:95
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:209
#define CATCH(n)
Definition: TException.h:63
#define ENDTRY
Definition: TException.h:69
#define RETRY
Definition: TException.h:49
#define TRY
Definition: TException.h:56
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:74
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.
Definition: TException.cxx:27
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:563
#define gInterpreter
Definition: TInterpreter.h:562
#define gROOT
Definition: TROOT.h:404
static void ResetTermAtExit()
Restore terminal to non-raw mode.
Definition: TRint.cxx:73
static Int_t Key_Pressed(Int_t key)
Definition: TRint.cxx:55
static Int_t BeepHook()
Definition: TRint.cxx:63
char * Form(const char *fmt,...)
void Printf(const char *fmt,...)
@ kSigInterrupt
@ kReadPermission
Definition: TSystem.h:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
R__EXTERN TTabCom * gTabCom
Definition: TTabCom.h:229
#define gVirtualX
Definition: TVirtualX.h:338
#define free
Definition: civetweb.c:1539
#define snprintf
Definition: civetweb.c:1540
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:39
virtual void KeyPressed(Int_t key)
virtual void LineProcessed(const char *line)
virtual Bool_t HandleTermInput()
Definition: TApplication.h:111
TObjArray * InputFiles() const
Definition: TApplication.h:141
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual Longptr_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Bool_t ReturnFromRun() const
Definition: TApplication.h:148
virtual Longptr_t ProcessRemote(const char *line, Int_t *error=0)
Process the content of a line starting with ".R" (already stripped-off) The format is.
virtual void ReturnPressed(char *text)
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Terminate(Int_t status=0)
char ** Argv() const
Definition: TApplication.h:136
virtual const char * ApplicationName() const
Definition: TApplication.h:123
virtual Longptr_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Bool_t NoLogOpt() const
Definition: TApplication.h:138
Bool_t NoLogoOpt() const
Definition: TApplication.h:139
const char * WorkingDirectory() const
Definition: TApplication.h:142
Bool_t QuitOpt() const
Definition: TApplication.h:140
Int_t Argc() const
Definition: TApplication.h:135
virtual void Run(Bool_t retrn=kFALSE)
TApplication * fAppRemote
Definition: TApplication.h:80
void SetSignalHandler(TSignalHandler *sh)
Definition: TApplication.h:90
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:491
virtual void Remove()
Remove file event handler from system file handler list.
virtual void Add()
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
Bool_t Notify()
TRint interrupt handler.
Definition: TRint.cxx:91
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Collectable string class.
Definition: TObjString.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2715
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2818
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2953
Definition: TRint.h:31
virtual void HandleException(Int_t sig)
Handle signals (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingException)...
Definition: TRint.cxx:670
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop.
Definition: TRint.cxx:356
Bool_t fInterrupt
Definition: TRint.h:38
Longptr_t ProcessLineNr(const char *filestem, const char *line, Int_t *error=nullptr)
Calls ProcessLine() possibly prepending a line directive for better diagnostics.
Definition: TRint.cxx:754
virtual void Terminate(int status)
Terminate the application.
Definition: TRint.cxx:686
virtual const char * SetPrompt(const char *newPrompt)
Set a new default prompt.
Definition: TRint.cxx:567
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 [user@]host[:di...
Definition: TRint.cxx:732
char fPrompt[64]
Definition: TRint.h:37
virtual char * GetPrompt()
Get prompt from interpreter. Either "root [n]" or "end with '}'".
Definition: TRint.cxx:547
virtual ~TRint()
Destructor.
Definition: TRint.cxx:288
virtual void PrintLogo(Bool_t lite=kFALSE)
Print the ROOT logo on standard output.
Definition: TRint.cxx:484
void ExecLogon()
Execute logon macro's.
Definition: TRint.cxx:313
virtual void SetEchoMode(Bool_t mode)
Set console mode:
Definition: TRint.cxx:716
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
Forward tab completion request to our TTabCom::Hook().
Definition: TRint.cxx:790
Bool_t fBackslashContinue
Definition: TRint.h:41
TString fDefaultPrompt
Definition: TRint.h:35
TString fNonContinuePrompt
Definition: TRint.h:36
virtual Bool_t HandleTermInput()
Handle input coming from terminal.
Definition: TRint.cxx:583
Int_t fCaughtSignal
Definition: TRint.h:39
Int_t fNcmd
Definition: TRint.h:34
TRint(const TRint &)=delete
TFileHandler * fInputHandler
Definition: TRint.h:40
virtual void Add()
Add signal handler to system signal handler list.
ESignals GetSignal() const
Stopwatch class.
Definition: TStopwatch.h:28
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:219
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1131
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1201
const char * Data() const
Definition: TString.h:369
TString & Chop()
Definition: TString.h:679
@ kBoth
Definition: TString.h:267
@ kIgnoreCase
Definition: TString.h:268
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:615
Bool_t IsNull() const
Definition: TString.h:407
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:2336
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2314
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
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:327
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1663
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1071
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1855
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:1296
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:395
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:863
virtual const char * GetBuildCompilerVersionStr() const
Return the build compiler version identifier string.
Definition: TSystem.cxx:3886
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:872
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1546
virtual const char * GetBuildArch() const
Return the build architecture.
Definition: TSystem.cxx:3862
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition: TSystem.cxx:888
Int_t Hook(char *buf, int *pLoc, std::ostream &out)
[private]
Definition: TTabCom.cxx:1566
void ClearAll()
clears all lists except for user names and system include files.
Definition: TTabCom.cxx:319
TTermInputHandler(Int_t fd)
Definition: TRint.cxx:122
Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Definition: TRint.cxx:124
Bool_t Notify()
Notify implementation. Call the application interupt handler.
Definition: TRint.cxx:130
TLine * line
const Int_t n
Definition: legend1.C:16
basic_string_view< char > string_view
R__EXTERN void * gMmallocDesc
Definition: TStorage.h:149
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
static constexpr double s
Definition: file.py:1