aboutsummaryrefslogtreecommitdiff
path: root/scripts/permute/permute.c
blob: fc1221c3915ae4e8e12e81e628af3d33f161d7c4 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <libintl.h>

#include <kconfig/lkc.h>
#include <macros.h>
#include <build_files.h>

#define INPUT_SIZE 1024

int verbose_level;
char *file, *folder;

void printf_help();

int main(int argc, char **argv) {
    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);
    }

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

    conf_parse(file);
    conf_read(".config");

    struct menu *wroot, *wmenu, *wwmenu;
    wroot = &rootmenu;
    unsigned menucount;
    char *input;
    int inputi;
    input = malloc(INPUT_SIZE * sizeof(char));

    printf_help();

    while (1) {
        printf("\n%s\n", wroot->prompt->text);
        wmenu = wroot->list;
        menucount = 0;
        while (wmenu != NULL) {
            if (wmenu->prompt != NULL) {
                if (wmenu->list == NULL)
                    printf("%3d<X>: %s\n", ++menucount,
                           wmenu->prompt->text);
                else
                    printf("%3d<X>: %s -->\n", ++menucount,
                           wmenu->prompt->text);
            }
            wmenu = wmenu->next;
        }

      input:
        printf("Input: ");
        fgets(input, INPUT_SIZE, stdin);
        switch (input[0]) {
        case 'e':
        case 'v':
        case 'f':
            inputi = atoi(input + 1);
            if (inputi <= 0 && inputi > menucount)
                goto input;
            int y = 0;
            wwmenu = wroot->list;
            while (1) {
                if (wwmenu->prompt != NULL)
                    y++;
                if (y >= inputi)
                    break;
                wwmenu = wwmenu->next;
            }
            break;
        case 'u':
            wmenu = wmenu->parent;
            break;
        case 'r':
            break;
        case 'q':
            goto quit;
        case 'h':
            printf_help();
        default:
            goto input;
        }
        switch (input[0]) {
        case 'e':
            wroot = wwmenu;
            break;
        case 'v':
            break;
        case 'f':
            break;
        }
    }

  quit:

    return 0;
}

void printf_help() {
    printf("As input are accepted these commands:\n");
    printf("  e <NUM> Enter menu according to number.\n");
    printf("  u       Go to previous upper menu.\n");
    printf("  v <NUM> Set menu and all its submenus as variable.\n");
    printf("  f <NUM> Set menu and all its submenus as fixed.\n");
    printf("  r       Reprint menu.\n");
    printf("  h       Prints this text.\n");
    printf("  q       Quit this program\n");
}