static int if_resize() { if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) != -1) { #ifdef NCURSES_VERSION if (screen_size.ws_row != LINES || screen_size.ws_col != COLS) { resizeterm(screen_size.ws_row, screen_size.ws_col); refresh(); rl_resize(screen_size.ws_row, screen_size.ws_col); return if_layout(); } #else /* Stupid way to resize - should work on most systems */ endwin(); LINES = screen_size.ws_row; COLS = screen_size.ws_col; refresh(); source_hscroll(src_win, 0); #endif rl_resize(screen_size.ws_row, screen_size.ws_col); return if_layout(); } return 0; }
/* See interface.h for function descriptions. */ int if_init(void) { if (init_curses()) return 1; hl_groups_instance = hl_groups_initialize(); if (!hl_groups_instance) return 3; if (hl_groups_setup(hl_groups_instance) == -1) return 3; /* Set up the signal handler to catch SIGWINCH */ if (set_up_signal() == -1) return 2; if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) { screen_size.ws_row = LINES; screen_size.ws_col = COLS; } /* Create the file dialog object */ if ((fd = filedlg_new(0, 0, HEIGHT, WIDTH)) == NULL) return 5; /* Set up window layout */ window_height_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); switch (if_layout()) { case 2: return 4; } return 0; }
void reset_window_shift(void) { int h_or_w = cur_split_orientation == SPLIT_HORIZONTAL ? HEIGHT : WIDTH; window_shift = (int) ((h_or_w / 2) * (cur_win_split / 2.0)); if_layout(); }
/* if_resize_term: Checks if a resize event occurred, and updates display if so. * ---------- * * Return Value: Zero on success, non-zero on failure. */ int if_resize_term(void) { if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) != -1) { if (screen_size.ws_row != swin_lines() || screen_size.ws_col != swin_cols()) { swin_resizeterm(screen_size.ws_row, screen_size.ws_col); swin_refresh(); rl_resize(screen_size.ws_row, screen_size.ws_col); return if_layout(); } rl_resize(screen_size.ws_row, screen_size.ws_col); return if_layout(); } return 0; }
/* * increase_win_height: Increase size of source or tty window * ____________________ * * Param jump_or_tty - if 0, increase source window by 1 * if 1, if tty window is visible, increase it by 1 * else jump source window to next biggest quarter * */ static void increase_win_height(int jump_or_tty) { int height = (HEIGHT / 2) - ((tty_win_on) ? TTY_WIN_OFFSET + 1 : 0); int old_window_height_shift = window_height_shift; int old_tty_win_height_shift = tty_win_height_shift; if (jump_or_tty) { /* user input: '+' */ if (tty_win_on) { /* tty window is visible */ height = get_gdb_height() + get_tty_height(); if (tty_win_height_shift + TTY_WIN_DEFAULT_HEIGHT < height - interface_winminheight) { /* increase tty window size by 1 */ tty_win_height_shift++; } } else { /* no tty window */ if (cur_win_split == WIN_SPLIT_FREE) { /* cur position is not on mark, find nearest mark */ cur_win_split = (int) (2 * window_height_shift) / height; /* handle rounding on either side of mid-way mark */ if (window_height_shift > 0) { cur_win_split++; } } else { /* increase to next mark */ cur_win_split++; } /* check split bounds */ if (cur_win_split > WIN_SPLIT_TOP_FULL) { cur_win_split = WIN_SPLIT_TOP_FULL; } /* set window height to specified quarter mark */ window_height_shift = (int) (height * (cur_win_split / 2.0)); } } else { /* user input: '=' */ cur_win_split = WIN_SPLIT_FREE; /* cur split is not on a mark */ window_height_shift++; /* increase src window size by 1 */ } /* reduce flicker by avoiding unnecessary redraws */ if (window_height_shift != old_window_height_shift || tty_win_height_shift != old_tty_win_height_shift) { if_layout(); } }
int if_change_winminwidth(int value) { if (value < 0) return -1; else if (value > WIDTH / 2) return -1; interface_winminwidth = value; if_layout(); return 0; }
int if_change_winminheight(int value) { if (value < 0) return -1; else if (value > HEIGHT / 2) return -1; interface_winminheight = value; if_layout(); return 0; }
/* * decrease_win_height: Decrease size of source or tty window * ____________________ * * Param jump_or_tty - if 0, decrease source window by 1 * if 1, if tty window is visible, decrease it by 1 * else jump source window to next smallest quarter * */ static void decrease_win_height(int jump_or_tty) { int height = HEIGHT / 2; int old_window_height_shift = window_height_shift; int old_tty_win_height_shift = tty_win_height_shift; if (jump_or_tty) { /* user input: '_' */ if (tty_win_on) { /* tty window is visible */ if (tty_win_height_shift > -(TTY_WIN_DEFAULT_HEIGHT - interface_winminheight)) { /* decrease tty window size by 1 */ tty_win_height_shift--; } } else { /* no tty window */ if (cur_win_split == WIN_SPLIT_FREE) { /* cur position is not on mark, find nearest mark */ cur_win_split = (int) (2 * window_height_shift) / height; /* handle rounding on either side of mid-way mark */ if (window_height_shift < 0) { cur_win_split--; } } else { /* decrease to next mark */ cur_win_split--; } /* check split bounds */ if (cur_win_split < WIN_SPLIT_BOTTOM_FULL) { cur_win_split = WIN_SPLIT_BOTTOM_FULL; } /* set window height to specified quarter mark */ window_height_shift = (int) (height * (cur_win_split / 2.0)); } } else { /* user input: '-' */ cur_win_split = WIN_SPLIT_FREE; /* cur split is not on a mark */ window_height_shift--; /* decrease src window size by 1 */ } /* reduce flicker by avoiding unnecessary redraws */ if (window_height_shift != old_window_height_shift || tty_win_height_shift != old_tty_win_height_shift) { if_layout(); } }
/* See interface.h for function descriptions. */ int if_init(void) { if (init_curses()) { clog_error(CLOG_CGDB, "Unable to initialize the ncurses library"); return -1; } hl_groups_instance = hl_groups_initialize(); if (!hl_groups_instance) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } if (hl_groups_setup(hl_groups_instance) == -1) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } /* Set up the signal handler to catch SIGWINCH */ if (set_up_signal() == -1) { clog_error(CLOG_CGDB, "Unable to handle signal: SIGWINCH"); return -1; } if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) { screen_size.ws_row = swin_lines(); screen_size.ws_col = swin_cols(); } /* Create the file dialog object */ fd = filedlg_new(0, 0, HEIGHT, WIDTH); /* Set up window layout */ window_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); switch (if_layout()) { case 2: return 4; } G_line_number = ibuf_init(); return 0; }
/* * decrease_win_height: Decrease size of the source window * ____________________ * * Param jump - if 0, decrease source window by 1 * if 1, jump source window to next smallest quarter * */ static void decrease_win_height(int jump) { int height = HEIGHT / 2; int old_window_shift = window_shift; if (jump) { /* user input: '_' */ if (cur_win_split == WIN_SPLIT_FREE) { /* cur position is not on mark, find nearest mark */ cur_win_split = (WIN_SPLIT_TYPE) ((2 * window_shift) / height); /* handle rounding on either side of mid-way mark */ if (window_shift < 0) { cur_win_split = (WIN_SPLIT_TYPE)(cur_win_split - 1); } } else { /* decrease to next mark */ cur_win_split = (WIN_SPLIT_TYPE)(cur_win_split - 1); } /* check split bounds */ if (cur_win_split < WIN_SPLIT_GDB_FULL) { cur_win_split = WIN_SPLIT_GDB_FULL; } /* set window height to specified quarter mark */ window_shift = (int) (height * (cur_win_split / 2.0)); } else { /* user input: '-' */ cur_win_split = WIN_SPLIT_FREE; /* cur split is not on a mark */ window_shift--; /* decrease src window size by 1 */ } /* reduce flicker by avoiding unnecessary redraws */ if (window_shift != old_window_shift) { if_layout(); } }
void if_set_winsplit(WIN_SPLIT_TYPE new_split) { cur_win_split = new_split; window_height_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); if_layout(); }
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; }
/** * Send input to the CGDB source window. * * @param key * The key to send to the CGDB source window. * * @param last_key * An output parameter. When set, that will tell cgdb to use the set value, * instead of the current key, as the "last_key_pressed" in the next * call to cgdb_input. This is useful to set mainly when the current input * has consumed more than one character, and the "last_key_pressed" should * be not set on the next call to cgdb_input. * * @return * Currently only returns 0. */ static int cgdb_input(int key, int *last_key) { int regex_icase = cgdbrc_get_int(CGDBRC_IGNORECASE); if (src_viewer && src_viewer->cur) { int ret = 0; /* Handle setting (mX) and going ('X) to source buffer marks */ if (last_key_pressed == 'm') ret = source_set_mark(src_viewer, key); else if (last_key_pressed == '\'') ret = source_goto_mark(src_viewer, key); if (ret) { /* When m[a-zA-Z] matches, don't let the marker char * be treated as the last key. That would allow the * chars mgg, to set the marker g, and then move to the top * of the file via gg. * CGDB should see those as mg (set a local mark g), and then * an individual g. */ *last_key = 0; if_draw(); return 0; } } switch (key) { case 's': gdb_scroller->in_scroll_mode = 1; if_set_focus(GDB); return 0; case 'i': if_set_focus(GDB); 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_viewer->cur) { regex_cur = ibuf_init(); regex_direction_cur = ('/' == key); orig_line_regex = src_viewer->cur->sel_line; sbc_kind = SBC_REGEX; if_set_focus(CGDB_STATUS_BAR); /* Capturing regular expressions */ source_search_regex_init(src_viewer); /* Initialize the function for finding a regex and tell user */ if_draw(); } return 0; case 'n': source_search_regex(src_viewer, ibuf_get(regex_last), 2, regex_direction_last, regex_icase); if_draw(); break; case 'N': source_search_regex(src_viewer, ibuf_get(regex_last), 2, !regex_direction_last, regex_icase); if_draw(); break; case CGDB_KEY_CTRL_T: if (tgdb_tty_new(tgdb) == -1) { /* Error */ } else { if_layout(); } break; case CGDB_KEY_CTRL_W: switch (cur_split_orientation) { case WSO_HORIZONTAL: cur_split_orientation = WSO_VERTICAL; break; case WSO_VERTICAL: cur_split_orientation = WSO_HORIZONTAL; break; } if_layout(); break; case CGDB_KEY_F1: if_display_help(); return 0; case CGDB_KEY_F5: /* Issue GDB run command */ tgdb_request_run_debugger_command(tgdb, TGDB_RUN); return 0; case CGDB_KEY_F6: /* Issue GDB continue command */ tgdb_request_run_debugger_command(tgdb, TGDB_CONTINUE); return 0; case CGDB_KEY_F7: /* Issue GDB finish command */ tgdb_request_run_debugger_command(tgdb, TGDB_FINISH); return 0; case CGDB_KEY_F8: /* Issue GDB next command */ tgdb_request_run_debugger_command(tgdb, TGDB_NEXT); case CGDB_KEY_F10: /* Issue GDB step command */ tgdb_request_run_debugger_command(tgdb, TGDB_STEP); return 0; case CGDB_KEY_CTRL_L: if_layout(); return 0; } source_input(src_viewer, key); return 0; }