Code

list_window: use "bool" instead of "int"
authorMax Kellermann <max@duempel.org>
Thu, 27 Nov 2008 16:56:32 +0000 (17:56 +0100)
committerMax Kellermann <max@duempel.org>
Thu, 27 Nov 2008 16:56:32 +0000 (17:56 +0100)
For flags and return values, use the "bool" data type instead of
"int".

12 files changed:
src/list_window.c
src/list_window.h
src/screen_artist.c
src/screen_browser.c
src/screen_browser.h
src/screen_help.c
src/screen_keydef.c
src/screen_lyrics.c
src/screen_play.c
src/screen_search.c
src/screen_song.c
src/screen_utils.c

index 46858ee2bb5d2862b9a16dee7fd257a536c2ec7a..b12e8eb8cff56ca1644405f7303fddc16e7ac753 100644 (file)
@@ -165,8 +165,8 @@ list_window_paint(struct list_window *lw,
                  void *callback_data)
 {
        unsigned i;
-       int fill = options.wide_cursor;
-       int show_cursor = !(lw->flags & LW_HIDE_CURSOR);
+       bool fill = options.wide_cursor;
+       bool show_cursor = !(lw->flags & LW_HIDE_CURSOR);
 
        if (show_cursor) {
                if (lw->selected < lw->start)
@@ -177,14 +177,14 @@ list_window_paint(struct list_window *lw,
        }
 
        for (i = 0; i < lw->rows; i++) {
-               int highlight = 0;
+               bool highlight = false;
                const char *label;
 
                label = callback(lw->start + i, &highlight, callback_data);
                wmove(lw->w, i, 0);
 
                if (label) {
-                       int selected = lw->start + i == lw->selected;
+                       bool selected = lw->start + i == lw->selected;
                        unsigned len = utf8_width(label);
 
                        if (highlight)
@@ -210,14 +210,14 @@ list_window_paint(struct list_window *lw,
        }
 }
 
-int
+bool
 list_window_find(struct list_window *lw,
                 list_window_callback_fn_t callback,
                 void *callback_data,
                 const char *str,
-                int wrap)
+                bool wrap)
 {
-       int h;
+       bool h;
        unsigned i = lw->selected + 1;
        const char *label;
 
@@ -225,10 +225,10 @@ list_window_find(struct list_window *lw,
                while ((label = callback(i,&h,callback_data))) {
                        if (str && label && strcasestr(label, str)) {
                                lw->selected = i;
-                               return 0;
+                               return true;
                        }
                        if (wrap && i == lw->selected)
-                               return 1;
+                               return false;
                        i++;
                }
                if (wrap) {
@@ -239,32 +239,32 @@ list_window_find(struct list_window *lw,
                }
        } while (wrap);
 
-       return 1;
+       return false;
 }
 
-int
+bool
 list_window_rfind(struct list_window *lw,
                  list_window_callback_fn_t callback,
                  void *callback_data,
                  const char *str,
-                 int wrap,
+                 bool wrap,
                  unsigned rows)
 {
-       int h;
+       bool h;
        int i = lw->selected - 1;
        const char *label;
 
        if (rows == 0)
-               return 1;
+               return false;
 
        do {
                while (i >= 0 && (label = callback(i,&h,callback_data))) {
                        if( str && label && strcasestr(label, str) ) {
                                lw->selected = i;
-                               return 0;
+                               return true;
                        }
                        if (wrap && i == (int)lw->selected)
-                               return 1;
+                               return false;
                        i--;
                }
                if (wrap) {
@@ -273,11 +273,11 @@ list_window_rfind(struct list_window *lw,
                }
        } while (wrap);
 
-       return 1;
+       return false;
 }
 
 /* perform basic list window commands (movement) */
-int
+bool
 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
 {
        switch (cmd) {
@@ -300,13 +300,13 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
                list_window_previous_page(lw);
                break;
        default:
-               return 0;
+               return false;
        }
 
-       return 1;
+       return true;
 }
 
-int
+bool
 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd)
 {
        switch (cmd) {
@@ -349,14 +349,14 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd)
                break;
 
        default:
-               return 0;
+               return false;
        }
 
-       return 1;
+       return true;
 }
 
 #ifdef HAVE_GETMOUSE
-int
+bool
 list_window_mouse(struct list_window *lw, unsigned rows,
                  unsigned long bstate, int y)
 {
@@ -368,7 +368,7 @@ list_window_mouse(struct list_window *lw, unsigned rows,
                        list_window_first(lw);
                else
                        list_window_previous_page(lw);
-               return 1;
+               return true;
        }
 
        /* if the even occured below the list window move down */
@@ -377,9 +377,9 @@ list_window_mouse(struct list_window *lw, unsigned rows,
                        list_window_last(lw, rows);
                else
                        list_window_next_page(lw, rows);
-               return 1;
+               return true;
        }
 
-       return 0;
+       return false;
 }
 #endif
index 11c4cddaba6d5dc3d04e4ec3d8d4b05fd81280fd..bcf3e3228913df012a59ad25ac2749d1c155869b 100644 (file)
@@ -5,6 +5,7 @@
 #include "command.h"
 
 #include <glib.h>
+#include <stdbool.h>
 
 #ifdef HAVE_NCURSESW_NCURSES_H
 #include <ncursesw/ncurses.h>
@@ -15,7 +16,7 @@
 #define LW_HIDE_CURSOR    0x01
 
 typedef const char *(*list_window_callback_fn_t)(unsigned index,
-                                                int *highlight,
+                                                bool *highlight,
                                                 void *data);
 
 typedef struct list_window {
@@ -45,13 +46,14 @@ void list_window_paint(struct list_window *lw,
                       void *callback_data);
 
 /* perform basic list window commands (movement) */
-int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
+bool
+list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
 
 /**
  * Scroll the window.  Returns non-zero if the command has been
  * consumed.
  */
-int
+bool
 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
 
 #ifdef HAVE_GETMOUSE
@@ -59,7 +61,7 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
  * The mouse was clicked.  Check if the list should be scrolled
  * Returns non-zero if the mouse event has been handled.
  */
-int
+bool
 list_window_mouse(struct list_window *lw, unsigned rows,
                  unsigned long bstate, int y);
 #endif
@@ -72,19 +74,20 @@ void list_window_set_selected(struct list_window *lw, unsigned n);
 void list_window_check_selected(struct list_window *lw, unsigned length);
 
 /* find a string in a list window */
-int  list_window_find(struct list_window *lw,
-                     list_window_callback_fn_t callback,
-                     void *callback_data,
-                     const char *str,
-                     int wrap);
+bool
+list_window_find(struct list_window *lw,
+                list_window_callback_fn_t callback,
+                void *callback_data,
+                const char *str,
+                bool wrap);
 
 /* find a string in a list window (reversed) */
-int
+bool
 list_window_rfind(struct list_window *lw,
                  list_window_callback_fn_t callback,
                  void *callback_data,
                  const char *str,
-                 int wrap,
+                 bool wrap,
                  unsigned rows);
 
 #endif
index 7180c38edd39f2d8fee3b6e7dc47c38a4cc56d0f..be951ee6ec902feafe6cf79a22d74b5848310d03 100644 (file)
@@ -59,7 +59,7 @@ compare_utf8(gconstpointer s1, gconstpointer s2)
 
 /* list_window callback */
 static const char *
-artist_lw_callback(unsigned idx, G_GNUC_UNUSED int *highlight,
+artist_lw_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
                   G_GNUC_UNUSED void *data)
 {
        GPtrArray *list = data;
index 3aeab0b33749fff2c3b681dd5202e14f188e38cc..4d911e0d7a618368f0caa3ab0e1ffd3fff438215 100644 (file)
@@ -119,7 +119,7 @@ browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c,
 
 /* list_window callback */
 const char *
-browser_lw_callback(unsigned idx, int *highlight, void *data)
+browser_lw_callback(unsigned idx, bool *highlight, void *data)
 {
        static char buf[BUFSIZE];
        mpdclient_filelist_t *fl = (mpdclient_filelist_t *) data;
@@ -134,7 +134,7 @@ browser_lw_callback(unsigned idx, int *highlight, void *data)
 
        entity = entry->entity;
 #ifndef NCMPC_MINI
-       *highlight = (entry->flags & HIGHLIGHT);
+       *highlight = (entry->flags & HIGHLIGHT) != 0;
 #else
        *highlight = false;
 #endif
index 6ea17cc18edae90a4def5e3766d6159192a0c34d..1cc0b2744a5505dc85890e993e5b503d88fdb2be 100644 (file)
@@ -46,7 +46,7 @@ browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c,
 
 #endif
 
-const char *browser_lw_callback(unsigned index, int *highlight, void *filelist);
+const char *browser_lw_callback(unsigned index, bool *highlight, void *filelist);
 
 bool
 browser_change_directory(struct screen_browser *browser, mpdclient_t *c,
index 2f06adacd54499801dc99ad5754c83b5e727c2e5..0cc15a37a2e302800e6e7233b9a848005398aa38 100644 (file)
@@ -141,7 +141,7 @@ static help_text_row_t help_text[] = {
 static list_window_t *lw;
 
 static const char *
-list_callback(unsigned idx, int *highlight, G_GNUC_UNUSED void *data)
+list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
 {
        static char buf[512];
 
@@ -149,7 +149,7 @@ list_callback(unsigned idx, int *highlight, G_GNUC_UNUSED void *data)
                return NULL;
 
        if (help_text[idx].highlight)
-               *highlight = 1;
+               *highlight = true;
 
        if (help_text[idx].command == CMD_NONE) {
                if (help_text[idx].text)
index 02ef177d828cce17df35b5f707a411bcb44513db..a8f01b352ee9195d207f8985069b12ba27ebe9fe 100644 (file)
@@ -187,14 +187,14 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index)
 }
 
 static const char *
-list_callback(unsigned idx, int *highlight, G_GNUC_UNUSED void *data)
+list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
 {
        static char buf[BUFSIZE];
 
        if (subcmd < 0) {
                if (idx < (unsigned)command_list_length) {
                        if (cmds[idx].flags & COMMAND_KEY_CONFLICT)
-                               *highlight = 1;
+                               *highlight = true;
                        return cmds[idx].name;
                } else if (idx == LIST_ITEM_APPLY())
                        return LIST_ITEM_APPLY_LABEL;
index 93a47cc8d3f3bae0b3a45094c5e7f7aa225e4a61..d54333d0cb2b20cf412de6baadc2821eaeaf0021 100644 (file)
@@ -223,7 +223,7 @@ static int store_lyr_hd(void)
 }
 
 static const char *
-list_callback(unsigned idx, G_GNUC_UNUSED int *highlight,
+list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
              G_GNUC_UNUSED void *data)
 {
        static char buffer[256];
index 525207618e7c3a976b388f27c080bbe0f8bd7175..7ee0a9ff487817967d9957e100eab7111a553bbc 100644 (file)
@@ -90,7 +90,7 @@ playlist_changed_callback(mpdclient_t *c, int event, gpointer data)
 }
 
 static const char *
-list_callback(unsigned idx, int *highlight, G_GNUC_UNUSED void *data)
+list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
 {
        static char songname[MAX_SONG_LENGTH];
 #ifndef NCMPC_MINI
@@ -103,7 +103,7 @@ list_callback(unsigned idx, int *highlight, G_GNUC_UNUSED void *data)
 
        song = playlist_get(playlist, idx);
        if (song->id == current_song_id)
-               *highlight = 1;
+               *highlight = true;
 
        strfsong(songname, MAX_SONG_LENGTH, options.list_format, song);
 
index 83054123d9a190d5eb0349456b861d45d93aed7c..3c0a18bf9ee6d6ad3afafbe59dee7008267e1427 100644 (file)
@@ -93,7 +93,7 @@ static struct screen_browser browser;
 
 /* search info */
 static const char *
-lw_search_help_callback(unsigned idx, G_GNUC_UNUSED int *highlight,
+lw_search_help_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
                        G_GNUC_UNUSED void *data)
 {
        unsigned text_rows;
index bda200ad74f9f645f98fbf1a265094c141132d55..2c73ea6f5ff5c436a6e3b875cd7f9dcbac67c7c0 100644 (file)
@@ -56,7 +56,7 @@ screen_song_repaint(void)
 }
 
 static const char *
-screen_song_list_callback(unsigned idx, G_GNUC_UNUSED int *highlight,
+screen_song_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
                          G_GNUC_UNUSED void *data)
 {
        static char buffer[256];
index ff3fffa44ce66961ea14cc2bb1d015729e78cf89..20b4be1a408cd71eb0f6533d065c63be738397f3 100644 (file)
@@ -159,7 +159,7 @@ screen_find(list_window_t *lw,
            void *callback_data)
 {
        int reversed = 0;
-       int retval = 0;
+       bool found;
        const char *prompt = FIND_PROMPT;
        char *value = options.find_show_last_pattern ? (char *) -1 : NULL;
 
@@ -189,21 +189,17 @@ screen_find(list_window_t *lw,
                if (screen.findbuf == NULL)
                        return 1;
 
-               if (reversed)
-                       retval = list_window_rfind(lw,
-                                                  callback_fn,
-                                                  callback_data,
-                                                  screen.findbuf,
-                                                  options.find_wrap,
-                                                  rows);
-               else
-                       retval = list_window_find(lw,
-                                                 callback_fn,
-                                                 callback_data,
-                                                 screen.findbuf,
-                                                 options.find_wrap);
-
-               if (retval != 0) {
+               found = reversed
+                       ? list_window_rfind(lw,
+                                           callback_fn, callback_data,
+                                           screen.findbuf,
+                                           options.find_wrap,
+                                           rows)
+                       : list_window_find(lw,
+                                          callback_fn, callback_data,
+                                          screen.findbuf,
+                                          options.find_wrap);
+               if (!found) {
                        screen_status_printf(_("Unable to find \'%s\'"),
                                             screen.findbuf);
                        screen_bell();