From 77e8cd0145d2ea6075a20841016eca96d4bce65d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 13 Dec 2008 12:23:20 +0100 Subject: [PATCH] variables cleaning --- src/browser.cpp | 9 +++--- src/help.cpp | 2 +- src/helpers.cpp | 2 +- src/ncmpcpp.cpp | 68 ++++++++++++++++++++++----------------------- src/search_engine.h | 2 +- src/tag_editor.cpp | 8 +++--- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/browser.cpp b/src/browser.cpp index 02cf6b85..5583d4e6 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -46,7 +46,7 @@ extern int browsed_dir_scroll_begin; namespace { - const string supported_extensions[] = { "wma", "asf", "rm", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", "it", "mod", "s3m", "xm", "wv", "." }; + const char *supported_extensions[] = { "wma", "asf", "rm", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", "it", "mod", "s3m", "xm", "wv", 0 }; bool hasSupportedExtension(const string &file) { @@ -56,8 +56,8 @@ namespace string ext = file.substr(last_dot+1); ToLower(ext); - for (int i = 0; supported_extensions[i] != "."; i++) - if (ext == supported_extensions[i]) + for (int i = 0; supported_extensions[i]; i++) + if (strcmp(ext.c_str(), supported_extensions[i]) == 0) return true; return false; @@ -142,8 +142,7 @@ void DisplayItem(const Item &item, void *, Menu *menu) return; } case itSong: - // I know casting that way is ugly etc., but it works. - DisplaySong(*item.song, &Config.song_list_format, (Menu *)menu); + DisplaySong(*item.song, &Config.song_list_format, reinterpret_cast *>(menu)); return; case itPlaylist: *menu << Config.browser_playlist_prefix << item.name; diff --git a/src/help.cpp b/src/help.cpp index 9a9d1b8d..498c4b95 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -82,7 +82,7 @@ namespace } if (result.length() > 12) result = result.substr(0, 12); - for (int i = result.length(); i <= 12; result += " ", i++) { } + for (size_t i = result.length(); i <= 12; result += " ", i++) { } result += ": "; return result; } diff --git a/src/helpers.cpp b/src/helpers.cpp index b625214b..e0359918 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -871,7 +871,7 @@ const basic_buffer &ShowTagInInfoScreen(const string &tag) if (tag.empty()) result << Config.empty_tags_color << ToWString(Config.empty_tag) << clEnd; else - result << TO_WSTRING(tag); + result << ToWString(tag); return result; # else return ShowTag(tag); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 4ef87270..337ed811 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -88,11 +88,8 @@ using namespace MPD; ncmpcpp_config Config; ncmpcpp_keys Key; -vector vFoundPositions; -int found_pos = 0; - -Window *wCurrent = 0; -Window *wPrev = 0; +Window *wCurrent; +Window *wPrev; Menu *mPlaylist; Menu *mBrowser; @@ -107,10 +104,10 @@ Menu *mTagEditor; Menu *mEditorAlbums; Menu *mEditorDirs; #endif // HAVE_TAGLIB_H -// blah, I use them in conditionals, so just let them be. -Menu *mEditorLeftCol = 0; +// blah, I use below in conditionals. +Menu *mEditorLeftCol; Menu *mEditorTagTypes; -Menu *mEditorTags = 0; +Menu *mEditorTags; Menu *mPlaylistList; Menu *mPlaylistEditor; @@ -200,8 +197,8 @@ int main(int argc, char *argv[]) InitScreen(Config.colors_enabled); - int main_start_y = 2; - int main_height = LINES-4; + size_t main_start_y = 2; + size_t main_height = LINES-4; if (!Config.header_visibility) { @@ -233,11 +230,11 @@ int main(int argc, char *argv[]) mSearcher->SetSelectPrefix(&Config.selected_item_prefix); mSearcher->SetSelectSuffix(&Config.selected_item_suffix); - int left_col_width = COLS/3-1; - int middle_col_width = COLS/3; - int middle_col_startx = left_col_width+1; - int right_col_width = COLS-COLS/3*2-1; - int right_col_startx = left_col_width+middle_col_width+2; + size_t left_col_width = COLS/3-1; + size_t middle_col_width = COLS/3; + size_t middle_col_startx = left_col_width+1; + size_t right_col_width = COLS-COLS/3*2-1; + size_t right_col_startx = left_col_width+middle_col_width+2; mLibArtists = new Menu(0, main_start_y, left_col_width, main_height, IntoStr(Config.media_lib_primary_tag) + "s", Config.main_color, brNone); mLibArtists->HighlightColor(Config.main_highlight_color); @@ -318,8 +315,8 @@ int main(int argc, char *argv[]) wHeader->Display(); } - int footer_start_y = LINES-(Config.statusbar_visibility ? 2 : 1); - int footer_height = Config.statusbar_visibility ? 2 : 1; + size_t footer_start_y = LINES-(Config.statusbar_visibility ? 2 : 1); + size_t footer_height = Config.statusbar_visibility ? 2 : 1; wFooter = new Window(0, footer_start_y, COLS, footer_height, "", Config.statusbar_color, brNone); wFooter->SetTimeout(ncmpcpp_window_timeout); @@ -335,6 +332,9 @@ int main(int argc, char *argv[]) Mpd->SetErrorHandler(NcmpcppErrorCallback, NULL); // local variables + vector vFoundPositions; + + int found_pos = 0; int input; Song edited_song; @@ -1010,7 +1010,7 @@ int main(int argc, char *argv[]) # ifdef HAVE_TAGLIB_H case csTinyTagEditor: { - int option = mTagEditor->Choice(); + size_t option = mTagEditor->Choice(); LockStatusbar(); Song &s = edited_song; @@ -1154,11 +1154,11 @@ int main(int argc, char *argv[]) { ENTER_SEARCH_ENGINE_SCREEN: - int option = mSearcher->Choice(); + size_t option = mSearcher->Choice(); LockStatusbar(); Song &s = sought_pattern; - if (option >= 0 && option <= 11) + if (option <= 11) mSearcher->Current().first->Clear(); switch (option+1) @@ -1243,7 +1243,7 @@ int main(int argc, char *argv[]) Search(s); if (!mSearcher->Back().first) { - int found = mSearcher->Size()-search_engine_static_options; + size_t found = mSearcher->Size()-search_engine_static_options; found += 3; // don't count options inserted below mSearcher->InsertSeparator(15); mSearcher->InsertOption(16, make_pair((Buffer *)0, (Song *)0), 1, 1); @@ -1252,7 +1252,7 @@ int main(int argc, char *argv[]) mSearcher->InsertSeparator(17); UpdateFoundList(); ShowMessage("Searching finished!"); - for (int i = 0; i < search_engine_static_options-4; i++) + for (size_t i = 0; i < search_engine_static_options-4; i++) mSearcher->Static(i, 1); mSearcher->Scroll(wDown); mSearcher->Scroll(wDown); @@ -1526,7 +1526,7 @@ int main(int argc, char *argv[]) SongGetFunction get = 0; SongSetFunction set = 0; - int id = mEditorTagTypes->RealChoice(); + size_t id = mEditorTagTypes->RealChoice(); switch (id) { case 0: @@ -1692,7 +1692,7 @@ int main(int argc, char *argv[]) if (wCurrent == mPlaylist || wCurrent == mEditorTags || (wCurrent == mBrowser && ((Menu *)wCurrent)->Choice() >= (browsed_dir != "/" ? 1 : 0)) || (wCurrent == mSearcher && !mSearcher->Current().first) || wCurrent == mLibSongs || wCurrent == mPlaylistEditor) { List *mList = (Menu *)wCurrent; - int i = mList->Choice(); + size_t i = mList->Choice(); mList->Select(i, !mList->isSelected(i)); wCurrent->Scroll(wDown); } @@ -1963,10 +1963,10 @@ int main(int argc, char *argv[]) mPlaylist->SetTimeout(50); while (!mPlaylist->Empty() && Keypressed(input, Key.Delete)) { - int id = mPlaylist->Choice(); + size_t id = mPlaylist->Choice(); TraceMpdStatus(); timer = time(NULL); - if (now_playing > id) // needed for keeping proper + if (size_t(now_playing) > id) // needed for keeping proper now_playing--; // position of now playing song. Mpd->QueueDeleteSong(id); mPlaylist->DeleteOption(id); @@ -2138,10 +2138,10 @@ int main(int argc, char *argv[]) } else { - int from, to; + size_t from, to; from = to = mPlaylist->Choice(); // unbold now playing as if song changes during move, this won't be unbolded. - if (to == now_playing && to > 0) + if (to == size_t(now_playing) && to > 0) mPlaylist->BoldOption(now_playing, 0); while (Keypressed(input, Key.MvSongUp) && to > 0) { @@ -2187,7 +2187,7 @@ int main(int argc, char *argv[]) } else { - int from, to; + size_t from, to; from = to = mPlaylistEditor->Choice(); while (Keypressed(input, Key.MvSongUp) && to > 0) { @@ -2540,7 +2540,7 @@ int main(int argc, char *argv[]) || (wCurrent == mEditorTags && !mEditorTags->Empty())) { List *mList = reinterpret_cast *>(wCurrent); - int id = mList->Choice(); + size_t id = mList->Choice(); switch (current_screen) { case csPlaylist: @@ -2661,7 +2661,7 @@ int main(int argc, char *argv[]) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) || (wCurrent == mEditorTags && !mEditorTags->Empty())) { - int id = ((Menu *)wCurrent)->Choice(); + size_t id = ((Menu *)wCurrent)->Choice(); Song *s; switch (current_screen) { @@ -2827,8 +2827,8 @@ int main(int argc, char *argv[]) } } - const int dialog_width = COLS*0.8; - const int dialog_height = LINES*0.6; + size_t dialog_width = COLS*0.8; + size_t dialog_height = LINES*0.6; Menu *mDialog = new Menu((COLS-dialog_width)/2, (LINES-dialog_height)/2, dialog_width, dialog_height, "Add selected items to...", Config.main_color, Config.window_border); mDialog->SetTimeout(ncmpcpp_window_timeout); mDialog->SetItemDisplayer(GenericDisplayer); @@ -3239,7 +3239,7 @@ int main(int argc, char *argv[]) || (wCurrent == mEditorTags && !mEditorTags->Empty())) { Song *s; - int id = ((Menu *)wCurrent)->Choice(); + size_t id = ((Menu *)wCurrent)->Choice(); switch (current_screen) { case csPlaylist: diff --git a/src/search_engine.h b/src/search_engine.h index a699bc0b..65332148 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -24,7 +24,7 @@ #include "mpdpp.h" #include "ncmpcpp.h" -const int search_engine_static_options = 18; +const size_t search_engine_static_options = 18; void SearchEngineDisplayer(const std::pair &, void *, Menu< std::pair > *); void UpdateFoundList(); diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index c32fe0c7..e0754434 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -422,7 +422,7 @@ bool WriteTags(Song &s) { // if we rename local file, it won't get updated // so just remove it from playlist and add again - int pos = mPlaylist->Choice(); + size_t pos = mPlaylist->Choice(); Mpd->QueueDeleteSong(pos); Mpd->CommitQueue(); int id = Mpd->AddSong("file://" + new_name); @@ -474,9 +474,9 @@ void __deal_with_filenames(SongList &v) height = LINES*0.8; bool exit = 0; bool preview = 1; - int choice = Main->Choice(); - int one_width = width/2; - int two_width = width-one_width; + size_t choice = Main->Choice(); + size_t one_width = width/2; + size_t two_width = width-one_width; delete Main;