Exemple #1
0
int
_rl_arg_callback (_rl_arg_cxt cxt)
{
  int c, r;

  c = _rl_arg_getchar ();
  if (c < 0)
    return (1);		/* EOF */

  if (_rl_argcxt & NUM_READONE)
    {
      _rl_argcxt &= ~NUM_READONE;
      rl_restore_prompt ();
      rl_clear_message ();
      RL_UNSETSTATE(RL_STATE_NUMERICARG);
      rl_execute_next (c);
      return 0;
    }

  r = _rl_arg_dispatch (cxt, c);
  if (r > 0)
    rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
  return (r != 1);
}
Exemple #2
0
/* Search non-interactively through the history list.  DIR < 0 means to
   search backwards through the history of previous commands; otherwise
   the search is for commands subsequent to the current position in the
   history list.  PCHAR is the character to use for prompting when reading
   the search string; if not specified (0), it defaults to `:'. */
static void
noninc_search (int dir, int pchar)
{
  int saved_point, c, pmtlen;
  char *p;

  maybe_save_line ();
  saved_point = rl_point;

  /* Use the line buffer to read the search string. */
  rl_line_buffer[0] = 0;
  rl_end = rl_point = 0;

  /* XXX - this needs fixing to work with the prompt expansion stuff - XXX */
  pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0;
  p = xmalloc (2 + pmtlen);
  if (pmtlen)
    strcpy (p, rl_prompt);
  p[pmtlen] = pchar ? pchar : ':';
  p[pmtlen + 1]  = '\0';

  rl_message (p, 0, 0);
  free (p);

  /* Read the search string. */
  while ((c = rl_read_key ()) != '\0')
    {
      switch (c)
	{
	case CTRL('H'):
	case RUBOUT:
	  if (rl_point == 0)
	    {
	      maybe_unsave_line ();
	      rl_clear_message ();
	      rl_point = saved_point;
	      return;
	    }
	  rl_rubout (1, c);
	  break;

	case CTRL('W'):
	  rl_unix_word_rubout (1, c);
	  break;

	case CTRL('U'):
	  rl_unix_line_discard (1, c);
	  break;

	case RETURN:
	case NEWLINE:
	  goto dosearch;
	  /* NOTREACHED */
	  break;

	case CTRL('C'):
	case CTRL('G'):
	  maybe_unsave_line ();
	  rl_clear_message ();
	  rl_point = saved_point;
	  DING ();
	  return;

	default:
	  rl_insert (1, c);
	  break;
	}
      rl_redisplay ();
    }

 dosearch:
  /* If rl_point == 0, we want to re-use the previous search string and
     start from the saved history position.  If there's no previous search
     string, punt. */
  if (rl_point == 0)
    {
      if (!noninc_search_string)
	{
	  DING ();
	  return;
	}
    }
  else
    {
      /* We want to start the search from the current history position. */
      noninc_history_pos = where_history ();
      if (noninc_search_string)
	free (noninc_search_string);
      noninc_search_string = strdup (rl_line_buffer);
    }

  noninc_dosearch (noninc_search_string, dir);
}