2 ** Copyright (C) 1991, 1997 Free Software Foundation, Inc.
4 ** This file is part of TACK.
6 ** TACK is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2, or (at your option)
11 ** TACK is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with TACK; see the file COPYING. If not, write to
18 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 ** Boston, MA 02111-1307, USA.
24 MODULE_ID("$Id: menu.c,v 1.2 2000/03/04 21:13:53 tom Exp $")
30 static void test_byname(struct test_menu *, int *, int *);
32 struct test_list *augment_test;
33 char prompt_string[80]; /* menu prompt storage */
38 ** Print the menu prompt string.
43 ptext(&prompt_string[1]);
47 ** menu_test_loop(test-structure, state, control-character)
49 ** This function implements the repeat test function.
53 struct test_list *test,
59 if ((test->flags & MENU_REP_MASK) && (augment_test != test)) {
60 /* set the augment variable (first time only) */
61 p = (test->flags >> 8) & 15;
62 if ((test->flags & MENU_REP_MASK) == MENU_LM1) {
65 if ((test->flags & MENU_ONE_MASK) == MENU_ONE) {
68 if ((test->flags & MENU_LC_MASK) == MENU_lines) {
69 augment = lines * p / 10;
71 if ((test->flags & MENU_LC_MASK) == MENU_columns) {
72 augment = columns * p / 10;
80 if ((test->flags | *state) & MENU_CLEAR) {
83 if (line_count + test->lines_needed >= lines) {
87 if (test->test_procedure) {
88 /* The procedure takes precedence so I can pass
89 the menu entry as an argument.
91 can_test(test->caps_done, FLAG_TESTED);
92 can_test(test->caps_tested, FLAG_TESTED);
93 test->test_procedure(test, state, &nch);
97 menu_display(test->sub_menu, &nch);
99 if (nch == 'q' || nch == 's') {
100 /* Quit and skip are killed here */
106 if (nch == '\r' || nch == '\n' || nch == 'n') {
110 } while (nch == 'r');
115 ** menu_display(menu-structure, flags)
117 ** This function implements menu control.
121 struct test_menu *menu,
124 int test_state = 0, run_standard_tests;
125 int hot_topic, ch = 0, nch = 0;
126 struct test_list *mt;
127 struct test_list *repeat_tests = 0;
128 int repeat_state = 0;
131 prompt_length = strlen(prompt_string);
133 sprintf(&prompt_string[prompt_length], "/%s", menu->ident);
135 hot_topic = menu->default_action;
136 run_standard_tests = menu->standard_tests ?
137 menu->standard_tests[0] : -1;
143 /* Display the menu */
145 if (menu->menu_function) {
147 this function may be used to restrict menu
148 entries. If used it must print the title.
150 menu->menu_function(menu);
152 if (menu->menu_title) {
153 ptextln(menu->menu_title);
155 for (mt = menu->tests; (mt->flags & MENU_LAST) == 0; mt++) {
156 if (mt->menu_entry) {
158 ptextln(mt->menu_entry);
161 if (menu->standard_tests) {
163 ptextln(menu->standard_tests);
164 ptextln(" r) repeat test");
165 ptextln(" s) skip to next test");
170 if (ch == 0 || ch == REQUEST_PROMPT) {
172 ptext(&prompt_string[1]);
179 /* read a character */
182 if (ch == '\r' || ch == '\n') {
194 /* Run one of the standard tests (by request) */
195 for (mt = menu->tests; (mt->flags & MENU_LAST) == 0; mt++) {
196 if (mt->menu_entry && (nch == mt->menu_entry[0])) {
197 if (mt->flags & MENU_MENU) {
198 test_byname(menu, &test_state, &nch);
200 menu_test_loop(mt, &test_state, &nch);
203 if ((mt->flags & MENU_COMPLETE) && ch == 0) {
210 if (menu->standard_tests && nch == 'r') {
211 menu->resume_tests = repeat_tests;
212 test_state = repeat_state;
213 nch = run_standard_tests;
215 if (nch == run_standard_tests) {
216 if (!(mt = menu->resume_tests)) {
219 if (mt->flags & MENU_LAST) {
222 /* Run the standard test suite */
223 for ( ; (mt->flags & MENU_LAST) == 0; ) {
224 if ((mt->flags & MENU_NEXT) == MENU_NEXT) {
226 repeat_state = test_state;
227 nch = run_standard_tests;
228 menu_test_loop(mt, &test_state, &nch);
229 if (nch != 0 && nch != 'n') {
233 if (test_state & MENU_STOP) {
242 menu->resume_tests = mt;
243 menu->resume_state = test_state;
244 menu->resume_char = ch;
246 if (ch == run_standard_tests) {
253 prompt_string[prompt_length] = '\0';
257 ** generic_done_message(test_list)
259 ** Print the Done message and request input.
262 generic_done_message(
263 struct test_list *test,
267 char done_message[128];
269 if (test->caps_done) {
270 sprintf(done_message, "(%s) Done ", test->caps_done);
276 if (*ch == '\r' || *ch == '\n' || *ch == 'n') {
286 ** menu_clear_screen(test, state, ch)
288 ** Just clear the screen.
292 struct test_list *test GCC_UNUSED,
293 int *state GCC_UNUSED,
300 ** menu_reset_init(test, state, ch)
302 ** Send the reset and init strings.
306 struct test_list *test GCC_UNUSED,
307 int *state GCC_UNUSED,
315 ** subtest_menu(test, state, ch)
317 ** Scan the menu looking for something to execute
318 ** Return TRUE if we found anything.
322 struct test_list *test,
326 struct test_list *mt;
329 for (mt = test; (mt->flags & MENU_LAST) == 0; mt++) {
330 if (mt->menu_entry && (*ch == mt->menu_entry[0])) {
332 menu_test_loop(mt, state, ch);
341 ** menu_can_scan(menu-structure)
343 ** Recursively scan the menu tree and find which cap names can be tested.
347 const struct test_menu *menu)
349 struct test_list *mt;
351 for (mt = menu->tests; (mt->flags & MENU_LAST) == 0; mt++) {
352 can_test(mt->caps_done, FLAG_CAN_TEST);
353 can_test(mt->caps_tested, FLAG_CAN_TEST);
354 if (!(mt->test_procedure)) {
356 menu_can_scan(mt->sub_menu);
363 ** menu_search(menu-structure, cap)
365 ** Recursively search the menu tree and execute any tests that use cap.
369 struct test_menu *menu,
374 struct test_list *mt;
377 for (mt = menu->tests; (mt->flags & MENU_LAST) == 0; mt++) {
379 if (cap_match(mt->caps_done, cap)
380 || cap_match(mt->caps_tested, cap)) {
381 menu_test_loop(mt, state, &nch);
383 if (!(mt->test_procedure)) {
385 menu_search(mt->sub_menu, state, &nch, cap);
388 if (*state & MENU_STOP) {
391 if (nch != 0 && nch != 'n') {
399 ** test_byname(menu, state, ch)
401 ** Get a cap name then run all tests that use that cap.
405 struct test_menu *menu,
406 int *state GCC_UNUSED,
412 if (tty_can_sync == SYNC_NOT_TESTED) {
415 ptext("enter name: ");
416 read_string(cap, sizeof(cap));
418 menu_search(menu, &test_state, ch, cap);