ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit e15c83daaa362fcabd54a393c146d430d3370504
parent bc7e4fabd5482c72fda0764b6678665c1c65a5d6
Author: Jacob R. Edwards <n/a>
Date:   Mon, 10 Oct 2022 15:00:45 -0700

Simply append item path to player arguments

This required a small modification to argdup which allows the user
to allocate an argument array of any length. (Also, argsub uses the
length of the given arguments when a length of 0 is given.)

Diffstat:
Maps/arg.c | 8+++++---
Maps/config.h | 4++--
Maps/player.c | 10++++------
Maps/player.h | 1+
4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/aps/arg.c b/aps/arg.c @@ -1,5 +1,5 @@ /* - * Copyright 2021 Jacob R. Edwards + * Copyright 2021, 2022 Jacob R. Edwards * * ap -- audio player * @@ -38,17 +38,19 @@ argdup(char **args, unsigned int len) char **nargs; unsigned int i; + if (!len) + len = arglen(args); nargs = calloc(len + 1, sizeof(*args)); if (nargs == NULL) return NULL; - for (i = 0; i < len; ++i) { + for (i = 0; args[i] && i < len; ++i) { nargs[i] = strdup(args[i]); if (nargs[i] == NULL) break; } - if (i == len) + if (!args[i] || i == len) return nargs; for (i = 0; nargs[i] != NULL; ++i) diff --git a/aps/config.h b/aps/config.h @@ -1,4 +1,4 @@ static char *player[] = { - /* Carot replaced by item path */ - "ffplay", "-loglevel", "error", "-nodisp", "-autoexit", "^", NULL + /* The item's path is appended */ + "ffplay", "-loglevel", "error", "-nodisp", "-autoexit", NULL }; diff --git a/aps/player.c b/aps/player.c @@ -1,5 +1,5 @@ /* - * Copyright 2021 Jacob R. Edwards + * Copyright 2021, 2022 Jacob R. Edwards * * ap -- audio player * @@ -50,10 +50,7 @@ pstart(struct player *p) prog = p->argv[0]; p->argv[0] = "apsplayer"; - - for (i = 0; p->argv[i] != NULL; ++i) - if (strcmp(p->argv[i], "^") == 0) - p->argv[i] = p->path; + p->argv[p->argc] = p->path; execvp(prog, p->argv); perror(prog); @@ -172,7 +169,8 @@ pnew(char **argv) if (p == NULL) return p; - p->argv = argdup(argv, arglen(argv)); + p->argc = arglen(argv); + p->argv = argdup(argv, p->argc + 1); if (p->argv == NULL) { pfree(p); return NULL; diff --git a/aps/player.h b/aps/player.h @@ -9,6 +9,7 @@ enum pstate { struct player { char **argv; + int argc; char *path; enum pstate state; pid_t pid;