static int test_delchar(ibuf s) { /* Delete the last '!' from the string. */ ibuf_delchar(s); /* Make sure it was deleted correctly. */ if (strcmp(ibuf_get(s), "hello world") != 0) { debug("test_delchar: Mismatch, expected \"hello world\", got: %s\n", ibuf_get(s)); return 1; } /* Wipe the string via delchar, testing ibuf_length simultaneously */ while (ibuf_length(s) > 0) { ibuf_delchar(s); } /* Make sure s is now an empty string. */ if (strcmp(ibuf_get(s), "") != 0) { debug("test_delchar: Expected empty string, got: %s\n", ibuf_get(s)); return 2; } debug("test_delchar: Succeeded.\n"); return 0; }
/** * Capture a regular expression from the user, one key at a time. * This modifies the global variables regex_cur and regex_last. * * \param sview * The source viewer. * * \return * 0 if user gave a regex, otherwise 1. */ static int status_bar_regex_input(struct sviewer *sview, int key) { int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val; /* Flag to indicate we're done with regex mode, need to switch back */ int done = 0; /* Recieve a regex from the user. */ switch (key) { case '\r': case '\n': case CGDB_KEY_CTRL_M: /* Save for future searches via 'n' or 'N' */ if (regex_last != NULL) { ibuf_free(regex_last); } regex_last = ibuf_dup(regex_cur); regex_direction_last = regex_direction_cur; source_search_regex(sview, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); done = 1; break; case 8: case 127: /* Backspace or DEL key */ if (ibuf_length(regex_cur) == 0) { done = 1; } else { ibuf_delchar(regex_cur); source_search_regex(sview, ibuf_get(regex_cur), 1, regex_direction_cur, regex_icase); if_draw(); update_status_win(); } break; default: if (kui_term_is_cgdb_key(key)) { const char *keycode = kui_term_get_keycode_from_cgdb_key(key); int length = strlen(keycode), i; for (i = 0; i < length; i++) ibuf_addchar(regex_cur, keycode[i]); } else { ibuf_addchar(regex_cur, key); } source_search_regex(sview, ibuf_get(regex_cur), 1, regex_direction_cur, regex_icase); if_draw(); update_status_win(); }; if (done) { ibuf_free(regex_cur); regex_cur = NULL; if_set_focus(CGDB); } return 0; }
static int status_bar_normal_input(int key) { /* Flag to indicate we're done with status mode, need to switch back */ int done = 0; /* The goal of this state is to recieve a command from the user. */ switch (key) { case '\r': case '\n': case CGDB_KEY_CTRL_M: /* Found a command */ if_run_command(src_win, cur_sbc); done = 1; break; case 8: case 127: /* Backspace or DEL key */ if (ibuf_length(cur_sbc) == 0) { done = 1; } else { ibuf_delchar(cur_sbc); update_status_win(); } break; default: if (kui_term_is_cgdb_key(key)) { const char *keycode = kui_term_get_keycode_from_cgdb_key(key); int length = strlen(keycode), i; for (i = 0; i < length; i++) ibuf_addchar(cur_sbc, keycode[i]); } else { ibuf_addchar(cur_sbc, key); } update_status_win(); break; }; if (done) { ibuf_free(cur_sbc); cur_sbc = NULL; if_set_focus(CGDB); } return 0; }
/* Please forgive me for adding all the comment below. This function * has some strange bahaviors that I thought should be well explained. */ void rlctx_send_user_command(char *line) { char *cline; int length; char *rline_prompt; tgdb_request_ptr request_ptr; if (line == NULL) { /* NULL line means rl_callback_read_char received EOF */ ibuf_add(current_line, "quit"); } else { /* Add the line passed in to the current line */ ibuf_add(current_line, line); } /* Get current line, and current line length */ cline = ibuf_get(current_line); length = ibuf_length(current_line); /* Check to see if the user is escaping the line, to use a * multi line command. If so, return so that the user can * continue the command. This data should not go into the history * buffer, or be sent to gdb yet. * * Also, notice the length > 0 condition. (length == 0) can happen * when the user simply hits Enter on the keyboard. */ if (length > 0 && cline[length - 1] == '\\') { /* The \ char is for continuation only, it is not meant to be sent * to GDB as a character. */ ibuf_delchar(current_line); /* Only need to change the prompt the first time the \ char is used. * Doing it a second time would erase the real rline_last_prompt, * since the prompt has already been set to "". */ if (!rline_last_prompt) { rline_get_prompt(rline, &rline_prompt); rline_last_prompt = strdup(rline_prompt); /* GDB set's the prompt to nothing when doing continuation. * This is here just for compatibility. */ rline_set_prompt(rline, ""); } return; } /* If here, a full command has been sent. Restore the prompt. */ if (rline_last_prompt) { rline_set_prompt(rline, rline_last_prompt); free(rline_last_prompt); rline_last_prompt = NULL; } /* Don't add the enter command to the history */ if (length > 0) rline_add_history(rline, cline); request_ptr = tgdb_request_run_console_command(tgdb, cline); if (!request_ptr) logger_write_pos(logger, __FILE__, __LINE__, "rlctx_send_user_command\n"); /* Send this command to TGDB */ handle_request(tgdb, request_ptr); ibuf_clear(current_line); }
/** * Capture a regular expression from the user, one key at a time. * This modifies the global variables regex_cur and regex_last. * * \param sview * The source viewer. * * \return * 0 if user gave a regex, otherwise 1. */ static int gdb_input_regex_input(struct scroller *scr, int key) { int regex_icase = cgdbrc_get_int(CGDBRC_IGNORECASE); /* Flag to indicate we're done with regex mode, need to switch back */ int done = 0; /* Receive a regex from the user. */ switch (key) { case '\r': case '\n': case CGDB_KEY_CTRL_M: /* Save for future searches via 'n' or 'N' */ ibuf_free(regex_last); regex_last = ibuf_dup(regex_cur); regex_direction_last = regex_direction_cur; scr_search_regex(scr, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); done = 1; break; case 8: case 127: /* Backspace or DEL key */ if (ibuf_length(regex_cur) == 0) { done = 1; scr_search_regex(scr, "", 2, regex_direction_cur, regex_icase); } else { ibuf_delchar(regex_cur); scr_search_regex(scr, ibuf_get(regex_cur), 1, regex_direction_cur, regex_icase); if_draw(); update_status_win(WIN_REFRESH); } break; default: if (kui_term_is_cgdb_key(key)) { const char *keycode = kui_term_get_keycode_from_cgdb_key(key); int length = strlen(keycode), i; for (i = 0; i < length; i++) ibuf_addchar(regex_cur, keycode[i]); } else { ibuf_addchar(regex_cur, key); } scr_search_regex(scr, ibuf_get(regex_cur), 1, regex_direction_cur, regex_icase); if_draw(); update_status_win(WIN_REFRESH); }; if (done) { gdb_scroller->in_search_mode = 0; ibuf_free(regex_cur); regex_cur = NULL; sbc_kind = SBC_NORMAL; if_set_focus(GDB); } return 0; }