ref: 6af19b681fa8496e039d9549cb194c9f0aea2e72
parent: 146f6cafca4541da7573162a93ca24526d809bbd
author: Sigrid Haflínudóttir <[email protected]>
date: Thu Jun 25 10:50:04 EDT 2020
mkplist: read files as well
--- a/mkplist.c
+++ b/mkplist.c
@@ -129,13 +129,51 @@
.aux = nil,
};
+static void
+scanfile(char *path)
+{
+ int res;
+ char *s;
+
+ if((bf = Bopen(path, OREAD)) == nil){
+ fprint(2, "%s: %r\n", path);
+ return;
+ }
+ if((curr = newmeta()) == nil)
+ sysfatal("no memory");
+ firstiscomposer = keepfirstartist = 0;
+ res = tagsget(&ctx);
+ if(ctx.format != Funknown){
+ if(res != 0)
+ fprint(2, "%s: no tags\n", path);
+ }else{
+ numall--;
+ Bterm(bf);
+ return;
+ }
+
+ if(ctx.duration == 0)
+ fprint(2, "%s: no duration\n", path);
+ if(curr->title == nil){
+ if((s = utfrrune(path, '/')) == nil)
+ s = path;
+ curr->title = strdup(s+1);
+ }
+ curr->path = strdup(path);
+ curr->duration = ctx.duration;
+ if(ctx.format >= nelem(fmts))
+ sysfatal("mkplist needs a rebuild with updated libtags");
+ curr->filefmt = fmts[ctx.format];
+ Bterm(bf);
+}
+
static int
scan(char **dir, int depth)
{
- char *path, *s;
+ char *path;
Dir *buf, *d;
long n;
- int dirfd, len, res;
+ int dirfd, len;
if((dirfd = open(*dir, OREAD)) < 0)
sysfatal("%s: %r", *dir);
@@ -145,9 +183,12 @@
path = *dir;
path[len] = '/';
- for(;;){
- if((n = dirread(dirfd, &buf)) < 0)
- sysfatal("dirread: %r");
+ for(n = 0, buf = nil; n >= 0;){
+ if((n = dirread(dirfd, &buf)) < 0){
+ path[len] = 0;
+ scanfile(path);
+ break;
+ }
if(n == 0){
free(buf);
break;
@@ -163,36 +204,7 @@
sysfatal("Maxname=%d was a bad choice", Maxname);
if((d->mode & DMDIR) == 0){
- if((bf = Bopen(path, OREAD)) == nil)
- fprint(2, "%s: %r\n", path);
- else{
- if((curr = newmeta()) == nil)
- sysfatal("no memory");
- firstiscomposer = keepfirstartist = 0;
- res = tagsget(&ctx);
- if(ctx.format != Funknown){
- if(res != 0)
- fprint(2, "%s: no tags\n", path);
- }else{
- numall--;
- Bterm(bf);
- continue;
- }
-
- if(ctx.duration == 0)
- fprint(2, "%s: no duration\n", path);
- if(curr->title == nil){
- if((s = utfrrune(path, '/')) == nil)
- s = &path[len+1];
- curr->title = strdup(s+1);
- }
- curr->path = strdup(path);
- curr->duration = ctx.duration;
- if(ctx.format >= nelem(fmts))
- sysfatal("mkplist needs a rebuild with updated libtags");
- curr->filefmt = fmts[ctx.format];
- }
- Bterm(bf);
+ scanfile(path);
}else if(depth < Maxdepth){ /* recurse into the directory */
scan(dir, depth+1);
path = *dir;