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[(
G4int)pos0] ==
'\"') {
48 pos = str.find_first_of(
'\"', pos0 + 1);
49 if (pos != G4String::npos) {
53 if (str[(
G4int)pos0] ==
'\'') {
54 pos = str.find_first_of(
'\'', pos0 + 1);
55 if (pos != G4String::npos) {
60 tokens.emplace_back(str.substr(pos0, pos - pos0));
61 pos0 = str.find_first_not_of(delimiter, pos);
62 pos = str.find_first_of(delimiter, pos0);
70 macroStream.open(fileName, std::ios::in);
71 if (macroStream.fail()) {
72 G4cerr <<
"ERROR: Can not open a macro file <" << fileName
73 <<
">. Set macro path with \"/control/macroPath\" if needed." << G4endl;
74 lastRC = fParameterUnreadable;
99 if (linebuf ==
nullptr) {
100 linebuf =
new char[BUFSIZE];
102 const char ctrM = 0x0d;
105 G4bool qcontinued =
false;
106 while (macroStream.good()) {
107 macroStream.getline(linebuf, BUFSIZE);
112 G4String::size_type nb = 0;
113 while ((nb = cmdline.find(
'\t', nb)) != G4String::npos) {
114 cmdline.replace(nb, 1,
" ");
118 G4StrUtil::strip(cmdline);
119 G4StrUtil::rstrip(cmdline, ctrM);
122 if (!qcontinued && cmdline.empty()) {
127 if (cmdline[(std::size_t)0] ==
'#') {
132 std::vector<G4String> tokens;
135 for (
G4int i = 0; i <
G4int(tokens.size()); ++i) {
137 if (tokens[i][(std::size_t)0] ==
'#') {
141 if (tokens[i] ==
"\\" || tokens[i] ==
"_") {
144 if (i !=
G4int(tokens.size()) - 1) {
146 "unexpected character after line continuation character");
150 cmdtotal += tokens[i];
158 if (!cmdtotal.empty()) {
161 if (macroStream.eof()) {
167 G4StrUtil::strip(cmdtotal);
170 if (macroStream.eof() && cmdtotal.empty()) {
187 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" <<
G4endl;
190 G4cerr <<
"***** Illegal application state <" << command <<
"> *****" <<
G4endl;
194 G4cerr <<
"***** Illegal parameter (" <<
pn <<
") <" << command <<
"> *****" <<
G4endl;
204 return previousSession;
208 G4String newCommand = ReadCommand();
210 if (newCommand ==
"exit") {
215 if (newCommand[(std::size_t)0] ==
'#') {
223 G4int rc = ExecCommand(newCommand);
231 return previousSession;
237 G4cout <<
"Pause session <" << Prompt <<
"> start." <<
G4endl;
241 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)