From 4062cc190a3b5a492cc156f2b001285e82555d08 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Thu, 16 Apr 2015 00:08:43 +0200 Subject: [PATCH] Streamline -s option by always requiring an option argument --- NEWS | 5 +++-- doc/ezstream.1.in.in | 10 ++++++---- src/ezstream.c | 29 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index be89615..f2b4455 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,10 @@ Changes in X.X.X, released on XXXX-XX-XX: * Windows is no longer actively supported. - * Certain legacy UNIX systems are no longer actively supported. - + * The behaviour of the -s command line argument was changed: + To shuffle lines from standard input, the special file name "-" needs + to be provided. Changes in 0.6.0, released on 2015-01-18: diff --git a/doc/ezstream.1.in.in b/doc/ezstream.1.in.in index 63b9893..16998e8 100644 --- a/doc/ezstream.1.in.in +++ b/doc/ezstream.1.in.in @@ -23,7 +23,7 @@ .Ek .Nm .Bk -words -.Fl s +.Fl s Ar playlistFile .Op Ar playlist .Ek .Sh DESCRIPTION @@ -53,13 +53,15 @@ Normalize metadata strings by removing excess whitespaces. .It Fl q Be more quiet. Suppress the output that external programs send to standard error. -.It Fl s Op Ar playlist +.It Fl s Ar playlist Run .Nm as a line-based shuffling utility. -If no +If a .Ar playlist -argument is given, a list of media file names is read from standard input +argument of +.Dq - +is given, a list of media file names is read from standard input instead of an input file. After successfully reading the entire list, it is shuffled and printed to standard output, and diff --git a/src/ezstream.c b/src/ezstream.c index a5a4247..69c495e 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -1110,6 +1110,7 @@ main(int argc, char *argv[]) { int c; char *configFile = NULL; + char *playlistFile = NULL; char *host = NULL; unsigned short port = 0; char *mount = NULL; @@ -1137,7 +1138,7 @@ main(int argc, char *argv[]) qFlag = 0; vFlag = 0; - while ((c = getopt(argc, argv, "c:hmnqsVv")) != -1) { + while ((c = getopt(argc, argv, "c:hmnqs:Vv")) != -1) { switch (c) { case 'c': if (configFile != NULL) { @@ -1162,6 +1163,12 @@ main(int argc, char *argv[]) break; case 's': sFlag = 1; + if (playlistFile != NULL) { + printf("Error: multiple -s arguments given\n"); + usage(); + return (ez_shutdown(2)); + } + playlistFile = xstrdup(optarg); break; case 'V': printf("%s\n", PACKAGE_STRING); @@ -1183,21 +1190,13 @@ main(int argc, char *argv[]) playlist_t *pl; const char *entry; - switch (argc) { - case 0: + if (0 == strcmp(playlistFile, "-")) pl = playlist_read(NULL); - if (pl == NULL) - return (ez_shutdown(1)); - break; - case 1: - pl = playlist_read(argv[0]); - if (pl == NULL) - return (ez_shutdown(1)); - break; - default: - printf("Error: Too many arguments.\n"); - return (ez_shutdown(2)); - } + else + pl = playlist_read(playlistFile); + + if (pl == NULL) + return (ez_shutdown(1)); playlist_shuffle(pl); while ((entry = playlist_get_next(pl)) != NULL)