X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=play.c;h=034e0f6f189a54cb9e7d4cb365dec0c4dbcc66c0;hp=6e6b91f93865dd3623592098c339a181be2dbb6d;hb=53d5ac455d0616a5ee8867c986631ed34c177a42;hpb=b0a115ed731885c92fcd8b6fb1c89b97dca410e8 diff --git a/play.c b/play.c index 6e6b91f9..034e0f6f 100644 --- a/play.c +++ b/play.c @@ -13,7 +13,6 @@ #include "para.h" #include "list.h" #include "play.cmdline.h" -#include "filter.cmdline.h" #include "error.h" #include "ggo.h" #include "buffer_tree.h" @@ -37,6 +36,9 @@ * Playlist handling is done exclusively in play context. */ +/** Array of error strings. */ +DEFINE_PARA_ERRLIST; + /** * Describes a request to change the state of para_play. * @@ -96,9 +98,6 @@ struct play_task { char *afhi_txt; }; -/** Initialize the array of errors for para_play. */ -INIT_PLAY_ERRLISTS; - /* Activate the afh receiver. */ extern void afh_recv_init(struct receiver *r); #undef AFH_RECEIVER @@ -277,7 +276,8 @@ static int eof_cleanup(struct play_task *pt) memset(&pt->wn, 0, sizeof(struct writer_node)); task_reap(&pt->fn.task); - decoder->close(&pt->fn); + if (decoder->close) + decoder->close(&pt->fn); btr_remove_node(&pt->fn.btrn); free(pt->fn.conf); memset(&pt->fn, 0, sizeof(struct filter_node)); @@ -397,7 +397,8 @@ static int load_file(struct play_task *pt) pt->fn.btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = decoder->name, .parent = pt->rn.btrn, .handler = decoder->execute, .context = &pt->fn)); - decoder->open(&pt->fn); + if (decoder->open) + decoder->open(&pt->fn); /* setup default writer */ pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num); @@ -591,6 +592,28 @@ static char *get_key_map_seq(int key) get_internal_key_map_seq(key) : get_user_key_map_seq(key); } +static char *get_key_map_seq_safe(int key) +{ + const char hex[] = "0123456789abcdef"; + char *seq = get_key_map_seq(key), *sseq; + size_t n, len = strlen(seq); + + if (len == 1 && isprint(*seq)) + return seq; + sseq = para_malloc(2 + 2 * len + 1); + sseq[0] = '0'; + sseq[1] = 'x'; + for (n = 0; n < len; n++) { + uint8_t val = (seq[n] & 0xf0) >> 4; + sseq[2 + 2 * n] = hex[val]; + val = seq[n] & 0xf; + sseq[2 + 2 * n + 1] = hex[val]; + } + free(seq); + sseq[2 + 2 * n] = '\0'; + return sseq; +} + static inline char *get_internal_key_map_cmd(int key) { return para_strdup(default_commands[get_internal_key_map_idx(key)]); @@ -619,15 +642,8 @@ static char **get_mapped_keyseqs(void) result = para_malloc((NUM_MAPPED_KEYS + 1) * sizeof(char *)); FOR_EACH_MAPPED_KEY(i) { - int idx = get_key_map_idx(i); char *seq = get_key_map_seq(i); - char *cmd = get_key_map_cmd(i); - bool internal = is_internal_key(i); - PARA_DEBUG_LOG("%s key sequence #%d: %s -> %s\n", - internal? "internal" : "user-defined", - idx, seq, cmd); result[i] = seq; - free(cmd); } result[i] = NULL; return result; @@ -716,7 +732,7 @@ static int com_help(struct play_task *pt, int argc, char **argv) FOR_EACH_MAPPED_KEY(i) { bool internal = is_internal_key(i); int idx = get_key_map_idx(i); - char *seq = get_key_map_seq(i); + char *seq = get_key_map_seq_safe(i); char *cmd = get_key_map_cmd(i); sz = xasprintf(&buf, "%s key #%d: %s -> %s\n", @@ -921,6 +937,8 @@ static int com_jmp(struct play_task *pt, int argc, char **argv) return ret; if (percent < 0 || percent > 100) return -ERRNO_TO_PARA_ERROR(EINVAL); + if (percent == 100) + return com_next(pt, 1, (char *[]){"next", NULL}); if (pt->playing && !pt->fn.btrn) return 0; pt->start_chunk = percent * pt->num_chunks / 100;