View Single Post
Old September 20, 2015, 05:08   #7
TricksterWolf
Scout
 
Join Date: Sep 2012
Posts: 43
TricksterWolf is on a distinguished road
Post

To ask the above less confusingly, perhaps.

I don't understand how here:

Code:
static enum parser_error parse_spell_name(struct parser *p) {
    struct magic_spell *next = parser_priv(p);
    struct magic_spell *spell = mem_zalloc(sizeof *spell);
    spell->name = string_make(parser_getstr(p, "name"));
    spell->next = next;
    parser_setpriv(p, spell);
    return PARSE_ERROR_NONE;
}
...parser_priv(p) successfully gives me a pointer to the next spell yet-to-be-parsed, yet here:

Code:
static errr finish_parse_spell(struct parser *p) {
    m_info = parser_priv(p);
    parser_destroy(p);
    return 0;
}
...parser_priv(p) gives me a pointer back to the initial spell after all the spells have been parsed. How can I access the last spell in the list in a way that will let me set its next field to NULL?

Or more directly, is there some way I can check *p in the very beginning to see if I've parsed the final spell in my spell.txt file...?
TricksterWolf is offline   Reply With Quote