]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/kconfig_parser/parser.c
Move gitignore rules to corresponds to kconfig sources move
[linux-conf-perf.git] / scripts / kconfig_parser / parser.c
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <limits.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <signal.h>
10 #include <unistd.h>
11 #include <locale.h>
12 #include <stdbool.h>
13 #include <argp.h>
14 #include "lkc.h"
15 #include "symlist.h"
16 #include "output.h"
17 #include "macros.h"
18
19 int verbose_level;
20 char *file;
21
22 struct symlist *gsymlist;
23 int noname_num;
24
25 void build_symlist();
26 void cpy_dep();
27
28 int main(int argc, char **argv) {
29     // TODO argp
30     verbose_level = 1;
31     int i;
32     for (i = 0; i < argc; i++) {
33         if (!strcmp(argv[i], "-v"))
34             verbose_level++;
35         else if (file == NULL)
36             file = argv[i];
37     }
38
39     if (argc < 2) {
40         Eprintf("No input file specified\n");
41         exit(1);
42     }
43     if (argc < 3) {
44         Eprintf("No output folder specified\n");
45         exit(2);
46     }
47
48     setlocale(LC_ALL, "");
49     bindtextdomain(PACKAGE, LOCALEDIR);
50     textdomain(PACKAGE);
51
52     conf_parse(argv[1]);
53     //sym_clear_all_valid();
54
55     gsymlist = symlist_create();
56
57     build_symlist();
58     cpy_dep();
59
60     char *rules_file, *symbol_map_file;
61     asprintf(&rules_file, "%s/%s", argv[2], DEFAULT_RULES_FILE);
62     asprintf(&symbol_map_file, "%s/%s", argv[2], DEFAULT_SYMBOL_MAP_FILE);
63     fprint_rules(gsymlist, rules_file);
64     fprint_symbol_map(gsymlist, symbol_map_file);
65     return 0;
66 }
67
68 void build_symlist() {
69     int i;
70     struct symbol *sym;
71     for_all_symbols(i, sym) {
72         if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
73             if (sym->name != NULL) {
74                 symlist_add(gsymlist, sym->name);
75             } else {
76                 sym->name = malloc((9 + 7) * sizeof(char));
77                 sprintf(sym->name, "NONAMEGEN%d", noname_num++);
78                 symlist_add(gsymlist, sym->name);
79             }
80         }
81     }
82 }
83
84 void cpy_dep() {
85     int i;
86     struct symbol *sym;
87     struct symlist_el *el;
88     for_all_symbols(i, sym) {
89         if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
90             && strstr(sym->name, "NONAMEGEN") == NULL) {
91             el = symlist_find(gsymlist, sym->name);
92             Iprintf("working: %s(%d)\n", sym->name, el->id);
93
94             if (sym->dir_dep.expr != NULL) {
95                 if (verbose_level > 3)
96                     printf_original(gsymlist, sym->dir_dep.expr);
97                 el->be = kconfig_cnfexpr(gsymlist, false, sym->dir_dep.expr);
98                 Iprintf("Direct:\n");
99                 if (verbose_level > 2)
100                     cnf_printf(el->be);
101             }
102             if (sym->rev_dep.expr != NULL) {
103                 if (verbose_level > 3)
104                     printf_original(gsymlist, sym->rev_dep.expr);
105                 el->re_be = kconfig_cnfexpr(gsymlist, true, sym->rev_dep.expr);
106                 Iprintf("Revers:\n");
107                 if (verbose_level > 2)
108                     cnf_printf(el->re_be);
109             }
110         }
111     }
112 }