summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e3a6567)
raw | patch | inline | side by side (parent: e3a6567)
author | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 18:52:09 +0000 (19:52 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 18:52:09 +0000 (19:52 +0100) |
37 files changed:
diff --git a/src/charset.c b/src/charset.c
index 909e77656faca5a9b18bf769271f0afa8956da3a..61d7dac70dbcbb3ef4774b34c2c0189a8a914c29 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
{
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) {
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);
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);
diff --git a/src/colors.c b/src/colors.c
index 06362623bf9fa43bc391aae339fef4851993e25c..449d372777686d5ee38acb34634ad99de77b4340 100644 (file)
--- a/src/colors.c
+++ b/src/colors.c
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];
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 */
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) */
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;
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;
_("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);
}
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
diff --git a/src/conf.c b/src/conf.c
index 87fa51e7a05e2b356dc9118d81f09975438bb6af..83c11c5f194b6359ffdd16a202355b64e98914e8 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
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);
/* 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) {
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 */
static int
parse_color(char *str)
{
- char *value;
-
- value = separate_value(str);
+ char *value = separate_value(str);
if (value == NULL)
return -1;
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) {
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)
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++];
i++;
/* get the value part */
+ char value[MAX_LINE_LENGTH];
j = 0;
while (i < len)
value[j++] = line[i++];
{
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);
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)) {
return 0;
}
- retval = g_mkdir(directory, 0755);
+ int retval = g_mkdir(directory, 0755);
g_free(directory);
return retval;
}
diff --git a/src/filelist.c b/src/filelist.c
index 6a5ade39a06ba90ad14fa7c64760e60141021e95..a5b7a136468874e3db6460ed3c7e78e18aa04e23 100644 (file)
--- a/src/filelist.c
+++ b/src/filelist.c
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)
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));
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)) {
void
filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func)
{
- unsigned first, last;
const struct mpd_entity *iter;
assert(filelist && filelist->entries);
/* 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++) {
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;
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;
diff --git a/src/gidle.c b/src/gidle.c
index 95ac64621aea80b26070b9470e0415dbe88f01d1..ca07fefbaf34a457c053f66d597797e06fd946c8 100644 (file)
--- a/src/gidle.c
+++ b/src/gidle.c
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;
}
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;
/* 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;
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;
bool
mpd_glib_enter(struct mpd_glib_source *source)
{
- bool success;
-
assert(source->io_events == 0);
assert(source->id == 0);
assert(!source->destroyed);
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;
}
bool
mpd_glib_leave(struct mpd_glib_source *source)
{
- enum mpd_idle events;
-
assert(!source->destroyed);
if (source->id == 0)
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);
diff --git a/src/hscroll.c b/src/hscroll.c
index cc2aa9c430e4a37262441d363ec4c3b9216ce302..72f6a5d2255ec87a4daf71d1020397182639c9e6 100644 (file)
--- a/src/hscroll.c
+++ b/src/hscroll.c
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 */
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);
diff --git a/src/list_window.c b/src/list_window.c
index ad2ae77cc1f588b7e691d17b2079756f148dda62..387b7766b4f2d1fdfa3ad6855b049a5cd3ae6a06 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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) {
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,
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) {
break;
}
- selected = show_cursor &&
+ bool selected = show_cursor &&
lw->start + i >= range.start &&
lw->start + i < range.end;
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)) {
bool bell_on_wrap)
{
int i = lw->selected - 1;
- const char *label;
assert(str != NULL);
do {
while (i >= 0) {
- label = callback(i, callback_data);
+ const char *label = callback(i, callback_data);
assert(label != NULL);
if (match_line(label, str)) {
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) {
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)) {
diff --git a/src/main.c b/src/main.c
index d49d40beaac10c8a871c45d4b646ce4231eccf86..6d0633e82d3f2a1f6e2fe87e933b6bc13fa08e12 100644 (file)
--- a/src/main.c
+++ b/src/main.c
update_xterm_title(void)
{
static char title[BUFSIZE];
- char tmp[BUFSIZE];
struct mpd_status *status = NULL;
const struct mpd_song *song = NULL;
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);
static gboolean
timer_reconnect(gcc_unused gpointer data)
{
- bool success;
- struct mpd_connection *connection;
-
assert(!mpdclient_is_connected(mpd));
reconnect_source_id = 0;
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 */
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;
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 */
#ifndef WIN32
/* setup signal behavior - SIGINT */
+ struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = catch_sigint;
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);
#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]);
diff --git a/src/match.c b/src/match.c
index 81a70f7f7d48fcd137434a82febec112880fa401..03b806d5abe76b066ac49c4672c41ed466400525 100644 (file)
--- a/src/match.c
+++ b/src/match.c
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);
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);
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 359a765119f8045d877d48a6bedce252ced4a39d..9baf70bc7134fa8d2125f4ff463660052eb3ff82 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
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);
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;
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;
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;
mpdclient_cmd_clear(struct mpdclient *c)
{
struct mpd_connection *connection = mpdclient_get_connection(c);
- struct mpd_status *status;
-
if (connection == NULL)
return false;
/* 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;
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;
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);
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;
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) */
c->events |= MPD_IDLE_QUEUE;
- status = mpdclient_recv_status(c);
+ struct mpd_status *status = mpdclient_recv_status(c);
if (status == NULL)
return false;
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;
c->events |= MPD_IDLE_QUEUE;
- status = mpdclient_recv_status(c);
+ struct mpd_status *status = mpdclient_recv_status(c);
if (status == NULL)
return false;
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;
c->events |= MPD_IDLE_QUEUE;
- status = mpdclient_recv_status(c);
+ struct mpd_status *status = mpdclient_recv_status(c);
if (status == NULL)
return false;
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));
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);
/* 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;
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;
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;
diff --git a/src/options.c b/src/options.c
index 6f674c6cd61b9d3736dfd27ebfd87d2ea224813b..0a453e23a51ea403885a878782208ddac6b70506 100644 (file)
--- a/src/options.c
+++ b/src/options.c
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)
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);
diff --git a/src/player_command.c b/src/player_command.c
index 9969d12257a81575879bbbc30ce9389b68d3af82..d4ff4ae280830e749adee8f1ce6ae01aaffc093f 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
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;
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);
diff --git a/src/playlist.c b/src/playlist.c
index 8ec007be47d27b2ff61e0dc735aae805eba1e767..6f452a8f1c6c7a202fe343601a54624e8ad33240 100644 (file)
--- a/src/playlist.c
+++ b/src/playlist.c
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);
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],
diff --git a/src/plugin.c b/src/plugin.c
index 29e4ffcd1a47a39dca5ec89c7fac6c1a9ac4648a..64e61ab73d2b1c31ade1bce65fcd8c5cf3664083 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
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);
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);
}
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;
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) {
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)
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;
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);
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]);
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);
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;
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;
diff --git a/src/progress_bar.c b/src/progress_bar.c
index 601b7ba3fa55ee3650a56d3329b84a66d85641b4..590b7bef974dce5e7c80ca60aab1cca0be28e31c 100644 (file)
--- a/src/progress_bar.c
+++ b/src/progress_bar.c
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);
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;
diff --git a/src/screen.c b/src/screen.c
index 4050add277367c224a45b949ffc010a9e8a73b0d..b272935fe2c04bda83531609fbc87016c60d14f6 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
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);
}
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))
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;
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 5ff6f9b81c8d258128fab32783c5da9b1de7b95a..077fca52bd61ccf442e88d1cafba8229feb347ad 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
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;
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)
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);
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);
}
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;
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
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);
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:
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 6c802f6e87aaa2a0654a0ce7b42c2d88d4598cdb..0835241ed2c9f46852c257620f70d1baa51bd14d 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
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;
{
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 "..";
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;
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);
}
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;
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)
browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd)
{
- const struct mpd_song *song;
-
if (browser->filelist == NULL)
return false;
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:
return false;
switch (cmd) {
+ const struct mpd_song *song;
+
case CMD_PLAY:
browser_handle_enter(browser, c);
return true;
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)));
diff --git a/src/screen_chat.c b/src/screen_chat.c
index f30da93bb980b292c61ca9391eec9f93340efbb8..b4c80fbce14c1432042a5519325444ba0fa8a94d 100644 (file)
--- a/src/screen_chat.c
+++ b/src/screen_chat.c
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);
diff --git a/src/screen_client.c b/src/screen_client.c
index b8e936fdbc0fe6147edd4bbd961f2c590551368d..6eb9bf4964de2f2950a60ae021fd65346eac0a46 100644 (file)
--- a/src/screen_client.c
+++ b/src/screen_client.c
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;
if (recursion > 2)
return false;
- password = screen_read_password(NULL);
+ char *password = screen_read_password(NULL);
if (password == NULL)
return false;
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 &&
diff --git a/src/screen_file.c b/src/screen_file.c
index da7969b7221d00e1da14d845551bf6f449799a61..175e7866ab2ea1e0285d62c762a7e58a81c504dd 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
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);
{
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)
}
}
+ char *defaultname_utf8 = NULL;
if(defaultname)
defaultname_utf8 = utf8_to_locale(defaultname);
playlist_save(c, NULL, defaultname_utf8);
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 =
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
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);
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) {
/* 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);
{
const char *uri, *slash, *parent;
char *allocated = NULL;
- bool ret;
- int i;
assert(song != NULL);
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;
diff --git a/src/screen_find.c b/src/screen_find.c
index 3fdf9f30dd923914723c2e85658161e95a8a322f..5f2277288bacd4905ca4b4c13f9f30b1d49a70c8 100644 (file)
--- a/src/screen_find.c
+++ b/src/screen_find.c
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:
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;
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);
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);
/* 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;
}
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index ad78c383d48b235ec6a12bc9f1ab8659c8821819..dde5ce571321e56f8aebd75500a264424775799e 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
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));
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);
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) {
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));
{
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);
}
diff --git a/src/screen_list.c b/src/screen_list.c
index 5ef6ddba172224f0168389df77aec598c0b573b0..e7cd694bf43d6ee6768fe0e621d459be6a924a20 100644 (file)
--- a/src/screen_list.c
+++ b/src/screen_list.c
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)
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)
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)
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;
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;
diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c
index cda976e0a05d058c55b16b0b0a3f5d9cf626a132..d6d1a6c3cf4c4ad64eedb420f06a70975b33c156 100644 (file)
--- a/src/screen_lyrics.c
+++ b/src/screen_lyrics.c
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);
}
create_lyr_file(const char *artist, const char *title)
{
char path[1024];
-
snprintf(path, 1024, "%s/.lyrics",
getenv("HOME"));
mkdir(path, S_IRWXU);
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));
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;
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);
lyrics_edit(void)
{
char *editor = options.text_editor;
- int status;
-
if (editor == NULL) {
screen_status_message(_("Editor not configured"));
return;
/* 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));
diff --git a/src/screen_outputs.c b/src/screen_outputs.c
index 5ec897dade076dfa2acbc01e6655fc797f2d7b25..e80d7bae50962af4320fcc6dc8182b4fdd342933 100644 (file)
--- a/src/screen_outputs.c
+++ b/src/screen_outputs.c
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))) {
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);
}
diff --git a/src/screen_queue.c b/src/screen_queue.c
index 87cdc63ad0a517c86c144d1652bafc75bb610af8..0d08bbcb63ce67f3eb8a5dec83681fbc1b74a77a 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
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);
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);
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;
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;
#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;
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) {
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
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
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();
return true;
}
- old_selected = lw->selected;
+ const unsigned old_selected = lw->selected;
list_window_set_cursor(lw, lw->start + row);
if (bstate & BUTTON1_CLICKED) {
{
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;
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)
diff --git a/src/screen_search.c b/src/screen_search.c
index 42253d0ad8c2d4c423a5c75c453929569119b9bc..0d39ddb151e76c6b7b7a32fd8b520d8bef778ac7 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
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))
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) {
}
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;
diff --git a/src/screen_song.c b/src/screen_song.c
index 32f1b85eaa50c6d289ecd6d5997e733ad3ff9063..6d3a0342a7c592eed21b0083e05915592db900e9 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
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);
/* +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 */
/* 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;
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);
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);
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);
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));
}
/* 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);
diff --git a/src/screen_status.c b/src/screen_status.c
index ca61fee17186304b3252720673c1cc8f8d6f563a..d122190bea79658eca9db785261da529d7dee394 100644 (file)
--- a/src/screen_status.c
+++ b/src/screen_status.c
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);
diff --git a/src/screen_text.c b/src/screen_text.c
index 44fe492e9ca0a6c16fbad7ab662ed81333f1a629..938d65627d69a2f63e1857d01656312dd3f7e3c1 100644 (file)
--- a/src/screen_text.c
+++ b/src/screen_text.c
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 */
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);
diff --git a/src/screen_utils.c b/src/screen_utils.c
index 8889ac13277b8b8cb0b2edf53609847bc469ae80..1c1f14b189c2cd71ac8252b7ab1aecd2adfe418a 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
screen_getch(const char *prompt)
{
WINDOW *w = screen.status_bar.window.w;
- int key = -1;
colors_use(w, COLOR_STATUS_ALERT);
werase(w);
echo();
curs_set(1);
+ int key;
while ((key = wgetch(w)) == ERR)
;
{
struct window *window = &screen.status_bar.window;
WINDOW *w = window->w;
- char *ret;
wmove(w, 0,0);
curs_set(1);
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;
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)
}
colors_use(w, COLOR_STATUS_ALERT);
+
+ unsigned y = 0;
while (y < screen.main_window.rows) {
GList *item = g_list_nth(list, y+offset);
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);
diff --git a/src/status_bar.c b/src/status_bar.c
index b1b301fd3df15524cbe4c4a60f29c9affe09e8bc..2294fe1e9230291d38acf9c8921d1739b076c072 100644 (file)
--- a/src/status_bar.c
+++ b/src/status_bar.c
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
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:");
break;
}
+ int x = 0;
if (str) {
waddstr(w, str);
x += utf8_width(str) + 1;
diff --git a/src/strfsong.c b/src/strfsong.c
index 00bcd87f3c6255bf2efab0fdfa8ba3bb2dff83f4..5107ba0bd2606f9a8cc28fecf9159701b0b3988a 100644 (file)
--- a/src/strfsong.c
+++ b/src/strfsong.c
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);
}
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);
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] == '|') {
if(missed && !found) {
s[0] = '\0';
length = 0;
- missed = FALSE;
+ missed = false;
} else {
p = skip(p);
}
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;
/* 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)
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);
diff --git a/src/title_bar.c b/src/title_bar.c
index 4d232566565a3e0b75f71f9d109c6cca187573c9..e8b913804a984a9761fe0ce9f97087df79ff6030 100644 (file)
--- a/src/title_bar.c
+++ b/src/title_bar.c
const struct mpd_status *status)
{
WINDOW *w = p->window.w;
- int volume;
- char flags[5];
- char buf[32];
assert(p != NULL);
#endif
}
- volume = get_volume(status);
+ int volume = get_volume(status);
+ char buf[32];
if (volume < 0)
g_snprintf(buf, 32, _("Volume n/a"));
else
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))
diff --git a/src/utils.c b/src/utils.c
index 6fdcbc764fcff2faee70cec4dec620a590c105ca..fb79aeb39af8520265d0d2983cb21c8cffd477ea 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
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;
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;
diff --git a/src/wreadln.c b/src/wreadln.c
index 45c2603bd3a87ea833ed5e89e78420ceb44a4086..dc0fe627094f63b66290ca4deff6f84ece8e0e83 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
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;
#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;
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);
{
#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;
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;
/* 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);
/* 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)
.fd = 0,
.events = POLLIN,
};
- int ret;
/* wide version: try to complete the multibyte sequence */
/* 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;
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);
}
.start = 0,
};
GList *hlist = NULL, *hcurrent = NULL;
- gint key = 0;
- size_t i;
#ifdef NCMPC_MINI
(void)gcmp;
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