commit e157546ebfbc00c5320cb7733aee7d04ac825761
parent c6edbfaf55df1a72634934a0b4e85497b2c1bee4
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Wed, 25 Aug 2021 21:57:15 -0700
Simplify player struct
Use the first argument as the program path and replace it with
'apsplayer' after forking.
Diffstat:
4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/aps/aps.c b/aps/aps.c
@@ -48,7 +48,7 @@ aps_open(char *path, char **player)
aps->pfds[i].events = POLLIN | POLLOUT;
}
- aps->player = pnew(player[0], player + 1);
+ aps->player = pnew(player);
if (aps->player == NULL) {
aps_close(aps);
return NULL;
diff --git a/aps/config.h b/aps/config.h
@@ -1,7 +1,6 @@
static char *player[] = {
- /* "" = path */
- /* prog, arg, ... */
- "ffplay", "apsplayer", "-loglevel", "error", "-nodisp", "-autoexit", "", NULL
+ /* Carot replaced by item path */
+ "ffplay", "-loglevel", "error", "-nodisp", "-autoexit", "^", NULL
};
static int timeout = 250;
diff --git a/aps/player.c b/aps/player.c
@@ -31,6 +31,7 @@
int
pstart(struct player *p)
{
+ char *prog;
int i;
if (p->state & (RUNNING | SUSPENDED)) {
@@ -45,12 +46,16 @@ pstart(struct player *p)
p->state = RUNNING;
return 0;
}
+
+ prog = p->argv[0];
+ p->argv[0] = "apsplayer";
for (i = 0; p->argv[i] != NULL; ++i)
- if (p->argv[i][0] == '\0')
+ if (strcmp(p->argv[i], "^") == 0)
p->argv[i] = p->path;
- execvp(p->prog, p->argv);
- perror(p->prog);
+
+ execvp(prog, p->argv);
+ perror(prog);
_exit(1);
}
@@ -154,12 +159,11 @@ pfree(struct player *p)
pstop(p);
argfree(p->argv);
free(p->path);
- free(p->prog);
free(p);
}
struct player *
-pnew(char *prog, char **argv)
+pnew(char **argv)
{
struct player *p;
@@ -167,8 +171,8 @@ pnew(char *prog, char **argv)
if (p == NULL)
return p;
- if ((p->prog = strdup(prog)) == NULL ||
- (p->argv = argdup(argv, arglen(argv))) == NULL) {
+ p->argv = argdup(argv, arglen(argv));
+ if (p->argv == NULL) {
pfree(p);
return NULL;
}
diff --git a/aps/player.h b/aps/player.h
@@ -10,7 +10,6 @@ enum pstate {
struct player {
char **argv;
char *path;
- char *prog;
enum pstate state;
pid_t pid;
};
@@ -23,4 +22,4 @@ int pplay(struct player *, char *);
int ptoggle(struct player *);
void pupdate(struct player *, int);
void pfree(struct player *);
-struct player *pnew(char *, char **);
+struct player *pnew(char **);