Ignore:
Timestamp:
Apr 29, 2008, 6:30:38 AM (18 years ago)
Author:
Frederik Heber <heber@…>
Children:
dac5c5
Parents:
661288
Message:

config::Load..() now get filename instead of pointer to file, bugfix for switch structure in command line parsin
g.

Load..() functions RetrieveConfigPath() - the path that is given for the config file on the command line - and p
ut it into config::configpath. This is necessary to allow later for a sensible storage path under fragmentation, as the old with defaultpath from the file was stupid, if the given path was wrong (whereas the config path always exists).
Switch structure in parsing the command line options needed to make better use of the already present flag in or
der to know when to just save and stop and when to continue to the interactive menu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/config.cpp

    r661288 rf5306f  
    1616  defaultpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
    1717  pseudopotpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
     18  configpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
    1819  strcpy(mainname,"pcp");
    19   strcpy(defaultpath,"not specified                                                                                                                                                                                                                                               ");
    20   strcpy(pseudopotpath,"not specified                                                                                                                                                                                                                                               ");
     20  strcpy(defaultpath,"not specified");
     21  strcpy(pseudopotpath,"not specified");
    2122 
    2223  ProcPEGamma=8;
     
    8687  Free((void **)&defaultpath, "config::~config: *defaultpath");
    8788  Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
     89  Free((void **)&configpath, "config::~config: *configpath");
    8890};
    8991
     
    352354
    353355/** Tests whether a given configuration file adhears to old or new syntax.
    354  * \param *file input file stream being the opened config file
     356 * \param *filename filename of config file to be tested
    355357 * \param *periode pointer to a periodentafel class with all elements
    356358 * \param *mol pointer to molecule containing all atoms of the molecule
    357359 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
    358360 */
    359 int config::TestSyntax(ifstream *file, periodentafel *periode, molecule *mol)
     361int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
    360362{
    361363  int test;
     364  ifstream file(filename);
     365 
    362366  // 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();
    364369    return 1;
     370  }
    365371  // 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();
    367374    return 0;
     375  }
     376  file.close();
    368377  return -1;
    369378}
     
    394403};
    395404
     405/** Retrieves the path in the given config file name.
     406 * \param *filename config file string
     407 */
     408void 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
    396428/** Initializes config file structure by loading elements from a give file.
    397429 * \param *file input file stream being the opened config file
     
    399431 * \param *mol pointer to molecule containing all atoms of the molecule
    400432 */
    401 void config::Load(ifstream *file, periodentafel *periode, molecule *mol)
     433void config::Load(char *filename, periodentafel *periode, molecule *mol)
    402434{
     435  ifstream *file = new ifstream(filename);
     436  if (file == NULL) {
     437    cerr << "ERROR: config file " << filename << " missing!" << endl;
     438    return;
     439  }
     440  RetrieveConfigPath(filename);
    403441  // ParseParameters
    404442 
     
    615653    }
    616654  }
     655  file->close();
     656  delete(file);
    617657};
    618658
     
    622662 * \param *mol pointer to molecule containing all atoms of the molecule
    623663 */
    624 void config::LoadOld(ifstream *file, periodentafel *periode, molecule *mol)
     664void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
    625665{
     666  ifstream *file = new ifstream(filename);
     667  if (file == NULL) {
     668    cerr << "ERROR: config file " << filename << " missing!" << endl;
     669    return;
     670  }
     671  RetrieveConfigPath(filename);
    626672  // ParseParameters
    627673 
     
    810856    }
    811857  }   
     858  file->close();
     859  delete(file);
    812860};
    813861
Note: See TracChangeset for help on using the changeset viewer.