Code

*: make variables more local
authorMax Kellermann <max@duempel.org>
Fri, 8 Nov 2013 18:52:09 +0000 (19:52 +0100)
committerMax Kellermann <max@duempel.org>
Fri, 8 Nov 2013 18:52:09 +0000 (19:52 +0100)
37 files changed:
src/charset.c
src/colors.c
src/conf.c
src/filelist.c
src/gidle.c
src/hscroll.c
src/list_window.c
src/main.c
src/match.c
src/mpdclient.c
src/options.c
src/player_command.c
src/playlist.c
src/plugin.c
src/progress_bar.c
src/screen.c
src/screen_artist.c
src/screen_browser.c
src/screen_chat.c
src/screen_client.c
src/screen_file.c
src/screen_find.c
src/screen_keydef.c
src/screen_list.c
src/screen_lyrics.c
src/screen_outputs.c
src/screen_queue.c
src/screen_search.c
src/screen_song.c
src/screen_status.c
src/screen_text.c
src/screen_utils.c
src/status_bar.c
src/strfsong.c
src/title_bar.c
src/utils.c
src/wreadln.c

index 909e77656faca5a9b18bf769271f0afa8956da3a..61d7dac70dbcbb3ef4774b34c2c0189a8a914c29 100644 (file)
@@ -123,10 +123,9 @@ wide_cut_width(char *p, unsigned max_width)
 {
        size_t length = g_utf8_strlen(p, -1);
        unsigned width = 0, prev_width;
-       gunichar c;
 
        while (length-- > 0) {
-               c = g_utf8_get_char(p);
+               gunichar c = g_utf8_get_char(p);
                prev_width = width;
                width += g_unichar_iswide(c) ? 2 : 1;
                if (width > max_width) {
@@ -162,16 +161,14 @@ char *
 utf8_to_locale(const char *utf8str)
 {
 #ifdef ENABLE_LOCALE
-       gchar *str;
-
        assert(utf8str != NULL);
 
        if (noconvert)
                return g_strdup(utf8str);
 
-       str = g_convert_with_fallback(utf8str, -1,
-                                     charset, "utf-8",
-                                     NULL, NULL, NULL, NULL);
+       gchar *str = g_convert_with_fallback(utf8str, -1,
+                                            charset, "utf-8",
+                                            NULL, NULL, NULL, NULL);
        if (str == NULL)
                return g_strdup(utf8str);
 
@@ -185,16 +182,14 @@ char *
 locale_to_utf8(const char *localestr)
 {
 #ifdef ENABLE_LOCALE
-       gchar *str;
-
        assert(localestr != NULL);
 
        if (noconvert)
                return g_strdup(localestr);
 
-       str = g_convert_with_fallback(localestr, -1,
-                                     "utf-8", charset,
-                                     NULL, NULL, NULL, NULL);
+       gchar *str = g_convert_with_fallback(localestr, -1,
+                                            "utf-8", charset,
+                                            NULL, NULL, NULL, NULL);
        if (str == NULL)
                return g_strdup(localestr);
 
index 06362623bf9fa43bc391aae339fef4851993e25c..449d372777686d5ee38acb34634ad99de77b4340 100644 (file)
@@ -72,9 +72,7 @@ static GList *color_definition_list = NULL;
 static color_entry_t *
 colors_lookup_by_name(const char *name)
 {
-       enum color i;
-
-       for (i = 1; i < COLOR_END; ++i)
+       for (enum color i = 1; i < COLOR_END; ++i)
                if (!strcasecmp(colors[i].name, name))
                        return &colors[i];
 
@@ -84,12 +82,10 @@ colors_lookup_by_name(const char *name)
 static int
 colors_update_pair(enum color id)
 {
-       int fg, bg;
-
        assert(id > 0 && id < COLOR_END);
 
-       fg = colors[id].color;
-       bg = colors[COLOR_BACKGROUND].color;
+       int fg = colors[id].color;
+       int bg = colors[COLOR_BACKGROUND].color;
 
        /* If color == COLOR_NONE (negative),
         * pass -1 to avoid cast errors */
@@ -102,9 +98,9 @@ colors_update_pair(enum color id)
 int
 colors_str2color(const char *str)
 {
-       int i, color = 0;
+       int color = 0;
        char **parts = g_strsplit(str, ",", 0);
-       for (i = 0; parts[i]; i++) {
+       for (int i = 0; parts[i]; i++) {
                char *cur = parts[i];
 
                /* Legacy colors (brightblue,etc) */
@@ -171,13 +167,13 @@ colors_str2color(const char *str)
 int
 colors_define(const char *name, short r, short g, short b)
 {
-       color_definition_entry_t *entry;
        int color = colors_str2color(name);
 
        if (color < 0)
                return color;
 
-       entry = g_malloc(sizeof(color_definition_entry_t));
+       color_definition_entry_t *entry =
+               g_malloc(sizeof(color_definition_entry_t));
        entry->color = color;
        entry->r = r;
        entry->g = g;
@@ -192,14 +188,14 @@ int
 colors_assign(const char *name, const char *value)
 {
        color_entry_t *entry = colors_lookup_by_name(name);
-       int color;
 
        if (!entry) {
                fprintf(stderr,_("Warning: Unknown color field - %s\n"), name);
                return -1;
        }
 
-       if ((color = colors_str2color(value)) == COLOR_ERROR)
+       const int color = colors_str2color(value);
+       if (color == COLOR_ERROR)
                return -1;
 
        entry->color = color;
@@ -231,9 +227,7 @@ colors_start(void)
                                _("Terminal lacks support for changing colors"));
 
                if (options.enable_colors) {
-                       enum color i;
-
-                       for (i = 1; i < COLOR_END; ++i)
+                       for (enum color i = 1; i < COLOR_END; ++i)
                                /* update the color pairs */
                                colors_update_pair(i);
                }
@@ -264,11 +258,11 @@ int
 colors_use(WINDOW *w, enum color id)
 {
        color_entry_t *entry = &colors[id];
-       short pair;
-       attr_t attrs;
 
        assert(id > 0 && id < COLOR_END);
 
+       attr_t attrs;
+       short pair;
        fix_wattr_get(w, &attrs, &pair, NULL);
 
 #ifdef ENABLE_COLORS
index 87fa51e7a05e2b356dc9118d81f09975438bb6af..83c11c5f194b6359ffdd16a202355b64e98914e8 100644 (file)
@@ -124,20 +124,17 @@ parse_key_value(char *str, char **end)
 static int
 parse_key_definition(char *str)
 {
-       char buf[MAX_LINE_LENGTH];
-       char *p;
-       size_t len = strlen(str), i;
-       int j,key;
-       int keys[MAX_COMMAND_KEYS];
-       command_t cmd;
-
        /* get the command name */
-       i=0;
-       j=0;
+       const size_t len = strlen(str);
+       size_t i = 0;
+       int j = 0;
+       char buf[MAX_LINE_LENGTH];
        memset(buf, 0, MAX_LINE_LENGTH);
        while (i < len && str[i] != '=' && !g_ascii_isspace(str[i]))
                buf[j++] = str[i++];
-       if( (cmd=get_key_command_from_name(buf)) == CMD_NONE ) {
+
+       command_t cmd = get_key_command_from_name(buf);
+       if(cmd == CMD_NONE) {
                /* the hotkey configuration contains an unknown
                   command */
                print_error(_("Unknown command"), buf);
@@ -159,8 +156,10 @@ parse_key_definition(char *str)
 
        /* parse key values */
        i = 0;
-       key = 0;
-       p = buf;
+       int key = 0;
+       char *p = buf;
+
+       int keys[MAX_COMMAND_KEYS];
        memset(keys, 0, sizeof(int)*MAX_COMMAND_KEYS);
        while (i < MAX_COMMAND_KEYS && *p != 0 &&
               (key = parse_key_value(p, &p)) >= 0) {
@@ -196,9 +195,7 @@ parse_timedisplay_type(const char *str)
 static char *
 separate_value(char *p)
 {
-       char *value;
-
-       value = strchr(p, '=');
+       char *value = strchr(p, '=');
        if (value == NULL) {
                /* an equals sign '=' was expected while parsing a
                   configuration file line */
@@ -215,9 +212,7 @@ separate_value(char *p)
 static int
 parse_color(char *str)
 {
-       char *value;
-
-       value = separate_value(str);
+       char *value = separate_value(str);
        if (value == NULL)
                return -1;
 
@@ -247,23 +242,21 @@ after_comma(char *p)
 static int
 parse_color_definition(char *str)
 {
-       char buf[MAX_LINE_LENGTH];
-       char *value;
-       short color, rgb[3];
-
-       value = separate_value(str);
+       char *value = separate_value(str);
        if (value == NULL)
                return -1;
 
        /* get the command name */
-       color = colors_str2color(str);
+       short color = colors_str2color(str);
        if (color < 0) {
+               char buf[MAX_LINE_LENGTH];
                print_error(_("Bad color name"), buf);
                return -1;
        }
 
        /* parse r,g,b values */
 
+       short rgb[3];
        for (unsigned i = 0; i < 3; ++i) {
                char *next = after_comma(value), *endptr;
                if (*value == 0) {
@@ -336,8 +329,7 @@ static int
 get_search_mode(char *value)
 {
        char * test;
-       int mode;
-       mode= strtol(value, &test, 10);
+       const int mode = strtol(value, &test, 10);
        if (*test == '\0')
        {
                if (0 <= mode && mode <= 4)
@@ -377,10 +369,9 @@ static bool
 parse_line(char *line)
 {
        size_t len = strlen(line), i = 0, j = 0;
-       char name[MAX_LINE_LENGTH];
-       char value[MAX_LINE_LENGTH];
 
        /* get the name part */
+       char name[MAX_LINE_LENGTH];
        while (i < len && line[i] != '=' && !g_ascii_isspace(line[i]))
                name[j++] = line[i++];
 
@@ -391,6 +382,7 @@ parse_line(char *line)
                i++;
 
        /* get the value part */
+       char value[MAX_LINE_LENGTH];
        j = 0;
        while (i < len)
                value[j++] = line[i++];
@@ -568,15 +560,13 @@ read_rc_file(char *filename)
 {
        assert(filename != NULL);
 
-       FILE *file;
-       char line[MAX_LINE_LENGTH];
-
-       file = fopen(filename, "r");
+       FILE *file = fopen(filename, "r");
        if (file == NULL) {
-                       perror(filename);
-                       return -1;
-               }
+               perror(filename);
+               return -1;
+       }
 
+       char line[MAX_LINE_LENGTH];
        while (fgets(line, sizeof(line), file) != NULL) {
                char *p = g_strchug(line);
 
@@ -591,7 +581,6 @@ read_rc_file(char *filename)
 int
 check_user_conf_dir(void)
 {
-       int retval;
        char *directory = g_build_filename(g_get_home_dir(), "." PACKAGE, NULL);
 
        if (g_file_test(directory, G_FILE_TEST_IS_DIR)) {
@@ -599,7 +588,7 @@ check_user_conf_dir(void)
                return 0;
        }
 
-       retval = g_mkdir(directory, 0755);
+       int retval = g_mkdir(directory, 0755);
        g_free(directory);
        return retval;
 }
index 6a5ade39a06ba90ad14fa7c64760e60141021e95..a5b7a136468874e3db6460ed3c7e78e18aa04e23 100644 (file)
@@ -38,9 +38,7 @@ filelist_new(void)
 void
 filelist_free(struct filelist *filelist)
 {
-       guint i;
-
-       for (i = 0; i < filelist_length(filelist); ++i) {
+       for (unsigned i = 0; i < filelist_length(filelist); ++i) {
                struct filelist_entry *entry = filelist_get(filelist, i);
 
                if (entry->entity)
@@ -69,9 +67,7 @@ filelist_append(struct filelist *filelist, struct mpd_entity *entity)
 void
 filelist_move(struct filelist *filelist, struct filelist *from)
 {
-       guint i;
-
-       for (i = 0; i < filelist_length(from); ++i)
+       for (unsigned i = 0; i < filelist_length(from); ++i)
                g_ptr_array_add(filelist->entries,
                                g_ptr_array_index(from->entries, i));
 
@@ -93,11 +89,11 @@ compare_filelist_entry_path(gconstpointer filelist_entry1,
                            gconstpointer filelist_entry2)
 {
        const struct mpd_entity *e1, *e2;
-       int n = 0;
 
        e1 = ((const struct filelist_entry *)filelist_entry1)->entity;
        e2 = ((const struct filelist_entry *)filelist_entry2)->entity;
 
+       int n = 0;
        if (e1 != NULL && e2 != NULL &&
            mpd_entity_get_type(e1) == mpd_entity_get_type(e2)) {
                switch (mpd_entity_get_type(e1)) {
@@ -132,7 +128,6 @@ filelist_sort_all(struct filelist *filelist, GCompareFunc compare_func)
 void
 filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func)
 {
-       unsigned first, last;
        const struct mpd_entity *iter;
 
        assert(filelist && filelist->entries);
@@ -142,7 +137,7 @@ filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func)
 
        /* If the first entry is NULL, skip it, because NULL stands for "[..]" */
        iter = ((struct filelist_entry*) g_ptr_array_index(filelist->entries, 0))->entity;
-       first = (iter == NULL)? 1 : 0;
+       unsigned first = iter == NULL ? 1 : 0, last;
 
        /* find the last directory entry */
        for (last = first+1; last < filelist->entries->len; last++) {
@@ -199,11 +194,9 @@ same_song(const struct mpd_song *a, const struct mpd_song *b)
 int
 filelist_find_song(const struct filelist *fl, const struct mpd_song *song)
 {
-       guint i;
-
        assert(song != NULL);
 
-       for (i = 0; i < filelist_length(fl); ++i) {
+       for (unsigned i = 0; i < filelist_length(fl); ++i) {
                struct filelist_entry *entry = filelist_get(fl, i);
                const struct mpd_entity *entity  = entry->entity;
 
@@ -223,11 +216,9 @@ filelist_find_song(const struct filelist *fl, const struct mpd_song *song)
 int
 filelist_find_directory(const struct filelist *filelist, const char *name)
 {
-       guint i;
-
        assert(name != NULL);
 
-       for (i = 0; i < filelist_length(filelist); ++i) {
+       for (unsigned i = 0; i < filelist_length(filelist); ++i) {
                struct filelist_entry *entry = filelist_get(filelist, i);
                const struct mpd_entity *entity  = entry->entity;
 
index 95ac64621aea80b26070b9470e0415dbe88f01d1..ca07fefbaf34a457c053f66d597797e06fd946c8 100644 (file)
@@ -247,11 +247,8 @@ static bool
 mpd_glib_recv(struct mpd_glib_source *source)
 {
        char *line;
-       bool success;
-
        while ((line = mpd_async_recv_line(source->async)) != NULL) {
-               success = mpd_glib_feed(source, line);
-               if (!success)
+               if (!mpd_glib_feed(source, line))
                        return false;
        }
 
@@ -271,17 +268,14 @@ mpd_glib_source_callback(gcc_unused GIOChannel *_source,
                         GIOCondition condition, gpointer data)
 {
        struct mpd_glib_source *source = data;
-       bool success;
-       enum mpd_async_event events;
 
        assert(source->id != 0);
        assert(source->io_events != 0);
 
        /* let libmpdclient do some I/O */
 
-       success = mpd_async_io(source->async,
-                              g_io_condition_to_mpd_async_event(condition));
-       if (!success) {
+       if (!mpd_async_io(source->async,
+                         g_io_condition_to_mpd_async_event(condition))) {
                source->id = 0;
                source->io_events = 0;
 
@@ -292,14 +286,13 @@ mpd_glib_source_callback(gcc_unused GIOChannel *_source,
        /* receive the response */
 
        if ((condition & G_IO_IN) != 0) {
-               success = mpd_glib_recv(source);
-               if (!success)
+               if (!mpd_glib_recv(source))
                        return false;
        }
 
        /* continue polling? */
 
-       events = mpd_async_events(source->async);
+       enum mpd_async_event events = mpd_async_events(source->async);
        if (events == 0) {
                /* no events - disable watch */
                source->id = 0;
@@ -326,13 +319,11 @@ static void
 mpd_glib_add_watch(struct mpd_glib_source *source)
 {
        enum mpd_async_event events = mpd_async_events(source->async);
-       GIOCondition condition;
 
        assert(source->io_events == 0);
        assert(source->id == 0);
 
-       condition = mpd_async_events_to_g_io_condition(events);
-
+       GIOCondition condition = mpd_async_events_to_g_io_condition(events);
        source->id = g_io_add_watch(source->channel, condition,
                                    mpd_glib_source_callback, source);
        source->io_events = events;
@@ -341,8 +332,6 @@ mpd_glib_add_watch(struct mpd_glib_source *source)
 bool
 mpd_glib_enter(struct mpd_glib_source *source)
 {
-       bool success;
-
        assert(source->io_events == 0);
        assert(source->id == 0);
        assert(!source->destroyed);
@@ -352,8 +341,7 @@ mpd_glib_enter(struct mpd_glib_source *source)
 
        source->idle_events = 0;
 
-       success = mpd_async_send_command(source->async, "idle", NULL);
-       if (!success) {
+       if (!mpd_async_send_command(source->async, "idle", NULL)) {
                mpd_glib_invoke_async_error(source);
                return false;
        }
@@ -365,8 +353,6 @@ mpd_glib_enter(struct mpd_glib_source *source)
 bool
 mpd_glib_leave(struct mpd_glib_source *source)
 {
-       enum mpd_idle events;
-
        assert(!source->destroyed);
 
        if (source->id == 0)
@@ -377,7 +363,7 @@ mpd_glib_leave(struct mpd_glib_source *source)
        source->id = 0;
        source->io_events = 0;
 
-       events = source->idle_events == 0
+       enum mpd_idle events = source->idle_events == 0
                ? mpd_run_noidle(source->connection)
                : mpd_recv_idle(source->connection, false);
 
index cc2aa9c430e4a37262441d363ec4c3b9216ce302..72f6a5d2255ec87a4daf71d1020397182639c9e6 100644 (file)
@@ -28,21 +28,18 @@ char *
 strscroll(struct hscroll *hscroll, const char *str, const char *separator,
          unsigned width)
 {
-       gchar *tmp, *buf;
-
        assert(hscroll != NULL);
        assert(str != NULL);
        assert(separator != NULL);
 
        /* create a buffer containing the string and the separator */
-       tmp = replace_locale_to_utf8(g_strconcat(str, separator,
-                                                str, separator, NULL));
-
+       char *tmp = replace_locale_to_utf8(g_strconcat(str, separator,
+                                                      str, separator, NULL));
        if (hscroll->offset >= (unsigned)g_utf8_strlen(tmp, -1) / 2)
                hscroll->offset = 0;
 
        /* create the new scrolled string */
-       buf = g_utf8_offset_to_pointer(tmp, hscroll->offset);
+       char *buf = g_utf8_offset_to_pointer(tmp, hscroll->offset);
        utf8_cut_width(buf, width);
 
        /* convert back to locale */
@@ -112,21 +109,19 @@ hscroll_clear(struct hscroll *hscroll)
 void
 hscroll_draw(struct hscroll *hscroll)
 {
-       attr_t old_attrs;
-       short old_pair;
-       char *p;
-
        assert(hscroll != NULL);
        assert(hscroll->w != NULL);
        assert(hscroll->text != NULL);
 
        /* set stored attributes and color */
+       attr_t old_attrs;
+       short old_pair;
        fix_wattr_get(hscroll->w, &old_attrs, &old_pair, NULL);
        wattr_set(hscroll->w, hscroll->attrs, hscroll->pair, NULL);
 
        /* scroll the string, and draw it */
-       p = strscroll(hscroll, hscroll->text, hscroll->separator,
-                     hscroll->width);
+       char *p = strscroll(hscroll, hscroll->text, hscroll->separator,
+                           hscroll->width);
        mvwaddstr(hscroll->w, hscroll->y, hscroll->x, p);
        g_free(p);
 
index ad2ae77cc1f588b7e691d17b2079756f148dda62..387b7766b4f2d1fdfa3ad6855b049a5cd3ae6a06 100644 (file)
@@ -351,8 +351,6 @@ list_window_paint(const struct list_window *lw,
                list_window_get_range(lw, &range);
 
        for (unsigned i = 0; i < lw->rows; i++) {
-               const char *label;
-
                wmove(lw->w, i, 0);
 
                if (lw->start + i >= lw->length) {
@@ -360,7 +358,7 @@ list_window_paint(const struct list_window *lw,
                        break;
                }
 
-               label = callback(lw->start + i, callback_data);
+               const char *label = callback(lw->start + i, callback_data);
                assert(label != NULL);
 
                list_window_paint_row(lw->w, lw->cols,
@@ -392,8 +390,6 @@ list_window_paint2(const struct list_window *lw,
                list_window_get_range(lw, &range);
 
        for (unsigned i = 0; i < lw->rows; i++) {
-               bool selected;
-
                wmove(lw->w, i, 0);
 
                if (lw->start + i >= lw->length) {
@@ -401,7 +397,7 @@ list_window_paint2(const struct list_window *lw,
                        break;
                }
 
-               selected = show_cursor &&
+               bool selected = show_cursor &&
                        lw->start + i >= range.start &&
                        lw->start + i < range.end;
 
@@ -425,13 +421,12 @@ list_window_find(struct list_window *lw,
                 bool bell_on_wrap)
 {
        unsigned i = lw->selected + 1;
-       const char *label;
 
        assert(str != NULL);
 
        do {
                while (i < lw->length) {
-                       label = callback(i, callback_data);
+                       const char *label = callback(i, callback_data);
                        assert(label != NULL);
 
                        if (match_line(label, str)) {
@@ -464,7 +459,6 @@ list_window_rfind(struct list_window *lw,
                  bool bell_on_wrap)
 {
        int i = lw->selected - 1;
-       const char *label;
 
        assert(str != NULL);
 
@@ -473,7 +467,7 @@ list_window_rfind(struct list_window *lw,
 
        do {
                while (i >= 0) {
-                       label = callback(i, callback_data);
+                       const char *label = callback(i, callback_data);
                        assert(label != NULL);
 
                        if (match_line(label, str)) {
@@ -502,13 +496,10 @@ list_window_jump(struct list_window *lw,
                 void *callback_data,
                 const char *str)
 {
-       unsigned i;
-       const char *label;
-
        assert(str != NULL);
 
-       for (i = 0; i < lw->length; i++) {
-               label = callback(i, callback_data);
+       for (unsigned i = 0; i < lw->length; i++) {
+               const char *label = callback(i, callback_data);
                assert(label != NULL);
 
                if (g_ascii_strncasecmp(label, str, strlen(str)) == 0) {
@@ -525,18 +516,14 @@ list_window_jump(struct list_window *lw,
                 void *callback_data,
                 const char *str)
 {
-       unsigned i;
-       const char *label;
-       GRegex *regex;
-
        assert(str != NULL);
 
-       regex = compile_regex(str, options.jump_prefix_only);
+       GRegex *regex = compile_regex(str, options.jump_prefix_only);
        if (regex == NULL)
                return false;
 
-       for (i = 0; i < lw->length; i++) {
-               label = callback(i, callback_data);
+       for (unsigned i = 0; i < lw->length; i++) {
+               const char *label = callback(i, callback_data);
                assert(label != NULL);
 
                if (match_regex(regex, label)) {
index d49d40beaac10c8a871c45d4b646ce4231eccf86..6d0633e82d3f2a1f6e2fe87e933b6bc13fa08e12 100644 (file)
@@ -75,7 +75,6 @@ static void
 update_xterm_title(void)
 {
        static char title[BUFSIZE];
-       char tmp[BUFSIZE];
        struct mpd_status *status = NULL;
        const struct mpd_song *song = NULL;
 
@@ -84,6 +83,7 @@ update_xterm_title(void)
                song = mpd->song;
        }
 
+       char tmp[BUFSIZE];
        if (options.xterm_title_format && status && song &&
            mpd_status_get_state(status) == MPD_STATE_PLAY)
                strfsong(tmp, BUFSIZE, options.xterm_title_format, song);
@@ -287,9 +287,6 @@ default_settings_name(void)
 static gboolean
 timer_reconnect(gcc_unused gpointer data)
 {
-       bool success;
-       struct mpd_connection *connection;
-
        assert(!mpdclient_is_connected(mpd));
 
        reconnect_source_id = 0;
@@ -301,18 +298,16 @@ timer_reconnect(gcc_unused gpointer data)
        doupdate();
 
        mpdclient_disconnect(mpd);
-       success = mpdclient_connect(mpd,
-                                   options.host, options.port,
-                                   options.timeout_ms,
-                                   options.password);
-       if (!success) {
+       if (!mpdclient_connect(mpd, options.host, options.port,
+                              options.timeout_ms,
+                              options.password)) {
                /* try again in 5 seconds */
                reconnect_source_id = g_timeout_add(5000,
                                                    timer_reconnect, NULL);
                return FALSE;
        }
 
-       connection = mpdclient_get_connection(mpd);
+       struct mpd_connection *connection = mpdclient_get_connection(mpd);
 
 #ifndef NCMPC_MINI
        /* quit if mpd is pre 0.14 - song id not supported by mpd */
@@ -465,11 +460,10 @@ keyboard_event(gcc_unused GIOChannel *source,
               gcc_unused GIOCondition condition,
               gcc_unused gpointer data)
 {
-       command_t cmd;
-
        begin_input_event();
 
-       if ((cmd=get_keyboard_command()) != CMD_NONE)
+       command_t cmd = get_keyboard_command();
+       if (cmd != CMD_NONE)
                if (do_input_event(cmd) != 0)
                        return FALSE;
 
@@ -521,23 +515,11 @@ timer_check_key_bindings(gcc_unused gpointer data)
 int
 main(int argc, const char *argv[])
 {
-#ifndef WIN32
-       struct sigaction act;
-#endif
 #ifdef ENABLE_LOCALE
 #ifndef ENABLE_NLS
        gcc_unused
 #endif
        const char *charset = NULL;
-#endif
-       GIOChannel *keyboard_channel;
-#ifdef ENABLE_LIRC
-       int lirc_socket;
-       GIOChannel *lirc_channel = NULL;
-#endif
-       GIOChannel *sigwinch_channel = NULL;
-
-#ifdef ENABLE_LOCALE
        /* time and date formatting */
        setlocale(LC_TIME,"");
        /* care about sorting order etc */
@@ -578,6 +560,7 @@ main(int argc, const char *argv[])
 
 #ifndef WIN32
        /* setup signal behavior - SIGINT */
+       struct sigaction act;
        sigemptyset(&act.sa_mask);
        act.sa_flags = 0;
        act.sa_handler = catch_sigint;
@@ -644,12 +627,13 @@ main(int argc, const char *argv[])
        main_loop = g_main_loop_new(NULL, FALSE);
 
        /* watch out for keyboard input */
-       keyboard_channel = g_io_channel_unix_new(STDIN_FILENO);
+       GIOChannel *keyboard_channel = g_io_channel_unix_new(STDIN_FILENO);
        g_io_add_watch(keyboard_channel, G_IO_IN, keyboard_event, NULL);
 
 #ifdef ENABLE_LIRC
        /* watch out for lirc input */
-       lirc_socket = ncmpc_lirc_open();
+       int lirc_socket = ncmpc_lirc_open();
+       GIOChannel *lirc_channel = NULL;
        if (lirc_socket >= 0) {
                lirc_channel = g_io_channel_unix_new(lirc_socket);
                g_io_add_watch(lirc_channel, G_IO_IN, lirc_event, NULL);
@@ -657,6 +641,7 @@ main(int argc, const char *argv[])
 #endif
 
 #ifndef WIN32
+       GIOChannel *sigwinch_channel = NULL;
        if (!pipe(sigwinch_pipes) &&
                !fcntl(sigwinch_pipes[1], F_SETFL, O_NONBLOCK)) {
                sigwinch_channel = g_io_channel_unix_new(sigwinch_pipes[0]);
index 81a70f7f7d48fcd137434a82febec112880fa401..03b806d5abe76b066ac49c4672c41ed466400525 100644 (file)
@@ -37,15 +37,14 @@ locale_casefold(const char *src)
 GRegex *
 compile_regex(const char *src, bool anchor)
 {
-       GRegex *regex;
-       GRegexCompileFlags compile_flags;
-       char *src_folded = locale_casefold(src);
-
-       compile_flags = G_REGEX_CASELESS | G_REGEX_DOTALL | G_REGEX_OPTIMIZE;
+       GRegexCompileFlags compile_flags =
+               G_REGEX_CASELESS | G_REGEX_DOTALL | G_REGEX_OPTIMIZE;
        if (anchor)
                compile_flags |= G_REGEX_ANCHORED;
 
-       regex = g_regex_new ((const gchar*)src_folded, compile_flags, 0, NULL);
+       char *src_folded = locale_casefold(src);
+       GRegex *regex = g_regex_new ((const gchar*)src_folded, compile_flags,
+                                    0, NULL);
 
        g_free(src_folded);
 
@@ -55,12 +54,10 @@ compile_regex(const char *src, bool anchor)
 bool
 match_regex(GRegex *regex, const char *line)
 {
-       GMatchInfo *match_info;
-       bool match;
        char *line_folded = locale_casefold(line);
-
+       GMatchInfo *match_info;
        g_regex_match(regex, line_folded, 0, &match_info);
-       match = (bool)g_match_info_matches(match_info);
+       bool match = (bool)g_match_info_matches(match_info);
 
        g_match_info_free(match_info);
        g_free(line_folded);
index 359a765119f8045d877d48a6bedce252ced4a39d..9baf70bc7134fa8d2125f4ff463660052eb3ff82 100644 (file)
@@ -40,16 +40,16 @@ gint
 compare_filelistentry_format(gconstpointer filelist_entry1,
                             gconstpointer filelist_entry2)
 {
-       const struct mpd_entity *e1, *e2;
-       char key1[BUFSIZE], key2[BUFSIZE];
-       int n = 0;
-
-       e1 = ((const struct filelist_entry *)filelist_entry1)->entity;
-       e2 = ((const struct filelist_entry *)filelist_entry2)->entity;
+       const struct mpd_entity *e1 =
+               ((const struct filelist_entry *)filelist_entry1)->entity;
+       const struct mpd_entity *e2 =
+               ((const struct filelist_entry *)filelist_entry2)->entity;
 
+       int n = 0;
        if (e1 && e2 &&
            mpd_entity_get_type(e1) == MPD_ENTITY_TYPE_SONG &&
            mpd_entity_get_type(e2) == MPD_ENTITY_TYPE_SONG) {
+               char key1[BUFSIZE], key2[BUFSIZE];
                strfsong(key1, BUFSIZE, options.list_format, mpd_entity_get_song(e1));
                strfsong(key2, BUFSIZE, options.list_format, mpd_entity_get_song(e2));
                n = strcmp(key1,key2);
@@ -86,9 +86,7 @@ mpdclient_handle_error(struct mpdclient *c)
 struct mpdclient *
 mpdclient_new(void)
 {
-       struct mpdclient *c;
-
-       c = g_new0(struct mpdclient, 1);
+       struct mpdclient *c = g_new0(struct mpdclient, 1);
        playlist_init(&c->playlist);
        c->volume = -1;
        c->events = 0;
@@ -256,11 +254,9 @@ mpdclient_put_connection(struct mpdclient *c)
 static struct mpd_status *
 mpdclient_recv_status(struct mpdclient *c)
 {
-       struct mpd_status *status;
-
        assert(c->connection != NULL);
 
-       status = mpd_recv_status(c->connection);
+       struct mpd_status *status = mpd_recv_status(c->connection);
        if (status == NULL) {
                mpdclient_handle_error(c);
                return NULL;
@@ -278,18 +274,15 @@ mpdclient_recv_status(struct mpdclient *c)
 bool
 mpdclient_cmd_crop(struct mpdclient *c)
 {
-       struct mpd_connection *connection;
-       int length, current;
-
        if (!mpdclient_is_playing(c))
                return false;
 
-       length = mpd_status_get_queue_length(c->status);
-       current = mpd_status_get_song_pos(c->status);
+       int length = mpd_status_get_queue_length(c->status);
+       int current = mpd_status_get_song_pos(c->status);
        if (current < 0 || mpd_status_get_queue_length(c->status) < 2)
                return true;
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return false;
 
@@ -309,8 +302,6 @@ bool
 mpdclient_cmd_clear(struct mpdclient *c)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct mpd_status *status;
-
        if (connection == NULL)
                return false;
 
@@ -323,7 +314,7 @@ mpdclient_cmd_clear(struct mpdclient *c)
 
        /* receive the new status, store it in the mpdclient struct */
 
-       status = mpdclient_recv_status(c);
+       struct mpd_status *status = mpdclient_recv_status(c);
        if (status == NULL)
                return false;
 
@@ -409,13 +400,10 @@ mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path_utf8)
 bool
 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song)
 {
-       struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct mpd_status *status;
-       struct mpd_song *new_song;
-
        assert(c != NULL);
        assert(song != NULL);
 
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL || c->status == NULL)
                return false;
 
@@ -434,14 +422,14 @@ mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song)
 
        c->events |= MPD_IDLE_QUEUE;
 
-       status = mpdclient_recv_status(c);
+       struct mpd_status *status = mpdclient_recv_status(c);
        if (status == NULL)
                return false;
 
        if (!mpd_response_next(connection))
                return mpdclient_handle_error(c);
 
-       new_song = mpd_recv_song(connection);
+       struct mpd_song *new_song = mpd_recv_song(connection);
        if (!mpd_response_finish(connection) || new_song == NULL) {
                if (new_song != NULL)
                        mpd_song_free(new_song);
@@ -471,8 +459,6 @@ bool
 mpdclient_cmd_delete(struct mpdclient *c, gint idx)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       const struct mpd_song *song;
-       struct mpd_status *status;
 
        if (connection == NULL || c->status == NULL)
                return false;
@@ -480,7 +466,7 @@ mpdclient_cmd_delete(struct mpdclient *c, gint idx)
        if (idx < 0 || (guint)idx >= playlist_length(&c->playlist))
                return false;
 
-       song = playlist_get(&c->playlist, idx);
+       const struct mpd_song *song = playlist_get(&c->playlist, idx);
 
        /* send the delete command to mpd; at the same time, get the
           new status (to verify the playlist id) */
@@ -493,7 +479,7 @@ mpdclient_cmd_delete(struct mpdclient *c, gint idx)
 
        c->events |= MPD_IDLE_QUEUE;
 
-       status = mpdclient_recv_status(c);
+       struct mpd_status *status = mpdclient_recv_status(c);
        if (status == NULL)
                return false;
 
@@ -521,15 +507,12 @@ mpdclient_cmd_delete(struct mpdclient *c, gint idx)
 bool
 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
 {
-       struct mpd_connection *connection;
-       struct mpd_status *status;
-
        if (end == start + 1)
                /* if that's not really a range, we choose to use the
                   safer "deleteid" version */
                return mpdclient_cmd_delete(c, start);
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return false;
 
@@ -544,7 +527,7 @@ mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
 
        c->events |= MPD_IDLE_QUEUE;
 
-       status = mpdclient_recv_status(c);
+       struct mpd_status *status = mpdclient_recv_status(c);
        if (status == NULL)
                return false;
 
@@ -576,13 +559,10 @@ mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
 bool
 mpdclient_cmd_move(struct mpdclient *c, unsigned dest_pos, unsigned src_pos)
 {
-       struct mpd_connection *connection;
-       struct mpd_status *status;
-
        if (dest_pos == src_pos)
                return true;
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return false;
 
@@ -597,7 +577,7 @@ mpdclient_cmd_move(struct mpdclient *c, unsigned dest_pos, unsigned src_pos)
 
        c->events |= MPD_IDLE_QUEUE;
 
-       status = mpdclient_recv_status(c);
+       struct mpd_status *status = mpdclient_recv_status(c);
        if (status == NULL)
                return false;
 
@@ -698,14 +678,14 @@ bool
 mpdclient_playlist_update(struct mpdclient *c)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct mpd_entity *entity;
-
        if (connection == NULL)
                return false;
 
        playlist_clear(&c->playlist);
 
        mpd_send_list_queue_meta(connection);
+
+       struct mpd_entity *entity;
        while ((entity = mpd_recv_entity(connection))) {
                if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG)
                        playlist_append(&c->playlist, mpd_entity_get_song(entity));
@@ -724,14 +704,13 @@ bool
 mpdclient_playlist_update_changes(struct mpdclient *c)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct mpd_song *song;
-       guint length;
 
        if (connection == NULL)
                return false;
 
        mpd_send_queue_changes_meta(connection, c->playlist.version);
 
+       struct mpd_song *song;
        while ((song = mpd_recv_song(connection)) != NULL) {
                int pos = mpd_song_get_pos(song);
 
@@ -748,7 +727,7 @@ mpdclient_playlist_update_changes(struct mpdclient *c)
 
        /* remove trailing songs */
 
-       length = mpd_status_get_queue_length(c->status);
+       unsigned length = mpd_status_get_queue_length(c->status);
        while (length < c->playlist.list->len) {
                guint pos = c->playlist.list->len - 1;
 
@@ -771,8 +750,6 @@ bool
 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       guint i;
-
        if (connection == NULL)
                return false;
 
@@ -781,7 +758,7 @@ mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl)
 
        mpd_command_list_begin(connection, false);
 
-       for (i = 0; i < filelist_length(fl); ++i) {
+       for (unsigned i = 0; i < filelist_length(fl); ++i) {
                struct filelist_entry *entry = filelist_get(fl, i);
                struct mpd_entity *entity  = entry->entity;
 
index 6f674c6cd61b9d3736dfd27ebfd87d2ea224813b..0a453e23a51ea403885a878782208ddac6b70506 100644 (file)
@@ -134,11 +134,9 @@ option_error(int error, const char *option, const char *arg)
 static void
 display_help(void)
 {
-       unsigned i;
-
        printf("Usage: %s [OPTION]...\n", PACKAGE);
 
-       for (i = 0; i < option_table_size; ++i) {
+       for (unsigned i = 0; i < option_table_size; ++i) {
                char tmp[32];
 
                if (option_table[i].argument)
@@ -295,11 +293,10 @@ handle_option(int c, const char *arg)
 void
 options_parse(int argc, const char *argv[])
 {
-       int i;
        const arg_opt_t *opt = NULL;
        option_callback_fn_t option_cb = handle_option;
 
-       for (i = 1; i < argc; i++) {
+       for (int i = 1; i < argc; i++) {
                const char *arg = argv[i];
                size_t len = strlen(arg);
 
index 9969d12257a81575879bbbc30ce9389b68d3af82..d4ff4ae280830e749adee8f1ce6ae01aaffc093f 100644 (file)
@@ -32,12 +32,10 @@ static guint seek_source_id;
 static void
 commit_seek(struct mpdclient *c)
 {
-       struct mpd_connection *connection;
-
        if (seek_id < 0)
                return;
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL) {
                seek_id = -1;
                return;
@@ -101,14 +99,14 @@ setup_seek(struct mpdclient *c)
 bool
 handle_player_command(struct mpdclient *c, command_t cmd)
 {
-       struct mpd_connection *connection;
-
        if (!mpdclient_is_connected(c) || c->status == NULL)
                return false;
 
        cancel_seek_timer();
 
        switch(cmd) {
+               struct mpd_connection *connection;
+
                /*
        case CMD_PLAY:
                mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
index 8ec007be47d27b2ff61e0dc735aae805eba1e767..6f452a8f1c6c7a202fe343601a54624e8ad33240 100644 (file)
@@ -31,11 +31,9 @@ playlist_init(struct mpdclient_playlist *playlist)
 void
 playlist_clear(struct mpdclient_playlist *playlist)
 {
-       guint i;
-
        playlist->version = 0;
 
-       for (i = 0; i < playlist->list->len; ++i) {
+       for (unsigned i = 0; i < playlist->list->len; ++i) {
                struct mpd_song *song = playlist_get(playlist, i);
 
                mpd_song_free(song);
@@ -69,14 +67,12 @@ void
 playlist_move(struct mpdclient_playlist *playlist,
              unsigned dest, unsigned src)
 {
-       struct mpd_song *song;
-
        assert(playlist != NULL);
        assert(src < playlist_length(playlist));
        assert(dest < playlist_length(playlist));
        assert(src != dest);
 
-       song = playlist_get(playlist, src);
+       struct mpd_song *song = playlist_get(playlist, src);
 
        if (src < dest) {
                memmove(&playlist->list->pdata[src],
index 29e4ffcd1a47a39dca5ec89c7fac6c1a9ac4648a..64e61ab73d2b1c31ade1bce65fcd8c5cf3664083 100644 (file)
@@ -72,11 +72,8 @@ struct plugin_cycle {
 static bool
 register_plugin(struct plugin_list *list, char *path)
 {
-       int ret;
        struct stat st;
-
-       ret = stat(path, &st);
-       if (ret < 0)
+       if (stat(path, &st) < 0)
                return false;
 
        g_ptr_array_add(list->plugins, path);
@@ -99,19 +96,14 @@ plugin_list_sort(struct plugin_list *list, GCompareFunc compare_func)
 bool
 plugin_list_load_directory(struct plugin_list *list, const char *path)
 {
-       GDir *dir;
-       const char *name;
-       char *plugin;
-       bool ret;
-
-       dir = g_dir_open(path, 0, NULL);
+       GDir *dir = g_dir_open(path, 0, NULL);
        if (dir == NULL)
                return false;
 
+       const char *name;
        while ((name = g_dir_read_name(dir)) != NULL) {
-               plugin = g_build_filename(path, name, NULL);
-               ret = register_plugin(list, plugin);
-               if (!ret)
+               char *plugin = g_build_filename(path, name, NULL);
+               if (!register_plugin(list, plugin))
                        g_free(plugin);
        }
 
@@ -135,8 +127,6 @@ next_plugin(struct plugin_cycle *cycle);
 static void
 plugin_eof(struct plugin_cycle *cycle, struct plugin_pipe *p)
 {
-       int ret, status;
-
        g_io_channel_unref(p->channel);
        close(p->fd);
        p->fd = -1;
@@ -145,7 +135,7 @@ plugin_eof(struct plugin_cycle *cycle, struct plugin_pipe *p)
        if (cycle->pipe_stdout.fd != -1 || cycle->pipe_stderr.fd != -1)
                return;
 
-       ret = waitpid(cycle->pid, &status, 0);
+       int status, ret = waitpid(cycle->pid, &status, 0);
        cycle->pid = -1;
 
        if (ret < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@@ -178,12 +168,10 @@ plugin_data(gcc_unused GIOChannel *source,
            gcc_unused GIOCondition condition, gpointer data)
 {
        struct plugin_cycle *cycle = data;
-       struct plugin_pipe *p = NULL;
-       char buffer[256];
-       ssize_t nbytes;
-
        assert(cycle != NULL);
        assert(cycle->pid > 0);
+
+       struct plugin_pipe *p = NULL;
        if (source == cycle->pipe_stdout.channel)
                p = &cycle->pipe_stdout;
        else if (source == cycle->pipe_stderr.channel)
@@ -191,7 +179,10 @@ plugin_data(gcc_unused GIOChannel *source,
        assert(p != NULL);
        assert(p->fd >= 0);
 
-       nbytes = condition & G_IO_IN ? read(p->fd, buffer, sizeof(buffer)) : 0;
+       char buffer[256];
+       ssize_t nbytes = condition & G_IO_IN
+               ? read(p->fd, buffer, sizeof(buffer))
+               : 0;
        if (nbytes <= 0) {
                plugin_eof(cycle, p);
                return FALSE;
@@ -236,9 +227,6 @@ plugin_fd_add(struct plugin_cycle *cycle, struct plugin_pipe *p, int fd)
 static int
 start_plugin(struct plugin_cycle *cycle, const char *plugin_path)
 {
-       int ret, fds_stdout[2], fds_stderr[2];
-       pid_t pid;
-
        assert(cycle != NULL);
        assert(cycle->pid < 0);
        assert(cycle->pipe_stdout.fd < 0);
@@ -251,17 +239,18 @@ start_plugin(struct plugin_cycle *cycle, const char *plugin_path)
        g_free(cycle->argv[0]);
        cycle->argv[0] = g_path_get_basename(plugin_path);
 
-       ret = pipe(fds_stdout);
-       if (ret < 0)
+       int fds_stdout[2];
+       if (pipe(fds_stdout) < 0)
                return -1;
-       ret = pipe(fds_stderr);
-       if (ret < 0) {
+
+       int fds_stderr[2];
+       if (pipe(fds_stderr) < 0) {
                close(fds_stdout[0]);
                close(fds_stdout[1]);
                return -1;
        }
 
-       pid = fork();
+       pid_t pid = fork();
 
        if (pid < 0) {
                close(fds_stdout[0]);
@@ -301,9 +290,6 @@ start_plugin(struct plugin_cycle *cycle, const char *plugin_path)
 static void
 next_plugin(struct plugin_cycle *cycle)
 {
-       const char *plugin_path;
-       int ret = -1;
-
        assert(cycle->pid < 0);
        assert(cycle->pipe_stdout.fd < 0);
        assert(cycle->pipe_stderr.fd < 0);
@@ -316,10 +302,9 @@ next_plugin(struct plugin_cycle *cycle)
                return;
        }
 
-       plugin_path = g_ptr_array_index(cycle->list->plugins,
-                                       cycle->next_plugin++);
-       ret = start_plugin(cycle, plugin_path);
-       if (ret < 0) {
+       const char *plugin_path = g_ptr_array_index(cycle->list->plugins,
+                                                   cycle->next_plugin++);
+       if (start_plugin(cycle, plugin_path) < 0) {
                /* system error */
                g_timeout_add(0, plugin_delayed_fail, cycle);
                return;
@@ -330,13 +315,11 @@ static char **
 make_argv(const char*const* args)
 {
        unsigned num = 0;
-       char **ret;
-
        while (args[num] != NULL)
                ++num;
        num += 2;
 
-       ret = g_new(char*, num);
+       char **ret = g_new(char *, num);
 
        /* reserve space for the program name */
        *ret++ = NULL;
index 601b7ba3fa55ee3650a56d3329b84a66d85641b4..590b7bef974dce5e7c80ca60aab1cca0be28e31c 100644 (file)
@@ -43,12 +43,10 @@ progress_bar_paint(const struct progress_bar *p)
 static bool
 progress_bar_calc(struct progress_bar *p)
 {
-       unsigned old_width;
-
        if (p->max == 0)
                return false;
 
-       old_width = p->width;
+       unsigned old_width = p->width;
        p->width = (p->window.cols * p->current) / (p->max + 1);
        assert(p->width < p->window.cols);
 
@@ -70,14 +68,12 @@ progress_bar_resize(struct progress_bar *p, unsigned width, int y, int x)
 bool
 progress_bar_set(struct progress_bar *p, unsigned current, unsigned max)
 {
-       bool modified;
-
        assert(p != NULL);
 
        if (current > max)
                current = max;
 
-       modified = (max == 0) != (p->max == 0);
+       bool modified = (max == 0) != (p->max == 0);
 
        p->max = max;
        p->current = current;
index 4050add277367c224a45b949ffc010a9e8a73b0d..b272935fe2c04bda83531609fbc87016c60d14f6 100644 (file)
@@ -132,18 +132,17 @@ static void
 screen_next_mode(struct mpdclient *c, int offset)
 {
        int max = g_strv_length(options.screen_list);
-       int current, next;
-       const struct screen_functions *sf;
 
        /* find current screen */
-       current = find_configured_screen(screen_get_name(mode_fn));
-       next = current + offset;
+       int current = find_configured_screen(screen_get_name(mode_fn));
+       int next = current + offset;
        if (next<0)
                next = max-1;
        else if (next>=max)
                next = 0;
 
-       sf = screen_lookup_name(options.screen_list[next]);
+       const struct screen_functions *sf =
+               screen_lookup_name(options.screen_list[next]);
        if (sf != NULL)
                screen_switch(sf, c);
 }
@@ -157,8 +156,7 @@ paint_top_window(const char *header, const struct mpdclient *c)
 static void
 update_progress_window(struct mpdclient *c, bool repaint)
 {
-       unsigned elapsed, duration;
-
+       unsigned elapsed;
        if (c->status == NULL)
                elapsed = 0;
        else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
@@ -166,7 +164,7 @@ update_progress_window(struct mpdclient *c, bool repaint)
        else
                elapsed = mpd_status_get_elapsed_time(c->status);
 
-       duration = mpdclient_is_playing(c)
+       unsigned duration = mpdclient_is_playing(c)
                ? mpd_status_get_total_time(c->status)
                : 0;
 
index 5ff6f9b81c8d258128fab32783c5da9b1de7b95a..077fca52bd61ccf442e88d1cafba8229feb347ad 100644 (file)
@@ -49,12 +49,10 @@ static gint
 compare_utf8(gconstpointer s1, gconstpointer s2)
 {
        const char *const*t1 = s1, *const*t2 = s2;
-       char *key1, *key2;
-       int n;
 
-       key1 = g_utf8_collate_key(*t1,-1);
-       key2 = g_utf8_collate_key(*t2,-1);
-       n = strcmp(key1,key2);
+       char *key1 = g_utf8_collate_key(*t1,-1);
+       char *key2 = g_utf8_collate_key(*t2,-1);
+       int n = strcmp(key1,key2);
        g_free(key1);
        g_free(key2);
        return n;
@@ -65,8 +63,6 @@ static const char *
 screen_artist_lw_callback(unsigned idx, void *data)
 {
        GPtrArray *list = data;
-       static char buf[BUFSIZE];
-       char *str, *str_utf8;
 
        if (mode == LIST_ALBUMS) {
                if (idx == 0)
@@ -79,10 +75,12 @@ screen_artist_lw_callback(unsigned idx, void *data)
 
        assert(idx < list->len);
 
-       str_utf8 = g_ptr_array_index(list, idx);
+       char *str_utf8 = g_ptr_array_index(list, idx);
        assert(str_utf8 != NULL);
 
-       str = utf8_to_locale(str_utf8);
+       char *str = utf8_to_locale(str_utf8);
+
+       static char buf[BUFSIZE];
        g_strlcpy(buf, str, sizeof(buf));
        g_free(str);
 
@@ -102,9 +100,7 @@ artist_repaint(void)
 static void
 string_array_free(GPtrArray *array)
 {
-       unsigned i;
-
-       for (i = 0; i < array->len; ++i) {
+       for (unsigned i = 0; i < array->len; ++i) {
                char *value = g_ptr_array_index(array, i);
                g_free(value);
        }
@@ -391,9 +387,9 @@ screen_artist_paint(void)
 static const char *
 screen_artist_get_title(char *str, size_t size)
 {
-       char *s1, *s2;
-
        switch(mode) {
+               char *s1, *s2;
+
        case LIST_ARTISTS:
                g_snprintf(str, size, _("All artists"));
                break;
@@ -453,15 +449,13 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, const char *_filter,
          const char *_artist)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       char *str;
-       struct filelist *addlist;
 
        assert(_filter != NULL);
 
        if (connection == NULL)
                return;
 
-       str = utf8_to_locale(_filter);
+       char *str = utf8_to_locale(_filter);
        if (table == MPD_TAG_ALBUM)
                screen_status_printf(_("Adding album %s..."), str);
        else
@@ -476,7 +470,7 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, const char *_filter,
                                              MPD_TAG_ARTIST, _artist);
        mpd_search_commit(connection);
 
-       addlist = filelist_new_recv(connection);
+       struct filelist *addlist = filelist_new_recv(connection);
 
        if (mpdclient_finish_command(c))
                mpdclient_filelist_add_all(c, addlist);
@@ -516,13 +510,13 @@ string_array_find(GPtrArray *array, const char *value)
 static bool
 screen_artist_cmd(struct mpdclient *c, command_t cmd)
 {
-       struct list_window_range range;
-       char *selected;
-       char *old;
-       char *old_ptr;
-       int idx;
-
        switch(cmd) {
+               struct list_window_range range;
+               char *selected;
+               char *old;
+               char *old_ptr;
+               int idx;
+
        case CMD_PLAY:
                switch (mode) {
                case LIST_ARTISTS:
index 6c802f6e87aaa2a0654a0ce7b42c2d88d4598cdb..0835241ed2c9f46852c257620f70d1baa51bd14d 100644 (file)
@@ -52,9 +52,7 @@ void
 screen_browser_sync_highlights(struct filelist *fl,
                               const struct mpdclient_playlist *playlist)
 {
-       guint i;
-
-       for (i = 0; i < filelist_length(fl); ++i) {
+       for (unsigned i = 0; i < filelist_length(fl); ++i) {
                struct filelist_entry *entry = filelist_get(fl, i);
                const struct mpd_entity *entity = entry->entity;
 
@@ -79,16 +77,14 @@ browser_lw_callback(unsigned idx, void *data)
 {
        const struct filelist *fl = (const struct filelist *) data;
        static char buf[BUFSIZE];
-       const struct filelist_entry *entry;
-       const struct mpd_entity *entity;
 
        assert(fl != NULL);
        assert(idx < filelist_length(fl));
 
-       entry = filelist_get(fl, idx);
+       const struct filelist_entry *entry = filelist_get(fl, idx);
        assert(entry != NULL);
 
-       entity = entry->entity;
+       const struct mpd_entity *entity = entry->entity;
 
        if( entity == NULL )
                return "..";
@@ -231,12 +227,10 @@ static bool
 browser_handle_enter(struct screen_browser *browser, struct mpdclient *c)
 {
        struct filelist_entry *entry = browser_get_selected_entry(browser);
-       struct mpd_entity *entity;
-
        if (entry == NULL)
                return false;
 
-       entity = entry->entity;
+       struct mpd_entity *entity = entry->entity;
        if (entity == NULL)
                return false;
 
@@ -313,13 +307,11 @@ static bool
 browser_handle_select(struct screen_browser *browser, struct mpdclient *c)
 {
        struct list_window_range range;
-       struct filelist_entry *entry;
        bool success = false;
 
        list_window_get_range(browser->lw, &range);
        for (unsigned i = range.start; i < range.end; ++i) {
-               entry = browser_get_index(browser, i);
-
+               struct filelist_entry *entry = browser_get_index(browser, i);
                if (entry != NULL && entry->entity != NULL)
                        success = browser_select_entry(c, entry, TRUE);
        }
@@ -331,13 +323,11 @@ static bool
 browser_handle_add(struct screen_browser *browser, struct mpdclient *c)
 {
        struct list_window_range range;
-       struct filelist_entry *entry;
        bool success = false;
 
        list_window_get_range(browser->lw, &range);
        for (unsigned i = range.start; i < range.end; ++i) {
-               entry = browser_get_index(browser, i);
-
+               struct filelist_entry *entry = browser_get_index(browser, i);
                if (entry != NULL && entry->entity != NULL)
                        success = browser_select_entry(c, entry, FALSE) ||
                                success;
@@ -349,12 +339,10 @@ browser_handle_add(struct screen_browser *browser, struct mpdclient *c)
 static void
 browser_handle_select_all(struct screen_browser *browser, struct mpdclient *c)
 {
-       guint i;
-
        if (browser->filelist == NULL)
                return;
 
-       for (i = 0; i < filelist_length(browser->filelist); ++i) {
+       for (unsigned i = 0; i < filelist_length(browser->filelist); ++i) {
                struct filelist_entry *entry = filelist_get(browser->filelist, i);
 
                if (entry != NULL && entry->entity != NULL)
@@ -396,8 +384,6 @@ bool
 browser_cmd(struct screen_browser *browser,
            struct mpdclient *c, command_t cmd)
 {
-       const struct mpd_song *song;
-
        if (browser->filelist == NULL)
                return false;
 
@@ -405,6 +391,10 @@ browser_cmd(struct screen_browser *browser,
                return true;
 
        switch (cmd) {
+#if defined(ENABLE_SONG_SCREEN) || defined(ENABLE_LYRICS_SCREEN)
+               const struct mpd_song *song;
+#endif
+
        case CMD_LIST_FIND:
        case CMD_LIST_RFIND:
        case CMD_LIST_FIND_NEXT:
@@ -454,6 +444,8 @@ browser_cmd(struct screen_browser *browser,
                return false;
 
        switch (cmd) {
+               const struct mpd_song *song;
+
        case CMD_PLAY:
                browser_handle_enter(browser, c);
                return true;
@@ -514,32 +506,30 @@ screen_browser_paint_callback(WINDOW *w, unsigned i,
                              bool selected, void *data)
 {
        const struct filelist *fl = (const struct filelist *) data;
-       const struct filelist_entry *entry;
-       const struct mpd_entity *entity;
-       bool highlight;
-       const struct mpd_directory *directory;
-       const struct mpd_playlist *playlist;
-       char *p;
 
        assert(fl != NULL);
        assert(i < filelist_length(fl));
 
-       entry = filelist_get(fl, i);
+       const struct filelist_entry *entry = filelist_get(fl, i);
        assert(entry != NULL);
 
-       entity = entry->entity;
+       const struct mpd_entity *entity = entry->entity;
        if (entity == NULL) {
                screen_browser_paint_directory(w, width, selected, "..");
                return;
        }
 
 #ifndef NCMPC_MINI
-       highlight = (entry->flags & HIGHLIGHT) != 0;
+       const bool highlight = (entry->flags & HIGHLIGHT) != 0;
 #else
-       highlight = false;
+       const bool highlight = false;
 #endif
 
        switch (mpd_entity_get_type(entity)) {
+               const struct mpd_directory *directory;
+               const struct mpd_playlist *playlist;
+               char *p;
+
        case MPD_ENTITY_TYPE_DIRECTORY:
                directory = mpd_entity_get_directory(entity);
                p = utf8_to_locale(g_basename(mpd_directory_get_path(directory)));
index f30da93bb980b292c61ca9391eec9f93340efbb8..b4c80fbce14c1432042a5519325444ba0fa8a94d 100644 (file)
@@ -106,14 +106,12 @@ screen_chat_paint(void)
 static void
 process_message(struct mpd_message *message)
 {
-       char *message_text;
-
        assert(message != NULL);
        /* You'll have to move this out of screen_chat, if you want to use
           client-to-client messages anywhere else */
        assert(g_strcmp0(mpd_message_get_channel(message), chat_channel) == 0);
 
-       message_text = utf8_to_locale(mpd_message_get_text(message));
+       char *message_text = utf8_to_locale(mpd_message_get_text(message));
        screen_text_append(&text, message_text);
        g_free(message_text);
 
index b8e936fdbc0fe6147edd4bbd961f2c590551368d..6eb9bf4964de2f2950a60ae021fd65346eac0a46 100644 (file)
 static bool
 _screen_auth(struct mpdclient *c, gint recursion)
 {
-       struct mpd_connection *connection;
-       char *password;
-
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return false;
 
@@ -38,7 +35,7 @@ _screen_auth(struct mpdclient *c, gint recursion)
        if (recursion > 2)
                return false;
 
-       password = screen_read_password(NULL);
+       char *password = screen_read_password(NULL);
        if (password == NULL)
                return false;
 
@@ -75,17 +72,14 @@ mpdclient_ui_error(const char *message_utf8)
 void
 screen_database_update(struct mpdclient *c, const char *path)
 {
-       struct mpd_connection *connection;
-       unsigned id;
-
        assert(c != NULL);
        assert(mpdclient_is_connected(c));
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return;
 
-       id = mpd_run_update(connection, path);
+       unsigned id = mpd_run_update(connection, path);
        if (id == 0) {
                if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
                    mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_UPDATE_ALREADY &&
index da7969b7221d00e1da14d845551bf6f449799a61..175e7866ab2ea1e0285d62c762a7e58a81c504dd 100644 (file)
@@ -109,20 +109,16 @@ static bool
 change_to_parent(struct mpdclient *c)
 {
        char *parent = g_path_get_dirname(current_path);
-       char *old_path;
-       int idx;
-       bool success;
-
        if (strcmp(parent, ".") == 0)
                parent[0] = '\0';
 
-       old_path = current_path;
+       char *old_path = current_path;
        current_path = NULL;
 
-       success = change_directory(c, parent);
+       bool success = change_directory(c, parent);
        g_free(parent);
 
-       idx = success
+       int idx = success
                ? filelist_find_directory(browser.filelist, old_path)
                : -1;
        g_free(old_path);
@@ -169,7 +165,6 @@ handle_save(struct mpdclient *c)
 {
        struct list_window_range range;
        const char *defaultname = NULL;
-       char *defaultname_utf8 = NULL;
 
        list_window_get_range(browser.lw, &range);
        if (range.start == range.end)
@@ -188,6 +183,7 @@ handle_save(struct mpdclient *c)
                }
        }
 
+       char *defaultname_utf8 = NULL;
        if(defaultname)
                defaultname_utf8 = utf8_to_locale(defaultname);
        playlist_save(c, NULL, defaultname_utf8);
@@ -198,14 +194,11 @@ static void
 handle_delete(struct mpdclient *c)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       struct list_window_range range;
-       struct mpd_entity *entity;
-       const struct mpd_playlist *playlist;
-       char *str, *buf;
 
        if (connection == NULL)
                return;
 
+       struct list_window_range range;
        list_window_get_range(browser.lw, &range);
        for (unsigned i = range.start; i < range.end; ++i) {
                struct filelist_entry *entry =
@@ -213,7 +206,7 @@ handle_delete(struct mpdclient *c)
                if( entry==NULL || entry->entity==NULL )
                        continue;
 
-               entity = entry->entity;
+               struct mpd_entity *entity = entry->entity;
 
                if (mpd_entity_get_type(entity) != MPD_ENTITY_TYPE_PLAYLIST) {
                        /* translators: the "delete" command is only possible
@@ -224,9 +217,9 @@ handle_delete(struct mpdclient *c)
                        continue;
                }
 
-               playlist = mpd_entity_get_playlist(entity);
-               str = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
-               buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO);
+               const struct mpd_playlist *playlist = mpd_entity_get_playlist(entity);
+               char *str = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
+               char *buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO);
                g_free(str);
                bool delete = screen_get_yesno(buf, false);
                g_free(buf);
@@ -285,7 +278,6 @@ static const char *
 screen_file_get_title(char *str, size_t size)
 {
        const char *path = NULL, *prev = NULL, *slash = current_path;
-       char *path_locale;
 
        /* determine the last 2 parts of the path */
        while ((slash = strchr(slash, '/')) != NULL) {
@@ -297,7 +289,7 @@ screen_file_get_title(char *str, size_t size)
                /* fall back to full path */
                path = current_path;
 
-       path_locale = utf8_to_locale(path);
+       char *path_locale = utf8_to_locale(path);
        g_snprintf(str, size, "%s: %s",
                   /* translators: caption of the browser screen */
                   _("Browse"), path_locale);
@@ -412,8 +404,6 @@ screen_file_goto_song(struct mpdclient *c, const struct mpd_song *song)
 {
        const char *uri, *slash, *parent;
        char *allocated = NULL;
-       bool ret;
-       int i;
 
        assert(song != NULL);
 
@@ -431,14 +421,14 @@ screen_file_goto_song(struct mpdclient *c, const struct mpd_song *song)
        else
                parent = "";
 
-       ret = change_directory(c, parent);
+       bool ret = change_directory(c, parent);
        g_free(allocated);
        if (!ret)
                return false;
 
        /* select the specified song */
 
-       i = filelist_find_song(browser.filelist, song);
+       int i = filelist_find_song(browser.filelist, song);
        if (i < 0)
                i = 0;
 
index 3fdf9f30dd923914723c2e85658161e95a8a322f..5f2277288bacd4905ca4b4c13f9f30b1d49a70c8 100644 (file)
@@ -35,15 +35,13 @@ screen_find(struct list_window *lw, command_t findcmd,
            list_window_callback_fn_t callback_fn,
            void *callback_data)
 {
-       int reversed = 0;
        bool found;
        const char *prompt = FIND_PROMPT;
-       char *value = options.find_show_last_pattern ? (char *) -1 : NULL;
 
-       if (findcmd == CMD_LIST_RFIND || findcmd == CMD_LIST_RFIND_NEXT) {
+       const bool reversed =
+               findcmd == CMD_LIST_RFIND || findcmd == CMD_LIST_RFIND_NEXT;
+       if (reversed)
                prompt = RFIND_PROMPT;
-               reversed = 1;
-       }
 
        switch (findcmd) {
        case CMD_LIST_FIND:
@@ -56,11 +54,14 @@ screen_find(struct list_window *lw, command_t findcmd,
 
        case CMD_LIST_FIND_NEXT:
        case CMD_LIST_RFIND_NEXT:
-               if (!screen.findbuf)
+               if (!screen.findbuf) {
+                       char *value = options.find_show_last_pattern
+                               ? (char *) -1 : NULL;
                        screen.findbuf=screen_readln(prompt,
                                                     value,
                                                     &screen.find_history,
                                                     NULL);
+               }
 
                if (screen.findbuf == NULL)
                        return 1;
@@ -96,10 +97,8 @@ screen_jump(struct list_window *lw,
            list_window_paint_callback_t paint_callback,
                void *callback_data)
 {
-       char *search_str, *iter, *temp;
        const int WRLN_MAX_LINE_SIZE = 1024;
        int key = 65;
-       command_t cmd;
 
        if (screen.findbuf) {
                g_free(screen.findbuf);
@@ -108,8 +107,8 @@ screen_jump(struct list_window *lw,
        screen.findbuf = g_malloc0(WRLN_MAX_LINE_SIZE);
        /* In screen.findbuf is the whole string which is displayed in the status_window
         * and search_str is the string the user entered (without the prompt) */
-       search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
-       iter = search_str;
+       char *search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
+       char *iter = search_str;
 
        while(1) {
                key = screen_getch(screen.findbuf);
@@ -143,10 +142,12 @@ screen_jump(struct list_window *lw,
 
        /* ncmpc should get the command */
        ungetch(key);
+
+       command_t cmd;
        if ((cmd=get_keyboard_command()) != CMD_NONE)
                do_input_event(cmd);
 
-       temp = g_strdup(search_str);
+       char *temp = g_strdup(search_str);
        g_free(screen.findbuf);
        screen.findbuf = temp;
 }
index ad78c383d48b235ec6a12bc9f1ab8659c8821819..dde5ce571321e56f8aebd75500a264424775799e 100644 (file)
@@ -145,9 +145,6 @@ apply_keys(void)
 static int
 save_keys(void)
 {
-       FILE *f;
-       char *filename;
-
        if (check_user_conf_dir()) {
                screen_status_printf(_("Error: Unable to create directory ~/.ncmpc - %s"),
                                     strerror(errno));
@@ -155,9 +152,9 @@ save_keys(void)
                return -1;
        }
 
-       filename = build_user_key_binding_filename();
-
-       if ((f = fopen(filename,"w")) == NULL) {
+       char *filename = build_user_key_binding_filename();
+       FILE *f = fopen(filename, "w");
+       if (f == NULL) {
                screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
                screen_bell();
                g_free(filename);
@@ -264,14 +261,11 @@ delete_key(int cmd_index, int key_index)
 static void
 overwrite_key(int cmd_index, int key_index)
 {
-       int key;
-       char *buf;
-       command_t cmd;
-
        assert(key_index < MAX_COMMAND_KEYS);
 
-       buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name);
-       key = screen_getch(buf);
+       char *buf = g_strdup_printf(_("Enter new key for %s: "),
+                                   cmds[cmd_index].name);
+       const int key = screen_getch(buf);
        g_free(buf);
 
        if (key == ERR) {
@@ -284,7 +278,7 @@ overwrite_key(int cmd_index, int key_index)
                return;
        }
 
-       cmd = find_key_command(key, cmds);
+       const command_t cmd = find_key_command(key, cmds);
        if (cmd != CMD_NONE) {
                screen_status_printf(_("Error: key %s is already used for %s"),
                                     key2str(key), get_key_command_name(cmd));
@@ -392,14 +386,13 @@ keydef_open(gcc_unused struct mpdclient *c)
 {
        if (cmds == NULL) {
                command_definition_t *current_cmds = get_command_definitions();
-               size_t cmds_size;
-
                command_n_commands = 0;
                while (current_cmds[command_n_commands].name)
                        command_n_commands++;
 
                /* +1 for the terminator element */
-               cmds_size = (command_n_commands + 1) * sizeof(command_definition_t);
+               size_t cmds_size = (command_n_commands + 1)
+                       * sizeof(command_definition_t);
                cmds = g_malloc0(cmds_size);
                memcpy(cmds, current_cmds, cmds_size);
        }
index 5ef6ddba172224f0168389df77aec598c0b573b0..e7cd694bf43d6ee6768fe0e621d459be6a924a20 100644 (file)
@@ -69,9 +69,7 @@ static const struct
 void
 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
 {
-       unsigned i;
-
-       for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
+       for (unsigned i = 0; i < G_N_ELEMENTS(screens); ++i) {
                const struct screen_functions *sf = screens[i].functions;
 
                if (sf->init)
@@ -82,9 +80,7 @@ screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
 void
 screen_list_exit(void)
 {
-       unsigned i;
-
-       for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
+       for (unsigned i = 0; i < G_N_ELEMENTS(screens); ++i) {
                const struct screen_functions *sf = screens[i].functions;
 
                if (sf->exit)
@@ -95,9 +91,7 @@ screen_list_exit(void)
 void
 screen_list_resize(unsigned cols, unsigned rows)
 {
-       unsigned i;
-
-       for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
+       for (unsigned i = 0; i < G_N_ELEMENTS(screens); ++i) {
                const struct screen_functions *sf = screens[i].functions;
 
                if (sf->resize)
@@ -108,9 +102,7 @@ screen_list_resize(unsigned cols, unsigned rows)
 const char *
 screen_get_name(const struct screen_functions *sf)
 {
-       unsigned i;
-
-       for (i = 0; i < G_N_ELEMENTS(screens); ++i)
+       for (unsigned i = 0; i < G_N_ELEMENTS(screens); ++i)
                if (screens[i].functions == sf)
                        return screens[i].name;
 
@@ -120,9 +112,7 @@ screen_get_name(const struct screen_functions *sf)
 const struct screen_functions *
 screen_lookup_name(const char *name)
 {
-       unsigned i;
-
-       for (i = 0; i < G_N_ELEMENTS(screens); ++i)
+       for (unsigned i = 0; i < G_N_ELEMENTS(screens); ++i)
                if (strcmp(name, screens[i].name) == 0)
                        return screens[i].functions;
 
index cda976e0a05d058c55b16b0b0a3f5d9cf626a132..d6d1a6c3cf4c4ad64eedb420f06a70975b33c156 100644 (file)
@@ -117,10 +117,9 @@ static bool
 exists_lyr_file(const char *artist, const char *title)
 {
        char path[1024];
-       struct stat result;
-
        path_lyr_file(path, 1024, artist, title);
 
+       struct stat result;
        return (stat(path, &result) == 0);
 }
 
@@ -128,7 +127,6 @@ static FILE *
 create_lyr_file(const char *artist, const char *title)
 {
        char path[1024];
-
        snprintf(path, 1024, "%s/.lyrics",
                 getenv("HOME"));
        mkdir(path, S_IRWXU);
@@ -141,14 +139,11 @@ create_lyr_file(const char *artist, const char *title)
 static int
 store_lyr_hd(void)
 {
-       FILE *lyr_file;
-       unsigned i;
-
-       lyr_file = create_lyr_file(current.artist, current.title);
+       FILE *lyr_file = create_lyr_file(current.artist, current.title);
        if (lyr_file == NULL)
                return -1;
 
-       for (i = 0; i < text.lines->len; ++i)
+       for (unsigned i = 0; i < text.lines->len; ++i)
                fprintf(lyr_file, "%s\n",
                        (const char*)g_ptr_array_index(text.lines, i));
 
@@ -159,11 +154,10 @@ store_lyr_hd(void)
 static int
 delete_lyr_hd(void)
 {
-       char path[1024];
-
        if (!exists_lyr_file(current.artist, current.title))
                return -1;
 
+       char path[1024];
        path_lyr_file(path, 1024, current.artist, current.title);
        if (unlink(path) != 0)
                return -2;
@@ -239,15 +233,13 @@ screen_lyrics_timeout_callback(gpointer gcc_unused data)
 static void
 screen_lyrics_load(const struct mpd_song *song)
 {
-       const char *artist, *title;
-
        assert(song != NULL);
 
        screen_lyrics_abort();
        screen_text_clear(&text);
 
-       artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
-       title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
+       const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
+       const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
 
        current.song = mpd_song_dup(song);
        current.artist = g_strdup(artist);
@@ -365,8 +357,6 @@ static void
 lyrics_edit(void)
 {
        char *editor = options.text_editor;
-       int status;
-
        if (editor == NULL) {
                screen_status_message(_("Editor not configured"));
                return;
@@ -391,6 +381,7 @@ lyrics_edit(void)
 
        /* TODO: fork/exec/wait won't work on Windows, but building a command
           string for system() is too tricky */
+       int status;
        pid_t pid = fork();
        if (pid == -1) {
                screen_status_printf(("%s (%s)"), _("Can't start editor"), g_strerror(errno));
index 5ec897dade076dfa2acbc01e6655fc797f2d7b25..e80d7bae50962af4320fcc6dc8182b4fdd342933 100644 (file)
@@ -47,20 +47,17 @@ outputs_repaint(void)
 static bool
 toggle_output(struct mpdclient *c, unsigned int output_index)
 {
-       struct mpd_connection *connection;
-       struct mpd_output *output;
-
        assert(mpd_outputs != NULL);
 
        if (output_index >= mpd_outputs->len)
                return false;
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return false;
 
-       output = g_ptr_array_index(mpd_outputs, output_index);
-
+       struct mpd_output *output =
+               g_ptr_array_index(mpd_outputs, output_index);
        if (!mpd_output_get_enabled(output)) {
                if (!mpd_run_enable_output(connection,
                                           mpd_output_get_id(output))) {
@@ -114,18 +111,17 @@ clear_outputs_list(void)
 static void
 fill_outputs_list(struct mpdclient *c)
 {
-       struct mpd_connection *connection;
-       struct mpd_output *output;
-
        assert(mpd_outputs != NULL);
 
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL) {
                list_window_set_length(lw, 0);
                return;
        }
 
        mpd_send_outputs(connection);
+
+       struct mpd_output *output;
        while ((output = mpd_recv_output(connection)) != NULL) {
                g_ptr_array_add(mpd_outputs, output);
        }
index 87cdc63ad0a517c86c144d1652bafc75bb610af8..0d08bbcb63ce67f3eb8a5dec83681fbc1b74a77a 100644 (file)
@@ -96,22 +96,19 @@ screen_queue_save_selection(void)
 static void
 screen_queue_restore_selection(void)
 {
-       const struct mpd_song *song;
-       int pos;
-
        list_window_set_length(lw, playlist_length(playlist));
 
        if (selected_song_id < 0)
                /* there was no selection */
                return;
 
-       song = screen_queue_selected_song();
+       const struct mpd_song *song = screen_queue_selected_song();
        if (song != NULL &&
            mpd_song_get_id(song) == (unsigned)selected_song_id)
                /* selection is still valid */
                return;
 
-       pos = playlist_get_index_from_id(playlist, selected_song_id);
+       int pos = playlist_get_index_from_id(playlist, selected_song_id);
        if (pos >= 0)
                list_window_set_cursor(lw, pos);
 
@@ -122,12 +119,11 @@ static const char *
 screen_queue_lw_callback(unsigned idx, gcc_unused void *data)
 {
        static char songname[MAX_SONG_LENGTH];
-       struct mpd_song *song;
 
        assert(playlist != NULL);
        assert(idx < playlist_length(playlist));
 
-       song = playlist_get(playlist, idx);
+       struct mpd_song *song = playlist_get(playlist, idx);
 
        strfsong(songname, MAX_SONG_LENGTH, options.list_format, song);
 
@@ -137,15 +133,13 @@ screen_queue_lw_callback(unsigned idx, gcc_unused void *data)
 static void
 center_playing_item(const struct mpd_status *status, bool center_cursor)
 {
-       int idx;
-
        if (status == NULL ||
            (mpd_status_get_state(status) != MPD_STATE_PLAY &&
             mpd_status_get_state(status) != MPD_STATE_PAUSE))
                return;
 
        /* try to center the song that are playing */
-       idx = mpd_status_get_song_pos(status);
+       int idx = mpd_status_get_song_pos(status);
        if (idx < 0)
                return;
 
@@ -229,12 +223,7 @@ int
 playlist_save(struct mpdclient *c, char *name, char *defaultname)
 {
        struct mpd_connection *connection;
-       gchar *filename, *filename_utf8;
-#ifndef NCMPC_MINI
-       GCompletion *gcmp;
-       GList *list = NULL;
-       completion_callback_data_t data;
-#endif
+       gchar *filename;
 
 #ifdef NCMPC_MINI
        (void)defaultname;
@@ -243,11 +232,14 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
 #ifndef NCMPC_MINI
        if (name == NULL) {
                /* initialize completion support */
-               gcmp = g_completion_new(NULL);
+               GCompletion *gcmp = g_completion_new(NULL);
                g_completion_set_compare(gcmp, completion_strncmp);
-               data.list = &list;
-               data.dir_list = NULL;
-               data.c = c;
+               GList *list = NULL;
+               completion_callback_data_t data = {
+                       .list = &list,
+                       .dir_list = NULL,
+                       .c = c,
+               };
                wrln_completion_callback_data = &data;
                wrln_pre_completion_callback = save_pre_completion_cb;
                wrln_post_completion_callback = save_post_completion_cb;
@@ -282,17 +274,14 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
                return -1;
        }
 
-       filename_utf8 = locale_to_utf8(filename);
+       char *filename_utf8 = locale_to_utf8(filename);
        if (!mpd_run_save(connection, filename_utf8)) {
                if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
                    mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
                    mpd_connection_clear_error(connection)) {
-                       char *buf;
-                       bool replace;
-
-                       buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
-                                             filename, YES, NO);
-                       replace = screen_get_yesno(buf, false);
+                       char *buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
+                                                   filename, YES, NO);
+                       bool replace = screen_get_yesno(buf, false);
                        g_free(buf);
 
                        if (!replace) {
@@ -378,31 +367,31 @@ static void add_post_completion_cb(GCompletion *gcmp, gchar *line,
 static int
 handle_add_to_playlist(struct mpdclient *c)
 {
-       gchar *path;
-       GCompletion *gcmp;
 #ifndef NCMPC_MINI
+       /* initialize completion support */
+       GCompletion *gcmp = g_completion_new(NULL);
+       g_completion_set_compare(gcmp, completion_strncmp);
+
        GList *list = NULL;
        GList *dir_list = NULL;
-       completion_callback_data_t data;
+       completion_callback_data_t data = {
+               .list = &list,
+               .dir_list = &dir_list,
+               .c = c,
+       };
 
-       /* initialize completion support */
-       gcmp = g_completion_new(NULL);
-       g_completion_set_compare(gcmp, completion_strncmp);
-       data.list = &list;
-       data.dir_list = &dir_list;
-       data.c = c;
        wrln_completion_callback_data = &data;
        wrln_pre_completion_callback = add_pre_completion_cb;
        wrln_post_completion_callback = add_post_completion_cb;
 #else
-       gcmp = NULL;
+       GCompletion *gcmp = NULL;
 #endif
 
        /* get path */
-       path = screen_readln(_("Add"),
-                            NULL,
-                            NULL,
-                            gcmp);
+       char *path = screen_readln(_("Add"),
+                                  NULL,
+                                  NULL,
+                                  gcmp);
 
        /* destroy completion data */
 #ifndef NCMPC_MINI
@@ -517,17 +506,13 @@ screen_queue_paint_callback(WINDOW *w, unsigned i,
                            unsigned y, unsigned width,
                            bool selected, gcc_unused void *data)
 {
-       const struct mpd_song *song;
-       struct hscroll *row_hscroll;
-
        assert(playlist != NULL);
        assert(i < playlist_length(playlist));
 
-       song = playlist_get(playlist, i);
+       const struct mpd_song *song = playlist_get(playlist, i);
 
-#ifdef NCMPC_MINI
-       row_hscroll = NULL;
-#else
+       struct hscroll *row_hscroll = NULL;
+#ifndef NCMPC_MINI
        row_hscroll = selected && options.scroll && lw->selected == i
                ? &hscroll : NULL;
 #endif
@@ -570,10 +555,8 @@ screen_queue_update(struct mpdclient *c)
 static bool
 handle_mouse_event(struct mpdclient *c)
 {
-       int row;
        unsigned long bstate;
-       unsigned old_selected;
-
+       int row;
        if (screen_get_mouse_event(c, &bstate, &row) ||
            list_window_mouse(lw, bstate, row)) {
                screen_queue_repaint();
@@ -586,7 +569,7 @@ handle_mouse_event(struct mpdclient *c)
                return true;
        }
 
-       old_selected = lw->selected;
+       const unsigned old_selected = lw->selected;
        list_window_set_cursor(lw, lw->start + row);
 
        if (bstate & BUTTON1_CLICKED) {
@@ -621,10 +604,8 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
 {
        struct mpd_connection *connection;
        static command_t cached_cmd = CMD_NONE;
-       command_t prev_cmd = cached_cmd;
-       struct list_window_range range;
-       const struct mpd_song *song;
 
+       const command_t prev_cmd = cached_cmd;
        cached_cmd = cmd;
 
        lw->hide_cursor = false;
@@ -715,6 +696,9 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
                return false;
 
        switch(cmd) {
+               const struct mpd_song *song;
+               struct list_window_range range;
+
        case CMD_PLAY:
                song = screen_queue_selected_song();
                if (song == NULL)
index 42253d0ad8c2d4c423a5c75c453929569119b9bc..0d39ddb151e76c6b7b7a32fd8b520d8bef778ac7 100644 (file)
@@ -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))
@@ -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;
index 32f1b85eaa50c6d289ecd6d5997e733ad3ff9063..6d3a0342a7c592eed21b0083e05915592db900e9 100644 (file)
@@ -193,12 +193,7 @@ screen_song_paint(void)
 static void
 screen_song_append(const char *label, const char *value, unsigned label_col)
 {
-       unsigned label_width = locale_width(label) + 2;
-       int value_col, label_size;
-       gchar *entry, *entry_iter;
-       const gchar *value_iter;
-       char *p, *q;
-       unsigned width;
+       const unsigned label_width = locale_width(label) + 2;
 
        assert(label != NULL);
        assert(value != NULL);
@@ -206,13 +201,13 @@ screen_song_append(const char *label, const char *value, unsigned label_col)
 
        /* +2 for ': ' */
        label_col += 2;
-       value_col = lw->cols - label_col;
+       const int value_col = lw->cols - label_col;
        /* calculate the number of required linebreaks */
-       value_iter = value;
-       label_size = strlen(label) + label_col;
+       const gchar *value_iter = value;
+       const int label_size = strlen(label) + label_col;
 
        while (*value_iter != 0) {
-               entry = g_malloc(label_size);
+               char *entry = g_malloc(label_size), *entry_iter;
                if (value_iter == value) {
                        entry_iter = entry + g_sprintf(entry, "%s: ", label);
                        /* fill the label column with whitespaces */
@@ -227,8 +222,8 @@ screen_song_append(const char *label, const char *value, unsigned label_col)
                /* skip whitespaces */
                while (g_ascii_isspace(*value_iter)) ++value_iter;
 
-               p = g_strdup(value_iter);
-               width = utf8_cut_width(p, value_col);
+               char *p = g_strdup(value_iter);
+               unsigned width = utf8_cut_width(p, value_col);
                if (width == 0)
                        /* not enough room for anything - bail out */
                        break;
@@ -237,7 +232,7 @@ screen_song_append(const char *label, const char *value, unsigned label_col)
 
                value_iter += strlen(p);
                p = replace_utf8_to_locale(p);
-               q = g_strconcat(entry, p, NULL);
+               char *q = g_strconcat(entry, p, NULL);
                g_free(entry);
                g_free(p);
 
@@ -338,15 +333,13 @@ screen_song_append_stats(enum stats_label label, const char *value)
 static bool
 screen_song_add_stats(struct mpd_connection *connection)
 {
-       char buf[64];
-       GDate *date;
-       struct mpd_stats *mpd_stats;
-
-       mpd_stats = mpd_run_stats(connection);
+       struct mpd_stats *mpd_stats = mpd_run_stats(connection);
        if (mpd_stats == NULL)
                return false;
 
        g_ptr_array_add(current.lines, g_strdup(_("MPD statistics")) );
+
+       char buf[64];
        g_snprintf(buf, sizeof(buf), "%d",
                   mpd_stats_get_number_of_artists(mpd_stats));
        screen_song_append_stats(STATS_ARTISTS, buf);
@@ -369,7 +362,7 @@ screen_song_add_stats(struct mpd_connection *connection)
                             mpd_stats_get_uptime(mpd_stats));
        screen_song_append_stats(STATS_UPTIME, buf);
 
-       date = g_date_new();
+       GDate *date = g_date_new();
        g_date_set_time_t(date, mpd_stats_get_db_update_time(mpd_stats));
        g_date_strftime(buf, sizeof(buf), "%x", date);
        screen_song_append_stats(STATS_DBUPTIME, buf);
@@ -382,8 +375,6 @@ screen_song_add_stats(struct mpd_connection *connection)
 static void
 screen_song_update(struct mpdclient *c)
 {
-       struct mpd_connection *connection;
-
        /* Clear all lines */
        for (guint i = 0; i < current.lines->len; ++i)
                g_free(g_ptr_array_index(current.lines, i));
@@ -417,7 +408,7 @@ screen_song_update(struct mpdclient *c)
        }
 
        /* Add some statistics about mpd */
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection != NULL && !screen_song_add_stats(connection))
                mpdclient_handle_error(c);
 
index ca61fee17186304b3252720673c1cc8f8d6f563a..d122190bea79658eca9db785261da529d7dee394 100644 (file)
@@ -37,11 +37,9 @@ screen_status_message(const char *msg)
 void
 screen_status_printf(const char *format, ...)
 {
-       char *msg;
        va_list ap;
-
        va_start(ap,format);
-       msg = g_strdup_vprintf(format,ap);
+       char *msg = g_strdup_vprintf(format,ap);
        va_end(ap);
        screen_status_message(msg);
        g_free(msg);
index 44fe492e9ca0a6c16fbad7ab662ed81333f1a629..938d65627d69a2f63e1857d01656312dd3f7e3c1 100644 (file)
@@ -39,14 +39,13 @@ screen_text_clear(struct screen_text *text)
 void
 screen_text_append(struct screen_text *text, const char *str)
 {
-       const char *eol, *next;
-
        assert(str != NULL);
 
+       const char *eol;
        while ((eol = strchr(str, '\n')) != NULL) {
                char *line;
 
-               next = eol + 1;
+               const char *next = eol + 1;
 
                /* strip whitespace at end */
 
@@ -80,12 +79,12 @@ const char *
 screen_text_list_callback(unsigned idx, void *data)
 {
        const struct screen_text *text = data;
-       static char buffer[256];
-       char *value;
 
        assert(idx < text->lines->len);
 
-       value = utf8_to_locale(g_ptr_array_index(text->lines, idx));
+       char *value = utf8_to_locale(g_ptr_array_index(text->lines, idx));
+
+       static char buffer[256];
        g_strlcpy(buffer, value, sizeof(buffer));
        g_free(value);
 
index 8889ac13277b8b8cb0b2edf53609847bc469ae80..1c1f14b189c2cd71ac8252b7ab1aecd2adfe418a 100644 (file)
@@ -42,7 +42,6 @@ int
 screen_getch(const char *prompt)
 {
        WINDOW *w = screen.status_bar.window.w;
-       int key = -1;
 
        colors_use(w, COLOR_STATUS_ALERT);
        werase(w);
@@ -52,6 +51,7 @@ screen_getch(const char *prompt)
        echo();
        curs_set(1);
 
+       int key;
        while ((key = wgetch(w)) == ERR)
                ;
 
@@ -105,7 +105,6 @@ screen_read_password(const char *prompt)
 {
        struct window *window = &screen.status_bar.window;
        WINDOW *w = window->w;
-       char *ret;
 
        wmove(w, 0,0);
        curs_set(1);
@@ -113,7 +112,7 @@ screen_read_password(const char *prompt)
 
        if (prompt == NULL)
                prompt = _("Password");
-       ret = wreadln_masked(w, prompt, NULL, window->cols, NULL, NULL);
+       char *ret = wreadln_masked(w, prompt, NULL, window->cols, NULL, NULL);
 
        curs_set(0);
        return ret;
@@ -126,9 +125,8 @@ screen_display_completion_list(GList *list)
        static guint prev_length = 0;
        static guint offset = 0;
        WINDOW *w = screen.main_window.w;
-       guint length, y=0;
 
-       length = g_list_length(list);
+       unsigned length = g_list_length(list);
        if (list == prev_list && length == prev_length) {
                offset += screen.main_window.rows;
                if (offset >= length)
@@ -140,6 +138,8 @@ screen_display_completion_list(GList *list)
        }
 
        colors_use(w, COLOR_STATUS_ALERT);
+
+       unsigned y = 0;
        while (y < screen.main_window.rows) {
                GList *item = g_list_nth(list, y+offset);
 
@@ -166,11 +166,9 @@ set_xterm_title(const char *format, ...)
 
        if (options.enable_xterm_title) {
                if (g_getenv("WINDOWID")) {
-                       char *msg;
                        va_list ap;
-
                        va_start(ap,format);
-                       msg = g_strdup_vprintf(format,ap);
+                       char *msg = g_strdup_vprintf(format,ap);
                        va_end(ap);
                        printf("%c]0;%s%c", '\033', msg, '\007');
                        g_free(msg);
index b1b301fd3df15524cbe4c4a60f29c9affe09e8bc..2294fe1e9230291d38acf9c8921d1739b076c072 100644 (file)
@@ -98,9 +98,6 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status,
                 const struct mpd_song *song)
 {
        WINDOW *w = p->window.w;
-       enum mpd_state state;
-       const char *str = NULL;
-       int x = 0;
        char buffer[p->window.cols * 4 + 1];
 
 #ifndef NCMPC_MINI
@@ -115,9 +112,10 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status,
        wclrtoeol(w);
        colors_use(w, COLOR_STATUS_BOLD);
 
-       state = status == NULL ? MPD_STATE_UNKNOWN
+       enum mpd_state state = status == NULL ? MPD_STATE_UNKNOWN
                : mpd_status_get_state(status);
 
+       const char *str = NULL;
        switch (state) {
        case MPD_STATE_PLAY:
                str = _("Playing:");
@@ -130,6 +128,7 @@ status_bar_paint(struct status_bar *p, const struct mpd_status *status,
                break;
        }
 
+       int x = 0;
        if (str) {
                waddstr(w, str);
                x += utf8_width(str) + 1;
index 00bcd87f3c6255bf2efab0fdfa8ba3bb2dff83f4..5107ba0bd2606f9a8cc28fecf9159701b0b3988a 100644 (file)
@@ -62,15 +62,13 @@ song_more_tag_values(const struct mpd_song *song, enum mpd_tag_type tag,
                     const char *first)
 {
        const char *p = mpd_song_get_tag(song, tag, 1);
-       char *buffer, *prev;
-
        if (p == NULL)
                return NULL;
 
-       buffer = concat_tag_values(first, p);
+       char *buffer = concat_tag_values(first, p);
        for (unsigned i = 2; (p = mpd_song_get_tag(song, tag, i)) != NULL;
             ++i) {
-               prev = buffer;
+               char *prev = buffer;
                buffer = concat_tag_values(buffer, p);
                g_free(prev);
        }
@@ -84,21 +82,16 @@ static char *
 song_tag_locale(const struct mpd_song *song, enum mpd_tag_type tag)
 {
        const char *value = mpd_song_get_tag(song, tag, 0);
-       char *result;
-#ifndef NCMPC_MINI
-       char *all;
-#endif /* !NCMPC_MINI */
-
        if (value == NULL)
                return NULL;
 
 #ifndef NCMPC_MINI
-       all = song_more_tag_values(song, tag, value);
+       char *all = song_more_tag_values(song, tag, value);
        if (all != NULL)
                value = all;
 #endif /* !NCMPC_MINI */
 
-       result = utf8_to_locale(value);
+       char *result = utf8_to_locale(value);
 
 #ifndef NCMPC_MINI
        g_free(all);
@@ -114,19 +107,18 @@ _strfsong(gchar *s,
          const struct mpd_song *song,
          const gchar **last)
 {
-       const gchar *p, *end;
-       gchar *temp;
-       gsize n, length = 0;
-       gboolean found = FALSE;
+       bool found = false;
        /* "missed" helps handling the case of mere literal text like
-          found==TRUE instead of found==FALSE. */
-       gboolean missed = FALSE;
+          found==true instead of found==false. */
+       bool missed = false;
 
        s[0] = '\0';
 
        if (song == NULL)
                return 0;
 
+       const char *p;
+       size_t length = 0;
        for (p = format; *p != '\0' && length<max;) {
                /* OR */
                if (p[0] == '|') {
@@ -134,7 +126,7 @@ _strfsong(gchar *s,
                        if(missed && !found) {
                                s[0] = '\0';
                                length = 0;
-                               missed = FALSE;
+                               missed = false;
                        } else {
                                p = skip(p);
                        }
@@ -147,21 +139,21 @@ _strfsong(gchar *s,
                        if(missed && !found) {
                                p = skip(p);
                        } else {
-                               found = FALSE;
-                               missed = FALSE;
+                               found = false;
+                               missed = false;
                        }
                        continue;
                }
 
                /* EXPRESSION START */
                if (p[0] == '[') {
-                       temp = g_malloc0(max);
+                       char *temp = g_malloc0(max);
                        if( _strfsong(temp, max, p+1, song, &p) >0 ) {
                                g_strlcat(s, temp, max);
                                length = strlen(s);
-                               found = TRUE;
+                               found = true;
                        } else {
-                               missed = TRUE;
+                               missed = true;
                        }
                        g_free(temp);
                        continue;
@@ -196,12 +188,12 @@ _strfsong(gchar *s,
                /* advance past the esc character */
 
                /* find the extent of this format specifier (stop at \0, ' ', or esc) */
-               temp = NULL;
-               end  = p+1;
+               char *temp = NULL;
+               const char *end = p + 1;
                while(*end >= 'a' && *end <= 'z') {
                        end++;
                }
-               n = end - p + 1;
+               size_t n = end - p + 1;
                if(*end != '%')
                        n--;
                else if (strncmp("%file%", p, n) == 0)
@@ -273,11 +265,11 @@ _strfsong(gchar *s,
                        length+=templen;
                        g_free(ident);
 
-                       missed = TRUE;
+                       missed = true;
                } else {
                        gsize templen = strlen(temp);
 
-                       found = TRUE;
+                       found = true;
                        if( length+templen > max )
                                templen = max-length;
                        g_strlcat(s, temp, max);
index 4d232566565a3e0b75f71f9d109c6cca187573c9..e8b913804a984a9761fe0ce9f97087df79ff6030 100644 (file)
@@ -59,9 +59,6 @@ title_bar_paint(const struct title_bar *p, const char *title,
                const struct mpd_status *status)
 {
        WINDOW *w = p->window.w;
-       int volume;
-       char flags[5];
-       char buf[32];
 
        assert(p != NULL);
 
@@ -96,7 +93,8 @@ title_bar_paint(const struct title_bar *p, const char *title,
 #endif
        }
 
-       volume = get_volume(status);
+       int volume = get_volume(status);
+       char buf[32];
        if (volume < 0)
                g_snprintf(buf, 32, _("Volume n/a"));
        else
@@ -105,6 +103,7 @@ title_bar_paint(const struct title_bar *p, const char *title,
        colors_use(w, COLOR_TITLE);
        mvwaddstr(w, 0, p->window.cols - utf8_width(buf), buf);
 
+       char flags[5];
        flags[0] = 0;
        if (status != NULL) {
                if (mpd_status_get_repeat(status))
index 6fdcbc764fcff2faee70cec4dec620a590c105ca..fb79aeb39af8520265d0d2983cb21c8cffd477ea 100644 (file)
@@ -76,15 +76,13 @@ GList *
 gcmp_list_from_path(struct mpdclient *c, const gchar *path,
                    GList *list, gint types)
 {
-       struct mpd_connection *connection;
-       struct mpd_entity *entity;
-
-       connection = mpdclient_get_connection(c);
+       struct mpd_connection *connection = mpdclient_get_connection(c);
        if (connection == NULL)
                return list;
 
        mpd_send_list_meta(connection, path);
 
+       struct mpd_entity *entity;
        while ((entity = mpd_recv_entity(connection)) != NULL) {
                char *name;
 
@@ -136,37 +134,35 @@ format_duration_short(char *buffer, size_t length, unsigned duration)
 void
 format_duration_long(char *p, size_t length, unsigned long duration)
 {
-       const char *year = _("year");
-       const char *years = _("years");
-       const char *week = _("week");
-       const char *weeks = _("weeks");
-       const char *day = _("day");
-       const char *days = _("days");
        unsigned bytes_written = 0;
 
        if (duration / 31536000 > 0) {
                if (duration / 31536000 == 1)
-                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, year);
+                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, _("year"));
                else
-                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 31536000, years);
+                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 31536000, _("years"));
                duration %= 31536000;
                length -= bytes_written;
                p += bytes_written;
        }
        if (duration / 604800 > 0) {
                if (duration / 604800 == 1)
-                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, week);
+                       bytes_written = g_snprintf(p, length, "%d %s, ",
+                                                  1, _("week"));
                else
-                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 604800, weeks);
+                       bytes_written = g_snprintf(p, length, "%lu %s, ",
+                                                  duration / 604800, _("weeks"));
                duration %= 604800;
                length -= bytes_written;
                p += bytes_written;
        }
        if (duration / 86400 > 0) {
                if (duration / 86400 == 1)
-                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, day);
+                       bytes_written = g_snprintf(p, length, "%d %s, ",
+                                                  1, _("day"));
                else
-                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 86400, days);
+                       bytes_written = g_snprintf(p, length, "%lu %s, ",
+                                                  duration / 86400, _("days"));
                duration %= 86400;
                length -= bytes_written;
                p += bytes_written;
index 45c2603bd3a87ea833ed5e89e78420ceb44a4086..dc0fe627094f63b66290ca4deff6f84ece8e0e83 100644 (file)
@@ -85,17 +85,13 @@ static unsigned
 byte_to_screen(const gchar *data, size_t x)
 {
 #if defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)
-       gchar *dup;
-       char *p;
-       unsigned width;
-
        assert(x <= strlen(data));
 
-       dup = g_strdup(data);
+       char *dup = g_strdup(data);
        dup[x] = 0;
-       p = replace_locale_to_utf8(dup);
+       char *p = replace_locale_to_utf8(dup);
 
-       width = utf8_width(p);
+       unsigned width = utf8_width(p);
        g_free(p);
 
        return width;
@@ -113,13 +109,11 @@ screen_to_bytes(const gchar *data, unsigned width)
 #if defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)
        size_t length = strlen(data);
        gchar *dup = g_strdup(data);
-       char *p;
-       unsigned p_width;
 
        while (true) {
                dup[length] = 0;
-               p = locale_to_utf8(dup);
-               p_width = utf8_width(p);
+               char *p = locale_to_utf8(dup);
+               unsigned p_width = utf8_width(p);
                g_free(p);
                if (p_width <= width)
                        break;
@@ -162,14 +156,13 @@ right_align_bytes(const gchar *data, size_t right, unsigned width)
        while (dup[start] != 0) {
                char *p = locale_to_utf8(dup + start), *q;
                unsigned p_width = utf8_width(p);
-               gunichar c;
 
                if (p_width < width) {
                        g_free(p);
                        break;
                }
 
-               c = g_utf8_get_char(p);
+               gunichar c = g_utf8_get_char(p);
                p[g_unichar_to_utf8(c, NULL)] = 0;
                q = utf8_to_locale(p);
                g_free(p);
@@ -194,15 +187,13 @@ next_char_size(const gchar *data)
 {
 #if defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)
        char *p = locale_to_utf8(data), *q;
-       gunichar c;
-       size_t size;
 
-       c = g_utf8_get_char(p);
+       gunichar c = g_utf8_get_char(p);
        p[g_unichar_to_utf8(c, NULL)] = 0;
        q = utf8_to_locale(p);
        g_free(p);
 
-       size = strlen(q);
+       size_t size = strlen(q);
        g_free(q);
 
        return size;
@@ -218,16 +209,14 @@ static inline size_t
 prev_char_size(const gchar *data, size_t x)
 {
 #if defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)
-       char *p = locale_to_utf8(data), *q;
-       gunichar c;
-       size_t size;
-
        assert(x > 0);
 
-       q = p;
+       char *p = locale_to_utf8(data);
+
+       char *q = p;
        while (true) {
-               c = g_utf8_get_char(q);
-               size = g_unichar_to_utf8(c, NULL);
+               gunichar c = g_utf8_get_char(q);
+               size_t size = g_unichar_to_utf8(c, NULL);
                if (size > x)
                        size = x;
                x -= size;
@@ -249,12 +238,10 @@ prev_char_size(const gchar *data, size_t x)
 /* move the cursor one step to the right */
 static inline void cursor_move_right(struct wreadln *wr)
 {
-       size_t size;
-
        if (wr->line[wr->cursor] == 0)
                return;
 
-       size = next_char_size(wr->line + wr->cursor);
+       size_t size = next_char_size(wr->line + wr->cursor);
        wr->cursor += size;
        if (cursor_column(wr) >= wr->width)
                wr->start = right_align_bytes(wr->line, wr->cursor, wr->width);
@@ -263,12 +250,10 @@ static inline void cursor_move_right(struct wreadln *wr)
 /* move the cursor one step to the left */
 static inline void cursor_move_left(struct wreadln *wr)
 {
-       size_t size;
-
        if (wr->cursor == 0)
                return;
 
-       size = prev_char_size(wr->line, wr->cursor);
+       size_t size = prev_char_size(wr->line, wr->cursor);
        assert(wr->cursor >= size);
        wr->cursor -= size;
        if (wr->cursor < wr->start)
@@ -329,7 +314,6 @@ wreadln_insert_byte(struct wreadln *wr, gint key)
                .fd = 0,
                .events = POLLIN,
        };
-       int ret;
 
        /* wide version: try to complete the multibyte sequence */
 
@@ -340,8 +324,7 @@ wreadln_insert_byte(struct wreadln *wr, gint key)
 
                /* poll for more bytes on stdin, without timeout */
 
-               ret = poll(&pfd, 1, 0);
-               if (ret <= 0)
+               if (poll(&pfd, 1, 0) <= 0)
                        /* no more input from keyboard */
                        break;
 
@@ -369,12 +352,10 @@ wreadln_insert_byte(struct wreadln *wr, gint key)
 static void
 wreadln_delete_char(struct wreadln *wr, size_t x)
 {
-       size_t rest, length;
-
        assert(x < strlen(wr->line));
 
-       length = next_char_size(&wr->line[x]);
-       rest = strlen(&wr->line[x + length]) + 1;
+       size_t length = next_char_size(&wr->line[x]);
+       size_t rest = strlen(&wr->line[x + length]) + 1;
        memmove(&wr->line[x], &wr->line[x + length], rest);
 }
 
@@ -396,8 +377,6 @@ _wreadln(WINDOW *w,
                .start = 0,
        };
        GList *hlist = NULL, *hcurrent = NULL;
-       gint key = 0;
-       size_t i;
 
 #ifdef NCMPC_MINI
        (void)gcmp;
@@ -449,17 +428,20 @@ _wreadln(WINDOW *w,
                drawline(&wr);
        }
 
+       gint key = 0;
        while (key != 13 && key != '\n') {
                key = wgetch(w);
 
                /* check if key is a function key */
-               for (i = 0; i < 63; i++)
+               for (size_t i = 0; i < 63; i++)
                        if (key == (int)KEY_F(i)) {
                                key = KEY_F(1);
                                i = 64;
                        }
 
                switch (key) {
+                       size_t i;
+
 #ifdef HAVE_GETMOUSE
                case KEY_MOUSE: /* ignore mouse events */
 #endif