shithub: riscv

Download patch

ref: 18521fc8c6a6d307013bafe2afad995ace0aea02
parent: a84f3ef5815f44ab6a610e8e174eb8ec0f03d6cc
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Oct 28 11:20:13 EDT 2021

mkplist: add -s option to enable "simple" sort (thanks qwx)

--- a/sys/man/1/zuke
+++ b/sys/man/1/zuke
@@ -3,6 +3,9 @@
 mkplist, zuke \- graphical music player
 .SH SYNOPSIS
 .B audio/mkplist
+[
+.B -s
+]
 .I directory/file/URL [...]
 .br
 .B audio/zuke
@@ -16,11 +19,15 @@
 .PP
 .I Zuke
 is a graphical music player that reads a playlist from standard input
-and presents an interface to play music.  Playlists are generated
-by
+and presents an interface to play music.
+.PP
+Playlists are generated by
 .IR mkplist ,
 which accepts files, directories, and URLs as its arguments,
-and writes the resulting playlist to standard output.
+and writes the resulting playlist to standard output. Option
+.B -s
+enables "simple" sorting of the entries of the playlist, where only
+full paths are compared.
 .PP
 Formats supported by
 .I zuke
--- a/sys/src/cmd/audio/zuke/mkplist.c
+++ b/sys/src/cmd/audio/zuke/mkplist.c
@@ -19,6 +19,7 @@
 static int numall;
 static int firstiscomposer;
 static int keepfirstartist;
+static int simplesort;
 
 static char *fmts[] =
 {
@@ -281,6 +282,9 @@
 	a = a_;
 	b = b_;
 
+	if(simplesort)
+		return cistrcmp(a->path, b->path);
+
 	ae = utfrrune(a->path, '/');
 	be = utfrrune(b->path, '/');
 	if(ae != nil && be != nil && (x = cistrncmp(a->path, b->path, MAX(ae-a->path, be-b->path))) != 0) /* different path */
@@ -313,6 +317,13 @@
 	return cistrcmp(a->path, b->path);
 }
 
+static void
+usage(void)
+{
+	fprint(2, "usage: %s [-s] directory/file/URL [...] > noise.plist\n", argv0);
+	exits("usage");
+}
+
 void
 main(int argc, char **argv)
 {
@@ -319,15 +330,21 @@
 	char *dir, wd[4096];
 	int i;
 
-	if(argc < 2){
-		fprint(2, "usage: mkplist DIR [DIR2 ...] > noise.plist\n");
-		exits("usage");
-	}
+	ARGBEGIN{
+	case 's':
+		simplesort = 1;
+		break;
+	default:
+		usage();
+	}ARGEND
+
+	if(argc < 1)
+		usage();
 	getwd(wd, sizeof(wd));
 
 	Binit(&out, 1, OWRITE);
 
-	for(i = 1; i < argc; i++){
+	for(i = 0; i < argc; i++){
 		if(strncmp(argv[i], "http://", 7) == 0 || strncmp(argv[i], "https://", 8) == 0){
 			if((curr = newmeta()) == nil)
 				sysfatal("no memory");