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