summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f7d53b7)
raw | patch | inline | side by side (parent: f7d53b7)
author | Max Kellermann <max@duempel.org> | |
Thu, 27 Nov 2008 16:56:32 +0000 (17:56 +0100) | ||
committer | Max 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".
"int".
12 files changed:
diff --git a/src/list_window.c b/src/list_window.c
index 46858ee2bb5d2862b9a16dee7fd257a536c2ec7a..b12e8eb8cff56ca1644405f7303fddc16e7ac753 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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)
}
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)
}
}
-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;
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) {
}
} 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) {
}
} 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) {
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) {
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)
{
list_window_first(lw);
else
list_window_previous_page(lw);
- return 1;
+ return true;
}
/* if the even occured below the list window move down */
list_window_last(lw, rows);
else
list_window_next_page(lw, rows);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
#endif
diff --git a/src/list_window.h b/src/list_window.h
index 11c4cddaba6d5dc3d04e4ec3d8d4b05fd81280fd..bcf3e3228913df012a59ad25ac2749d1c155869b 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
#include "command.h"
#include <glib.h>
+#include <stdbool.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#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 {
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
* 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
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
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 7180c38edd39f2d8fee3b6e7dc47c38a4cc56d0f..be951ee6ec902feafe6cf79a22d74b5848310d03 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
/* 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;
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 3aeab0b33749fff2c3b681dd5202e14f188e38cc..4d911e0d7a618368f0caa3ab0e1ffd3fff438215 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.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;
entity = entry->entity;
#ifndef NCMPC_MINI
- *highlight = (entry->flags & HIGHLIGHT);
+ *highlight = (entry->flags & HIGHLIGHT) != 0;
#else
*highlight = false;
#endif
diff --git a/src/screen_browser.h b/src/screen_browser.h
index 6ea17cc18edae90a4def5e3766d6159192a0c34d..1cc0b2744a5505dc85890e993e5b503d88fdb2be 100644 (file)
--- a/src/screen_browser.h
+++ b/src/screen_browser.h
#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,
diff --git a/src/screen_help.c b/src/screen_help.c
index 2f06adacd54499801dc99ad5754c83b5e727c2e5..0cc15a37a2e302800e6e7233b9a848005398aa38 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
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];
return NULL;
if (help_text[idx].highlight)
- *highlight = 1;
+ *highlight = true;
if (help_text[idx].command == CMD_NONE) {
if (help_text[idx].text)
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 02ef177d828cce17df35b5f707a411bcb44513db..a8f01b352ee9195d207f8985069b12ba27ebe9fe 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
}
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;
diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c
index 93a47cc8d3f3bae0b3a45094c5e7f7aa225e4a61..d54333d0cb2b20cf412de6baadc2821eaeaf0021 100644 (file)
--- a/src/screen_lyrics.c
+++ b/src/screen_lyrics.c
}
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];
diff --git a/src/screen_play.c b/src/screen_play.c
index 525207618e7c3a976b388f27c080bbe0f8bd7175..7ee0a9ff487817967d9957e100eab7111a553bbc 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
}
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
song = playlist_get(playlist, idx);
if (song->id == current_song_id)
- *highlight = 1;
+ *highlight = true;
strfsong(songname, MAX_SONG_LENGTH, options.list_format, song);
diff --git a/src/screen_search.c b/src/screen_search.c
index 83054123d9a190d5eb0349456b861d45d93aed7c..3c0a18bf9ee6d6ad3afafbe59dee7008267e1427 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
/* 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;
diff --git a/src/screen_song.c b/src/screen_song.c
index bda200ad74f9f645f98fbf1a265094c141132d55..2c73ea6f5ff5c436a6e3b875cd7f9dcbac67c7c0 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
}
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];
diff --git a/src/screen_utils.c b/src/screen_utils.c
index ff3fffa44ce66961ea14cc2bb1d015729e78cf89..20b4be1a408cd71eb0f6533d065c63be738397f3 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
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;
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();