Commit 8ff1b66a authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Fixed Parameters.cc (valgrind reported some errors)

parent 37322782
...@@ -20,61 +20,53 @@ namespace AMDiS { ...@@ -20,61 +20,53 @@ namespace AMDiS {
int Parameters::getGlobalParameter(int info, const ::std::string& key, int Parameters::getGlobalParameter(int info, const ::std::string& key,
const char *format, ...) const char *format, ...)
{ {
FUNCNAME("Parameters::getGlobalParameter"); FUNCNAME("Parameters::getGlobalParameter()");
int count, *ival;
int count, *ival;
::std::vector<struct Parameters::param>::iterator i; ::std::vector<struct Parameters::param>::iterator i;
char *sval, *cval; char *sval, *cval;
const char *word; const char *word;
::std::string s; ::std::string s;
const char *p; const char *p;
double *rval; double *rval;
unsigned char *Uval; unsigned char *Uval;
char *Sval; char *Sval;
double dval; double dval;
param tParam(key); param tParam(key);
const char* funcName2 = param_call_fct ? param_call_fct : funcName; const char* funcName2 = param_call_fct ? param_call_fct : funcName;
va_list arg;
va_list arg;
Parameters::initIntern(); Parameters::initIntern();
if (Parameters::singlett->paramInfo) if (Parameters::singlett->paramInfo) {
{ if (Parameters::singlett->paramInfo > 1)
if (Parameters::singlett->paramInfo > 1) info = max(info, Parameters::singlett->paramInfo-1);
info = max(info, Parameters::singlett->paramInfo-1); } else {
}
else
info = 0; info = 0;
}
if (0==Parameters::singlett->allParam.size()) if (0 == Parameters::singlett->allParam.size()) {
{ if (0==Parameters::singlett->filename.size()) {
if (0==Parameters::singlett->filename.size()) INFO(info,1)("no parameters defined\n");
{ return(0);
INFO(info,1)("no parameters defined\n"); } else {
return(0); Parameters::singlett->read(Parameters::singlett->filename,key);
}
else
{
Parameters::singlett->read(Parameters::singlett->filename,key);
}
} }
}
i = ::std::find(Parameters::singlett->allParam.begin(),Parameters::singlett->allParam.end(),tParam); i = ::std::find(Parameters::singlett->allParam.begin(),Parameters::singlett->allParam.end(),tParam);
if (i == Parameters::singlett->allParam.end()) if (i == Parameters::singlett->allParam.end()) {
{ if (funcName != funcName2) {
if (funcName != funcName2) INFO(info,1)("initialization of parameter `%s'\n", key.data());
{ INFO(info,1)("fails on line %d of file %s\n", param_call_line,
INFO(info,1)("initialization of parameter `%s'\n", key.data()); param_call_file);
INFO(info,1)("fails on line %d of file %s\n", param_call_line, } else {
param_call_file); INFO(info,1)("initialization of parameter `%s' fails\n", key.data());
}
else
INFO(info,1)("initialization of parameter `%s' fails\n", key.data());
// param_call_fct = NULL;
return(0);
} }
return(0);
}
va_start(arg, format); va_start(arg, format);
count = 0; count = 0;
...@@ -83,103 +75,89 @@ namespace AMDiS { ...@@ -83,103 +75,89 @@ namespace AMDiS {
s = (*i).parameters; s = (*i).parameters;
for (p = format; *p; p++) for (p = format; *p; p++) {
{ if (*p != '%')
if (*p != '%') continue; continue;
word = Parameters::singlett->getNextWord(&s); word = Parameters::singlett->getNextWord(&s);
if (!*word) if (!*word) {
{ PRINT_INFO(info,2)("\n");
PRINT_INFO(info,2)("\n"); if (0<(*i).funcName.size()) {
if (0<(*i).funcName.size()) INFO(info,4)("parameter initialized by %s()\n",
{ (*i).funcName.data());
INFO(info,4)("parameter initialized by %s()\n", INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
(*i).funcName.data()); (*i).filename.data());
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo, } else if (0<(*i).filename.size()) {
(*i).filename.data()); INFO(info,4)
} ("parameter initialized on line %2d of init file \"%s\"\n",
else if (0<(*i).filename.size()) (*i).lineNo, (*i).filename.data());
{ } else {
INFO(info,4) INFO(info,4)("location of initialization unknown\n");
("parameter initialized on line %2d of init file \"%s\"\n", }
(*i).lineNo, (*i).filename.data()); va_end(arg);
} return(count);
else
{
INFO(info,4)("location of initialization unknown\n");
}
va_end(arg);
return(count);
}
count++;
switch(*++p)
{
case 'S':
Sval = va_arg(arg, char *);
*Sval = static_cast<char>(atoi(word));
INFO(info,2)("%d ", *Sval);
break;
case 'U':
Uval = va_arg(arg, unsigned char *);
*Uval = static_cast<unsigned char>(atoi(word));
INFO(info,2)("%d ", *Uval);
break;
case 'c':
cval = va_arg(arg, char *);
*cval = *word;
INFO(info,2)("%c ", *cval);
break;
case 's':
sval = va_arg(arg, char *);
strcpy(sval, word);
INFO(info,2)("%s ", sval);
break;
case 'd':
ival = va_arg(arg, int *);
*ival = atoi(word);
INFO(info,2)("%d ", *ival);
break;
case 'e':
case 'f':
case 'g':
rval = va_arg(arg, double *);
*rval = dval = atof(word);
INFO(info,2)("%g ", dval);
break;
case '*':
break;
default:
INFO(info,2)("\n");
INFO(info,2)
("unknow format specifier `%%%c', skipping initialization of %s\n",
*p, key.data());
}
} }
count++;
switch(*++p) {
case 'S':
Sval = va_arg(arg, char *);
*Sval = static_cast<char>(atoi(word));
INFO(info,2)("%d ", *Sval);
break;
case 'U':
Uval = va_arg(arg, unsigned char *);
*Uval = static_cast<unsigned char>(atoi(word));
INFO(info,2)("%d ", *Uval);
break;
case 'c':
cval = va_arg(arg, char *);
*cval = *word;
INFO(info,2)("%c ", *cval);
break;
case 's':
sval = va_arg(arg, char *);
strcpy(sval, word);
INFO(info,2)("%s ", sval);
break;
case 'd':
ival = va_arg(arg, int *);
*ival = atoi(word);
INFO(info,2)("%d ", *ival);
break;
case 'e':
case 'f':
case 'g':
rval = va_arg(arg, double *);
*rval = dval = atof(word);
INFO(info,2)("%g ", dval);
break;
case '*':
break;
default:
INFO(info,2)("\n");
INFO(info,2)
("unknow format specifier `%%%c', skipping initialization of %s\n",
*p, key.data());
}
}
INFO(info,2)("\n"); INFO(info,2)("\n");
// if (funcName != func_name)
// INFO(info,2)("on line %d of file %s\n", param_call_line, param_call_file);
if ((*i).funcName.size()>0) if ((*i).funcName.size() > 0) {
{ INFO(info,4)("parameter initialized by %s()\n", (*i).funcName.data());
INFO(info,4)("parameter initialized by %s()\n", (*i).funcName.data()); INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo, (*i).filename.data());
(*i).filename.data()); } else if ((*i).filename.size() > 0) {
} INFO(info,4)
else if ((*i).filename.size()>0) ("parameter initialized on line %2d of init file \"%s\"\n",
{ (*i).lineNo, (*i).filename.data());
INFO(info,4) } else {
("parameter initialized on line %2d of init file \"%s\"\n", INFO(info,4)("location of initialization unknown\n");
(*i).lineNo, (*i).filename.data()); }
}
else
{
INFO(info,4)("location of initialization unknown\n");
}
va_end(arg); va_end(arg);
// param_call_fct = NULL;
return(count); return(count);
} }
...@@ -198,8 +176,8 @@ namespace AMDiS { ...@@ -198,8 +176,8 @@ namespace AMDiS {
{ {
FUNCNAME("Parameters::read()"); FUNCNAME("Parameters::read()");
char line[256]; char line[256];
int nLine = 0; int nLine = 0;
::std::string key, parameter; ::std::string key, parameter;
::std::string actfile; ::std::string actfile;
...@@ -212,11 +190,9 @@ namespace AMDiS { ...@@ -212,11 +190,9 @@ namespace AMDiS {
return; return;
} }
if (!cppRead) { INFO(paramInfo,2)("reading from file %s\n", aFilename.data());
INFO(paramInfo,2)("reading from file %s\n", aFilename.data()); actfile = getActFile(aFilename);
actfile = getActFile(aFilename);
}
while (!inputFile.eof()) { while (!inputFile.eof()) {
inputFile.getline(line, 255); inputFile.getline(line, 255);
nLine++; nLine++;
...@@ -225,19 +201,6 @@ namespace AMDiS { ...@@ -225,19 +201,6 @@ namespace AMDiS {
if (key == "") if (key == "")
continue; continue;
if (cppRead && key[0] == '#') {
int pos=0;
sscanf(key.data(), "#%d", &nLine);
nLine--;
pos=key.find('\"');
pos=key.find('\"',pos+1);
key.resize(pos);
actfile = getActFile(key);
continue;
}
parameter = getPar(key, line, &nLine, aFilename); parameter = getPar(key, line, &nLine, aFilename);
if (parameter == "") if (parameter == "")
...@@ -254,22 +217,21 @@ namespace AMDiS { ...@@ -254,22 +217,21 @@ namespace AMDiS {
const ::std::string& Parameters::getActFile(const ::std::string& aFilename) const ::std::string& Parameters::getActFile(const ::std::string& aFilename)
{ {
FUNCNAME("Parameters::getActFile"); FUNCNAME("Parameters::getActFile()");
::std::list< ::std::string>::iterator i;
::std::string actfile; ::std::list< ::std::string >::iterator i;
::std::string actfile;
for (i = filenames.begin(); i != filenames.end(); i++) for (i = filenames.begin(); i != filenames.end(); i++)
if (aFilename==*i) break; if (aFilename==*i)
break;
if (i != filenames.end()) if (i != filenames.end()) {
{ return(const_cast<const ::std::string&>(*i));
return(const_cast<const ::std::string&>(*i)); } else {
} filenames.push_back(aFilename);
else return(const_cast<const ::std::string&>(aFilename));
{ }
filenames.push_back(aFilename);
return(const_cast<const ::std::string&>(aFilename));
}
} }
void Parameters::swap(int i, int j) void Parameters::swap(int i, int j)
...@@ -302,96 +264,85 @@ namespace AMDiS { ...@@ -302,96 +264,85 @@ namespace AMDiS {
const ::std::string Parameters::getKey(const ::std::string& s, int nLine, const ::std::string Parameters::getKey(const ::std::string& s, int nLine,
const ::std::string& aFilename) const ::std::string& aFilename)
{ {
FUNCNAME("Parameters::getKey"); FUNCNAME("Parameters::getKey()");
::std::string fn,key="";
char c;
int i,pos,epos;
::std::string h=" \t\r\f";
if (cppRead) ::std::string fn, key="";
{ char c;
if (s[0] == '#') /* Praeprozessor line */ int i, epos;
return(s); ::std::string h= " \t\r\f";
}
pos=0; int pos = 0;
pos=s.find_first_not_of(" \t\f\r"); //skip Blank pos = s.find_first_not_of(" \t\f\r"); //skip Blank
if(pos < 0) if (pos < 0)
return key; return key;
if (s[pos] == comment || s[pos] == '\0' || s[pos] == '\n') if (s[pos] == comment || s[pos] == '\0' || s[pos] == '\n')
return(key); return(key);
if (s[pos] == '#') if (s[pos] == '#') {
{ if (static_cast<int>(s.find("#include")) == pos) {
if (static_cast<int>(s.find("#include")) == pos) /****************************************************************************/
/****************************************************************************/ /* another init file has to be included */
/* another init file has to be included */ /****************************************************************************/
/****************************************************************************/
{ pos += strlen("#include");
pos += strlen("#include"); pos=s.find_first_not_of(" \t\f\r");
pos=s.find_first_not_of(" \t\f\r");
i = 0;
i = 0; switch (c = s[pos++]) {
switch (c = s[pos++]) case '<':
{ c = '>';
case '<': case '\"':
c = '>'; h+=c;
case '\"': epos=s.find_first_not_of(h,pos);
h+=c; fn = s.substr(pos,epos-1);
epos=s.find_first_not_of(h,pos);
fn = s.substr(pos,epos-1);
if (s[epos] != c) if (s[epos] != c) {
{ ERROR("aFilename of include not terminated by %c\n", c);
ERROR("aFilename of include not terminated by %c\n", c); ERROR("skipping line %d of file %s\n", nLine, aFilename.c_str());
ERROR("skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
break;
default:
ERROR("no aFilename of include file found\n");
ERROR("skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
read(fn);
return("");
}
else
{
ERROR("# must not be the first character on a line; except #include\n");
return(""); return("");
} }
break;
default:
ERROR("no aFilename of include file found\n");
ERROR("skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
read(fn);
return("");
} else {
ERROR("# must not be the first character on a line; except #include\n");
return("");
} }
}
/****************************************************************************/ /****************************************************************************/
/* now get the key */ /* now get the key */
/****************************************************************************/ /****************************************************************************/
i = 0; i = 0;
epos=s.find_first_of(":#",pos+1); epos=s.find_first_of(":#",pos+1);
if (s[epos] == '#') if (s[epos] == '#') {
{ ERROR("key must not contain '%c'.\n", '#');
ERROR("key must not contain '%c'.\n", '#'); ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str()); return("");
return(""); }
}
key= s.substr(pos,epos); key = s.substr(pos,epos);
if (s[epos] != ':') if (s[epos] != ':') {
{ ERROR("key was not terminated by ':'.\n");
ERROR("key was not terminated by ':'.\n"); ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str()); return("");
return(""); }
}
if (key.size() == 0) {
ERROR("use of ':' without key.\n");
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
if (key.size() == 0)
{
ERROR("use of ':' without key.\n");
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
return(key); return(key);
} }
......
...@@ -351,7 +351,11 @@ namespace AMDiS { ...@@ -351,7 +351,11 @@ namespace AMDiS {
int nLine, int nLine,
const ::std::string& fname); const ::std::string& fname);
Parameters() {}; Parameters()
: paramInfo(1),
msgInfo(1),
msgWait(1)
{};
virtual ~Parameters() {}; virtual ~Parameters() {};
...@@ -365,7 +369,6 @@ namespace AMDiS { ...@@ -365,7 +369,6 @@ namespace AMDiS {
private: private:
::std::string cppFlags; ::std::string cppFlags;
bool cppRead;
::std::ifstream inputFile; ::std::ifstream inputFile;
::std::list< ::std::string> filenames; ::std::list< ::std::string> filenames;
size_t maxFiles; size_t maxFiles;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment