30#include "G4UIcommandStatus.hh"
31#include "G4UImanager.hh"
38void Tokenize(
const G4String& str, std::vector<G4String>& tokens)
40 const char* delimiter =
" ";
42 auto pos0 = str.find_first_not_of(delimiter);
43 auto pos = str.find_first_of(delimiter, pos0);
45 while (pos != G4String::npos || pos0 != G4String::npos) {
46 if (str[pos0] ==
'\"') {
47 pos = str.find_first_of(
"\"", pos0+1);
48 if(pos != G4String::npos) pos++;
50 if (str[pos0] ==
'\'') {
51 pos = str.find_first_of(
"\'", pos0+1);
52 if(pos != G4String::npos) pos++;
55 tokens.push_back(str.substr(pos0, pos-pos0));
56 pos0 = str.find_first_not_of(delimiter, pos);
57 pos = str.find_first_of(delimiter, pos0);
70 G4cerr <<
"cannot open a macro file(" << fname <<
")."
87 enum { BUFSIZE = 4096 };
88 static char linebuf[BUFSIZE];
91 G4bool qcontinued =
false;
98 G4String::size_type nb = 0;
99 while ((nb= cmdline.find(
'\t',nb)) != G4String::npos) {
100 cmdline.replace(nb, 1,
" ");
107 if( !qcontinued && cmdline.size() == 0 )
continue;
110 if( cmdline[0] ==
'#' )
return cmdline;
113 std::vector<G4String> tokens;
114 Tokenize(cmdline, tokens);
116 for( G4int i = 0; i < G4int(tokens.size()); i++ ) {
118 if( tokens[i][0] ==
'#' )
break;
120 if( tokens[i] ==
"\\" || tokens[i] ==
"_" ) {
123 if( i != G4int(tokens.size())-1 ) {
124 G4Exception(
"G4MPIbatch::ReadCommand",
"MPI004", JustWarning,
125 "unexpected character after line continuation character");
129 cmdtotal += tokens[i];
133 if( qcontinued )
continue;
135 if( cmdtotal.size() != 0 )
break;
157 g4mpi_-> BcastCommand(
"exit");
166 scommand =
g4mpi_-> BcastCommand(newCommand);
167 if( scommand ==
"exit" ) {
173 if( scommand[0] ==
'#' ) {
174 if( G4UImanager::GetUIpointer()-> GetVerboseLevel() == 2 ) {
175 G4cout << scommand << G4endl;
181 if ( rc != fCommandSucceeded ) {
182 G4cerr << G4endl <<
"***** Batch is interupted!! *****" << G4endl;
std::ifstream batch_stream_
virtual G4UIsession * SessionStart()
G4MPIbatch(const G4String &fname="", G4bool qbatch=false)
G4int ExecCommand(const G4String &acommand)
G4String BypassCommand(const G4String &command) const
void strip(G4String &str, char ch=' ')