From 3200d04d75c5e7556ed8880b155533e881a4d1e1 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Thu, 20 Aug 2009 16:47:44 +0000 Subject: 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 --- apps/plugins/calendar.c | 2 +- apps/plugins/chessbox/chessbox_pgn.c | 8 +++----- apps/plugins/disktidy.c | 4 ++-- apps/plugins/doom/rockdoom.c | 8 +++++--- apps/plugins/goban/goban.c | 20 +++++++++++--------- apps/plugins/goban/types.h | 2 +- apps/plugins/goban/util.c | 2 +- apps/plugins/keybox.c | 4 ++-- apps/plugins/mpegplayer/mpeg_settings.c | 13 +++++++------ apps/plugins/properties.c | 6 +++--- apps/plugins/random_folder_advance_config.c | 4 +++- apps/plugins/rockboy/menu.c | 6 +++--- apps/plugins/rockpaint.c | 10 +++++----- apps/plugins/shortcuts/shortcuts_view.c | 8 ++++---- apps/plugins/superdom.c | 4 ++-- apps/plugins/text_editor.c | 4 ++-- 16 files changed, 55 insertions(+), 50 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index cfb92909bf..20b7fa9226 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c @@ -669,7 +669,7 @@ static bool edit_memo(int change, struct shown *shown) 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) { struct shown *shown = (struct shown *) data; diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index cd163a5e1c..512fb0ca15 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c @@ -528,11 +528,10 @@ void coords_to_pgn(struct pgn_ply_node* ply){ } } -char * get_game_text(int selected_item, void *data, - char *buffer, size_t buffer_len){ +static const char* get_game_text(int selected_item, void *data, + char *buffer, size_t buffer_len){ int i; struct pgn_game_node *temp_node = (struct pgn_game_node *)data; - char text_buffer[50]; for (i=0;inext_node; @@ -540,10 +539,9 @@ char * get_game_text(int selected_item, void *data, if (temp_node == 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); - rb->strlcpy(buffer, text_buffer, buffer_len); return buffer; } diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c index b7b9aa1770..84cc220891 100644 --- a/apps/plugins/disktidy.c +++ b/apps/plugins/disktidy.c @@ -380,8 +380,8 @@ enum themable_icons get_icon(int item, void * data) return Icon_NOICON; } -char * get_name(int selected_item, void * data, - char * buffer, size_t buffer_len) +static const char* get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) { (void)data; if (tidy_types[selected_item].directory) diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index ca08ec1665..1d065cc981 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c @@ -550,14 +550,15 @@ static bool Doptions() return (1); } -char* choice_get_name(int selected_item, void * data, - char * buffer, size_t buffer_len) +static const char* choice_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) { - char **names = (char **) data; + const char **names = (const char **) data; (void) buffer; (void) buffer_len; return names[selected_item]; } + int list_action_callback(int action, struct gui_synclist *lists) { (void) lists; @@ -565,6 +566,7 @@ int list_action_callback(int action, struct gui_synclist *lists) return ACTION_STD_CANCEL; return action; } + bool menuchoice(char **names, int count, int *selected) { struct simplelist_info info; diff --git a/apps/plugins/goban/goban.c b/apps/plugins/goban/goban.c index 65a03f6953..4e20e71a37 100644 --- a/apps/plugins/goban/goban.c +++ b/apps/plugins/goban/goban.c @@ -114,37 +114,39 @@ set_defaults (void) autosave_time = 7; } -static void +static const char* komi_formatter (char *dest, size_t size, int menu_item, const char *unknown) { (void) unknown; 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) { - (void) unknown; - rb->snprintf (dest, size, "%s", ruleset_names[menu_item]); + (void)dest, (void)size, (void)unknown; + return ruleset_names[menu_item]; } -static void +static const char* autosave_formatter (char *dest, size_t size, int menu_item, const char * unknown) { (void) unknown; if (menu_item == 0) { - rb->snprintf (dest, size, "Off"); + return "Off"; } else { rb->snprintf (dest, size, "%d minute%s", menu_item, menu_item == 1 ? "" : "s"); + return dest; } } -static void +static const char* time_formatter (char *dest, size_t size, int menu_item, const char *unknown) { 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) { - rb->snprintf (dest, size, "0"); - return; + return "0"; } 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; size -= temp; } + return dest; } enum plugin_status diff --git a/apps/plugins/goban/types.h b/apps/plugins/goban/types.h index 216d41bc21..a7c2b9b0ae 100644 --- a/apps/plugins/goban/types.h +++ b/apps/plugins/goban/types.h @@ -218,7 +218,7 @@ struct prop_t /* 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!!! */ enum ruleset_t diff --git a/apps/plugins/goban/util.c b/apps/plugins/goban/util.c index e9966311ef..0e83173f40 100644 --- a/apps/plugins/goban/util.c +++ b/apps/plugins/goban/util.c @@ -210,7 +210,7 @@ char *prop_names[] = { /* 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) */ -char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" }; +const char *ruleset_names[] = { "AGA", "Japanese", "Chinese", "NZ", "GOE" }; diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c index 733c6e95cd..d926105962 100644 --- a/apps/plugins/keybox.c +++ b/apps/plugins/keybox.c @@ -122,8 +122,8 @@ MENUITEM_STRINGLIST(context_m, "Context menu", context_item_cb, "Delete entry", "Playback Control"); -static char * kb_list_cb(int selected_item, void *data, - char *buffer, size_t buffer_len) +static const char* kb_list_cb(int selected_item, void *data, + char *buffer, size_t buffer_len) { (void)data; int i; diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c index 62293d101f..3868d759f6 100644 --- a/apps/plugins/mpegplayer/mpeg_settings.c +++ b/apps/plugins/mpegplayer/mpeg_settings.c @@ -317,7 +317,7 @@ static bool mpeg_set_int(const char *string, const char *unit, 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*)) { mpeg_menu_sysevent_clear(); @@ -350,15 +350,16 @@ static void backlight_brightness_function(int value) mpeg_backlight_update_brightness(value); } -static void backlight_brightness_formatter(char *buf, size_t length, - int value, const char *input) +static const char* backlight_brightness_formatter(char *buf, size_t length, + int value, const char *input) { + (void)input; + if (value < 0) - rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length); + return BACKLIGHT_OPTION_DEFAULT; else rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING); - - (void)input; + return buf; } #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c index c76a25b06a..7cd29c126f 100644 --- a/apps/plugins/properties.c +++ b/apps/plugins/properties.c @@ -228,7 +228,8 @@ static bool dir_properties(char* selected_file) 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; @@ -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); break; default: - rb->strlcpy(buffer, "ERROR", buffer_len); - break; + return "ERROR"; } return buffer; } diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index c9ffaed319..ba3f0d3f7e 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c @@ -234,7 +234,9 @@ void generate(void) rb->close(fd); 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; rb->strlcpy(buf, list->folder[selected_item], buf_len); diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index 455c91b5b6..bd4088300c 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c @@ -270,10 +270,10 @@ static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) { /* * slot_get_name */ -static char *slot_get_name(int selected_item, void * data, - char * buffer, size_t buffer_len) +static const char* slot_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) { - char (*items)[20] = data; + const char (*items)[20] = data; (void) buffer; (void) buffer_len; return items[selected_item]; diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index a4084a2ca7..219f013ed8 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c @@ -600,8 +600,8 @@ char bbuf[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; -static char * browse_get_name_cb( int selected_item, void *data, - char *buffer, size_t buffer_len ) +static const char* browse_get_name_cb(int selected_item, void *data, + char *buffer, size_t buffer_len) { int *indexes = (int *) data; struct entry* dc = tree->dircache; @@ -609,7 +609,7 @@ static char * browse_get_name_cb( int selected_item, void *data, (void) buffer; (void) buffer_len; - return (e->name); + return e->name; } static bool browse( char *dst, int dst_size, const char *start ) @@ -633,8 +633,8 @@ static bool browse( char *dst, int dst_size, const char *start ) } bbuf_s[0] = '\0'; - rb->gui_synclist_init( &browse_list, browse_get_name_cb, - (void*) indexes, false, 1, NULL ); + rb->gui_synclist_init(&browse_list, browse_get_name_cb, + (void*) indexes, false, 1, NULL); tree = rb->tree_get_context(); backup = *tree; diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c index f6a26a519d..b964968737 100644 --- a/apps/plugins/shortcuts/shortcuts_view.c +++ b/apps/plugins/shortcuts/shortcuts_view.c @@ -40,8 +40,8 @@ static bool usb_connected = false; enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc); /* Will be passed sc_file* as data */ -char* build_sc_list(int selected_item, void *data, - char *buffer, size_t buffer_len); +static const char* build_sc_list(int selected_item, void *data, + char *buffer, size_t buffer_len); /* Returns true iff we should leave the main loop */ bool list_sc(void); @@ -89,8 +89,8 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc) } -char* build_sc_list(int selected_item, void *data, - char *buffer, size_t buffer_len) +static const char* build_sc_list(int selected_item, void *data, + char *buffer, size_t buffer_len) { sc_file_t *file = (sc_file_t*)data; diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index d6b9621343..dc078170e9 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c @@ -1251,8 +1251,8 @@ int movement_menu(void) { return RET_VAL_OK; } -static char * inventory_data(int selected_item, void * data, - char * buffer, size_t buffer_len) { +static const char* inventory_data(int selected_item, void * data, + char * buffer, size_t buffer_len) { (void)data; switch(selected_item) { case 0: diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 473bb68ead..dc792046fa 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c @@ -121,8 +121,8 @@ int _do_action(int action, char* str, int line) last_char_index = c; return 1; } -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; char *b = &buffer[do_action(ACTION_GET,0,selected_item)]; -- cgit v1.2.3