int rl_vi_overstrike (int count, int key) { int i; if (_rl_vi_doing_insert == 0) { _rl_vi_doing_insert = 1; rl_begin_undo_group (); } for (i = 0; i < count; i++) { vi_replace_count++; rl_begin_undo_group (); if (rl_point < rl_end) { rl_delete (1, key); rl_insert (1, key); } else rl_insert (1, key); rl_end_undo_group (); } return (0); }
int rl_vi_change_char (int count, int key) { int c; if (vi_redoing) c = _rl_vi_last_replacement; else _rl_vi_last_replacement = c = rl_getc (rl_instream); if (c == '\033' || c == CTRL ('C')) return -1; while (count-- && rl_point < rl_end) { rl_begin_undo_group (); rl_delete (1, c); rl_insert (1, c); if (count == 0) rl_backward (1, c); rl_end_undo_group (); } return (0); }
static int match_paren(int x, int k) { int tmp; fd_set readset; struct timeval timeout; rl_insert(x, k); /* Did we just insert a quoted paren? If so, then don't bounce. */ if (rl_point - 1 >= 1 && rl_line_buffer[rl_point - 2] == '\\') return 0; /* tmp = 200000 */ timeout.tv_sec = 0 /* tmp / 1000000 */ ; timeout.tv_usec = 200000 /* tmp % 1000000 */ ; FD_ZERO(&readset); FD_SET(fileno(rl_instream), &readset); if(rl_point > 1) { tmp = rl_point; rl_point = find_matching_paren(k); if(rl_point > -1) { rl_redisplay(); select(1, &readset, NULL, NULL, &timeout); } rl_point = tmp; } return 0; }
/* * Handle key to insert itself */ static void rl_key_insert (wchar_tt ucs) { if (rl_tab_state > 0 && rl_tab_common) { rl_tab_cancel (); rl_insert (ucs); rl_key_tab (); } else { if (rl_tab_state > 0) { rl_tab_accept (); rl_insert (' '); } rl_insert (ucs); } }
static int input_help(int arg, int key UNUSED) { int i, in_string, in_bracket; if (arg != 1) return rl_insert(arg, '?'); in_string = in_bracket = 0; for (i = 0; i < rl_point; i++) { if (rl_line_buffer[i] == '"') in_string = ! in_string; else if (! in_string) { if (rl_line_buffer[i] == '[') in_bracket++; else if (rl_line_buffer[i] == ']') in_bracket--; } } /* `?' inside string or path -> insert */ if (in_string || in_bracket) return rl_insert(1, '?'); rl_begin_undo_group(); /* HACK: We want to display `?' at point position */ rl_insert_text("?"); rl_redisplay(); rl_end_undo_group(); input_start_list(); cmd_help(rl_line_buffer, rl_point); rl_undo_command(1, 0); input_stop_list(); return 0; }
/* * Expand given UTF8 string into (and replace) editing line */ static void rl_lineexpand (const char *hist) { str_s str = { NULL, 0, 0 }; int off; s_init (&rl_ucs, "", 0); s_init (&rl_ucscol, "", 0); s_init (&rl_ucsbytes, "", 0); s_init (&rl_display, "", 0); rl_colpos = rl_ucspos = rl_bytepos = 0; str.txt = (char *) hist; str.len = strlen (str.txt); for (off = 0; off < str.len; ) rl_insert (ConvGetUTF8 (&str, &off)); }
int rl_vi_change_case (int count, int ignore) { char c = 0; /* Don't try this on an empty line. */ if (rl_point >= rl_end) return (0); while (count-- && rl_point < rl_end) { if (uppercase_p (rl_line_buffer[rl_point])) c = to_lower (rl_line_buffer[rl_point]); else if (lowercase_p (rl_line_buffer[rl_point])) c = to_upper (rl_line_buffer[rl_point]); else { /* Just skip over characters neither upper nor lower case. */ rl_forward (1, c); continue; } /* Vi is kind of strange here. */ if (c) { rl_begin_undo_group (); rl_delete (1, c); rl_insert (1, c); rl_end_undo_group (); rl_vi_check (); } else rl_forward (1, c); } return (0); }
// Bounces the cursor to the matching paren for a while int gnu_readline_paren_bounce(int count, int key) { int insert_success; int old_point; int matching; if (gnu_readline_bounce_ms == 0) return 0; // Write the just entered paren out first insert_success = rl_insert(count, key); if (insert_success != 0) return insert_success; rl_redisplay(); // Need at least two chars to bounce... if (rl_point < 2) // rl_point set to next char (implicit +1) return 0; // If it's an escaped paren, don't bounce... if (rl_line_buffer[rl_point - 2] == '\\') return 0; // Bounce old_point = rl_point; matching = gnu_readline_find_match(key); if (matching < 0) return 0; else rl_point = matching; rl_redisplay(); gnu_readline_timid_delay(gnu_readline_bounce_ms); rl_point = old_point; return 0; }
/* TUI readline command. Temporarily leave the TUI SingleKey mode to allow editing a gdb command with the normal readline. Once the command is executed, the TUI SingleKey mode is installed back. */ static int tui_rl_command_mode (int count, int key) { tui_set_key_mode (TUI_ONE_COMMAND_MODE); return rl_insert (count, key); }
/* Search non-interactively through the history list. DIR < 0 means to search backwards through the history of previous commands; otherwise the search is for commands subsequent to the current position in the history list. PCHAR is the character to use for prompting when reading the search string; if not specified (0), it defaults to `:'. */ static void noninc_search (int dir, int pchar) { int saved_point, c, pmtlen; char *p; maybe_save_line (); saved_point = rl_point; /* Use the line buffer to read the search string. */ rl_line_buffer[0] = 0; rl_end = rl_point = 0; /* XXX - this needs fixing to work with the prompt expansion stuff - XXX */ pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; p = xmalloc (2 + pmtlen); if (pmtlen) strcpy (p, rl_prompt); p[pmtlen] = pchar ? pchar : ':'; p[pmtlen + 1] = '\0'; rl_message (p, 0, 0); free (p); /* Read the search string. */ while ((c = rl_read_key ()) != '\0') { switch (c) { case CTRL('H'): case RUBOUT: if (rl_point == 0) { maybe_unsave_line (); rl_clear_message (); rl_point = saved_point; return; } rl_rubout (1, c); break; case CTRL('W'): rl_unix_word_rubout (1, c); break; case CTRL('U'): rl_unix_line_discard (1, c); break; case RETURN: case NEWLINE: goto dosearch; /* NOTREACHED */ break; case CTRL('C'): case CTRL('G'): maybe_unsave_line (); rl_clear_message (); rl_point = saved_point; DING (); return; default: rl_insert (1, c); break; } rl_redisplay (); } dosearch: /* If rl_point == 0, we want to re-use the previous search string and start from the saved history position. If there's no previous search string, punt. */ if (rl_point == 0) { if (!noninc_search_string) { DING (); return; } } else { /* We want to start the search from the current history position. */ noninc_history_pos = where_history (); if (noninc_search_string) free (noninc_search_string); noninc_search_string = strdup (rl_line_buffer); } noninc_dosearch (noninc_search_string, dir); }
/* * Process one byte of input */ str_t ReadLine (UBYTE newbyte) { strc_t input, inputucs; static UWORD ucsesc; UWORD ucs; ReadLineHandleSig (); s_catc (&rl_input, newbyte); input = ConvFrom (&rl_input, prG->enc_loc); if (input->txt[0] == CHAR_INCOMPLETE) { if (strcmp (rl_input.txt, ConvTo (input->txt, prG->enc_loc)->txt)) return NULL; } rl_inputdone = 0; rl_signal &= ~1; inputucs = ConvTo (input->txt, ENC_UCS2BE); ucs = ((UBYTE)inputucs->txt[1]) | (((UBYTE)inputucs->txt[0]) << 8); s_init (&rl_input, "", 0); s_init (&rl_operate, "", 0); rl_dump_line (); ReadLinePrompt (); switch (rl_stat) { case 0: if (0) ; #if HAVE_TCGETATTR #if defined(VERASE) else if (ucs == tty_attr.c_cc[VERASE] && tty_attr.c_cc[VERASE] != _POSIX_VDISABLE) rl_key_backspace (); #endif #if defined(VEOF) else if (ucs == tty_attr.c_cc[VEOF] && tty_attr.c_cc[VEOF] != _POSIX_VDISABLE) { rl_tab_cancel (); if (rl_ucscol.len) { rl_key_left (); rl_key_delete (); } else { rl_insert ('q'); rl_historyadd (); } } #endif #if defined(VKILL) else if (ucs == tty_attr.c_cc[VKILL] && tty_attr.c_cc[VKILL] != _POSIX_VDISABLE) rl_key_kill (); #endif #if defined(VREPRINT) else if (ucs == tty_attr.c_cc[VREPRINT] && tty_attr.c_cc[VREPRINT] != _POSIX_VDISABLE) ReadLinePromptHide (); #endif #endif else switch (ucs) { case 1: /* ^A */ rl_tab_cancel (); rl_goto (0); break; case 5: /* ^E */ rl_key_end (); break; case 8: /* ^H = \b */ rl_key_backspace (); break; case 9: /* ^I = \t */ rl_key_tab (); break; case 11: /* ^K */ rl_key_cut (); break; case 12: /* ^L */ ReadLineClrScr (); break; case '\r': case '\n': rl_tab_accept (); if (rl_tab_state == 0) rl_checkautoexpand (); rl_key_end (); rl_historyadd (); break; case 23: /* ^W */ rl_key_delete_backward_word (); break; case 25: /* ^Y */ if (rl_yank) { rl_tab_state = 0; rl_goto (0); rl_lineexpand (rl_yank); } break; case 27: /* ^[ = ESC */ #ifdef ANSI_TERM rl_stat = 1; #endif break; case 32: /* = SPACE */ if (rl_tab_state > 0) rl_tab_accept (); else if (rl_tab_state == 0) rl_checkautoexpand (); rl_insert (' '); break; case 127: /* DEL */ if (prG->flags & FLAG_DELBS) rl_key_backspace (); else rl_key_delete (); break; case 0x9b: /* CSI */ #ifdef ANSI_TERM if (ENC(enc_loc) == ENC_LATIN1) { rl_stat = 2; break; } #else printf ("\a"); break; #endif /* fall-through */ default: rl_key_insert (ucs); } break; #ifdef ANSI_TERM case 1: /* state 1: ESC was pressed */ rl_stat = 0; if (ucs == 'u' || ucs == 'U') rl_stat = 10; else if (ucs == '[' || ucs == 'O') rl_stat = 2; else if (ucs == 'b') rl_key_backward_word (); else if (ucs == 'f') rl_key_forward_word (); else if (ucs == 127) rl_key_delete_backward_word (); else printf ("\a"); break; case 2: /* state 2: CSI was typed */ rl_stat = 0; switch (ucs) { case 'A': /* up */ rl_tab_cancel (); rl_historyback (); break; case 'B': /* down */ rl_tab_cancel (); rl_historyforward (); break; case 'C': /* right */ rl_key_right (); break; case 'D': /* left */ rl_key_left (); break; case 'H': /* home */ rl_tab_cancel (); rl_goto (0); break; case 'F': /* end */ rl_key_end (); break; case 'Z': /* shift tab */ rl_key_shifttab (); break; case '3': /* + ~ = delete */ rl_stat = 3; break; case '1': /* + ~ = home */ case '7': /* + ~ = home */ rl_stat = 4; break; case '4': /* + ~ = end */ case '8': /* + ~ = end */ rl_stat = 5; break; default: printf ("\a"); } break; case 3: /* state 3: incomplete delete key */ rl_stat = 0; if (ucs == '~') rl_key_delete (); else printf ("\a"); break; case 4: /* state 4: incomplete home key */ rl_stat = 0; if (ucs == '~') { rl_tab_cancel (); rl_goto (0); } else printf ("\a"); break; case 5: /* state 5: incomplete end key */ rl_stat = 0; if (ucs == '~') rl_key_end (); else printf ("\a"); break; case 10: /* state 10: unicode sequence to be entered */ rl_stat++; if (ucs >= '0' && ucs <= '9') ucsesc = ucs - '0'; else if (ucs >= 'a' && ucs <= 'f') ucsesc = ucs - 'a' + 10; else if (ucs >= 'A' && ucs <= 'F') ucsesc = ucs - 'A' + 10; else { rl_stat = 0; printf ("\a"); } break; case 11: rl_stat++; ucsesc <<= 4; if (ucs >= '0' && ucs <= '9') ucsesc |= ucs - '0'; else if (ucs >= 'a' && ucs <= 'f') ucsesc |= ucs - 'a' + 10; else if (ucs >= 'A' && ucs <= 'F') ucsesc |= ucs - 'A' + 10; else { rl_stat = 0; printf ("\a"); } break; case 12: rl_stat++; ucsesc <<= 4; if (ucs >= '0' && ucs <= '9') ucsesc |= ucs - '0'; else if (ucs >= 'a' && ucs <= 'f') ucsesc |= ucs - 'a' + 10; else if (ucs >= 'A' && ucs <= 'F') ucsesc |= ucs - 'A' + 10; else { rl_stat = 0; printf ("\a"); } break; case 13: rl_stat = 0; ucsesc <<= 4; if (ucs >= '0' && ucs <= '9') ucsesc |= ucs - '0'; else if (ucs >= 'a' && ucs <= 'f') ucsesc |= ucs - 'a' + 10; else if (ucs >= 'A' && ucs <= 'F') ucsesc |= ucs - 'A' + 10; else { printf ("\a"); break; } rl_key_insert (ucsesc); break; } #endif #if DEBUG_RL fprintf (stderr, "oper: %s\n", s_qquote (rl_operate.txt)); #endif rl_dump_line (); if (rl_operate.len) printf ("%s", rl_operate.txt); if (!rl_inputdone) return NULL; printf ("\n"); return &rl_temp; }
/* * Handle tab key - start or continue tabbing */ static void rl_key_tab (void) { str_s str = { NULL, 0, 0 }; strc_t ins; const char *display; int i, off; UWORD columns; if (rl_tab_state == -1) { rl_insert (9); return; } if (!rl_tab_state) { if (!rl_ucs.len) { rl_insert ('m'); rl_insert ('s'); rl_insert ('g'); rl_insert (' '); } for (i = 0; i < rl_ucspos; i++) { if (rl_ucs_at (&rl_ucs, i) == ' ') { rl_tab_index = 0; rl_tab_state = 1; rl_tab_pos = i + 1; rl_linecompress (&rl_temp, rl_tab_pos, rl_ucspos); if ((rl_tab_cont = rl_tab_getnext (&rl_temp))) { ins = ConvTo (COLQUOTE, ENC(enc_loc)); s_init (&rl_colon, "", 0); s_catn (&rl_colon, ins->txt, ins->len); ins = ConvTo (COLNONE, ENC(enc_loc)); s_init (&rl_coloff, "", 0); s_catn (&rl_coloff, ins->txt, ins->len); while (rl_ucspos > rl_tab_pos) rl_left (1), rl_tab_len++; rl_tab_common = rl_tab_len; break; } } } if (!rl_tab_state) { printf ("\a"); return; } } else { rl_linecompress (&rl_temp, rl_tab_pos, rl_ucspos); rl_tab_cont = rl_tab_getnext (&rl_temp); rl_left (rl_tab_common); } for ( ; rl_tab_len; rl_tab_len--) rl_delete (); if (!rl_tab_cont) { printf ("\a"); rl_tab_state = 0; rl_recheck (TRUE); return; } str.txt = rl_tab_alias ? rl_tab_alias->alias : rl_tab_cont->nick; str.len = strlen (str.txt); for (off = 0; off < str.len; ) { wint_tt ucs = ConvGetUTF8 (&str, &off); rl_analyze_ucs (ucs, &display, &columns); rl_insert_basic (ucs, s_sprintf ("%s%s%s", rl_colon.txt, display, rl_coloff.txt), strlen (display) + rl_colon.len + rl_coloff.len, columns & 0xff); rl_tab_len++; } rl_left (rl_tab_len - rl_tab_common); rl_recheck (TRUE); }