- win->client_cache = silc_idcache_alloc(0);
- win->channel_cache = silc_idcache_alloc(0);
- win->server_cache = silc_idcache_alloc(0);
-
- /* Add the window to windows table */
- client->windows = silc_realloc(client->windows, sizeof(*client->windows)
- * (client->windows_count + 1));
- client->windows[client->windows_count] = win;
- client->windows_count++;
-
- if (is_current == TRUE)
- client->current_win = win;
-
- return win;
-}
-
-/* The main task on SILC client. This processes the key pressings user
- has made. */
-
-SILC_TASK_CALLBACK(silc_client_process_key_press)
-{
- SilcClient client = (SilcClient)context;
- int c;
-
- /* There is data pending in stdin, this gets it directly */
- c = wgetch(client->screen->input_win);
- if (silc_client_bad_keys(c))
- return;
-
- SILC_LOG_DEBUG(("Pressed key: %d", c));
-
- switch(c) {
- /*
- * Special character handling
- */
- case KEY_UP:
- case KEY_DOWN:
- break;
- case KEY_RIGHT:
- /* Right arrow */
- SILC_LOG_DEBUG(("RIGHT"));
- silc_screen_input_cursor_right(client->screen);
- break;
- case KEY_LEFT:
- /* Left arrow */
- SILC_LOG_DEBUG(("LEFT"));
- silc_screen_input_cursor_left(client->screen);
- break;
- case KEY_BACKSPACE:
- case KEY_DC:
- case '\177':
- case '\b':
- /* Backspace */
- silc_screen_input_backspace(client->screen);
- break;
- case '\011':
- /* Tabulator */
- break;
- case KEY_IC:
- /* Insert switch. Turns on/off insert on input window */
- silc_screen_input_insert(client->screen);
- break;
- case CTRL('j'):
- case '\r':
- /* Enter, Return. User pressed enter we are ready to
- process the message. */
- silc_client_process_message(client);
- break;
- case CTRL('l'):
- /* Refresh screen, Ctrl^l */
- silc_screen_refresh_all(client->screen);
- break;
- case CTRL('a'):
- case KEY_HOME:
- case KEY_BEG:
- /* Beginning, Home */
- silc_screen_input_cursor_home(client->screen);
- break;
- case CTRL('e'):
- case KEY_END:
- /* End */
- silc_screen_input_cursor_end(client->screen);
- break;
- case KEY_LL:
- /* End */
- break;
- case CTRL('g'):
- /* Bell, Ctrl^g */
- beep();
- break;
- case KEY_DL:
- case CTRL('u'):
- /* Delete line */
- silc_client_clear_input(client);
- break;
- default:
- /*
- * Other characters
- */
- if (c < 32) {
- /* Control codes are printed as reversed */
- c = (c & 127) | 64;
- wattron(client->screen->input_win, A_REVERSE);
- silc_screen_input_print(client->screen, c);
- wattroff(client->screen->input_win, A_REVERSE);
- } else {
- /* Normal character */
- silc_screen_input_print(client->screen, c);
- }
- }
-
- silc_screen_print_coordinates(client->screen, 0);
- silc_screen_refresh_win(client->screen->input_win);
-}
-
-static int silc_client_bad_keys(unsigned char key)
-{
- /* these are explained in curses.h */
- switch(key) {
- case KEY_SF:
- case KEY_SR:
- case KEY_NPAGE:
- case KEY_PPAGE:
- case KEY_PRINT:
- case KEY_A1:
- case KEY_A3:
- case KEY_B2:
- case KEY_C1:
- case KEY_C3:
- case KEY_UNDO:
- case KEY_EXIT:
- case '\v': /* VT */
- case '\E': /* we ignore ESC */
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-/* Clears input buffer */
-
-static void silc_client_clear_input(SilcClient client)
-{
- silc_buffer_clear(client->input_buffer);
- silc_buffer_pull_tail(client->input_buffer,
- SILC_BUFFER_END(client->input_buffer));
- silc_screen_input_reset(client->screen);
-}
-
-/* Processes messages user has typed on the screen. This either sends
- a packet out to network or if command were written executes it. */
-
-static void silc_client_process_message(SilcClient client)
-{
- unsigned char *data;
- unsigned int len;
-
- SILC_LOG_DEBUG(("Start"));
-
- data = client->input_buffer->data;
- len = strlen(data);
-
- if (data[0] == '/' && data[1] != ' ') {
- /* Command */
- unsigned int argc = 0;
- unsigned char **argv, *tmpcmd;
- unsigned int *argv_lens, *argv_types;
- SilcClientCommand *cmd;
- SilcClientCommandContext ctx;
-
- /* Get the command */
- tmpcmd = silc_client_parse_command(data);
-
- /* Find command match */
- for (cmd = silc_command_list; cmd->name; cmd++) {
- if (!strncmp(cmd->name, tmpcmd, strlen(tmpcmd)))
- break;