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