/** \file play.c Paraslash's standalone player. */
#include <regex.h>
-#include <fnmatch.h>
#include <signal.h>
#include <inttypes.h>
#include <lopsub.h>
}
EXPORT_PLAY_CMD_HANDLER(help);
-static int com_info(struct play_task *pt, int argc, __a_unused char **argv)
+static int com_info(struct play_task *pt,
+ __a_unused struct lls_parse_result *lpr)
{
char *buf;
size_t sz;
static char dflt[] = "[no information available]";
- if (argc != 1)
- return -E_PLAY_SYNTAX;
sz = xasprintf(&buf, "playlist_pos: %u\npath: %s\n",
pt->current_file, conf.inputs[pt->current_file]);
btr_add_output(buf, sz, pt->btrn);
btr_add_output_dont_free(buf, strlen(buf), pt->btrn);
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(info);
static void list_file(struct play_task *pt, int num)
{
return 0;
}
-static int com_ls(struct play_task *pt, int argc, char **argv)
+static int com_ls(struct play_task *pt,
+ __a_unused struct lls_parse_result *lpr)
{
- int i, j, ret;
+ int i;
- if (argc == 1) {
- FOR_EACH_PLAYLIST_FILE(i)
- list_file(pt, i);
- return 0;
- }
- for (j = 1; j < argc; j++) {
- FOR_EACH_PLAYLIST_FILE(i) {
- ret = fnmatch(argv[j], conf.inputs[i], 0);
- if (ret == 0) /* match */
- list_file(pt, i);
- }
- }
+ FOR_EACH_PLAYLIST_FILE(i)
+ list_file(pt, i);
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(ls);
static int com_play(struct play_task *pt, int argc, char **argv)
{
return 0;
}
-static int com_prev(struct play_task *pt, int argc, __a_unused char **argv)
-
+static int com_prev(struct play_task *pt,
+ __a_unused struct lls_parse_result *lpr)
{
int ret;
- if (argc != 1)
- return -E_PLAY_SYNTAX;
ret = previous_valid_file(pt);
if (ret < 0)
return ret;
pt->start_chunk = 0;
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(prev);
-static int com_next(struct play_task *pt, int argc, __a_unused char **argv)
+static int com_next(struct play_task *pt,
+ __a_unused struct lls_parse_result *lpr)
{
int ret;
- if (argc != 1)
- return -E_PLAY_SYNTAX;
ret = next_valid_file(pt);
if (ret < 0)
return ret;
pt->start_chunk = 0;
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(next);
static int com_fg(struct play_task *pt,
__a_unused struct lls_parse_result *lpr)
}
EXPORT_PLAY_CMD_HANDLER(fg);
-static int com_bg(struct play_task *pt, int argc, __a_unused char **argv)
+static int com_bg(struct play_task *pt,
+ __a_unused struct lls_parse_result *lpr)
{
- if (argc != 1)
- return -E_PLAY_SYNTAX;
pt->background = true;
return 0;
}
+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)
return -ERRNO_TO_PARA_ERROR(EINVAL);
if (percent == 100)
- return com_next(pt, 1, (char *[]){"next", NULL});
+ return com_next(pt, NULL);
if (pt->playing && !pt->fn.btrn)
return 0;
pt->start_chunk = percent * pt->num_chunks / 100;
kill_stream(pt);
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(jmp);
-static int com_ff(struct play_task *pt, int argc, char **argv)
+static int com_ff(struct play_task *pt, struct lls_parse_result *lpr)
{
int32_t seconds;
+ char *errctx;
int ret;
- if (argc != 2)
- return -E_PLAY_SYNTAX;
- ret = para_atoi32(argv[1], &seconds);
+ 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), &seconds);
if (ret < 0)
return ret;
if (pt->playing && !pt->fn.btrn)
kill_stream(pt);
return 0;
}
+EXPORT_PLAY_CMD_HANDLER(ff);
static int run_command(char *line, struct play_task *pt)
{