aboutsummaryrefslogtreecommitdiff
path: root/scripts/write_config/write.c
blob: 5402286615a2c7b8d0d089ebec40c1f9c80971f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#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;
}