From 33c44461e1b5fb9aff2f8ba7470ad2449b3c410e Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Sat, 26 Apr 2008 09:30:24 +0000 Subject: Const police raid, making a lot of pointers to lang strings const and removing some ugly casting git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17251 a1c6a512-1295-4272-9138-f99709370657 --- apps/bookmark.c | 8 ++++---- apps/filetree.c | 6 +++--- apps/gui/textarea.c | 4 ++-- apps/gui/textarea.h | 6 +++--- apps/gui/yesno.c | 14 +++++++------- apps/gui/yesno.h | 10 +++++----- apps/menus/main_menu.c | 17 ++++++++++------- apps/misc.c | 6 +++--- apps/onplay.c | 12 ++++++------ apps/playlist_catalog.c | 8 +++----- apps/recorder/radio.c | 6 +++--- apps/root_menu.c | 5 +++-- apps/screens.c | 4 ++-- apps/tagtree.c | 4 ++-- apps/tree.c | 4 ++-- 15 files changed, 58 insertions(+), 56 deletions(-) diff --git a/apps/bookmark.c b/apps/bookmark.c index 30102bb954..13c9abe936 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -187,12 +187,12 @@ bool bookmark_autobookmark(void) return write_bookmark(false); } #ifdef HAVE_LCD_BITMAP - unsigned char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY)}; - struct text_message message={(char **)lines, 1}; + const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY)}; + const struct text_message message={lines, 1}; #else - unsigned char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY), + const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY), str(LANG_CONFIRM_WITH_BUTTON)}; - struct text_message message={(char **)lines, 2}; + const struct text_message message={lines, 2}; #endif #if LCD_DEPTH > 1 show_main_backdrop(); /* switch to main backdrop as we may come from wps */ diff --git a/apps/filetree.c b/apps/filetree.c index e8fb459d52..cac2c79034 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -104,7 +104,7 @@ bool ft_play_playlist(char* pathname, char* dirname, char* filename) if (global_settings.warnon_erase_dynplaylist && playlist_modified(NULL)) { - char *lines[] = {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; + const char *lines[] = {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; struct text_message message = {lines, 1}; if (gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) @@ -408,8 +408,8 @@ int ft_enter(struct tree_context* c) !global_settings.party_mode && playlist_modified(NULL)) { - char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; - struct text_message message={lines, 1}; + static const char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; + static const struct text_message message={lines, 1}; if(gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) break; diff --git a/apps/gui/textarea.c b/apps/gui/textarea.c index b30667df4e..dcffd0e621 100644 --- a/apps/gui/textarea.c +++ b/apps/gui/textarea.c @@ -47,7 +47,7 @@ void gui_textarea_update(struct screen * display) } int gui_textarea_put_message(struct screen * display, - struct text_message * message, + const struct text_message * message, int ystart) { int i; @@ -78,7 +78,7 @@ void gui_textarea_update_nblines(struct screen * display) display->nb_lines = height / display->char_height; } -void talk_text_message(struct text_message * message, bool enqueue) +void talk_text_message(const struct text_message * message, bool enqueue) { int line; if(message) diff --git a/apps/gui/textarea.h b/apps/gui/textarea.h index 765add084a..3f16dd440c 100644 --- a/apps/gui/textarea.h +++ b/apps/gui/textarea.h @@ -25,7 +25,7 @@ struct text_message { - char **message_lines; + const char **message_lines; int nb_lines; }; @@ -50,7 +50,7 @@ extern void gui_textarea_update(struct screen * display); * returns : the number of lines effectively displayed */ extern int gui_textarea_put_message(struct screen * display, - struct text_message * message, + const struct text_message * message, int ystart); /* * Compute the number of text lines the display can draw with the current font @@ -63,7 +63,7 @@ extern void gui_textarea_update_nblines(struct screen * display); * Speak a text_message. The message's lines may be virtual pointers * representing language / voicefont IDs (see settings.h). */ -extern void talk_text_message(struct text_message * message, bool enqueue); +extern void talk_text_message(const struct text_message * message, bool enqueue); #ifdef HAVE_LCD_BITMAP /* diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c index 891e73809b..51a1eabd60 100644 --- a/apps/gui/yesno.c +++ b/apps/gui/yesno.c @@ -33,9 +33,9 @@ * - no_message : message displayed if answer is 'no' */ static void gui_yesno_init(struct gui_yesno * yn, - struct text_message * main_message, - struct text_message * yes_message, - struct text_message * no_message) + const struct text_message * main_message, + const struct text_message * yes_message, + const struct text_message * no_message) { yn->main_message=main_message; yn->result_message[YESNO_YES]=yes_message; @@ -92,7 +92,7 @@ static void gui_yesno_draw(struct gui_yesno * yn) */ static bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result) { - struct text_message * message=yn->result_message[result]; + const struct text_message * message=yn->result_message[result]; if(message==NULL) return false; gui_textarea_put_message(yn->display, message, 0); @@ -101,9 +101,9 @@ static bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result) #include "debug.h" -enum yesno_res gui_syncyesno_run(struct text_message * main_message, - struct text_message * yes_message, - struct text_message * no_message) +enum yesno_res gui_syncyesno_run(const struct text_message * main_message, + const struct text_message * yes_message, + const struct text_message * no_message) { int i; unsigned button; diff --git a/apps/gui/yesno.h b/apps/gui/yesno.h index 67456cf69b..b57ee89d48 100644 --- a/apps/gui/yesno.h +++ b/apps/gui/yesno.h @@ -32,8 +32,8 @@ enum yesno_res struct gui_yesno { - struct text_message * main_message; - struct text_message * result_message[2]; + const struct text_message * main_message; + const struct text_message * result_message[2]; struct screen * display; }; @@ -47,7 +47,7 @@ struct gui_yesno * - no_message : message displayed if answer is 'no' */ extern enum yesno_res gui_syncyesno_run( - struct text_message * main_message, - struct text_message * yes_message, - struct text_message * no_message); + const struct text_message * main_message, + const struct text_message * yes_message, + const struct text_message * no_message); #endif /* _GUI_YESNO_H_ */ diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index 8e4ee61aee..57db13f52c 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c @@ -55,15 +55,18 @@ static const struct browse_folder_info config = {ROCKBOX_DIR, SHOW_CFG}; static int reset_settings(void) { - const unsigned char *lines[]={ID2P(LANG_RESET_ASK)}; - const unsigned char *yes_lines[]={ - str(LANG_SETTINGS), + static const char *lines[]={ID2P(LANG_RESET_ASK)}; + static const char *yes_lines[]={ + ID2P(LANG_SETTINGS), ID2P(LANG_RESET_DONE_CLEAR) }; - const unsigned char *no_lines[]={yes_lines[0], ID2P(LANG_CANCEL)}; - struct text_message message={(char **)lines, 1}; - struct text_message yes_message={(char **)yes_lines, 2}; - struct text_message no_message={(char **)no_lines, 2}; + static const char *no_lines[]={ + ID2P(LANG_SETTINGS), + ID2P(LANG_CANCEL) + }; + static const struct text_message message={lines, 1}; + static const struct text_message yes_message={yes_lines, 2}; + static const struct text_message no_message={no_lines, 2}; switch(gui_syncyesno_run(&message, &yes_message, &no_message)) { diff --git a/apps/misc.c b/apps/misc.c index f6e5e6b880..ef4f968119 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1050,9 +1050,9 @@ void check_bootfile(bool do_rolo) if((entry->wrtdate != wrtdate) || (entry->wrttime != wrttime)) { - char *lines[] = { ID2P(LANG_BOOT_CHANGED), - ID2P(LANG_REBOOT_NOW) }; - struct text_message message={ lines, 2 }; + static const char *lines[] = { ID2P(LANG_BOOT_CHANGED), + ID2P(LANG_REBOOT_NOW) }; + static const struct text_message message={ lines, 2 }; button_clear_queue(); /* Empty the keyboard buffer */ if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_YES) rolo_load(BOOTDIR "/" BOOTFILE); diff --git a/apps/onplay.c b/apps/onplay.c index 21b16c9381..a0de6f2e81 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -160,11 +160,11 @@ static bool save_playlist(void) static bool add_to_playlist(int position, bool queue) { bool new_playlist = !(audio_status() & AUDIO_STATUS_PLAY); - char *lines[] = { + const char *lines[] = { ID2P(LANG_RECURSE_DIRECTORY_QUESTION), selected_file }; - struct text_message message={lines, 2}; + const struct text_message message={lines, 2}; gui_syncsplash(0, ID2P(LANG_WAIT)); @@ -523,11 +523,11 @@ static int remove_dir(char* dirname, int len) /* share code for file and directory deletion, saves space */ static bool delete_handler(bool is_dir) { - char *lines[]={ + const char *lines[]={ ID2P(LANG_REALLY_DELETE), selected_file }; - char *yes_lines[]={ + const char *yes_lines[]={ ID2P(LANG_DELETED), selected_file }; @@ -867,8 +867,8 @@ static bool clipboard_paste(void) char *cwd, *nameptr; bool success; - unsigned char *lines[]={ID2P(LANG_REALLY_OVERWRITE)}; - struct text_message message={(char **)lines, 1}; + static const char *lines[]={ID2P(LANG_REALLY_OVERWRITE)}; + static const struct text_message message={lines, 1}; /* Get the name of the current directory */ cwd = getcwd(NULL, 0); diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 9ac9e32e00..2b5020f7f3 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -378,11 +378,9 @@ static int add_to_playlist(const char* playlist, char* sel, int sel_attr) { /* search directory for tracks and append to playlist */ bool recurse = false; - char *lines[] = { - (char *)str(LANG_RECURSE_DIRECTORY_QUESTION), - sel - }; - struct text_message message={lines, 2}; + const char *lines[] = { + str(LANG_RECURSE_DIRECTORY_QUESTION), sel}; + const struct text_message message={lines, 2}; struct add_track_context context; if (global_settings.recursive_dir_insert != RECURSE_ASK) diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index e103c6bc82..522f1dac93 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -136,11 +136,11 @@ static int scan_presets(void); /* Function to manipulate all yesno dialogues. This function needs the output text as an argument. */ -static bool yesno_pop(char* text) +static bool yesno_pop(const char* text) { int i; - char *lines[]={text}; - struct text_message message={lines, 1}; + const char *lines[]={text}; + const struct text_message message={lines, 1}; bool ret = (gui_syncyesno_run(&message,NULL,NULL)== YESNO_YES); FOR_NB_SCREENS(i) gui_textarea_clear(&screens[i]); diff --git a/apps/root_menu.c b/apps/root_menu.c index dcbd95c23f..378b776b81 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -143,8 +143,9 @@ static int browser(void* param) { /* Prompt the user */ reinit_attempted = true; - char *lines[]={ID2P(LANG_TAGCACHE_BUSY), ID2P(LANG_TAGCACHE_FORCE_UPDATE)}; - struct text_message message={lines, 2}; + static const char *lines[]={ + ID2P(LANG_TAGCACHE_BUSY), ID2P(LANG_TAGCACHE_FORCE_UPDATE)}; + static const struct text_message message={lines, 2}; if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO) break; int i; diff --git a/apps/screens.c b/apps/screens.c index 569ece4faa..0855b12002 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -1270,8 +1270,8 @@ static int runtime_speak_data(int selected_item, void* data) bool view_runtime(void) { - unsigned char *lines[]={ID2P(LANG_CLEAR_TIME)}; - struct text_message message={(char **)lines, 1}; + static const char *lines[]={ID2P(LANG_CLEAR_TIME)}; + static const struct text_message message={lines, 1}; struct gui_synclist lists; int action; diff --git a/apps/tagtree.c b/apps/tagtree.c index 50921d0baf..f9646a0b00 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -1501,8 +1501,8 @@ int tagtree_enter(struct tree_context* c) !global_settings.party_mode && playlist_modified(NULL)) { - char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; - struct text_message message={lines, 1}; + static const char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; + static const struct text_message message={lines, 1}; if (gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) break; diff --git a/apps/tree.c b/apps/tree.c index 275eb6ad2d..d1d9adb3b2 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -645,8 +645,8 @@ static int dirbrowse() tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */ #ifdef BOOTFILE if (boot_changed) { - char *lines[]={ID2P(LANG_BOOT_CHANGED), ID2P(LANG_REBOOT_NOW)}; - struct text_message message={lines, 2}; + static const char *lines[]={ID2P(LANG_BOOT_CHANGED), ID2P(LANG_REBOOT_NOW)}; + static const struct text_message message={lines, 2}; if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) rolo_load("/" BOOTFILE); restore = true; -- cgit