summaryrefslogtreecommitdiff
path: root/sources.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-03-27 16:53:14 -0400
committerJakob Kaivo <jkk@ung.org>2020-03-27 16:53:14 -0400
commit1a21f9e690a5e5b334a5c5fbc2b4d1f71d00d43d (patch)
treead9b6733871fc075315c6512d8509df5066303e4 /sources.c
parent2a15bdb94ea913b361c026541eff3cfdcffccde6 (diff)
initial support for adding local headers as dependencies
Diffstat (limited to 'sources.c')
-rw-r--r--sources.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/sources.c b/sources.c
index 22d71a2..6255750 100644
--- a/sources.c
+++ b/sources.c
@@ -6,7 +6,6 @@
#include "maje.h"
static struct majefile *filelist = NULL;
-static struct majefile *tail = NULL;
static int add_source(const char *path, const struct stat *st, int flags, struct FTW *ft)
{
@@ -17,22 +16,10 @@ static int add_source(const char *path, const struct stat *st, int flags, struct
}
if (strcmp(path + strlen(path) - 2, ".c") == 0) {
- struct majefile *tmp = malloc(sizeof(*filelist) + strlen(path) + 1);
- if (tmp == NULL) {
+ filelist = insert_file(filelist, path, st);
+ if (filelist == NULL) {
return 1;
}
-
- tmp->next = NULL;
- tmp->st = *st;
- strcpy(tmp->path, path);
-
- if (tail == NULL) {
- filelist = tmp;
- tail = filelist;
- } else {
- tail->next = tmp;
- tail = tail->next;
- }
}
return 0;
@@ -41,5 +28,14 @@ static int add_source(const char *path, const struct stat *st, int flags, struct
struct majefile * find_source_files(const char *dir)
{
nftw(dir, add_source, -1, 0);
+
+ if (filelist == NULL) {
+ return NULL;
+ }
+
+ while (filelist->prev != NULL) {
+ filelist = filelist->prev;
+ }
+
return filelist;
}