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)
46 if(str[(
G4int)pos0] ==
'\"')
48 pos = str.find_first_of(
"\"", pos0 + 1);
49 if(pos != G4String::npos)
54 if(str[(
G4int)pos0] ==
'\'')
56 pos = str.find_first_of(
"\'", pos0 + 1);
57 if(pos != G4String::npos)
63 tokens.emplace_back(str.substr(pos0, pos - pos0));
64 pos0 = str.find_first_not_of(delimiter, pos);
65 pos = str.find_first_of(delimiter, pos0);
72 , previousSession(prevSession)
74 macroStream.open(fileName, std::ios::in);
75 if(macroStream.fail())
77 G4cerr <<
"ERROR: Can not open a macro file <" << fileName
78 <<
">. Set macro path with \"/control/macroPath\" if needed."
107 if(linebuf ==
nullptr)
109 linebuf =
new char[BUFSIZE];
111 const char ctrM = 0x0d;
114 G4bool qcontinued =
false;
115 while(macroStream.good())
117 macroStream.getline(linebuf, BUFSIZE);
122 G4String::size_type nb = 0;
123 while((nb = cmdline.find(
'\t', nb)) != G4String::npos)
125 cmdline.replace(nb, 1,
" ");
133 if(!qcontinued && cmdline.empty())
139 if(cmdline[(std::size_t) 0] ==
'#')
145 std::vector<G4String> tokens;
148 for(
G4int i = 0; i <
G4int(tokens.size()); ++i)
151 if(tokens[i][(std::size_t) 0] ==
'#')
156 if(tokens[i] ==
"\\" || tokens[i] ==
"_")
160 if(i !=
G4int(tokens.size()) - 1)
163 "unexpected character after line continuation character");
167 cmdtotal += tokens[i];
176 if(!cmdtotal.empty())
180 if(macroStream.eof())
190 if(macroStream.eof() && cmdtotal.empty())
209 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" <<
G4endl;
212 G4cerr <<
"***** Illegal application state <" << command <<
"> *****"
217 G4cerr <<
"***** Illegal parameter (" <<
pn <<
") <" << command
229 return previousSession;
234 G4String newCommand = ReadCommand();
236 if(newCommand ==
"exit")
242 if(newCommand[(std::size_t) 0] ==
'#')
252 G4int rc = ExecCommand(newCommand);
261 return previousSession;
267 G4cout <<
"Pause session <" << Prompt <<
"> start." <<
G4endl;
271 G4cout <<
"Pause session <" << Prompt <<
"> Terminate." <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void PauseSessionStart(const G4String &Prompt) override
G4UIsession * SessionStart() override
G4UIbatch(const char *fileName, G4UIsession *prevSession=nullptr)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
void strip(G4String &str, char ch=' ')
Remove leading and trailing characters from string.
void rstrip(G4String &str, char ch=' ')
Remove trailing characters from string.