]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blob - scripts/permute_conf/menudata.c
Add database initialisation check
[linux-conf-perf.git] / scripts / permute_conf / menudata.c
1 #include "menudata.h"
2
3 struct menudata *menudata_new(void) {
4     struct menudata *rtn;
5     rtn = calloc(1, sizeof(struct menudata));
6     return rtn;
7 }
8
9 void menudata_set_permute(struct menu *m, bool perm) {
10     ((struct menudata *) m->data)->permute = perm;
11     struct menu *prnt;
12     for (prnt = m; prnt != NULL; prnt = prnt->parent) {
13         menudata_cal(prnt);
14     }
15 }
16
17 void menudata_set_all_permute(struct menu *m, bool perm) {
18     menudata_set_permute(m, perm);
19
20     struct menu **stack;
21     size_t stack_size = 2, stack_pos = 0;
22     stack = malloc(stack_size * sizeof(struct menu *));
23
24     m = m->list;
25     while (m != NULL) {
26         if (m->data == NULL)
27             m->data = menudata_new();
28         ((struct menudata *) m->data)->permute = perm;
29         ((struct menudata *) m->data)->subpermute = perm;
30
31         if (m->list != NULL) {
32             if (stack_pos >= stack_size) {
33                 stack_size *= 2;
34                 stack = realloc(stack, stack_size * sizeof(struct menu *));
35             }
36             stack[stack_pos++] = m->list;
37         }
38
39         m = m->next;
40         if (m == NULL && stack_pos > 0)
41             m = stack[--stack_pos];
42     }
43
44 }
45
46 void menudata_cal(struct menu *m) {
47     bool subperm = false;
48     struct menu *w;
49     for (w = m->list; w != NULL; w = w->next) {
50         if (w->data != NULL && (((struct menudata *) w->data)->permute
51                                 || ((struct menudata *) w->data)->
52                                 subpermute)) {
53             if (m->data == NULL)
54                 m->data = menudata_new();
55             ((struct menudata *) m->data)->subpermute = subperm;
56         }
57     }
58 }