Changeset f5306f for molecuilder/src/config.cpp
- Timestamp:
- Apr 29, 2008, 6:30:38 AM (18 years ago)
- Children:
- dac5c5
- Parents:
- 661288
- File:
-
- 1 edited
-
molecuilder/src/config.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/config.cpp
r661288 rf5306f 16 16 defaultpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname"); 17 17 pseudopotpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname"); 18 configpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname"); 18 19 strcpy(mainname,"pcp"); 19 strcpy(defaultpath,"not specified ");20 strcpy(pseudopotpath,"not specified ");20 strcpy(defaultpath,"not specified"); 21 strcpy(pseudopotpath,"not specified"); 21 22 22 23 ProcPEGamma=8; … … 86 87 Free((void **)&defaultpath, "config::~config: *defaultpath"); 87 88 Free((void **)&pseudopotpath, "config::~config: *pseudopotpath"); 89 Free((void **)&configpath, "config::~config: *configpath"); 88 90 }; 89 91 … … 352 354 353 355 /** Tests whether a given configuration file adhears to old or new syntax. 354 * \param *file input file stream being the opened config file356 * \param *filename filename of config file to be tested 355 357 * \param *periode pointer to a periodentafel class with all elements 356 358 * \param *mol pointer to molecule containing all atoms of the molecule 357 359 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax 358 360 */ 359 int config::TestSyntax( ifstream *file, periodentafel *periode, molecule *mol)361 int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol) 360 362 { 361 363 int test; 364 ifstream file(filename); 365 362 366 // search file for keyword: ProcPEGamma (new syntax) 363 if (ParseForParameter(1,file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) 367 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) { 368 file.close(); 364 369 return 1; 370 } 365 371 // search file for keyword: ProcsGammaPsi (old syntax) 366 if (ParseForParameter(1,file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) 372 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) { 373 file.close(); 367 374 return 0; 375 } 376 file.close(); 368 377 return -1; 369 378 } … … 394 403 }; 395 404 405 /** Retrieves the path in the given config file name. 406 * \param *filename config file string 407 */ 408 void config::RetrieveConfigPath(char *filename) 409 { 410 int last = -1; 411 for(int i=0;i<255;i++) { 412 if (filename[i] == '/') 413 last = i; 414 if (filename[i] == '\0') 415 break; 416 } 417 if (last == -1) { // no path in front, set to local directory. 418 strcpy(configpath, "./"); 419 } else { 420 strncpy(configpath, filename, last+1); 421 if (last < 254) 422 configpath[last+1]='\0'; 423 } 424 cout << "Found configpath: " << configpath << ", dir slash was found at " << last << "." << endl; 425 }; 426 427 396 428 /** Initializes config file structure by loading elements from a give file. 397 429 * \param *file input file stream being the opened config file … … 399 431 * \param *mol pointer to molecule containing all atoms of the molecule 400 432 */ 401 void config::Load( ifstream *file, periodentafel *periode, molecule *mol)433 void config::Load(char *filename, periodentafel *periode, molecule *mol) 402 434 { 435 ifstream *file = new ifstream(filename); 436 if (file == NULL) { 437 cerr << "ERROR: config file " << filename << " missing!" << endl; 438 return; 439 } 440 RetrieveConfigPath(filename); 403 441 // ParseParameters 404 442 … … 615 653 } 616 654 } 655 file->close(); 656 delete(file); 617 657 }; 618 658 … … 622 662 * \param *mol pointer to molecule containing all atoms of the molecule 623 663 */ 624 void config::LoadOld( ifstream *file, periodentafel *periode, molecule *mol)664 void config::LoadOld(char *filename, periodentafel *periode, molecule *mol) 625 665 { 666 ifstream *file = new ifstream(filename); 667 if (file == NULL) { 668 cerr << "ERROR: config file " << filename << " missing!" << endl; 669 return; 670 } 671 RetrieveConfigPath(filename); 626 672 // ParseParameters 627 673 … … 810 856 } 811 857 } 858 file->close(); 859 delete(file); 812 860 }; 813 861
Note:
See TracChangeset
for help on using the changeset viewer.
