⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tui-io.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
static intprint_filename (char *to_print, char *full_pathname){  int printed_len = 0;  char *s;  for (s = to_print; *s; s++)    {      PUTX (*s);    }  return printed_len;}/* The user must press "y" or "n".  Non-zero return means "y" pressed.   Comes from readline/complete.c  */static intget_y_or_n (void){  extern int _rl_abort_internal ();  int c;  for (;;)    {      c = rl_read_key ();      if (c == 'y' || c == 'Y' || c == ' ')	return (1);      if (c == 'n' || c == 'N' || c == RUBOUT)	return (0);      if (c == ABORT_CHAR)	_rl_abort_internal ();      beep ();    }}/* A convenience function for displaying a list of strings in   columnar format on readline's output stream.  MATCHES is the list   of strings, in argv format, LEN is the number of strings in MATCHES,   and MAX is the length of the longest string in MATCHES.   Comes from readline/complete.c and modified to write in   the TUI command window using tui_putc/tui_puts.  */static voidtui_rl_display_match_list (char **matches, int len, int max){  typedef int QSFUNC (const void *, const void *);  extern int _rl_qsort_string_compare (const void*, const void*);  extern int _rl_print_completions_horizontally;    int count, limit, printed_len;  int i, j, k, l;  char *temp;  /* Screen dimension correspond to the TUI command window.  */  int screenwidth = TUI_CMD_WIN->generic.width;  /* If there are many items, then ask the user if she really wants to     see them all. */  if (len >= rl_completion_query_items)    {      char msg[256];      sprintf (msg, "\nDisplay all %d possibilities? (y or n)", len);      tui_puts (msg);      if (get_y_or_n () == 0)	{	  tui_puts ("\n");	  return;	}    }  /* How many items of MAX length can we fit in the screen window? */  max += 2;  limit = screenwidth / max;  if (limit != 1 && (limit * max == screenwidth))    limit--;  /* Avoid a possible floating exception.  If max > screenwidth,     limit will be 0 and a divide-by-zero fault will result. */  if (limit == 0)    limit = 1;  /* How many iterations of the printing loop? */  count = (len + (limit - 1)) / limit;  /* Watch out for special case.  If LEN is less than LIMIT, then     just do the inner printing loop.	   0 < len <= limit  implies  count = 1. */  /* Sort the items if they are not already sorted. */  if (rl_ignore_completion_duplicates == 0)    qsort (matches + 1, len, sizeof (char *),           (QSFUNC *)_rl_qsort_string_compare);  tui_putc ('\n');  if (_rl_print_completions_horizontally == 0)    {      /* Print the sorted items, up-and-down alphabetically, like ls. */      for (i = 1; i <= count; i++)	{	  for (j = 0, l = i; j < limit; j++)	    {	      if (l > len || matches[l] == 0)		break;	      else		{		  temp = printable_part (matches[l]);		  printed_len = print_filename (temp, matches[l]);		  if (j + 1 < limit)		    for (k = 0; k < max - printed_len; k++)		      tui_putc (' ');		}	      l += count;	    }	  tui_putc ('\n');	}    }  else    {      /* Print the sorted items, across alphabetically, like ls -x. */      for (i = 1; matches[i]; i++)	{	  temp = printable_part (matches[i]);	  printed_len = print_filename (temp, matches[i]);	  /* Have we reached the end of this line? */	  if (matches[i+1])	    {	      if (i && (limit > 1) && (i % limit) == 0)		tui_putc ('\n');	      else		for (k = 0; k < max - printed_len; k++)		  tui_putc (' ');	    }	}      tui_putc ('\n');    }}/* Setup the IO for curses or non-curses mode.   - In non-curses mode, readline and gdb use the standard input and   standard output/error directly.   - In curses mode, the standard output/error is controlled by TUI   with the tui_stdout and tui_stderr.  The output is redirected in   the curses command window.  Several readline callbacks are installed   so that readline asks for its input to the curses command window   with wgetch().  */voidtui_setup_io (int mode){  extern int readline_echoing_p;   if (mode)    {      /* Redirect readline to TUI.  */      tui_old_rl_redisplay_function = rl_redisplay_function;      tui_old_rl_deprep_terminal = rl_deprep_term_function;      tui_old_rl_prep_terminal = rl_prep_term_function;      tui_old_rl_getc_function = rl_getc_function;      tui_old_rl_outstream = rl_outstream;      tui_old_readline_echoing_p = readline_echoing_p;      rl_redisplay_function = tui_redisplay_readline;      rl_deprep_term_function = tui_deprep_terminal;      rl_prep_term_function = tui_prep_terminal;      rl_getc_function = tui_getc;      readline_echoing_p = 0;      rl_outstream = tui_rl_outstream;      rl_prompt = 0;      rl_completion_display_matches_hook = tui_rl_display_match_list;      rl_already_prompted = 0;      /* Keep track of previous gdb output.  */      tui_old_stdout = gdb_stdout;      tui_old_stderr = gdb_stderr;      tui_old_uiout = uiout;      /* Reconfigure gdb output.  */      gdb_stdout = tui_stdout;      gdb_stderr = tui_stderr;      gdb_stdlog = gdb_stdout;	/* for moment */      gdb_stdtarg = gdb_stderr;	/* for moment */      uiout = tui_out;      /* Save tty for SIGCONT.  */      savetty ();    }  else    {      /* Restore gdb output.  */      gdb_stdout = tui_old_stdout;      gdb_stderr = tui_old_stderr;      gdb_stdlog = gdb_stdout;	/* for moment */      gdb_stdtarg = gdb_stderr;	/* for moment */      uiout = tui_old_uiout;      /* Restore readline.  */      rl_redisplay_function = tui_old_rl_redisplay_function;      rl_deprep_term_function = tui_old_rl_deprep_terminal;      rl_prep_term_function = tui_old_rl_prep_terminal;      rl_getc_function = tui_old_rl_getc_function;      rl_outstream = tui_old_rl_outstream;      rl_completion_display_matches_hook = 0;      readline_echoing_p = tui_old_readline_echoing_p;      rl_already_prompted = 0;      /* Save tty for SIGCONT.  */      savetty ();    }}#ifdef SIGCONT/* Catch SIGCONT to restore the terminal and refresh the screen.  */static voidtui_cont_sig (int sig){  if (tui_active)    {      /* Restore the terminal setting because another process (shell)         might have changed it.  */      resetty ();      /* Force a refresh of the screen.  */      tui_refresh_all_win ();      /* Update cursor position on the screen.  */      wmove (TUI_CMD_WIN->generic.handle,             TUI_CMD_WIN->detail.command_info.start_line,             TUI_CMD_WIN->detail.command_info.curch);      wrefresh (TUI_CMD_WIN->generic.handle);    }  signal (sig, tui_cont_sig);}#endif/* Initialize the IO for gdb in curses mode.  */voidtui_initialize_io (void){#ifdef SIGCONT  signal (SIGCONT, tui_cont_sig);#endif  /* Create tui output streams.  */  tui_stdout = tui_fileopen (stdout);  tui_stderr = tui_fileopen (stderr);  tui_out = tui_out_new (tui_stdout);  /* Create the default UI.  It is not created because we installed a     deprecated_init_ui_hook.  */  tui_old_uiout = uiout = cli_out_new (gdb_stdout);#ifdef TUI_USE_PIPE_FOR_READLINE  /* Temporary solution for readline writing to stdout:     redirect readline output in a pipe, read that pipe and     output the content in the curses command window.  */  if (pipe (tui_readline_pipe) != 0)    {      fprintf_unfiltered (gdb_stderr, "Cannot create pipe for readline");      exit (1);    }  tui_rl_outstream = fdopen (tui_readline_pipe[1], "w");  if (tui_rl_outstream == 0)    {      fprintf_unfiltered (gdb_stderr, "Cannot redirect readline output");      exit (1);    }  setvbuf (tui_rl_outstream, (char*) NULL, _IOLBF, 0);#ifdef O_NONBLOCK  (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NONBLOCK);#else#ifdef O_NDELAY  (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NDELAY);#endif#endif  add_file_handler (tui_readline_pipe[0], tui_readline_output, 0);#else  tui_rl_outstream = stdout;#endif}/* Get a character from the command window.  This is called from the readline   package.  */inttui_getc (FILE *fp){  int ch;  WINDOW *w;  w = TUI_CMD_WIN->generic.handle;#ifdef TUI_USE_PIPE_FOR_READLINE  /* Flush readline output.  */  tui_readline_output (GDB_READABLE, 0);#endif  ch = wgetch (w);  ch = tui_handle_resize_during_io (ch);  /* The \n must be echoed because it will not be printed by readline.  */  if (ch == '\n')    {      /* When hitting return with an empty input, gdb executes the last         command.  If we emit a newline, this fills up the command window         with empty lines with gdb prompt at beginning.  Instead of that,         stay on the same line but provide a visual effect to show the         user we recognized the command.  */      if (rl_end == 0)        {          wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0);          /* Clear the line.  This will blink the gdb prompt since             it will be redrawn at the same line.  */          wclrtoeol (w);          wrefresh (w);          napms (20);        }      else        {          wmove (w, TUI_CMD_WIN->detail.command_info.cur_line,                 TUI_CMD_WIN->detail.command_info.curch);          waddch (w, ch);        }    }    if (key_is_command_char (ch))    {				/* Handle prev/next/up/down here */      ch = tui_dispatch_ctrl_char (ch);    }    if (ch == '\n' || ch == '\r' || ch == '\f')    TUI_CMD_WIN->detail.command_info.curch = 0;  if (ch == KEY_BACKSPACE)    return '\b';    return ch;}/* Cleanup when a resize has occured.   Returns the character that must be processed.  */static unsigned inttui_handle_resize_during_io (unsigned int original_ch){  if (tui_win_resized ())    {      tui_refresh_all_win ();      dont_repeat ();      tui_set_win_resized_to (FALSE);      return '\n';    }  else    return original_ch;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -