diff options
author | Nils Wallménius <nils@rockbox.org> | 2009-08-20 16:47:44 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2009-08-20 16:47:44 +0000 |
commit | 3200d04d75c5e7556ed8880b155533e881a4d1e1 (patch) | |
tree | 188e2c9525b25cb8922a14766e51ab02bad3f831 /apps/gui | |
parent | 0a1728444882cdbc6a0c815bd88464de25ad94e9 (diff) |
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
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/bitmap/list.c | 2 | ||||
-rw-r--r-- | apps/gui/charcell/list.c | 2 | ||||
-rw-r--r-- | apps/gui/list.c | 10 | ||||
-rw-r--r-- | apps/gui/list.h | 4 | ||||
-rw-r--r-- | apps/gui/option_select.c | 22 | ||||
-rw-r--r-- | apps/gui/option_select.h | 2 | ||||
-rw-r--r-- | apps/gui/quickscreen.c | 4 |
7 files changed, 24 insertions, 22 deletions
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index 8e4cd44d21..71c74dbd09 100644 --- a/apps/gui/bitmap/list.c +++ b/apps/gui/bitmap/list.c @@ -173,7 +173,7 @@ void list_draw(struct screen *display, struct gui_synclist *list) for (i=start; i<end && i<list->nb_items; i++) { /* do the text */ - unsigned char *s; + unsigned const char *s; char entry_buffer[MAX_PATH]; unsigned char *entry_name; int text_pos = 0; diff --git a/apps/gui/charcell/list.c b/apps/gui/charcell/list.c index 8d91c2f6b8..2374156f0b 100644 --- a/apps/gui/charcell/list.c +++ b/apps/gui/charcell/list.c @@ -69,7 +69,7 @@ void list_draw(struct screen *display, struct gui_synclist *gui_list) for (i = start; i < end; i++) { - unsigned char *s; + unsigned const char *s; char entry_buffer[MAX_PATH]; unsigned char *entry_name; int current_item = gui_list->start_item[display->screen_type] + i; diff --git a/apps/gui/list.c b/apps/gui/list.c index 332459c57f..9b139dd47c 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -827,10 +827,10 @@ void simplelist_addline(int line_number, const char *fmt, ...) va_end(ap); } -static char* simplelist_static_getname(int item, - void * data, - char *buffer, - size_t buffer_len) +static const char* simplelist_static_getname(int item, + void * data, + char *buffer, + size_t buffer_len) { (void)data; (void)buffer; (void)buffer_len; return simplelist_text[item]; @@ -841,7 +841,7 @@ bool simplelist_show_list(struct simplelist_info *info) struct gui_synclist lists; int action, old_line_count = simplelist_line_count; 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; if (info->get_name) getname = info->get_name; diff --git a/apps/gui/list.h b/apps/gui/list.h index 7148e340cc..8a36acb005 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -64,8 +64,8 @@ typedef enum themable_icons list_get_icon(int selected_item, void * data); * - buffer_len : length of the buffer * Returns a pointer to a string that contains the text to display */ -typedef char * list_get_name(int selected_item, void * data, - char * buffer, size_t buffer_len); +typedef const char * list_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len); /* * Voice callback * - selected_item : an integer that tells the number of the item to speak diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 01259c4136..d806a0aa08 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -69,10 +69,11 @@ static const char *unit_strings[] = /* 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 */ static int table_setting_oldval = 0, table_setting_array_position = 0; -char *option_get_valuestring(const struct settings_list *setting, - char *buffer, int buf_len, - intptr_t temp_var) +const char *option_get_valuestring(const struct settings_list *setting, + char *buffer, int buf_len, + intptr_t temp_var) { + const char* str = buffer; if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) { 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 table_setting *tbl_info = setting->table_setting; 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) { formatter = int_info->formatter; @@ -105,7 +106,7 @@ char *option_get_valuestring(const struct settings_list *setting, unit = unit_strings[tbl_info->unit]; } if (formatter) - formatter(buffer, buf_len, (int)temp_var, unit); + str = formatter(buffer, buf_len, (int)temp_var, unit); else 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); } } - return buffer; + return str; } void option_talk_value(const struct settings_list *setting, int value, bool enqueue) { @@ -363,10 +364,11 @@ static int selection_to_val(const struct settings_list *setting, int selection) } return max- (selection * step); } -static char * value_setting_get_name_cb(int selected_item, - void * data, - char *buffer, - size_t buffer_len) + +static const char * value_setting_get_name_cb(int selected_item, + void * data, + char *buffer, + size_t buffer_len) { selected_item = selection_to_val(data, selected_item); return option_get_valuestring(data, buffer, buffer_len, selected_item); diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h index b1a4a86e65..a8661fb8ad 100644 --- a/apps/gui/option_select.h +++ b/apps/gui/option_select.h @@ -33,7 +33,7 @@ bool option_screen(const struct settings_list *setting, void option_select_next_val(const struct settings_list *setting, bool previous, bool apply); #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, intptr_t temp_var); void option_talk_value(const struct settings_list *setting, int value, bool enqueue); diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 20d27380d2..d6d662b1f1 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -147,7 +147,7 @@ static void quickscreen_fix_viewports(struct gui_quickscreen *qs, 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) { int nb_lines = viewport_get_nb_lines(vp); @@ -186,7 +186,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, int i; char buf[MAX_PATH]; - unsigned char *title, *value; + unsigned const char *title, *value; void *setting; int temp; display->set_viewport(parent); |