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