ROOT  6.06/08
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 
90 Bool_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)
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 
126 Bool_t TTermInputHandler::Notify()
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;
278  fInputHandler->Remove();
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  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
306  ProcessFile(s);
307  }
308  delete [] s;
311  ProcessFile(s);
312  }
313  delete [] s;
314  // avoid executing ~/.rootlogon.C twice
315  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
317  ProcessFile(name);
318  }
319 
320  // execute also the logon macro specified by "Rint.Logon"
321  const char *logon = gEnv->GetValue("Rint.Logon", (char*)0);
322  if (logon) {
323  char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
324  if (mac)
325  ProcessFile(logon);
326  delete [] mac;
327  }
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// Main application eventloop. First process files given on the command
332 /// line and then go into the main application event loop, unless the -q
333 /// command line option was specfied in which case the program terminates.
334 /// When retrun is true this method returns even when -q was specified.
335 ///
336 /// When QuitOpt is true and retrn is false, terminate the application with
337 /// an error code equal to either the ProcessLine error (if any) or the
338 /// return value of the command casted to a long.
339 
340 void TRint::Run(Bool_t retrn)
341 {
342  Getlinem(kInit, GetPrompt());
343 
344  Long_t retval = 0;
345  Int_t error = 0;
346  volatile Bool_t needGetlinemInit = kFALSE;
347 
348  if (strlen(WorkingDirectory())) {
349  // if directory specified as argument make it the working directory
350  gSystem->ChangeDirectory(WorkingDirectory());
351  TSystemDirectory *workdir = new TSystemDirectory("workdir", gSystem->WorkingDirectory());
352  TObject *w = gROOT->GetListOfBrowsables()->FindObject("workdir");
353  TObjLink *lnk = gROOT->GetListOfBrowsables()->FirstLink();
354  while (lnk) {
355  if (lnk->GetObject() == w) {
356  lnk->SetObject(workdir);
358  break;
359  }
360  lnk = lnk->Next();
361  }
362  delete w;
363  }
364 
365  // Process shell command line input files
366  if (InputFiles()) {
367  // Make sure that calls into the event loop
368  // ignore end-of-file on the terminal.
369  fInputHandler->DeActivate();
370  TIter next(InputFiles());
371  RETRY {
372  retval = 0; error = 0;
373  Int_t nfile = 0;
374  TObjString *file;
375  while ((file = (TObjString *)next())) {
376  char cmd[kMAXPATHLEN+50];
377  if (!fNcmd)
378  printf("\n");
379  Bool_t rootfile = kFALSE;
380 
381  if (file->TestBit(kExpression)) {
382  snprintf(cmd, kMAXPATHLEN+50, "%s", (const char*)file->String());
383  } else {
384  if (file->String().EndsWith(".root") || file->String().BeginsWith("file:")) {
385  rootfile = kTRUE;
386  } else {
387  rootfile = gROOT->IsRootFile(file->String());
388  }
389  if (rootfile) {
390  // special trick to be able to open files using UNC path names
391  if (file->String().BeginsWith("\\\\"))
392  file->String().Prepend("\\\\");
393  file->String().ReplaceAll("\\","/");
394  const char *rfile = (const char*)file->String();
395  Printf("Attaching file %s as _file%d...", rfile, nfile);
396  snprintf(cmd, kMAXPATHLEN+50, "TFile *_file%d = TFile::Open(\"%s\")", nfile++, rfile);
397  } else {
398  Printf("Processing %s...", (const char*)file->String());
399  snprintf(cmd, kMAXPATHLEN+50, ".x %s", (const char*)file->String());
400  }
401  }
402  Getlinem(kCleanUp, 0);
403  Gl_histadd(cmd);
404  fNcmd++;
405 
406  // The ProcessLine might throw an 'exception'. In this case,
407  // GetLinem(kInit,"Root >") is called and we are jump back
408  // to RETRY ... and we have to avoid the Getlinem(kInit, GetPrompt());
409  needGetlinemInit = kFALSE;
410  retval = ProcessLineNr("ROOT_cli_", cmd, &error);
412 
413  // The ProcessLine has successfully completed and we need
414  // to call Getlinem(kInit, GetPrompt());
415  needGetlinemInit = kTRUE;
416 
417  if (error != 0 || fCaughtException) break;
418  }
419  } ENDTRY;
420 
421  if (QuitOpt()) {
422  if (retrn) return;
423  if (error) {
424  retval = error;
425  } else if (fCaughtException) {
426  retval = 1;
427  }
428  // Bring retval into sensible range, 0..125.
429  if (retval < 0) retval = 1;
430  else if (retval > 125) retval = 1;
431  Terminate(retval);
432  }
433 
434  // Allow end-of-file on the terminal to be noticed
435  // after we finish processing the command line input files.
436  fInputHandler->Activate();
437 
438  ClearInputFiles();
439 
440  if (needGetlinemInit) Getlinem(kInit, GetPrompt());
441  }
442 
443  if (QuitOpt()) {
444  printf("\n");
445  if (retrn) return;
446  Terminate(fCaughtException ? 1 : 0);
447  }
448 
449  TApplication::Run(retrn);
450 
451  Getlinem(kCleanUp, 0);
452 }
453 
454 ////////////////////////////////////////////////////////////////////////////////
455 /// Print the ROOT logo on standard output.
456 
458 {
459  if (!lite) {
460  // Fancy formatting: the content of lines are format strings; their %s is
461  // replaced by spaces needed to make all lines as long as the longest line.
462  std::vector<TString> lines;
463  // Here, %%s results in %s after TString::Format():
464  lines.emplace_back(TString::Format("Welcome to ROOT %s%%shttp://root.cern.ch",
465  gROOT->GetVersion()));
466  lines.emplace_back(TString::Format("%%s(c) 1995-2016, The ROOT Team"));
467  lines.emplace_back(TString::Format("Built for %s%%s", gSystem->GetBuildArch()));
468  if (!strcmp(gROOT->GetGitBranch(), gROOT->GetGitCommit())) {
469  static const char *months[] = {"January","February","March","April","May",
470  "June","July","August","September","October",
471  "November","December"};
472  Int_t idatqq = gROOT->GetVersionDate();
473  Int_t iday = idatqq%100;
474  Int_t imonth = (idatqq/100)%100;
475  Int_t iyear = (idatqq/10000);
476 
477  lines.emplace_back(TString::Format("From tag %s, %d %s %4d%%s",
478  gROOT->GetGitBranch(),
479  iday,months[imonth-1],iyear));
480  } else {
481  // If branch and commit are identical - e.g. "v5-34-18" - then we have
482  // a release build. Else specify the git hash this build was made from.
483  lines.emplace_back(TString::Format("From %s@%s, %s%%s",
484  gROOT->GetGitBranch(),
485  gROOT->GetGitCommit(), gROOT->GetGitDate()));
486  }
487  lines.emplace_back(TString("Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'%s"));
488 
489  // Find the longest line and its length:
490  auto itLongest = std::max_element(lines.begin(), lines.end(),
491  [](const TString& left, const TString& right) {
492  return left.Length() < right.Length(); });
493  Ssiz_t lenLongest = itLongest->Length();
494 
495 
496  Printf(" %s", TString('-', lenLongest).Data());
497  for (const auto& line: lines) {
498  // Print the line, expanded with the necessary spaces at %s, and
499  // surrounded by some ASCII art.
500  Printf(" | %s |",
501  TString::Format(line.Data(),
502  TString(' ', lenLongest - line.Length()).Data()).Data());
503  }
504  Printf(" %s\n", TString('-', lenLongest).Data());
505  }
506 
507 #ifdef R__UNIX
508  // Popdown X logo, only if started with -splash option
509  for (int i = 0; i < Argc(); i++)
510  if (!strcmp(Argv(i), "-splash"))
511  kill(getppid(), SIGUSR1);
512 #endif
513 }
514 
515 ////////////////////////////////////////////////////////////////////////////////
516 /// Get prompt from interpreter. Either "root [n]" or "end with '}'".
517 
519 {
520  char *s = gCling->GetPrompt();
521  if (s[0])
522  strlcpy(fPrompt, s, sizeof(fPrompt));
523  else
524  snprintf(fPrompt, sizeof(fPrompt), fDefaultPrompt.Data(), fNcmd);
525 
526  return fPrompt;
527 }
528 
529 ////////////////////////////////////////////////////////////////////////////////
530 /// Set a new default prompt. It returns the previous prompt.
531 /// The prompt may contain a %d which will be replaced by the commend
532 /// number. The default prompt is "root [%d] ". The maximum length of
533 /// the prompt is 55 characters. To set the prompt in an interactive
534 /// session do:
535 /// root [0] ((TRint*)gROOT->GetApplication())->SetPrompt("aap> ")
536 /// aap>
537 
538 const char *TRint::SetPrompt(const char *newPrompt)
539 {
540  static TString op = fDefaultPrompt;
541 
542  if (newPrompt && strlen(newPrompt) <= 55)
543  fDefaultPrompt = newPrompt;
544  else
545  Error("SetPrompt", "newPrompt too long (> 55 characters)");
546 
547  return op.Data();
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////
551 /// Handle input coming from terminal.
552 
554 {
555  static TStopwatch timer;
556  const char *line;
557 
558  if ((line = Getlinem(kOneChar, 0))) {
559  if (line[0] == 0 && Gl_eof())
560  Terminate(0);
561 
562  gVirtualX->SetKeyAutoRepeat(kTRUE);
563 
564  Gl_histadd(line);
565 
566  TString sline = line;
567 
568  // strip off '\n' and leading and trailing blanks
569  sline = sline.Chop();
570  sline = sline.Strip(TString::kBoth);
571  ReturnPressed((char*)sline.Data());
572 
573  fInterrupt = kFALSE;
574 
575  if (!gCling->GetMore() && !sline.IsNull()) fNcmd++;
576 
577  // prevent recursive calling of this input handler
578  fInputHandler->DeActivate();
579 
580  if (gROOT->Timer()) timer.Start();
581 
582 #ifdef R__EH
583  Bool_t added = kFALSE;
584 #endif
585 
586  // This is needed when working with remote sessions
587  SetBit(kProcessRemotely);
588 
589 #ifdef R__EH
590  try {
591 #endif
592  TRY {
593  if (!sline.IsNull())
594  LineProcessed(sline);
595  ProcessLineNr("ROOT_prompt_", sline);
596  } CATCH(excode) {
597  // enable again input handler
598  fInputHandler->Activate();
599 #ifdef R__EH
600  added = kTRUE;
601 #endif
602  Throw(excode);
603  } ENDTRY;
604 #ifdef R__EH
605  }
606  // handle every exception
607  catch (...) {
608  // enable again intput handler
609  if (!added) fInputHandler->Activate();
610  throw;
611  }
612 #endif
613 
614  if (gROOT->Timer()) timer.Print("u");
615 
616  // enable again intput handler
617  fInputHandler->Activate();
618 
619  if (!sline.BeginsWith(".reset"))
621 
622  gTabCom->ClearAll();
623  Getlinem(kInit, GetPrompt());
624  }
625  return kTRUE;
626 }
627 
628 ////////////////////////////////////////////////////////////////////////////////
629 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
630 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
631 /// Specific TApplication implementations may want something different here.
632 
634 {
635  fCaughtException = kTRUE;
636  if (TROOT::Initialized()) {
637  if (gException) {
638  Getlinem(kCleanUp, 0);
639  Getlinem(kInit, "Root > ");
640  }
641  }
643 }
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Terminate the application. Reset the terminal to sane mode and call
647 /// the logoff macro defined via Rint.Logoff environment variable.
648 
650 {
651  Getlinem(kCleanUp, 0);
652 
653  if (ReturnFromRun()) {
654  gSystem->ExitLoop();
655  } else {
656  delete gTabCom;
657  gTabCom = 0;
658 
659  //Execute logoff macro
660  const char *logoff;
661  logoff = gEnv->GetValue("Rint.Logoff", (char*)0);
662  if (logoff && !NoLogOpt()) {
663  char *mac = gSystem->Which(TROOT::GetMacroPath(), logoff, kReadPermission);
664  if (mac)
665  ProcessFile(logoff);
666  delete [] mac;
667  }
668 
669  TApplication::Terminate(status);
670  }
671 }
672 
673 ////////////////////////////////////////////////////////////////////////////////
674 /// Set console mode:
675 ///
676 /// mode = kTRUE - echo input symbols
677 /// mode = kFALSE - noecho input symbols
678 
680 {
681  Gl_config("noecho", mode ? 0 : 1);
682 }
683 
684 ////////////////////////////////////////////////////////////////////////////////
685 /// Process the content of a line starting with ".R" (already stripped-off)
686 /// The format is
687 /// [user@]host[:dir] [-l user] [-d dbg] [script]
688 /// The variable 'dir' is the remote directory to be used as working dir.
689 /// The username can be specified in two ways, "-l" having the priority
690 /// (as in ssh).
691 /// A 'dbg' value > 0 gives increasing verbosity.
692 /// The last argument 'script' allows to specify an alternative script to
693 /// be executed remotely to startup the session.
694 
696 {
698 
699  if (ret == 1) {
700  if (fAppRemote) {
701  TString prompt; prompt.Form("%s:root [%%d] ", fAppRemote->ApplicationName());
702  SetPrompt(prompt);
703  } else {
704  SetPrompt("root [%d] ");
705  }
706  }
707 
708  return ret;
709 }
710 
711 
712 ////////////////////////////////////////////////////////////////////////////////
713 /// Calls ProcessLine() possibly prepending a #line directive for
714 /// better diagnostics. Must be called after fNcmd has been increased for
715 /// the next line.
716 
717 Long_t TRint::ProcessLineNr(const char* filestem, const char *line, Int_t *error /*= 0*/)
718 {
719  Int_t err;
720  if (!error)
721  error = &err;
722  if (line && line[0] != '.') {
723  TString lineWithNr = TString::Format("#line 1 \"%s%d\"\n", filestem, fNcmd - 1);
724  int res = ProcessLine(lineWithNr + line, kFALSE, error);
725  if (*error == TInterpreter::kProcessing)
726  SetPrompt("root (cont'ed, cancel with .@) [%d]");
727  else
728  SetPrompt("root [%d] ");
729  return res;
730  }
731  if (line && line[0] == '.' && line[1] == '@') {
732  ProcessLine(line, kFALSE, error);
733  SetPrompt("root [%d] ");
734  }
735  return ProcessLine(line, kFALSE, error);
736 }
737 
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 /// Forward tab completion request to our TTabCom::Hook().
741 
742 Int_t TRint::TabCompletionHook(char *buf, int *pLoc, std::ostream& out)
743 {
744  if (gTabCom)
745  return gTabCom->Hook(buf, pLoc, out);
746 
747  return -1;
748 }
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:1264
virtual void Terminate(int status)
Terminate the application.
Definition: TRint.cxx:649
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:217
TLine * line
Collectable string class.
Definition: TObjString.h:32
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:97
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual Bool_t HandleTermInput()
Handle input coming from terminal.
Definition: TRint.cxx:553
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:881
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:856
#define gROOT
Definition: TROOT.h:352
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1817
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:717
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 char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1510
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...
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...
virtual void SetGetline(const char *(*getlineFunc)(const char *prompt), void(*histaddFunc)(const char *line))=0
virtual Bool_t HandleTermInput()
Definition: TApplication.h:117
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2395
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&#39;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:679
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2450
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:1626
std::vector< std::vector< double > > Data
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
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
void Error(const char *location, const char *msgfmt,...)
void ClearAll()
clears all lists except for user names and system include files.
Definition: TTabCom.cxx:314
virtual const char * SetPrompt(const char *newPrompt)
Set a new default prompt.
Definition: TRint.cxx:538
Describes an Operating System directory for the browser.
#define CATCH(n)
Definition: TException.h:73
virtual const char * GetBuildArch() const
Return the build architecture.
Definition: TSystem.cxx:3670
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
Forward tab completion request to our TTabCom::Hook().
Definition: TRint.cxx:742
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:480
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
Definition: TRint.cxx:633
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:390
ESignals GetSignal() const
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
This class is a ROOT utility to help benchmarking applications.
Definition: TBenchmark.h:33
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop.
Definition: TRint.cxx:340
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:457
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
#define ClassImp(name)
Definition: Rtypes.h:279
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:695
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
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
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2601
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
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 Reset()=0
Bool_t IsNull() const
Definition: TString.h:387
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 &#39;}&#39;".
Definition: TRint.cxx:518
virtual ~TRint()
Destructor.
Definition: TRint.cxx:272
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
R__EXTERN void * gMmallocDesc
Definition: TRint.cxx:50
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
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
TString & Chop()
Definition: TString.h:622
const char * Data() const
Definition: TString.h:349
Stopwatch class.
Definition: TStopwatch.h:30