shithub: zuke

Download patch

ref: 277e60764d872ef9fdd0fbe7c18bcf0a9d20499b
parent: 242c59a09d4de8026aa6a865651f92c03c5e441c
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Dec 24 10:45:54 EST 2019

mkplist: sort using paths mostly, take album difference into account; exits(nil)

--- a/mkplist.c
+++ b/mkplist.c
@@ -19,23 +19,6 @@
 static int firstiscomposer;
 static int keepfirstartist;
 
-static void
-freemeta(Meta *m)
-{
-	int i;
-
-	if(m != nil){
-		for(i = 0; i < m->numartist; i++)
-			free(m->artist[i]);
-		free(m->album);
-		free(m->title);
-		free(m->date);
-		free(m->track);
-		free(m->path);
-		numall--;
-	}
-}
-
 static Meta *
 newmeta(void)
 {
@@ -256,9 +239,17 @@
 	a = a_;
 	b = b_;
 
+	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 */
+		return x;
+
+	/* same path, must be the same album/cd, but first check */
 	for(i = 0; i < a->numartist && i < b->numartist; i++){
-		if((x = cistrcmp(a->artist[i], b->artist[i])) != 0)
-			return x;
+		if((x = cistrcmp(a->artist[i], b->artist[i])) != 0){
+			if(a->album != nil && b->album != nil && cistrcmp(a->album, b->album) != 0)
+				return x;
+		}
 	}
 
 	if(a->date != nil || b->date != nil){
@@ -271,11 +262,6 @@
 		if((x = cistrcmp(a->album, b->album)) != 0) return x;
 	}
 
-	ae = utfrrune(a->path, '/');
-	be = utfrrune(b->path, '/');
-	if(ae != nil && be != nil && (x = strncmp(a->path, b->path, MAX(ae-a->path, be-b->path))) != 0)
-		return x;
-
 	if(a->track != nil || b->track != nil){
 		if(a->track == nil && b->track != nil) return -1;
 		if(a->track != nil && b->track == nil) return 1;
@@ -310,4 +296,5 @@
 		printmeta(&all[i], i);
 	}
 	fprint(2, "found %d tagged tracks\n", numall);
+	exits(nil);
 }