[Plib-users] ssgParser, losing tokens? please help me!
Brought to you by:
sjbaker
|
From: Simon <sim...@ho...> - 2003-04-11 12:45:37
|
Hi all, I've been trying to use the ssgParser to parse through a text
file and read it into a tree. The problem that I have is that im
reading 3 part lines in one at a time and in the third section the
second word is ALWAYS dropped. This may be easier with an example:
0 HEAD
1 CHAR ASCII
1 ADDR Submitters address
2 CONT address was continued here and here
(gedcom format)
ok well in this example the first two lines will read in fine but the
word "address" on line 3 will be skipped and the word "was" on the last
line will be missed. I reached this point on the first day of writing
my code and spent around a week trying to fix it. I figured in the end
that it couldn't be my code and that it must be ssgParser so downloaded
the latest CVS ssgParser and still have no success. The exact same
problem which now makes me think that it must just be my code. Can
someone take a look at the following and tell me where im going wrong.
Its now been two weeks stuck on the same problem and I think that I am
too far into the code to see something really obviously wrong.
static int parse()
{
bool firsttime = true;
char* token;
int startLevel = parser.level;
//Create the tree using the header as the root node. This works
since there
//can only be one header in a gedcom transmission.
tree<gedcom_line> tr;
tree<gedcom_line>::iterator root, trHeader;
root=tr.begin();
char *tempWord;
char *tokCopy;
while ((token = parser.getLine( startLevel )) != NULL)
{
if (firsttime)
{
if (strcmp(token,"0"))
{
parser.error("Not gedcom
format, invalid header");
return false ;
}
level = atoi(token);
parser.expect(" ");
token = parser.getNextToken(0);
if (strcmp(token,"HEAD"))
{
parser.error("Not gedcom
format, invalid header");
return false ;
}
tag = token;
line_value = "";
//Create the first structure in the tree -
The Header...checkout the
//string to int function - atoi(const char*)
gedcom_line *Header = new gedcom_line;
Header->level = level;
Header->tag = tag;
Header->line_value = line_value;
trHeader=tr.insert(root, *Header);
firsttime = false;
}
else
{
/* problem starts around here, the code in the if statement above deals
with the first line i.e. 0 HEAD as gedcom filetype validation. This
next bit deals with every other line
A typical line consists of : level(space)tag(space)line_Value.
It is the line_Value area that is not working */
level = atoi(token);
parser.expect(" ");
tag = parser.getNextToken(0);
line_value2 = parser.getNextToken(0);
if(strcmp(line_value2, "\n") == 0)
{
line_value = "";
}
else
{//it probably equals a sqace then
line_value = parser.getNextToken(0);
bool running = true;
while(running)
{
tempVal =
parser.parseToken(0);
if(strcmp(tempVal, "\n")
!= 0)
{
strcat(line_value, tempVal);
}
else
{
tempVal
= "";
running
= false;
}
}
}
gedcom_line *newNode = new
gedcom_line;
newNode->level = level;
newNode->tag = tag;
newNode->line_value = line_value;
trHeader=tr.insert(root,
*newNode);
level = 0;
tag = "";
line_value = "";
}
}
return true ;
}
Thanks in advance
Simon
|