X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fmisc.c;h=c4c0352db9007474e321a03a14b7d68cb8ce1709;hb=29014045f4de045f8452fdf7ab32622c94b37eef;hp=253a8d7fcee20e336a05b27b9b68843987a34c32;hpb=f9b768303c640858ba5192babe50ba85eab9a8a4;p=rocksndiamonds.git diff --git a/src/misc.c b/src/misc.c index 253a8d7f..c4c0352d 100644 --- a/src/misc.c +++ b/src/misc.c @@ -17,8 +17,10 @@ #include #include #include +#include #include "misc.h" +#include "init.h" #include "tools.h" #include "sound.h" #include "random.h" @@ -73,8 +75,7 @@ static void sleep_milliseconds(unsigned long milliseconds_delay) delay.tv_usec = 1000 * (milliseconds_delay % 1000); if (select(0, NULL, NULL, NULL, &delay) != 0) - fprintf(stderr,"%s: in function sleep_milliseconds: select() failed!\n", - progname); + Error(ERR_RETURN, "sleep_milliseconds(): select() failed"); } } @@ -187,3 +188,59 @@ void MarkTileDirty(int x, int y) redraw_mask |= REDRAW_TILES; } } + +void Error(BOOL fatal_error, char *format_str, ...) +{ + FILE *output_stream = stderr; + va_list ap; + char *format_ptr; + char *s_value; + int i_value; + double d_value; + + va_start(ap, format_str); /* ap points to first unnamed argument */ + + fprintf(output_stream, "%s: ", program_name); + + for(format_ptr=format_str; *format_ptr; format_ptr++) + { + if (*format_ptr != '%') + { + fprintf(output_stream, "%c", *format_ptr); + continue; + } + + switch(*++format_ptr) + { + case 'd': + i_value = va_arg(ap, int); + fprintf(output_stream, "%d", i_value); + break; + + case 'f': + d_value = va_arg(ap, double); + fprintf(output_stream, "%f", d_value); + break; + + case 's': + s_value = va_arg(ap, char *); + fprintf(output_stream, "%s", s_value); + break; + + default: + fprintf(stderr, "\nfatal(): invalid format string: %s\n", format_str); + exit(-1); + } + } + + va_end(ap); + + fprintf(output_stream, "\n"); + + if (fatal_error) + { + fprintf(output_stream, "%s: aborting\n", program_name); + CloseAll(); + exit(1); + } +}