static void present_form(struct dfui_form *f, char *action) { int done = 0; struct dfui_action *a; display_form(f); while (!done) { printf("Select an action> "); fgets(action, 80, stdin); action[strlen(action) - 1] = '\0'; if ((a = dfui_form_action_find(f, action)) != NULL) { done = 1; } else { printf("Invalid option.\n"); } } }
static void demo_forms(void) { WINDOW *w; FORM *form; FIELD *f[100]; /* FIXME memset to zero */ int finished = 0, c; unsigned n = 0; int pg; WINDOW *also; #ifdef NCURSES_MOUSE_VERSION mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); #endif help_edit_field(); MvAddStr(4, 57, "Forms Entry Test"); show_insert_mode(TRUE); refresh(); /* describe the form */ memset(f, 0, sizeof(f)); for (pg = 0; pg < 4; ++pg) { char label[80]; sprintf(label, "Sample Form Page %d", pg + 1); f[n++] = make_label(0, 15, label); set_new_page(f[n - 1], TRUE); switch (pg) { default: f[n++] = make_label(2, 0, "Last Name"); f[n++] = make_field(3, 0, 1, 18); set_field_type(f[n - 1], TYPE_ALPHA, 1); f[n++] = make_label(2, 20, "First Name"); f[n++] = make_field(3, 20, 1, 12); set_field_type(f[n - 1], TYPE_ALPHA, 1); f[n++] = make_label(2, 34, "Middle Name"); f[n++] = make_field(3, 34, 1, 12); set_field_type(f[n - 1], TYPE_ALPHA, 1); break; case 1: f[n++] = make_label(2, 0, "Last Name"); f[n++] = make_field(3, 0, 1, 18); set_field_type(f[n - 1], TYPE_ALPHA, 1); f[n++] = make_label(2, 20, "First Name"); f[n++] = make_field(3, 20, 1, 12); set_field_type(f[n - 1], TYPE_ALPHA, 1); f[n++] = make_label(2, 34, "MI"); f[n++] = make_field(3, 34, 1, 1); set_field_pad(f[n - 1], '?'); set_field_type(f[n - 1], TYPE_ALPHA, 1); break; case 2: f[n++] = make_label(2, 0, "Host Name"); f[n++] = make_field(3, 0, 1, 18); set_field_type(f[n - 1], TYPE_ALNUM, 1); #ifdef NCURSES_VERSION f[n++] = make_label(2, 20, "IP Address"); f[n++] = make_field(3, 20, 1, 12); set_field_type(f[n - 1], TYPE_IPV4, 1); #endif break; case 3: f[n++] = make_label(2, 0, "Four digits"); f[n++] = make_field(3, 0, 1, 18); set_field_type(f[n - 1], TYPE_INTEGER, 4, 0, 0); f[n++] = make_label(2, 20, "Numeric"); f[n++] = make_field(3, 20, 1, 12); set_field_type(f[n - 1], TYPE_NUMERIC, 3, -10000.0, 100000000.0); break; } f[n++] = make_label(5, 0, "Comments"); f[n++] = make_field(6, 0, 4, 46); set_field_buffer(f[n - 1], 0, "HELLO\nWORLD!"); set_field_buffer(f[n - 1], 1, "Hello\nWorld!"); } f[n] = (FIELD *) 0; if ((form = new_form(f)) != 0) { display_form(form); w = form_win(form); also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0); show_current_field(also, form); while (!finished) { switch (edit_field(form, &c)) { case E_OK: break; case E_UNKNOWN_COMMAND: finished = my_form_driver(form, c); break; default: beep(); break; } show_current_field(also, form); } erase_form(form); free_form(form); } for (c = 0; f[c] != 0; c++) { void *ptr = field_userptr(f[c]); free(ptr); free_field(f[c]); } noraw(); nl(); #ifdef NCURSES_MOUSE_VERSION mousemask(0, (mmask_t *) 0); #endif }