creator-level saving new files in fat
[quarnos.git] / scripts / nc_config.c
blob131f5a1f9528084bab2bd6f541065b531e36d8f4
1 /* Quarn OS
3 * Configuration tool
5 * Copyright (C) 2008 Pawel Dziepak
7 * This is a tool that generate configuration file before compilation of Quarn
8 * OS. Possible configuration options are read from external file and parsed.
9 * Then there are shown menus in which user can adjust his own compilation of
10 * the system. This tool uses ncurses, for computers without this library, there
11 * is a less user-friendly shell script.
14 #include <ncurses.h>
15 #include <menu.h>
17 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
19 char *descrs[] = {
20 "Choice 1",
21 "Choice 2",
22 "Choice 3",
25 char *names[] = {
26 "NAME1",
27 "NAME2",
28 "NAME3",
31 int main() {
32 ITEM **config_items;
33 MENU *main_menu;
34 ITEM *cur_item;
35 int n_descrs, i;
36 int c;
38 /* Initialize curses */
39 initscr();
40 start_color();
41 cbreak();
42 noecho();
43 keypad(stdscr, TRUE);
45 /* Initialize and set colors */
46 init_pair(1, COLOR_RED, COLOR_WHITE);
47 init_pair(2, COLOR_GREEN, COLOR_WHITE);
48 init_pair(3, COLOR_YELLOW, COLOR_WHITE);
49 attron(COLOR_PAIR(3));
51 /* Initialize items */
52 n_descrs = ARRAY_SIZE(descrs);
53 config_items = (ITEM **)calloc(n_descrs + 1, sizeof(ITEM *));
54 for(i = 0; i < n_descrs; ++i)
55 config_items[i] = new_item(descrs[i],"");
56 config_items[n_descrs] = (ITEM *)NULL;
58 /* Create menu */
59 main_menu = new_menu((ITEM **)config_items);
61 /* Set foreground and background */
62 set_menu_fore(main_menu, COLOR_PAIR(1) | A_REVERSE);
63 set_menu_back(main_menu, COLOR_PAIR(1));
64 set_menu_grey(main_menu, COLOR_PAIR(2));
66 /* Show the menu */
67 post_menu(main_menu);
68 refresh();
70 /* Main loop */
71 while((c = getch()) != 'q') {
72 switch(c) {
73 case KEY_DOWN:
74 menu_driver(main_menu, REQ_DOWN_ITEM);
75 break;
76 case KEY_UP:
77 menu_driver(main_menu, REQ_UP_ITEM);
78 break;
79 case 10: /* Enter */
80 cur_item = current_item(main_menu);
81 if (item_opts(cur_item) & O_SELECTABLE == O_SELECTABLE) {
82 item_opts_off(cur_item, O_SELECTABLE);
83 } else {
84 item_opts_on(cur_item, O_SELECTABLE);
86 break;
90 /* Clean everything */
91 unpost_menu(main_menu);
92 for(i = 0; i < n_descrs; ++i)
93 free_item(config_items[i]);
94 free_menu(main_menu);
95 endwin();