20 #include "RConfigure.h"
47 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
55 TList *TApplication::fgApplications = 0;
59 class TIdleTimer :
public TTimer {
78 static
void CallEndOfProcessCleanups()
82 gROOT->EndOfProcessCleanups();
89 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
91 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
112 void * ,
Int_t numOptions) :
113 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
115 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
139 Error(
"TApplication",
"only one instance of TApplication allowed");
145 ::Fatal(
"TApplication::TApplication",
"ROOT system not initialized");
148 ::Fatal(
"TApplication::TApplication",
"gSystem not initialized");
151 if (!hasRegisterAtExit) {
153 atexit(CallEndOfProcessCleanups);
154 hasRegisterAtExit =
kTRUE;
156 gROOT->SetName(appClassName);
159 if (argc && *argc > 0) {
164 for (
int i = 0; i <
fArgc; i++)
190 gROOT->SetLineHasBeenProcessed();
197 const char *ssystem =
gEnv->
GetValue(
"Root.TMemStat.system",
"gnubuiltin");
199 gROOT->ProcessLine(
Form(
"new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
205 gROOT->SetApplication(
this);
214 for (
int i = 0; i <
fArgc; i++)
232 gROOT->EndOfProcessCleanups();
261 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
262 gVirtualX =
new ROOT::iOS::TGIOS(
"TGIOS",
"VirtualX for iOS");
281 #if !defined(R__WIN32)
291 if ((h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX",
"x11ttf")))
293 Info(
"InitializeGraphics",
"no TTF support");
347 if (index >=
fArgc) {
348 Error(
"Argv",
"index (%d) >= number of arguments (%d)", index,
fArgc);
396 static char null[1] = {
"" };
408 for (i = 1; i < *argc; i++) {
409 if (!strcmp(argv[i],
"-?") || !strncmp(argv[i],
"-h", 2) ||
410 !strncmp(argv[i],
"--help", 6)) {
411 fprintf(stderr,
"Usage: %s [-l] [-b] [-n] [-q] [dir] [[file:]data.root] [file1.C ... fileN.C]\n", argv[0]);
412 fprintf(stderr,
"Options:\n");
413 fprintf(stderr,
" -b : run in batch mode without graphics\n");
414 fprintf(stderr,
" -x : exit on exception\n");
415 fprintf(stderr,
" -e expression: request execution of the given C++ expression\n");
416 fprintf(stderr,
" -n : do not execute logon and logoff macros as specified in .rootrc\n");
417 fprintf(stderr,
" -q : exit after processing command line macro files\n");
418 fprintf(stderr,
" -l : do not show splash screen\n");
419 fprintf(stderr,
" dir : if dir is a valid directory cd to it before executing\n");
420 fprintf(stderr,
"\n");
421 fprintf(stderr,
" -? : print usage\n");
422 fprintf(stderr,
" -h : print usage\n");
423 fprintf(stderr,
" --help : print usage\n");
424 fprintf(stderr,
" -config : print ./configure options\n");
425 fprintf(stderr,
" -memstat : run with memory usage monitoring\n");
426 fprintf(stderr,
"\n");
428 }
else if (!strcmp(argv[i],
"-config")) {
429 fprintf(stderr,
"ROOT ./configure options:\n%s\n",
gROOT->GetConfigOptions());
431 }
else if (!strcmp(argv[i],
"-memstat")) {
434 }
else if (!strcmp(argv[i],
"-b")) {
437 }
else if (!strcmp(argv[i],
"-n")) {
440 }
else if (!strcmp(argv[i],
"-q")) {
443 }
else if (!strcmp(argv[i],
"-l")) {
447 }
else if (!strcmp(argv[i],
"-x")) {
450 }
else if (!strcmp(argv[i],
"-splash")) {
454 }
else if (!strcmp(argv[i],
"-e")) {
465 Warning(
"GetOptions",
"-e must be followed by an expression.");
468 }
else if (argv[i][0] !=
'-' && argv[i][0] !=
'+') {
471 char *arg = strchr(argv[i],
'(');
472 if (arg) *arg =
'\0';
484 }
else if (!strcmp(
gROOT->GetName(),
"Rint")) {
485 Warning(
"GetOptions",
"only one directory argument can be specified (%s)", dir);
487 }
else if (size > 0) {
493 Warning(
"GetOptions",
"file %s has size 0, skipping", dir);
500 if (!strcmp(
gROOT->GetName(),
"Rint"))
501 Warning(
"GetOptions",
"file %s not found", dir);
522 if (!strcmp(
gROOT->GetName(),
"Rint"))
523 Warning(
"GetOptions",
"macro %s not found", fname.
Data());
538 for (i = 0; i < *argc; i++) {
539 if (strcmp(argv[i],
"")) {
557 Emit(
"HandleIdleTimer()");
603 Printf(
"\nROOT special commands.");
604 Printf(
"===========================================================================");
605 Printf(
" pwd : show current directory, pad and style");
606 Printf(
" ls : list contents of current directory");
607 Printf(
" which [file] : shows path of macro file");
616 if (
gROOT->IsBatch())
return;
619 if ((h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualPad")))
624 TString title1 =
"ROOT interface to ";
629 nativex =
"win32gdk";
631 title = title1 +
"Win32gdk";
632 #elif defined(R__HAS_COCOA)
635 title = title1 +
"Quartz";
639 title = title1 +
"X11";
644 if (guiBackend ==
"native") {
645 guiBackend = nativex;
648 title = title1 + guiBackend;
652 if (guiFactory ==
"native")
653 guiFactory = nativeg;
655 if ((h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX", guiBackend))) {
663 if ((h =
gROOT->GetPluginManager()->FindHandler(
"TGuiFactory", guiFactory))) {
703 if (!ln || strlen(ln) <= 0)
715 while (line.
Tokenize(tkn, from,
" ")) {
719 }
else if (tkn ==
"-d") {
721 }
else if (tkn ==
"-close") {
724 ::Warning(
"TApplication::ParseRemoteLine",
"unknown option: %s", tkn.
Data());
732 }
else if (isHostDir) {
737 }
else if (isScript) {
769 if (!strncmp(line,
"-?", 2) || !strncmp(line,
"-h", 2) ||
770 !strncmp(line,
"--help", 6)) {
771 Info(
"ProcessRemote",
"remote session help:");
772 Printf(
".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
773 Printf(
"Create a ROOT session on the specified remote host.");
774 Printf(
"The variable \"dir\" is the remote directory to be used as working dir.");
775 Printf(
"The username can be specified in two ways, \"-l\" having the priority");
776 Printf(
"(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
777 Printf(
"The last argument \"script\" allows to specify an alternative script to");
778 Printf(
"be executed remotely to startup the session, \"roots\" being");
779 Printf(
"the default. If the script is preceded by a \"<\" the script will be");
780 Printf(
"sourced, after which \"roots\" is executed. The sourced script can be ");
781 Printf(
"used to change the PATH and other variables, allowing an alternative");
782 Printf(
"\"roots\" script to be found.");
783 Printf(
"To close down a session do \".R host -close\".");
784 Printf(
"To switch between sessions do \".R host\", to switch to the local");
785 Printf(
"session do \".R\".");
786 Printf(
"To list all open sessions do \"gApplication->GetApplications()->Print()\".");
793 if (hostdir.
Length() <= 0) {
803 }
else if (rc == 1) {
814 const char *sc = (script.
Length() > 0) ? script.
Data() : 0;
825 static int PrintFile(
const char* filename) {
829 Error(
"ProcessLine()",
"Cannot find file %s", filename);
832 std::ifstream instr(sFileName);
847 if (!line || !*line)
return 0;
850 if (!strncmp(line,
".R", 2)) {
852 while (*(line+n) ==
' ')
863 if (!strncasecmp(line,
".qqqqqqq", 7)) {
865 }
else if (!strncasecmp(line,
".qqqqq", 5)) {
866 Info(
"ProcessLine",
"Bye... (try '.qqqqqqq' if still running)");
868 }
else if (!strncasecmp(line,
".exit", 4) || !strncasecmp(line,
".quit", 2)) {
873 if (!strncmp(line,
"?", 1) || !strncmp(line,
".help", 5)) {
878 if (!strncmp(line,
".demo", 5)) {
879 if (
gROOT->IsBatch()) {
880 Error(
"ProcessLine",
"Cannot show demos in batch mode!");
891 if (!strncmp(line,
".license", 8)) {
893 return PrintFile(ROOTDOCDIR
"/LICENSE");
895 return PrintFile(
"$(ROOTSYS)/LICENSE");
899 if (!strncmp(line,
".credits", 8)) {
901 return PrintFile(ROOTDOCDIR
"/CREDITS");
903 return PrintFile(
"$(ROOTSYS)/README/CREDITS");
908 if (!strncmp(line,
".pwd", 4)) {
918 if (!strncmp(line,
".ls", 3)) {
920 if (line[3]) opt = &line[3];
925 if (!strncmp(line,
".which", 6)) {
926 char *fn =
Strip(line+7);
927 char *s = strtok(fn,
"+(");
938 if (!strncmp(line,
".L", 2) || !strncmp(line,
".U", 2)) {
946 Warning(
"ProcessLine",
"argument(s) \"%s\" ignored with .%c", arguments.
Data(),
951 Error(
"ProcessLine",
"macro %s not found in path %s", fname.
Data(),
956 if (posSpace == -1) cmd.
Remove(1);
957 else cmd.
Remove(posSpace);
977 if (!strncmp(line,
".X", 2) || !strncmp(line,
".x", 2)) {
981 if (!strcmp(line,
".reset")) {
983 Printf(
"*** .reset not allowed, please use gROOT->Reset() ***");
989 gROOT->GetListOfClasses()->Delete();
1014 static const Int_t kBufSize = 1024;
1016 if (!file || !*file)
return 0;
1025 ::Error(
"TApplication::ExecuteFile",
"macro %s not found in path %s", fname.
Data(),
1031 ::std::ifstream macro(exnam, std::ios::in);
1032 if (!macro.good()) {
1033 ::Error(
"TApplication::ExecuteFile",
"%s no such file", exnam);
1038 char currentline[kBufSize];
1039 char dummyline[kBufSize];
1049 bool res = (bool)macro.getline(currentline, kBufSize);
1050 if (macro.eof())
break;
1055 while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1060 while (s && (*s ==
' ' || *s ==
'\t')) s++;
1067 if (strstr(cs,
"#ifndef__CINT__") ||
1068 strstr(cs,
"#if!defined(__CINT__)"))
1070 else if (ifndefc && (strstr(cs,
"#ifdef") || strstr(cs,
"#ifndef") ||
1071 strstr(cs,
"#ifdefined") || strstr(cs,
"#if!defined")))
1073 else if (ifndefc && strstr(cs,
"#endif")) {
1078 }
else if (ifndefc && !ifdef && strstr(cs,
"#else"))
1082 if (!*s || *s ==
'#' || ifndefc || !strncmp(s,
"//", 2))
continue;
1084 if (!comment && (!strncmp(s,
".X", 2) || !strncmp(s,
".x", 2))) {
1090 if (!strncmp(s,
"/*", 2)) comment = 1;
1094 s = strstr(s,
"*/");
1099 while (s && (*s ==
' ' || *s ==
'\t')) s++;
1101 if (!strncmp(s,
"//", 2))
continue;
1102 if (!strncmp(s,
"/*", 2)) {
1108 if (!comment && *s ==
'{') tempfile = 1;
1109 if (!comment)
break;
1118 exname += aclicMode;
1120 exname += arguments;
1125 tempbuf.
Form(
".x %s", exname.
Data());
1127 tempbuf.
Form(
".X%s %s", keep ?
"k" :
" ", exname.
Data());
1157 fIdleTimer =
new TIdleTimer(idleTimeInSec*1000);
1208 Emit(
"Terminate(Int_t)", status);
1228 Emit(
"LineProcessed(const char*)", line);
1236 Emit(
"KeyPressed(Int_t)", key);
1244 Emit(
"ReturnPressed(char*)", text);
1263 if (!gApplication) {
1265 if (!gApplication) {
1274 Printf(
"<TApplication::CreateApplication>: "
1275 "created default TApplication");
1276 delete []
a;
delete [] b;
1313 ::Error(
"TApplication::Open",
"list of applications undefined - protocol error");
1325 if ((h =
gROOT->GetPluginManager()->FindHandler(
"TApplication",
"remote"))) {
1329 ::Error(
"TApplication::Open",
"failed to load plugin for TApplicationRemote");
1332 ::Error(
"TApplication::Open",
"failed to find plugin for TApplicationRemote");
1343 gROOT->RefreshBrowsers();
1347 "TApplicationRemote for %s could not be instantiated", url);
1362 gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1367 gROOT->RefreshBrowsers();
const char * GetHost() const
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
R__EXTERN TGuiFactory * gBatchGuiFactory
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 "...
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
const char * GetIdleCommand() const
static Bool_t fgGraphInit
virtual const char * WorkingDirectory()
Return working directory.
char * Compress(const char *str)
Remove all blanks from the string str.
void Reset()
Reset the timer.
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
R__EXTERN TClassTable * gClassTable
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
R__EXTERN TVirtualMutex * gInterpreterMutex
This class represents a WWW compatible URL.
TString & ReplaceAll(const TString &s1, const TString &s2)
R__EXTERN TStyle * gStyle
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
const char * GetProtocol() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual void MakeBatch()
Switch to batch mode.
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Int_t LoadPlugin()
Load the plugin library for this handler.
void ToLower()
Change string to lower-case.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
static Bool_t fgGraphNeeded
R__EXTERN TVirtualMutex * gROOTMutex
EExitOnException fExitOnException
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.
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
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...
Long_t ExecPlugin(int nargs, const T &...params)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Insert(Ssiz_t pos, const char *s)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
static const char * GetMacroPath()
Get macro search path. Static utility function.
const char * Data() const
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Set the command to be executed after the system has been idle for idleTimeInSec seconds.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
static Int_t ParseRemoteLine(const char *ln, TString &hostdir, TString &user, Int_t &dbg, TString &script)
Parse the content of a line starting with ".R" (already stripped-off) The format is [user@]host[:dir]...
virtual ~TApplication()
TApplication dtor.
virtual void ExitLoop()
Exit from event loop.
Int_t Atoi() const
Return integer value of string.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
R__EXTERN TGuiFactory * gGuiFactory
void Error(const char *location, const char *msgfmt,...)
void Emit(const char *signal)
Acitvate signal without args.
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
virtual Bool_t Notify()
Notify when timer times out.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
static TList * GetApplications()
Static method returning the list of available applications.
Using a TBrowser one can browse all ROOT objects.
R__EXTERN TVirtualX * gGXBatch
Bool_t fIsRunning
Window system specific application implementation.
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual void RemoveIdleTimer()
Remove idle timer. Normally called via TROOT::Idle(0).
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
void SetScreenFactor(Float_t factor=1)
char * Strip(const char *str, char c= ' ')
Strip leading and trailing c (blanks by default) from a string.
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Execute a file containing a C++ macro (static method).
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t TestBit(UInt_t f) const
char * Form(const char *fmt,...)
TApplicationImp * fAppImp
virtual void SetEchoMode(Bool_t mode)
Set console echo mode:
Handles synchronous and a-synchronous timer events.
virtual const char * GetName() const
Returns name of object.
virtual void StopIdleing()
Called when system stops idleing.
virtual void Abort(int code=0)
Abort the application.
TApplication * fAppRemote
virtual TObjLink * FirstLink() const
void Reset(Detail::TBranchProxy *x)
static void Close(TApplication *app)
Static function used to close a remote application.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
virtual void Run()
System event loop.
char * StrDup(const char *str)
Duplicate the string str.
virtual void Help(const char *line)
Print help on interpreter.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
static void CreateApplication()
Static function used to create a default application environment.
void InitializeGraphics()
Initialize the graphics environment.
TString & Remove(Ssiz_t pos)
R__EXTERN ExceptionContext_t * gException
virtual void StartIdleing()
Called when system starts idleing.
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.
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
What to do when tab is pressed.
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
This ABC is a factory for GUI components.
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Add(TObject *obj)
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
void SetOptions(const char *opt)
TApplication * gApplication
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
static TList * fgApplications
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void SetReturnFromRun(Bool_t ret)
ClassImp(TApplication) static void CallEndOfProcessCleanups()
virtual const char * ApplicationName() const
const char * GetUser() const
const char * GetFile() const
virtual void RecursiveRemove(TObject *obj)
Recursively remove obj from browser.
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
virtual void ls(Option_t *option="") const
Show available sessions.
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.