aboutsummaryrefslogtreecommitdiff
path: root/scripts/allconfig/inv.c
blob: 0e87163d9129090265685535acce7be58a47de06 (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
#include "inv.h"

void inv_prepare(char *input_file) {
    FILE *f;
    f = fopen(input_file, "r");
    if (f == NULL) {
        Eprintf("Can't open input file: %s\n", input_file);
        exit(-2);
    }

    struct property *fixed_prop;
    fixed_prop = malloc(sizeof(struct property));
    fixed_prop->type = P_UNKNOWN;
    fixed_prop->lineno = LINENUM_IDENTIFICATOR;
    fixed_prop->next = NULL;
    char buffer[READBUFFER_SIZE];
    while (fgets(buffer, READBUFFER_SIZE, f) != NULL) {
        if (buffer[0] == '\0' || buffer[1] == '\0')
            continue;
        if (buffer[0] != '#') {
            char *wstr = buffer + 7;
            char *end = strchr(wstr, '=');
            *end = '\0';
            struct symbol *sym = sym_find(wstr);
            if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
                continue;
            if (sym->prop == NULL) {
                sym->prop = fixed_prop;
                continue;
            }
            struct property *prop;
            prop = sym->prop;
            while (prop->next != NULL)
                prop = prop->next;
            prop->next = fixed_prop;
        }
    }

    fclose(f);
}

bool inv_fixed(struct symbol *sym) {
    if (sym->prop == NULL)
        return false;
    struct property *prop;
    prop = sym->prop;
    while (prop->next != NULL)
        prop = prop->next;
    if (prop->type == P_UNKNOWN && prop->lineno == LINENUM_IDENTIFICATOR)
        return true;
    else
        return false;
}