Example #1
0
static void DEH_ParseContext(deh_context_t *context)
{
    deh_section_t *current_section = NULL;
    char section_name[20];
    void *tag = NULL;
    boolean extended;
    char *line;

    // Read the header and check it matches the signature

    if (!CheckSignatures(context))
    {
        DEH_Error(context, "This is not a valid dehacked patch file!");
    }

    // Read the file

    while (!DEH_HadError(context))
    {
        // Read the next line. We only allow the special extended parsing
        // for the BEX [STRINGS] section.
        extended = current_section != NULL
                && !strcasecmp(current_section->name, "[STRINGS]");
        line = DEH_ReadLine(context, extended);

        // end of file?

        if (line == NULL)
        {
            return;
        }

        while (line[0] != '\0' && isspace(line[0]))
            ++line;

        if (line[0] == '#')
        {
            // comment

            DEH_ParseComment(line);
            continue;
        }

        if (IsWhitespace(line))
        {
            if (current_section != NULL)
            {
                // end of section

                if (current_section->end != NULL)
                {
                    current_section->end(context, tag);
                }

                //printf("end %s tag\n", current_section->name);
                current_section = NULL;
            }
        }
        else
        {
            if (current_section != NULL)
            {
                // parse this line

                current_section->line_parser(context, line, tag);
            }
            else
            {
                // possibly the start of a new section

                sscanf(line, "%19s", section_name);

                current_section = GetSectionByName(section_name);

                if (current_section != NULL)
                {
                    tag = current_section->start(context, line);
                    //printf("started %s tag\n", section_name);
                }
                else
                {
                    //printf("unknown section name %s\n", section_name);
                }
            }
        }
    }
}
Example #2
0
static void DEH_ParseContext(deh_context_t *context)
{
    deh_section_t *current_section = NULL;
    deh_section_t *prev_section = NULL; // [crispy] remember previous line parser
    char section_name[20];
    void *tag = NULL;
    boolean extended;
    char *line;

    // Read the header and check it matches the signature

    if (!CheckSignatures(context))
    {
        // [crispy] make non-fatal
        fprintf(stderr, "This is not a valid dehacked patch file!\n");
    }

    // Read the file

    while (!DEH_HadError(context))
    {
        // Read the next line. We only allow the special extended parsing
        // for the BEX [STRINGS] section.
        extended = current_section != NULL
                && !strcasecmp(current_section->name, "[STRINGS]");
        // [crispy] save pointer to start of line, just in case
        DEH_SaveLineStart(context);
        line = DEH_ReadLine(context, extended);

        // end of file?

        if (line == NULL)
        {
            return;
        }

        while (line[0] != '\0' && isspace(line[0]))
            ++line;

        if (line[0] == '#')
        {
            // comment

            DEH_ParseComment(line);
            continue;
        }

        if (IsWhitespace(line))
        {
            if (current_section != NULL)
            {
                // end of section

                if (current_section->end != NULL)
                {
                    current_section->end(context, tag);
                }

                // [crispy] if this was a BEX line parser, remember it in case
                // the next section does not start with a section marker
                if (current_section->name[0] == '[')
                {
                    prev_section = current_section;
                }
                else
                {
                    prev_section = NULL;
                }

                //printf("end %s tag\n", current_section->name);
                current_section = NULL;
            }
        }
        else
        {
            if (current_section != NULL)
            {
                // parse this line

                current_section->line_parser(context, line, tag);
            }
            else
            {
                // possibly the start of a new section

                sscanf(line, "%19s", section_name);

                current_section = GetSectionByName(section_name);

                if (current_section != NULL)
                {
                    tag = current_section->start(context, line);
                    //printf("started %s tag\n", section_name);
                }
                else
                if (prev_section != NULL)
                {
                    // [crispy] try this line again with the previous line parser
                    DEH_RestoreLineStart(context);
                    current_section = prev_section;
                    prev_section = NULL;
                }
                else
                {
                    //printf("unknown section name %s\n", section_name);
                }
            }
        }
    }
}