summaryrefslogtreecommitdiff
path: root/sources.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-01-14 11:32:45 -0500
committerJakob Kaivo <jkk@ung.org>2020-01-14 11:32:45 -0500
commite44ac1094eaba6b7ca59d5b2539d660c44bba5c3 (patch)
tree4e120b0073a257b7717cf329c924f474350fb4db /sources.c
parentf26eb1e014203cbd8137b69825e9594c92b6ab4d (diff)
initial commit
Diffstat (limited to 'sources.c')
-rw-r--r--sources.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/sources.c b/sources.c
new file mode 100644
index 0000000..3defa73
--- /dev/null
+++ b/sources.c
@@ -0,0 +1,38 @@
+#define _XOPEN_SOURCE 700
+#include <ftw.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "maje.h"
+
+static char **filelist = NULL;
+static size_t nfiles = 0;
+
+static int addfile(const char *path, const struct stat *st, int flags, struct FTW *ft)
+{
+ (void)st; (void)flags; (void)ft;
+
+ if (path[0] == '.' && path[1] == '/') {
+ path += 2;
+ }
+
+ if (strcmp(path + strlen(path) - 2, ".c") == 0) {
+ char **tmp = realloc(filelist, sizeof(*filelist) * (nfiles + 2));
+ if (tmp == NULL) {
+ return 1;
+ }
+ filelist = tmp;
+
+ filelist[nfiles] = strdup(path);
+ filelist[nfiles + 1] = NULL;
+ nfiles++;
+ }
+
+ return 0;
+}
+
+char ** find_source_files(const char *dir)
+{
+ nftw(dir, addfile, -1, 0);
+ return filelist;
+}