30#if defined(G4UI_BUILD_QT_SESSION)
35#if defined(G4UI_BUILD_XM_SESSION)
39#if defined(G4UI_BUILD_WIN32_SESSION)
51#if defined(G4UI_BUILD_QT_SESSION)
52static const G4bool qt_build =
true;
54static const G4bool qt_build =
false;
57#if defined(G4UI_BUILD_XM_SESSION)
58static const G4bool xm_build =
true;
60static const G4bool xm_build =
false;
63#if defined(G4UI_BUILD_WIN32_SESSION)
64static const G4bool win32_build =
true;
66static const G4bool win32_build =
false;
70static const G4bool tcsh_build =
true;
72static const G4bool tcsh_build =
false;
75#define DISCARD_PARAMETER(p) (void)p
79 : selected(
kNone),
session(NULL), shell(NULL), isGUI(false), verbose(true)
82 G4cout <<
"Available UI session types: [ ";
83 if ( qt_build )
G4cout <<
"Qt, ";
84 if ( xm_build )
G4cout <<
"Xm, ";
85 if ( win32_build)
G4cout <<
"Win32, ";
86 if (tcsh_build )
G4cout <<
"tcsh, ";
93 if (type !=
"") SelectSessionByArg(stype);
96 if ( selected == kNone ) SelectSessionByEnv();
99 if ( selected == kNone ) {
102 size_t islash = appinput.find_last_of(
"/\\");
103 if (islash == G4String::npos)
106 appname = appinput.substr(islash+1, appinput.size()-islash-1);
108 SelectSessionByFile(appname);
112 if ( selected == kNone) SelectSessionByBestGuess();
115 switch ( selected ) {
117#if defined(G4UI_BUILD_QT_SESSION)
123#if defined(G4UI_BUILD_XM_SESSION)
129#if defined(G4UI_BUILD_WIN32_SESSION)
137#if !(defined(WIN32) || defined(__MINGW32__))
158 "Specified session type is not build in your system,\n"
159 "or no session type is specified.\n"
160 "A fallback session type is used.");
179void G4UIExecutive::SelectSessionByArg(
const G4String& stype)
181 if ( qt_build && stype ==
"qt" ) selected = kQt;
182 else if ( xm_build && stype ==
"xm" ) selected = kXm;
183 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
184 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
185 else if ( stype ==
"csh" ) selected = kCsh;
189void G4UIExecutive::SelectSessionByEnv()
191 if ( qt_build && std::getenv(
"G4UI_USE_QT") ) selected = kQt;
192 else if ( xm_build && std::getenv(
"G4UI_USE_XM") ) selected = kXm;
193 else if ( win32_build && std::getenv(
"G4UI_USE_WIN32") ) selected = kWin32;
194 else if ( tcsh_build && std::getenv(
"G4UI_USE_TCSH") ) selected = kTcsh;
198void G4UIExecutive::SelectSessionByFile(
const G4String& appname)
200 const char* path = std::getenv(
"HOME");
201 if( path == NULL )
return;
205 G4String fname= homedir +
"/.g4session";
207 G4String fname= homedir +
"\\.g4session";
210 std::ifstream fsession;
211 enum { BUFSIZE= 1024 };
char linebuf[BUFSIZE];
213 fsession.open(fname, std::ios::in);
218 while( fsession.good() ) {
219 if( fsession.eof())
break;
220 fsession.getline(linebuf, BUFSIZE);
222 if ( aline[0] ==
'#' )
continue;
223 if ( aline ==
"" )
continue;
225 default_session = aline;
227 size_t idx = aline.find_first_of(
" ");
228 if ( idx == G4String::npos )
break;
229 G4String aname = aline.substr(0, idx);
230 idx = aline.find_first_not_of(
" ", idx);
231 if (idx == G4String::npos )
break;
232 G4String sname = aline.substr(idx, aline.size()-idx);
233 sessionMap[aname] = sname;
240 std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
241 if ( it != sessionMap.end() ) stype = sessionMap[appname];
242 else stype = default_session;
246 if ( qt_build && stype ==
"qt" ) selected = kQt;
247 else if ( xm_build && stype ==
"xm" ) selected = kXm;
248 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
249 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
250 else if ( stype ==
"csh" ) selected = kCsh;
254void G4UIExecutive::SelectSessionByBestGuess()
256 if ( qt_build ) selected = kQt;
257 else if ( win32_build ) selected = kWin32;
258 else if ( tcsh_build ) selected = kTcsh;
259 else if ( xm_build ) selected = kXm;
272 if(shell) shell->
SetLsColor(dirColor, cmdColor);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define TIMEMORY_INIT(...)
#define DISCARD_PARAMETER(p)
G4GLOB_DLL std::ostream G4cout
void SetPrompt(const G4String &prompt)
G4UIExecutive(G4int argc, char **argv, const G4String &type="")
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.
G4String to_lower_copy(G4String str)
Return lowercased copy of string.
void to_lower(G4String &str)
Convert string to lowercase.