int do_dictionary_prompt(bool all, const char *msg, char *str) { s_list l; s_node *p; int ok = -2, width = 16; const char *yesstr; /* String of Yes characters accepted. */ const char *nostr; /* Same for No. */ const char *allstr; /* And All, surprise! */ int u; char **thisarray = (char **)malloc(sizeof(char)*5); for(u = 0; u < 5; u++) thisarray[u] = (char *)malloc(sizeof(char)*16); thisarray = thisfunc(str); int oldmenu = currmenu; char but[16]; int i, j = 0; int count = 0; int t = 0; int bs = 0; char buf[16]; strcpy(buf, str); int tp; int we = 0, wc = 0; tp = typepos(); assert(msg != NULL); s_init(&l); u = 0; while(u < 5) { s_append(&l, thisarray[u]); u++; } /*Now partial matched list is prepared*/ p = l.head; if(str == NULL){ count = 0; while(p){ count++; p = p->next; } } //count=5; p = l.head; do { int kbinput; functionptrtype func; i = 0; #ifndef DISABLE_MOUSE int mouse_x, mouse_y; #endif if (!ISSET(NO_HELP)) { char shortstr[3]; /* Temporary string for (translated) " Y", " N" and " A". */ if (COLS < 32) width = COLS / 2; /* Clear the shortcut list from the bottom of the screen. */ blank_bottombars(); /* Now show the ones for "Yes", "No", "Cancel" and maybe "All". */ if (all) { shortstr[1] = allstr[0]; wmove(bottomwin, 1, width); onekey(shortstr, _("All"), width); } for(i = 0; i < count && i < 5; i++){ sprintf(but, "%d", i + 1); if(i == 0) wmove(bottomwin, 1, 0); else wmove(bottomwin, 1, i * width); if(p){ onekey(but, p->word, width); p = p->next; } j++; } wmove(bottomwin, 1, i * width); onekey("^C", _("Cancel"), width); } if (interface_color_pair[TITLE_BAR].bright) wattron(bottomwin, A_BOLD); wattron(bottomwin, interface_color_pair[TITLE_BAR].pairnum); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); wattroff(bottomwin, A_BOLD); wattroff(bottomwin, interface_color_pair[TITLE_BAR].pairnum); /* Refresh edit window and statusbar before getting input. */ wnoutrefresh(edit); wnoutrefresh(bottomwin); currmenu = MYESNO; kbinput = get_kbinput(bottomwin); #ifndef NANO_TINY if (kbinput == KEY_WINCH) continue; #endif /*49 is 1, 50 is 2 and so on*/ func = func_from_key(&kbinput); if (func == do_cancel){ ok = 0; return ok; } if(kbinput == 's'){ if(i == 5) { continue; } } if(kbinput <= '0' || kbinput > '0' + count) return -1; if(kbinput > '0' && kbinput <= '0' + count){ p = l.head; i = kbinput - '0' - 1; if(j > 5) t = j - 5 + i; else t = i; while(t--) if(p){ p = p->next; } if(tp == 1 || tp == 2){ bs = strlen(str); while(bs--) do_backspace(); } if(tp == 6 || tp == 7){ if(str != NULL){ we = openfile->current_x; while(openfile->current->data[we] != ' ' && openfile->current->data[we] != '\00'){ we++; wc++; do_right(); } we--; while(openfile->current->data[we] != ' ' && openfile->current->data[we] != '\00'){ do_backspace(); we--; } } } do_output(p->word, strlen(p->word), FALSE); return tp; } else if (func == total_refresh) { total_redraw(); continue; } else { /* Look for the kbinput in the Yes, No and (optionally) * All strings. */ if (strchr(yesstr, kbinput) != NULL) ok = 1; else if (strchr(nostr, kbinput) != NULL) ok = 0; else if (all && strchr(allstr, kbinput) != NULL) ok = 2; } i = 0; p = l.head; } while (ok == -2); currmenu = oldmenu; return ok; }
/* Event handler in Podzilla compiling style */ static int tuxchess_handle_event(GR_EVENT *event) { int ret = 0; switch (event->type) { case GR_EVENT_TYPE_KEY_DOWN: switch (event->keystroke.ch) { case'm': do_menu(); ret |= KEY_CLICK; break; case'w': if (end == 0) { do_rev(); ret |= KEY_CLICK; } break; case'f': if (end == 0) { do_fwd(); ret |= KEY_CLICK; } break; case'\r': if (end == 0) { do_action(); } else if (end == 1) { draw_end(end_type); } else { new_game(); } ret |= KEY_CLICK; break; case'l': if (end == 0) { do_left(); ret |= KEY_CLICK; } break; case'r': if (end == 0) { do_right(); ret |= KEY_CLICK; } break; default: ret |= KEY_UNUSED; break; } break; default: ret |= EVENT_UNUSED; break; } return ret; }