diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-12-08 09:28:53 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-12-08 09:28:53 -0600 |
commit | 0507d9d25493d7d473b21e617ea0d522a11178f0 (patch) | |
tree | fc8fc75823a85b6118df55c141ccecb3ad0ca571 /apps/graphics/traveler/src/trv_world.c | |
parent | a9bd9b40b95080059faff0818a9370f3b650aa3c (diff) | |
download | nuttx-0507d9d25493d7d473b21e617ea0d522a11178f0.tar.gz nuttx-0507d9d25493d7d473b21e617ea0d522a11178f0.tar.bz2 nuttx-0507d9d25493d7d473b21e617ea0d522a11178f0.zip |
Traveler: Change the way that the world path is managed.
Diffstat (limited to 'apps/graphics/traveler/src/trv_world.c')
-rw-r--r-- | apps/graphics/traveler/src/trv_world.c | 50 |
1 files changed, 30 insertions, 20 deletions
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 <stdio.h> +#include <stdlib.h> #include <errno.h> #include <apps/inifile.h> @@ -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 */ |