aboutsummaryrefslogtreecommitdiff
path: root/programs/src/kconfig/kconfig_parser.c
blob: 4fac8b2928a9b914382a39f5415a104de8f4d60c (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <locale.h>
#include <stdbool.h>
#include "kconfig/lkc.h"
#include "symlist.h"
#include "boolexp.h"
#include "output.h"

void kconfig_menu_walker(void (*solve)
                          (struct symbol * sym));

void solve_names(struct symbol *sym);
void solve_dep(struct symbol *sym);

struct symlist *gsymlist;
int noname_num;

int main(int argc, char **argv) {

    if (argc < 2) {
        printf("No input file specified\n");
        return;
    }

    setlocale(LC_ALL, "");
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);

    conf_parse(argv[1]);
    sym_clear_all_valid();

    gsymlist = symlist_create();

    kconfig_menu_walker(solve_names);
    kconfig_menu_walker(solve_dep);

    //symlist_print(gsymlist);
	fprint_rules(gsymlist);
	fprint_linker(gsymlist);
}

void kconfig_menu_walker(void (*solve) (struct symbol * sym)) {
    struct menu *menu;
    struct symbol *sym;
    menu = rootmenu.list;

    while (menu != NULL) {
        sym = menu->sym;
        if (sym != NULL) {
            do {
                if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
                    solve(sym);
                }
            } while ((sym = sym->next) != NULL);
        }
        // switch to menu
        if (menu->list != NULL) {
            menu = menu->list;
        } else if (menu->next != NULL) {
            menu = menu->next;
        } else {
            while ((menu = menu->parent) != NULL) {
                if (menu->next != NULL) {
                    menu = menu->next;
                    break;
                }
            }
        }
    }
}

void solve_names(struct symbol *sym) {
    if (sym->name != NULL) {
        if (symlist_find(gsymlist, sym->name) == NULL)
            symlist_add(gsymlist, sym->name);
    } else {
        sym->name = malloc((9 + 7) * sizeof(char));
        sprintf(sym->name, "NONAMEGEN%d", noname_num++);
        symlist_add(gsymlist, sym->name);
    }
}

void solve_dep(struct symbol *sym) {
    if (sym->dir_dep.expr != NULL) {
        struct symlist_el *el;
        el = symlist_find(gsymlist, sym->name);
        el->be = copy_kconfig_dep(gsymlist, sym->dir_dep.expr);
        if (el->be != NULL)
            el->be = boolexp_cnf(el->be);
    }
}