1
0
Fork 0
forked from len0rd/rockbox

Make the formatter functions used by the settings return a pointer to avoid usless copying of lang strings, this brought with it a long chain of const correctness and a few random cleanups

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22440 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nils Wallménius 2009-08-20 16:47:44 +00:00
parent 0a17284448
commit 3200d04d75
43 changed files with 191 additions and 170 deletions

View file

@ -86,7 +86,7 @@ static bool parse_bookmark(const char *bookmark,
bool *shuffle, bool *shuffle,
char* file_name); char* file_name);
static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line); static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line);
static char* get_bookmark_info(int list_index, static const char* get_bookmark_info(int list_index,
void* data, void* data,
char *buffer, char *buffer,
size_t buffer_len); size_t buffer_len);
@ -515,7 +515,7 @@ static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line)
return bookmarks->start + bookmarks->count; return bookmarks->start + bookmarks->count;
} }
static char* get_bookmark_info(int list_index, static const char* get_bookmark_info(int list_index,
void* data, void* data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)

View file

@ -234,7 +234,7 @@ int cue_find_current_track(struct cuesheet *cue, unsigned long curpos)
} }
/* callback that gives list item titles for the cuesheet browser */ /* callback that gives list item titles for the cuesheet browser */
static char *list_get_name_cb(int selected_item, static const char* list_get_name_cb(int selected_item,
void *data, void *data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)

View file

@ -141,7 +141,7 @@ static char thread_status_char(unsigned status)
return thread_status_chars[status]; return thread_status_chars[status];
} }
static char* threads_getname(int selected_item, void *data, static const char* threads_getname(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)data; (void)data;
@ -183,6 +183,7 @@ static char* threads_getname(int selected_item, void *data,
return buffer; return buffer;
} }
static int dbg_threads_action_callback(int action, struct gui_synclist *lists) static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
{ {
(void)lists; (void)lists;
@ -783,7 +784,7 @@ static bool dbg_hw_info(void)
#endif /* !SIMULATOR */ #endif /* !SIMULATOR */
#ifndef SIMULATOR #ifndef SIMULATOR
static char* dbg_partitions_getname(int selected_item, void *data, static const char* dbg_partitions_getname(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)data; (void)data;
@ -2796,12 +2797,14 @@ static int menu_action_callback(int btn, struct gui_synclist *lists)
} }
return btn; return btn;
} }
static char* dbg_menu_getname(int item, void * data,
static const char* dbg_menu_getname(int item, void * data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)data; (void)buffer; (void)buffer_len; (void)data; (void)buffer; (void)buffer_len;
return menuitems[item].desc; return menuitems[item].desc;
} }
bool debug_menu(void) bool debug_menu(void)
{ {
struct simplelist_info info; struct simplelist_info info;

View file

@ -435,13 +435,13 @@ static enum themable_icons openwith_get_icon(int selected_item, void * data)
return filetypes[items[selected_item]].icon; return filetypes[items[selected_item]].icon;
} }
static char * openwith_get_name(int selected_item, void * data, static const char* openwith_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
(void)buffer; (void)buffer_len; (void)buffer; (void)buffer_len;
struct cb_data *info = (struct cb_data *)data; struct cb_data *info = (struct cb_data *)data;
int *items = info->items; int *items = info->items;
char *s = strrchr(filetypes[items[selected_item]].plugin, '/'); const char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
if (s) if (s)
return s+1; return s+1;
else return filetypes[items[selected_item]].plugin; else return filetypes[items[selected_item]].plugin;

View file

@ -173,7 +173,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
for (i=start; i<end && i<list->nb_items; i++) for (i=start; i<end && i<list->nb_items; i++)
{ {
/* do the text */ /* do the text */
unsigned char *s; unsigned const char *s;
char entry_buffer[MAX_PATH]; char entry_buffer[MAX_PATH];
unsigned char *entry_name; unsigned char *entry_name;
int text_pos = 0; int text_pos = 0;

View file

@ -69,7 +69,7 @@ void list_draw(struct screen *display, struct gui_synclist *gui_list)
for (i = start; i < end; i++) for (i = start; i < end; i++)
{ {
unsigned char *s; unsigned const char *s;
char entry_buffer[MAX_PATH]; char entry_buffer[MAX_PATH];
unsigned char *entry_name; unsigned char *entry_name;
int current_item = gui_list->start_item[display->screen_type] + i; int current_item = gui_list->start_item[display->screen_type] + i;

View file

@ -827,7 +827,7 @@ void simplelist_addline(int line_number, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
static char* simplelist_static_getname(int item, static const char* simplelist_static_getname(int item,
void * data, void * data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)
@ -841,7 +841,7 @@ bool simplelist_show_list(struct simplelist_info *info)
struct gui_synclist lists; struct gui_synclist lists;
int action, old_line_count = simplelist_line_count; int action, old_line_count = simplelist_line_count;
int oldbars = viewportmanager_set_statusbar(VP_SB_ALLSCREENS); int oldbars = viewportmanager_set_statusbar(VP_SB_ALLSCREENS);
char* (*getname)(int item, void * data, char *buffer, size_t buffer_len); const char* (*getname)(int item, void * data, char *buffer, size_t buffer_len);
int wrap = LIST_WRAP_UNLESS_HELD; int wrap = LIST_WRAP_UNLESS_HELD;
if (info->get_name) if (info->get_name)
getname = info->get_name; getname = info->get_name;

View file

@ -64,7 +64,7 @@ typedef enum themable_icons list_get_icon(int selected_item, void * data);
* - buffer_len : length of the buffer * - buffer_len : length of the buffer
* Returns a pointer to a string that contains the text to display * Returns a pointer to a string that contains the text to display
*/ */
typedef char * list_get_name(int selected_item, void * data, typedef const char * list_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len); char * buffer, size_t buffer_len);
/* /*
* Voice callback * Voice callback

View file

@ -69,10 +69,11 @@ static const char *unit_strings[] =
/* these two vars are needed so arbitrary values can be added to the /* these two vars are needed so arbitrary values can be added to the
TABLE_SETTING settings if the F_ALLOW_ARBITRARY_VALS flag is set */ TABLE_SETTING settings if the F_ALLOW_ARBITRARY_VALS flag is set */
static int table_setting_oldval = 0, table_setting_array_position = 0; static int table_setting_oldval = 0, table_setting_array_position = 0;
char *option_get_valuestring(const struct settings_list *setting, const char *option_get_valuestring(const struct settings_list *setting,
char *buffer, int buf_len, char *buffer, int buf_len,
intptr_t temp_var) intptr_t temp_var)
{ {
const char* str = buffer;
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
{ {
bool val = (bool)temp_var; bool val = (bool)temp_var;
@ -93,7 +94,7 @@ char *option_get_valuestring(const struct settings_list *setting,
const struct int_setting *int_info = setting->int_setting; const struct int_setting *int_info = setting->int_setting;
const struct table_setting *tbl_info = setting->table_setting; const struct table_setting *tbl_info = setting->table_setting;
const char *unit; const char *unit;
void (*formatter)(char*, size_t, int, const char*); const char* (*formatter)(char*, size_t, int, const char*);
if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
{ {
formatter = int_info->formatter; formatter = int_info->formatter;
@ -105,7 +106,7 @@ char *option_get_valuestring(const struct settings_list *setting,
unit = unit_strings[tbl_info->unit]; unit = unit_strings[tbl_info->unit];
} }
if (formatter) if (formatter)
formatter(buffer, buf_len, (int)temp_var, unit); str = formatter(buffer, buf_len, (int)temp_var, unit);
else else
snprintf(buffer, buf_len, "%d %s", (int)temp_var, unit?unit:""); snprintf(buffer, buf_len, "%d %s", (int)temp_var, unit?unit:"");
} }
@ -152,7 +153,7 @@ char *option_get_valuestring(const struct settings_list *setting,
strlcpy(buffer, val, buf_len); strlcpy(buffer, val, buf_len);
} }
} }
return buffer; return str;
} }
void option_talk_value(const struct settings_list *setting, int value, bool enqueue) void option_talk_value(const struct settings_list *setting, int value, bool enqueue)
{ {
@ -363,7 +364,8 @@ static int selection_to_val(const struct settings_list *setting, int selection)
} }
return max- (selection * step); return max- (selection * step);
} }
static char * value_setting_get_name_cb(int selected_item,
static const char * value_setting_get_name_cb(int selected_item,
void * data, void * data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)

View file

@ -33,7 +33,7 @@ bool option_screen(const struct settings_list *setting,
void option_select_next_val(const struct settings_list *setting, void option_select_next_val(const struct settings_list *setting,
bool previous, bool apply); bool previous, bool apply);
#endif #endif
char *option_get_valuestring(const struct settings_list *setting, const char *option_get_valuestring(const struct settings_list *setting,
char *buffer, int buf_len, char *buffer, int buf_len,
intptr_t temp_var); intptr_t temp_var);
void option_talk_value(const struct settings_list *setting, int value, bool enqueue); void option_talk_value(const struct settings_list *setting, int value, bool enqueue);

View file

@ -147,7 +147,7 @@ static void quickscreen_fix_viewports(struct gui_quickscreen *qs,
vps[screen][QUICKSCREEN_BOTTOM].y - vp_icons[screen].y; vps[screen][QUICKSCREEN_BOTTOM].y - vp_icons[screen].y;
} }
static void quickscreen_draw_text(char *s, int item, bool title, static void quickscreen_draw_text(const char *s, int item, bool title,
struct screen *display, struct viewport *vp) struct screen *display, struct viewport *vp)
{ {
int nb_lines = viewport_get_nb_lines(vp); int nb_lines = viewport_get_nb_lines(vp);
@ -186,7 +186,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs,
int i; int i;
char buf[MAX_PATH]; char buf[MAX_PATH];
unsigned char *title, *value; unsigned const char *title, *value;
void *setting; void *setting;
int temp; int temp;
display->set_viewport(parent); display->set_viewport(parent);

View file

@ -93,7 +93,7 @@ static int find_menu_selection(int selected)
return i; return i;
return 0; return 0;
} }
static char * get_menu_item_name(int selected_item, static const char* get_menu_item_name(int selected_item,
void * data, void * data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)
@ -109,7 +109,7 @@ static char * get_menu_item_name(int selected_item,
if (menu->flags&MENU_DYNAMIC_DESC) if (menu->flags&MENU_DYNAMIC_DESC)
return menu->menu_get_name_and_icon->list_get_name(selected_item, return menu->menu_get_name_and_icon->list_get_name(selected_item,
menu->menu_get_name_and_icon->list_get_name_data, buffer); menu->menu_get_name_and_icon->list_get_name_data, buffer);
return (char*)menu->strings[selected_item]; return menu->strings[selected_item];
} }
menu = menu->submenus[selected_item]; menu = menu->submenus[selected_item];

View file

@ -51,15 +51,18 @@
* Utility functions * Utility functions
*/ */
void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit) const char* eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit)
{ {
snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit); snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR,
value % EQ_USER_DIVISOR, unit);
return buffer;
} }
void eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit) const char* eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit)
{ {
snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-", snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit); value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
return buffer;
} }
/* /*

View file

@ -43,7 +43,9 @@ bool eq_browse_presets(void);
bool eq_menu_graphical(void); bool eq_menu_graphical(void);
/* utility functions for settings_list.c */ /* utility functions for settings_list.c */
void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit); const char* eq_q_format(char* buffer, size_t buffer_size, int value,
void eq_precut_format(char* buffer, size_t buffer_size, int value, const char* unit); const char* unit);
const char* eq_precut_format(char* buffer, size_t buffer_size, int value,
const char* unit);
#endif #endif

View file

@ -164,7 +164,7 @@ static const unsigned char *byte_units[] =
ID2P(LANG_MEGABYTE) ID2P(LANG_MEGABYTE)
}; };
static char* info_getname(int selected_item, void *data, static const char* info_getname(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
struct info_data *info = (struct info_data*)data; struct info_data *info = (struct info_data*)data;
@ -199,27 +199,27 @@ static char* info_getname(int selected_item, void *data,
#if CONFIG_CHARGING == CHARGING_SIMPLE #if CONFIG_CHARGING == CHARGING_SIMPLE
/* Only know if plugged */ /* Only know if plugged */
if (charger_inserted()) if (charger_inserted())
return (char *)str(LANG_BATTERY_CHARGE); return str(LANG_BATTERY_CHARGE);
else else
#elif CONFIG_CHARGING >= CHARGING_MONITOR #elif CONFIG_CHARGING >= CHARGING_MONITOR
#ifdef ARCHOS_RECORDER #ifdef ARCHOS_RECORDER
/* Report the particular algorithm state */ /* Report the particular algorithm state */
if (charge_state == CHARGING) if (charge_state == CHARGING)
return (char *)str(LANG_BATTERY_CHARGE); return str(LANG_BATTERY_CHARGE);
else if (charge_state == TOPOFF) else if (charge_state == TOPOFF)
return (char *)str(LANG_BATTERY_TOPOFF_CHARGE); return str(LANG_BATTERY_TOPOFF_CHARGE);
else if (charge_state == TRICKLE) else if (charge_state == TRICKLE)
return (char *)str(LANG_BATTERY_TRICKLE_CHARGE); return str(LANG_BATTERY_TRICKLE_CHARGE);
else else
#else /* !ARCHOS_RECORDER */ #else /* !ARCHOS_RECORDER */
/* Go by what power management reports */ /* Go by what power management reports */
if (charging_state()) if (charging_state())
return (char *)str(LANG_BATTERY_CHARGE); return str(LANG_BATTERY_CHARGE);
else else
#endif /* ARCHOS_RECORDER */ #endif /* ARCHOS_RECORDER */
#endif /* CONFIG_CHARGING = */ #endif /* CONFIG_CHARGING = */
if (battery_level() >= 0) if (battery_level() >= 0)
snprintf(buffer, buffer_len, (char *)str(LANG_BATTERY_TIME), snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
battery_level(), battery_time() / 60, battery_time() % 60); battery_level(), battery_time() / 60, battery_time() % 60);
else else
return "(n/a)"; return "(n/a)";
@ -399,19 +399,19 @@ MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
/* sleep Menu */ /* sleep Menu */
static void sleep_timer_formatter(char* buffer, size_t buffer_size, int value, static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
const char* unit) int value, const char* unit)
{ {
int minutes, hours;
(void) unit; (void) unit;
int minutes, hours;
if (value) { if (value) {
hours = value / 60; hours = value / 60;
minutes = value - (hours * 60); minutes = value - (hours * 60);
snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
return buffer;
} else { } else {
strlcpy(buffer, str(LANG_OFF), buffer_size); return str(LANG_OFF);
} }
} }

View file

@ -415,7 +415,7 @@ static enum themable_icons trigger_get_icon(int selected_item, void * data)
return Icon_NOICON; return Icon_NOICON;
} }
static char * trigger_get_name(int selected_item, void * data, static const char * trigger_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
const struct settings_list **settings = const struct settings_list **settings =

View file

@ -184,7 +184,7 @@ exit:
} }
/* Callback for gui_synclist */ /* Callback for gui_synclist */
static char* playlist_callback_name(int selected_item, void* data, static const char* playlist_callback_name(int selected_item, void* data,
char* buffer, size_t buffer_len) char* buffer, size_t buffer_len)
{ {
char** playlists = (char**) data; char** playlists = (char**) data;

View file

@ -559,7 +559,7 @@ static int get_track_num( struct playlist_viewer * local_viewer,
return selected_item; return selected_item;
} }
static char *playlist_callback_name(int selected_item, static const char* playlist_callback_name(int selected_item,
void *data, void *data,
char *buffer, char *buffer,
size_t buffer_len) size_t buffer_len)
@ -778,7 +778,7 @@ exit:
return ret; return ret;
} }
static char *playlist_search_callback_name(int selected_item, void * data, static const char* playlist_search_callback_name(int selected_item, void * data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)buffer_len; /* this should probably be used */ (void)buffer_len; /* this should probably be used */
@ -786,7 +786,7 @@ static char *playlist_search_callback_name(int selected_item, void * data,
static struct playlist_track_info track; static struct playlist_track_info track;
playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track); playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
format_name(buffer, track.filename); format_name(buffer, track.filename);
return(buffer); return buffer;
} }
bool search_playlist(void) bool search_playlist(void)

View file

@ -133,12 +133,12 @@ void* plugin_get_buffer(size_t *buffer_size);
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 170 #define PLUGIN_API_VERSION 171
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 170 #define PLUGIN_MIN_API_VERSION 171
/* plugin return codes */ /* plugin return codes */
enum plugin_status { enum plugin_status {
@ -672,7 +672,7 @@ struct plugin_api {
bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit, bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
const int* variable, void (*function)(int), int step, const int* variable, void (*function)(int), int step,
int min, int max, int min, int max,
void (*formatter)(char*, size_t, int, const char*) ); const char* (*formatter)(char*, size_t, int, const char*) );
bool (*set_bool)(const char* string, const bool* variable ); bool (*set_bool)(const char* string, const bool* variable );
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR

View file

@ -669,7 +669,7 @@ static bool edit_memo(int change, struct shown *shown)
return false; return false;
} }
static char * get_event_text(int selected, void *data, static const char* get_event_text(int selected, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
struct shown *shown = (struct shown *) data; struct shown *shown = (struct shown *) data;

View file

@ -528,11 +528,10 @@ void coords_to_pgn(struct pgn_ply_node* ply){
} }
} }
char * get_game_text(int selected_item, void *data, static const char* get_game_text(int selected_item, void *data,
char *buffer, size_t buffer_len){ char *buffer, size_t buffer_len){
int i; int i;
struct pgn_game_node *temp_node = (struct pgn_game_node *)data; struct pgn_game_node *temp_node = (struct pgn_game_node *)data;
char text_buffer[50];
for (i=0;i<selected_item && temp_node != NULL;i++){ for (i=0;i<selected_item && temp_node != NULL;i++){
temp_node = temp_node->next_node; temp_node = temp_node->next_node;
@ -540,10 +539,9 @@ char * get_game_text(int selected_item, void *data,
if (temp_node == NULL){ if (temp_node == NULL){
return NULL; return NULL;
} }
rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player, rb->snprintf(buffer, buffer_len,"%s vs. %s (%s)", temp_node->white_player,
temp_node->black_player, temp_node->game_date); temp_node->black_player, temp_node->game_date);
rb->strlcpy(buffer, text_buffer, buffer_len);
return buffer; return buffer;
} }

View file

@ -380,7 +380,7 @@ enum themable_icons get_icon(int item, void * data)
return Icon_NOICON; return Icon_NOICON;
} }
char * get_name(int selected_item, void * data, static const char* get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
(void)data; (void)data;

View file

@ -550,14 +550,15 @@ static bool Doptions()
return (1); return (1);
} }
char* choice_get_name(int selected_item, void * data, static const char* choice_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
char **names = (char **) data; const char **names = (const char **) data;
(void) buffer; (void) buffer;
(void) buffer_len; (void) buffer_len;
return names[selected_item]; return names[selected_item];
} }
int list_action_callback(int action, struct gui_synclist *lists) int list_action_callback(int action, struct gui_synclist *lists)
{ {
(void) lists; (void) lists;
@ -565,6 +566,7 @@ int list_action_callback(int action, struct gui_synclist *lists)
return ACTION_STD_CANCEL; return ACTION_STD_CANCEL;
return action; return action;
} }
bool menuchoice(char **names, int count, int *selected) bool menuchoice(char **names, int count, int *selected)
{ {
struct simplelist_info info; struct simplelist_info info;

View file

@ -114,37 +114,39 @@ set_defaults (void)
autosave_time = 7; autosave_time = 7;
} }
static void static const char*
komi_formatter (char *dest, size_t size, int menu_item, const char *unknown) komi_formatter (char *dest, size_t size, int menu_item, const char *unknown)
{ {
(void) unknown; (void) unknown;
snprint_fixed (dest, size, menu_item); snprint_fixed (dest, size, menu_item);
return dest;
} }
static void static const char*
ruleset_formatter (char *dest, size_t size, int menu_item, const char *unknown) ruleset_formatter (char *dest, size_t size, int menu_item, const char *unknown)
{ {
(void) unknown; (void)dest, (void)size, (void)unknown;
rb->snprintf (dest, size, "%s", ruleset_names[menu_item]); return ruleset_names[menu_item];
} }
static void static const char*
autosave_formatter (char *dest, size_t size, int menu_item, const char * autosave_formatter (char *dest, size_t size, int menu_item, const char *
unknown) unknown)
{ {
(void) unknown; (void) unknown;
if (menu_item == 0) if (menu_item == 0)
{ {
rb->snprintf (dest, size, "Off"); return "Off";
} }
else else
{ {
rb->snprintf (dest, size, "%d minute%s", menu_item, rb->snprintf (dest, size, "%d minute%s", menu_item,
menu_item == 1 ? "" : "s"); menu_item == 1 ? "" : "s");
return dest;
} }
} }
static void static const char*
time_formatter (char *dest, size_t size, int menu_item, const char *unknown) time_formatter (char *dest, size_t size, int menu_item, const char *unknown)
{ {
int time_values[4]; /* days hours minutes seconds */ int time_values[4]; /* days hours minutes seconds */
@ -183,8 +185,7 @@ time_formatter (char *dest, size_t size, int menu_item, const char *unknown)
if (max_set == -1) if (max_set == -1)
{ {
rb->snprintf (dest, size, "0"); return "0";
return;
} }
for (i = min_set; i <= 3; ++i) for (i = min_set; i <= 3; ++i)
@ -236,6 +237,7 @@ time_formatter (char *dest, size_t size, int menu_item, const char *unknown)
dest += temp; dest += temp;
size -= temp; size -= temp;
} }
return dest;
} }
enum plugin_status enum plugin_status

View file

@ -218,7 +218,7 @@ struct prop_t
/* The names of the rulesets, ex. "AGA", "Japanese", etc. */ /* The names of the rulesets, ex. "AGA", "Japanese", etc. */
extern char *ruleset_names[]; extern const char *ruleset_names[];
/* IMPORTANT! keep in sync with ruleset_names!!! */ /* IMPORTANT! keep in sync with ruleset_names!!! */
enum ruleset_t enum ruleset_t

View file

@ -210,7 +210,7 @@ char *prop_names[] = {
/* These seems to be specified by the SGF specification. You can do free /* These seems to be specified by the SGF specification. You can do free
form ones as well, but I haven't implemented that (and don't plan to) */ form ones as well, but I haven't implemented that (and don't plan to) */
char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" }; const char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" };

View file

@ -122,7 +122,7 @@ MENUITEM_STRINGLIST(context_m, "Context menu", context_item_cb,
"Delete entry", "Delete entry",
"Playback Control"); "Playback Control");
static char * kb_list_cb(int selected_item, void *data, static const char* kb_list_cb(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)data; (void)data;

View file

@ -317,7 +317,7 @@ static bool mpeg_set_int(const char *string, const char *unit,
void (*function)(int), int step, void (*function)(int), int step,
int min, int min,
int max, int max,
void (*formatter)(char*, size_t, int, const char*)) const char* (*formatter)(char*, size_t, int, const char*))
{ {
mpeg_menu_sysevent_clear(); mpeg_menu_sysevent_clear();
@ -350,15 +350,16 @@ static void backlight_brightness_function(int value)
mpeg_backlight_update_brightness(value); mpeg_backlight_update_brightness(value);
} }
static void backlight_brightness_formatter(char *buf, size_t length, static const char* backlight_brightness_formatter(char *buf, size_t length,
int value, const char *input) int value, const char *input)
{ {
(void)input;
if (value < 0) if (value < 0)
rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length); return BACKLIGHT_OPTION_DEFAULT;
else else
rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING); rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING);
return buf;
(void)input;
} }
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #endif /* HAVE_BACKLIGHT_BRIGHTNESS */

View file

@ -228,7 +228,8 @@ static bool dir_properties(char* selected_file)
return true; return true;
} }
char * get_props(int selected_item, void* data, char *buffer, size_t buffer_len) static const char * get_props(int selected_item, void* data,
char *buffer, size_t buffer_len)
{ {
(void)data; (void)data;
@ -263,8 +264,7 @@ char * get_props(int selected_item, void* data, char *buffer, size_t buffer_len)
rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
break; break;
default: default:
rb->strlcpy(buffer, "ERROR", buffer_len); return "ERROR";
break;
} }
return buffer; return buffer;
} }

View file

@ -234,7 +234,9 @@ void generate(void)
rb->close(fd); rb->close(fd);
rb->splash(HZ, "Done"); rb->splash(HZ, "Done");
} }
char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len)
static const char* list_get_name_cb(int selected_item, void* data,
char* buf, size_t buf_len)
{ {
(void)data; (void)data;
rb->strlcpy(buf, list->folder[selected_item], buf_len); rb->strlcpy(buf, list->folder[selected_item], buf_len);

View file

@ -270,10 +270,10 @@ static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) {
/* /*
* slot_get_name * slot_get_name
*/ */
static char *slot_get_name(int selected_item, void * data, static const char* slot_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
char (*items)[20] = data; const char (*items)[20] = data;
(void) buffer; (void) buffer;
(void) buffer_len; (void) buffer_len;
return items[selected_item]; return items[selected_item];

View file

@ -600,7 +600,7 @@ char bbuf[MAX_PATH+1]; /* used by file and font browsers */
char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */ char bbuf_s[MAX_PATH+1]; /* used by file and font browsers */
struct tree_context *tree = NULL; struct tree_context *tree = NULL;
static char * browse_get_name_cb( int selected_item, void *data, static const char* browse_get_name_cb(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
int *indexes = (int *) data; int *indexes = (int *) data;
@ -609,7 +609,7 @@ static char * browse_get_name_cb( int selected_item, void *data,
(void) buffer; (void) buffer;
(void) buffer_len; (void) buffer_len;
return (e->name); return e->name;
} }
static bool browse( char *dst, int dst_size, const char *start ) static bool browse( char *dst, int dst_size, const char *start )

View file

@ -40,7 +40,7 @@ static bool usb_connected = false;
enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc); enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc);
/* Will be passed sc_file* as data */ /* Will be passed sc_file* as data */
char* build_sc_list(int selected_item, void *data, static const char* build_sc_list(int selected_item, void *data,
char *buffer, size_t buffer_len); char *buffer, size_t buffer_len);
/* Returns true iff we should leave the main loop */ /* Returns true iff we should leave the main loop */
@ -89,7 +89,7 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc)
} }
char* build_sc_list(int selected_item, void *data, static const char* build_sc_list(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
sc_file_t *file = (sc_file_t*)data; sc_file_t *file = (sc_file_t*)data;

View file

@ -1251,7 +1251,7 @@ int movement_menu(void) {
return RET_VAL_OK; return RET_VAL_OK;
} }
static char * inventory_data(int selected_item, void * data, static const char* inventory_data(int selected_item, void * data,
char * buffer, size_t buffer_len) { char * buffer, size_t buffer_len) {
(void)data; (void)data;
switch(selected_item) { switch(selected_item) {

View file

@ -121,7 +121,7 @@ int _do_action(int action, char* str, int line)
last_char_index = c; last_char_index = c;
return 1; return 1;
} }
char *list_get_name_cb(int selected_item, void* data, static const char* list_get_name_cb(int selected_item, void* data,
char* buf, size_t buf_len) char* buf, size_t buf_len)
{ {
(void)data; (void)data;

View file

@ -1347,7 +1347,7 @@ MAKE_MENU(handle_radio_preset_menu, ID2P(LANG_PRESET),
radio_preset_callback, Icon_NOICON, &radio_edit_preset_item, radio_preset_callback, Icon_NOICON, &radio_edit_preset_item,
&radio_delete_preset_item); &radio_delete_preset_item);
/* present a list of preset stations */ /* present a list of preset stations */
static char * presets_get_name(int selected_item, void *data, static const char* presets_get_name(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
(void)data; (void)data;

View file

@ -848,7 +848,7 @@ enum rec_list_items_spdif {
static int listid_to_enum[ITEM_COUNT]; static int listid_to_enum[ITEM_COUNT];
static char * reclist_get_name(int selected_item, void * data, static const char* reclist_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
char buf2[32]; char buf2[32];

View file

@ -789,12 +789,14 @@ static const int id3_headers[]=
#endif #endif
LANG_ID3_PATH, LANG_ID3_PATH,
}; };
struct id3view_info { struct id3view_info {
struct mp3entry* id3; struct mp3entry* id3;
int count; int count;
int info_id[sizeof(id3_headers)/sizeof(id3_headers[0])]; int info_id[ARRAYLEN(id3_headers)];
}; };
static char * id3_get_info(int selected_item, void* data,
static const char* id3_get_info(int selected_item, void* data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
struct id3view_info *info = (struct id3view_info*)data; struct id3view_info *info = (struct id3view_info*)data;
@ -903,7 +905,7 @@ bool browse_id3(void)
struct id3view_info info; struct id3view_info info;
info.count = 0; info.count = 0;
info.id3 = id3; info.id3 = id3;
for (i=0; i<sizeof(id3_headers)/sizeof(id3_headers[0]); i++) for (i = 0; i < ARRAYLEN(id3_headers); i++)
{ {
char temp[8]; char temp[8];
info.info_id[i] = i; info.info_id[i] = i;
@ -924,7 +926,7 @@ bool browse_id3(void)
} }
} }
static char* runtime_get_data(int selected_item, void* data, static const char* runtime_get_data(int selected_item, void* data,
char* buffer, size_t buffer_len) char* buffer, size_t buffer_len)
{ {
(void)data; (void)data;

View file

@ -1083,7 +1083,7 @@ bool set_int(const unsigned char* string,
int step, int step,
int min, int min,
int max, int max,
void (*formatter)(char*, size_t, int, const char*) ) const char* (*formatter)(char*, size_t, int, const char*) )
{ {
return set_int_ex(string, unit, voice_unit, variable, function, return set_int_ex(string, unit, voice_unit, variable, function,
step, min, max, formatter, NULL); step, min, max, formatter, NULL);
@ -1097,7 +1097,7 @@ bool set_int_ex(const unsigned char* string,
int step, int step,
int min, int min,
int max, int max,
void (*formatter)(char*, size_t, int, const char*), const char* (*formatter)(char*, size_t, int, const char*),
int32_t (*get_talk_id)(int, int)) int32_t (*get_talk_id)(int, int))
{ {
(void)unit; (void)unit;
@ -1117,17 +1117,18 @@ bool set_int_ex(const unsigned char* string,
static const struct opt_items *set_option_options; static const struct opt_items *set_option_options;
static void set_option_formatter(char* buf, size_t size, int item, const char* unit) static const char* set_option_formatter(char* buf, size_t size, int item, const char* unit)
{ {
(void)unit; (void)buf, (void)unit, (void)size;
const unsigned char *text = set_option_options[item].string; return P2STR(set_option_options[item].string);
strlcpy(buf, P2STR(text), size);
} }
static int32_t set_option_get_talk_id(int value, int unit) static int32_t set_option_get_talk_id(int value, int unit)
{ {
(void)unit; (void)unit;
return set_option_options[value].voice_id; return set_option_options[value].voice_id;
} }
bool set_option(const char* string, const void* variable, enum optiontype type, bool set_option(const char* string, const void* variable, enum optiontype type,
const struct opt_items* options, const struct opt_items* options,
int numoptions, void (*function)(int)) int numoptions, void (*function)(int))

View file

@ -271,13 +271,13 @@ bool set_bool(const char* string, const bool* variable);
bool set_int(const unsigned char* string, const char* unit, int voice_unit, bool set_int(const unsigned char* string, const char* unit, int voice_unit,
const int* variable, const int* variable,
void (*function)(int), int step, int min, int max, void (*function)(int), int step, int min, int max,
void (*formatter)(char*, size_t, int, const char*) ); const char* (*formatter)(char*, size_t, int, const char*) );
/* use this one if you need to create a lang from the value (i.e with TALK_ID()) */ /* use this one if you need to create a lang from the value (i.e with TALK_ID()) */
bool set_int_ex(const unsigned char* string, const char* unit, int voice_unit, bool set_int_ex(const unsigned char* string, const char* unit, int voice_unit,
const int* variable, const int* variable,
void (*function)(int), int step, int min, int max, void (*function)(int), int step, int min, int max,
void (*formatter)(char*, size_t, int, const char*), const char* (*formatter)(char*, size_t, int, const char*),
int32_t (*get_talk_id)(int, int)); int32_t (*get_talk_id)(int, int));
void set_file(const char* filename, char* setting, int maxlen); void set_file(const char* filename, char* setting, int maxlen);

View file

@ -269,13 +269,14 @@ static const char graphic_numeric[] = "graphic,numeric";
#endif /* HAVE_RECORDING */ #endif /* HAVE_RECORDING */
static void formatter_unit_0_is_off(char *buffer, size_t buffer_size, static const char* formatter_unit_0_is_off(char *buffer, size_t buffer_size,
int val, const char *unit) int val, const char *unit)
{ {
if (val == 0) if (val == 0)
strcpy(buffer, str(LANG_OFF)); return str(LANG_OFF);
else else
snprintf(buffer, buffer_size, "%d %s", val, unit); snprintf(buffer, buffer_size, "%d %s", val, unit);
return buffer;
} }
static int32_t getlang_unit_0_is_off(int value, int unit) static int32_t getlang_unit_0_is_off(int value, int unit)
@ -286,16 +287,17 @@ static int32_t getlang_unit_0_is_off(int value, int unit)
return TALK_ID(value,unit); return TALK_ID(value,unit);
} }
static void formatter_unit_0_is_skip_track(char *buffer, size_t buffer_size, static const char* formatter_unit_0_is_skip_track(char *buffer, size_t buffer_size,
int val, const char *unit) int val, const char *unit)
{ {
(void)unit; (void)unit;
if (val == 0) if (val == 0)
strcpy(buffer, str(LANG_SKIP_TRACK)); return str(LANG_SKIP_TRACK);
else if (val % 60 == 0) else if (val % 60 == 0)
snprintf(buffer, buffer_size, "%d min", val/60); snprintf(buffer, buffer_size, "%d min", val/60);
else else
snprintf(buffer, buffer_size, "%d s", val); snprintf(buffer, buffer_size, "%d s", val);
return buffer;
} }
static int32_t getlang_unit_0_is_skip_track(int value, int unit) static int32_t getlang_unit_0_is_skip_track(int value, int unit)
@ -310,15 +312,16 @@ static int32_t getlang_unit_0_is_skip_track(int value, int unit)
} }
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
static void backlight_formatter(char *buffer, size_t buffer_size, static const char* backlight_formatter(char *buffer, size_t buffer_size,
int val, const char *unit) int val, const char *unit)
{ {
if (val == -1) if (val == -1)
strcpy(buffer, str(LANG_OFF)); return str(LANG_OFF);
else if (val == 0) else if (val == 0)
strcpy(buffer, str(LANG_ON)); return str(LANG_ON);
else else
snprintf(buffer, buffer_size, "%d %s", val, unit); snprintf(buffer, buffer_size, "%d %s", val, unit);
return buffer;
} }
static int32_t backlight_getlang(int value, int unit) static int32_t backlight_getlang(int value, int unit)
{ {
@ -332,14 +335,15 @@ static int32_t backlight_getlang(int value, int unit)
#endif #endif
#ifndef HAVE_WHEEL_ACCELERATION #ifndef HAVE_WHEEL_ACCELERATION
static void scanaccel_formatter(char *buffer, size_t buffer_size, static const char* scanaccel_formatter(char *buffer, size_t buffer_size,
int val, const char *unit) int val, const char *unit)
{ {
(void)unit; (void)unit;
if (val == 0) if (val == 0)
strcpy(buffer, str(LANG_OFF)); return str(LANG_OFF);
else else
snprintf(buffer, buffer_size, "2x/%ds", val); snprintf(buffer, buffer_size, "2x/%ds", val);
return buffer;
} }
#endif #endif
@ -352,13 +356,14 @@ static void crossfeed_cross_set(int val)
global_settings.crossfeed_hf_cutoff); global_settings.crossfeed_hf_cutoff);
} }
static void db_format(char* buffer, size_t buffer_size, int value, static const char* db_format(char* buffer, size_t buffer_size, int value,
const char* unit) const char* unit)
{ {
int v = abs(value); int v = abs(value);
snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "", snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
v / 10, v % 10, unit); v / 10, v % 10, unit);
return buffer;
} }
static int32_t get_dec_talkid(int value, int unit) static int32_t get_dec_talkid(int value, int unit)
@ -384,27 +389,25 @@ static void set_superbass(bool value)
#endif #endif
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
static void jumpscroll_format(char* buffer, size_t buffer_size, int value, static const char* jumpscroll_format(char* buffer, size_t buffer_size, int value,
const char* unit) const char* unit)
{ {
(void)unit; (void)unit;
switch (value) switch (value)
{ {
case 0: case 0:
strcpy(buffer, str(LANG_OFF)); return str(LANG_OFF);
break;
case 1: case 1:
strcpy(buffer, str(LANG_ONE_TIME)); return str(LANG_ONE_TIME);
break;
case 2: case 2:
case 3: case 3:
case 4: case 4:
snprintf(buffer, buffer_size, "%d", value); snprintf(buffer, buffer_size, "%d", value);
break; break;
case 5: case 5:
strcpy(buffer, str(LANG_ALWAYS)); return str(LANG_ALWAYS);
break;
} }
return buffer;
} }
static int32_t jumpscroll_getlang(int value, int unit) static int32_t jumpscroll_getlang(int value, int unit)
{ {

View file

@ -73,7 +73,7 @@ struct int_setting {
int min; int min;
int max; int max;
int step; int step;
void (*formatter)(char*, size_t, int, const char*); const char* (*formatter)(char*, size_t, int, const char*);
int32_t (*get_talk_id)(int, int); int32_t (*get_talk_id)(int, int);
}; };
#define F_INT_SETTING 0x80 #define F_INT_SETTING 0x80
@ -92,7 +92,7 @@ struct choice_setting {
struct table_setting { struct table_setting {
void (*option_callback)(int); void (*option_callback)(int);
void (*formatter)(char*, size_t, int, const char*); const char* (*formatter)(char*, size_t, int, const char*);
int32_t (*get_talk_id)(int, int); int32_t (*get_talk_id)(int, int);
int unit; int unit;
int count; int count;

View file

@ -106,7 +106,7 @@ static int ft_play_dirname(char* name);
static void ft_play_filename(char *dir, char *file); static void ft_play_filename(char *dir, char *file);
static void say_filetype(int attr); static void say_filetype(int attr);
static char * tree_get_filename(int selected_item, void *data, static const char* tree_get_filename(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
struct tree_context * local_tc=(struct tree_context *)data; struct tree_context * local_tc=(struct tree_context *)data;