dir2list

generate a list of files shuffled by directory
git clone anongit@rnpnr.xyz:dir2list.git
Log | Files | Refs | Feed | README | LICENSE

Commit: ca0f6312a9ec25af0c1c9037d0d91a0a6ea543d1
Parent: ee8b5be1dd4f6c294964ea46083656fea79268d1
Author: 0x766F6964
Date:   Sat, 17 Oct 2020 12:18:17 -0600

specify dir on cmd line

Diffstat:
Mconfig.def.h | 5+----
Mdir2list.c | 24+++++++++++++++++++++---
2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,5 +1,2 @@ -/* the top level dir to traverse */ -const char *topdir = "/mnt/media"; - /* the list of valid filetypes to include in the created list */ -const char *filetypes[] = { "mkv", "mp4", NULL }; +const char *filetypes[] = { "mkv", "mp4", "mp3", "ogg", "flac", NULL }; diff --git a/dir2list.c b/dir2list.c @@ -1,4 +1,5 @@ #include <dirent.h> +#include <errno.h> #include <stdarg.h> #include <stdio.h> #include <stdint.h> @@ -40,6 +41,12 @@ die(const char *fmt, ...) exit(1); } +static void +usage(const char *argv0) +{ + die("usage: %s [dir]\n", argv0); +} + static void * xmalloc(size_t s) { @@ -177,12 +184,23 @@ printlist(void) } int -main(void) +main(int argc, char *argv[]) { + struct stat sb; + + if (argc != 2) + usage(argv[0]); + + if (stat(argv[1], &sb) != 0 || !S_ISDIR(sb.st_mode)) { + if (errno == ENOENT && argv[1][0] == '/') + die("dir: %s: does not exist\n", argv[1]); + usage(argv[0]); + } + nodes = reallocarray(nodes, ++n_nodes, sizeof(struct node)); - nodes[0].path = xmalloc(strlen(topdir) + 1); - nodes[0].path = strcpy(nodes[0].path, topdir); + nodes[0].path = xmalloc(strlen(argv[1]) + 1); + nodes[0].path = strcpy(nodes[0].path, argv[1]); nodes[0].a = 0; srand(time(NULL));