Hello,
Thanks for the pointer. I rewrote the code, and here's what I came up with.
It still reads the bottom line twice, but the loop problem is solved, so I 
guess I can live with the bottom line being replicated, though I'd like to fix 
it at some point or another.
//code:
map<string,Var> ParseFile(string FileName)
{
map <string,Var> parsed; //will hold the parsed data
fstream input;
input.open(FileName.c_str(),fstream::in);
char data[128]; //the line as read from the file.
string line; //holds the line to be parsed.
string name; //the name of the variable.
string val; //the value of the variable.
string temp; //will be used for stripping out whitespace
Var variable; //the actual variable.
char v; //used to get a char from the file.
string::iterator top; //will be used to count.
string::iterator tracker; //another counter/placeholder iterator.
size_t index; //used to find '"' in strings.
size_t fq; //holds the position of the first quote.
size_t lq; //holds the position of the last quote.
int check=1; //used for controling our loop.

//we'll run until end of file is reached:
//runs until feof or end of line
//will also set the variable line up for parsing
while (std::getline(input,line))
{
top = line.begin();
//checks to see if we've got a comment.
if (*top=='#')
{
continue;
}
//will run until we see '='
//will split the variable and value apart.
for (top=line.begin();top<line.end();top++)
{
if (*top=='=')
{
name="";
//we found the name; lets take it off the line variable.
for (tracker=line.begin();tracker<top;tracker++)
{
name+=*tracker;
}
top++; //skip the '=' sign.
val="";
//retrieve the rest of the string.
for (tracker=top;tracker<line.end();tracker++)
{
val+=*tracker;
}
break;
}
}
temp="";
//now we'll run through the name and strip off whitespace.
for (top=name.begin();top<name.end();top++)
{
if (*top!=' ')
{
temp+=*top;
}
}
name=temp;
//now we find out what kind of variable val holds:
index=val.find('"');
if (index==string::npos)
{
//quote wasn't found, we've got ourselves an integer, boys and girls.
//we'll strip the spaces out:
temp="";
for (top=val.begin();top<val.end();top++)
{
if (*top!=' ')
{
temp+=*top;
}
}
val=temp;
//we'll initialize the variable, and clean it up
variable.type=TYPE_INT;
variable.str="";
variable.integer=atoi(val.c_str());
parsed[name.c_str()]=variable;
continue;
}
else
{
fq=val.find_first_of('"');
lq=val.find_last_of('"');
top=(val.begin()+fq);
temp="";
tracker=(val.begin()+lq);
for (top=top;top<tracker;top++)
{
temp+=*top;
}
variable.str=val;
variable.type=TYPE_STR;
variable.integer=0;
parsed[name.c_str()]=variable;
}
}
return parsed;
}


Thanks,
Tyler Littlefield
email: [EMAIL PROTECTED]
web: tysdomain-com
Visit for quality software and web design.
skype: st8amnd2005

  ----- Original Message ----- 
  From: John Matthews 
  To: [email protected] 
  Sent: Saturday, November 01, 2008 11:10 AM
  Subject: [c-prog] Re: c++ code help please?


  --- In [email protected], "Tyler Littlefield" <[EMAIL PROTECTED]> wrote:
  >
  > I tried playing with bison--I don't understand a bit of it.

  There's a great introduction to lex and yacc (on which bison is based)
  here:
  http://epaperpress.com/lexandyacc/index.html

  I would recommend giving it another go.

  John



   

[Non-text portions of this message have been removed]

Reply via email to