diff options
author | Simon Howard | 2005-10-08 20:54:16 +0000 |
---|---|---|
committer | Simon Howard | 2005-10-08 20:54:16 +0000 |
commit | 5547ba06ca0e267fa82a6b9b7953a980e0876e61 (patch) | |
tree | c4a27e16fde56addc8e00e4d3f0badddaf3449f8 | |
parent | 25f6da1861deedeb2d0650ecf0ebe42a83b682c8 (diff) | |
download | chocolate-doom-5547ba06ca0e267fa82a6b9b7953a980e0876e61.tar.gz chocolate-doom-5547ba06ca0e267fa82a6b9b7953a980e0876e61.tar.bz2 chocolate-doom-5547ba06ca0e267fa82a6b9b7953a980e0876e61.zip |
Proper dehacked error/warning framework. Catch a load more errors.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 175
-rw-r--r-- | src/deh_ammo.c | 21 | ||||
-rw-r--r-- | src/deh_cheat.c | 15 | ||||
-rw-r--r-- | src/deh_frame.c | 20 | ||||
-rw-r--r-- | src/deh_io.c | 52 | ||||
-rw-r--r-- | src/deh_io.h | 7 | ||||
-rw-r--r-- | src/deh_mapping.c | 15 | ||||
-rw-r--r-- | src/deh_mapping.h | 9 | ||||
-rw-r--r-- | src/deh_misc.c | 9 | ||||
-rw-r--r-- | src/deh_ptr.c | 23 | ||||
-rw-r--r-- | src/deh_sound.c | 18 | ||||
-rw-r--r-- | src/deh_text.c | 11 | ||||
-rw-r--r-- | src/deh_thing.c | 17 | ||||
-rw-r--r-- | src/deh_weapon.c | 21 |
13 files changed, 187 insertions, 51 deletions
diff --git a/src/deh_ammo.c b/src/deh_ammo.c index 9bab7759..7709894f 100644 --- a/src/deh_ammo.c +++ b/src/deh_ammo.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_ammo.c 163 2005-10-04 22:04:06Z fraggle $ +// $Id: deh_ammo.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2005/10/08 20:54:15 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.3 2005/10/04 22:04:06 fraggle // Parse dehacked "Ammo" sections properly // @@ -45,6 +48,7 @@ #include "doomdef.h" #include "doomtype.h" #include "deh_defs.h" +#include "deh_io.h" #include "deh_main.h" #include "p_local.h" @@ -52,11 +56,18 @@ static void *DEH_AmmoStart(deh_context_t *context, char *line) { int ammo_number = 0; - sscanf(line, "Ammo %i", &ammo_number); + if (sscanf(line, "Ammo %i", &ammo_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } if (ammo_number < 0 || ammo_number >= NUMAMMO) + { + DEH_Warning(context, "Invalid ammo number: %i", ammo_number); return NULL; - + } + return &maxammo[ammo_number]; } @@ -77,6 +88,7 @@ static void DEH_AmmoParseLine(deh_context_t *context, char *line, void *tag) { // Failed to parse + DEH_Warning(context, "Failed to parse assignment"); return; } @@ -90,8 +102,7 @@ static void DEH_AmmoParseLine(deh_context_t *context, char *line, void *tag) maxammo[ammo_number] = ivalue; else { - fprintf(stderr, "DEH_AmmoParseLine: field named '%s' not found\n", - variable_name); + DEH_Warning(context, "Field named '%s' not found", variable_name); } } diff --git a/src/deh_cheat.c b/src/deh_cheat.c index 0fd8cd2a..c4f05bc1 100644 --- a/src/deh_cheat.c +++ b/src/deh_cheat.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_cheat.c 162 2005-10-04 21:41:42Z fraggle $ +// $Id: deh_cheat.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.1 2005/10/04 21:41:42 fraggle // Rewrite cheats code. Add dehacked cheat replacement. // @@ -40,7 +43,9 @@ #include "doomdef.h" #include "doomtype.h" + #include "deh_defs.h" +#include "deh_io.h" #include "deh_main.h" #include "am_map.h" #include "st_stuff.h" @@ -97,10 +102,11 @@ static void DEH_CheatParseLine(deh_context_t *context, char *line, void *tag) unsigned char *value; int i; - if (!DEH_ParseAssignment(line, &variable_name, (char *) &value)) + if (!DEH_ParseAssignment(line, &variable_name, (char **) &value)) { // Failed to parse - + + DEH_Warning(context, "Failed to parse assignment"); return; } @@ -108,8 +114,7 @@ static void DEH_CheatParseLine(deh_context_t *context, char *line, void *tag) if (cheat == NULL) { - fprintf(stderr, "DEH_ParseCheatLine: Unknown cheat '%s'\n", - variable_name); + DEH_Warning(context, "Unknown cheat '%s'", variable_name); return; } diff --git a/src/deh_frame.c b/src/deh_frame.c index 5140ef42..4e11ca31 100644 --- a/src/deh_frame.c +++ b/src/deh_frame.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_frame.c 157 2005-10-03 11:08:16Z fraggle $ +// $Id: deh_frame.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.5 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.4 2005/10/03 11:08:16 fraggle // Replace end of section functions with NULLs as they arent currently being // used for anything. @@ -49,6 +52,7 @@ #include "info.h" #include "deh_defs.h" +#include "deh_io.h" #include "deh_main.h" #include "deh_mapping.h" @@ -66,10 +70,17 @@ static void *DEH_FrameStart(deh_context_t *context, char *line) int frame_number = 0; state_t *state; - sscanf(line, "Frame %i", &frame_number); + if (sscanf(line, "Frame %i", &frame_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } if (frame_number < 0 || frame_number >= NUMSTATES) + { + DEH_Warning(context, "Invalid frame number: %i", frame_number); return NULL; + } state = &states[frame_number]; @@ -93,18 +104,17 @@ static void DEH_FrameParseLine(deh_context_t *context, char *line, void *tag) { // Failed to parse + DEH_Warning(context, "Failed to parse assignment"); return; } -// printf("Set %s to %s for state\n", variable_name, value); - // all values are integers ivalue = atoi(value); // set the appropriate field - DEH_SetMapping(&state_mapping, state, variable_name, ivalue); + DEH_SetMapping(context, &state_mapping, state, variable_name, ivalue); } deh_section_t deh_section_frame = diff --git a/src/deh_io.c b/src/deh_io.c index 56b75e6b..65185ea1 100644 --- a/src/deh_io.c +++ b/src/deh_io.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_io.c 153 2005-10-02 23:49:01Z fraggle $ +// $Id: deh_io.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.1 2005/10/02 23:49:01 fraggle // The beginnings of dehacked support // @@ -31,10 +34,12 @@ // //----------------------------------------------------------------------------- +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "i_system.h" #include "z_zone.h" #include "deh_defs.h" @@ -43,6 +48,9 @@ struct deh_context_s { FILE *stream; + char *filename; + int linenum; + boolean last_was_newline; char *readbuffer; int readbuffer_size; }; @@ -67,6 +75,9 @@ deh_context_t *DEH_OpenFile(char *filename) context->readbuffer_size = 128; context->readbuffer = Z_Malloc(context->readbuffer_size, PU_STATIC, NULL); + context->filename = filename; + context->linenum = 0; + context->last_was_newline = true; return context; } @@ -104,6 +115,15 @@ int DEH_GetChar(deh_context_t *context) } while (result == '\r'); + // Track the current line number + + if (context->last_was_newline) + { + ++context->linenum; + } + + context->last_was_newline = result == '\n'; + return result; } @@ -129,7 +149,6 @@ static void IncreaseReadBuffer(deh_context_t *context) char *DEH_ReadLine(deh_context_t *context) { - char *p; int c; int pos; @@ -167,3 +186,32 @@ char *DEH_ReadLine(deh_context_t *context) return context->readbuffer; } +void DEH_Warning(deh_context_t *context, char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + fprintf(stderr, "%s:%i: warning: ", context->filename, context->linenum); + vfprintf(stderr, msg, args); + fprintf(stderr, "\n"); + + va_end(args); +} + +void DEH_Error(deh_context_t *context, char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + fprintf(stderr, "%s:%i: ", context->filename, context->linenum); + vfprintf(stderr, msg, args); + fprintf(stderr, "\n"); + + va_end(args); + + I_Error("Error parsing dehacked file"); +} + + diff --git a/src/deh_io.h b/src/deh_io.h index 96de223d..2656f3e0 100644 --- a/src/deh_io.h +++ b/src/deh_io.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_io.h 153 2005-10-02 23:49:01Z fraggle $ +// $Id: deh_io.h 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.1 2005/10/02 23:49:01 fraggle // The beginnings of dehacked support // @@ -40,6 +43,8 @@ deh_context_t *DEH_OpenFile(char *filename); void DEH_CloseFile(deh_context_t *context); int DEH_GetChar(deh_context_t *context); char *DEH_ReadLine(deh_context_t *context); +void DEH_Error(deh_context_t *context, char *msg, ...); +void DEH_Warning(deh_context_t *context, char *msg, ...); #endif /* #ifndef DEH_IO_H */ diff --git a/src/deh_mapping.c b/src/deh_mapping.c index e79d2ea7..04316f0f 100644 --- a/src/deh_mapping.c +++ b/src/deh_mapping.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_mapping.c 173 2005-10-08 20:14:24Z fraggle $ +// $Id: deh_mapping.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.3 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.2 2005/10/08 20:14:24 fraggle // Add the ability to specify unsupported fields // @@ -47,7 +50,7 @@ // Set the value of a particular field in a structure by name // -boolean DEH_SetMapping(deh_mapping_t *mapping, +boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, void *structptr, char *name, int value) { int i; @@ -62,8 +65,7 @@ boolean DEH_SetMapping(deh_mapping_t *mapping, if (entry->location == NULL) { - fprintf(stderr, "DEH_SetMapping: Field '%s' is unsupported.\n", - name); + DEH_Warning(context, "Field '%s' is unsupported", name); return false; } @@ -87,7 +89,7 @@ boolean DEH_SetMapping(deh_mapping_t *mapping, * ((unsigned long long *) location) = value; break; default: - fprintf(stderr, "DEH_SetMapping: Unknown field type for %s\n", name); + DEH_Error(context, "Unknown field type for '%s' (BUG)", name); return false; } @@ -97,8 +99,7 @@ boolean DEH_SetMapping(deh_mapping_t *mapping, // field with this name not found - fprintf(stderr, "DEH_SetMapping: field named '%s' not found\n", - name); + DEH_Warning(context, "Field named '%s' not found", name); return false; } diff --git a/src/deh_mapping.h b/src/deh_mapping.h index b025b67f..41c09332 100644 --- a/src/deh_mapping.h +++ b/src/deh_mapping.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_mapping.h 173 2005-10-08 20:14:24Z fraggle $ +// $Id: deh_mapping.h 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.3 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.2 2005/10/08 20:14:24 fraggle // Add the ability to specify unsupported fields // @@ -41,6 +44,7 @@ #define DEH_MAPPING_H #include "doomtype.h" +#include "deh_io.h" #define DEH_BEGIN_MAPPING(mapping_name, structname) \ static structname deh_mapping_base; \ @@ -90,7 +94,8 @@ struct deh_mapping_s deh_mapping_entry_t entries[MAX_MAPPING_ENTRIES]; }; -boolean DEH_SetMapping(deh_mapping_t *mapping, void *structptr, char *name, int value); +boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, + void *structptr, char *name, int value); #endif /* #ifndef DEH_MAPPING_H */ diff --git a/src/deh_misc.c b/src/deh_misc.c index e488d545..2cbba2f9 100644 --- a/src/deh_misc.c +++ b/src/deh_misc.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_misc.c 164 2005-10-04 22:10:32Z fraggle $ +// $Id: deh_misc.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.1 2005/10/04 22:10:32 fraggle // Dehacked "Misc" section parser (currently a dummy) // @@ -34,11 +37,11 @@ #include "doomdef.h" #include "doomtype.h" #include "deh_defs.h" +#include "deh_io.h" static void *DEH_MiscStart(deh_context_t *context, char *line) { - fprintf(stderr, "DEH_MiscStart: Warning: dehacked 'Misc' sections are " - "not yet supported.\n"); + DEH_Warning(context, "Dehacked 'Misc' sections are not supported yet."); return NULL; } diff --git a/src/deh_ptr.c b/src/deh_ptr.c index a7c41ba7..bb0757b9 100644 --- a/src/deh_ptr.c +++ b/src/deh_ptr.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_ptr.c 157 2005-10-03 11:08:16Z fraggle $ +// $Id: deh_ptr.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.3 2005/10/03 11:08:16 fraggle // Replace end of section functions with NULLs as they arent currently being // used for anything. @@ -46,6 +49,7 @@ #include "info.h" #include "deh_defs.h" +#include "deh_io.h" #include "deh_main.h" static actionf_t codeptrs[NUMSTATES]; @@ -67,10 +71,17 @@ static void *DEH_PointerStart(deh_context_t *context, char *line) // FIXME: can the third argument here be something other than "Frame" // or are we ok? - sscanf(line, "%*s %*i (%*s %i)", &frame_number); + if (sscanf(line, "Pointer %*i (%*s %i)", &frame_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } if (frame_number < 0 || frame_number >= NUMSTATES) + { + DEH_Warning(context, "Invalid frame number: %i", frame_number); return NULL; + } return &states[frame_number]; } @@ -91,7 +102,7 @@ static void DEH_PointerParseLine(deh_context_t *context, char *line, void *tag) if (!DEH_ParseAssignment(line, &variable_name, &value)) { // Failed to parse - + DEH_Warning(context, "Failed to parse assignment"); return; } @@ -107,8 +118,7 @@ static void DEH_PointerParseLine(deh_context_t *context, char *line, void *tag) { if (ivalue < 0 || ivalue >= NUMSTATES) { - fprintf(stderr, "DEH_PointerParseLine: Invalid state %i\n", - ivalue); + DEH_Warning(context, "Invalid state '%i'", ivalue); } else { @@ -117,8 +127,7 @@ static void DEH_PointerParseLine(deh_context_t *context, char *line, void *tag) } else { - fprintf(stderr, "DEH_PointerParseLine: Unknown variable name '%s'\n", - variable_name); + DEH_Warning(context, "Unknown variable name '%s'", variable_name); } } diff --git a/src/deh_sound.c b/src/deh_sound.c index 87c4d2fa..1fde9d3e 100644 --- a/src/deh_sound.c +++ b/src/deh_sound.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_sound.c 174 2005-10-08 20:14:38Z fraggle $ +// $Id: deh_sound.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.1 2005/10/08 20:14:38 fraggle // Dehacked "Sound" section support // @@ -60,10 +63,17 @@ static void *DEH_SoundStart(deh_context_t *context, char *line) int sound_number = 0; sfxinfo_t *sfx; - sscanf(line, "Sound %i", &sound_number); + if (sscanf(line, "Sound %i", &sound_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } if (sound_number < 0 || sound_number >= NUMSFX) + { + DEH_Warning(context, "Invalid sound number: %i", sound_number); return NULL; + } sfx = &S_sfx[sound_number]; @@ -86,7 +96,7 @@ static void DEH_SoundParseLine(deh_context_t *context, char *line, void *tag) if (!DEH_ParseAssignment(line, &variable_name, &value)) { // Failed to parse - + DEH_Warning(context, "Failed to parse assignment"); return; } @@ -96,7 +106,7 @@ static void DEH_SoundParseLine(deh_context_t *context, char *line, void *tag) // Set the field value - DEH_SetMapping(&sound_mapping, sfx, variable_name, ivalue); + DEH_SetMapping(context, &sound_mapping, sfx, variable_name, ivalue); } diff --git a/src/deh_text.c b/src/deh_text.c index e2c86662..6d95944b 100644 --- a/src/deh_text.c +++ b/src/deh_text.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_text.c 160 2005-10-03 21:39:39Z fraggle $ +// $Id: deh_text.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.3 2005/10/03 21:39:39 fraggle // Dehacked text substitutions // @@ -174,7 +177,11 @@ static void *DEH_TextStart(deh_context_t *context, char *line) int fromlen, tolen; int i; - sscanf(line, "Text %i %i", &fromlen, &tolen); + if (sscanf(line, "Text %i %i", &fromlen, &tolen) != 2) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } sub = Z_Malloc(sizeof(deh_substitution_t), PU_STATIC, NULL); sub->from_text = Z_Malloc(fromlen + 1, PU_STATIC, NULL); diff --git a/src/deh_thing.c b/src/deh_thing.c index a57b9ff0..b9fb37a5 100644 --- a/src/deh_thing.c +++ b/src/deh_thing.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_thing.c 157 2005-10-03 11:08:16Z fraggle $ +// $Id: deh_thing.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.3 2005/10/03 11:08:16 fraggle // Replace end of section functions with NULLs as they arent currently being // used for anything. @@ -81,13 +84,20 @@ static void *DEH_ThingStart(deh_context_t *context, char *line) int thing_number = 0; mobjinfo_t *mobj; - sscanf(line, "Thing %i", &thing_number); + if (sscanf(line, "Thing %i", &thing_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } // dehacked files are indexed from 1 --thing_number; if (thing_number < 0 || thing_number >= NUMMOBJTYPES) + { + DEH_Warning("Invalid thing number: %i", thing_number); return NULL; + } mobj = &mobjinfo[thing_number]; @@ -111,6 +121,7 @@ static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag) { // Failed to parse + DEH_Warning(context, "Failed to parse assignment"); return; } @@ -122,7 +133,7 @@ static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag) // Set the field value - DEH_SetMapping(&thing_mapping, mobj, variable_name, ivalue); + DEH_SetMapping(context, &thing_mapping, mobj, variable_name, ivalue); } deh_section_t deh_section_thing = diff --git a/src/deh_weapon.c b/src/deh_weapon.c index 62ea61fe..26cd29ad 100644 --- a/src/deh_weapon.c +++ b/src/deh_weapon.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: deh_weapon.c 158 2005-10-03 13:21:11Z fraggle $ +// $Id: deh_weapon.c 175 2005-10-08 20:54:16Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.5 2005/10/08 20:54:16 fraggle +// Proper dehacked error/warning framework. Catch a load more errors. +// // Revision 1.4 2005/10/03 13:21:11 fraggle // Weapons mapping code // @@ -66,11 +69,18 @@ static void *DEH_WeaponStart(deh_context_t *context, char *line) { int weapon_number = 0; - sscanf(line, "Weapon %i", &weapon_number); + if (sscanf(line, "Weapon %i", &weapon_number) != 1) + { + DEH_Warning(context, "Parse error on section start"); + return NULL; + } if (weapon_number < 0 || weapon_number >= NUMWEAPONS) + { + DEH_Warning(context, "Invalid weapon number: %i", weapon_number); return NULL; - + } + return &weaponinfo[weapon_number]; } @@ -88,13 +98,14 @@ static void DEH_WeaponParseLine(deh_context_t *context, char *line, void *tag) if (!DEH_ParseAssignment(line, &variable_name, &value)) { // Failed to parse - + + DEH_Warning(context, "Failed to parse assignment"); return; } ivalue = atoi(value); - DEH_SetMapping(&weapon_mapping, weapon, variable_name, ivalue); + DEH_SetMapping(context, &weapon_mapping, weapon, variable_name, ivalue); } deh_section_t deh_section_weapon = |