38static void Tokenize(
const G4String& str, std::vector<G4String>& tokens)
41 const char* delimiter=
" ";
43 G4String::size_type pos0= str.find_first_not_of(delimiter);
44 G4String::size_type pos = str.find_first_of(delimiter, pos0);
46 while (pos != G4String::npos || pos0 != G4String::npos) {
47 if (str[pos0] ==
'\"') {
48 pos = str.find_first_of(
"\"", pos0+1);
49 if(pos != G4String::npos) pos++;
51 if (str[pos0] ==
'\'') {
52 pos = str.find_first_of(
"\'", pos0+1);
53 if(pos != G4String::npos) pos++;
56 tokens.push_back(str.substr(pos0, pos-pos0));
57 pos0 = str.find_first_not_of(delimiter, pos);
58 pos = str.find_first_of(delimiter, pos0);
70 : previousSession(prevSession), isOpened(false)
73 macroStream.open(fileName, std::ios::in);
74 if(macroStream.fail()) {
75 G4cerr <<
"***** Can not open a macro file <"
90 if(isOpened) macroStream.close();
98 enum { BUFSIZE= 4096 };
99 static char linebuf[BUFSIZE];
100 const char ctrM = 0x0d;
104 while(macroStream.good()) {
105 macroStream.getline(linebuf, BUFSIZE);
111 while ((nb= cmdline.find(
'\t',nb)) != G4String::npos) {
112 cmdline.replace(nb, 1,
" ");
120 if(!qcontinued && cmdline.size()==0)
continue;
123 if(cmdline[(
size_t)0]==
'#')
return cmdline;
126 std::vector<G4String> tokens;
127 Tokenize(cmdline, tokens);
129 for (
G4int i=0; i<
G4int(tokens.size()); i++) {
131 if(tokens[i][(
size_t)0] ==
'#' )
break;
133 if(tokens[i] ==
'\\' || tokens[i] ==
'_' ) {
136 if( i !=
G4int(tokens.size())-1) {
139 "unexpected character after line continuation character");
143 cmdtotal+= tokens[i];
147 if(qcontinued)
continue;
149 if(cmdtotal.size() != 0)
break;
150 if(macroStream.eof())
break;
157 if(macroStream.eof() && cmdtotal.size()==0) {
170 G4int rc= UI-> ApplyCommand(command);
176 G4cerr <<
"***** COMMAND NOT FOUND <"
177 << command <<
"> *****" <<
G4endl;
180 G4cerr <<
"***** Illegal application state <"
181 << command <<
"> *****" <<
G4endl;
185 G4cerr <<
"***** Illegal parameter (" <<
pn <<
") <"
186 << command <<
"> *****" <<
G4endl;
197 if(!isOpened)
return previousSession;
200 G4String newCommand = ReadCommand();
202 if(newCommand ==
"exit") {
207 if( newCommand[(
size_t)0] ==
'#') {
215 G4int rc= ExecCommand(newCommand);
222 return previousSession;
230 G4cout <<
"Pause session <" << Prompt <<
"> start." <<
G4endl;
234 G4cout <<
"Pause session <" << Prompt <<
"> Terminate." <<
G4endl;
std::string::size_type str_size
@ fIllegalApplicationState
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4String strip(G4int strip_Type=trailing, char c=' ')
virtual G4UIsession * SessionStart()
G4UIbatch(const char *fileName, G4UIsession *prevSession=0)
virtual void PauseSessionStart(const G4String &Prompt)
static G4UImanager * GetUIpointer()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)