X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=gui.c;h=64fab61b7859e5192a3d1583a693622be8977087;hp=4866979a2e93c197bd92a6679c7ff08de2af32f3;hb=9bf4bc297a7cb88f4f886c6b8d600fd6c584139c;hpb=8ea8abb73199b32fdd7afdf8825afa42ed8de244 diff --git a/gui.c b/gui.c index 4866979a..64fab61b 100644 --- a/gui.c +++ b/gui.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1998-2009 Andre Noll + * Copyright (C) 1998-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -45,7 +45,7 @@ struct rb_entry { size_t len; int color; }; -struct ringbuffer *bot_win_rb; +static struct ringbuffer *bot_win_rb; #define NUM_LINES(len) (1 + (len) / bot.cols) static unsigned scroll_position; @@ -91,8 +91,8 @@ struct stat_item { static struct gui_theme theme; -int _argc; -char **_argv; +static int _argc; +static char **_argv; static void com_help(void); static void com_reread_conf(void); @@ -110,7 +110,7 @@ static void com_scroll_down(void); static void com_page_up(void); static void com_page_down(void); -struct gui_command command_list[] = { +static struct gui_command command_list[] = { { .key = "?", .name = "help", @@ -309,7 +309,7 @@ static int align_str(WINDOW* win, char *str, unsigned int len, num = 0; } /* replace newlines by spaces */ - for (i = 0; i < len; i++) { + for (i = 0; i < len && str[i]; i++) { if (str[i] == '\n') str[i] = ' '; } @@ -679,8 +679,31 @@ static void print_stat_item(int i) static int update_item(int item_num, char *buf) { - free(stat_content[item_num]); - stat_content[item_num] = para_strdup(buf); + char **c = stat_content + item_num; + + free(*c); + if (buf && buf[0]) + goto dup; + switch (item_num) { + case SI_ARTIST: + *c = para_strdup("(artist tag not set)"); + goto print; + case SI_TITLE: + *c = para_strdup("(title tag not set)"); + goto print; + case SI_YEAR: + *c = para_strdup("????"); + goto print; + case SI_ALBUM: + *c = para_strdup("(album tag not set)"); + goto print; + case SI_COMMENT: + *c = para_strdup("(comment tag not set)"); + goto print; + } +dup: + *c = para_strdup(buf); +print: print_stat_item(item_num); return 1; } @@ -707,6 +730,8 @@ static int read_audiod_pipe(int fd) ret = for_each_stat_item(buf, loaded, update_item); if (ret < 0) return ret; + if (ret > 0 && ret < loaded) + memmove(buf, buf + loaded - ret, ret); loaded = ret; return 1; } @@ -1325,31 +1350,30 @@ static void handle_command(int c) /* first check user's key bindings */ for (i = 0; i < conf.key_map_given; ++i) { - char tmp[MAXLINE], *handler, *arg; + char *tmp, *handler, *arg; - strcpy(tmp, conf.key_map_arg[i]); - if (!split_key_map(tmp, &handler, &arg)) + tmp = para_strdup(conf.key_map_arg[i]); + if (!split_key_map(tmp, &handler, &arg)) { + free(tmp); return; - if (!strcmp(tmp, km_keyname(c))) { - if (*handler == 'd') { - display_cmd(arg); - return; - } - if (*handler == 'x') { - external_cmd(arg); - return; - } - if (*handler == 'p') { - client_cmd_cmdline(arg); - return; - } - if (*handler == 'i') { - int num = find_cmd_byname(arg); - if (num >= 0) - command_list[num].handler(); - return; - } } + if (strcmp(tmp, km_keyname(c))) { + free(tmp); + continue; + } + if (*handler == 'd') + display_cmd(arg); + else if (*handler == 'x') + external_cmd(arg); + else if (*handler == 'p') + client_cmd_cmdline(arg); + else if (*handler == 'i') { + int num = find_cmd_byname(arg); + if (num >= 0) + command_list[num].handler(); + } + free(tmp); + return; } /* not found, check internal key bindings */ for (i = 0; command_list[i].handler; i++) {