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