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

📄 isearch.c

📁 在非GUI环境下
💻 C
📖 第 1 页 / 共 2 页
字号:
	 not subsequently execute the character as a command.  The default	 value is "\033\012" (ESC and C-J). */      if (strchr (isearch_terminators, c))	{	  /* ESC still terminates the search, but if there is pending	     input or if input arrives within 0.1 seconds (on systems	     with select(2)) it is used as a prefix character	     with rl_execute_next.  WATCH OUT FOR THIS!  This is intended	     to allow the arrow keys to be used like ^F and ^B are used	     to terminate the search and execute the movement command.	     XXX - since _rl_input_available depends on the application-	     settable keyboard timeout value, this could alternatively	     use _rl_input_queued(100000) */	  if (c == ESC && _rl_input_available ())	    rl_execute_next (ESC);	  break;	}#define ENDSRCH_CHAR(c) \  ((CTRL_CHAR (c) || META_CHAR (c) || (c) == RUBOUT) && ((c) != CTRL ('G')))#if defined (HANDLE_MULTIBYTE)      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	{	  if (c >= 0 && strlen (mb) == 1 && ENDSRCH_CHAR (c))	    {	      /* This sets rl_pending_input to c; it will be picked up the next		 time rl_read_key is called. */	      rl_execute_next (c);	      break;	    }	}      else#endif      if (c >= 0 && ENDSRCH_CHAR (c))	{	  /* This sets rl_pending_input to c; it will be picked up the next	     time rl_read_key is called. */	  rl_execute_next (c);	  break;	}      switch (c)	{	case -1:	  if (search_string_index == 0)	    {	      if (last_isearch_string)		{		  search_string_size = 64 + last_isearch_string_len;		  search_string = (char *)xrealloc (search_string, search_string_size);		  strcpy (search_string, last_isearch_string);		  search_string_index = last_isearch_string_len;		  rl_display_search (search_string, reverse, -1);		  break;		}	      continue;	    }	  else if (reverse)	    --line_index;	  else if (line_index != sline_len)	    ++line_index;	  else	    rl_ding ();	  break;	  /* switch directions */	case -2:	  direction = -direction;	  reverse = direction < 0;	  break;	/* delete character from search string. */	case -3:	/* C-H, DEL */	  /* This is tricky.  To do this right, we need to keep a	     stack of search positions for the current search, with	     sentinels marking the beginning and end.  But this will	     do until we have a real isearch-undo. */	  if (search_string_index == 0)	    rl_ding ();	  else	    search_string[--search_string_index] = '\0';	  break;	case -4:	/* C-G */	  rl_replace_line (lines[orig_line], 0);	  rl_point = orig_point;	  rl_mark = orig_mark;	  rl_restore_prompt();	  rl_clear_message ();	  if (allocated_line)	    free (allocated_line);	  free (lines);	  RL_UNSETSTATE(RL_STATE_ISEARCH);	  return 0;	case -5:	/* C-W */	  /* skip over portion of line we already matched */	  wstart = rl_point + search_string_index;	  if (wstart >= rl_end)	    {	      rl_ding ();	      break;	    }	  /* if not in a word, move to one. */	  if (rl_alphabetic(rl_line_buffer[wstart]) == 0)	    {	      rl_ding ();	      break;	    }	  n = wstart;	  while (n < rl_end && rl_alphabetic(rl_line_buffer[n]))	    n++;	  wlen = n - wstart + 1;	  if (search_string_index + wlen + 1 >= search_string_size)	    {	      search_string_size += wlen + 1;	      search_string = (char *)xrealloc (search_string, search_string_size);	    }	  for (; wstart < n; wstart++)	    search_string[search_string_index++] = rl_line_buffer[wstart];	  search_string[search_string_index] = '\0';	  break;	case -6:	/* C-Y */	  /* skip over portion of line we already matched */	  wstart = rl_point + search_string_index;	  if (wstart >= rl_end)	    {	      rl_ding ();	      break;	    }	  n = rl_end - wstart + 1;	  if (search_string_index + n + 1 >= search_string_size)	    {	      search_string_size += n + 1;	      search_string = (char *)xrealloc (search_string, search_string_size);	    }	  for (n = wstart; n < rl_end; n++)	    search_string[search_string_index++] = rl_line_buffer[n];	  search_string[search_string_index] = '\0';	  break;	default:	  /* Add character to search string and continue search. */	  if (search_string_index + 2 >= search_string_size)	    {	      search_string_size += 128;	      search_string = (char *)xrealloc (search_string, search_string_size);	    }#if defined (HANDLE_MULTIBYTE)	  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	    {	      int j, l;	      for (j = 0, l = strlen (mb); j < l; )		search_string[search_string_index++] = mb[j++];	    }	  else#endif	    search_string[search_string_index++] = c;	  search_string[search_string_index] = '\0';	  break;	}      for (found = failed = 0;;)	{	  int limit = sline_len - search_string_index + 1;	  /* Search the current line. */	  while (reverse ? (line_index >= 0) : (line_index < limit))	    {	      if (STREQN (search_string, sline + line_index, search_string_index))		{		  found++;		  break;		}	      else		line_index += direction;	    }	  if (found)	    break;	  /* Move to the next line, but skip new copies of the line	     we just found and lines shorter than the string we're	     searching for. */	  do	    {	      /* Move to the next line. */	      i += direction;	      /* At limit for direction? */	      if (reverse ? (i < 0) : (i == hlen))		{		  failed++;		  break;		}	      /* We will need these later. */	      sline = lines[i];	      sline_len = strlen (sline);	    }	  while ((prev_line_found && STREQ (prev_line_found, lines[i])) ||		 (search_string_index > sline_len));	  if (failed)	    break;	  /* Now set up the line for searching... */	  line_index = reverse ? sline_len - search_string_index : 0;	}      if (failed)	{	  /* We cannot find the search string.  Ding the bell. */	  rl_ding ();	  i = last_found_line;	  continue; 		/* XXX - was break */	}      /* We have found the search string.  Just display it.  But don't	 actually move there in the history list until the user accepts	 the location. */      if (found)	{	  prev_line_found = lines[i];	  rl_replace_line (lines[i], 0);	  rl_point = line_index;	  last_found_line = i;	  rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);	}    }  /* The searching is over.  The user may have found the string that she     was looking for, or else she may have exited a failing search.  If     LINE_INDEX is -1, then that shows that the string searched for was     not found.  We use this to determine where to place rl_point. */  /* First put back the original state. */  strcpy (rl_line_buffer, lines[orig_line]);  rl_restore_prompt ();  /* Save the search string for possible later use. */  FREE (last_isearch_string);  last_isearch_string = search_string;  last_isearch_string_len = search_string_index;  if (last_found_line < orig_line)    rl_get_previous_history (orig_line - last_found_line, 0);  else    rl_get_next_history (last_found_line - orig_line, 0);  /* If the string was not found, put point at the end of the last matching     line.  If last_found_line == orig_line, we didn't find any matching     history lines at all, so put point back in its original position. */  if (line_index < 0)    {      if (last_found_line == orig_line)	line_index = orig_point;      else	line_index = strlen (rl_line_buffer);      rl_mark = orig_mark;    }  rl_point = line_index;  /* Don't worry about where to put the mark here; rl_get_previous_history     and rl_get_next_history take care of it. */  rl_clear_message ();  FREE (allocated_line);  free (lines);  RL_UNSETSTATE(RL_STATE_ISEARCH);  return 0;}

⌨️ 快捷键说明

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