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