aboutsummaryrefslogtreecommitdiff
path: root/scripts/parse_kconfig/output.c
blob: 064d787e297766737b950230259650a52e39c1a5 (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
#include "output.h"

void fprint_rules_cnf(FILE * f, struct cnfexpr *cnf) {
    unsigned i, y;
    switch (cnf->type) {
    case CT_FALSE:
        // Never satisfiable
        // This should newer happen
        fprintf(stderr,
                "ERROR: Some rule is not satisfiable. But this should never happen.\n");
        exit(28);
    case CT_TRUE:
        // Always satisfiable
        break;
    case CT_EXPR:
        for (i = 0; i < cnf->size; i++) {
            for (y = 0; y < cnf->sizes[i] - 1; y++) {
                fprintf(f, "%d ", cnf->exprs[i][y]);
            }
            fprintf(f, "%d\n", cnf->exprs[i][cnf->sizes[i] - 1]);
        }
        break;
    }
}

void fprint_rules(struct symlist *sl, char *output) {
    FILE *f;
    f = fopen(output, "w");
    if (f == NULL) {
        fprintf(stderr, "Can't create file: %s\n", output);
        return;
    }
    size_t i;
    struct symlist_el *el;
    for (i = 0; i < sl->pos; i++) {
        if (sl->array[i].be != NULL) {
            el = sl->array + i;
            if (el->be != NULL) {
                fprint_rules_cnf(f, el->be);
            }
            if (el->re_be != NULL) {
                fprint_rules_cnf(f, el->re_be);
            }
        }
    }
    fclose(f);
}

void fprint_symbol_map(struct symlist *sl, char *output) {
    FILE *f;
    f = fopen(output, "w");
    if (f == NULL) {
        fprintf(stderr, "Can't create file: %s\n", output);
        return;
    }
    size_t i;
    for (i = 0; i < sl->pos; i++) {
        fprintf(f, "%d:%s\n", sl->array[i].id, sl->array[i].name);
    }
    fclose(f);
}