140{
142
143
144
145
146
147 G4int wsiz = wordlist.size();
149 for (ii = 0; ii < wsiz; ii++)
150 {
151 wordlist.pop_back();
152 }
153
154
155 const G4int NMAXLIN = 1000;
156 char ltemp[NMAXLIN];
157 for (;;)
158 {
159 (theLineNo[theCurrentFile])++;
160 for ( ii = 0; ii < NMAXLIN; ii++) { ltemp[ii] = ' '; }
161 theFiles[theCurrentFile]->getline( ltemp, NMAXLIN );
162
163
164 for ( ii=0; ii < NMAXLIN; ii++)
165 {
166 if ( ltemp[ii] == '\0' ) { break; }
167 }
168 if ( ii == NMAXLIN-1 )
169 {
171 G4String ErrMessage =
"Too long line. Please split it "
172 +
G4String(
"putting a '\\' at the end!");
173 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
175 }
176
177
179 {
180 return 0;
181 }
182
183
184 std::istringstream istr_line(ltemp);
185
186
187
189 char* tt = ltemp;
190
192 do
193 {
194 if( *tt != ' ' && *(tt) != '\0' )
195 {
196 if( tt == ltemp)
197 {
198 NoWords++;
199#ifdef G4VERBOSE
201 {
202 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
203 << NoWords << ltemp <<
G4endl;
204 }
205#endif
206 }
207 else if( *(tt-1) == ' ' || *(tt-1) == '\015' || *(tt-1) == '\t')
208 {
209 NoWords++;
210#ifdef G4VERBOSE
212 {
213 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
214 << NoWords << ltemp <<
G4endl;
215 }
216#endif
217 }
218 }
219 tt++;
220 } while((*tt != '\0') && (stemp.length()!=0));
221
222 if(stemp.length() == 0) { NoWords = 0; }
223
224
225 for( ii=0; ii < NoWords; ii++)
226 {
227 stemp = "";
228 istr_line >> stemp;
229 if ( stemp.length() == 0 ) { break; }
231#ifdef G4VERBOSE
233 {
234 G4cout <<
"!!!COMMENT" << comment << stemp.c_str() <<
G4endl;
235 }
236#endif
237 if ( comment == 0 )
238 {
239 break;
240 }
241 else if ( comment > 0 )
242 {
243 stemp = stemp.substr( 0, comment );
244 wordlist.push_back(stemp);
245 break;
246 }
247 wordlist.push_back(stemp);
248 }
249
250
251
252
253
254
255
256
257
258
259 if ( wordlist.size() != 0 )
260 {
261 if( (*(wordlist.end()-1)).compare("\\") == 0 )
262 {
263 wordlist.pop_back();
264 }
265 else
266 {
267 break;
268 }
269 }
270 }
271
272
273
274 std::vector<G4String> wordlist2;
276 unsigned int imerge = 0;
277 for( size_t jj = 0; jj < wordlist.size(); jj++)
278 {
279 if( wordlist[jj].substr(0,1) == "\"" )
280 {
281 imerge = 1;
282 }
283 if( wordlist[jj][ wordlist[jj].size()-1 ] == '\"' )
284 {
285 if( imerge != 1 )
286 {
287 G4String err1 =
" word with trailing '\"' while there is no";
288 G4String err2 =
" previous word with leading '\"' in line ";
291 }
292 imerge = 2;
293 }
294 if( imerge == 0 )
295 {
296 wordlist2.push_back( wordlist[jj] );
297 }
298 else if( imerge == 1 )
299 {
300 if( wordq == "" )
301 {
302 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()) );
303 }
304 else
305 {
306 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()) );
307 }
309 }
310 else if( imerge == 2 )
311 {
312 if( wordq == "" )
313 {
314 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()-2));
315 }
316 else
317 {
318 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()-1) );
319 }
320 wordlist2.push_back( wordq );
321 wordq = "";
322 imerge = 0;
323 }
324 }
325 if( imerge == 1 )
326 {
327 G4String err1 =
" word with leading '\"' in line while there is no";
328 G4String err2 =
" later word with trailing '\"' in line ";
331 }
332
333 wordlist = wordlist2;
334
335
336
337
338
339
340 if( wordlist[0] == "#include" )
341 {
342 if( wordlist.size() != 2 )
343 {
346 = "'#include' should have as second argument, the filename !";
347 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
349 }
350
351#ifdef G4VERBOSE
353 {
354 G4cout <<
" G4tgrFileIn::GetWordsInLine() - Include found !" <<
G4endl;
355 }
356#endif
359 }
360
361 return isok;
362}
G4String & append(const G4String &)
G4int GetWordsInLine(std::vector< G4String > &wl)
void DumpException(const G4String &sent)