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