int menu2(MENU *table, int top) { int i, tablesize, choice; char c; char storage[BUFSIZ]; int pagesize = max_lines - 7 - TITLE_LINE; int pagetop = 1; int redraw = FALSE; tablesize = 0; for (i = 0; !end_of_menu(table, i); i++) { tablesize++; } tablesize--; for (;;) { vt_move(top, 1); vt_clear(0); println(""); show_entry(table, 0); for (i = 0; i < pagesize; i++) { int j = pagetop + i; if (end_of_menu(table, j)) break; show_entry(table, pagetop + i); } printf("\n Enter choice number (0 - %d): ", tablesize); for (;;) { char *s = storage; inputline(s); choice = 0; redraw = FALSE; while ((c = *s++) != '\0') { if (c == '*') { choice = -1; break; } else if (c == '?') { redraw = TRUE; break; } else if (tablesize > pagesize && c == 'n') { pagetop = next_menu(table, pagetop, pagesize); redraw = TRUE; break; } else if (tablesize > pagesize && c == 'p') { pagetop = prev_menu(pagetop, pagesize); redraw = TRUE; break; } else if (c >= '0' && c <= '9') { choice = 10 * choice + c - '0'; } else { choice = tablesize + 1; break; } } if (redraw) break; if (choice < 0) { for (choice = 0; choice <= tablesize; choice++) { vt_clear(2); if (table[choice].dispatch != 0) { const char *save = push_menu(choice); const char *name = table[choice].description; if (LOG_ENABLED) fprintf(log_fp, "Menu %s: %s\n", current_menu, name); if ((*table[choice].dispatch) (name) == MENU_HOLD) holdit(); pop_menu(save); } } return 1; } else if (choice <= tablesize) { vt_clear(2); if (table[choice].dispatch != 0) { const char *save = push_menu(choice); const char *name = table[choice].description; if (LOG_ENABLED) fprintf(log_fp, "Menu %s: %s\n", current_menu, name); if ((*table[choice].dispatch) (name) != MENU_NOHOLD) holdit(); pop_menu(save); } return (table[choice].dispatch != 0); } printf(" Bad choice, try again: "); } } }
void doback(Fl_Widget *, void *) {pop_menu();}