From 45b78d8c3962a64ca098465973e3e9293faffc94 Mon Sep 17 00:00:00 2001 From: EvanR Date: Sat, 20 Feb 2010 14:09:04 -0600 Subject: [PATCH] Error output changed interface throughout code. report_error was renamed to error_msg. cases where printf was used for a boot message in video.c was changed to boot_msg. In other branches (audio) we will need to find those printfs and change them to boot_msg. Some cases of report_error followed by exit(-1) were replaced with fatal_error. --- audio.c | 3 +-- input.c | 10 +++++----- kernel.c | 2 +- loader.c | 11 ++++------- util.c | 17 ++++++++++++----- util.h | 3 ++- video.c | 58 +++++++++++++++++++++++++++------------------------------- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/audio.c b/audio.c index c5b4df3..5cfb9ec 100644 --- a/audio.c +++ b/audio.c @@ -59,8 +59,7 @@ void audio_init(){ if(SDL_OpenAudio(&want, &got)<0){ - report_error("sdl: cannot open audio (%s)\n", SDL_GetError()); - exit(-1); + fatal_error("sdl: cannot open audio (%s)\n", SDL_GetError()); } printf("audio:\n"); diff --git a/input.c b/input.c index dbb96be..62e9386 100644 --- a/input.c +++ b/input.c @@ -113,7 +113,7 @@ enum input_type kmtype(Uint8 type){ case SDL_KEYDOWN: return BUTTON_PRESS; case SDL_KEYUP: return BUTTON_RELEASE; default: - report_error("input map_key: invalid SDL event type\n"); + error_msg("input map_key: invalid SDL event type\n"); return INVALID_INPUT; } } @@ -123,7 +123,7 @@ enum input_type jmtype(Uint8 type){ case SDL_JOYBUTTONDOWN: return BUTTON_PRESS; case SDL_JOYBUTTONUP: return BUTTON_RELEASE; default: - report_error("input map_jbutton: invalid SDL event type\n"); + error_msg("input map_jbutton: invalid SDL event type\n"); return INVALID_INPUT; } } @@ -133,10 +133,10 @@ enum input_button ambutton(int state, struct axis_map* am){ case -1: return am->button[0]; case 1: return am->button[1]; case 0: - report_error("input axis_motion: axis state 0 does not imply a button\n"); + error_msg("input axis_motion: axis state 0 does not imply a button\n"); return INVALID_BUTTON; default: - report_error("input axis_motion: invalid axis state (%d)\n", state); + error_msg("input axis_motion: invalid axis state (%d)\n", state); return INVALID_BUTTON; } } @@ -197,7 +197,7 @@ input axis_motion(Sint16 value, struct axis_map* am){ to do a button press note that without this fix, it wont get stuck, the input system will just be slightly inconsistent*/ - report_error("input axis_motion: (FIXME) joystick almost got stuck\n"); + error_msg("input axis_motion: (FIXME) joystick almost got stuck\n"); } if(diff == 0){ diff --git a/kernel.c b/kernel.c index ad7e6fc..e3bc265 100644 --- a/kernel.c +++ b/kernel.c @@ -58,7 +58,7 @@ static void press(input in){ handler.press(in); } static void release(input in){ handler.release(in); } void dispatch_error(const char* msg){ - report_error("kernel.c dispatch_input: %s\n", msg); + error_msg("kernel.c dispatch_input: %s\n", msg); } static void dispatch_input(){ diff --git a/loader.c b/loader.c index 682b32e..ff45d10 100644 --- a/loader.c +++ b/loader.c @@ -44,7 +44,7 @@ void loader_init(){ if(arc == NULL){ fatal_error("loader: unable to load data archive \"%s\" (%s)\n", filename, zip_geterror()); } - printf("loader: ... OK\n"); + boot_msg("loader: ... OK\n"); } void loader_quit(){ @@ -65,15 +65,12 @@ reader* loader_open(char* filename){ buf[1023] = 0; reader* rd = xmalloc(sizeof(reader)); - rd->next_c = -1; + //rd->next_c = -1; //rd->f = zzip_file_open(zzip_dir, buf, 0); //rd->f = zzip_open(buf, 0); - rd->f = NULL; + rd->f = zip_fopen(arc, filename); if(!rd->f){ - //report_error("loader: unable to open %s (%s)\n", - // filename, zzip_strerror_of( zzip_dir ) ); -/* report_error("loader: unable to open %s (%s)\n", - filename, strerror( errno ) );*/ + error_msg("loader: can't open %s (%s)\n", filename, zip_geterror()); free(rd); return NULL; } diff --git a/util.c b/util.c index bfd24d5..0d56030 100644 --- a/util.c +++ b/util.c @@ -35,23 +35,30 @@ void report_verror(const char* format, va_list ap){ vprintf(format, ap); } -void report_error(const char* format, ...){ +void fatal_error(const char* format, ...){ va_list ap; va_start(ap, format); report_verror(format, ap); va_end(ap); + exit(-1); } -void fatal_error(const char* format, ...){ +void boot_msg(const char* format, ...){ + va_list ap; + va_start(ap, format); + vprintf(format, ap); + va_end(ap); +} + +void error_msg(const char* format, ...){ va_list ap; va_start(ap, format); report_verror(format, ap); va_end(ap); - exit(-1); } void out_of_memory(const char* prefix){ - report_error("%s: *out of memory*\n", prefix); + error_msg("%s: *out of memory*\n", prefix); exit(-2); } @@ -172,7 +179,7 @@ void tree_insert( else{ptr->r = node; break;} } else{ /* key already exists */ - report_error("tree_insert: key already exists\n"); + error_msg("tree_insert: key already exists\n"); break; } } diff --git a/util.h b/util.h index 00cee72..bc18a5a 100644 --- a/util.h +++ b/util.h @@ -22,9 +22,10 @@ typedef unsigned long utf32; -void report_error(const char* format, ...); void fatal_error(const char* format, ...); void out_of_memory(const char*); +void error_msg(const char* format, ...); +void boot_msg(const char* format, ...); void* xmalloc(size_t size); char* strxcpy(const char* str); diff --git a/video.c b/video.c index 71f1245..1e949dc 100644 --- a/video.c +++ b/video.c @@ -174,7 +174,7 @@ SDL_Surface* load_pixmap(char* filename){ int w = header[12] + (header[13]<<8); int h = header[14] + (header[15]<<8); int bpp = header[16]; - printf("load_pixmap: %s has bpp=%d\n",filename, bpp); + //printf("load_pixmap: %s has bpp=%d\n",filename, bpp); SDL_Surface* surf = SDL_CreateRGBSurface(0,w,h,bpp, 0x00ff0000,0x0000ff00,0x000000ff,0xff000000); if(!surf){ @@ -197,7 +197,7 @@ int load_gfx(char* filename){ } - printf("loading %s\n",filename); + //printf("loading %s\n",filename); for(i=0; i