From 2419c04b9b4f1ab252b6a135254cf4555a11a1a4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 28 Mar 2016 16:55:58 +0000 Subject: [PATCH] play: Convert com_jmp() to lopsub. The command handler needs to check that there is a single argument which is an integer between 0 and 100. This check needs to be modified to use the lopsub primitives rather than accessing the argument vector directly. Unfortunately we can not perform the conversion of the string argument into an int value with lopsub since the given percentage is an unnamed option rather than an argument of an option. The patch also rewords the summary and the help text of the jmp subcommand slightly to be more clear. --- m4/lls/play_cmd.suite.m4 | 7 +++++++ play.c | 15 +++++++++++---- play.cmd | 5 ----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/m4/lls/play_cmd.suite.m4 b/m4/lls/play_cmd.suite.m4 index d2f12a05..744e7931 100644 --- a/m4/lls/play_cmd.suite.m4 +++ b/m4/lls/play_cmd.suite.m4 @@ -33,3 +33,10 @@ caption = list of commands key bindings map the colon key to this command, so pressing : in command mode activates insert mode. [/description] + +[subcommand jmp] + purpose = change playback position + non-opts-name = percent + [description] + The percent argument must be an integer between 0 and 100, inclusively. + [/description] diff --git a/play.c b/play.c index 2b43f355..95270754 100644 --- a/play.c +++ b/play.c @@ -955,14 +955,20 @@ static int com_bg(struct play_task *pt, } EXPORT_PLAY_CMD_HANDLER(bg); -static int com_jmp(struct play_task *pt, int argc, char **argv) +static int com_jmp(struct play_task *pt, struct lls_parse_result *lpr) { int32_t percent; int ret; + char *errctx; - if (argc != 2) - return -E_PLAY_SYNTAX; - ret = para_atoi32(argv[1], &percent); + ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); + if (ret < 0) { + if (errctx) + PARA_ERROR_LOG("%s\n", errctx); + free(errctx); + return ret; + } + ret = para_atoi32(lls_input(0, lpr), &percent); if (ret < 0) return ret; if (percent < 0 || percent > 100) @@ -978,6 +984,7 @@ static int com_jmp(struct play_task *pt, int argc, char **argv) kill_stream(pt); return 0; } +EXPORT_PLAY_CMD_HANDLER(jmp); static int com_ff(struct play_task *pt, int argc, char **argv) { diff --git a/play.cmd b/play.cmd index d6b1396f..8e2fb6ac 100644 --- a/play.cmd +++ b/play.cmd @@ -2,11 +2,6 @@ BN: play SF: play.c SN: list of commands --- -N: jmp -D: Jump to position in current file. -U: jmp -H: The argument should be an integer between 0 and 100. ---- N: ff D: Jump forwards or backwards. U: ff -- 2.30.2