Import Geant4 9.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 17:01:34 +02:00
parent b1eb5424d2
commit e2d2f9810a
10384 changed files with 698580 additions and 628834 deletions
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIArrayString.cc,v 1.8 2006-06-29 19:09:43 gunter Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
#include <iomanip>
@@ -0,0 +1,306 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
// $Id: G4UIExecutive.icc,v 1.7 2010-05-28 08:12:27 kmura Exp $
// GEANT4 tag $Name: geant4-09-04-patch-02 $
#include "G4UIExecutive.hh"
#include "G4UIsession.hh"
#include "G4UImanager.hh"
#if defined(G4UI_BUILD_QT_SESSION)
#include "G4UIQt.hh"
#include "G4Qt.hh"
#endif
#if defined(G4UI_BUILD_XM_SESSION)
#include "G4UIXm.hh"
#endif
#if defined(G4UI_BUILD_WIN32_SESSION)
#include "G4UIWin32.hh"
#endif
#if defined(G4UI_BUILD_WT_SESSION)
//#include "G4UIWt.hh"
#endif
#include "G4UIGAG.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "G4UIcsh.hh"
// --------------------------------------------------------------------------
// build flags as variables
#if defined(G4UI_BUILD_QT_SESSION)
static const G4bool qt_build = true;
#else
static const G4bool qt_build = false;
#endif
#if defined(G4UI_BUILD_XM_SESSION)
static const G4bool xm_build = true;
#else
static const G4bool xm_build = false;
#endif
#if defined(G4UI_BUILD_WIN32_SESSION)
static const G4bool win32_build = true;
#else
static const G4bool win32_build = false;
#endif
#if defined(G4UI_BUILD_WT_SESSION)
static const G4bool wt_build = true;
#else
static const G4bool wt_build = false;
#endif
#ifndef WIN32
static const G4bool tcsh_build = true;
#else
static const G4bool tcsh_build = false;
#endif
#define DISCARD_PARAMETER(p) (void)p
// --------------------------------------------------------------------------
G4UIExecutive::G4UIExecutive(G4int argc, char** argv, const G4String& type)
: selected(kNone), session(NULL), shell(NULL), isGUI(false)
{
G4cout << "Available UI session types: [ ";
if ( qt_build ) G4cout << "Qt, ";
if ( xm_build ) G4cout << "Xm, ";
if ( win32_build) G4cout << "Win32, ";
if ( wt_build ) G4cout << "Wt, ";
G4cout << "GAG, ";
if (tcsh_build ) G4cout << "tcsh, ";
G4cout << "csh ]" << G4endl;
// selecting session type...
// 1st priority : in case argumant specified
G4String stype = type;
stype.toLower(); // session type is case-insensitive.
if (type != "") SelectSessionByArg(stype);
// 2nd priority : refer environment variables (as backword compatibility)
if ( selected == kNone ) SelectSessionByEnv();
// 3rd priority : refer $HOME/.g4session
if ( selected == kNone ) {
G4String appinput = argv[0];
G4String appname = "";
size_t islash = appinput.find_last_of("/\\");
if (islash == G4String::npos)
appname = appinput;
else
appname = appinput(islash+1, appinput.size()-islash-1);
SelectSessionByFile(appname);
}
// 4th, best guess of session type
if ( selected == kNone) SelectSessionByBestGuess();
// instantiate a session...
switch ( selected ) {
case kQt:
#if defined(G4UI_BUILD_QT_SESSION)
session = new G4UIQt(argc, argv);
isGUI = true;
#endif
break;
case kXm:
#if defined(G4UI_BUILD_XM_SESSION)
session = new G4UIXm(argc, argv);
isGUI = true;
#endif
break;
case kWin32:
#if defined(G4UI_BUILD_WIN32_SESSION)
DISCARD_PARAMETER(argc);
DISCARD_PARAMETER(argv);
session = new G4UIWin32();
#endif
break;
case kWt:
#if defined(G4UI_BUILD_WT_SESSION)
//session = new G4UIWt(argc, argv);
//isGUI = true;
#endif
break;
case kGag:
DISCARD_PARAMETER(argc);
DISCARD_PARAMETER(argv);
session = new G4UIGAG();
isGUI = true;
break;
case kTcsh:
#ifndef WIN32
DISCARD_PARAMETER(argc);
DISCARD_PARAMETER(argv);
shell = new G4UItcsh;
session = new G4UIterminal(shell);
#endif
break;
case kCsh:
DISCARD_PARAMETER(argc);
DISCARD_PARAMETER(argv);
shell = new G4UIcsh;
session = new G4UIterminal(shell);
default:
break;
}
// fallback (csh)
if ( session == NULL ) {
G4Exception("G4UIExecutive::G4UIExecutive()",
"UI0002",
JustWarning,
"Specified session type is not build in your system,\n"
"or no session type is specified.\n"
"A fallback session type is used.");
selected = kCsh;
DISCARD_PARAMETER(argc);
DISCARD_PARAMETER(argv);
shell = new G4UIcsh;
session = new G4UIterminal(shell);
}
}
// --------------------------------------------------------------------------
G4UIExecutive::~G4UIExecutive()
{
if ( selected != kWt ) delete session;
}
// --------------------------------------------------------------------------
void G4UIExecutive::SelectSessionByArg(const G4String& stype)
{
if ( qt_build && stype == "qt" ) selected = kQt;
else if ( xm_build && stype == "xm" ) selected = kXm;
else if ( win32_build && stype == "win32" ) selected = kWin32;
//else if ( wt_build && stype == "wt" ) selected = kWt;
else if ( stype == "gag" ) selected = kGag;
else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
else if ( stype == "csh" ) selected = kCsh;
}
// --------------------------------------------------------------------------
void G4UIExecutive::SelectSessionByEnv()
{
if ( qt_build && getenv("G4UI_USE_QT") ) selected = kQt;
else if ( xm_build && getenv("G4UI_USE_XM") ) selected = kXm;
else if ( win32_build && getenv("G4UI_USE_WIN32") ) selected = kWin32;
//else if ( wt_build && getenv("G4UI_USE_WT") ) selected = kWt;
else if ( getenv("G4UI_USE_GAG") ) selected = kGag;
else if ( tcsh_build && getenv("G4UI_USE_TCSH") ) selected = kTcsh;
}
// --------------------------------------------------------------------------
void G4UIExecutive::SelectSessionByFile(const G4String& appname)
{
const char* path = getenv("HOME");
if( path == NULL ) return;
G4String homedir = path;
#ifndef WIN32
G4String fname= homedir + "/.g4session";
#else
G4String fname= homedir + "\\.g4session";
#endif
std::ifstream fsession;
enum { BUFSIZE= 1024 }; char linebuf[BUFSIZE];
fsession.open(fname, std::ios::in);
G4String default_session = "";
G4int iline = 1;
sessionMap.clear();
while( fsession.good() ) {
if( fsession.eof()) break;
fsession.getline(linebuf, BUFSIZE);
G4String aline = linebuf;
aline.strip(G4String::both);
if ( aline(0) == '#' ) continue;
if ( iline == 1 )
default_session = aline;
else {
size_t idx = aline.find_first_of(" ");
if ( idx == G4String::npos ) break;
G4String aname = aline.substr(0, idx);
idx = aline.find_first_not_of(" ", idx);
if (idx == G4String::npos ) break;
G4String sname = aline.substr(idx, aline.size()-idx);
sessionMap[aname] = sname;
}
iline++;
}
fsession.close();
G4String stype = "";
std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
if ( it != sessionMap.end() ) stype = sessionMap[appname];
else stype = default_session;
stype.toLower();
// select session...
if ( qt_build && stype == "qt" ) selected = kQt;
else if ( xm_build && stype == "xm" ) selected = kXm;
else if ( win32_build && stype == "win32" ) selected = kWin32;
//else if ( wt_build && stype == "wt" ) selected = kWt;
else if ( stype == "gag" ) selected = kGag;
else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
else if ( stype == "csh" ) selected = kCsh;
}
// --------------------------------------------------------------------------
void G4UIExecutive::SelectSessionByBestGuess()
{
if ( qt_build ) selected = kQt;
else if ( tcsh_build ) selected = kTcsh;
else if ( xm_build ) selected = kXm;
}
// --------------------------------------------------------------------------
void G4UIExecutive::SetPrompt(const G4String& prompt)
{
if(shell) shell-> SetPrompt(prompt);
}
// --------------------------------------------------------------------------
void G4UIExecutive::SetLsColor(TermColorIndex dirColor,
TermColorIndex cmdColor)
{
if(shell) shell-> SetLsColor(dirColor, cmdColor);
}
// --------------------------------------------------------------------------
void G4UIExecutive::SessionStart()
{
session-> SessionStart();
}
File diff suppressed because it is too large Load Diff
+26 -27
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIWin32.cc,v 1.13 2006-06-29 19:09:45 gunter Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
// G.Barrand
@@ -242,7 +241,7 @@ G4UIWin32::G4UIWin32 (
::GetModuleHandle(NULL),
NULL);
tmpSession = NULL;
::SetWindowLong(mainWindow,GWL_USERDATA,LONG(this));
::SetWindowLongPtr(mainWindow,GWLP_USERDATA,LONG(this));
::SetForegroundWindow(mainWindow);
::ShowWindow(mainWindow,SW_SHOWDEFAULT);
@@ -262,9 +261,9 @@ G4UIWin32::~G4UIWin32 (
UI->SetCoutDestination(NULL);
}
delete textBuffer;
if(textWindow!=NULL) ::SetWindowLong(textWindow,GWL_USERDATA,LONG(NULL));
if(textWindow!=NULL) ::SetWindowLongPtr(textWindow,GWLP_USERDATA,LONG(NULL));
if(mainWindow!=NULL) {
::SetWindowLong(mainWindow,GWL_USERDATA,LONG(NULL));
::SetWindowLongPtr(mainWindow,GWLP_USERDATA,LONG(NULL));
::DestroyWindow(mainWindow);
}
}
@@ -288,7 +287,7 @@ G4UIsession* G4UIWin32::SessionStart (
}
/***************************************************************************/
void G4UIWin32::Prompt (
G4String a_prompt
const G4String& a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -303,7 +302,7 @@ void G4UIWin32::SessionTerminate (
}
/***************************************************************************/
void G4UIWin32::PauseSessionStart (
G4String a_state
const G4String& a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -319,7 +318,7 @@ void G4UIWin32::PauseSessionStart (
}
/***************************************************************************/
void G4UIWin32::SecondaryLoop (
G4String a_prompt
const G4String& a_prompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -336,7 +335,7 @@ void G4UIWin32::SecondaryLoop (
}
/***************************************************************************/
G4int G4UIWin32::ReceiveG4cout (
G4String a_string
const G4String& a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -346,7 +345,7 @@ G4int G4UIWin32::ReceiveG4cout (
}
/***************************************************************************/
G4int G4UIWin32::ReceiveG4cerr (
G4String a_string
const G4String& a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -380,7 +379,7 @@ G4bool G4UIWin32::GetHelpChoice(
}
/***************************************************************************/
void G4UIWin32::ExitHelp(
)
) const
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
@@ -466,7 +465,7 @@ LRESULT CALLBACK G4UIWin32::MainWindowProc (
a_window,NULL,
GetWindowInstance(a_window),
NULL);
::SetWindowLong (This->textWindow,GWL_USERDATA,LONG(This));
::SetWindowLongPtr (This->textWindow,GWLP_USERDATA,LONG(This));
This->editWindow = CreateWindow ("edit",NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
@@ -475,8 +474,8 @@ LRESULT CALLBACK G4UIWin32::MainWindowProc (
a_window,(HMENU)1,
GetWindowInstance(a_window),
NULL);
oldEditWindowProc = (WNDPROC)GetWindowLong(This->editWindow,GWL_WNDPROC);
SetWindowLong (This->editWindow,GWL_WNDPROC,(LONG)EditWindowProc);
oldEditWindowProc = (WNDPROC)GetWindowLongPtr(This->editWindow,GWLP_WNDPROC);
SetWindowLongPtr (This->editWindow,GWLP_WNDPROC,(LONG)EditWindowProc);
MoveWindow (a_window,
rect.left,rect.top,
@@ -489,7 +488,7 @@ LRESULT CALLBACK G4UIWin32::MainWindowProc (
}
}return 0;
case WM_SIZE:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
if(This!=NULL) {
// Client size :
int width = LOWORD(a_lParam);
@@ -507,11 +506,11 @@ LRESULT CALLBACK G4UIWin32::MainWindowProc (
}
}return 0;
case WM_SETFOCUS:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
if(This!=NULL) SetFocus (This->editWindow);
}return 0;
case WM_COMMAND:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
if(This!=NULL) {
if(This->fHelp==false) {
G4String command = This->GetCommand(a_wParam);
@@ -537,7 +536,7 @@ LRESULT CALLBACK G4UIWin32::TextWindowProc (
{
switch (a_message) {
case WM_PAINT:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
if(This!=NULL) {
TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
RECT rect;
@@ -549,7 +548,7 @@ LRESULT CALLBACK G4UIWin32::TextWindowProc (
}
}return 0;
case WM_VSCROLL:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(a_window,GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(a_window,GWLP_USERDATA);
if(This!=NULL) {
TextBuffer* textBuffer = (TextBuffer*)This->textBuffer;
int what = LOWORD(a_wParam);
@@ -597,8 +596,8 @@ LRESULT CALLBACK G4UIWin32::EditWindowProc (
case WM_KEYDOWN:
switch(a_wParam){
case VK_RETURN:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(
GetParent(a_window),GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
GetParent(a_window),GWLP_USERDATA);
char buffer[128];
GetWindowText (a_window,buffer,128);
G4String command (buffer);
@@ -619,8 +618,8 @@ LRESULT CALLBACK G4UIWin32::EditWindowProc (
}break;
case VK_TAB:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(
GetParent(a_window),GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
GetParent(a_window),GWLP_USERDATA);
if( (This!=NULL) && (This->fHelp==true) ) break;
char buffer[128];
Edit_GetText(a_window,buffer,128);
@@ -637,8 +636,8 @@ LRESULT CALLBACK G4UIWin32::EditWindowProc (
}break;
case VK_UP:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(
GetParent(a_window),GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
GetParent(a_window),GWLP_USERDATA);
if(This!=NULL) {
int pos = This->fHistoryPos== -1 ?
This->fHistory.size()-1 : This->fHistoryPos-1;
@@ -654,8 +653,8 @@ LRESULT CALLBACK G4UIWin32::EditWindowProc (
}
}return 0; //Do not jump into oldEditProc.
case VK_DOWN:{
G4UIWin32* This = (G4UIWin32*)::GetWindowLong(
GetParent(a_window),GWL_USERDATA);
G4UIWin32* This = (G4UIWin32*)::GetWindowLongPtr(
GetParent(a_window),GWLP_USERDATA);
if(This!=NULL) {
int pos = This->fHistoryPos + 1;
if((pos>=0)&&(pos<(int)This->fHistory.size())) {
+14 -5
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIXaw.cc,v 1.6 2006-06-29 19:09:47 gunter Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
// G.Barrand
@@ -62,6 +61,16 @@ G4UIXaw::G4UIXaw (
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
static G4bool warned = false;
if (!warned) {
warned = true;
G4cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
"\n!!!!! Xaw is deprecated and will be removed in the next major release."
"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
<< G4endl;
}
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI!=NULL) UI->SetSession(this);
@@ -109,7 +118,7 @@ G4UIsession* G4UIXaw::SessionStart (
}
/***************************************************************************/
void G4UIXaw::Prompt (
G4String aPrompt
const G4String& aPrompt
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -127,7 +136,7 @@ void G4UIXaw::SessionTerminate (
}
/***************************************************************************/
void G4UIXaw::PauseSessionStart (
G4String a_state
const G4String& a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -192,7 +201,7 @@ G4bool G4UIXaw::GetHelpChoice(
}
/***************************************************************************/
void G4UIXaw::ExitHelp(
)
) const
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
+5 -6
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIXm.cc,v 1.15 2008-11-14 16:21:42 lgarnier Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
// G.Barrand
@@ -217,7 +216,7 @@ void G4UIXm::SessionTerminate (
}
/***************************************************************************/
void G4UIXm::PauseSessionStart (
G4String a_state
const G4String& a_state
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -250,7 +249,7 @@ void G4UIXm::SecondaryLoop (
}
/***************************************************************************/
G4int G4UIXm::ReceiveG4cout (
G4String a_string
const G4String& a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -260,7 +259,7 @@ G4int G4UIXm::ReceiveG4cout (
}
/***************************************************************************/
G4int G4UIXm::ReceiveG4cerr (
G4String a_string
const G4String& a_string
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
@@ -294,7 +293,7 @@ G4bool G4UIXm::GetHelpChoice(
}
/***************************************************************************/
void G4UIXm::ExitHelp(
)
) const
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
+4 -5
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIcsh.cc,v 1.8 2006-06-29 19:09:51 gunter Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
#include "G4UIcsh.hh"
@@ -44,9 +43,9 @@ G4UIcsh::~G4UIcsh()
}
//////////////////////////////////
G4String G4UIcsh::GetCommandLine(const char* msg)
//////////////////////////////////
///////////////////////////////////////////////////////
G4String G4UIcsh::GetCommandLineString(const char* msg)
///////////////////////////////////////////////////////
{
MakePrompt(msg);
G4cout << promptString << std::flush;
+29 -22
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UItcsh.cc,v 1.17 2008-07-18 06:37:06 kmura Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
#ifndef WIN32
@@ -75,7 +74,10 @@ G4UItcsh::G4UItcsh(const G4String& prompt, G4int maxhist)
tcgetattr(0, &tios);
// read a shell history file
G4String homedir= getenv("HOME");
const char* path = getenv("HOME");
if( path == NULL ) return;
G4String homedir= path;
G4String fname= homedir + historyFileName;
std::ifstream histfile;
@@ -98,7 +100,10 @@ G4UItcsh::~G4UItcsh()
/////////////////////
{
// store a shell history
G4String homedir= getenv("HOME");
const char* path = getenv("HOME");
if( path == NULL ) return;
G4String homedir= path;
G4String fname= homedir + historyFileName;
std::ofstream histfile;
@@ -403,10 +408,11 @@ void G4UItcsh::ListMatchedCommand()
input.remove(0, jhead);
input= input.strip(G4String::leading);
}
//G4cout << "@@@@ input=" << input << G4endl;
// command tree of "user specified directory"
G4String vpath= currentCommandDir;
G4String vcmd;
G4String vpath = currentCommandDir;
G4String vcmd = "";
if( !input.empty() ) {
G4int len= input.length();
@@ -415,7 +421,7 @@ void G4UItcsh::ListMatchedCommand()
if(input[(size_t)i]=='/') {
indx= i;
break;
}
}
}
// get abs. path
if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
@@ -423,6 +429,7 @@ void G4UItcsh::ListMatchedCommand()
}
// list matched dirs/commands
//G4cout << "@@@ vpath=" << vpath <<":vcmd=" << vcmd << G4endl;
ListCommand(vpath, vpath+vcmd);
G4cout << promptString << commandLine << std::flush;
@@ -441,6 +448,11 @@ void G4UItcsh::CompleteCommand()
input= input.strip(G4String::leading);
}
// tail string
size_t thead = input.find_last_of('/');
G4String strtail = input;
if (thead != G4String::npos) strtail = input(thead+1, input.size()-thead-1);
// command tree of "user specified directory"
G4String vpath= currentCommandDir;
G4String vcmd;
@@ -455,7 +467,7 @@ void G4UItcsh::CompleteCommand()
}
}
// get abs. path
if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
if(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); // care for "/"
}
@@ -501,8 +513,6 @@ void G4UItcsh::CompleteCommand()
}
}
if(nMatch==0) return; // no matched
// display...
input= commandLine;
// target token is last token
@@ -510,11 +520,7 @@ void G4UItcsh::CompleteCommand()
if(jhead == G4int(G4String::npos)) jhead=0;
else jhead++;
G4int jt= input.find_last_of('/');
if(jt<jhead) jt=G4int(G4String::npos);
if(jt==G4int(G4String::npos)) jt= jhead;
else jt++;
G4int jt = jhead;
G4String dspstr;
G4int i;
@@ -522,18 +528,19 @@ void G4UItcsh::CompleteCommand()
for(i=jt; i<=G4int(input.length())-1; i++) dspstr+= G4String(' ');
for(i=jt; i<=G4int(input.length())-1; i++) dspstr+= G4String(AsciiBS);
dspstr+= stream;
G4cout << dspstr << std::flush;
dspstr+= (vpath + stream);
if (nMatch == 0) dspstr+= strtail;
G4cout << dspstr << std::flush;
// command line string
input.remove(jt);
input+= stream;
input+= (vpath + stream);
if (nMatch==0) input+= strtail;
commandLine= input;
cursorPosition= commandLine.length()+1;
}
// --------------------------------------------------------------------
// commad line
// --------------------------------------------------------------------
@@ -637,9 +644,9 @@ G4String G4UItcsh::ReadLine()
return commandLine;
}
//////////////////////////////////////////////////
G4String G4UItcsh::GetCommandLine(const char* msg)
//////////////////////////////////////////////////
////////////////////////////////////////////////////////
G4String G4UItcsh::GetCommandLineString(const char* msg)
////////////////////////////////////////////////////////
{
SetTermToInputMode();
+20 -21
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4UIterminal.cc,v 1.28 2008-07-18 06:38:59 kmura Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
// ====================================================================
// G4UIterminal.cc
@@ -145,9 +144,9 @@ G4UIsession* G4UIterminal::SessionStart()
return NULL;
}
//////////////////////////////////////////////////
void G4UIterminal::PauseSessionStart(G4String msg)
//////////////////////////////////////////////////
/////////////////////////////////////////////////////////
void G4UIterminal::PauseSessionStart(const G4String& msg)
/////////////////////////////////////////////////////////
{
iCont= TRUE;
@@ -158,9 +157,9 @@ void G4UIterminal::PauseSessionStart(G4String msg)
}
}
////////////////////////////////////////////////////
void G4UIterminal::ExecuteCommand(G4String aCommand)
////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void G4UIterminal::ExecuteCommand(const G4String& aCommand)
///////////////////////////////////////////////////////////
{
if(aCommand.length()<2) return;
@@ -209,16 +208,16 @@ void G4UIterminal::ExecuteCommand(G4String aCommand)
}
}
///////////////////////////////////
//////////////////////////////////////////////////
G4String G4UIterminal::GetCommand(const char* msg)
///////////////////////////////////
//////////////////////////////////////////////////
{
G4String newCommand;
G4String nullString;
newCommand= shell-> GetCommandLine(msg);
newCommand= shell-> GetCommandLineString(msg);
G4String nC= newCommand.strip(G4String::leading);
G4String nC = newCommand.strip(G4String::leading);
if( nC.length() == 0 ) {
newCommand= nullString;
@@ -304,17 +303,17 @@ G4String G4UIterminal::GetCommand(const char* msg)
}
//////////////////////////////////////////////////////
G4int G4UIterminal::ReceiveG4cout(G4String coutString)
//////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
G4int G4UIterminal::ReceiveG4cout(const G4String& coutString)
/////////////////////////////////////////////////////////////
{
std::cout << coutString << std::flush;
return 0;
}
//////////////////////////////////////////////////////
G4int G4UIterminal::ReceiveG4cerr(G4String cerrString)
//////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
G4int G4UIterminal::ReceiveG4cerr(const G4String& cerrString)
/////////////////////////////////////////////////////////////
{
std::cerr << cerrString << std::flush;
return 0;
@@ -333,9 +332,9 @@ G4bool G4UIterminal::GetHelpChoice(G4int& aInt)
return TRUE;
}
/////////////////////////////
void G4UIterminal::ExitHelp()
/////////////////////////////
///////////////////////////////////
void G4UIterminal::ExitHelp() const
///////////////////////////////////
{
char temp[100];
G4cin.getline(temp, 100);
+15 -6
View File
@@ -24,8 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VUIshell.cc,v 1.10 2007-06-14 05:44:58 kmura Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
#include "G4UImanager.hh"
@@ -159,23 +158,33 @@ G4String G4VUIshell::GetAbsCommandDirPath(const G4String& apath) const
G4String absPath= "/";
for(G4int indx=1; indx<=G4int(bpath.length())-1; ) {
G4int jslash= bpath.index("/", indx); // search index begin with "/"
if(indx == jslash) { // skip first '///'
indx++;
continue;
}
if(jslash != G4int(G4String::npos)) {
if(bpath(indx,jslash-indx) == ".."){ // directory up
if(absPath.length() >=1) {
if(bpath.substr(indx,jslash-indx) == ".."){ // directory up
if(absPath == "/") {
indx = jslash+1;
continue;
}
if(absPath.length() >= 2) {
absPath.remove(absPath.length()-1); // remove last "/"
G4int jpre= absPath.last('/');
if(jpre != G4int(G4String::npos)) absPath.remove(jpre+1);
}
} else if(bpath(indx,jslash-indx) == "."){ // nothing to do
} else if(bpath.substr(indx,jslash-indx) == "."){ // nothing to do
} else { // add
if( !(jslash==indx && bpath(indx)=='/') ) // truncate "////"
absPath+= bpath(indx, jslash-indx+1);
// better to be check directory existence. (it costs!)
}
indx= jslash+1;
} else { // directory ONLY (ignore non-"/" terminated string)
break;
}
indx= jslash+1;
}
return absPath;
}