summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-25 19:45:31 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-25 19:45:31 -0400
commit319c7568828a01fa5ba8ded0b560d852124ffb84 (patch)
tree7ca966f27a06885ae6451e730128f70994355a4a /list.c
parent0c72419d193ca13edc8302cd8c151bbe80a4716f (diff)
add support for setting flags in source
Diffstat (limited to 'list.c')
-rw-r--r--list.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/list.c b/list.c
index 24d265c..2fa06ab 100644
--- a/list.c
+++ b/list.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 700
+#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -34,3 +35,45 @@ struct majefile *insert_file(struct majefile *list, const char *path, const stru
}
return tmp;
}
+
+struct majeflag *insert_flag(struct majeflag *list, char *flag)
+{
+ char *eq = strchr(flag, '=');
+ *eq = '\0';
+ eq++;
+
+ int type = 0;
+ if (!strcmp(flag, "MAJE_CFLAG")) {
+ type = MAJE_CFLAG;
+ } else if (!strcmp(flag, "MAJE_LDFLAG")) {
+ type = MAJE_LDFLAG;
+ } else if (!strcmp(flag, "MAJE_LDLIB")) {
+ type = MAJE_LDLIB;
+ } else {
+ fprintf(stderr, "maje: unkonwn directive '%s'\n", flag);
+ return list;
+ }
+
+ struct majeflag *tmp = malloc(sizeof(*tmp) + strlen(flag) + 1);
+ if (tmp == NULL) {
+ return NULL;
+ }
+
+ tmp->next = NULL;
+ tmp->prev = NULL;
+
+ tmp->type = type;
+ strcpy(tmp->flag, eq);
+
+ if (list == NULL) {
+ return tmp;
+ }
+
+ tmp->next = list->next;
+ tmp->prev = list;
+ list->next = tmp;
+ if (tmp->next != NULL) {
+ tmp->next->prev = tmp;
+ }
+ return tmp;
+}