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/menus/eq_menu.c | 9 ++++++--- apps/menus/eq_menu.h | 6 ++++-- apps/menus/main_menu.c | 28 ++++++++++++++-------------- apps/menus/recording_menu.c | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) (limited to 'apps/menus') diff --git a/apps/menus/eq_menu.c b/apps/menus/eq_menu.c index 6087ebfd5b..0e04dddc18 100644 --- a/apps/menus/eq_menu.c +++ b/apps/menus/eq_menu.c @@ -51,15 +51,18 @@ * 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 ? " " : "-", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit); + return buffer; } /* diff --git a/apps/menus/eq_menu.h b/apps/menus/eq_menu.h index 6be099113a..6c8301c572 100644 --- a/apps/menus/eq_menu.h +++ b/apps/menus/eq_menu.h @@ -43,7 +43,9 @@ bool eq_browse_presets(void); bool eq_menu_graphical(void); /* utility functions for settings_list.c */ -void eq_q_format(char* buffer, size_t buffer_size, int value, const char* unit); -void eq_precut_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); +const char* eq_precut_format(char* buffer, size_t buffer_size, int value, + const char* unit); #endif diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index 1e7465559e..99c73f2cdb 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c @@ -164,8 +164,8 @@ static const unsigned char *byte_units[] = ID2P(LANG_MEGABYTE) }; -static char* info_getname(int selected_item, void *data, - char *buffer, size_t buffer_len) +static const char* info_getname(int selected_item, void *data, + char *buffer, size_t buffer_len) { struct info_data *info = (struct info_data*)data; char s1[32]; @@ -199,27 +199,27 @@ static char* info_getname(int selected_item, void *data, #if CONFIG_CHARGING == CHARGING_SIMPLE /* Only know if plugged */ if (charger_inserted()) - return (char *)str(LANG_BATTERY_CHARGE); + return str(LANG_BATTERY_CHARGE); else #elif CONFIG_CHARGING >= CHARGING_MONITOR #ifdef ARCHOS_RECORDER /* Report the particular algorithm state */ if (charge_state == CHARGING) - return (char *)str(LANG_BATTERY_CHARGE); + return str(LANG_BATTERY_CHARGE); else if (charge_state == TOPOFF) - return (char *)str(LANG_BATTERY_TOPOFF_CHARGE); + return str(LANG_BATTERY_TOPOFF_CHARGE); else if (charge_state == TRICKLE) - return (char *)str(LANG_BATTERY_TRICKLE_CHARGE); + return str(LANG_BATTERY_TRICKLE_CHARGE); else #else /* !ARCHOS_RECORDER */ /* Go by what power management reports */ if (charging_state()) - return (char *)str(LANG_BATTERY_CHARGE); + return str(LANG_BATTERY_CHARGE); else #endif /* ARCHOS_RECORDER */ #endif /* CONFIG_CHARGING = */ 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); else return "(n/a)"; @@ -399,19 +399,19 @@ MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO), /* sleep Menu */ -static void sleep_timer_formatter(char* buffer, size_t buffer_size, int value, - const char* unit) +static const char* sleep_timer_formatter(char* buffer, size_t buffer_size, + int value, const char* unit) { - int minutes, hours; - (void) unit; + int minutes, hours; if (value) { hours = value / 60; minutes = value - (hours * 60); snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); - } else { - strlcpy(buffer, str(LANG_OFF), buffer_size); + return buffer; + } else { + return str(LANG_OFF); } } diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index c15a18291c..7b99b48a2d 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -415,7 +415,7 @@ static enum themable_icons trigger_get_icon(int selected_item, void * data) 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) { const struct settings_list **settings = -- cgit v1.2.3