From 2c46c7e4b57604a299b0639560934e1f523f725a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 21 May 2015 19:24:24 +0200 Subject: Rename program permute to permute_conf --- scripts/permute/.gitignore | 1 - scripts/permute/Makefile | 25 ----- scripts/permute/constlist.h | 7 -- scripts/permute/dotconf.c | 108 ---------------------- scripts/permute/dotconf.h | 19 ---- scripts/permute/menudata.c | 58 ------------ scripts/permute/menudata.h | 20 ---- scripts/permute/permute.c | 180 ------------------------------------ scripts/permute/permutelist.h | 17 ---- scripts/permute_conf/.gitignore | 1 + scripts/permute_conf/Makefile | 25 +++++ scripts/permute_conf/constlist.h | 7 ++ scripts/permute_conf/dotconf.c | 108 ++++++++++++++++++++++ scripts/permute_conf/dotconf.h | 19 ++++ scripts/permute_conf/menudata.c | 58 ++++++++++++ scripts/permute_conf/menudata.h | 20 ++++ scripts/permute_conf/permute_conf.c | 180 ++++++++++++++++++++++++++++++++++++ scripts/permute_conf/permutelist.h | 17 ++++ 18 files changed, 435 insertions(+), 435 deletions(-) delete mode 100644 scripts/permute/.gitignore delete mode 100644 scripts/permute/Makefile delete mode 100644 scripts/permute/constlist.h delete mode 100644 scripts/permute/dotconf.c delete mode 100644 scripts/permute/dotconf.h delete mode 100644 scripts/permute/menudata.c delete mode 100644 scripts/permute/menudata.h delete mode 100644 scripts/permute/permute.c delete mode 100644 scripts/permute/permutelist.h create mode 100644 scripts/permute_conf/.gitignore create mode 100644 scripts/permute_conf/Makefile create mode 100644 scripts/permute_conf/constlist.h create mode 100644 scripts/permute_conf/dotconf.c create mode 100644 scripts/permute_conf/dotconf.h create mode 100644 scripts/permute_conf/menudata.c create mode 100644 scripts/permute_conf/menudata.h create mode 100644 scripts/permute_conf/permute_conf.c create mode 100644 scripts/permute_conf/permutelist.h (limited to 'scripts') diff --git a/scripts/permute/.gitignore b/scripts/permute/.gitignore deleted file mode 100644 index 4456899..0000000 --- a/scripts/permute/.gitignore +++ /dev/null @@ -1 +0,0 @@ -permute diff --git a/scripts/permute/Makefile b/scripts/permute/Makefile deleted file mode 100644 index 531b484..0000000 --- a/scripts/permute/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -MAKEFLAGS += --no-builtin-rules -.PHONY: all clean -.SUFFIXES: - -all: permute - -KCONFIG_PREFIX = ../shared/kconfig -include $(KCONFIG_PREFIX)/files.mk - -SRC = permute.c \ - menudata.c \ - dotconf.c -OBJ = $(patsubst %.c,%.o,$(SRC)) -CFLAGS = -O0 -Wall -ggdb -DDEBUG -INCLUDES = -I../shared - -%.o: %.c - gcc -c $(CFLAGS) -o $@ $^ $(INCLUDES) - -permute: $(OBJ) $(KCONFIG_OBJ) - gcc -o $@ $^ - -clean:: - $(RM) $(OBJ) - $(RM) permute diff --git a/scripts/permute/constlist.h b/scripts/permute/constlist.h deleted file mode 100644 index 01f172a..0000000 --- a/scripts/permute/constlist.h +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -#ifndef _CONSTLIST_H_ -#define _CONSTLIST_H_ - -#endif /* _CONSTLIST_H_ */ diff --git a/scripts/permute/dotconf.c b/scripts/permute/dotconf.c deleted file mode 100644 index bf8e067..0000000 --- a/scripts/permute/dotconf.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "dotconf.h" - -void dotconfig_read(bool * reqsave) { - FILE *f; - f = fopen(DOTCONFIG_FILE, "r"); - if (f == NULL) { - *reqsave = true; - return; - } - - 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_get_tristate_value(sym) == yes && *(end + 1) != 'y') - || (sym_get_tristate_value(sym) == no - && *(end + 1) != 'n')) - *reqsave = true; - struct property *prop; - for_all_prompts(sym, prop) { - if (prop->menu->data == NULL) - prop->menu->data = menudata_new(); - } - } - } - - fclose(f); - - struct menu *wmenu; - struct menu **stack; - size_t stack_size = 2, stack_pos = 0; - stack = malloc(stack_size * sizeof(struct menu *)); - wmenu = rootmenu.list; - while (wmenu != NULL) { - if (wmenu->list != NULL) { - if (stack_pos >= stack_size) { - stack_size *= 2; - stack = realloc(stack, stack_size * sizeof(struct menu *)); - } - stack[stack_pos++] = wmenu->list; - } - if (wmenu->data == NULL) { - if (wmenu->sym == NULL || wmenu->sym->name == NULL) { - wmenu->data = menudata_new(); - } else { - wmenu->data = menudata_new(); - menudata_set_permute(wmenu, true); - } - } - wmenu = wmenu->next; - if (wmenu == NULL && stack_pos > 0) - wmenu = stack[--stack_pos]; - } - while (wmenu != NULL) { - if (wmenu->list != NULL) - stack[stack_pos++] = wmenu->list; - if (wmenu->data == NULL) { - if (wmenu->sym == NULL || wmenu->sym->name == NULL) { - wmenu->data = menudata_new(); - } else { - wmenu->data = menudata_new(); - menudata_set_permute(wmenu, true); - } - } - wmenu = wmenu->next; - if (wmenu == NULL && stack_pos > 0) - wmenu = stack[--stack_pos]; - } -} - -void dotconfig_write(void) { - FILE *f; - f = fopen(DOTCONFIG_FILE, "w"); - - struct symbol *sym; - struct property *prop; - int i; - unsigned variable = 0, fixed = 0; - for_all_symbols(i, sym) - if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) - && sym->name != NULL) { - for_all_prompts(sym, prop) { - if (prop->menu->data == NULL - || !((struct menudata *) prop->menu->data)->permute) { - fprintf(f, "CONFIG_%s=%s\n", sym->name, - sym_get_tristate_value(sym) == no ? "n" : "y"); - fixed++; - break; - } else { - variable++; - if (verbose_level > 1) - printf("%s=%s\n", sym->name, - sym_get_tristate_value(sym) == no ? "n" : "y"); - } - } - } - - printf("Variable: %d, Fixed: %d\n", variable, fixed); - - fclose(f); -} diff --git a/scripts/permute/dotconf.h b/scripts/permute/dotconf.h deleted file mode 100644 index 34fa8db..0000000 --- a/scripts/permute/dotconf.h +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include "menudata.h" - -#ifndef _DOTCONF_H_ -#define _DOTCONF_H_ - -#define DOTCONFIG_FILE "../dot_config" -#define READBUFFER_SIZE 128 - -void dotconfig_read(bool * reqsave); -void dotconfig_write(void); - -#endif /* _DOTCONF_H_ */ diff --git a/scripts/permute/menudata.c b/scripts/permute/menudata.c deleted file mode 100644 index 88910ab..0000000 --- a/scripts/permute/menudata.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "menudata.h" - -struct menudata *menudata_new(void) { - struct menudata *rtn; - rtn = calloc(1, sizeof(struct menudata)); - return rtn; -} - -void menudata_set_permute(struct menu *m, bool perm) { - ((struct menudata *) m->data)->permute = perm; - struct menu *prnt; - for (prnt = m; prnt != NULL; prnt = prnt->parent) { - menudata_cal(prnt); - } -} - -void menudata_set_all_permute(struct menu *m, bool perm) { - menudata_set_permute(m, perm); - - struct menu **stack; - size_t stack_size = 2, stack_pos = 0; - stack = malloc(stack_size * sizeof(struct menu *)); - - m = m->list; - while (m != NULL) { - if (m->data == NULL) - m->data = menudata_new(); - ((struct menudata *) m->data)->permute = perm; - ((struct menudata *) m->data)->subpermute = perm; - - if (m->list != NULL) { - if (stack_pos >= stack_size) { - stack_size *= 2; - stack = realloc(stack, stack_size * sizeof(struct menu *)); - } - stack[stack_pos++] = m->list; - } - - m = m->next; - if (m == NULL && stack_pos > 0) - m = stack[--stack_pos]; - } - -} - -void menudata_cal(struct menu *m) { - bool subperm = false; - struct menu *w; - for (w = m->list; w != NULL; w = w->next) { - if (w->data != NULL && (((struct menudata *) w->data)->permute - || ((struct menudata *) w->data)-> - subpermute)) { - if (m->data == NULL) - m->data = menudata_new(); - ((struct menudata *) m->data)->subpermute = subperm; - } - } -} diff --git a/scripts/permute/menudata.h b/scripts/permute/menudata.h deleted file mode 100644 index a273891..0000000 --- a/scripts/permute/menudata.h +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -#include - -#ifndef _MENUDATA_H_ -#define _MENUDATA_H_ - -struct menudata { - bool permute; - bool subpermute; -}; - -struct menudata *menudata_new(void); -void menudata_set_permute(struct menu *m, bool perm); -void menudata_set_all_permute(struct menu *m, bool perm); -void menudata_cal(struct menu *m); - -#endif /* _MENUDATA_H_ */ diff --git a/scripts/permute/permute.c b/scripts/permute/permute.c deleted file mode 100644 index ec9abf0..0000000 --- a/scripts/permute/permute.c +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "menudata.h" -#include "dotconf.h" - -#define INPUT_SIZE 1024 - -int verbose_level; -char *file; - -bool reqsave; - -void printf_help(void); -void exit_save(void); - -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 { - Eprintf("Unknown parameter: %s\n", argv[i]); - exit(1); - } - } - - if (file == NULL) { - Eprintf("No Kconfig input file specified\n"); - exit(2); - } - - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); - - conf_parse(file); - conf_read(".config"); - - dotconfig_read(&reqsave); - - struct menu *wroot, *wmenu, *wwmenu; - wroot = &rootmenu; - int menucount; - char *input; - int inputi; - input = malloc(INPUT_SIZE * sizeof(char)); - - printf_help(); - - rootmenu.data = menudata_new(); - while (1) { - printf("\n%s\n", wroot->prompt->text); - wmenu = wroot->list; - menucount = 0; - while (wmenu != NULL) { - if (wmenu->prompt != NULL - && (wmenu->sym == NULL || wmenu->sym->type == S_BOOLEAN - || wmenu->sym->type == S_TRISTATE - || wmenu->sym->type == S_OTHER)) { - if (wmenu->data == NULL) - wmenu->data = menudata_new(); - printf("%3d", ++menucount); - if (((struct menudata *) wmenu->data)->permute) { - printf(""); - } else if (((struct menudata *) wmenu->data)->subpermute) { - printf("<->"); - } else { - printf(""); - } - if (wmenu->sym == NULL || sym_is_choice(wmenu->sym)) - printf(" %s -->\n", wmenu->prompt->text); - else - printf(" %s\n", 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 - && (wwmenu->sym == NULL - || wwmenu->sym->type == S_BOOLEAN - || wwmenu->sym->type == S_TRISTATE - || wwmenu->sym->type == S_OTHER)) - y++; - if (y >= inputi) - break; - wwmenu = wwmenu->next; - } - break; - case 'u': - if (wroot->parent == NULL) - goto input; - wroot = wroot->parent; - break; - case 's': - reqsave = false; - dotconfig_write(); - printf("Configuration saved...\n"); - case 'r': - break; - case 'q': - goto quit; - case 'h': - printf_help(); - default: - goto input; - } - switch (input[0]) { - case 'e': - if (wwmenu->list != NULL) - wroot = wwmenu; - else - goto input; - break; - case 'v': - if (input[1] == 'a') { - menudata_set_all_permute(wwmenu, true); - } else { - menudata_set_permute(wwmenu, true); - } - reqsave = true; - break; - case 'f': - menudata_set_permute(wwmenu, false); - reqsave = true; - break; - } - } - - quit: - exit_save(); - - return 0; -} - -void printf_help(void) { - printf("As input are accepted these commands:\n"); - printf(" e Enter menu according to number.\n"); - printf(" u Go to previous upper menu.\n"); - printf(" v Set config as variable.\n"); - printf(" va Set menu and all its submenus as variable.\n"); - printf(" f Set menu and all its submenus as fixed.\n"); - printf(" s Save settings.\n"); - printf(" r Reprint menu.\n"); - printf(" h Prints this text.\n"); - printf(" q Quit this program\n"); -} - -void exit_save(void) { - if (!reqsave) - return; - printf("Unsaved chages. Save (y/N): "); - int ch = fgetc(stdin); - if (ch == 'y' || ch == 'Y') { - dotconfig_write(); - printf("Configuration saved.\n"); - } -} diff --git a/scripts/permute/permutelist.h b/scripts/permute/permutelist.h deleted file mode 100644 index 725f6d6..0000000 --- a/scripts/permute/permutelist.h +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - -#ifndef _PERMUTELIST_H_ -#define _PERMUTELIST_H_ - -struct permutelist { - struct menu *permute; - size_t size, pos; -}; - -void permutelist_add(struct menu *m); -void permutelist_remove(struct menu *m); -bool permutelist_is_permute(struct menu *m); - -#endif /* _PERMUTELIST_H_ */ diff --git a/scripts/permute_conf/.gitignore b/scripts/permute_conf/.gitignore new file mode 100644 index 0000000..7fe1c05 --- /dev/null +++ b/scripts/permute_conf/.gitignore @@ -0,0 +1 @@ +permute_conf diff --git a/scripts/permute_conf/Makefile b/scripts/permute_conf/Makefile new file mode 100644 index 0000000..e0f7cd2 --- /dev/null +++ b/scripts/permute_conf/Makefile @@ -0,0 +1,25 @@ +MAKEFLAGS += --no-builtin-rules +.PHONY: all clean +.SUFFIXES: + +all: permute_conf + +KCONFIG_PREFIX = ../shared/kconfig +include $(KCONFIG_PREFIX)/files.mk + +SRC = permute_conf.c \ + menudata.c \ + dotconf.c +OBJ = $(patsubst %.c,%.o,$(SRC)) +CFLAGS = -O0 -Wall -ggdb -DDEBUG +INCLUDES = -I../shared + +%.o: %.c + gcc -c $(CFLAGS) -o $@ $^ $(INCLUDES) + +permute_conf: $(OBJ) $(KCONFIG_OBJ) + gcc -o $@ $^ + +clean:: + $(RM) $(OBJ) + $(RM) permute_conf diff --git a/scripts/permute_conf/constlist.h b/scripts/permute_conf/constlist.h new file mode 100644 index 0000000..01f172a --- /dev/null +++ b/scripts/permute_conf/constlist.h @@ -0,0 +1,7 @@ +#include +#include + +#ifndef _CONSTLIST_H_ +#define _CONSTLIST_H_ + +#endif /* _CONSTLIST_H_ */ diff --git a/scripts/permute_conf/dotconf.c b/scripts/permute_conf/dotconf.c new file mode 100644 index 0000000..bf8e067 --- /dev/null +++ b/scripts/permute_conf/dotconf.c @@ -0,0 +1,108 @@ +#include "dotconf.h" + +void dotconfig_read(bool * reqsave) { + FILE *f; + f = fopen(DOTCONFIG_FILE, "r"); + if (f == NULL) { + *reqsave = true; + return; + } + + 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_get_tristate_value(sym) == yes && *(end + 1) != 'y') + || (sym_get_tristate_value(sym) == no + && *(end + 1) != 'n')) + *reqsave = true; + struct property *prop; + for_all_prompts(sym, prop) { + if (prop->menu->data == NULL) + prop->menu->data = menudata_new(); + } + } + } + + fclose(f); + + struct menu *wmenu; + struct menu **stack; + size_t stack_size = 2, stack_pos = 0; + stack = malloc(stack_size * sizeof(struct menu *)); + wmenu = rootmenu.list; + while (wmenu != NULL) { + if (wmenu->list != NULL) { + if (stack_pos >= stack_size) { + stack_size *= 2; + stack = realloc(stack, stack_size * sizeof(struct menu *)); + } + stack[stack_pos++] = wmenu->list; + } + if (wmenu->data == NULL) { + if (wmenu->sym == NULL || wmenu->sym->name == NULL) { + wmenu->data = menudata_new(); + } else { + wmenu->data = menudata_new(); + menudata_set_permute(wmenu, true); + } + } + wmenu = wmenu->next; + if (wmenu == NULL && stack_pos > 0) + wmenu = stack[--stack_pos]; + } + while (wmenu != NULL) { + if (wmenu->list != NULL) + stack[stack_pos++] = wmenu->list; + if (wmenu->data == NULL) { + if (wmenu->sym == NULL || wmenu->sym->name == NULL) { + wmenu->data = menudata_new(); + } else { + wmenu->data = menudata_new(); + menudata_set_permute(wmenu, true); + } + } + wmenu = wmenu->next; + if (wmenu == NULL && stack_pos > 0) + wmenu = stack[--stack_pos]; + } +} + +void dotconfig_write(void) { + FILE *f; + f = fopen(DOTCONFIG_FILE, "w"); + + struct symbol *sym; + struct property *prop; + int i; + unsigned variable = 0, fixed = 0; + for_all_symbols(i, sym) + if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) + && sym->name != NULL) { + for_all_prompts(sym, prop) { + if (prop->menu->data == NULL + || !((struct menudata *) prop->menu->data)->permute) { + fprintf(f, "CONFIG_%s=%s\n", sym->name, + sym_get_tristate_value(sym) == no ? "n" : "y"); + fixed++; + break; + } else { + variable++; + if (verbose_level > 1) + printf("%s=%s\n", sym->name, + sym_get_tristate_value(sym) == no ? "n" : "y"); + } + } + } + + printf("Variable: %d, Fixed: %d\n", variable, fixed); + + fclose(f); +} diff --git a/scripts/permute_conf/dotconf.h b/scripts/permute_conf/dotconf.h new file mode 100644 index 0000000..34fa8db --- /dev/null +++ b/scripts/permute_conf/dotconf.h @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#include +#include +#include "menudata.h" + +#ifndef _DOTCONF_H_ +#define _DOTCONF_H_ + +#define DOTCONFIG_FILE "../dot_config" +#define READBUFFER_SIZE 128 + +void dotconfig_read(bool * reqsave); +void dotconfig_write(void); + +#endif /* _DOTCONF_H_ */ diff --git a/scripts/permute_conf/menudata.c b/scripts/permute_conf/menudata.c new file mode 100644 index 0000000..88910ab --- /dev/null +++ b/scripts/permute_conf/menudata.c @@ -0,0 +1,58 @@ +#include "menudata.h" + +struct menudata *menudata_new(void) { + struct menudata *rtn; + rtn = calloc(1, sizeof(struct menudata)); + return rtn; +} + +void menudata_set_permute(struct menu *m, bool perm) { + ((struct menudata *) m->data)->permute = perm; + struct menu *prnt; + for (prnt = m; prnt != NULL; prnt = prnt->parent) { + menudata_cal(prnt); + } +} + +void menudata_set_all_permute(struct menu *m, bool perm) { + menudata_set_permute(m, perm); + + struct menu **stack; + size_t stack_size = 2, stack_pos = 0; + stack = malloc(stack_size * sizeof(struct menu *)); + + m = m->list; + while (m != NULL) { + if (m->data == NULL) + m->data = menudata_new(); + ((struct menudata *) m->data)->permute = perm; + ((struct menudata *) m->data)->subpermute = perm; + + if (m->list != NULL) { + if (stack_pos >= stack_size) { + stack_size *= 2; + stack = realloc(stack, stack_size * sizeof(struct menu *)); + } + stack[stack_pos++] = m->list; + } + + m = m->next; + if (m == NULL && stack_pos > 0) + m = stack[--stack_pos]; + } + +} + +void menudata_cal(struct menu *m) { + bool subperm = false; + struct menu *w; + for (w = m->list; w != NULL; w = w->next) { + if (w->data != NULL && (((struct menudata *) w->data)->permute + || ((struct menudata *) w->data)-> + subpermute)) { + if (m->data == NULL) + m->data = menudata_new(); + ((struct menudata *) m->data)->subpermute = subperm; + } + } +} diff --git a/scripts/permute_conf/menudata.h b/scripts/permute_conf/menudata.h new file mode 100644 index 0000000..a273891 --- /dev/null +++ b/scripts/permute_conf/menudata.h @@ -0,0 +1,20 @@ +#include +#include +#include + +#include + +#ifndef _MENUDATA_H_ +#define _MENUDATA_H_ + +struct menudata { + bool permute; + bool subpermute; +}; + +struct menudata *menudata_new(void); +void menudata_set_permute(struct menu *m, bool perm); +void menudata_set_all_permute(struct menu *m, bool perm); +void menudata_cal(struct menu *m); + +#endif /* _MENUDATA_H_ */ diff --git a/scripts/permute_conf/permute_conf.c b/scripts/permute_conf/permute_conf.c new file mode 100644 index 0000000..ec9abf0 --- /dev/null +++ b/scripts/permute_conf/permute_conf.c @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "menudata.h" +#include "dotconf.h" + +#define INPUT_SIZE 1024 + +int verbose_level; +char *file; + +bool reqsave; + +void printf_help(void); +void exit_save(void); + +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 { + Eprintf("Unknown parameter: %s\n", argv[i]); + exit(1); + } + } + + if (file == NULL) { + Eprintf("No Kconfig input file specified\n"); + exit(2); + } + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + conf_parse(file); + conf_read(".config"); + + dotconfig_read(&reqsave); + + struct menu *wroot, *wmenu, *wwmenu; + wroot = &rootmenu; + int menucount; + char *input; + int inputi; + input = malloc(INPUT_SIZE * sizeof(char)); + + printf_help(); + + rootmenu.data = menudata_new(); + while (1) { + printf("\n%s\n", wroot->prompt->text); + wmenu = wroot->list; + menucount = 0; + while (wmenu != NULL) { + if (wmenu->prompt != NULL + && (wmenu->sym == NULL || wmenu->sym->type == S_BOOLEAN + || wmenu->sym->type == S_TRISTATE + || wmenu->sym->type == S_OTHER)) { + if (wmenu->data == NULL) + wmenu->data = menudata_new(); + printf("%3d", ++menucount); + if (((struct menudata *) wmenu->data)->permute) { + printf(""); + } else if (((struct menudata *) wmenu->data)->subpermute) { + printf("<->"); + } else { + printf(""); + } + if (wmenu->sym == NULL || sym_is_choice(wmenu->sym)) + printf(" %s -->\n", wmenu->prompt->text); + else + printf(" %s\n", 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 + && (wwmenu->sym == NULL + || wwmenu->sym->type == S_BOOLEAN + || wwmenu->sym->type == S_TRISTATE + || wwmenu->sym->type == S_OTHER)) + y++; + if (y >= inputi) + break; + wwmenu = wwmenu->next; + } + break; + case 'u': + if (wroot->parent == NULL) + goto input; + wroot = wroot->parent; + break; + case 's': + reqsave = false; + dotconfig_write(); + printf("Configuration saved...\n"); + case 'r': + break; + case 'q': + goto quit; + case 'h': + printf_help(); + default: + goto input; + } + switch (input[0]) { + case 'e': + if (wwmenu->list != NULL) + wroot = wwmenu; + else + goto input; + break; + case 'v': + if (input[1] == 'a') { + menudata_set_all_permute(wwmenu, true); + } else { + menudata_set_permute(wwmenu, true); + } + reqsave = true; + break; + case 'f': + menudata_set_permute(wwmenu, false); + reqsave = true; + break; + } + } + + quit: + exit_save(); + + return 0; +} + +void printf_help(void) { + printf("As input are accepted these commands:\n"); + printf(" e Enter menu according to number.\n"); + printf(" u Go to previous upper menu.\n"); + printf(" v Set config as variable.\n"); + printf(" va Set menu and all its submenus as variable.\n"); + printf(" f Set menu and all its submenus as fixed.\n"); + printf(" s Save settings.\n"); + printf(" r Reprint menu.\n"); + printf(" h Prints this text.\n"); + printf(" q Quit this program\n"); +} + +void exit_save(void) { + if (!reqsave) + return; + printf("Unsaved chages. Save (y/N): "); + int ch = fgetc(stdin); + if (ch == 'y' || ch == 'Y') { + dotconfig_write(); + printf("Configuration saved.\n"); + } +} diff --git a/scripts/permute_conf/permutelist.h b/scripts/permute_conf/permutelist.h new file mode 100644 index 0000000..725f6d6 --- /dev/null +++ b/scripts/permute_conf/permutelist.h @@ -0,0 +1,17 @@ +#include +#include +#include + +#ifndef _PERMUTELIST_H_ +#define _PERMUTELIST_H_ + +struct permutelist { + struct menu *permute; + size_t size, pos; +}; + +void permutelist_add(struct menu *m); +void permutelist_remove(struct menu *m); +bool permutelist_is_permute(struct menu *m); + +#endif /* _PERMUTELIST_H_ */ -- cgit v1.2.3