39 const char* delimiter =
" ";
41 G4String::size_type pos0 = str.find_first_not_of(delimiter);
42 G4String::size_type
pos = str.find_first_of(delimiter, pos0);
44 while(pos != G4String::npos || pos0 != G4String::npos)
48 pos = str.find_first_of(
"\"", pos0 + 1);
49 if(pos != G4String::npos)
54 pos = str.find_first_of(
"\'", pos0 + 1);
55 if(pos != G4String::npos)
59 tokens.push_back(str.substr(pos0, pos - pos0));
60 pos0 = str.find_first_not_of(delimiter, pos);
61 pos = str.find_first_of(delimiter, pos0);
68 , previousSession(prevSession)
70 macroStream.open(fileName, std::ios::in);
71 if(macroStream.fail())
73 G4cerr <<
"ERROR: Can not open a macro file <" << fileName
74 <<
">. Set macro path with \"/control/macroPath\" if needed."
102 linebuf =
new char[BUFSIZE];
103 const char ctrM = 0x0d;
106 G4bool qcontinued =
false;
107 while(macroStream.good())
109 macroStream.getline(linebuf, BUFSIZE);
115 while((nb = cmdline.find(
'\t', nb)) != G4String::npos)
117 cmdline.replace(nb, 1,
" ");
125 if(!qcontinued && cmdline.size() == 0)
129 if(cmdline[(std::size_t) 0] ==
'#')
133 std::vector<G4String> tokens;
136 for(
G4int i = 0; i <
G4int(tokens.size()); ++i)
139 if(tokens[i][(std::size_t) 0] ==
'#')
142 if(tokens[i] ==
'\\' || tokens[i] ==
'_')
146 if(i !=
G4int(tokens.size()) - 1)
149 "unexpected character after line continuation character");
153 cmdtotal += tokens[i];
160 if(cmdtotal.size() != 0)
162 if(macroStream.eof())
170 if(macroStream.eof() && cmdtotal.size() == 0)
189 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" <<
G4endl;
192 G4cerr <<
"***** Illegal application state <" << command <<
"> *****"
197 G4cerr <<
"***** Illegal parameter (" <<
pn <<
") <" << command
208 return previousSession;
212 G4String newCommand = ReadCommand();
214 if(newCommand ==
"exit")
220 if(newCommand[(std::size_t) 0] ==
'#')
230 G4int rc = ExecCommand(newCommand);
239 return previousSession;
245 G4cout <<
"Pause session <" << Prompt <<
"> start." <<
G4endl;
249 G4cout <<
"Pause session <" << Prompt <<
"> Terminate." <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::string::size_type str_size
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4String strip(G4int strip_Type=trailing, char c=' ')
virtual G4UIsession * SessionStart()
G4UIbatch(const char *fileName, G4UIsession *prevSession=nullptr)
virtual void PauseSessionStart(const G4String &Prompt)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)