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