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 {
int Parameters::getGlobalParameter(int info, const ::std::string& key,
const char *format, ...)
{
FUNCNAME("Parameters::getGlobalParameter");
int count, *ival;
FUNCNAME("Parameters::getGlobalParameter()");
int count, *ival;
::std::vector<struct Parameters::param>::iterator i;
char *sval, *cval;
char *sval, *cval;
const char *word;
::std::string s;
const char *p;
double *rval;
unsigned char *Uval;
char *Sval;
double dval;
param tParam(key);
const char *p;
double *rval;
unsigned char *Uval;
char *Sval;
double dval;
param tParam(key);
const char* funcName2 = param_call_fct ? param_call_fct : funcName;
va_list arg;
va_list arg;
Parameters::initIntern();
if (Parameters::singlett->paramInfo)
{
if (Parameters::singlett->paramInfo > 1)
info = max(info, Parameters::singlett->paramInfo-1);
}
else
if (Parameters::singlett->paramInfo) {
if (Parameters::singlett->paramInfo > 1)
info = max(info, Parameters::singlett->paramInfo-1);
} else {
info = 0;
}
if (0==Parameters::singlett->allParam.size())
{
if (0==Parameters::singlett->filename.size())
{
INFO(info,1)("no parameters defined\n");
return(0);
}
else
{
Parameters::singlett->read(Parameters::singlett->filename,key);
}
if (0 == Parameters::singlett->allParam.size()) {
if (0==Parameters::singlett->filename.size()) {
INFO(info,1)("no parameters defined\n");
return(0);
} else {
Parameters::singlett->read(Parameters::singlett->filename,key);
}
}
i = ::std::find(Parameters::singlett->allParam.begin(),Parameters::singlett->allParam.end(),tParam);
if (i == Parameters::singlett->allParam.end())
{
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,
param_call_file);
}
else
INFO(info,1)("initialization of parameter `%s' fails\n", key.data());
// param_call_fct = NULL;
return(0);
if (i == Parameters::singlett->allParam.end()) {
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,
param_call_file);
} else {
INFO(info,1)("initialization of parameter `%s' fails\n", key.data());
}
return(0);
}
va_start(arg, format);
count = 0;
......@@ -83,103 +75,89 @@ namespace AMDiS {
s = (*i).parameters;
for (p = format; *p; p++)
{
if (*p != '%') continue;
word = Parameters::singlett->getNextWord(&s);
if (!*word)
{
PRINT_INFO(info,2)("\n");
if (0<(*i).funcName.size())
{
INFO(info,4)("parameter initialized by %s()\n",
(*i).funcName.data());
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
(*i).filename.data());
}
else if (0<(*i).filename.size())
{
INFO(info,4)
("parameter initialized on line %2d of init file \"%s\"\n",
(*i).lineNo, (*i).filename.data());
}
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());
}
for (p = format; *p; p++) {
if (*p != '%')
continue;
word = Parameters::singlett->getNextWord(&s);
if (!*word) {
PRINT_INFO(info,2)("\n");
if (0<(*i).funcName.size()) {
INFO(info,4)("parameter initialized by %s()\n",
(*i).funcName.data());
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
(*i).filename.data());
} else if (0<(*i).filename.size()) {
INFO(info,4)
("parameter initialized on line %2d of init file \"%s\"\n",
(*i).lineNo, (*i).filename.data());
} 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());
}
}
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)
{
INFO(info,4)("parameter initialized by %s()\n", (*i).funcName.data());
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
(*i).filename.data());
}
else if ((*i).filename.size()>0)
{
INFO(info,4)
("parameter initialized on line %2d of init file \"%s\"\n",
(*i).lineNo, (*i).filename.data());
}
else
{
INFO(info,4)("location of initialization unknown\n");
}
if ((*i).funcName.size() > 0) {
INFO(info,4)("parameter initialized by %s()\n", (*i).funcName.data());
INFO(info,4)("on line %d of file \"%s\"\n", (*i).lineNo,
(*i).filename.data());
} else if ((*i).filename.size() > 0) {
INFO(info,4)
("parameter initialized on line %2d of init file \"%s\"\n",
(*i).lineNo, (*i).filename.data());
} else {
INFO(info,4)("location of initialization unknown\n");
}
va_end(arg);
// param_call_fct = NULL;
return(count);
}
......@@ -198,8 +176,8 @@ namespace AMDiS {
{
FUNCNAME("Parameters::read()");
char line[256];
int nLine = 0;
char line[256];
int nLine = 0;
::std::string key, parameter;
::std::string actfile;
......@@ -212,11 +190,9 @@ namespace AMDiS {
return;
}
if (!cppRead) {
INFO(paramInfo,2)("reading from file %s\n", aFilename.data());
actfile = getActFile(aFilename);
}
INFO(paramInfo,2)("reading from file %s\n", aFilename.data());
actfile = getActFile(aFilename);
while (!inputFile.eof()) {
inputFile.getline(line, 255);
nLine++;
......@@ -225,19 +201,6 @@ namespace AMDiS {
if (key == "")
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);
if (parameter == "")
......@@ -254,22 +217,21 @@ namespace AMDiS {
const ::std::string& Parameters::getActFile(const ::std::string& aFilename)
{
FUNCNAME("Parameters::getActFile");
::std::list< ::std::string>::iterator i;
::std::string actfile;
FUNCNAME("Parameters::getActFile()");
::std::list< ::std::string >::iterator i;
::std::string actfile;
for (i = filenames.begin(); i != filenames.end(); i++)
if (aFilename==*i) break;
if (aFilename==*i)
break;
if (i != filenames.end())
{
return(const_cast<const ::std::string&>(*i));
}
else
{
filenames.push_back(aFilename);
return(const_cast<const ::std::string&>(aFilename));
}
if (i != filenames.end()) {
return(const_cast<const ::std::string&>(*i));
} else {
filenames.push_back(aFilename);
return(const_cast<const ::std::string&>(aFilename));
}
}
void Parameters::swap(int i, int j)
......@@ -302,96 +264,85 @@ namespace AMDiS {
const ::std::string Parameters::getKey(const ::std::string& s, int nLine,
const ::std::string& aFilename)
{
FUNCNAME("Parameters::getKey");
::std::string fn,key="";
char c;
int i,pos,epos;
::std::string h=" \t\r\f";
FUNCNAME("Parameters::getKey()");
if (cppRead)
{
if (s[0] == '#') /* Praeprozessor line */
return(s);
}
pos=0;
pos=s.find_first_not_of(" \t\f\r"); //skip Blank
::std::string fn, key="";
char c;
int i, epos;
::std::string h= " \t\r\f";
int pos = 0;
pos = s.find_first_not_of(" \t\f\r"); //skip Blank
if(pos < 0)
if (pos < 0)
return key;
if (s[pos] == comment || s[pos] == '\0' || s[pos] == '\n')
return(key);
if (s[pos] == '#')
{
if (static_cast<int>(s.find("#include")) == pos)
/****************************************************************************/
/* another init file has to be included */
/****************************************************************************/
{
pos += strlen("#include");
pos=s.find_first_not_of(" \t\f\r");
i = 0;
switch (c = s[pos++])
{
case '<':
c = '>';
case '\"':
h+=c;
epos=s.find_first_not_of(h,pos);
fn = s.substr(pos,epos-1);
if (s[pos] == '#') {
if (static_cast<int>(s.find("#include")) == pos) {
/****************************************************************************/
/* another init file has to be included */
/****************************************************************************/
pos += strlen("#include");
pos=s.find_first_not_of(" \t\f\r");
i = 0;
switch (c = s[pos++]) {
case '<':
c = '>';
case '\"':
h+=c;
epos=s.find_first_not_of(h,pos);
fn = s.substr(pos,epos-1);
if (s[epos] != c)
{
ERROR("aFilename of include not terminated by %c\n", c);
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");
if (s[epos] != c) {
ERROR("aFilename of include not terminated by %c\n", c);
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("");
}
}
/****************************************************************************/
/* now get the key */
/****************************************************************************/
i = 0;
epos=s.find_first_of(":#",pos+1);
if (s[epos] == '#')
{
ERROR("key must not contain '%c'.\n", '#');
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
if (s[epos] == '#') {
ERROR("key must not contain '%c'.\n", '#');
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
key= s.substr(pos,epos);
key = s.substr(pos,epos);
if (s[epos] != ':')
{
ERROR("key was not terminated by ':'.\n");
ERROR("Skipping line %d of file %s\n", nLine, aFilename.c_str());
return("");
}
if (s[epos] != ':') {
ERROR("key was not terminated by ':'.\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("");
}
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);
}
......
......@@ -351,7 +351,11 @@ namespace AMDiS {
int nLine,
const ::std::string& fname);
Parameters() {};
Parameters()
: paramInfo(1),
msgInfo(1),
msgWait(1)
{};
virtual ~Parameters() {};
......@@ -365,7 +369,6 @@ namespace AMDiS {
private:
::std::string cppFlags;
bool cppRead;
::std::ifstream inputFile;
::std::list< ::std::string> filenames;
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