]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
Rewrite write_config
authorKarel Kočí <cynerd@email.cz>
Fri, 24 Jul 2015 15:19:22 +0000 (17:19 +0200)
committerKarel Kočí <cynerd@email.cz>
Fri, 24 Jul 2015 15:19:22 +0000 (17:19 +0200)
Write config don't need to load jobfiles any more.
We only have to load file passed via argument and save using kconfig code.

Configuration checking is disabled. It needs more editing.

scripts/write_config/.gitignore
scripts/write_config/Makefile
scripts/write_config/solution.h
scripts/write_config/symlist.c [deleted file]
scripts/write_config/symlist.h [deleted file]
scripts/write_config/write.c [deleted file]
scripts/write_config/write_config.c [new file with mode: 0644]

index 77ec0bed919bdb30d0d77737e9a2b82ff77d8441..60f5db07a95d407d907cbcebcc8ef0467073a992 100644 (file)
@@ -1 +1 @@
-write
+write_config
index bab1f4b5b34e74d9c22ffad5dafd13266b8b09a8..ec56a8721959af971bff5449995f6035beb026ed 100644 (file)
@@ -2,24 +2,22 @@ MAKEFLAGS += --no-builtin-rules
 .PHONY: all clean
 .SUFFIXES:
 
-all: write
+all: write_config
 
 KCONFIG_PREFIX = ../shared/kconfig
 include $(KCONFIG_PREFIX)/files.mk
 
-SRC  = write.c \
-          symlist.c \
-          solution.c
+SRC  = write_config.c
 OBJ = $(patsubst %.c,%.o,$(SRC))
-CFLAGS = -O0 -w -ggdb
+CFLAGS = -O0 -Wall -ggdb
 INCLUDES = -I../shared
 
 %.o: %.c
        gcc -c $(CFLAGS) -o $@ $^ $(INCLUDES)
 
-write: $(OBJ) $(KCONFIG_OBJ)
+write_config: $(OBJ) $(KCONFIG_OBJ)
        gcc -o $@ $^
 
 clean::
        $(RM) $(OBJ)
-       $(RM) write
+       $(RM) write_config
index 100a9fe418e316ccb7a4ccbd2ae5a42b2d9783dc..7a37c1518843e606e855d809bed9d7a620b8d692 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdbool.h>
 #include <kconfig/lkc.h>
 #include <build_files.h>
-#include "symlist.h"
 
 #ifndef _SOLUTION_H_
 #define _SOLUTION_H_
@@ -15,7 +14,7 @@ struct solution {
     size_t size;
 };
 
-struct solution *solution_load(FILE *fmap, FILE *fsolved);
-void solution_check(struct symlist *sl, struct solution *s);
+struct solution *solution_load(char *source_config);
+int solution_check(struct solution *s);
 
 #endif /* _SOLUTION_H_ */
diff --git a/scripts/write_config/symlist.c b/scripts/write_config/symlist.c
deleted file mode 100644 (file)
index fd0aca8..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "symlist.h"
-
-#define NONAMEGEN "NONAMEGEN"
-
-struct symlist *symlist_read(FILE * f) {
-    struct symlist *ret;
-    ret = malloc(sizeof(struct symlist));
-    ret->size = 1;
-    ret->maxid = 0;
-    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 == '\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));
-            }
-            if (id > ret->maxid)
-                ret->maxid = id;
-            ret->array[(size_t) id - 1].id = id;
-            if (!strncmp(w, NONAMEGEN, strlen(NONAMEGEN)))
-                ret->array[(size_t) id - 1].sym = NULL;
-            else
-                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
deleted file mode 100644 (file)
index 8bc61c1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#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;
-    unsigned maxid;
-};
-
-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
deleted file mode 100644 (file)
index 5402286..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#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"
-#include "solution.h"
-
-int verbose_level;
-char *file, *folder;
-
-int exit_status;
-
-int main(int argc, char **argv) {
-    exit_status = 0;
-    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, *config_map, *config_solved;
-    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);
-    asprintf(&config_map, "%s/%s", folder, DEFAULT_CONFIG_MAP_FILE);
-    asprintf(&config_solved, "%s/%s", folder, DEFAULT_CONFIG_SOLVED_FILE);
-
-    setlocale(LC_ALL, "");
-    bindtextdomain(PACKAGE, LOCALEDIR);
-    textdomain(PACKAGE);
-
-    conf_parse(file);
-    struct symbol *sym;
-    //conf_read(def_config_file);
-    conf_read(".config");
-
-    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);
-
-    FILE *fconfig_map = fopen(config_map, "r");
-    if (fconfig_map == NULL) {
-        Eprintf("Can't open file: %s\n", config_map);
-        exit(-2);
-    }
-    FILE *fconfig_solved = fopen(config_solved, "r");
-    if (fconfig_map == NULL) {
-        Eprintf("Can't open file: %s\n", config_solved);
-        exit(-3);
-    }
-    //struct solution *sol = solution_load(fconfig_map, fconfig_solved);
-    //solution_check(sl, sol);
-    fclose(fconfig_map);
-    fclose(fconfig_solved);
-
-    conf_write(".config");
-
-    return exit_status;
-}
diff --git a/scripts/write_config/write_config.c b/scripts/write_config/write_config.c
new file mode 100644 (file)
index 0000000..1f061d1
--- /dev/null
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <string.h>
+
+#include <kconfig/lkc.h>
+#include <macros.h>
+#include <build_files.h>
+#include "solution.h"
+
+const char defkconfig_file[] = "Kconfig";
+const char defoutput_config[] = ".config";
+
+int verbose_level;
+char *kconfig_file;
+char *input_config;
+
+void print_help();
+
+int exit_status;
+
+int main(int argc, char **argv) {
+    exit_status = 0;
+    verbose_level = 1;
+    kconfig_file = (char*)defkconfig_file;
+    int i;
+    for (i = 1; i < argc; i++) {
+        if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
+            print_help();
+            exit(0);
+        } else if (!strcmp(argv[i], "-v")) {
+            verbose_level++;
+        } else if (input_config == NULL) {
+            input_config = argv[i];
+        } else {
+            Eprintf("Unknown parameter: %s\n", argv[i]);
+            exit(-1);
+        }
+    }
+
+    if (input_config == NULL) {
+        Eprintf("No input config specified.");
+        print_help();
+        exit(2);
+    }
+
+    setlocale(LC_ALL, "");
+    bindtextdomain(PACKAGE, LOCALEDIR);
+    textdomain(PACKAGE);
+
+    conf_parse(kconfig_file);
+    conf_read(input_config);
+
+    // TODO configuration check disabled. It is not compatible after changes.
+
+    conf_write(defoutput_config);
+
+    return exit_status;
+}
+
+void print_help() {
+    printf("Usage: write_config [-v] [-h] Input\n");
+    printf("  This applies configuration to Linux.");
+}