int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error) { deh_context_t *context; if (!deh_initialized) { DEH_Init(); } // Reset all special flags to defaults. deh_allow_long_strings = allow_long; deh_allow_long_cheats = allow_long; deh_allow_extended_strings = false; context = DEH_OpenLump(lumpnum); if (context == NULL) { fprintf(stderr, "DEH_LoadFile: Unable to open lump %i\n", lumpnum); return 0; } DEH_ParseContext(context); DEH_CloseFile(context); // If there was an error while parsing, abort with an error, but allow // errors to just be ignored if allow_error=true. if (!allow_error && DEH_HadError(context)) { I_Error("Error parsing dehacked lump"); } return 1; }
int DEH_LoadFile(const char *filename) { deh_context_t *context; if (!deh_initialized) { DEH_Init(); } // Before parsing a new file, reset special override flags to false. // Magic comments should only apply to the file in which they were // defined, and shouldn't carry over to subsequent files as well. // [crispy] always allow everything /* deh_allow_long_strings = false; deh_allow_long_cheats = false; deh_allow_extended_strings = false; */ printf(" loading %s\n", filename); context = DEH_OpenFile(filename); if (context == NULL) { fprintf(stderr, "DEH_LoadFile: Unable to open %s\n", filename); return 0; } DEH_ParseContext(context); DEH_CloseFile(context); if (DEH_HadError(context)) { I_Error("Error parsing dehacked file"); } return 1; }
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); } } } } }
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); } } } } }