int cgdbrc_get_mapped_key_timeoutlen(void) { cgdbrc_config_option_ptr timeout_option_ptr = cgdbrc_get(CGDBRC_TIMEOUT); /* Do not time out. */ if (timeout_option_ptr->variant.int_val == 0) return 0; return cgdbrc_get(CGDBRC_TIMEOUT_LEN)->variant.int_val; }
int cgdbrc_get_key_code_timeoutlen(void) { cgdbrc_config_option_ptr timeout_option_ptr = cgdbrc_get(CGDBRC_TIMEOUT); cgdbrc_config_option_ptr ttimeout_option_ptr = cgdbrc_get(CGDBRC_TTIMEOUT); /* Do not time out. */ if (timeout_option_ptr->variant.int_val == 0 && ttimeout_option_ptr->variant.int_val == 0) return 0; if (cgdbrc_get(CGDBRC_TTIMEOUT_LEN)->variant.int_val < 0) return cgdbrc_get(CGDBRC_TIMEOUT_LEN)->variant.int_val; else return cgdbrc_get(CGDBRC_TTIMEOUT_LEN)->variant.int_val; }
/** * 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; }
int internal_if_input(int key) { int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val; /* Normally, CGDB_KEY_ESC, but can be configured by the user */ int cgdb_mode_key = cgdbrc_get(CGDBRC_CGDB_MODE_KEY)->variant.int_val; /* The cgdb mode key, puts the debugger into command mode */ if (focus != CGDB && key == cgdb_mode_key) { /* Depending on which cgdb was in, it can free some memory here that * it was previously using. */ if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) { ibuf_free(cur_sbc); cur_sbc = NULL; } else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX) { ibuf_free(regex_cur); regex_cur = NULL; free(src_win->cur->buf.cur_line); src_win->cur->buf.cur_line = NULL; src_win->cur->sel_rline = orig_line_regex; src_win->cur->sel_line = orig_line_regex; } if_set_focus(CGDB); return 0; } /* If you are already in cgdb mode, the cgdb mode key does nothing */ else if (key == cgdb_mode_key) return 0; /* Check for global keystrokes */ switch (focus) { case CGDB: switch (key) { case 'i': if_set_focus(GDB); return 0; case 'I': if_set_focus(TTY); return 0; case ':': /* Set the type of the command the user is typing in the status bar */ sbc_kind = SBC_NORMAL; if_set_focus(CGDB_STATUS_BAR); /* Since the user is about to type in a command, allocate a buffer * in which this command can be stored. */ cur_sbc = ibuf_init(); return 0; case '/': case '?': if (src_win->cur != NULL) { regex_cur = ibuf_init(); regex_direction_cur = ('/' == key); orig_line_regex = src_win->cur->sel_line; sbc_kind = SBC_REGEX; if_set_focus(CGDB_STATUS_BAR); /* Capturing regular expressions */ source_search_regex_init(src_win); /* Initialize the function for finding a regex and tell user */ if_draw(); } return 0; case 'n': source_search_regex(src_win, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); break; case 'N': source_search_regex(src_win, ibuf_get(regex_last), 2, !regex_direction_last, regex_icase); if_draw(); break; case 'T': if (tty_win_on) { tty_win_on = 0; focus = CGDB; } else { tty_win_on = 1; focus = TTY; } if_layout(); break; case CGDB_KEY_CTRL_T: if (tgdb_tty_new(tgdb) == -1) { /* Error */ } else { scr_free(tty_win); tty_win = NULL; if_layout(); } break; case CGDB_KEY_F1: if_display_help(); return 0; case CGDB_KEY_F5: /* Issue GDB run command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_RUN); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F6: /* Issue GDB continue command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_CONTINUE); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F7: /* Issue GDB finish command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_FINISH); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F8: /* Issue GDB next command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_NEXT); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_F10: /* Issue GDB step command */ { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_run_debugger_command(tgdb, TGDB_STEP); handle_request(tgdb, request_ptr); } return 0; case CGDB_KEY_CTRL_L: if_layout(); return 0; } source_input(src_win, key); return 0; break; case TTY: return tty_input(key); case GDB: return gdb_input(key); case FILE_DLG: { static char filedlg_file[MAX_LINE]; int ret = filedlg_recv_char(fd, key, filedlg_file); /* The user cancelled */ if (ret == -1) { if_set_focus(CGDB); return 0; /* Needs more data */ } else if (ret == 0) { return 0; /* The user picked a file */ } else if (ret == 1) { tgdb_request_ptr request_ptr; request_ptr = tgdb_request_filename_pair(tgdb, filedlg_file); handle_request(tgdb, request_ptr); if_set_focus(CGDB); return 0; } } return 0; case CGDB_STATUS_BAR: return status_bar_input(src_win, key); } /* Never gets here */ return 0; }
enum LineDisplayStyle cgdbrc_get_displaystyle(enum cgdbrc_option_kind option) { return cgdbrc_get(option)->variant.line_display_style; }
int cgdbrc_get_int(enum cgdbrc_option_kind option) { return cgdbrc_get(option)->variant.int_val; }
int hl_regex(const char *regex, const char **hl_lines, const char **tlines, const int length, char **cur_line, int *sel_line, int *sel_rline, int *sel_col_rbeg, int *sel_col_rend, int opt, int direction, int icase) { regex_t t; /* Regular expression */ regmatch_t pmatch[1]; /* Indexes of matches */ int i = 0, result = 0; char *local_cur_line; int success = 0; int offset = 0; int config_wrapscan = cgdbrc_get (CGDBRC_WRAPSCAN)->variant.int_val; if (tlines == NULL || tlines[0] == NULL || cur_line == NULL || sel_line == NULL || sel_rline == NULL || sel_col_rbeg == NULL || sel_col_rend == NULL ) return -1; /* Clear last highlighted line */ if ( *cur_line != NULL ) { free ( *cur_line); *cur_line=NULL; } /* If regex is empty, set current line to original line */ if ( regex == NULL || *regex == '\0' ) { *sel_line = *sel_rline; return -2; } /* Compile the regular expression */ if ( regcomp(&t, regex, REG_EXTENDED & (icase)?REG_ICASE:0) != 0) { regfree(&t); return -3; } /* Forward search */ if ( direction ) { int start = *sel_rline; int end = length; offset = *sel_col_rend; while(!success) { for ( i = start; i < end; i++) { int local_cur_line_length; local_cur_line = (char *)tlines[i]; local_cur_line_length = strlen ( local_cur_line ); /* Add the position of the current line's last match */ if ( i == *sel_rline ) { if ( offset >= local_cur_line_length ) continue; local_cur_line += offset; } /* Found a match */ if ( ( result = regexec(&t, local_cur_line, 1, pmatch, 0)) == 0 ) { success = 1; break; } } if (success || start == 0 || !config_wrapscan) { break; } else { end = start; start = 0; } } } else { /* Reverse search */ int j, pos; int start = *sel_rline; int end = 0; offset = *sel_col_rbeg; /* Try each line */ while(!success) { for ( i = start; i >= end; i--) { local_cur_line = (char *)tlines[i]; pos = strlen(local_cur_line) - 1; if ( pos < 0 ) continue; if ( i == *sel_rline ) pos = offset - 1; /* Try each line, char by char starting from the end */ for ( j = pos; j >= 0; j-- ) { if ( ( result = regexec(&t, local_cur_line + j, 1, pmatch, 0)) == 0 ) { if ( i == *sel_rline && pmatch[0].rm_so > pos - j) continue; /* Found a match */ success = 1; offset = j; break; } } if ( success ) break; } if (success || start == length - 1 || !config_wrapscan) { break; } else { end = start; start = length - 1; } } } if ( success ) { /* The offset is 0 if the line was not on the original line */ if ( direction && *sel_rline != i ) offset = 0; /* If final match ( user hit enter ) make position perminant */ if ( opt == 2 ) { *sel_col_rbeg = pmatch[0].rm_so + offset; *sel_col_rend = pmatch[0].rm_eo + offset; *sel_rline = i; } /* Keep the new line as the selected line */ *sel_line = i; /* If the match is not perminant then give cur_line highlighting */ if ( opt != 2 && pmatch[0].rm_so != -1 && pmatch[0].rm_eo != -1 ) *cur_line = highlight_line_segment( hl_lines[i], pmatch[0].rm_so + offset, pmatch[0].rm_eo + offset); } else { /* On failure, the current line goes to the original line */ *sel_line = *sel_rline; } regfree(&t); return success; }
void hl_wprintw(WINDOW *win, const char *line, int width, int offset) { int length; /* Length of the line passed in */ enum hl_group_kind color; /* Color used to print current char */ int i; /* Loops through the line char by char */ int j; /* General iterator */ int p; /* Count of chars printed to screen */ int pad; /* Used to pad partial tabs */ int attr; /* A temp variable used for attributes */ int highlight_tabstop = cgdbrc_get (CGDBRC_TABSTOP)->variant.int_val; /* Jump ahead to the character at offset (process color commands too) */ length = strlen(line); color = HLG_TEXT; for (i = 0, j = 0; i < length && j < offset; i++) { if (line[i] == HL_CHAR && i+1 < length) { /* Even though we're not printing anything in this loop, * the color attribute needs to be maintained for when we * start printing in the loop below. This way the text * printed will be done in the correct color. */ color = (int)line[++i]; } else if (line[i] == '\t') { /* Tab character, expand to size set by user */ j += highlight_tabstop - (j % highlight_tabstop); } else { /* Normal character, just increment counter by one */ j++; } } pad = j - offset; /* Pad tab spaces if offset is less than the size of a tab */ for (j = 0, p = 0; j < pad && p < width; j++, p++) wprintw(win, " "); /* Set the color appropriately */ if (hl_groups_get_attr (hl_groups_instance, color, &attr) == -1) { logger_write_pos ( logger, __FILE__, __LINE__, "hl_groups_get_attr error"); return; } wattron(win, attr); /* Print string 1 char at a time */ for (; i < length && p < width; i++) { if (line[i] == HL_CHAR) { if (++i < length) { wattroff(win, attr); color = (int)line[i]; if (hl_groups_get_attr (hl_groups_instance, color, &attr) == -1) { logger_write_pos ( logger, __FILE__, __LINE__, "hl_groups_get_attr error"); return; } wattron(win, attr); } } else { switch (line[i]) { case '\t': do { wprintw(win, " "); p++; } while ((p+offset) % highlight_tabstop > 0 && p < width); break; default: wprintw(win, "%c", line[i]); p++; } } } /* Shut off color attribute */ wattroff(win, attr); for (; p < width; p++) wprintw(win, " "); }