unify pointers to value for configfile, and add TYPE_BOOL type, used by

pictureflow

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19786 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andrew Mahone 2009-01-17 22:53:12 +00:00
parent 2fecb713ea
commit 0b41f0599f
16 changed files with 120 additions and 91 deletions

View file

@ -813,7 +813,7 @@ int highscore;
#define MAX_POINTS 200000 /* i dont think it needs to be more */
static struct configdata config[] =
{
{TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
{TYPE_INT, 0, MAX_POINTS, { .int_p = &highscore }, "highscore", NULL}
};
void int_game(int new_game)

View file

@ -181,7 +181,7 @@ static int score;
#define MAX_POINTS 50000
static struct configdata config[] =
{
{TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
{TYPE_INT, 0, MAX_POINTS, { .int_p = &highscore }, "highscore", NULL}
};
struct CBlock

View file

@ -63,8 +63,8 @@ static int nb_sides_values[] = { 3, 4, 6, 8, 10, 12, 20, 100 };
static char *sides_conf[] = {"3", "4", "6", "8", "10", "12", "20", "100" };
static struct configdata config[] =
{
{TYPE_INT, 0, MAX_DICES, &dice.nb_dices, "dice count", NULL, NULL},
{TYPE_ENUM, 0, 8, &sides_index, "side count", sides_conf, NULL}
{TYPE_INT, 0, MAX_DICES, { .int_p = &dice.nb_dices}, "dice count", NULL},
{TYPE_ENUM, 0, 8, { .int_p = &sides_index }, "side count", sides_conf}
};
void dice_init(struct dices* dice);

View file

@ -122,13 +122,13 @@ static struct jpeg_settings old_settings;
static struct configdata jpeg_config[] =
{
#ifdef HAVE_LCD_COLOR
{ TYPE_ENUM, 0, COLOUR_NUM_MODES, &jpeg_settings.colour_mode,
"Colour Mode", (char *[]){ "Colour", "Grayscale" }, NULL },
{ TYPE_ENUM, 0, DITHER_NUM_MODES, &jpeg_settings.dither_mode,
"Dither Mode", (char *[]){ "None", "Ordered", "Diffusion" }, NULL },
{ TYPE_ENUM, 0, COLOUR_NUM_MODES, { .int_p = &jpeg_settings.colour_mode },
"Colour Mode", (char *[]){ "Colour", "Grayscale" } },
{ TYPE_ENUM, 0, DITHER_NUM_MODES, { .int_p = &jpeg_settings.dither_mode },
"Dither Mode", (char *[]){ "None", "Ordered", "Diffusion" } },
#endif
{ TYPE_INT, SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, &jpeg_settings.ss_timeout,
"Slideshow Time", NULL, NULL},
{ TYPE_INT, SS_MIN_TIMEOUT, SS_MAX_TIMEOUT,
{ .int_p = &jpeg_settings.ss_timeout }, "Slideshow Time", NULL },
};
#if LCD_DEPTH > 1

View file

@ -59,13 +59,19 @@ int configfile_save(const char *filename, struct configdata *cfg,
/* pre-allocate 10 bytes for INT */
rb->fdprintf(fd, "%s: %10d\n",
cfg[i].name,
*cfg[i].val);
*cfg[i].int_p);
break;
case TYPE_BOOL:
rb->fdprintf(fd, "%s: 10%d\n",
cfg[i].name,
(int)*cfg[i].bool_p);
break;
case TYPE_ENUM:
rb->fdprintf(fd, "%s: %s\n",
cfg[i].name,
cfg[i].values[*cfg[i].val]);
cfg[i].values[*cfg[i].int_p]);
break;
case TYPE_STRING:
@ -116,13 +122,18 @@ int configfile_load(const char *filename, struct configdata *cfg,
tmp = rb->atoi(val);
/* Only set it if it's within range */
if(tmp >= cfg[i].min && tmp <= cfg[i].max)
*cfg[i].val = tmp;
*cfg[i].int_p = tmp;
break;
case TYPE_BOOL:
tmp = rb->atoi(val);
*cfg[i].bool_p = (bool)tmp;
break;
case TYPE_ENUM:
for(j = 0;j < cfg[i].max;j++) {
if(!rb->strcmp(cfg[i].values[j], val)) {
*cfg[i].val = j;
*cfg[i].int_p = j;
}
}
break;

View file

@ -24,6 +24,7 @@
#define TYPE_INT 1
#define TYPE_ENUM 2
#define TYPE_STRING 3
#define TYPE_BOOL 4
struct configdata
{
@ -31,12 +32,14 @@ struct configdata
int min; /* Min value for integers, should be 0 for enums */
int max; /* Max value for enums and integers,
buffer size for strings */
int *val; /* Pointer to integer/enum value,
NULL if the item is a string */
union
{
int *int_p;
bool *bool_p;
char *string;
}; /* Pointer to value, a union of the possible types */
char *name; /* Pointer to the name of the item */
char **values; /* List of strings for enums, NULL if not enum */
char *string; /* Pointer to a string buffer if the item is a string,
NULL otherwise */
};
/* configfile_save - Given configdata entries this function will

View file

@ -807,8 +807,8 @@ static void game_loop(struct resume_data *r)
static void resume_load_data (struct resume_data *r, struct resume_data *old)
{
struct configdata config[] = {
{TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level),
MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL}
{TYPE_INT,0,MAZEZAM_NUM_LEVELS-1, { .int_p = &(r->level) },
MAZEZAM_CONFIG_LEVELS_NAME,NULL}
};
if (configfile_load(MAZEZAM_CONFIG_FILENAME,config,
@ -827,8 +827,8 @@ static void resume_load_data (struct resume_data *r, struct resume_data *old)
static void resume_save_data (struct resume_data *r, struct resume_data *old)
{
struct configdata config[] = {
{TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level),
MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL}
{TYPE_INT,0,MAZEZAM_NUM_LEVELS-1, {.int_p = &(r->level) },
MAZEZAM_CONFIG_LEVELS_NAME,NULL}
};
/* To reduce disk usage, only write the file if the resume data has

View file

@ -178,25 +178,27 @@ struct mpeg_settings settings;
static struct configdata config[] =
{
{TYPE_INT, 0, 2, &settings.showfps, "Show FPS", NULL, NULL},
{TYPE_INT, 0, 2, &settings.limitfps, "Limit FPS", NULL, NULL},
{TYPE_INT, 0, 2, &settings.skipframes, "Skip frames", NULL, NULL},
{TYPE_INT, 0, INT_MAX, &settings.resume_count, "Resume count",
NULL, NULL},
{TYPE_INT, 0, MPEG_RESUME_NUM_OPTIONS, &settings.resume_options,
"Resume options", NULL, NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.showfps }, "Show FPS", NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.limitfps }, "Limit FPS", NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.skipframes }, "Skip frames", NULL},
{TYPE_INT, 0, INT_MAX, { .int_p = &settings.resume_count }, "Resume count",
NULL},
{TYPE_INT, 0, MPEG_RESUME_NUM_OPTIONS,
{ .int_p = &settings.resume_options }, "Resume options", NULL},
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200)
{TYPE_INT, 0, INT_MAX, &settings.displayoptions, "Display options",
NULL, NULL},
{TYPE_INT, 0, INT_MAX, { .int_p = &settings.displayoptions },
"Display options", NULL},
#endif
{TYPE_INT, 0, 2, &settings.tone_controls, "Tone controls", NULL, NULL},
{TYPE_INT, 0, 2, &settings.channel_modes, "Channel modes", NULL, NULL},
{TYPE_INT, 0, 2, &settings.crossfeed, "Crossfeed", NULL, NULL},
{TYPE_INT, 0, 2, &settings.equalizer, "Equalizer", NULL, NULL},
{TYPE_INT, 0, 2, &settings.dithering, "Dithering", NULL, NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.tone_controls }, "Tone controls",
NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.channel_modes }, "Channel modes",
NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.crossfeed }, "Crossfeed", NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.equalizer }, "Equalizer", NULL},
{TYPE_INT, 0, 2, { .int_p = &settings.dithering }, "Dithering", NULL},
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
{TYPE_INT, -1, INT_MAX, &settings.backlight_brightness,
"Backlight brightness", NULL, NULL},
{TYPE_INT, -1, INT_MAX, { .int_p = &settings.backlight_brightness },
"Backlight brightness", NULL},
#endif
};

View file

@ -312,10 +312,12 @@ static char *advance_str[2] = { "scroll", "wrap" };
static char *orientation_str[2] = { "horizontal", "vertical" };
struct configdata disk_config[] = {
{ TYPE_INT, 1, 99, &osc_disk.delay, "delay", NULL, NULL },
{ TYPE_ENUM, 0, MAX_DRAW, &osc_disk.draw, "draw", draw_str, NULL },
{ TYPE_ENUM, 0, MAX_ADV, &osc_disk.advance, "advance", advance_str, NULL },
{ TYPE_ENUM, 0, MAX_OSC, &osc_disk.orientation, "orientation", orientation_str, NULL }
{ TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
{ TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
{ TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
advance_str },
{ TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
orientation_str }
};

View file

@ -57,11 +57,15 @@ static char* showfps_options[] = {"No", "Yes"};
static struct configdata config[] =
{
{TYPE_ENUM, 0, 2, &settings.difficulty, "Difficulty", difficulty_options, NULL},
{TYPE_ENUM, 0, 4, &settings.numlives, "Pacmen Per Game", numlives_options, NULL},
{TYPE_ENUM, 0, 4, &settings.bonus, "Bonus", bonus_options, NULL},
{TYPE_ENUM, 0, 2, &settings.ghostnames, "Ghost Names", ghostnames_options , NULL},
{TYPE_ENUM, 0, 2, &settings.showfps, "Show FPS", showfps_options, NULL},
{TYPE_ENUM, 0, 2, { .int_p = &settings.difficulty }, "Difficulty",
difficulty_options},
{TYPE_ENUM, 0, 4, { .int_p = &settings.numlives }, "Pacmen Per Game",
numlives_options},
{TYPE_ENUM, 0, 4, { .int_p = &settings.bonus }, "Bonus", bonus_options},
{TYPE_ENUM, 0, 2, { .int_p = &settings.ghostnames }, "Ghost Names",
ghostnames_options},
{TYPE_ENUM, 0, 2, { .int_p = &settings.showfps }, "Show FPS",
showfps_options},
};
static bool loadFile( const char * name, unsigned char * buf, int len )

View file

@ -203,22 +203,25 @@ static int slide_spacing = (LCD_WIDTH - DISPLAY_WIDTH) / 8;
static int center_margin = (LCD_WIDTH - DISPLAY_WIDTH) / 16;
static int num_slides = 4;
static int zoom = 100;
static int show_fps = false;
static int resize = true;
static bool show_fps = false;
static bool resize = true;
static int cache_version = 0;
static int show_album_name = album_name_top;
static struct configdata config[] =
{
{ TYPE_INT, 0, MAX_SPACING, &slide_spacing, "slide spacing", NULL, NULL },
{ TYPE_INT, 0, MAX_MARGIN, &center_margin, "center margin", NULL, NULL },
{ TYPE_INT, 0, MAX_SLIDES_COUNT, &num_slides, "slides count", NULL, NULL },
{ TYPE_INT, 0, 300, &zoom, "zoom", NULL, NULL },
{ TYPE_INT, 0, 1, &show_fps, "show fps", NULL, NULL },
{ TYPE_INT, 0, 1, &resize, "resize", NULL, NULL },
{ TYPE_INT, 0, 100, &cache_version, "cache version", NULL, NULL },
{ TYPE_ENUM, 0, 2, &show_album_name, "show album name",
show_album_name_conf, NULL }
{ TYPE_INT, 0, MAX_SPACING, { .int_p = &slide_spacing }, "slide spacing",
NULL },
{ TYPE_INT, 0, MAX_MARGIN, { .int_p = &center_margin }, "center margin",
NULL },
{ TYPE_INT, 0, MAX_SLIDES_COUNT, { .int_p = &num_slides }, "slides count",
NULL },
{ TYPE_INT, 0, 300, { .int_p = &zoom }, "zoom", NULL },
{ TYPE_BOOL, 0, 1, { .bool_p = &show_fps }, "show fps", NULL },
{ TYPE_BOOL, 0, 1, { .bool_p = &resize }, "resize", NULL },
{ TYPE_INT, 0, 100, { .int_p = &cache_version }, "cache version", NULL },
{ TYPE_ENUM, 0, 2, { .int_p = &show_album_name }, "show album name",
show_album_name_conf }
};
#define CONFIG_NUM_ITEMS (sizeof(config) / sizeof(struct configdata))
@ -1555,7 +1558,6 @@ int settings_menu(void)
{
int selection = 0;
bool old_val;
bool new_val;
MENUITEM_STRINGLIST(settings_menu, "PictureFlow Settings", NULL, "Show FPS",
"Spacing", "Center margin", "Number of slides", "Zoom",
@ -1565,9 +1567,7 @@ int settings_menu(void)
selection=rb->do_menu(&settings_menu,&selection, NULL, false);
switch(selection) {
case 0:
new_val = show_fps;
rb->set_bool("Show FPS", &new_val);
show_fps = new_val;
rb->set_bool("Show FPS", &show_fps);
reset_track_list();
break;
@ -1607,10 +1607,9 @@ int settings_menu(void)
reset_slides();
break;
case 6:
old_val = new_val = resize;
rb->set_bool("Resize Covers", &new_val);
resize = new_val;
if (old_val == new_val) /* changed? */
old_val = resize;
rb->set_bool("Resize Covers", &resize);
if (old_val == resize) /* changed? */
break;
/* fallthrough if changed, since cache needs to be rebuilt */
case 7:

View file

@ -749,7 +749,7 @@ struct sol_config sol_disk = {0};
struct sol_config sol;
static struct configdata config[] = {
{ TYPE_INT, 0, 1, &sol_disk.draw_type, "draw_type", NULL, NULL },
{ TYPE_INT, 0, 1, { .int_p = &sol_disk.draw_type }, "draw_type", NULL }
};
char draw_option_string[32];

View file

@ -245,10 +245,12 @@ static char *mark_str[2] = { "hide", "show" };
struct configdata disk_config[] = {
#ifdef HAVE_LCD_COLOR
{ TYPE_ENUM, 0, 2, &sudcfg_disk.number_display, "numbers", number_str, NULL },
{ TYPE_ENUM, 0, 2, { .int_p = &sudcfg_disk.number_display }, "numbers",
number_str },
#endif
#ifdef SUDOKU_BUTTON_POSSIBLE
{ TYPE_ENUM, 0, 2, &sudcfg_disk.show_markings, "markings", mark_str, NULL },
{ TYPE_ENUM, 0, 2, { .int_p = &sudcfg_disk.show_markings }, "markings",
mark_str },
#endif
};
#endif

View file

@ -3191,9 +3191,12 @@ static char *source_str[WAV_NUM_SRC] = { "line in", "mic",
HAVE_SPDIF_REC_("spdif",) };
struct configdata disk_config[] = {
{ TYPE_ENUM, 0, 9, &reccfg_disk.samplerate, "sample rate", samplerate_str, NULL },
{ TYPE_ENUM, 0, 2, &reccfg_disk.channels, "channels", channel_str, NULL },
{ TYPE_ENUM, 0, WAV_NUM_SRC, &reccfg_disk.source, "source", source_str, NULL },
{ TYPE_ENUM, 0, 9, { .int_p = &reccfg_disk.samplerate }, "sample rate",
samplerate_str },
{ TYPE_ENUM, 0, 2, { .int_p = &reccfg_disk.channels }, "channels",
channel_str },
{ TYPE_ENUM, 0, WAV_NUM_SRC, { .int_p = &reccfg_disk.source }, "source",
source_str },
};
static char recfilename[MAX_PATH];

View file

@ -468,15 +468,14 @@ static int players = 1;
static struct configdata config[] =
{
{TYPE_INT, 0, 1024, &highscore, "highscore", NULL, NULL},
{TYPE_INT, 0, 15, &arghs_per_food, "arghs per food", NULL, NULL},
{TYPE_INT, 0, 15, &argh_size, "argh size", NULL, NULL},
{TYPE_INT, 0, 15, &food_size, "food size", NULL, NULL},
{TYPE_INT, 0, 3, &players, "players", NULL, NULL},
{TYPE_INT, 0, 3, &worm_count, "worms", NULL, NULL},
{TYPE_INT, 0, 20, &speed, "speed", NULL, NULL},
{TYPE_INT, 0, 15, &worm_food, "Worm Growth Per Food", NULL, NULL}//,
//{TYPE_INT, 0, 3, &use_remote, "use remote", NULL, NULL}
{TYPE_INT, 0, 1024, { .int_p = &highscore }, "highscore", NULL},
{TYPE_INT, 0, 15, { .int_p = &arghs_per_food }, "arghs per food", NULL},
{TYPE_INT, 0, 15, { .int_p = &argh_size }, "argh size", NULL},
{TYPE_INT, 0, 15, { .int_p = &food_size }, "food size", NULL},
{TYPE_INT, 0, 3, { .int_p = &players }, "players", NULL},
{TYPE_INT, 0, 3, { .int_p = &worm_count }, "worms", NULL},
{TYPE_INT, 0, 20, { .int_p = &speed }, "speed", NULL},
{TYPE_INT, 0, 15, { .int_p = &worm_food }, "Worm Growth Per Food", NULL}
};
#ifdef DEBUG_WORMLET

View file

@ -75,13 +75,17 @@ static char* showfps_options[] = {"No", "Yes"};*/
static struct configdata config[] =
{
{TYPE_ENUM, 0, 2, &settings.invert_colors, "Invert Colors", noyes_options, NULL},
{TYPE_ENUM, 0, 2, &settings.kempston, "Map keys to kempston", noyes_options, NULL},
{TYPE_ENUM, 0, 2, &settings.showfps, "Show Speed", noyes_options, NULL},
{TYPE_ENUM, 0, 2, &settings.sound, "Sound", noyes_options, NULL},
{TYPE_INT, 0, 9, &settings.frameskip, "Frameskip", NULL, NULL},
{TYPE_INT, 1, 10, &settings.volume, "Volume", NULL, NULL},
{TYPE_STRING, 0, 5, NULL,"Key Mapping", NULL, (char*)&settings.keymap},
{TYPE_ENUM, 0, 2, { .int_p = &settings.invert_colors }, "Invert Colors",
noyes_options},
{TYPE_ENUM, 0, 2, { .int_p = &settings.kempston }, "Map keys to kempston",
noyes_options},
{TYPE_ENUM, 0, 2, { .int_p = &settings.showfps }, "Show Speed",
noyes_options},
{TYPE_ENUM, 0, 2, { .int_p = &settings.sound }, "Sound", noyes_options},
{TYPE_INT, 0, 9, { .int_p = &settings.frameskip }, "Frameskip", NULL},
{TYPE_INT, 1, 10, { .int_p = &settings.volume }, "Volume", NULL},
{TYPE_STRING, 0, 5, { .string = (char*)&settings.keymap }, "Key Mapping",
NULL},
};
int spcf_read_conf_file(const char *filename)
{