From 0507d9d25493d7d473b21e617ea0d522a11178f0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 Dec 2014 09:28:53 -0600 Subject: Traveler: Change the way that the world path is managed. --- apps/graphics/traveler/Kconfig | 9 +++++ apps/graphics/traveler/include/trv_fsutils.h | 1 + apps/graphics/traveler/include/trv_world.h | 2 +- apps/graphics/traveler/src/trv_fsutils.c | 23 +++++++++++++ apps/graphics/traveler/src/trv_graphics.c | 10 +++--- apps/graphics/traveler/src/trv_input.c | 2 +- apps/graphics/traveler/src/trv_main.c | 49 +++++++++++++-------------- apps/graphics/traveler/src/trv_world.c | 50 +++++++++++++++++----------- 8 files changed, 94 insertions(+), 52 deletions(-) (limited to 'apps/graphics') diff --git a/apps/graphics/traveler/Kconfig b/apps/graphics/traveler/Kconfig index 719b5c3a1..517cd2a0d 100644 --- a/apps/graphics/traveler/Kconfig +++ b/apps/graphics/traveler/Kconfig @@ -18,6 +18,15 @@ config GRAPHICS_TRAVELER_RGB32_888 endchoice # Color format +config GRAPHICS_TRAVELER_DEFPATH + string "Default path to world data" + default "/mnt/world" + ---help--- + This is the default path to the directory where the world file data + can be found. The default world file name is transfrom.wld (not + configurable). + + config GRAPHICS_TRAVELER_PALRANGES bool "Use ranged palette" default y diff --git a/apps/graphics/traveler/include/trv_fsutils.h b/apps/graphics/traveler/include/trv_fsutils.h index 9a3fb15e5..2c7c30730 100644 --- a/apps/graphics/traveler/include/trv_fsutils.h +++ b/apps/graphics/traveler/include/trv_fsutils.h @@ -49,5 +49,6 @@ ****************************************************************************/ int16_t trv_read_decimal(FAR FILE *fp); +FAR char *trv_fullpath(FAR const char *path, FAR const char *name); #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_FSUTILS_H */ diff --git a/apps/graphics/traveler/include/trv_world.h b/apps/graphics/traveler/include/trv_world.h index 97b6c7443..bb9736ad6 100644 --- a/apps/graphics/traveler/include/trv_world.h +++ b/apps/graphics/traveler/include/trv_world.h @@ -85,7 +85,7 @@ extern trv_coord_t g_run_stepheight; * Public Function Prototypes ****************************************************************************/ -int trv_world_create(FAR const char *mapfile); +int trv_world_create(FAR const char *wldpath, FAR const char *wldfile); void trv_world_destroy(void); #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H */ diff --git a/apps/graphics/traveler/src/trv_fsutils.c b/apps/graphics/traveler/src/trv_fsutils.c index ad0f8d30d..ef458d9dc 100644 --- a/apps/graphics/traveler/src/trv_fsutils.c +++ b/apps/graphics/traveler/src/trv_fsutils.c @@ -95,3 +95,26 @@ int16_t trv_read_decimal(FAR FILE *fp) return value; } + +/**************************************************************************** + * Name: trv_fullpath + * + * Description: + * Concatenate a filename and a path to produce the full, absolute path + * to the file. The pointer returned by this function is allocated and + * must be freed by the caller. + * + ***************************************************************************/ + +FAR char *trv_fullpath(FAR const char *path, FAR const char *name) +{ + FAR char *fullpath = NULL; + + (void)asprintf(&fullpath, "%s/%s", path, name); + if (!fullpath) + { + trv_abort("ERROR: Failured to created full path\n"); + } + + return fullpath; +} diff --git a/apps/graphics/traveler/src/trv_graphics.c b/apps/graphics/traveler/src/trv_graphics.c index c37086cab..32e2e199a 100644 --- a/apps/graphics/traveler/src/trv_graphics.c +++ b/apps/graphics/traveler/src/trv_graphics.c @@ -86,7 +86,7 @@ static FAR struct fb_vtable_s *trv_get_fbdev(void) ret = up_fbinitialize(); if (ret < 0) { - trv_abort("up_fbinitialize failed: %d\n", -ret); + trv_abort("ERROR: up_fbinitialize failed: %d\n", -ret); } /* Set up to use video plane 0. There is no support for anything but @@ -96,7 +96,7 @@ static FAR struct fb_vtable_s *trv_get_fbdev(void) fbdev = up_fbgetvplane(0); if (!fbdev) { - trv_abort("up_fbgetvplane(0) failed\n"); + trv_abort("ERROR: up_fbgetvplane(0) failed\n"); } return fbdev; @@ -128,7 +128,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo) ret = fbdev->getvideoinfo(fbdev, &vinfo); if (ret < 0) { - trv_abort("getvideoinfo() failed\n"); + trv_abort("ERROR: getvideoinfo() failed\n"); } ginfo->xres = vinfo.xres; @@ -137,7 +137,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo) ret = fbdev->getplaneinfo(fbdev, 0, &pinfo); if (ret < 0) { - trv_abort("getplaneinfo() failed\n"); + trv_abort("ERROR: getplaneinfo() failed\n"); } ginfo->stride = pinfo.stride; @@ -145,7 +145,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo) if (vinfo.fmt != TRV_COLOR_FMT || pinfo.bpp != TRV_BPP) { - trv_abort("Bad color format(%d)/bpp(%b)\n", vinfo.fmt, pinfo.bpp); + trv_abort("ERROR: Bad color format(%d)/bpp(%d)\n", vinfo.fmt, pinfo.bpp); } } #endif diff --git a/apps/graphics/traveler/src/trv_input.c b/apps/graphics/traveler/src/trv_input.c index 44644e150..f2e9d2bfb 100644 --- a/apps/graphics/traveler/src/trv_input.c +++ b/apps/graphics/traveler/src/trv_input.c @@ -118,7 +118,7 @@ static struct trv_input_info_s g_trv_input_info; #ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK static void trv_joystick_calibrate(void) { -#warning Missing logic" +#warning Missing logic } #endif diff --git a/apps/graphics/traveler/src/trv_main.c b/apps/graphics/traveler/src/trv_main.c index 029fd4065..078a5aef9 100644 --- a/apps/graphics/traveler/src/trv_main.c +++ b/apps/graphics/traveler/src/trv_main.c @@ -59,25 +59,17 @@ #if CONFIG_GRAPHICS_TRAVELER_PERFMON # include # include -# include #endif /**************************************************************************** - * Private Function Prototypes + * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ -static void trv_exit(int exitCode); -static void trv_usage(char *execname); -#if CONFIG_GRAPHICS_TRAVELER_PERFMON -static double trv_current_time(void); +#ifndef CONFIG_GRAPHICS_TRAVELER_DEFPATH +# define CONFIG_GRAPHICS_TRAVELER_DEFPATH "/mnt/world" #endif -/**************************************************************************** - * Public Data - *************************************************************************/ - -bool g_trv_terminate; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -88,11 +80,18 @@ static void trv_usage(char *execname); static double trv_current_time(void); #endif +/**************************************************************************** + * Public Data + *************************************************************************/ + +bool g_trv_terminate; + /**************************************************************************** * Private Data *************************************************************************/ static const char g_default_worldfile[] = "transfrm.wld"; +static const char g_default_worldpath[] = CONFIG_GRAPHICS_TRAVELER_DEFPATH; static FAR struct trv_graphics_info_s g_trv_ginfo; /**************************************************************************** @@ -166,7 +165,8 @@ int main(int argc, FAR char *argv[]) int traveler_main(int argc, char *argv[]) #endif { - FAR const char *world_filename; + FAR const char *wldpath; + FAR const char *wldfile; #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON int32_t frame_count = 0; double elapsed_time = 0.0; @@ -175,9 +175,13 @@ int traveler_main(int argc, char *argv[]) int ret; int i; + /* Defaults */ + + wldpath = g_default_worldpath; + wldfile = g_default_worldfile; + /* Check for command line arguments */ - world_filename = g_default_worldfile; for (i = 1; i < argc; i++) { FAR char *ptr = argv[i]; @@ -187,13 +191,7 @@ int traveler_main(int argc, char *argv[]) switch (*ptr) { case 'p' : - ptr++; - printf("World data path = %s\n", ptr); - if (chdir(ptr)) - { - fprintf(stderr, "Bad path name\n"); - trv_usage(argv[0]); - } + wldpath = ptr++; break; default: @@ -204,11 +202,12 @@ int traveler_main(int argc, char *argv[]) } else { - world_filename = ptr; + wldfile = ptr; } } - trv_debug("World data file = %s\n", world_filename); + trv_debug("World data file: %s\n", wldfile); + trv_debug("World data path: %s\n", wldpath); /* Initialize the graphics interface */ @@ -216,11 +215,11 @@ int traveler_main(int argc, char *argv[]) /* Load the word data structures */ - ret = trv_world_create(world_filename); + ret = trv_world_create(wldpath, wldfile); if (ret < 0) { trv_abort("ERROR: Failed to load world file %s: %d\n", - world_filename, ret); + wldfile, ret); } /* Release color mapping tables */ diff --git a/apps/graphics/traveler/src/trv_world.c b/apps/graphics/traveler/src/trv_world.c index b21379be3..f48e23f2a 100644 --- a/apps/graphics/traveler/src/trv_world.c +++ b/apps/graphics/traveler/src/trv_world.c @@ -39,12 +39,15 @@ ****************************************************************************/ #include "trv_types.h" +#include "trv_main.h" +#include "trv_fsutils.h" #include "trv_paltable.h" #include "trv_world.h" #include "trv_plane.h" #include "trv_bitmaps.h" #include +#include #include #include @@ -101,9 +104,10 @@ static int trv_ini_short(INIHANDLE inihandle, FAR int16_t *value, static int trv_ini_long(INIHANDLE inihandle, FAR long *value, FAR const char *section, FAR const char *name); #endif -static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename, - FAR const char *section, FAR const char *name); -static int trv_manage_wldfile(INIHANDLE inihandle); +static int trv_ini_filename(INIHANDLE inihandle, FAR const char *wldpath, + FAR const char *section, FAR const char *name, + FAR char **filename); +static int trv_manage_wldfile(INIHANDLE inihandle, FAR const char *wldfile); /**************************************************************************** * Public Data @@ -239,8 +243,9 @@ static uint8_t trv_ini_long(INIHANDLE inihandle, FAR long *value, * ***************************************************************************/ -static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename, - FAR const char *section, FAR const char *name) +static int trv_ini_filename(INIHANDLE inihandle, FAR const char *path, + FAR const char *section, FAR const char *name, + FAR char **filename) { /* Read the string from the .INI file. We supply the default value of * NULL. If this value is returned, we assume that that is evidence that @@ -264,7 +269,8 @@ static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename, } else { - *filename = value; + *filename = trv_fullpath(path, value); + inifile_free_string(value); return OK; } } @@ -277,7 +283,7 @@ static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename, * ***************************************************************************/ -static int trv_manage_wldfile(INIHANDLE inihandle) +static int trv_manage_wldfile(INIHANDLE inihandle, FAR const char *wldpath) { FAR char *filename; int ret; @@ -348,8 +354,8 @@ static int trv_manage_wldfile(INIHANDLE inihandle) /* Get the name of the file containing the world map */ - ret = trv_ini_filename(inihandle, &filename, - g_world_section_name, g_world_map_name); + ret = trv_ini_filename(inihandle, wldpath, g_world_section_name, + g_world_map_name, &filename); if (ret < 0) { return ret; @@ -369,14 +375,14 @@ static int trv_manage_wldfile(INIHANDLE inihandle) return ret; } - inifile_free_string(filename); + free(filename); /* Get the name of the file containing the palette table which is used * to adjust the lighting with distance. */ - ret = trv_ini_filename(inihandle, &filename, - g_world_section_name, g_world_palette_name); + ret = trv_ini_filename(inihandle,wldpath, g_world_section_name, + g_world_palette_name, &filename); if (ret < 0) { return ret; @@ -390,12 +396,12 @@ static int trv_manage_wldfile(INIHANDLE inihandle) return ret; } - inifile_free_string(filename); + free(filename); /* Get the name of the file containing the texture data */ - ret = trv_ini_filename(inihandle, &filename, - g_world_section_name, g_world_images_name); + ret = trv_ini_filename(inihandle, wldpath, g_world_section_name, + g_world_images_name, &filename); if (ret < 0) { return ret; @@ -410,7 +416,7 @@ static int trv_manage_wldfile(INIHANDLE inihandle) } ret = trv_load_bitmapfile(filename); - inifile_free_string(filename); + free(filename); return ret; } @@ -427,8 +433,9 @@ static int trv_manage_wldfile(INIHANDLE inihandle) * ***************************************************************************/ -int trv_world_create(FAR const char *wldfile) +int trv_world_create(FAR const char *wldpath, FAR const char *wldfile) { + FAR char *fullpath; INIHANDLE inihandle; int ret; @@ -436,16 +443,19 @@ int trv_world_create(FAR const char *wldfile) * need to construct the world */ - inihandle = inifile_initialize(wldfile); + fullpath = trv_fullpath(wldpath, wldfile); + inihandle = inifile_initialize(fullpath); + free(fullpath); + if (!inihandle) { - fprintf(stderr, "ERROR: Could not open INI file=\"%s\"\n", wldfile); + fprintf(stderr, "ERROR: Could not open INI file=\"%s\"\n", fullpath); return -ENOENT; } /* Load the world file data */ - ret = trv_manage_wldfile(inihandle); + ret = trv_manage_wldfile(inihandle, wldfile); /* Close the INI file and return */ -- cgit v1.2.3