From 9aff401234aa044cac94a37e1004c5916d52e491 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Tue, 10 Feb 2015 13:34:00 -0500 Subject: [PATCH] replace setjmp with try-catch --- CMakeLists.txt | 1 - include/missionparse.h | 1 - include/parselo.h | 15 +- src/asteroid/asteroid.cpp | 44 +++--- src/cutscene/cutscenes.cpp | 57 ++++--- src/debugconsole/console.cpp | 131 ++++++++-------- src/fireball/fireballs.cpp | 56 +++---- src/gamehelp/contexthelp.cpp | 191 +++++++++++------------ src/gamesnd/eventmusic.cpp | 18 +-- src/gamesnd/gamesnd.cpp | 68 ++++----- src/hud/hudartillery.cpp | 79 +++++----- src/hud/hudconfig.cpp | 33 ++-- src/hud/hudshield.cpp | 34 +++-- src/localization/localize.cpp | 12 +- src/menuui/credits.cpp | 67 ++++---- src/menuui/mainhallmenu.cpp | 6 +- src/menuui/playermenu.cpp | 18 ++- src/menuui/techmenu.cpp | 10 +- src/mission/missionbriefcommon.cpp | 79 +++++----- src/mission/missioncampaign.cpp | 211 +++++++++++++------------ src/mission/missionmessage.cpp | 8 +- src/mission/missionparse.cpp | 109 +++++++------ src/missionui/missiondebrief.cpp | 83 +++++----- src/nebula/neb.cpp | 48 +++--- src/nebula/neblightning.cpp | 238 +++++++++++++++-------------- src/palman/palman.cpp | 27 ++-- src/parse/parselo.cpp | 26 ++-- src/parse/sexp.cpp | 2 +- src/ship/aicode.cpp | 8 +- src/ship/ship.cpp | 10 +- src/starfield/starfield.cpp | 226 +++++++++++++-------------- src/stats/medals.cpp | 109 ++++++------- src/stats/scoring.cpp | 60 ++++---- src/weapon/muzzleflash.cpp | 78 +++++----- src/weapon/weapons.cpp | 65 ++++---- 35 files changed, 1130 insertions(+), 1098 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22e1a01..c933501 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,6 @@ else() add_definitions(/W4) add_definitions(/wd4100) # unreferenced parameter add_definitions(/wd4127) # conditional expression is constant: do { } while (0) - add_definitions(/wd4611) # non-portable interaction between setjmp() and C++ object destruction add_definitions(/wd4996) # deprecated functions: fopen, fileno, ... endif() diff --git a/include/missionparse.h b/include/missionparse.h index ed179ed..580ef99 100644 --- a/include/missionparse.h +++ b/include/missionparse.h @@ -171,7 +171,6 @@ #ifndef _PARSE_H #define _PARSE_H -#include #include "parselo.h" #include "ship.h" #include "ai.h" diff --git a/include/parselo.h b/include/parselo.h index 2c56d9b..3c56135 100644 --- a/include/parselo.h +++ b/include/parselo.h @@ -233,7 +233,6 @@ #ifndef _PARSELO_H #define _PARSELO_H -#include #include "cfile.h" #define MISSION_TEXT_SIZE 390000 @@ -244,8 +243,20 @@ extern char *Mp; extern const char *token_found; extern int fred_parse_flag; extern int Token_found_flag; -extern jmp_buf parse_abort; +// NOTE: numbered to match original error values +typedef enum { + PARSE_ERROR_MISSING_TOKEN = 1, + PARSE_ERROR_MISSING_TOKEN_EITHER = 2, + PARSE_ERROR_MISSING_STRING = 3, + PARSE_ERROR_TOO_LONG = 4, + PARSE_ERROR_EMPTY_FILENAME = 10, + PARSE_ERROR_FILE_NOT_FOUND = 5, + PARSE_ERROR_STRING_LIST = 100, + PARSE_ERROR_INT_LIST = 6, + PARSE_ERROR_VECTOR_PSTART = 11, + PARSE_ERROR_VECTOR_PEND = 12 +} parse_error_t; #define COMMENT_CHAR (char)';' #define EOF_CHAR (char)-128 diff --git a/src/asteroid/asteroid.cpp b/src/asteroid/asteroid.cpp index 3edbc5c..52f6944 100644 --- a/src/asteroid/asteroid.cpp +++ b/src/asteroid/asteroid.cpp @@ -2016,32 +2016,36 @@ void asteroid_parse_tbl() // open localization lcl_ext_open(); - read_file_text("asteroid.tbl"); - reset_parse(); + try { + read_file_text("asteroid.tbl"); + reset_parse(); - required_string("#Asteroid Types"); + required_string("#Asteroid Types"); - while (required_string_either("#End","$Name:")) { - SDL_assert( Num_asteroid_types < MAX_DEBRIS_TYPES ); - asteroid_parse_section(); - Num_asteroid_types++; - } + while (required_string_either("#End","$Name:")) { + SDL_assert( Num_asteroid_types < MAX_DEBRIS_TYPES ); + asteroid_parse_section(); + Num_asteroid_types++; + } - required_string("#End"); + required_string("#End"); - // check all read in - SDL_assert(Num_asteroid_types == MAX_DEBRIS_TYPES); + // check all read in + SDL_assert(Num_asteroid_types == MAX_DEBRIS_TYPES); - Asteroid_impact_explosion_ani = -1; - required_string("$Impact Explosion:"); - stuff_string(impact_ani_file, F_NAME, NULL); - if ( SDL_strcasecmp(impact_ani_file,NOX("none"))) { - int num_frames; - Asteroid_impact_explosion_ani = bm_load_animation( impact_ani_file, &num_frames, NULL, 1); - } + Asteroid_impact_explosion_ani = -1; + required_string("$Impact Explosion:"); + stuff_string(impact_ani_file, F_NAME, NULL); + if ( SDL_strcasecmp(impact_ani_file,NOX("none"))) { + int num_frames; + Asteroid_impact_explosion_ani = bm_load_animation( impact_ani_file, &num_frames, NULL, 1); + } - required_string("$Impact Explosion Radius:"); - stuff_float(&Asteroid_impact_explosion_radius); + required_string("$Impact Explosion Radius:"); + stuff_float(&Asteroid_impact_explosion_radius); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'asteroid.tbl'\r\nError code = %i.\r\n", (int)rval); + } // close localization lcl_ext_close(); diff --git a/src/cutscene/cutscenes.cpp b/src/cutscene/cutscenes.cpp index 02a83c4..af0ccc9 100644 --- a/src/cutscene/cutscenes.cpp +++ b/src/cutscene/cutscenes.cpp @@ -202,40 +202,39 @@ void cutscene_init() { #ifndef FS1_DEMO // no cuscenes in FS1 demo char buf[MULTITEXT_LENGTH]; - int rval; - - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'rank.tbl'\r\nError code = %i.\r\n", rval); - } // open localization lcl_ext_open(); - read_file_text("cutscenes.tbl"); - reset_parse(); - - // parse in all the rank names - Num_cutscenes = 0; - skip_to_string("#Cutscenes"); - ignore_white_space(); - while ( required_string_either("#End", "$Filename:") ) { - SDL_assert ( Num_cutscenes < MAX_CUTSCENES ); - required_string("$Filename:"); - stuff_string( Cutscenes[Num_cutscenes].filename, F_PATHNAME, NULL ); - required_string("$Name:"); - stuff_string( Cutscenes[Num_cutscenes].name, F_NAME, NULL ); - required_string("$Description:"); - stuff_string(buf, F_MULTITEXT, NULL); - drop_white_space(buf); - compact_multitext_string(buf); - Cutscenes[Num_cutscenes].description = strdup(buf); - required_string("$cd:"); - stuff_int( &Cutscenes[Num_cutscenes].cd ); - - Num_cutscenes++; - } + try { + read_file_text("cutscenes.tbl"); + reset_parse(); + + // parse in all the rank names + Num_cutscenes = 0; + skip_to_string("#Cutscenes"); + ignore_white_space(); + while ( required_string_either("#End", "$Filename:") ) { + SDL_assert ( Num_cutscenes < MAX_CUTSCENES ); + required_string("$Filename:"); + stuff_string( Cutscenes[Num_cutscenes].filename, F_PATHNAME, NULL ); + required_string("$Name:"); + stuff_string( Cutscenes[Num_cutscenes].name, F_NAME, NULL ); + required_string("$Description:"); + stuff_string(buf, F_MULTITEXT, NULL); + drop_white_space(buf); + compact_multitext_string(buf); + Cutscenes[Num_cutscenes].description = strdup(buf); + required_string("$cd:"); + stuff_int( &Cutscenes[Num_cutscenes].cd ); + + Num_cutscenes++; + } - required_string("#End"); + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'cutscenes.tbl'\r\nError code = %i.\r\n", (int)rval); + } Cutscenes_viewable = INTRO_CUTSCENE_FLAG; diff --git a/src/debugconsole/console.cpp b/src/debugconsole/console.cpp index 64136eb..3b4a591 100644 --- a/src/debugconsole/console.cpp +++ b/src/debugconsole/console.cpp @@ -106,7 +106,6 @@ #include #include #include -#include #include #include "pstypes.h" @@ -333,7 +332,6 @@ void scanner_start_command( const char * s ) int Dc_debug_on = 0; -jmp_buf dc_bad_arg; void dc_get_arg(uint type) { @@ -428,7 +426,8 @@ void dc_get_arg(uint type) dc_printf( "Error: Not enough parameters.\n" ); else dc_printf( "Error: '%s' invalid type\n", Dc_arg ); - longjmp(dc_bad_arg,1); + + throw (int)1; } } @@ -447,85 +446,85 @@ void debug_do_command(const char * command) Dc_command_line = command; scanner_start_command(command); - if (setjmp(dc_bad_arg) ) { - return; - } - - dc_get_arg( ARG_ANY ); - - if ( !strcmp( Dc_arg, "debug" ) ) { - Dc_debug_on = 1; - dc_printf( "Command line: '%s'\n", Dc_command_line ); + try { dc_get_arg( ARG_ANY ); - } - if ( !strcmp( Dc_arg, "?" ) ) { - mode = 1; - dc_get_arg( ARG_ANY ); + if ( !strcmp( Dc_arg, "debug" ) ) { + Dc_debug_on = 1; + dc_printf( "Command line: '%s'\n", Dc_command_line ); + dc_get_arg( ARG_ANY ); + } - if ( Dc_arg_type&ARG_NONE ) { - debug_help(); - return; + if ( !strcmp( Dc_arg, "?" ) ) { + mode = 1; + dc_get_arg( ARG_ANY ); + + if ( Dc_arg_type&ARG_NONE ) { + debug_help(); + return; + } } - } - if ( !strcmp( Dc_arg, "help" ) || !strcmp( Dc_arg, "man" ) ) { - mode = 2; - dc_get_arg( ARG_ANY ); - if ( Dc_arg_type&ARG_NONE ) { - debug_help(); - return; + if ( !strcmp( Dc_arg, "help" ) || !strcmp( Dc_arg, "man" ) ) { + mode = 2; + dc_get_arg( ARG_ANY ); + if ( Dc_arg_type&ARG_NONE ) { + debug_help(); + return; + } } - } - if ( strstr( Dc_command_line, "?" ) ) { - mode = 2; - } + if ( strstr( Dc_command_line, "?" ) ) { + mode = 2; + } - if ( !(Dc_arg_type&ARG_STRING) ) { - dc_printf( "Invalid keyword '%s'\n", Dc_arg ); - return; - } + if ( !(Dc_arg_type&ARG_STRING) ) { + dc_printf( "Invalid keyword '%s'\n", Dc_arg ); + return; + } - if (Dc_debug_on) { - dc_printf( "Searching for command '%s'\n", Dc_arg ); - } + if (Dc_debug_on) { + dc_printf( "Searching for command '%s'\n", Dc_arg ); + } - for (i=0; iname, Dc_arg )) { - - if (mode==0) { - if (Dc_debug_on) - dc_printf( "Calling function '%s'\n", Dc_arg ); - Dc_command = 1; - Dc_help = 0; - Dc_status = 1; - } else if (mode==1) { - if (Dc_debug_on) - dc_printf( "Checking status for '%s'\n", Dc_arg ); - Dc_command = 0; - Dc_help = 0; - Dc_status = 1; - } else { - if (Dc_debug_on) - dc_printf( "Doing help for '%s'\n", Dc_arg ); - Dc_command = 0; - Dc_help = 1; - Dc_status = 0; - } + for (i=0; iname, Dc_arg )) { + + if (mode==0) { + if (Dc_debug_on) + dc_printf( "Calling function '%s'\n", Dc_arg ); + Dc_command = 1; + Dc_help = 0; + Dc_status = 1; + } else if (mode==1) { + if (Dc_debug_on) + dc_printf( "Checking status for '%s'\n", Dc_arg ); + Dc_command = 0; + Dc_help = 0; + Dc_status = 1; + } else { + if (Dc_debug_on) + dc_printf( "Doing help for '%s'\n", Dc_arg ); + Dc_command = 0; + Dc_help = 1; + Dc_status = 0; + } - (*Debug_command[i]->func)(); + (*Debug_command[i]->func)(); - if (mode==0) { - dc_get_arg(ARG_ANY); - if (!(Dc_arg_type&ARG_NONE)) { - dc_printf( "Ignoring the unused command line tail '%s %s'\n", Dc_arg_org, Dc_command_line ); + if (mode==0) { + dc_get_arg(ARG_ANY); + if (!(Dc_arg_type&ARG_NONE)) { + dc_printf( "Ignoring the unused command line tail '%s %s'\n", Dc_arg_org, Dc_command_line ); + } } - } - return; + return; + } } + } catch (int) { + return; } dc_printf( "Unknown command '%s'\n", Dc_arg ); diff --git a/src/fireball/fireballs.cpp b/src/fireball/fireballs.cpp index f5c518b..5f16c8c 100644 --- a/src/fireball/fireballs.cpp +++ b/src/fireball/fireballs.cpp @@ -448,50 +448,50 @@ void fireball_play_warphole_close_sound(fireball *fb) void fireball_parse_tbl() { - int rval, idx; + int idx; char base_filename[256] = ""; // open localization lcl_ext_open(); - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Unable to parse fireball.tbl! Code = %i.\n", rval); - } - else { + try { read_file_text(NOX("fireball.tbl")); reset_parse(); - } - int ntypes = 0; - required_string("#Start"); - while (required_string_either("#End","$Name:")) { - SDL_assert( ntypes < MAX_FIREBALL_TYPES); + int ntypes = 0; + required_string("#Start"); + while (required_string_either("#End","$Name:")) { + SDL_assert( ntypes < MAX_FIREBALL_TYPES); - // base filename - required_string("$Name:"); - stuff_string(base_filename, F_NAME, NULL); + // base filename + required_string("$Name:"); + stuff_string(base_filename, F_NAME, NULL); - // # of lod levels - make sure old fireball.tbl is compatible - Fireball_info[ntypes].lod_count = 1; - if(optional_string("$LOD:")){ - stuff_int(&Fireball_info[ntypes].lod_count); - } + // # of lod levels - make sure old fireball.tbl is compatible + Fireball_info[ntypes].lod_count = 1; + if(optional_string("$LOD:")){ + stuff_int(&Fireball_info[ntypes].lod_count); + } - // stuff default filename - SDL_strlcpy(Fireball_info[ntypes].lod[0].filename, base_filename, sizeof(Fireball_info[0].lod[0].filename)); + // stuff default filename + SDL_strlcpy(Fireball_info[ntypes].lod[0].filename, base_filename, sizeof(Fireball_info[0].lod[0].filename)); - // stuff LOD level filenames - for(idx=1; idx= MAX_FIREBALL_LOD){ - break; + // stuff LOD level filenames + for(idx=1; idx= MAX_FIREBALL_LOD){ + break; + } + + SDL_snprintf(Fireball_info[ntypes].lod[idx].filename, MAX_FILENAME_LEN, "%s_%d", base_filename, idx); } - SDL_snprintf(Fireball_info[ntypes].lod[idx].filename, MAX_FILENAME_LEN, "%s_%d", base_filename, idx); + ntypes++; } - - ntypes++; + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse fireball.tbl! Code = %i.\n", (int)rval); } - required_string("#End"); + // close localization lcl_ext_close(); diff --git a/src/gamehelp/contexthelp.cpp b/src/gamehelp/contexthelp.cpp index b48e298..6f240d6 100644 --- a/src/gamehelp/contexthelp.cpp +++ b/src/gamehelp/contexthelp.cpp @@ -126,7 +126,6 @@ * */ #include -#include #include "contexthelp.h" #include "gamesequence.h" @@ -560,117 +559,121 @@ void parse_helptbl() // open localization lcl_ext_open(); - - read_file_text(HELP_OVERLAY_FILENAME); - - // for each overlay... - for (overlay_id=0; overlay_id= MAX_SSM_TYPES){ - s = &bogus; - } else { - s = &Ssm_info[Ssm_info_count]; - } + try { + read_file_text("ssm.tbl"); + reset_parse(); + + // parse the table + Ssm_info_count = 0; + while(!optional_string("#end")){ + // another ssm definition + if(optional_string("$SSM:")){ + // pointer to info struct + if(Ssm_info_count >= MAX_SSM_TYPES){ + s = &bogus; + } else { + s = &Ssm_info[Ssm_info_count]; + } - // name - stuff_string(s->name, F_NAME, NULL); - - // stuff data - required_string("+Weapon:"); - stuff_string(weapon_name, F_NAME, NULL); - required_string("+Count:"); - stuff_int(&s->count); - required_string("+WarpRadius:"); - stuff_float(&s->warp_radius); - required_string("+WarpTime:"); - stuff_float(&s->warp_time); - required_string("+Radius:"); - stuff_float(&s->radius); - required_string("+Offset:"); - stuff_float(&s->offset); - - // see if we have a valid weapon - s->weapon_info_index = -1; - s->weapon_info_index = weapon_name_lookup(weapon_name); - if(s->weapon_info_index >= 0){ - // valid - Ssm_info_count++; + // name + stuff_string(s->name, F_NAME, NULL); + + // stuff data + required_string("+Weapon:"); + stuff_string(weapon_name, F_NAME, NULL); + required_string("+Count:"); + stuff_int(&s->count); + required_string("+WarpRadius:"); + stuff_float(&s->warp_radius); + required_string("+WarpTime:"); + stuff_float(&s->warp_time); + required_string("+Radius:"); + stuff_float(&s->radius); + required_string("+Offset:"); + stuff_float(&s->offset); + + // see if we have a valid weapon + s->weapon_info_index = -1; + s->weapon_info_index = weapon_name_lookup(weapon_name); + if(s->weapon_info_index >= 0){ + // valid + Ssm_info_count++; + } } } + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse ssm.tbl! Code = %i.\n", (int)rval); } + #else // not for FS1 Ssm_info_count = 0; diff --git a/src/hud/hudconfig.cpp b/src/hud/hudconfig.cpp index 82078da..0f1b492 100644 --- a/src/hud/hudconfig.cpp +++ b/src/hud/hudconfig.cpp @@ -1992,31 +1992,30 @@ void hud_config_color_save(const char *name) void hud_config_color_load(const char *name) { - int idx, rval; + int idx; char str[1024] = ""; char *fname; fname = cf_add_ext(name, ".hcf"); - if ((rval = setjmp(parse_abort)) != 0) { - mprintf(("Error opening hud config file!\n")); - return; - } else { + try { read_file_text(fname); reset_parse(); - } - // write out all gauges - for(idx=0; idx 0){ - line_count--; + while(line_count > 0){ + line_count--; #endif - stuff_string_line(line, 511); - linep1 = line; - - do { - linep2 = split_str_once(linep1, Credits_text_coords[gr_screen.res][2]); - SDL_strlcat(Credit_text, linep1, size+200); - SDL_strlcat(Credit_text, "\n", size+200); - linep1 = linep2; - } while (linep2 != NULL); - } + stuff_string_line(line, 511); + linep1 = line; + + do { + linep2 = split_str_once(linep1, Credits_text_coords[gr_screen.res][2]); + SDL_strlcat(Credit_text, linep1, size+200); + SDL_strlcat(Credit_text, "\n", size+200); + linep1 = linep2; + } while (linep2 != NULL); + } + } catch (parse_error_t rval) { + mprintf(("Error parsing 'credits.tbl'\nError code = %i.\n", (int)rval)); + } // close localization lcl_ext_close(); diff --git a/src/menuui/mainhallmenu.cpp b/src/menuui/mainhallmenu.cpp index b3d67bd..d1ad292 100644 --- a/src/menuui/mainhallmenu.cpp +++ b/src/menuui/mainhallmenu.cpp @@ -818,7 +818,11 @@ void main_hall_init(int main_hall_num) char temp[100], whee[100]; // read in the main hall table - main_hall_read_table(); + try { + main_hall_read_table(); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse mainhall.tbl! Code = %i.\n", (int)rval); + } // create the snazzy interface and load up the info from the table snazzy_menu_init(); diff --git a/src/menuui/playermenu.cpp b/src/menuui/playermenu.cpp index ee4191e..0001208 100644 --- a/src/menuui/playermenu.cpp +++ b/src/menuui/playermenu.cpp @@ -1535,16 +1535,20 @@ void player_tips_init() // begin external localization stuff lcl_ext_open(); - read_file_text("tips.tbl"); - reset_parse(); + try { + read_file_text("tips.tbl"); + reset_parse(); - while(!optional_string("#end")){ - required_string("+Tip:"); + while(!optional_string("#end")){ + required_string("+Tip:"); - if(Num_player_tips >= MAX_PLAYER_TIPS){ - break; + if(Num_player_tips >= MAX_PLAYER_TIPS){ + break; + } + Player_tips[Num_player_tips++] = stuff_and_malloc_string(F_NAME, NULL, 1024); } - Player_tips[Num_player_tips++] = stuff_and_malloc_string(F_NAME, NULL, 1024); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse tips.tbl! Code = %i.\n", (int)rval); } // stop externalizing, homey diff --git a/src/menuui/techmenu.cpp b/src/menuui/techmenu.cpp index 2c8ed05..dbffd0d 100644 --- a/src/menuui/techmenu.cpp +++ b/src/menuui/techmenu.cpp @@ -1488,19 +1488,13 @@ int techroom_load_ani(anim **animpp, char *name) void techroom_intel_init() { - int rval; static int inited = 0; // open localization lcl_ext_open(); if (!inited) { - if ((rval = setjmp(parse_abort)) != 0) { - // close localization - lcl_ext_close(); - - return; - } else { + try { read_file_text("species.tbl"); reset_parse(); @@ -1556,6 +1550,8 @@ void techroom_intel_init() } #endif inited = 1; + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse species.tbl! Code = %i.\n", (int)rval); } } diff --git a/src/mission/missionbriefcommon.cpp b/src/mission/missionbriefcommon.cpp index e01f968..39a989a 100644 --- a/src/mission/missionbriefcommon.cpp +++ b/src/mission/missionbriefcommon.cpp @@ -833,7 +833,7 @@ int brief_icon_used_in_briefing(int icon_type) void brief_parse_icon_tbl() { #ifndef MAKE_FS1 - int num_icons, rval; + int num_icons; char name[NAME_LENGTH]; hud_frames *hf; hud_anim *ha; @@ -842,59 +842,58 @@ void brief_parse_icon_tbl() // open localization lcl_ext_open(); - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Unable to parse icons.tbl! Code = %i.\n", rval); - } - else { + try { read_file_text("icons.tbl"); reset_parse(); - } - num_icons = 0; - required_string("#Start"); + num_icons = 0; + required_string("#Start"); - int load_this_icon = 0; + int load_this_icon = 0; - while (required_string_either("#End","$Name:")) { - for(idx=0; idxfirst_frame = bm_load_animation(name, &hf->num_frames); - if ( hf->first_frame == -1 ) { - Int3(); // missing briefing icon + if ( load_this_icon ) { + hf->first_frame = bm_load_animation(name, &hf->num_frames); + if ( hf->first_frame == -1 ) { + Int3(); // missing briefing icon + } } + + // load in fade frames + required_string("$Name:"); + stuff_string(name, F_NAME, NULL); + ha = &Icon_fade_anims[num_icons][idx]; + hud_anim_init(ha, 0, 0, name); + + // load in highlighting frames + required_string("$Name:"); + stuff_string(name, F_NAME, NULL); + ha = &Icon_highlight_anims[num_icons][idx]; + hud_anim_init(ha, 0, 0, name); } - // load in fade frames - required_string("$Name:"); - stuff_string(name, F_NAME, NULL); - ha = &Icon_fade_anims[num_icons][idx]; - hud_anim_init(ha, 0, 0, name); - - // load in highlighting frames - required_string("$Name:"); - stuff_string(name, F_NAME, NULL); - ha = &Icon_highlight_anims[num_icons][idx]; - hud_anim_init(ha, 0, 0, name); + // next icon _type_ + num_icons++; } - - // next icon _type_ - num_icons++; + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse icons.tbl! Code = %i.\n", (int)rval); } - required_string("#End"); // close localization lcl_ext_close(); diff --git a/src/mission/missioncampaign.cpp b/src/mission/missioncampaign.cpp index 39fc460..a92de10 100644 --- a/src/mission/missioncampaign.cpp +++ b/src/mission/missioncampaign.cpp @@ -198,7 +198,6 @@ #include #endif #include -#include #include #include "key.h" @@ -274,7 +273,7 @@ campaign Campaign; // player or multiplayer campaign. The type field will only be valid if the name returned is non-NULL int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc) { - int rval, i; + int i; char campaign_type[NAME_LENGTH], fname[MAX_FILENAME_LEN]; SDL_assert( name != NULL ); @@ -290,17 +289,7 @@ int mission_campaign_get_info(const char *filename, char *name, int *type, int * SDL_assert(strlen(fname) < MAX_FILENAME_LEN); - if ((rval = setjmp(parse_abort)) != 0) { - if (rval == 5){ - // close localization - lcl_ext_close(); - - return 0; - } - - Error(LOCATION, "Error parsing '%s'\r\nError code = %i.\r\n", fname, rval); - - } else { + try { read_file_text( fname ); reset_parse(); required_string("$Name:"); @@ -346,6 +335,15 @@ int mission_campaign_get_info(const char *filename, char *name, int *type, int * return 1; } + } catch (parse_error_t rval) { + if (rval == PARSE_ERROR_FILE_NOT_FOUND) { + // close localization + lcl_ext_close(); + + return 0; + } + + Error(LOCATION, "Error parsing '%s'\r\nError code = %i.\r\n", fname, (int)rval); } Int3(); // get Allender -- incorrect type found @@ -361,20 +359,13 @@ int mission_campaign_get_info(const char *filename, char *name, int *type, int * // int mission_campaign_get_mission_list(const char *filename, char **list, int max) { - int rval, i, num = 0; + int i, num = 0; char name[NAME_LENGTH]; filename = cf_add_ext(filename, FS_CAMPAIGN_FILE_EXT); // read the mission file and get the list of mission filenames - if ((rval = setjmp(parse_abort)) != 0) { - // since we can't return count of allocated elements, free them instead - for (i=0; ievents = NULL; Campaign.num_missions++; } + } catch (parse_error_t rval) { + mprintf(("Error parsing '%s'\r\nError code = %i.\r\n", filename, (int)rval)); + + // close localization + lcl_ext_close(); + + return CAMPAIGN_ERROR_CORRUPT; } // set up the other variables for the campaign stuff. After initializing, we must try and load @@ -1513,13 +1509,8 @@ void mission_campaign_shutdown() // note that dest should allocate at least dest[MAX_CAMPAIGN_MISSIONS][NAME_LENGTH] int mission_campaign_get_filenames(const char *filename, char dest[][NAME_LENGTH], int *num) { - int rval; - // read the mission file and get the list of mission filenames - if ((rval = setjmp(parse_abort)) != 0) { - return rval; - - } else { + try { read_file_text(filename); SDL_assert(strlen(filename) < MAX_FILENAME_LEN - 1); // make sure no overflow @@ -1536,6 +1527,8 @@ int mission_campaign_get_filenames(const char *filename, char dest[][NAME_LENGTH stuff_string(dest[*num], F_NAME, NULL); (*num)++; } + } catch (parse_error_t rval) { + return (int)rval; } return 0; @@ -1547,78 +1540,80 @@ void read_mission_goal_list(int num) { char *filename, notes[NOTES_LENGTH], goals[MAX_GOALS][NAME_LENGTH]; char events[MAX_MISSION_EVENTS][NAME_LENGTH]; - int i, z, r, event_count, count = 0; + int i, z, event_count, count = 0; filename = Campaign.missions[num].name; - if ((r = setjmp(parse_abort))>0) { - Warning(LOCATION, "Error reading \"%s\" (code = %d)", filename, r); - return; - } // open localization lcl_ext_open(); - - read_file_text(filename); - init_parse(); - - // first, read the mission notes for this mission. Used in campaign editor - if (skip_to_string("#Mission Info")) { - if (skip_to_string("$Notes:")) { - stuff_string(notes, F_NOTES, NULL); - if (Campaign.missions[num].notes){ - free(Campaign.missions[num].notes); - } - - Campaign.missions[num].notes = (char *) malloc(strlen(notes) + 1); - SDL_strlcpy(Campaign.missions[num].notes, notes, strlen(notes) + 1); - } - } + // default counts to zero event_count = 0; - // skip to events section in the mission file. Events come before goals, so we process them first - if ( skip_to_string("#Events") ) { - while (1) { - if (skip_to_string("$Formula:", "#Goals") != 1){ - break; - } + count = 0; - z = skip_to_string("+Name:", "$Formula:"); - if (!z){ - break; - } + try { + read_file_text(filename); + init_parse(); + + // first, read the mission notes for this mission. Used in campaign editor + if (skip_to_string("#Mission Info")) { + if (skip_to_string("$Notes:")) { + stuff_string(notes, F_NOTES, NULL); + if (Campaign.missions[num].notes){ + free(Campaign.missions[num].notes); + } - if (z == 1){ - stuff_string(events[event_count], F_NAME, NULL); - } else { - SDL_snprintf(events[event_count], NAME_LENGTH, NOX("Event #%d"), event_count + 1); + Campaign.missions[num].notes = (char *) malloc(strlen(notes) + 1); + SDL_strlcpy(Campaign.missions[num].notes, notes, strlen(notes) + 1); } - - event_count++; - SDL_assert(event_count < MAX_MISSION_EVENTS); } - } - count = 0; - if (skip_to_string("#Goals")) { - while (1) { - if (skip_to_string("$Type:", "#End") != 1){ - break; - } + // skip to events section in the mission file. Events come before goals, so we process them first + if ( skip_to_string("#Events") ) { + while (1) { + if (skip_to_string("$Formula:", "#Goals") != 1){ + break; + } - z = skip_to_string("+Name:", "$Type:"); - if (!z){ - break; - } + z = skip_to_string("+Name:", "$Formula:"); + if (!z){ + break; + } - if (z == 1){ - stuff_string(goals[count], F_NAME, NULL); - } else { - SDL_snprintf(goals[count], NAME_LENGTH, NOX("Goal #%d"), count + 1); + if (z == 1){ + stuff_string(events[event_count], F_NAME, NULL); + } else { + SDL_snprintf(events[event_count], NAME_LENGTH, NOX("Event #%d"), event_count + 1); + } + + event_count++; + SDL_assert(event_count < MAX_MISSION_EVENTS); } + } - count++; - SDL_assert(count < MAX_GOALS); + if (skip_to_string("#Goals")) { + while (1) { + if (skip_to_string("$Type:", "#End") != 1){ + break; + } + + z = skip_to_string("+Name:", "$Type:"); + if (!z){ + break; + } + + if (z == 1){ + stuff_string(goals[count], F_NAME, NULL); + } else { + SDL_snprintf(goals[count], NAME_LENGTH, NOX("Goal #%d"), count + 1); + } + + count++; + SDL_assert(count < MAX_GOALS); + } } + } catch (parse_error_t rval) { + Warning(LOCATION, "Error reading \"%s\" (code = %d)", filename, (int)rval); } Campaign.missions[num].num_goals = count; @@ -1712,22 +1707,26 @@ int mission_campaign_parse_is_multi(const char *filename, char *name, const int { int i; char temp[50]; - - read_file_text( filename ); - reset_parse(); - - required_string("$Name:"); - stuff_string( temp, F_NAME, NULL ); - if ( name ) - SDL_strlcpy( name, temp, max_len ); - required_string( "$Type:" ); - stuff_string( temp, F_NAME, NULL ); + try { + read_file_text( filename ); + reset_parse(); - for (i = 0; i < MAX_CAMPAIGN_TYPES; i++ ) { - if ( !SDL_strcasecmp(temp, campaign_types[i]) ) { - return i; + required_string("$Name:"); + stuff_string( temp, F_NAME, NULL ); + if ( name ) + SDL_strlcpy( name, temp, max_len ); + + required_string( "$Type:" ); + stuff_string( temp, F_NAME, NULL ); + + for (i = 0; i < MAX_CAMPAIGN_TYPES; i++ ) { + if ( !SDL_strcasecmp(temp, campaign_types[i]) ) { + return i; + } } + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse %s! Code = %i.\n", filename, (int)rval); } Error(LOCATION, "Unknown campaign type %s", temp ); diff --git a/src/mission/missionmessage.cpp b/src/mission/missionmessage.cpp index 1d6edb1..c22f836 100644 --- a/src/mission/missionmessage.cpp +++ b/src/mission/missionmessage.cpp @@ -769,17 +769,17 @@ void parse_msgtbl() // this is called at the start of each level void messages_init() { - int rval, i; + int i; static int table_read = 0; if ( !table_read ) { Command_persona = -1; - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing '%s'\r\nError code = %i.\r\n", "messages.tbl", rval); - } else { + try { parse_msgtbl(); table_read = 1; + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing messages.tbl\r\nError code = %i.\r\n", (int)rval); } } diff --git a/src/mission/missionparse.cpp b/src/mission/missionparse.cpp index 893c18f..6afdf5e 100644 --- a/src/mission/missionparse.cpp +++ b/src/mission/missionparse.cpp @@ -335,7 +335,6 @@ #include #include #include -#include #include "freespace.h" #include "parselo.h" @@ -3778,49 +3777,46 @@ void post_process_mission() int get_mission_info(char *filename, mission *mission_p) { - int rval; - // if mission_p is NULL, make it point to The_mission if ( mission_p == NULL ) mission_p = &The_mission; - if ((rval = setjmp(parse_abort)) != 0) { - nprintf(("Error", "Error abort! Code = %d", rval)); - return rval; - - } else { - int filelength; + int filelength; - // open localization - lcl_ext_open(); + // open localization + lcl_ext_open(); - CFILE *ftemp = cfopen(filename, "rt"); - if (!ftemp){ - // close localization - lcl_ext_close(); + CFILE *ftemp = cfopen(filename, "rt"); + if (!ftemp){ + // close localization + lcl_ext_close(); - return -1; - } + return -1; + } - // 7/9/98 -- MWA -- check for 0 length file. - filelength = cfilelength(ftemp); - cfclose(ftemp); - if ( filelength == 0 ){ - // close localization - lcl_ext_close(); + // 7/9/98 -- MWA -- check for 0 length file. + filelength = cfilelength(ftemp); + cfclose(ftemp); + if ( filelength == 0 ){ + // close localization + lcl_ext_close(); - return -1; - } + return -1; + } + try { read_file_text(filename, CF_TYPE_MISSIONS); memset( mission_p, 0, sizeof(mission) ); init_parse(); parse_mission_info(mission_p); - - // close localization - lcl_ext_close(); + } catch (parse_error_t rval) { + nprintf(("Error", "Error abort! Code = %d", (int)rval)); + return (int)rval; } + // close localization + lcl_ext_close(); + return 0; } @@ -3829,7 +3825,7 @@ int get_mission_info(char *filename, mission *mission_p) // info such as game type, number of players etc. int parse_main(const char *mission_name, int flags) { - int rval, i; + int i; // fill in Ship_class_names array with the names from the ship_info struct; Num_parse_names = 0; @@ -3839,41 +3835,41 @@ int parse_main(const char *mission_name, int flags) for (i = 0; i < Num_ship_types; i++) Ship_class_names[i] = Ship_info[i].name; - if ((rval = setjmp(parse_abort)) != 0) { - nprintf(("Error", "Error abort! Code = %i.", rval)); - return rval; - - } else { - // open localization - lcl_ext_open(); - CFILE *ftemp = cfopen(mission_name, "rt", CFILE_NORMAL, CF_TYPE_MISSIONS); - // fail situation. - if (!ftemp) { - if (!Fred_running) - Error( LOCATION, "Couldn't open mission '%s'\n", mission_name ); + // open localization + lcl_ext_open(); - Current_file_length = -1; - Current_file_checksum = 0; + CFILE *ftemp = cfopen(mission_name, "rt", CFILE_NORMAL, CF_TYPE_MISSIONS); + // fail situation. + if (!ftemp) { + if (!Fred_running) + Error( LOCATION, "Couldn't open mission '%s'\n", mission_name ); - // close localization - lcl_ext_close(); + Current_file_length = -1; + Current_file_checksum = 0; - return -1; - } + // close localization + lcl_ext_close(); - Current_file_length = cfilelength(ftemp); - cfclose(ftemp); + return -1; + } + Current_file_length = cfilelength(ftemp); + cfclose(ftemp); + + try { read_file_text(mission_name, CF_TYPE_MISSIONS); memset(&The_mission, 0, sizeof(The_mission)); parse_mission(&The_mission, flags); display_parse_diagnostics(); - - // close localization - lcl_ext_close(); + } catch (parse_error_t rval) { + nprintf(("Error", "Error abort! Code = %i.", (int)rval)); + return (int)rval; } + // close localization + lcl_ext_close(); + if (!Fred_running) SDL_strlcpy(Mission_filename, mission_name, sizeof(Mission_filename)); @@ -4024,7 +4020,7 @@ void mission_parse_do_initial_docks() // function which returns true or false if the given mission support multiplayers int mission_parse_is_multi(const char *filename, char *mission_name) { - int rval, game_type; + int game_type; int filelength; CFILE *ftemp; @@ -4046,9 +4042,7 @@ int mission_parse_is_multi(const char *filename, char *mission_name) // open localization lcl_ext_open(); - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Bogus! Trying to get multi game type on mission %s returned as a mission from cf_get_filelist\n"); - } else { + try { read_file_text(filename, CF_TYPE_MISSIONS); reset_parse(); if ( skip_to_string("$Name:") != 1 ) { @@ -4069,7 +4063,10 @@ int mission_parse_is_multi(const char *filename, char *mission_name) return 0; } stuff_int(&game_type); + } catch (parse_error_t) { + Error(LOCATION, "Bogus! Trying to get multi game type on mission %s returned as a mission from cf_get_filelist\n", filename); } + if ( game_type & MISSION_TYPE_MULTI ){ // close localization lcl_ext_close(); diff --git a/src/missionui/missiondebrief.cpp b/src/missionui/missiondebrief.cpp index 7660d22..2a7c426 100644 --- a/src/missionui/missiondebrief.cpp +++ b/src/missionui/missiondebrief.cpp @@ -1488,60 +1488,59 @@ void debrief_traitor_init() if ( !inited ) { debriefing *debrief; debrief_stage *stagep; - int rval; int stage_num; - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Unable to parse traitor.tbl! Code = %i.\n", rval); - } - else { - read_file_text("traitor.tbl"); - reset_parse(); - } - // open localization lcl_ext_open(); - // simplied form of the debriefing stuff. - debrief = &Traitor_debriefing; - required_string("#Debriefing_info"); - - required_string("$Num stages:"); - stuff_int(&debrief->num_stages); - SDL_assert(debrief->num_stages == 1); - - stage_num = 0; - stagep = &debrief->stages[stage_num++]; - required_string("$Formula:"); - stagep->formula = get_sexp_main(); - required_string("$multi text"); - if ( Fred_running ) { - stuff_string( stagep->new_text, F_MULTITEXT, NULL, MAX_DEBRIEF_LEN); - } else { - stagep->new_text = stuff_and_malloc_string( F_MULTITEXT, NULL, MAX_DEBRIEF_LEN); - } - required_string("$Voice:"); - char traitor_voice_file[NAME_LENGTH]; - stuff_string(traitor_voice_file, F_FILESPEC, NULL); + try { + read_file_text("traitor.tbl"); + reset_parse(); + + // simplied form of the debriefing stuff. + debrief = &Traitor_debriefing; + required_string("#Debriefing_info"); + + required_string("$Num stages:"); + stuff_int(&debrief->num_stages); + SDL_assert(debrief->num_stages == 1); + + stage_num = 0; + stagep = &debrief->stages[stage_num++]; + required_string("$Formula:"); + stagep->formula = get_sexp_main(); + required_string("$multi text"); + if ( Fred_running ) { + stuff_string( stagep->new_text, F_MULTITEXT, NULL, MAX_DEBRIEF_LEN); + } else { + stagep->new_text = stuff_and_malloc_string( F_MULTITEXT, NULL, MAX_DEBRIEF_LEN); + } + required_string("$Voice:"); + char traitor_voice_file[NAME_LENGTH]; + stuff_string(traitor_voice_file, F_FILESPEC, NULL); // DKA 9/13/99 Only 1 traitor msg for FS2 #ifdef MAKE_FS1 - if ( Player->on_bastion ) { - SDL_strlcpy(stagep->voice, NOX("3_"), sizeof(stagep->voice)); - } else { - SDL_strlcpy(stagep->voice, NOX("1_"), sizeof(stagep->voice)); - } + if ( Player->on_bastion ) { + SDL_strlcpy(stagep->voice, NOX("3_"), sizeof(stagep->voice)); + } else { + SDL_strlcpy(stagep->voice, NOX("1_"), sizeof(stagep->voice)); + } #endif - SDL_strlcat(stagep->voice, traitor_voice_file, sizeof(stagep->voice)); + SDL_strlcat(stagep->voice, traitor_voice_file, sizeof(stagep->voice)); - required_string("$Recommendation text:"); - if ( Fred_running ) { - stuff_string( stagep->new_recommendation_text, F_MULTITEXT, NULL, MAX_RECOMMENDATION_LEN); - } else { - stagep->new_recommendation_text = stuff_and_malloc_string( F_MULTITEXT, NULL, MAX_RECOMMENDATION_LEN); + required_string("$Recommendation text:"); + if ( Fred_running ) { + stuff_string( stagep->new_recommendation_text, F_MULTITEXT, NULL, MAX_RECOMMENDATION_LEN); + } else { + stagep->new_recommendation_text = stuff_and_malloc_string( F_MULTITEXT, NULL, MAX_RECOMMENDATION_LEN); + } + + inited = 1; + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse traitor.tbl! Code = %i.\n", (int)rval); } - inited = 1; // close localization lcl_ext_close(); diff --git a/src/nebula/neb.cpp b/src/nebula/neb.cpp index 743e222..226c582 100644 --- a/src/nebula/neb.cpp +++ b/src/nebula/neb.cpp @@ -313,32 +313,36 @@ void neb2_init() #ifndef MAKE_FS1 char name[255] = ""; - // read in the nebula.tbl - read_file_text("nebula.tbl"); - reset_parse(); - - // background bitmaps - Neb2_bitmap_count = 0; - while(!optional_string("#end")){ - // nebula - required_string("+Nebula:"); - stuff_string(name, F_NAME, NULL); - - if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){ - SDL_strlcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name, sizeof(Neb2_bitmap_filenames[0])); + try { + // read in the nebula.tbl + read_file_text("nebula.tbl"); + reset_parse(); + + // background bitmaps + Neb2_bitmap_count = 0; + while(!optional_string("#end")){ + // nebula + required_string("+Nebula:"); + stuff_string(name, F_NAME, NULL); + + if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){ + SDL_strlcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name, sizeof(Neb2_bitmap_filenames[0])); + } } - } - // poofs - Neb2_poof_count = 0; - while(!optional_string("#end")){ - // nebula - required_string("+Poof:"); - stuff_string(name, F_NAME, NULL); + // poofs + Neb2_poof_count = 0; + while(!optional_string("#end")){ + // nebula + required_string("+Poof:"); + stuff_string(name, F_NAME, NULL); - if(Neb2_poof_count < MAX_NEB2_POOFS){ - SDL_strlcpy(Neb2_poof_filenames[Neb2_poof_count++], name, sizeof(Neb2_poof_filenames[0])); + if(Neb2_poof_count < MAX_NEB2_POOFS){ + SDL_strlcpy(Neb2_poof_filenames[Neb2_poof_count++], name, sizeof(Neb2_poof_filenames[0])); + } } + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse nebula.tbl! Code = %i.\n", (int)rval); } // should always have 6 neb poofs diff --git a/src/nebula/neblightning.cpp b/src/nebula/neblightning.cpp index 4a42a89..a6c465d 100644 --- a/src/nebula/neblightning.cpp +++ b/src/nebula/neblightning.cpp @@ -352,146 +352,150 @@ void nebl_init() storm_type bogus_storm, *s; int temp; - // parse the lightning table - read_file_text("lightning.tbl"); - reset_parse(); + try { + // parse the lightning table + read_file_text("lightning.tbl"); + reset_parse(); + + Num_bolt_types = 0; + Num_storm_types = 0; + + memset(Bolt_types, 0, sizeof(bolt_type) * MAX_BOLT_TYPES_INTERNAL); + + // parse the individual lightning bolt types + required_string("#Bolts begin"); + while(!optional_string("#Bolts end")){ + // get a pointer + if(Num_bolt_types >= MAX_BOLT_TYPES){ + l = &bogus_lightning; + } else { + l = &Bolt_types[Num_bolt_types]; + } - Num_bolt_types = 0; - Num_storm_types = 0; + // bolt title + required_string("$Bolt:"); + stuff_string(l->name, F_NAME, NULL); - memset(Bolt_types, 0, sizeof(bolt_type) * MAX_BOLT_TYPES_INTERNAL); + // b_scale + required_string("+b_scale:"); + stuff_float(&l->b_scale); - // parse the individual lightning bolt types - required_string("#Bolts begin"); - while(!optional_string("#Bolts end")){ - // get a pointer - if(Num_bolt_types >= MAX_BOLT_TYPES){ - l = &bogus_lightning; - } else { - l = &Bolt_types[Num_bolt_types]; - } + // b_shrink + required_string("+b_shrink:"); + stuff_float(&l->b_shrink); - // bolt title - required_string("$Bolt:"); - stuff_string(l->name, F_NAME, NULL); + // b_poly_pct + required_string("+b_poly_pct:"); + stuff_float(&l->b_poly_pct); - // b_scale - required_string("+b_scale:"); - stuff_float(&l->b_scale); + // child rand + required_string("+b_rand:"); + stuff_float(&l->b_rand); - // b_shrink - required_string("+b_shrink:"); - stuff_float(&l->b_shrink); + // z add + required_string("+b_add:"); + stuff_float(&l->b_add); - // b_poly_pct - required_string("+b_poly_pct:"); - stuff_float(&l->b_poly_pct); + // # strikes + required_string("+b_strikes:"); + stuff_int(&l->num_strikes); - // child rand - required_string("+b_rand:"); - stuff_float(&l->b_rand); + // lifetime + required_string("+b_lifetime:"); + stuff_int(&l->lifetime); - // z add - required_string("+b_add:"); - stuff_float(&l->b_add); + // noise + required_string("+b_noise:"); + stuff_float(&l->noise); - // # strikes - required_string("+b_strikes:"); - stuff_int(&l->num_strikes); + // emp effect + required_string("+b_emp:"); + stuff_float(&l->emp_intensity); + stuff_float(&l->emp_time); - // lifetime - required_string("+b_lifetime:"); - stuff_int(&l->lifetime); + // texture + required_string("+b_texture:"); + stuff_string(name, F_NAME, NULL); + if((l != &bogus_lightning) && !Fred_running){ + l->texture = bm_load(name); + } - // noise - required_string("+b_noise:"); - stuff_float(&l->noise); + // glow + required_string("+b_glow:"); + stuff_string(name, F_NAME, NULL); + if((l != &bogus_lightning) && !Fred_running){ + l->glow = bm_load(name); + } - // emp effect - required_string("+b_emp:"); - stuff_float(&l->emp_intensity); - stuff_float(&l->emp_time); + // brightness + required_string("+b_bright:"); + stuff_float(&l->b_bright); - // texture - required_string("+b_texture:"); - stuff_string(name, F_NAME, NULL); - if((l != &bogus_lightning) && !Fred_running){ - l->texture = bm_load(name); + // increment the # of bolt types + if(l != &bogus_lightning){ + Num_bolt_types++; + } } - // glow - required_string("+b_glow:"); - stuff_string(name, F_NAME, NULL); - if((l != &bogus_lightning) && !Fred_running){ - l->glow = bm_load(name); - } + // copy the first bolt to the debug bolt + memcpy(&Bolt_types[DEBUG_BOLT], &Bolt_types[0], sizeof(bolt_type)); - // brightness - required_string("+b_bright:"); - stuff_float(&l->b_bright); + // parse storm types + required_string("#Storms begin"); + while(!optional_string("#Storms end")){ + // get a pointer + if(Num_storm_types >= MAX_STORM_TYPES){ + s = &bogus_storm; + } else { + s = &Storm_types[Num_storm_types]; + } - // increment the # of bolt types - if(l != &bogus_lightning){ - Num_bolt_types++; - } - } + // bolt title + required_string("$Storm:"); + stuff_string(s->name, F_NAME, NULL); - // copy the first bolt to the debug bolt - memcpy(&Bolt_types[DEBUG_BOLT], &Bolt_types[0], sizeof(bolt_type)); + // bolt types + s->num_bolt_types = 0; + while(optional_string("+bolt:")){ + stuff_string(name, F_NAME, NULL); - // parse storm types - required_string("#Storms begin"); - while(!optional_string("#Storms end")){ - // get a pointer - if(Num_storm_types >= MAX_STORM_TYPES){ - s = &bogus_storm; - } else { - s = &Storm_types[Num_storm_types]; - } + // fill this guy in + if(s->num_bolt_types < MAX_BOLT_TYPES){ + s->bolt_types[s->num_bolt_types] = (char)nebl_get_bolt_index(name); + SDL_assert(s->bolt_types[s->num_bolt_types] != -1); - // bolt title - required_string("$Storm:"); - stuff_string(s->name, F_NAME, NULL); - - // bolt types - s->num_bolt_types = 0; - while(optional_string("+bolt:")){ - stuff_string(name, F_NAME, NULL); - - // fill this guy in - if(s->num_bolt_types < MAX_BOLT_TYPES){ - s->bolt_types[s->num_bolt_types] = (char)nebl_get_bolt_index(name); - SDL_assert(s->bolt_types[s->num_bolt_types] != -1); - - s->num_bolt_types++; - } - // bogus - else { - required_string("+bolt_prec:"); - stuff_int(&temp); - } - } + s->num_bolt_types++; + } + // bogus + else { + required_string("+bolt_prec:"); + stuff_int(&temp); + } + } - // flavor - required_string("+flavor:"); - stuff_float(&s->flavor.xyz.x); - stuff_float(&s->flavor.xyz.y); - stuff_float(&s->flavor.xyz.z); - - // frequencies - required_string("+random_freq:"); - stuff_int(&s->min); - stuff_int(&s->max); - - // counts - required_string("+random_count:"); - stuff_int(&s->min_count); - stuff_int(&s->max_count); - - // increment the # of bolt types - if(s != &bogus_storm){ - Num_storm_types++; + // flavor + required_string("+flavor:"); + stuff_float(&s->flavor.xyz.x); + stuff_float(&s->flavor.xyz.y); + stuff_float(&s->flavor.xyz.z); + + // frequencies + required_string("+random_freq:"); + stuff_int(&s->min); + stuff_int(&s->max); + + // counts + required_string("+random_count:"); + stuff_int(&s->min_count); + stuff_int(&s->max_count); + + // increment the # of bolt types + if(s != &bogus_storm){ + Num_storm_types++; + } } + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse lightning.tbl! Code = %i.\n", (int)rval); } #endif } diff --git a/src/palman/palman.cpp b/src/palman/palman.cpp index 318348a..65055a0 100644 --- a/src/palman/palman.cpp +++ b/src/palman/palman.cpp @@ -266,19 +266,24 @@ int palman_is_nondarkening(int r,int g, int b) void palman_load_pixels() { #ifndef MAKE_FS1 - // open pixels.tbl - read_file_text("pixels.tbl"); - reset_parse(); - - // parse pixels - while(!optional_string("#END")){ - // nondarkening pixel - if(required_string("+ND")){ - stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][0]); - stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][1]); - stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default++][2]); + try { + // open pixels.tbl + read_file_text("pixels.tbl"); + reset_parse(); + + // parse pixels + while(!optional_string("#END")){ + // nondarkening pixel + if(required_string("+ND")){ + stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][0]); + stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][1]); + stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default++][2]); + } } + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse pixels.tbl! Code = %i.\n", (int)rval); } + #else // hard-coded FS1 values Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 255; diff --git a/src/parse/parselo.cpp b/src/parse/parselo.cpp index 699dae6..fb44102 100644 --- a/src/parse/parselo.cpp +++ b/src/parse/parselo.cpp @@ -113,7 +113,6 @@ #include #include #include -#include #include "pstypes.h" #include "parselo.h" @@ -134,7 +133,6 @@ int my_errno; int Warning_count, Error_count; int fred_parse_flag = 0; int Token_found_flag; -jmp_buf parse_abort; char Mission_text[MISSION_TEXT_SIZE]; char Mission_text_raw[MISSION_TEXT_SIZE]; @@ -443,7 +441,7 @@ int required_string(const char *pstr) if (count == RS_MAX_TRIES) { nprintf(("Error", "Error: Unable to find required token [%s]\n", pstr)); Warning(LOCATION, "Error: Unable to find required token [%s]\n", pstr); - longjmp(parse_abort, 1); + throw PARSE_ERROR_MISSING_TOKEN; } Mp += strlen(pstr); @@ -589,7 +587,7 @@ int required_string_either(const char *str1, const char *str2) if (count == RS_MAX_TRIES) { nprintf(("Error", "Error: Unable to find either required token [%s] or [%s]\n", str1, str2)); Warning(LOCATION, "Error: Unable to find either required token [%s] or [%s]\n", str1, str2); - longjmp(parse_abort, 2); + throw PARSE_ERROR_MISSING_TOKEN_EITHER; } return -1; @@ -721,7 +719,7 @@ void copy_text_until(char *outstr, const char *instr, const char *endstr, int ma if (foundstr == NULL) { nprintf(("Error", "Error. Looking for [%s], but never found it.\n", endstr)); - longjmp(parse_abort, 3); + throw PARSE_ERROR_MISSING_STRING; } if (foundstr - instr + strlen(endstr) < (uint) max_chars) { @@ -731,7 +729,7 @@ void copy_text_until(char *outstr, const char *instr, const char *endstr, int ma nprintf(("Error", "Error. Too much text (%i chars, %i allowed) before %s\n", foundstr - instr - strlen(endstr), max_chars, endstr)); - longjmp(parse_abort, 4); + throw PARSE_ERROR_TOO_LONG; } diag_printf("Here's the partial wad of text:\n%.30s", outstr); @@ -1152,13 +1150,13 @@ void read_file_text(const char *filename, int mode) int file_is_encrypted = 0, in_comment = 0; if (!filename) - longjmp(parse_abort, 10); + throw PARSE_ERROR_EMPTY_FILENAME; SDL_strlcpy(Current_filename, filename, sizeof(Current_filename)); mf = cfopen(filename, "rb", CFILE_NORMAL, mode); if (mf == NULL) { nprintf(("Error", "Wokka! Error opening mission.txt!\n")); - longjmp(parse_abort, 5); + throw PARSE_ERROR_FILE_NOT_FOUND; } // read the entire file in @@ -1386,7 +1384,7 @@ int stuff_string_list(char slp[][NAME_LENGTH], int max_strings) if ( *Mp != '(' ) { error_display(1, "Reading string list. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 100); + throw PARSE_ERROR_STRING_LIST; } Mp++; @@ -1417,7 +1415,7 @@ int stuff_int_list(int *ilp, int max_ints, int lookup_type) if (*Mp != '(') { error_display(1, "Reading integer list. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 6); + throw PARSE_ERROR_INT_LIST; } Mp++; @@ -1505,7 +1503,7 @@ void mark_int_list(int *ilp, int max_ints, int lookup_type) if (*Mp != '(') { error_display(1, "Marking integer list. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 6); + throw PARSE_ERROR_INT_LIST; } Mp++; @@ -1570,14 +1568,14 @@ void stuff_parenthesized_vector(vector *vp) if (*Mp != '(') { error_display(1, "Reading parenthesized vector. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 11); + throw PARSE_ERROR_VECTOR_PSTART; } else { Mp++; stuff_vector(vp); ignore_white_space(); if (*Mp != ')') { error_display(1, "Reading parenthesized vector. Found [%c]. Expecting ')'.\n", *Mp); - longjmp(parse_abort, 12); + throw PARSE_ERROR_VECTOR_PEND; } Mp++; } @@ -1597,7 +1595,7 @@ int stuff_vector_list(vector *vlp, int max_vecs) if (*Mp != '(') { error_display(1, "Reading integer list. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 6); + throw PARSE_ERROR_INT_LIST; } Mp++; diff --git a/src/parse/sexp.cpp b/src/parse/sexp.cpp index 405d80b..f5465cf 100644 --- a/src/parse/sexp.cpp +++ b/src/parse/sexp.cpp @@ -2020,7 +2020,7 @@ int stuff_sexp_variable_list() // check for start of list if (*Mp != '(') { error_display(1, "Reading sexp variable list. Found [%c]. Expecting '('.\n", *Mp); - longjmp(parse_abort, 6); + throw PARSE_ERROR_INT_LIST; } Mp++; diff --git a/src/ship/aicode.cpp b/src/ship/aicode.cpp index 3527cc4..f537fdd 100644 --- a/src/ship/aicode.cpp +++ b/src/ship/aicode.cpp @@ -1108,12 +1108,10 @@ void ai_init() { if ( !ai_inited ) { // Do the first time initialization stuff here - int rval; - - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'ai.tbl'\r\nError code = %i.\r\n", rval); - } else { + try { parse_aitbl(); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'ai.tbl'\r\nError code = %i.\r\n", (int)rval); } ai_inited = 1; diff --git a/src/ship/ship.cpp b/src/ship/ship.cpp index 60e7f59..58ead57 100644 --- a/src/ship/ship.cpp +++ b/src/ship/ship.cpp @@ -667,7 +667,6 @@ */ #include -#include #include "pstypes.h" #include "object.h" @@ -1752,15 +1751,12 @@ DCF_BOOL( show_velocity_dot, ship_show_velocity_dot ) // structure void ship_init() { - int rval; - if ( !ships_inited ) { - - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'ships.tbl'\r\nError code = %i.\r\n", rval); - } else { + try { parse_shiptbl(); ships_inited = 1; + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'ships.tbl'\r\nError code = %i.\r\n", (int)rval); } ship_iff_init_colors(); diff --git a/src/starfield/starfield.cpp b/src/starfield/starfield.cpp index 880c73c..f9c5d92 100644 --- a/src/starfield/starfield.cpp +++ b/src/starfield/starfield.cpp @@ -382,132 +382,136 @@ void stars_init() char glow_filename[MAX_FILENAME_LEN+1] = ""; float r, g, b, i; - // parse stars.tbl - read_file_text("stars.tbl"); - reset_parse(); - - // make all bitmaps invalid - for(idx=0; idxfilename, filename, sizeof(bm->filename)); - bm->xparent = 0; - bm->bitmap = bm_load(bm->filename); - SDL_assert(bm->bitmap != -1); - - // if fred is running we should lock the bitmap now - if(Fred_running && (bm->bitmap >= 0)){ - bm_lock(bm->bitmap, 8, BMP_TEX_OTHER); - bm_unlock(bm->bitmap); - } - } + try { + // parse stars.tbl + read_file_text("stars.tbl"); + reset_parse(); + + // make all bitmaps invalid + for(idx=0; idxfilename, filename, sizeof(bm->filename)); - bm->xparent = 1; - bm->bitmap = bm_load(bm->filename); - SDL_assert(bm->bitmap != -1); - - // if fred is running we should lock as a 0, 255, 0 bitmap now - if(Fred_running && (bm->bitmap >= 0)){ - bm_lock(bm->bitmap, 8, BMP_TEX_XPARENT); - bm_unlock(bm->bitmap); - } - } - } - } - // sun bitmaps - count = 0; - while(!optional_string("#end")){ - if(optional_string("$Sun:")){ - stuff_string(filename, F_NAME, NULL); - - // associated glow - required_string("$Sunglow:"); - stuff_string(glow_filename, F_NAME, NULL); - - // associated lighting values - required_string("$SunRGBI:"); - stuff_float(&r); - stuff_float(&g); - stuff_float(&b); - stuff_float(&i); - - if(count < MAX_STARFIELD_BITMAPS){ - bm = &Sun_bitmaps[count++]; - SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); - SDL_strlcpy(bm->glow_filename, glow_filename, sizeof(bm->glow_filename)); - bm->xparent = 1; - bm->bitmap = bm_load(bm->filename); - bm->glow_bitmap = bm_load(bm->glow_filename); - SDL_assert(bm->bitmap != -1); - SDL_assert(bm->glow_bitmap != -1); - bm->r = r; - bm->g = g; - bm->b = b; - bm->i = i; - - // if fred is running we should lock the bitmap now - if(Fred_running){ - if(bm->bitmap >= 0){ + // starfield bitmaps + count = 0; + while(!optional_string("#end")){ + // intensity alpha bitmap + if(optional_string("$Bitmap:")){ + stuff_string(filename, F_NAME, NULL); + if(count < MAX_STARFIELD_BITMAPS){ + bm = &Starfield_bitmaps[count++]; + SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); + bm->xparent = 0; + bm->bitmap = bm_load(bm->filename); + SDL_assert(bm->bitmap != -1); + + // if fred is running we should lock the bitmap now + if(Fred_running && (bm->bitmap >= 0)){ bm_lock(bm->bitmap, 8, BMP_TEX_OTHER); bm_unlock(bm->bitmap); } - if(bm->glow_bitmap >= 0){ - bm_lock(bm->glow_bitmap, 8, BMP_TEX_OTHER); - bm_unlock(bm->glow_bitmap); + } + } + // green xparency bitmap + else if(optional_string("$BitmapX:")){ + stuff_string(filename, F_NAME, NULL); + if(count < MAX_STARFIELD_BITMAPS){ + bm = &Starfield_bitmaps[count++]; + SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); + bm->xparent = 1; + bm->bitmap = bm_load(bm->filename); + SDL_assert(bm->bitmap != -1); + + // if fred is running we should lock as a 0, 255, 0 bitmap now + if(Fred_running && (bm->bitmap >= 0)){ + bm_lock(bm->bitmap, 8, BMP_TEX_XPARENT); + bm_unlock(bm->bitmap); } - } + } } } - } - // normal debris pieces - count = 0; - while(!optional_string("#end")){ - required_string("$Debris:"); - stuff_string(filename, F_NAME, NULL); + // sun bitmaps + count = 0; + while(!optional_string("#end")){ + if(optional_string("$Sun:")){ + stuff_string(filename, F_NAME, NULL); + + // associated glow + required_string("$Sunglow:"); + stuff_string(glow_filename, F_NAME, NULL); + + // associated lighting values + required_string("$SunRGBI:"); + stuff_float(&r); + stuff_float(&g); + stuff_float(&b); + stuff_float(&i); + + if(count < MAX_STARFIELD_BITMAPS){ + bm = &Sun_bitmaps[count++]; + SDL_strlcpy(bm->filename, filename, sizeof(bm->filename)); + SDL_strlcpy(bm->glow_filename, glow_filename, sizeof(bm->glow_filename)); + bm->xparent = 1; + bm->bitmap = bm_load(bm->filename); + bm->glow_bitmap = bm_load(bm->glow_filename); + SDL_assert(bm->bitmap != -1); + SDL_assert(bm->glow_bitmap != -1); + bm->r = r; + bm->g = g; + bm->b = b; + bm->i = i; + + // if fred is running we should lock the bitmap now + if(Fred_running){ + if(bm->bitmap >= 0){ + bm_lock(bm->bitmap, 8, BMP_TEX_OTHER); + bm_unlock(bm->bitmap); + } + if(bm->glow_bitmap >= 0){ + bm_lock(bm->glow_bitmap, 8, BMP_TEX_OTHER); + bm_unlock(bm->glow_bitmap); + } + } + } + } + } + + // normal debris pieces + count = 0; + while(!optional_string("#end")){ + required_string("$Debris:"); + stuff_string(filename, F_NAME, NULL); - if(count < MAX_DEBRIS_VCLIPS){ - SDL_strlcpy(debris_vclips_normal[count++].name, filename, sizeof(debris_vclips_normal[0].name)); + if(count < MAX_DEBRIS_VCLIPS){ + SDL_strlcpy(debris_vclips_normal[count++].name, filename, sizeof(debris_vclips_normal[0].name)); + } } - } - SDL_assert(count == 4); + SDL_assert(count == 4); - // nebula debris pieces - count = 0; - while(!optional_string("#end")){ - required_string("$DebrisNeb:"); - stuff_string(filename, F_NAME, NULL); + // nebula debris pieces + count = 0; + while(!optional_string("#end")){ + required_string("$DebrisNeb:"); + stuff_string(filename, F_NAME, NULL); - if(count < MAX_DEBRIS_VCLIPS){ - SDL_strlcpy(debris_vclips_nebula[count++].name, filename, sizeof(debris_vclips_nebula[0].name)); + if(count < MAX_DEBRIS_VCLIPS){ + SDL_strlcpy(debris_vclips_nebula[count++].name, filename, sizeof(debris_vclips_nebula[0].name)); + } } - } - SDL_assert(count == 4); + SDL_assert(count == 4); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse stars.tbl! Code = %i.\n", (int)rval); + } #else // hard-coded for FS1 starfield_bitmap *bm; diff --git a/src/stats/medals.cpp b/src/stats/medals.cpp index 948ac93..806c839 100644 --- a/src/stats/medals.cpp +++ b/src/stats/medals.cpp @@ -439,69 +439,70 @@ int Init_flags; void parse_medal_tbl() { - int rval, num_medals, i, bi; - - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'medals.tbl'\r\nError code = %i.\r\n", rval); - } + int num_medals = 0, i, bi; // open localization lcl_ext_open(); - read_file_text("medals.tbl"); - - reset_parse(); - - // parse in all the rank names - num_medals = 0; - bi = 0; - required_string("#Medals"); - while ( required_string_either("#End", "$Name:") ) { - SDL_assert ( num_medals < NUM_MEDALS); - required_string("$Name:"); - stuff_string( Medals[num_medals].name, F_NAME, NULL ); - required_string("$Bitmap:"); - stuff_string( Medals[num_medals].bitmap, F_NAME, NULL ); - required_string("$Num mods:"); - stuff_int( &Medals[num_medals].num_versions); - - // some medals are based on kill counts. When string +Num Kills: is present, we know that - // this medal is a badge and should be treated specially - Medals[num_medals].kills_needed = 0; - if ( optional_string("+Num Kills:") ) { - char buf[MULTITEXT_LENGTH + 1]; - - SDL_assert( bi < MAX_BADGES ); - stuff_int( &Medals[num_medals].kills_needed ); - Badge_index[bi] = num_medals; -#ifdef MAKE_FS1 - required_string("$Wavefile 1:"); - stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); - required_string("$Wavefile 2:"); - stuff_string(Badge_info[bi].voice_base2, F_NAME, NULL, MAX_FILENAME_LEN); -#elif FS2_DEMO -#warning FS2_DEMO HACK: Wavefile 1/2: wave1? wave2? - required_string("$Wavefile 1:"); - stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); - required_string("$Wavefile 2:"); - stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); - //stuff_string(Badge_info[bi].wave2, F_NAME, NULL, MAX_FILENAME_LEN); -#else - required_string("$Wavefile Base:"); - stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); -#endif - - required_string("$Promotion Text:"); - stuff_string(buf, F_MULTITEXT, NULL); - Badge_info[bi].promotion_text = strdup(buf); + try { + read_file_text("medals.tbl"); + + reset_parse(); + + // parse in all the rank names + num_medals = 0; + bi = 0; + required_string("#Medals"); + while ( required_string_either("#End", "$Name:") ) { + SDL_assert ( num_medals < NUM_MEDALS); + required_string("$Name:"); + stuff_string( Medals[num_medals].name, F_NAME, NULL ); + required_string("$Bitmap:"); + stuff_string( Medals[num_medals].bitmap, F_NAME, NULL ); + required_string("$Num mods:"); + stuff_int( &Medals[num_medals].num_versions); + + // some medals are based on kill counts. When string +Num Kills: is present, we know that + // this medal is a badge and should be treated specially + Medals[num_medals].kills_needed = 0; + if ( optional_string("+Num Kills:") ) { + char buf[MULTITEXT_LENGTH + 1]; + + SDL_assert( bi < MAX_BADGES ); + stuff_int( &Medals[num_medals].kills_needed ); + Badge_index[bi] = num_medals; + #ifdef MAKE_FS1 + required_string("$Wavefile 1:"); + stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); + required_string("$Wavefile 2:"); + stuff_string(Badge_info[bi].voice_base2, F_NAME, NULL, MAX_FILENAME_LEN); + #elif FS2_DEMO + #warning FS2_DEMO HACK: Wavefile 1/2: wave1? wave2? + required_string("$Wavefile 1:"); + stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); + required_string("$Wavefile 2:"); + stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); + //stuff_string(Badge_info[bi].wave2, F_NAME, NULL, MAX_FILENAME_LEN); + #else + required_string("$Wavefile Base:"); + stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN); + #endif + + required_string("$Promotion Text:"); + stuff_string(buf, F_MULTITEXT, NULL); + Badge_info[bi].promotion_text = strdup(buf); + + bi++; + } - bi++; + num_medals++; } - num_medals++; + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'medals.tbl'\r\nError code = %i.\r\n", (int)rval); } - required_string("#End"); SDL_assert( num_medals == NUM_MEDALS ); // be sure that the badges kill numbers show up in order diff --git a/src/stats/scoring.cpp b/src/stats/scoring.cpp index 151d4f0..40c8ae5 100644 --- a/src/stats/scoring.cpp +++ b/src/stats/scoring.cpp @@ -234,41 +234,41 @@ float Scoring_scale_factors[NUM_SKILL_LEVELS] = { void parse_rank_tbl() { char buf[MULTITEXT_LENGTH]; - int rval, idx; - - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'rank.tbl'\r\nError code = %i.\r\n", rval); - } + int idx; // open localization lcl_ext_open(); - read_file_text("rank.tbl"); - reset_parse(); - - // parse in all the rank names - idx = 0; - skip_to_string("[RANK NAMES]"); - ignore_white_space(); - while ( required_string_either("#End", "$Name:") ) { - SDL_assert ( idx < NUM_RANKS ); - required_string("$Name:"); - stuff_string( Ranks[idx].name, F_NAME, NULL ); - required_string("$Points:"); - stuff_int( &Ranks[idx].points ); - required_string("$Bitmap:"); - stuff_string( Ranks[idx].bitmap, F_NAME, NULL ); - required_string("$Promotion Voice Base:"); - stuff_string( Ranks[idx].promotion_voice_base, F_NAME, NULL, MAX_FILENAME_LEN - 2 ); - required_string("$Promotion Text:"); - stuff_string(buf, F_MULTITEXT, NULL); - drop_white_space(buf); - compact_multitext_string(buf); - Ranks[idx].promotion_text = strdup(buf); - idx++; - } + try { + read_file_text("rank.tbl"); + reset_parse(); + + // parse in all the rank names + idx = 0; + skip_to_string("[RANK NAMES]"); + ignore_white_space(); + while ( required_string_either("#End", "$Name:") ) { + SDL_assert ( idx < NUM_RANKS ); + required_string("$Name:"); + stuff_string( Ranks[idx].name, F_NAME, NULL ); + required_string("$Points:"); + stuff_int( &Ranks[idx].points ); + required_string("$Bitmap:"); + stuff_string( Ranks[idx].bitmap, F_NAME, NULL ); + required_string("$Promotion Voice Base:"); + stuff_string( Ranks[idx].promotion_voice_base, F_NAME, NULL, MAX_FILENAME_LEN - 2 ); + required_string("$Promotion Text:"); + stuff_string(buf, F_MULTITEXT, NULL); + drop_white_space(buf); + compact_multitext_string(buf); + Ranks[idx].promotion_text = strdup(buf); + idx++; + } - required_string("#End"); + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'rank.tbl'\r\nError code = %i.\r\n", (int)rval); + } // be sure that all rank points are in order #ifndef NDEBUG diff --git a/src/weapon/muzzleflash.cpp b/src/weapon/muzzleflash.cpp index 857621b..cf283aa 100644 --- a/src/weapon/muzzleflash.cpp +++ b/src/weapon/muzzleflash.cpp @@ -117,52 +117,56 @@ void mflash_game_init() float offset, radius; int idx; - read_file_text("mflash.tbl"); - reset_parse(); - - // header - required_string("#Muzzle flash types"); - - // read em in - Num_mflash_types = 0; - while(optional_string("$Mflash:")){ - if(Num_mflash_types < MAX_MUZZLE_FLASH_TYPES){ - m = &Mflash_info[Num_mflash_types++]; - } else { - m = &bogus; - } - memset(m, 0, sizeof(mflash_info)); - for(idx=0; idxblob_anims[idx] = -1; - } + try { + read_file_text("mflash.tbl"); + reset_parse(); + + // header + required_string("#Muzzle flash types"); + + // read em in + Num_mflash_types = 0; + while(optional_string("$Mflash:")){ + if(Num_mflash_types < MAX_MUZZLE_FLASH_TYPES){ + m = &Mflash_info[Num_mflash_types++]; + } else { + m = &bogus; + } + memset(m, 0, sizeof(mflash_info)); + for(idx=0; idxblob_anims[idx] = -1; + } - required_string("+name:"); - stuff_string(m->name, F_NAME, NULL); + required_string("+name:"); + stuff_string(m->name, F_NAME, NULL); - // read in all blobs - m->num_blobs = 0; - while(optional_string("+blob_name:")){ - stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN); + // read in all blobs + m->num_blobs = 0; + while(optional_string("+blob_name:")){ + stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN); - required_string("+blob_offset:"); - stuff_float(&offset); + required_string("+blob_offset:"); + stuff_float(&offset); - required_string("+blob_radius:"); - stuff_float(&radius); + required_string("+blob_radius:"); + stuff_float(&radius); - // if we have room left - if(m->num_blobs < MAX_MFLASH_BLOBS){ - SDL_strlcpy(m->blob_names[m->num_blobs], name, MAX_MFLASH_NAME_LEN); - m->blob_offset[m->num_blobs] = offset; - m->blob_radius[m->num_blobs] = radius; + // if we have room left + if(m->num_blobs < MAX_MFLASH_BLOBS){ + SDL_strlcpy(m->blob_names[m->num_blobs], name, MAX_MFLASH_NAME_LEN); + m->blob_offset[m->num_blobs] = offset; + m->blob_radius[m->num_blobs] = radius; - m->num_blobs++; + m->num_blobs++; + } } } - } - // close - required_string("#end"); + // close + required_string("#end"); + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'mflash.tbl'\r\nError code = %i.\r\n", (int)rval); + } #else // hardcoded FS1 values int idx; diff --git a/src/weapon/weapons.cpp b/src/weapon/weapons.cpp index b07828a..7f464eb 100644 --- a/src/weapon/weapons.cpp +++ b/src/weapon/weapons.cpp @@ -516,50 +516,49 @@ extern int compute_num_homing_objects(object *target_objp); void parse_weapon_expl_tbl() { #ifndef MAKE_FS1 - int rval, idx; + int idx; char base_filename[256] = ""; // open localization lcl_ext_open(); - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Unable to parse weapon_expl.tbl! Code = %i.\n", rval); - } - else { + try { read_file_text(NOX("weapon_expl.tbl")); - reset_parse(); - } + reset_parse(); - Num_weapon_expl = 0; - required_string("#Start"); - while (required_string_either("#End","$Name:")) { - SDL_assert( Num_weapon_expl < MAX_Weapon_expl_info); + Num_weapon_expl = 0; + required_string("#Start"); + while (required_string_either("#End","$Name:")) { + SDL_assert( Num_weapon_expl < MAX_Weapon_expl_info); - // base filename - required_string("$Name:"); - stuff_string(base_filename, F_NAME, NULL); + // base filename + required_string("$Name:"); + stuff_string(base_filename, F_NAME, NULL); - // # of lod levels - make sure old fireball.tbl is compatible - Weapon_expl_info[Num_weapon_expl].lod_count = 1; - if(optional_string("$LOD:")){ - stuff_int(&Weapon_expl_info[Num_weapon_expl].lod_count); - } + // # of lod levels - make sure old fireball.tbl is compatible + Weapon_expl_info[Num_weapon_expl].lod_count = 1; + if(optional_string("$LOD:")){ + stuff_int(&Weapon_expl_info[Num_weapon_expl].lod_count); + } - // stuff default filename - SDL_strlcpy(Weapon_expl_info[Num_weapon_expl].lod[0].filename, base_filename, MAX_FILENAME_LEN); + // stuff default filename + SDL_strlcpy(Weapon_expl_info[Num_weapon_expl].lod[0].filename, base_filename, MAX_FILENAME_LEN); - // stuff LOD level filenames - for(idx=1; idx= MAX_weapon_expl_lod){ - break; + // stuff LOD level filenames + for(idx=1; idx= MAX_weapon_expl_lod){ + break; + } + + SDL_snprintf(Weapon_expl_info[Num_weapon_expl].lod[idx].filename, MAX_FILENAME_LEN, "%s_%d", base_filename, idx); } - SDL_snprintf(Weapon_expl_info[Num_weapon_expl].lod[idx].filename, MAX_FILENAME_LEN, "%s_%d", base_filename, idx); + Num_weapon_expl++; } - - Num_weapon_expl++; + required_string("#End"); + } catch (parse_error_t rval) { + Error(LOCATION, "Unable to parse weapon_expl.tbl! Code = %i.\n", (int)rval); } - required_string("#End"); // close localization lcl_ext_close(); @@ -1534,20 +1533,18 @@ void create_weapon_names() // This will get called once at game startup void weapon_init() { - int rval; - if ( !Weapons_inited ) { #if !(defined(FS2_DEMO) || defined(FS1_DEMO)) // parse weapon_exp.tbl parse_weapon_expl_tbl(); #endif // parse weapons.tbl - if ((rval = setjmp(parse_abort)) != 0) { - Error(LOCATION, "Error parsing 'weapons.tbl'\r\nError code = %i.\r\n", rval); - } else { + try { parse_weaponstbl(); create_weapon_names(); Weapons_inited = 1; + } catch (parse_error_t rval) { + Error(LOCATION, "Error parsing 'weapons.tbl'\r\nError code = %i.\r\n", (int)rval); } } -- 2.39.2