static void dcc_files(int idx, char *buf, int i) { Context; if (buf[0] && detect_dcc_flood(&dcc[idx].timeval, dcc[idx].u.file->chat, idx)) return; dcc[idx].timeval = now; strcpy(buf, check_tcl_filt(idx, buf)); if (!buf[0]) return; touch_laston(dcc[idx].user, "filearea", now); if (buf[0] == ',') { for (i = 0; i < dcc_total; i++) { if ((dcc[i].type->flags & DCT_MASTER) && dcc[idx].user && (dcc[idx].user->flags & USER_MASTER) && ((dcc[i].type == &DCC_FILES) || (dcc[i].u.chat->channel >= 0)) && ((i != idx) || (dcc[idx].status & STAT_ECHO))) dprintf(i, "-%s- %s\n", dcc[idx].nick, &buf[1]); } } else if (got_files_cmd(idx, buf)) { dprintf(idx, "*** Ja mata!\n"); flush_lines(idx, dcc[idx].u.file->chat); putlog(LOG_FILES, "*", "DCC user [%s]%s left file system", dcc[idx].nick, dcc[idx].host); set_user(&USERENTRY_DCCDIR, dcc[idx].user, dcc[idx].u.file->dir); if (dcc[idx].status & STAT_CHAT) { struct chat_info *ci; dprintf(idx, "Returning you to command mode...\n"); ci = dcc[idx].u.file->chat; nfree(dcc[idx].u.file); dcc[idx].u.chat = ci; dcc[idx].status &= (~STAT_CHAT); dcc[idx].type = &DCC_CHAT; if (dcc[idx].u.chat->channel >= 0) { chanout_but(-1, dcc[idx].u.chat->channel, "*** %s has returned.\n", dcc[idx].nick); if (dcc[idx].u.chat->channel < 100000) botnet_send_join_idx(idx, -1); } } else { dprintf(idx, "Dropping connection now.\n"); putlog(LOG_FILES, "*", "Left files: [%s]%s/%d", dcc[idx].nick, dcc[idx].host, dcc[idx].port); killsock(dcc[idx].sock); lostdcc(idx); } } if (dcc[idx].status & STAT_PAGE) flush_lines(idx, dcc[idx].u.file->chat); }
/** * Display inventory items. */ void inventory () { int old_fg, old_bg; int n; /* screen is white with black text */ old_fg = game.color_fg; old_bg = game.color_bg; game.color_fg = 0; game.color_bg = 15; clear_screen (game.color_bg); print_text (YOUHAVE_MSG, 0, YOUHAVE_X, YOUHAVE_Y, 40, STATUS_FG, STATUS_BG); /* FIXME: doesn't check if objects overflow off screen... */ intobj = malloc (4 + game.num_objects); memset(intobj, 0, (4 + game.num_objects)); n = show_items (); if (getflag (F_status_selects_items)) { print_text (SELECT_MSG, 0, SELECT_X, SELECT_Y, 40, STATUS_FG, STATUS_BG); } else { print_text (ANY_KEY_MSG, 0, ANY_KEY_X, ANY_KEY_Y, 40, STATUS_FG, STATUS_BG); } flush_screen (); /* If flag 13 is set, we want to highlight & select an item. * opon selection, put objnum in var 25. Then on esc put in * var 25 = 0xff. */ if (getflag (F_status_selects_items)) select_items (n); free (intobj); if (!getflag (F_status_selects_items)) wait_any_key(); clear_screen (0); write_status (); show_pic (); game.color_fg = old_fg; game.color_bg = old_bg; game.has_prompt = 0; flush_lines (game.line_user_input, 24); }
/** * Write the status line. */ void TextMan::write_status() { char x[64]; if (debug_.statusline) { print_status("%3d(%03d) %3d,%3d(%3d,%3d) ", getvar(0), getvar(1), game.view_table[0].x_pos, game.view_table[0].y_pos, WIN_TO_PIC_X(mouse.x), WIN_TO_PIC_Y(mouse.y)); return; } if (!game.status_line) { int l = game.line_status; clear_lines(l, l, 0); flush_lines(l, l); return; } sprintf(x, " Score:%i of %-3i", game.vars[V_score], game.vars[V_max_score]); print_status("%-17s Sound:%s ", x, getflag(F_sound_on) ? "on " : "off"); }
/** * Print user input prompt. */ void TextMan::write_prompt() { int l, fg, bg, pos; if (!game.input_enabled || game.input_mode != INPUT_NORMAL) return; l = game.line_user_input; fg = game.color_fg; bg = game.color_bg; pos = game.cursor_pos; debugC(4, kDebugLevelText, "erase line %d", l); clear_lines(l, l, game.color_bg); debugC(4, kDebugLevelText, "prompt = '%s'", agi_sprintf(game.strings[0])); print_text(game.strings[0], 0, 0, l, 1, fg, bg); print_text((char *)game.input_buffer, 0, 1, l, pos + 1, fg, bg); print_character(pos + 1, l, game.cursor_char, fg, bg); flush_lines(l, l); do_update(); }
int main(int argc, char **argv) { wint_t ch; CHAR *c; CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ int cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ int nflushd_lines; /* number of lines that were flushed */ int adjust, opt, warned, width; (void)setlocale(LC_CTYPE, ""); max_bufd_lines = 128; compress_spaces = 1; /* compress spaces into tabs */ while ((opt = getopt(argc, argv, "bfhl:px")) != -1) switch (opt) { case 'b': /* do not output backspaces */ no_backspaces = 1; break; case 'f': /* allow half forward line feeds */ fine = 1; break; case 'h': /* compress spaces into tabs */ compress_spaces = 1; break; case 'l': /* buffered line count */ if ((max_bufd_lines = atoi(optarg)) <= 0) errx(1, "bad -l argument %s", optarg); break; case 'p': /* pass unknown control sequences */ pass_unknown_seqs = 1; break; case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; case '?': default: usage(); } if (optind != argc) usage(); /* this value is in half lines */ max_bufd_lines *= 2; adjust = cur_col = extra_lines = warned = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); while ((ch = getwchar()) != WEOF) { if (!iswgraph(ch)) { switch (ch) { case BS: /* can't go back further */ if (cur_col == 0) continue; --cur_col; continue; case CR: cur_col = 0; continue; case ESC: /* just ignore EOF */ switch(getwchar()) { case RLF: cur_line -= 2; break; case RHLF: cur_line--; break; case FHLF: cur_line++; if (cur_line > max_line) max_line = cur_line; } continue; case NL: cur_line += 2; if (cur_line > max_line) max_line = cur_line; cur_col = 0; continue; case SPACE: ++cur_col; continue; case SI: cur_set = CS_NORMAL; continue; case SO: cur_set = CS_ALTERNATE; continue; case TAB: /* adjust column */ cur_col |= 7; ++cur_col; continue; case VT: cur_line -= 2; continue; } if (iswspace(ch)) { if ((width = wcwidth(ch)) > 0) cur_col += width; continue; } if (!pass_unknown_seqs) continue; } /* Must stuff ch in a line - are we at the right one? */ if (cur_line != this_line - adjust) { LINE *lnew; int nmove; adjust = 0; nmove = cur_line - this_line; if (!fine) { /* round up to next line */ if (cur_line & 1) { adjust = 1; nmove++; } } if (nmove < 0) { for (; nmove < 0 && l->l_prev; nmove++) l = l->l_prev; if (nmove) { if (nflushd_lines == 0) { /* * Allow backup past first * line if nothing has been * flushed yet. */ for (; nmove < 0; nmove++) { lnew = alloc_line(); l->l_prev = lnew; lnew->l_next = l; l = lines = lnew; extra_lines++; } } else { if (!warned++) dowarn(cur_line); cur_line -= nmove; } } } else { /* may need to allocate here */ for (; nmove > 0 && l->l_next; nmove--) l = l->l_next; for (; nmove > 0; nmove--) { lnew = alloc_line(); lnew->l_prev = l; l->l_next = lnew; l = lnew; } } this_line = cur_line + adjust; nmove = this_line - nflushd_lines; if (nmove >= max_bufd_lines + BUFFER_MARGIN) { nflushd_lines += nmove - max_bufd_lines; flush_lines(nmove - max_bufd_lines); } } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { int need; need = l->l_lsize ? l->l_lsize * 2 : 90; if ((l->l_line = realloc(l->l_line, (unsigned)need * sizeof(CHAR))) == NULL) err(1, (char *)NULL); l->l_lsize = need; } c = &l->l_line[l->l_line_len++]; c->c_char = ch; c->c_set = cur_set; c->c_column = cur_col; c->c_width = wcwidth(ch); /* * If things are put in out of order, they will need sorting * when it is flushed. */ if (cur_col < l->l_max_col) l->l_needs_sort = 1; else l->l_max_col = cur_col; if (c->c_width > 0) cur_col += c->c_width; } if (ferror(stdin)) err(1, NULL); if (max_line == 0) exit(0); /* no lines, so just exit */ /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) this_line++; flush_lines(this_line - nflushd_lines + extra_lines + 1); /* make sure we leave things in a sane state */ if (last_set != CS_NORMAL) PUTC('\017'); /* flush out the last few blank lines */ nblank_lines = max_line - this_line; if (max_line & 1) nblank_lines++; else if (!nblank_lines) /* missing a \n on the last line? */ nblank_lines = 2; flush_blanks(); exit(0); }
void handle_keys (int key) { UINT8 *p=NULL; int c = 0; static UINT8 formated_entry[256]; int l = game.line_user_input; int fg = game.color_fg, bg = game.color_bg; setvar (V_word_not_found, 0); _D ("handling key: %02x", key); switch (key) { case KEY_ENTER: _D (("KEY_ENTER")); game.keypress = 0; /* Remove all leading spaces */ for (p = game.input_buffer; *p && *p == 0x20; p++); /* Copy to internal buffer */ for (; *p; p++) { /* Squash spaces */ if (*p == 0x20 && *(p + 1) == 0x20) { p++; continue; } formated_entry[c++] = tolower (*p); } formated_entry[c++] = 0; /* Handle string only if it's not empty */ if (formated_entry[0]) { strcpy (game.echo_buffer, game.input_buffer); strcpy (last_sentence, formated_entry); dictionary_words (last_sentence); } /* Clear to start a new line*/ game.has_prompt = 0; game.input_buffer[game.cursor_pos = 0] = 0; _D (_D_WARN "clear lines"); clear_lines (l, l + 1, bg); flush_lines (l, l + 1); break; case KEY_ESCAPE: _D (("KEY_ESCAPE")); new_input_mode (INPUT_MENU); break; case KEY_BACKSPACE: /* Ignore backspace at start of line */ if (game.cursor_pos == 0) break; /* erase cursor */ print_character (game.cursor_pos + 1, l, ' ', fg, bg); game.input_buffer[--game.cursor_pos] = 0; /* Print cursor */ print_character (game.cursor_pos + 1, l, game.cursor_char, fg, bg ); break; default: /* Ignore invalid keystrokes */ if (key < 0x20 || key > 0x7f) break; /* Maximum input size reached */ if (game.cursor_pos >= getvar (V_max_input_chars)) break; game.input_buffer[game.cursor_pos++] = key; game.input_buffer[game.cursor_pos] = 0; /* echo */ print_character (game.cursor_pos, l, game.input_buffer[game.cursor_pos - 1], fg, bg); /* Print cursor */ print_character (game.cursor_pos + 1, l, game.cursor_char, fg, bg); break; } }