Code

update copyright year
[ncmpc.git] / src / screen_search.c
index 5e9226e6cff234246638f1121bf1c15447ae2860..90e075fe96c95d2da9469a74c5bb5ac421d0b997 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -58,13 +58,11 @@ static const struct {
 static int
 search_get_tag_id(const char *name)
 {
-       unsigned i;
-
        if (g_ascii_strcasecmp(name, "file") == 0 ||
            strcasecmp(name, _("file")) == 0)
                return SEARCH_URI;
 
-       for (i = 0; i < MPD_TAG_COUNT; ++i)
+       for (unsigned i = 0; i < MPD_TAG_COUNT; ++i)
                if (search_tag[i].name != NULL &&
                    (strcasecmp(search_tag[i].name, name) == 0 ||
                     strcasecmp(search_tag[i].localname, name) == 0))
@@ -107,7 +105,7 @@ static const char *const help_text[] = {
 
 /* search info */
 static const char *
-lw_search_help_callback(unsigned idx, G_GNUC_UNUSED void *data)
+lw_search_help_callback(unsigned idx, gcc_unused void *data)
 {
        assert(idx < G_N_ELEMENTS(help_text));
 
@@ -204,23 +202,19 @@ search_simple_query(struct mpd_connection *connection, bool exact_match,
 static struct filelist *
 search_advanced_query(struct mpd_connection *connection, char *query)
 {
-       int i,j;
-       char **strv;
-       int table[10];
-       char *arg[10];
-       struct filelist *fl = NULL;
-
        advanced_search_mode = FALSE;
        if (strchr(query, ':') == NULL)
                return NULL;
 
-       strv = g_strsplit_set(query, ": ", 0);
+       char **strv = g_strsplit_set(query, ": ", 0);
 
+       int table[10];
        memset(table, 0, 10*sizeof(int));
+
+       char *arg[10];
        memset(arg, 0, 10*sizeof(char *));
 
-       i=0;
-       j=0;
+       int i = 0, j = 0;
        while (strv[i] && strlen(strv[i]) > 0 && i < 9) {
                int id = search_get_tag_id(strv[i]);
                if (id == -1) {
@@ -277,7 +271,7 @@ search_advanced_query(struct mpd_connection *connection, char *query)
        }
 
        mpd_search_commit(connection);
-       fl = filelist_new_recv(connection);
+       struct filelist *fl = filelist_new_recv(connection);
        if (!mpd_response_finish(connection)) {
                filelist_free(fl);
                fl = NULL;
@@ -293,9 +287,10 @@ static struct filelist *
 do_search(struct mpdclient *c, char *query)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct filelist *fl;
+       if (connection == NULL)
+               return NULL;
 
-       fl = search_advanced_query(connection, query);
+       struct filelist *fl = search_advanced_query(connection, query);
        if (fl != NULL)
                return fl;
 
@@ -357,6 +352,11 @@ static void
 screen_search_init(WINDOW *w, int cols, int rows)
 {
        browser.lw = list_window_init(w, cols, rows);
+       if (options.search_format != NULL) {
+               browser.song_format = options.search_format;
+       } else {
+               browser.song_format = options.list_format;
+       }
        list_window_set_length(browser.lw, G_N_ELEMENTS(help_text));
 }
 
@@ -376,13 +376,13 @@ screen_search_quit(void)
 }
 
 static void
-screen_search_open(G_GNUC_UNUSED struct mpdclient *c)
+screen_search_open(gcc_unused struct mpdclient *c)
 {
        //  if( pattern==NULL )
        //    search_new(screen, c);
        // else
        screen_status_printf(_("Press %s for a new search"),
-                            get_key_names(CMD_SCREEN_SEARCH,0));
+                            get_key_names(CMD_SCREEN_SEARCH, false));
        search_check_mode();
 }
 
@@ -416,7 +416,7 @@ screen_search_get_title(char *str, size_t size)
                           _(mode[options.search_mode].label));
        else
                g_snprintf(str, size, _("Search: Press %s for a new search [%s]"),
-                          get_key_names(CMD_SCREEN_SEARCH,0),
+                          get_key_names(CMD_SCREEN_SEARCH, false),
                           _(mode[options.search_mode].label));
 
        return str;
@@ -441,7 +441,7 @@ screen_search_cmd(struct mpdclient *c, command_t cmd)
                        options.search_mode = 0;
                screen_status_printf(_("Search mode: %s"),
                                     _(mode[options.search_mode].label));
-               /* continue and update... */
+               /* fall through */
        case CMD_SCREEN_UPDATE:
                screen_search_reload(c);
                search_repaint();