aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/write_config/Makefile3
-rw-r--r--scripts/write_config/symlist.c46
-rw-r--r--scripts/write_config/symlist.h23
-rw-r--r--scripts/write_config/write.c59
4 files changed, 130 insertions, 1 deletions
diff --git a/scripts/write_config/Makefile b/scripts/write_config/Makefile
index 9bb6246..a4926e8 100644
--- a/scripts/write_config/Makefile
+++ b/scripts/write_config/Makefile
@@ -7,7 +7,8 @@ all: write
KCONFIG_PREFIX = ../shared/kconfig
include $(KCONFIG_PREFIX)/files.mk
-SRC = write.c
+SRC = write.c \
+ symlist.c
OBJ = $(patsubst %.c,%.o,$(SRC))
CFLAGS = -O0 -w -ggdb
INCLUDES = -I../shared
diff --git a/scripts/write_config/symlist.c b/scripts/write_config/symlist.c
new file mode 100644
index 0000000..71d9470
--- /dev/null
+++ b/scripts/write_config/symlist.c
@@ -0,0 +1,46 @@
+#include "symlist.h"
+
+struct symlist *symlist_read(FILE * f) {
+ struct symlist *ret;
+ ret = malloc(sizeof(struct symlist));
+ ret->size = 1;
+ ret->array = malloc(ret->size * sizeof(struct symlist_el));
+
+ unsigned int id;
+ char *w;
+ size_t w_pos = 0, w_size = 2;
+ w = malloc((w_size + 1) * sizeof(char));
+
+ int c;
+ do {
+ c = fgetc(f);
+ if (c == EOF || c == '\n') {
+ w[w_pos] = '\0';
+ if ((size_t) id > ret->size) {
+ ret->size *= 2;
+ ret->array =
+ realloc(ret->array,
+ ret->size * sizeof(struct symlist_el));
+ }
+ ret->array[(size_t) id - 1].id = id;
+ ret->array[(size_t) id - 1].sym = sym_lookup(w, 0);
+ w_pos = 0;
+ } else if (c == ':') {
+ w[w_pos] = '\0';
+ id = atoi(w);
+ w_pos = 0;
+ } else {
+ if (w_pos >= w_size) {
+ w_size *= 2;
+ w = realloc(w, (w_size + 1) * sizeof(char));
+ }
+ w[w_pos++] = (char) c;
+ }
+ } while (c != EOF);
+
+ return ret;
+}
+
+struct symbol *symlist_get(struct symlist *sl, unsigned int id) {
+ return sl->array[id].sym;
+}
diff --git a/scripts/write_config/symlist.h b/scripts/write_config/symlist.h
new file mode 100644
index 0000000..3736b2b
--- /dev/null
+++ b/scripts/write_config/symlist.h
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdio.h>
+#include <kconfig/lkc.h>
+
+#ifndef _SYMLIST_H_
+#define _SYMLIST_H_
+
+struct symlist_el {
+ unsigned int id;
+ struct symbol *sym;
+};
+
+struct symlist {
+ struct symlist_el *array;
+ size_t size;
+};
+
+struct symlist *symlist_read(FILE *f);
+struct symbol *symlist_get(struct symlist *, unsigned int id);
+
+#endif /* _SYMLIST_H_ */
diff --git a/scripts/write_config/write.c b/scripts/write_config/write.c
new file mode 100644
index 0000000..f5a3181
--- /dev/null
+++ b/scripts/write_config/write.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <kconfig/lkc.h>
+#include <macros.h>
+#include <build_files.h>
+#include "symlist.h"
+
+int verbose_level;
+char *file, *folder;
+
+int main(int argc, char **argv) {
+ verbose_level = 1;
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-v"))
+ verbose_level++;
+ else if (file == NULL)
+ file = argv[i];
+ else if (folder == NULL)
+ folder = argv[i];
+ else {
+ Eprintf("Unknown parameter: %s\n", argv[i]);
+ exit(1);
+ }
+ }
+
+ if (file == NULL) {
+ Eprintf("No Kconfig input file specified\n");
+ exit(2);
+ }
+ if (folder == NULL) {
+ Eprintf("No output folder specified\n");
+ exit(3);
+ }
+
+ char *rules_file, *symbol_map_file, *def_config_file;
+ asprintf(&rules_file, "%s/%s", folder, DEFAULT_RULES_FILE);
+ asprintf(&symbol_map_file, "%s/%s", folder, DEFAULT_SYMBOL_MAP_FILE);
+ asprintf(&def_config_file, "%s/%s", folder, DEFAULT_DEF_CONFIG_FILE);
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ conf_parse(file);
+ conf_read(def_config_file);
+
+ FILE *f = fopen(symbol_map_file, "r");
+ if (f == NULL) {
+ Eprintf("Can't open file: %s\n", symbol_map_file);
+ exit(1);
+ }
+ struct symlist *sl = symlist_read(f);
+ fclose(f);
+
+ return 0;
+}