commit - 0e89621609ecbccc896bfc5614eb58894c98e6cd
commit + 4b42d3a3f30acc64f6720bf33c8f6d695577bf74
blob - 940c6f3e44493e581b166e148052859aef01f73e
blob + 11ac2583368d6c0ef18c232b16178c6977b0f86d
--- amused.h
+++ amused.h
struct parse_result {
enum actions action;
char **files;
- const char *file;
+ FILE *fp;
int pretty;
int monitor[IMSG__LAST];
struct player_repeat rep;
enum actions action;
int (*main)(struct parse_result *, int, char **);
const char *usage;
- int has_pledge;
};
struct playlist;
blob - 15c10f6fcb680c129ae25fad3452638e3a4dc10a
blob + 5dca2bb38b92fe3ed1c51b8bc848c8a5ae35c964
--- ctl.c
+++ ctl.c
static int ctl_status(struct parse_result *, int, char **);
struct ctl_command ctl_commands[] = {
- { "add", ADD, ctl_add, "files...", 0 },
- { "flush", FLUSH, ctl_noarg, "", 0 },
- { "jump", JUMP, ctl_jump, "pattern", 0 },
- { "load", LOAD, ctl_load, "[file]", 1 },
- { "monitor", MONITOR, ctl_monitor, "[events]", 0 },
- { "next", NEXT, ctl_noarg, "", 0 },
- { "pause", PAUSE, ctl_noarg, "", 0 },
- { "play", PLAY, ctl_noarg, "", 0 },
- { "prev", PREV, ctl_noarg, "", 0 },
- { "repeat", REPEAT, ctl_repeat, "one|all on|off", 0 },
- { "restart", RESTART, ctl_noarg, "", 0 },
- { "seek", SEEK, ctl_seek, "[+-]time[%]", 0 },
- { "show", SHOW, ctl_show, "[-p]", 0 },
- { "status", STATUS, ctl_status, "[-f fmt]", 0 },
- { "stop", STOP, ctl_noarg, "", 0 },
- { "toggle", TOGGLE, ctl_noarg, "", 0 },
- { NULL, 0, NULL, NULL, 0 },
+ { "add", ADD, ctl_add, "files..."},
+ { "flush", FLUSH, ctl_noarg, ""},
+ { "jump", JUMP, ctl_jump, "pattern"},
+ { "load", LOAD, ctl_load, "[file]"},
+ { "monitor", MONITOR, ctl_monitor, "[events]"},
+ { "next", NEXT, ctl_noarg, ""},
+ { "pause", PAUSE, ctl_noarg, ""},
+ { "play", PLAY, ctl_noarg, ""},
+ { "prev", PREV, ctl_noarg, ""},
+ { "repeat", REPEAT, ctl_repeat, "one|all on|off"},
+ { "restart", RESTART, ctl_noarg, ""},
+ { "seek", SEEK, ctl_seek, "[+-]time[%]"},
+ { "show", SHOW, ctl_show, "[-p]"},
+ { "status", STATUS, ctl_status, "[-f fmt]"},
+ { "stop", STOP, ctl_noarg, ""},
+ { "toggle", TOGGLE, ctl_noarg, ""},
+ { NULL, 0, NULL, NULL},
};
__dead void
res->action = ctl->action;
res->ctl = ctl;
- if (!ctl->has_pledge) {
- /* pledge(2) default if command doesn't have its own */
- if (pledge("stdio", NULL) == -1)
- fatal("pledge");
- }
-
status = ctl->main(res, argc, argv);
close(ibuf->fd);
free(ibuf);
static int
load_files(struct parse_result *res, int *ret)
{
- FILE *f;
const char *file;
char *line = NULL;
char path[PATH_MAX];
size_t linesize = 0, i = 0;
ssize_t linelen, curr = -1;
- if (res->file == NULL)
- f = stdin;
- else if ((f = fopen(res->file, "r")) == NULL) {
- log_warn("can't open %s", res->file);
- *ret = 1;
- return 1;
- }
-
- while ((linelen = getline(&line, &linesize, f)) != -1) {
+ while ((linelen = getline(&line, &linesize, res->fp)) != -1) {
if (linelen == 0)
continue;
line[linelen-1] = '\0';
}
free(line);
- if (ferror(f))
+ if (ferror(res->fp))
fatal("getline");
- fclose(f);
+ fclose(res->fp);
+ res->fp = NULL;
if (i == 0) {
*ret = 1;
ssize_t n;
int i, type, ret = 0, done = 1;
+ if (pledge("stdio", NULL) == -1)
+ fatal("pledge");
+
switch (res->action) {
case PLAY:
imsg_compose(ibuf, IMSG_CTL_PLAY, 0, 0, -1, NULL, 0);
case JUMP:
done = 0;
memset(path, 0, sizeof(path));
- strlcpy(path, res->file, sizeof(path));
+ strlcpy(path, res->files[0], sizeof(path));
imsg_compose(ibuf, IMSG_CTL_JUMP, 0, 0, -1,
path, sizeof(path));
break;
argc -= optind;
argv += optind;
- if (argc == 0)
- res->file = NULL;
- else if (argc == 1)
- res->file = argv[0];
- else
+ if (argc > 1)
ctl_usage(res->ctl);
- if (pledge("stdio rpath", NULL) == -1)
- fatal("pledge");
+ res->fp = stdin;
+ if (argc == 1) {
+ if ((res->fp = fopen(argv[0], "r")) == NULL)
+ fatal("can't open %s", argv[0]);
+ }
return ctlaction(res);
}
if (argc != 1)
ctl_usage(res->ctl);
- res->file = argv[0];
+ res->files = argv;
return ctlaction(res);
}
optreset = 1;
optind = 1;
+ /* we'll drop rpath too later in ctlaction */
+ if (pledge("stdio rpath", NULL) == -1)
+ fatal("pledge");
+
exit(parse(&res, argc, argv));
}
blob - 87b17682b388e6b44771cb6d6250b06508472d66
blob + 21f3b019133bd3132f1cae81b403ac3f8c9047ec
--- player_123.c
+++ player_123.c
#include <sys/stat.h>
#include <limits.h>
+#include <stdio.h>
#include <unistd.h>
#include <mpg123.h>