Commit Diff


commit - 4c86871ab14f4311fe9cdf5ecc1b673baa181f70
commit + 14be015f3c563add60cb33ffcc0e69cdf57433d8
blob - 5a7e9925de5df941f9b4a4125173fe21e3f629ea
blob + ce92c23f936b012809b3081a4783a6873d5cf8bf
--- amused.h
+++ amused.h
@@ -69,6 +69,7 @@ enum actions {
 	STATUS,
 	PREV,
 	NEXT,
+	LOAD,
 };
 
 struct ctl_command;
@@ -76,6 +77,7 @@ struct ctl_command;
 struct parse_result {
 	enum actions		 action;
 	char			**files;
+	FILE			*file;
 	struct ctl_command	*ctl;
 };
 
blob - e114270c47715e7def09409e57b3bb68fa9a80f7
blob + 51e0ab98f5323f13c6edbc66247701cbb13e4721
--- control.c
+++ control.c
@@ -29,6 +29,7 @@
 #include <event.h>
 #include <imsg.h>
 #include <limits.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
blob - 4d52664ae3db887063c53cdee56f05de8970a9c6
blob + 02bbe15906490d60141f220f9f732cfa276ac027
--- ctl.c
+++ ctl.c
@@ -41,6 +41,7 @@ static struct imsgbuf *ibuf;
 
 int	ctl_noarg(struct parse_result *, int, char **);
 int	ctl_add(struct parse_result *, int, char **);
+int	ctl_load(struct parse_result *, int, char **);
 
 struct ctl_command ctl_commands[] = {
 	{ "play",	PLAY,		ctl_noarg,	"" },
@@ -54,6 +55,7 @@ struct ctl_command ctl_commands[] = {
 	{ "status",	STATUS,		ctl_noarg,	"" },
 	{ "next",	NEXT,		ctl_noarg,	"" },
 	{ "prev",	PREV,		ctl_noarg,	"" },
+	{ "load",	LOAD,		ctl_load,	"[file]", 1 },
 	{ NULL },
 };
 
@@ -285,6 +287,7 @@ ctlaction(struct parse_result *res)
 	case PREV:
 		imsg_compose(ibuf, IMSG_CTL_PREV, 0, 0, -1, NULL, 0);
 		break;
+	case LOAD:
 	case NONE:
 		/* action not expected */
 		fatalx("invalid action %u", res->action);
@@ -345,9 +348,63 @@ ctl_add(struct parse_result *res, int argc, char **arg
 	if (argc < 2)
 		ctl_usage(res->ctl);
 	res->files = argv+1;
+
+	if (pledge("stdio rpath", NULL) == -1)
+		fatal("pledge");
+
 	return ctlaction(res);
 }
+
+int
+ctl_load(struct parse_result *res, int argc, char **argv)
+{
+	const char	*file;
+	char		*line = NULL;
+	char		 path[PATH_MAX];
+	size_t		 linesize = 0;
+	ssize_t		 linelen;
 
+	if (argc < 2)
+		res->file = stdin;
+	else if (argc == 2) {
+		if ((res->file = fopen(argv[1], "r")) == NULL)
+			fatal("open %s", argv[1]);
+	} else
+		ctl_usage(res->ctl);
+
+	if (pledge("stdio rpath", NULL) == -1)
+		fatal("pledge");
+
+	imsg_compose(ibuf, IMSG_CTL_FLUSH, 0, 0, -1, NULL, 0);
+
+	while ((linelen = getline(&line, &linesize, res->file)) != -1) {
+		if (linelen == 0)
+			continue;
+		line[linelen-1] = '\0';
+		file = line;
+		if (file[0] == '>' && file[1] == ' ')
+			file += 2;
+		if (file[0] == ' ' && file[1] == ' ')
+			file += 2;
+
+		memset(&path, 0, sizeof(path));
+		if (realpath(file, path) == NULL) {
+			log_warn("realpath %s", file);
+			continue;
+		}
+
+		imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1,
+		    path, sizeof(path));
+	}
+
+	imsg_flush(ibuf);
+	free(line);
+	if (ferror(res->file))
+		fatal("getline");
+	fclose(res->file);
+	return 0;
+}
+
 static int
 sockconn(void)
 {
blob - ab861362cf2454ff1c6b8747c681a37bdb870959
blob + 665e02746dafe1fcaa4a1ff568c7b389d90a0e01
--- player.c
+++ player.c
@@ -27,6 +27,7 @@
 #include <poll.h>
 #include <signal.h>
 #include <sndio.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <imsg.h>