16 Aug, 2010, Bojack wrote in the 1st comment:
Votes: 0
So im trying to come up with my own parser for just one command since I cant figure out how to code a parser like most people that takes a string and breaks it down nor a reference to look at so I came up with this as a test which doesnt work.

while (*argument != '\0')
{
if (*argument == '.' || *argument == '?'
|| *argument == '\n' || *argument == '\r'
|| granted == TRUE)
break;

*string = *argument;
string++;
argument++;

if (*argument == ' ')
{
if (is_name("immortality", string))
{
ch->immortality = 1;
granted = TRUE;
break;
}
}
}


What im trying to figure out is why it doesnt work correctly, it gets stuck in an infinite loop. What im trying to do is for one command it will take each word in a sentence and check it with a specific word either like that or will be in a list. If found it will do the function, I have more complex type sentences too but I just need something like this then I can figure out the rest. Any reference, code or help is appreciated.
16 Aug, 2010, David Haley wrote in the 2nd comment:
Votes: 0
How is it getting stuck in an infinite loop? The 'argument' variable advances at every iteration, so should eventually hit the null string. Where is the infinite loop? Have you run this through gdb?
16 Aug, 2010, ATT_Turan wrote in the 3rd comment:
Votes: 0
I agree that I don't see how it could get stuck in an infinite loop unless argument is not a null-terminated string to begin with. What is the value of argument being input?
16 Aug, 2010, Bojack wrote in the 4th comment:
Votes: 0
Yea I dont see how it is unless its because of the one_argument(string, arg1) coming from another function that calls this one.
0x08094c29 in interpret_wish (ch=0xb5818188, argument=0xbfcb6c5a "immortality")
at dragon.c:1627
1627 *string = *argument;
16 Aug, 2010, David Haley wrote in the 5th comment:
Votes: 0
If it's an infinite loop, it should be rather apparent what is happening in gdb.

You can also try using printf to see if all input strings are null terminated.
30 Aug, 2010, Bojack wrote in the 6th comment:
Votes: 0
Update: It turns out it was is_name part of that. It dont like multiple words in a string. The function gets thrown around a lot when you add a lot of words to the namelist. is_exact_name works better cuz it only uses one call to one_argument.
31 Aug, 2010, Oliver wrote in the 7th comment:
Votes: 0
Bojack said:
Update: It turns out it was is_name part of that. It dont like multiple words in a string. The function gets thrown around a lot when you add a lot of words to the namelist. is_exact_name works better cuz it only uses one call to one_argument.


Er. Are you sure about that?

I'm about 90% certain that RoM2.4b6 uses is_name() every time it parses a player targeting any sort of object, which can have tons and tons of separate names in the namelist. I've never seen a problem with it before.
0.0/7