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

📄 tui-win.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    }  else    printf_filtered (WIN_HEIGHT_USAGE);}/* Set the height of the specified window, with va_list.    */static voidtui_set_win_height_command (char *arg, int from_tty){  /* Make sure the curses mode is enabled.  */  tui_enable ();  tui_set_win_height (arg, from_tty);}/* XDB Compatibility command for setting the window height.  This will   increase or decrease the command window by the specified amount.  */static voidtui_xdb_set_win_height (char *arg, int from_tty){  /* Make sure the curses mode is enabled.  */  tui_enable ();  if (arg != (char *) NULL)    {      int input_no = atoi (arg);      if (input_no > 0)	{			/* Add 1 for the locator */	  int new_height = tui_term_height () - (input_no + 1);	  if (!new_height_ok (tui_win_list[CMD_WIN], new_height) ||	      tui_adjust_win_heights (tui_win_list[CMD_WIN],				    new_height) == TUI_FAILURE)	    warning ("Invalid window height specified.\n%s",		     XDBWIN_HEIGHT_USAGE);	}      else	warning ("Invalid window height specified.\n%s",		 XDBWIN_HEIGHT_USAGE);    }  else    warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE);}/* Set the height of the specified window, with va_list.  */static voidtui_xdb_set_win_height_command (char *arg, int from_tty){  tui_xdb_set_win_height (arg, from_tty);}/* Function to adjust all window heights around the primary.   */static enum tui_statustui_adjust_win_heights (struct tui_win_info * primary_win_info, int new_height){  enum tui_status status = TUI_FAILURE;  if (new_height_ok (primary_win_info, new_height))    {      status = TUI_SUCCESS;      if (new_height != primary_win_info->generic.height)	{	  int diff;	  struct tui_win_info * win_info;	  struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();	  enum tui_layout_type cur_layout = tui_current_layout ();	  diff = (new_height - primary_win_info->generic.height) * (-1);	  if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)	    {	      struct tui_win_info * src_win_info;	      make_invisible_and_set_new_height (primary_win_info, new_height);	      if (primary_win_info->generic.type == CMD_WIN)		{		  win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];		  src_win_info = win_info;		}	      else		{		  win_info = tui_win_list[CMD_WIN];		  src_win_info = primary_win_info;		}	      make_invisible_and_set_new_height (win_info,					     win_info->generic.height + diff);	      TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;	      make_visible_with_new_height (win_info);	      make_visible_with_new_height (primary_win_info);	      if (src_win_info->generic.content_size <= 0)		tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);	    }	  else	    {	      struct tui_win_info *first_win;	      struct tui_win_info *second_win;	      if (cur_layout == SRC_DISASSEM_COMMAND)		{		  first_win = TUI_SRC_WIN;		  second_win = TUI_DISASM_WIN;		}	      else		{		  first_win = TUI_DATA_WIN;		  second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];		}	      if (primary_win_info == TUI_CMD_WIN)		{		/*				   ** Split the change in height accross the 1st & 2nd windows				   ** adjusting them as well.				 */		  int first_split_diff = diff / 2;	/* subtract the locator */		  int second_split_diff = first_split_diff;		  if (diff % 2)		    {		      if (first_win->generic.height >			  second_win->generic.height)			if (diff < 0)			  first_split_diff--;			else			  first_split_diff++;		      else			{			  if (diff < 0)			    second_split_diff--;			  else			    second_split_diff++;			}		    }		  /* make sure that the minimum hieghts are honored */		  while ((first_win->generic.height + first_split_diff) < 3)		    {		      first_split_diff++;		      second_split_diff--;		    }		  while ((second_win->generic.height + second_split_diff) < 3)		    {		      second_split_diff++;		      first_split_diff--;		    }		  make_invisible_and_set_new_height (						  first_win,				 first_win->generic.height + first_split_diff);		  second_win->generic.origin.y = first_win->generic.height - 1;		  make_invisible_and_set_new_height (		    second_win, second_win->generic.height + second_split_diff);		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;		  make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);		}	      else		{		  if ((TUI_CMD_WIN->generic.height + diff) < 1)		    {		/*				   ** If there is no way to increase the command window				   ** take real estate from the 1st or 2nd window.				 */		      if ((TUI_CMD_WIN->generic.height + diff) < 1)			{			  int i;			  for (i = TUI_CMD_WIN->generic.height + diff;			       (i < 1); i++)			    if (primary_win_info == first_win)			      second_win->generic.height--;			    else			      first_win->generic.height--;			}		    }		  if (primary_win_info == first_win)		    make_invisible_and_set_new_height (first_win, new_height);		  else		    make_invisible_and_set_new_height (						    first_win,						  first_win->generic.height);		  second_win->generic.origin.y = first_win->generic.height - 1;		  if (primary_win_info == second_win)		    make_invisible_and_set_new_height (second_win, new_height);		  else		    make_invisible_and_set_new_height (				      second_win, second_win->generic.height);		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;		  if ((TUI_CMD_WIN->generic.height + diff) < 1)		    make_invisible_and_set_new_height (TUI_CMD_WIN, 1);		  else		    make_invisible_and_set_new_height (				     TUI_CMD_WIN, TUI_CMD_WIN->generic.height + diff);		}	      make_visible_with_new_height (TUI_CMD_WIN);	      make_visible_with_new_height (second_win);	      make_visible_with_new_height (first_win);	      if (first_win->generic.content_size <= 0)		tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);	      if (second_win->generic.content_size <= 0)		tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);	    }	}    }  return status;}/* Function make the target window (and auxillary windows associated   with the targer) invisible, and set the new height and location.  */static voidmake_invisible_and_set_new_height (struct tui_win_info * win_info, int height){  int i;  struct tui_gen_win_info * gen_win_info;  tui_make_invisible (&win_info->generic);  win_info->generic.height = height;  if (height > 1)    win_info->generic.viewport_height = height - 1;  else    win_info->generic.viewport_height = height;  if (win_info != TUI_CMD_WIN)    win_info->generic.viewport_height--;  /* Now deal with the auxillary windows associated with win_info */  switch (win_info->generic.type)    {    case SRC_WIN:    case DISASSEM_WIN:      gen_win_info = win_info->detail.source_info.execution_info;      tui_make_invisible (gen_win_info);      gen_win_info->height = height;      gen_win_info->origin.y = win_info->generic.origin.y;      if (height > 1)	gen_win_info->viewport_height = height - 1;      else	gen_win_info->viewport_height = height;      if (win_info != TUI_CMD_WIN)	gen_win_info->viewport_height--;      if (tui_win_has_locator (win_info))	{	  gen_win_info = tui_locator_win_info_ptr ();	  tui_make_invisible (gen_win_info);	  gen_win_info->origin.y = win_info->generic.origin.y + height;	}      break;    case DATA_WIN:      /* delete all data item windows */      for (i = 0; i < win_info->generic.content_size; i++)	{	  gen_win_info = (struct tui_gen_win_info *) & ((struct tui_win_element *)		      win_info->generic.content[i])->which_element.data_window;	  tui_delete_win (gen_win_info->handle);	  gen_win_info->handle = (WINDOW *) NULL;	}      break;    default:      break;    }}/* Function to make the windows with new heights visible.  This means   re-creating the windows' content since the window had to be   destroyed to be made invisible.  */static voidmake_visible_with_new_height (struct tui_win_info * win_info){  struct symtab *s;  tui_make_visible (&win_info->generic);  tui_check_and_display_highlight_if_needed (win_info);  switch (win_info->generic.type)    {    case SRC_WIN:    case DISASSEM_WIN:      tui_free_win_content (win_info->detail.source_info.execution_info);      tui_make_visible (win_info->detail.source_info.execution_info);      if (win_info->generic.content != NULL)	{	  union tui_line_or_address line_or_addr;	  struct symtab_and_line cursal	    = get_current_source_symtab_and_line ();	  if (win_info->generic.type == SRC_WIN)	    line_or_addr.line_no =	      win_info->detail.source_info.start_line_or_addr.line_no;	  else	    line_or_addr.addr =	      win_info->detail.source_info.start_line_or_addr.addr;	  tui_free_win_content (&win_info->generic);	  tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE);	}      else if (deprecated_selected_frame != (struct frame_info *) NULL)	{	  union tui_line_or_address line;	  struct symtab_and_line cursal = get_current_source_symtab_and_line ();	  s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));	  if (win_info->generic.type == SRC_WIN)	    line.line_no = cursal.line;	  else	    {	      find_line_pc (s, cursal.line, &line.addr);	    }	  tui_update_source_window (win_info, s, line, TRUE);	}      if (tui_win_has_locator (win_info))	{	  tui_make_visible (tui_locator_win_info_ptr ());	  tui_show_locator_content ();	}      break;    case DATA_WIN:      tui_display_all_data ();      break;    case CMD_WIN:      win_info->detail.command_info.cur_line = 0;      win_info->detail.command_info.curch = 0;      wmove (win_info->generic.handle,	     win_info->detail.command_info.cur_line,	     win_info->detail.command_info.curch);      break;    default:      break;    }}static intnew_height_ok (struct tui_win_info * primary_win_info, int new_height){  int ok = (new_height < tui_term_height ());  if (ok)    {      int diff;      enum tui_layout_type cur_layout = tui_current_layout ();      diff = (new_height - primary_win_info->generic.height) * (-1);      if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)	{	  ok = ((primary_win_info->generic.type == CMD_WIN &&		 new_height <= (tui_term_height () - 4) &&		 new_height >= MIN_CMD_WIN_HEIGHT) ||		(primary_win_info->generic.type != CMD_WIN &&		 new_height <= (tui_term_height () - 2) &&		 new_height >= MIN_WIN_HEIGHT));	  if (ok)	    {			/* check the total height */	      struct tui_win_info * win_info;	      if (primary_win_info == TUI_CMD_WIN)		win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];	      else		win_info = TUI_CMD_WIN;	      ok = ((new_height +		     (win_info->generic.height + diff)) <= tui_term_height ());	    }	}      else	{	  int cur_total_height, total_height, min_height = 0;	  struct tui_win_info *first_win;	  struct tui_win_info *second_win;	  if (cur_layout == SRC_DISASSEM_COMMAND)	    {	      first_win = TUI_SRC_WIN;	      second_win = TUI_DISASM_WIN;	    }	  else	    {	      first_win = TUI_DATA_WIN;	      second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];	    }	  /*	     ** We could simply add all the heights to obtain the same result	     ** but below is more explicit since we subtract 1 for the	     ** line that the first and second windows share, and add one	     ** for the locator.	   */	  total_height = cur_total_height =	    (first_win->generic.height + second_win->generic.height - 1)	    + TUI_CMD_WIN->generic.height + 1 /*locator */ ;	  if (primary_win_info == TUI_CMD_WIN)	    {	      /* locator included since first & second win share a line */	      ok = ((first_win->generic.height +		     second_win->generic.height + diff) >=		    (MIN_WIN_HEIGHT * 2) &&		    new_height >= MIN_CMD_WIN_HEIGHT);	      if (ok)		{		  total_height = new_height + (first_win->generic.height +					  second_win->generic.height + diff);		  min_height = MIN_CMD_WIN_HEIGHT;		}	    }	  else	    {	      min_height = MIN_WIN_HEIGHT;	      /*	         ** First see if we can increase/decrease the command	         ** window.  And make sure that the command window is	         ** at least 1 line	       */	      ok = ((TUI_CMD_WIN->generic.height + diff) > 0);	      if (!ok)		{		/*				   ** Looks like we have to increase/decrease one of				   ** the other windows				 */		  if (primary_win_info == first_win)		    ok = (second_win->generic.height + diff) >= min_height;		  else		    ok = (first_win->generic.height + diff) >= min_height;		}	      if (ok)		{		  if (primary_win_info == first_win)		    total_height = new_height +		      second_win->generic.height +		      TUI_CMD_WIN->generic.height + diff;		  else		    total_height = new_height +		      first_win->generic.height +		      TUI_CMD_WIN->generic.height + diff;		}	    }	  /*	     ** Now make sure that the proposed total height doesn't exceed	     ** the old total height.	   */	  if (ok)	    ok = (new_height >= min_height && total_height <= cur_total_height);	}    }  return ok;}static voidparse_scrolling_args (char *arg, struct tui_win_info * * win_to_scroll,		      int *num_to_scroll){  if (num_to_scroll)    *num_to_scroll = 0;  *win_to_scroll = tui_win_with_focus ();  /*     ** First set up the default window to scroll, in case there is no     ** window name arg   */  if (arg != (char *) NULL)    {      char *buf, *buf_ptr;      /* process the number of lines to scroll */      buf = buf_ptr = xstrdup (arg);      if (isdigit (*buf_ptr))	{	  char *num_str;	  num_str = buf_ptr;	  buf_ptr = strchr (buf_ptr, ' ');	  if (buf_ptr != (char *) NULL)	    {	      *buf_ptr = (char) 0;	      if (num_to_scroll)		*num_to_scroll = atoi (num_str);	      buf_ptr++;	    }	  else if (num_to_scroll)	    *num_to_scroll = atoi (num_str);	}      /* process the window name if one is specified */      if (buf_ptr != (char *) NULL)	{	  char *wname;	  int i;	  if (*buf_ptr == ' ')	    while (*(++buf_ptr) == ' ')	      ;	  if (*buf_ptr != (char) 0)	    wname = buf_ptr;	  else	    wname = "?";	  	  /* Validate the window name */	  for (i = 0; i < strlen (wname); i++)	    wname[i] = toupper (wname[i]);	  *win_to_scroll = tui_partial_win_by_name (wname);	  if (*win_to_scroll == (struct tui_win_info *) NULL ||	      !(*win_to_scroll)->generic.is_visible)	    warning ("Invalid window specified. \n\The window name specified must be valid and visible.\n");	  else if (*win_to_scroll == TUI_CMD_WIN)	    *win_to_scroll = (struct tui_win_info *) (tui_source_windows ())->list[0];	}      xfree (buf);    }}

⌨️ 快捷键说明

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