From 810ae2a3ffd7fa2de9034677c67fef6df8d23afd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Nov 2016 14:17:05 -0600 Subject: [PATCH] tcledit: Fix some initialization issues --- .../traveler/tools/libwld/wld_createworld.c | 10 +++---- .../traveler/tools/libwld/wld_loadplanefile.c | 6 ++-- .../traveler/tools/libwld/wld_loadplanes.c | 2 +- graphics/traveler/tools/libwld/wld_plane.h | 2 +- .../tools/libwld/wld_readgraphicfile.c | 4 +-- .../tools/libwld/wld_readtexturefile.c | 2 +- .../traveler/tools/libwld/wld_saveplanes.c | 4 +-- graphics/traveler/tools/tcledit/tcl_edit.c | 9 +++--- .../traveler/tools/tcledit/tcl_x11graphics.c | 30 +++++++++---------- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/graphics/traveler/tools/libwld/wld_createworld.c b/graphics/traveler/tools/libwld/wld_createworld.c index a075c7754..5923c18a0 100644 --- a/graphics/traveler/tools/libwld/wld_createworld.c +++ b/graphics/traveler/tools/libwld/wld_createworld.c @@ -308,7 +308,7 @@ static uint8_t wld_read_shortint(INIHANDLE handle, if (value != INT32_MAX) { - fprintf(stderr, "Error: Integer out of range in INI file:\n"); + fprintf(stderr, "ERROR: Integer out of range in INI file:\n"); fprintf(stderr, " Section=\"%s\" Variable name=\"%s\" value=%ld\n", section_name, variable_name, (long)variable_value); @@ -318,7 +318,7 @@ static uint8_t wld_read_shortint(INIHANDLE handle, else { - fprintf(stderr, "Error: Requird integer not found in INI file:\n"); + fprintf(stderr, "ERROR: Requird integer not found in INI file:\n"); fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n", section_name, variable_name); return WORLD_INTEGER_NOT_FOUND; @@ -375,7 +375,7 @@ static uint8_t wld_read_filename(INIHANDLE handle, *filename = NULL; - fprintf(stderr, "Error: Required filename not found in INI file:\n"); + fprintf(stderr, "ERROR: Required filename not found in INI file:\n"); fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n", section_name, variable_name); return WORLD_FILENAME_NOT_FOUND; @@ -388,7 +388,7 @@ static uint8_t wld_read_filename(INIHANDLE handle, } /************************************************************************* - * Private Functions + * Public Functions *************************************************************************/ /************************************************************************* @@ -407,7 +407,7 @@ uint8_t wld_create_world(char *wldfile) handle = inifile_initialize(wldfile); if (handle == NULL) { - fprintf(stderr, "Error: Could not open INI file=\"%s\"\n", wldfile); + fprintf(stderr, "ERROR: Could not open INI file=\"%s\"\n", wldfile); return WORLD_FILE_OPEN_ERROR; } diff --git a/graphics/traveler/tools/libwld/wld_loadplanefile.c b/graphics/traveler/tools/libwld/wld_loadplanefile.c index 7b3b0a994..0eb01f44c 100644 --- a/graphics/traveler/tools/libwld/wld_loadplanefile.c +++ b/graphics/traveler/tools/libwld/wld_loadplanefile.c @@ -54,18 +54,18 @@ * This function opens the input file and loads the world data from it ************************************************************************/ -uint8_t wld_load_planefile(const char *wldFile) +uint8_t wld_load_planefile(const char *wldfile) { FILE *fp; uint8_t result; /* Open the map file which contains the description of the world */ - fp = fopen(wldFile, "rb"); + fp = fopen(wldfile, "rb"); if (fp == NULL) { fprintf(stderr, "ERROR: Could not open map file=\"%s\": %s\n", - wldFile, strerror(errno)); + wldfile, strerror(errno)); return PLANE_READ_OPEN_ERROR; } diff --git a/graphics/traveler/tools/libwld/wld_loadplanes.c b/graphics/traveler/tools/libwld/wld_loadplanes.c index e6f4ba790..1a7372ca4 100644 --- a/graphics/traveler/tools/libwld/wld_loadplanes.c +++ b/graphics/traveler/tools/libwld/wld_loadplanes.c @@ -71,7 +71,7 @@ static uint8_t wld_load_worldplane(FILE * fp, rect_head_t * list, if (fread((char *)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1) { - fprintf(stderr, "Error: read of rectangle %d (of %d) failed! ", + fprintf(stderr, "ERROR: read of rectangle %d (of %d) failed! ", i, numRects); fprintf(stderr, "feof=%d ferror=%d\n", feof(fp), ferror(fp)); return PLANE_DATA_READ_ERROR; diff --git a/graphics/traveler/tools/libwld/wld_plane.h b/graphics/traveler/tools/libwld/wld_plane.h index 24c9cd982..e094f5b94 100644 --- a/graphics/traveler/tools/libwld/wld_plane.h +++ b/graphics/traveler/tools/libwld/wld_plane.h @@ -181,7 +181,7 @@ uint8_t wld_initialize_planes(void); void wld_discard_planes(void); uint8_t wld_load_planefile(const char *wldfile); uint8_t wld_load_planes(FILE *fp); -uint8_t wld_save_planes(const char *wldFile); +uint8_t wld_save_planes(const char *wldfile); rect_list_t *wld_new_plane(void); void wld_add_plane(rect_list_t *rect, rect_head_t *list); diff --git a/graphics/traveler/tools/libwld/wld_readgraphicfile.c b/graphics/traveler/tools/libwld/wld_readgraphicfile.c index cb5558bdc..85e39e22d 100644 --- a/graphics/traveler/tools/libwld/wld_readgraphicfile.c +++ b/graphics/traveler/tools/libwld/wld_readgraphicfile.c @@ -71,7 +71,7 @@ static graphic_file_format_t wld_check_format(FILE * fp, char *filename) if (fread(magic, 1, MAGIC_LENGTH, fp) != MAGIC_LENGTH) { - wld_fatal_error("Error reading texture %s.", filename); + wld_fatal_error("ERROR: Reading texture %s.", filename); } if (strncmp(magic, PPM_MAGIC, sizeof(PPM_MAGIC) - 1) == 0) @@ -171,7 +171,7 @@ graphic_file_t *wld_readgraphic_file(char *filename) if (gfile == NULL) { - wld_fatal_error("Error reading texture %s\n"); + wld_fatal_error("ERROR: Reading texture %s\n"); } fclose(fp); diff --git a/graphics/traveler/tools/libwld/wld_readtexturefile.c b/graphics/traveler/tools/libwld/wld_readtexturefile.c index b6c6cb4f7..d83a75f1a 100644 --- a/graphics/traveler/tools/libwld/wld_readtexturefile.c +++ b/graphics/traveler/tools/libwld/wld_readtexturefile.c @@ -160,7 +160,7 @@ wld_bitmap_t *wld_read_texturefile(char *filename) gFile = wld_readgraphic_file(filename); if (gFile == NULL) { - wld_fatal_error("Error reading texture %s.", filename); + wld_fatal_error("ERROR: Reading texture %s.", filename); } /* The height and width should be powers of two for efficient texture diff --git a/graphics/traveler/tools/libwld/wld_saveplanes.c b/graphics/traveler/tools/libwld/wld_saveplanes.c index 8e10a0878..cf745c65c 100644 --- a/graphics/traveler/tools/libwld/wld_saveplanes.c +++ b/graphics/traveler/tools/libwld/wld_saveplanes.c @@ -90,7 +90,7 @@ static uint8_t wld_save_worldplane(FILE * fp, rect_list_t * rect) * This function stores the world data into the specified file ************************************************************************/ -uint8_t wld_save_planes(const char *wldFile) +uint8_t wld_save_planes(const char *wldfile) { FILE *fp; plane_file_header_t fileHeader; @@ -98,7 +98,7 @@ uint8_t wld_save_planes(const char *wldFile) /* Open the file which contains the description of the world */ - fp = fopen(wldFile, "wb"); + fp = fopen(wldfile, "wb"); if (!fp) { return PLANE_WRITE_OPEN_ERROR; diff --git a/graphics/traveler/tools/tcledit/tcl_edit.c b/graphics/traveler/tools/tcledit/tcl_edit.c index 1595fec67..93c820010 100644 --- a/graphics/traveler/tools/tcledit/tcl_edit.c +++ b/graphics/traveler/tools/tcledit/tcl_edit.c @@ -47,7 +47,7 @@ #include "trv_types.h" #include "debug.h" -#include "wld_plane.h" +#include "wld_world.h" #include "wld_utils.h" #include "tcl_x11graphics.h" #include "tcl_colors.h" @@ -650,10 +650,11 @@ int main(int argc, char **argv, char **envp) g_in_filename = argv[optind]; - /* Read the plane file now so that we can be certain that it is a valid - * plaine file. */ + /* Read the world files now so that we can be certain that it is a valid + * world file. + */ - if (wld_load_planefile(g_in_filename) != PLANE_SUCCESS) + if (wld_create_world(g_in_filename) != PLANE_SUCCESS) { exit(1); } diff --git a/graphics/traveler/tools/tcledit/tcl_x11graphics.c b/graphics/traveler/tools/tcledit/tcl_x11graphics.c index abc410142..d67bf41f4 100644 --- a/graphics/traveler/tools/tcledit/tcl_x11graphics.c +++ b/graphics/traveler/tools/tcledit/tcl_x11graphics.c @@ -67,7 +67,7 @@ static GC gc; #ifndef NO_XSHM static XShmSegmentInfo xshminfo; -static int xError; +static int xerror; #endif static int shmCheckPoint = 0; static int useShm; @@ -210,43 +210,43 @@ static bool x11_allocate_colors(tcl_window_t * w, Colormap colormap) } /**************************************************************************** - * Name: errorHandler + * Name: x11_error_handler * Description: ***************************************************************************/ #ifndef NO_XSHM -static int errorHandler(Display * display, XErrorEvent * event) +static int x11_error_handler(Display * display, XErrorEvent * event) { - xError = 1; + xerror = 1; return 0; } #endif /**************************************************************************** - * Name: trapErrors + * Name: x11_trap_errors * Description: ***************************************************************************/ #ifndef NO_XSHM -static void trapErrors(void) +static void x11_trap_errors(void) { - xError = 0; - XSetErrorHandler(errorHandler); + xerror = 0; + XSetErrorHandler(x11_error_handler); } #endif /**************************************************************************** - * Name: untrapErrors + * Name: x11_untrap_errors * Description: ***************************************************************************/ #ifndef NO_XSHM -static int untrapErrors(Display * display) +static int x11_untrap_errors(Display * display) { XSync(display, 0); XSetErrorHandler(NULL); - return xError; + return xerror; } #endif @@ -276,13 +276,13 @@ static void x11_map_sharedmemory(tcl_window_t * w, int depth) useShm = 1; printf("Using shared memory.\n"); - trapErrors(); + x11_trap_errors(); w->image = XShmCreateImage(w->display, DefaultVisual(w->display, w->screen), depth, ZPixmap, NULL, &xshminfo, w->width, w->height); - if (untrapErrors(w->display)) + if (x11_untrap_errors(w->display)) { x11_unmap_sharedmemory(w); goto shmerror; @@ -315,9 +315,9 @@ static void x11_map_sharedmemory(tcl_window_t * w, int depth) xshminfo.shmaddr = w->image->data; xshminfo.readOnly = false; - trapErrors(); + x11_trap_errors(); result = XShmAttach(w->display, &xshminfo); - if (untrapErrors(w->display) || !result) + if (x11_untrap_errors(w->display) || !result) { x11_unmap_sharedmemory(w); goto shmerror;