//*CMZ :  2.23/08 29/10/99  10.05.01  by  Rene Brun
//*CMZ :  2.23/07 24/10/99  18.14.19  by  Fons Rademakers
//*CMZ :  2.23/06 21/10/99  08.20.45  by  Rene Brun
//*CMZ :  2.23/05 20/10/99  18.58.25  by  Rene Brun
//*CMZ :  2.23/04 11/10/99  19.21.26  by  Fons Rademakers
//*CMZ :  2.23/03 24/09/99  18.20.05  by  Rene Brun
//*CMZ :  2.23/02 07/09/99  16.47.26  by  Rene Brun
//*CMZ :  2.23/01 31/08/99  12.31.47  by  Fons Rademakers
//*CMZ :  2.23/00 07/08/99  18.08.51  by  Fons Rademakers
//*-- Author :    Rene Brun   17/02/95

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun and Fons Rademakers.                               *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/AA_LICENSE.                      *
 * For the list of contributors see $ROOTSYS/AA_CREDITS.                 *
 *************************************************************************/
//*KEND.

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Rint                                                                 //
//                                                                      //
// Rint is the ROOT Interactive Interface. It allows interactive access //
// to the ROOT system via the CINT C/C++ interpreter.                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

//*KEEP,TROOT.
#include "TROOT.h"
//*KEEP,TClass.
#include "TClass.h"
//*KEEP,TVirtualX.
#include "TVirtualX.h"
//*KEEP,Getline.
#include "Getline.h"
//*KEEP,TStyle.
#include "TStyle.h"
//*KEEP,TObjectTable.
#include "TObjectTable.h"
//*KEEP,TClassTable.
#include "TClassTable.h"
//*KEEP,TStopwatch.
#include "TStopwatch.h"
//*KEEP,TCanvas.
#include "TCanvas.h"
//*KEEP,TBenchmark,T=C++.
#include "TBenchmark.h"
//*KEEP,TRint.
#include "TRint.h"
//*KEEP,TSystem.
#include "TSystem.h"
//*KEEP,TEnv.
#include "TEnv.h"
//*KEEP,TSysEvtHandler.
#include "TSysEvtHandler.h"
//*KEEP,TError.
#include "TError.h"
//*KEEP,TException.
#include "TException.h"
//*KEEP,TInterpreter, T=C++.
#include "TInterpreter.h"
//*KEEP,TObjArray.
#include "TObjArray.h"
//*KEEP,TObjString.
#include "TObjString.h"
//*KEEP,TFile.
#include "TFile.h"
//*KEEP,TMapFile.
#include "TMapFile.h"
//*KEEP,TTabCom,T=C++.
#include "TTabCom.h"
//*KEND.

#ifdef R__UNIX
#include <signal.h>

extern "C" {
   extern int G__get_security_error();
   extern int G__genericerror(char* msg);
}
#endif



//----- Interrupt signal handler -----------------------------------------------
//______________________________________________________________________________
class TInterruptHandler : public TSignalHandler {
public:
   TInterruptHandler() : TSignalHandler(kSigInterrupt, kFALSE) { }
   Bool_t  Notify();
};

//______________________________________________________________________________
Bool_t TInterruptHandler::Notify()
{
   // TRint interrupt handler.

   if (fDelay) {
      fDelay++;
      return kTRUE;
   }

   // make sure we use the sbrk heap (in case of mapped files)
   gMmallocDesc = 0;
//  go via the interpreter???
//   if (gProof) gProof->Interrupt(TProof::kHardInterrupt);

   if (!G__get_security_error())
      G__genericerror("n *** Break *** keyboard interrupt");
   else {
      Printf("n *** Break *** keyboard interrupt");
      if (TROOT::Initialized()) {
         Getlinem(kInit, "Root > ");
         gInterpreter->RewindDictionary();
         Throw(GetSignal());
      }
   }
   return kTRUE;
}

//----- Terminal Input file handler --------------------------------------------
//______________________________________________________________________________
class TTermInputHandler : public TFileHandler {
public:
   TTermInputHandler(int fd) : TFileHandler(fd, 1) { }
   Bool_t Notify();
   Bool_t ReadNotify() { return Notify(); }
};

//______________________________________________________________________________
Bool_t TTermInputHandler::Notify()
{
   gApplication->HandleTermInput();
   return kTRUE;
}


ClassImp(TRint)

//______________________________________________________________________________
 TRint::TRint(char *appClassName, int *argc, char **argv, void *options, int numOptions)
       : TApplication(appClassName, argc, argv, options, numOptions)
{
   // Create an application environment. The TRint environment provides an
   // interface to the WM manager functionality and eventloop via inheritance
   // of TApplication and in addition provides interactive access to
   // the CINT C++ interpreter via the command line.

   fNcmd          = 0;
   fDefaultPrompt = "root [%d] ";
   fInterrupt     = kFALSE;

   gBenchmark = new TBenchmark();

   PrintLogo();

   // Everybody expects iostream to be available, so load it...
#ifndef WIN32
   ProcessLine("#include <iostream>");
#endif
   // The following libs are also useful to have,
   // make sure they are loaded...
   gROOT->LoadClass("TGeometry",   "Graf3d");
   gROOT->LoadClass("TTree",       "Tree");
   gROOT->LoadClass("TMatrix",     "Matrix");
   gROOT->LoadClass("TMinuit",     "Minuit");
   gROOT->LoadClass("TPostScript", "Postscript");
   gROOT->LoadClass("TCanvas",     "Gpad");
   gROOT->LoadClass("THtml",       "Html");

   // Load user functions
   const char *logon;
   logon = gEnv->GetValue("Rint.Load", (char*)0);
   if (logon) {
      char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
      if (mac)
         ProcessLine(Form(".L %s",logon));
      delete [] mac;
   }

   // Execute logon macro
   logon = gEnv->GetValue("Rint.Logon", (char*)0);
   if (logon && !NoLogOpt()) {
      char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
      if (mac)
         ProcessFile(logon);
      delete [] mac;
   }

   gInterpreter->SaveContext();
   gInterpreter->SaveGlobalsContext();

   // Install interrupt and terminal input handlers
   TInterruptHandler *ih = new TInterruptHandler();
   gSystem->AddSignalHandler(ih);
   SetSignalHandler(ih);

   TTermInputHandler *th = new TTermInputHandler(0);
   gSystem->AddFileHandler(th);

   // Goto into raw terminal input mode
   char defhist[128];
#ifndef R__VMS
   sprintf(defhist, "%s/.root_hist", gSystem->Getenv("HOME"));
#else
   sprintf(defhist, "%s.root_hist", gSystem->Getenv("HOME"));
#endif
   logon = gEnv->GetValue("Rint.History", defhist);
   Gl_histinit((char *)logon);
   Gl_windowchanged();

   // Setup for tab completion
   gTabCom = new TTabCom;
}

//______________________________________________________________________________
 TRint::~TRint()
{

}

//______________________________________________________________________________
 void TRint::Run(Bool_t retrn)
{
   // Main application eventloop. First process files given on the command
   // line and then go into the main application event loop.

   Getlinem(kInit, GetPrompt());

   // Process shell command line input files
   if (InputFiles()) {
      TObjString *file;
      TIter next(InputFiles());
      RETRY {
         while ((file = (TObjString *)next())) {
            char cmd[256];
            if (file->String().EndsWith(".root")) {
               const char *rfile = (const char*)file->String();
               Printf("nAttaching file %s...", rfile);
               char *base = StrDup(gSystem->BaseName(rfile));
               char *s = strchr(base, '.'); *s = 0;
               sprintf(cmd, "TFile *%s = TFile::Open("%s")", base, rfile);
               delete [] base;
            } else {
               Printf("nProcessing %s...", (const char*)file->String());
               sprintf(cmd, ".x %s", (const char*)file->String());
            }
            Getlinem(kCleanUp, 0);
            Gl_histadd(cmd);
            fNcmd++;
            ProcessLine(cmd);
         }
      } ENDTRY;

      if (QuitOpt())
         Terminate(0);

      ClearInputFiles();

      Getlinem(kInit, GetPrompt());
   }

   TApplication::Run(retrn);

   Getlinem(kCleanUp, 0);
}

//______________________________________________________________________________
 void TRint::PrintLogo()
{
   // Print the ROOT logo on standard output.

   Int_t iday,imonth,iyear,mille;
   static const char *months[] = {"January","February","March","April","May",
                                  "June","July","August","September","October",
                                  "November","December"};
   const char *root_version = gROOT->GetVersion();
   Int_t idatqq = gROOT->GetVersionDate();
   iday   = idatqq%100;
   imonth = (idatqq/100)%100;
   iyear  = (idatqq/10000);
   if (iyear < 90) mille = 2000 + iyear;
   else            mille = 1900 + iyear;
   char *root_date = Form("%d %s %4d",iday,months[imonth-1],mille);

   Printf("  *******************************************");
   Printf("  *                                         *");
   Printf("  *        W E L C O M E  to  R O O T       *");
   Printf("  *                                         *");
   Printf("  *   Version%10s %17s   *",root_version,root_date);
// Printf("  *            Development version          *");
   Printf("  *                                         *");
   Printf("  *  You are welcome to visit our Web site  *");
   Printf("  *          http://root.cern.ch            *");
   Printf("  *                                         *");
   Printf("  *******************************************");

#ifdef R__UNIX
   if (!strcmp(gVirtualX->GetName(), "X11TTF"))
      Printf("\nFreeType Engine v1.1 used to render TrueType fonts.");
#endif

   gInterpreter->PrintIntro();

#ifdef R__UNIX
   // Popup down X logo, only if started with -p option
   for (int i = 0; i < Argc(); i++)
      if (!strcmp(Argv(i), "-p"))
         kill(getppid(), SIGUSR1);
#endif
}

//______________________________________________________________________________
 char *TRint::GetPrompt()
{
   // Get prompt from interpreter. Either "root [n]" or "end with '}'".

   char *s = gInterpreter->GetPrompt();
   if (s[0])
      strcpy(fPrompt, s);
   else
      sprintf(fPrompt, fDefaultPrompt, fNcmd);

   return fPrompt;
}

//______________________________________________________________________________
 const char *TRint::SetPrompt(const char *newPrompt)
{
   // Set a new default prompt. It returns the previous prompt.
   // The prompt may contain a %d which will be replaced by the commend
   // number. The default prompt is "root [%d] ". The maximum length of
   // the prompt is 55 characters. To set the prompt in an interactive
   // session do:
   // root [0] ((TRint*)gROOT->GetApplication())->SetPrompt("aap> ")
   // aap>

   const char *op = fDefaultPrompt;

   if (strlen(newPrompt) <= 55)
      fDefaultPrompt = newPrompt;
   else
      Error("SetPrompt", "newPrompt too long (> 55 characters)");

   return op;
}

//______________________________________________________________________________
 void TRint::HandleTermInput()
{
   // Handle input coming from terminal.

   static TStopwatch timer;
   char *line;

   if ((line = Getlinem(kOneChar, 0))) {
      if (gROOT->Timer()) timer.Start();

      Gl_histadd(line);

      char *s = line;
      while (s && *s == ' ') s++;     // strip-off leading blanks
      s[strlen(s)-1] = '0';          // strip also 'n' off
      fInterrupt = kFALSE;

      if (!gInterpreter->GetMore() && strlen(s) != 0) fNcmd++;

      ProcessLine(s);

      if (strstr(s,".reset") != s)
          gInterpreter->EndOfLineAction();

      if (gROOT->Timer()) timer.Print();

      gTabCom->ClearAll();
      Getlinem(kInit, GetPrompt());
   }
}

//______________________________________________________________________________
 void TRint::Terminate(int status)
{
   // Terminate the application. Reset the terminal to sane mode and call
   // the logoff macro defined via Rint.Logoff environment variable.

   Getlinem(kCleanUp, 0);

   if (ReturnFromRun()) {
      gSystem->ExitLoop();
   } else {
      //Execute logoff macro
      const char *logoff;
      logoff = gEnv->GetValue("Rint.Logoff", (char*)0);
      if (logoff && !NoLogOpt()) {
         char *mac = gSystem->Which(TROOT::GetMacroPath(), logoff, kReadPermission);
         if (mac)
            ProcessFile(logoff);
         delete [] mac;
      }

      gSystem->Exit(status);
   }
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.