contrib/gdb-7/gdb/linespec.c
static void
decode_line_2 (struct linespec_state *self,
	       struct symtabs_and_lines *result,
	       const char *select_mode)
{
  const char *iter;
  char *args, *prompt;
  int i;
  struct cleanup *old_chain;
  VEC (const_char_ptr) *item_names = NULL, *filters = NULL;
  struct get_number_or_range_state state;

  gdb_assert (select_mode != multiple_symbols_all);
  gdb_assert (self->canonical != NULL);

  old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &item_names);
  make_cleanup (VEC_cleanup (const_char_ptr), &filters);
  for (i = 0; i < result->nelts; ++i)
    {
      int j, found = 0;
      const char *iter;

      gdb_assert (self->canonical_names[i] != NULL);
      for (j = 0; VEC_iterate (const_char_ptr, item_names, j, iter); ++j)
	{
	  if (strcmp (iter, self->canonical_names[i]) == 0)
	    {
	      found = 1;
	      break;
	    }
	}

      if (!found)
	VEC_safe_push (const_char_ptr, item_names, self->canonical_names[i]);
    }

  if (select_mode == multiple_symbols_cancel
      && VEC_length (const_char_ptr, item_names) > 1)
    error (_("canceled because the command is ambiguous\n"
	     "See set/show multiple-symbol."));
  
  if (select_mode == multiple_symbols_all
      || VEC_length (const_char_ptr, item_names) == 1)
    {
      do_cleanups (old_chain);
      convert_results_to_lsals (self, result);
      return;
    }

  printf_unfiltered (_("[0] cancel\n[1] all\n"));
  for (i = 0; VEC_iterate (const_char_ptr, item_names, i, iter); ++i)
    printf_unfiltered ("[%d] %s\n", i + 2, iter);

  prompt = getenv ("PS2");
  if (prompt == NULL)
    {
      prompt = "> ";
    }
  args = command_line_input (prompt, 0, "overload-choice");

  if (args == 0 || *args == 0)
    error_no_arg (_("one or more choice numbers"));

  init_number_or_range (&state, args);
  while (!state.finished)
    {
      int num;

      num = get_number_or_range (&state);

      if (num == 0)
	error (_("canceled"));
      else if (num == 1)
	{
	  /* We intentionally make this result in a single breakpoint,
	     contrary to what older versions of gdb did.  The
	     rationale is that this lets a user get the
	     multiple_symbols_all behavior even with the 'ask'
	     setting; and he can get separate breakpoints by entering
	     "2-57" at the query.  */
	  do_cleanups (old_chain);
	  convert_results_to_lsals (self, result);
	  return;
	}

      num -= 2;
      if (num >= VEC_length (const_char_ptr, item_names))
	printf_unfiltered (_("No choice number %d.\n"), num);
      else
	{
	  const char *elt = VEC_index (const_char_ptr, item_names, num);

	  if (elt != NULL)
	    {
	      VEC_safe_push (const_char_ptr, filters, elt);
	      VEC_replace (const_char_ptr, item_names, num, NULL);
	    }
	  else
	    {
	      printf_unfiltered (_("duplicate request for %d ignored.\n"),
				 num);
	    }
	}
    }

  filter_results (self, result, filters);
  do_cleanups (old_chain);
}
/* Handle multiple results in RESULT depending on SELECT_MODE.  This
   will either return normally, throw an exception on multiple
   results, or present a menu to the user.  On return, the SALS vector
   in SELF->CANONICAL is set up properly.  */
Handle multiple results in RESULT depending on SELECT_MODE.  This
will either return normally, throw an exception on multiple
results, or present a menu to the user.  On return, the SALS vector
in SELF->CANONICAL is set up properly.
Handle multiple results in RESULT depending on SELECT_MODE . This will either return normally throw an exception on multiple results or present a menu to the user . On return the SALS vector in SELF - > CANONICAL is set up properly .
static void
decode_line_2 (struct linespec_state *self,
	       struct symtabs_and_lines *result,
	       const char *select_mode)
{
  const char *iter;
  char *args, *prompt;
  int i;
  struct cleanup *old_chain;
  VEC (const_char_ptr) *item_names = NULL, *filters = NULL;
  struct get_number_or_range_state state;
  gdb_assert (select_mode != multiple_symbols_all);
  gdb_assert (self->canonical != NULL);
  old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &item_names);
  make_cleanup (VEC_cleanup (const_char_ptr), &filters);
  for (i = 0; i < result->nelts; ++i)
    {
      int j, found = 0;
      const char *iter;
      gdb_assert (self->canonical_names[i] != NULL);
      for (j = 0; VEC_iterate (const_char_ptr, item_names, j, iter); ++j)
	{
	  if (strcmp (iter, self->canonical_names[i]) == 0)
	    {
	      found = 1;
	      break;
	    }
	}
      if (!found)
	VEC_safe_push (const_char_ptr, item_names, self->canonical_names[i]);
    }
  if (select_mode == multiple_symbols_cancel
      && VEC_length (const_char_ptr, item_names) > 1)
    error (_("canceled because the command is ambiguous\n"
	     "See set/show multiple-symbol."));
  if (select_mode == multiple_symbols_all
      || VEC_length (const_char_ptr, item_names) == 1)
    {
      do_cleanups (old_chain);
      convert_results_to_lsals (self, result);
      return;
    }
  printf_unfiltered (_("[0] cancel\n[1] all\n"));
  for (i = 0; VEC_iterate (const_char_ptr, item_names, i, iter); ++i)
    printf_unfiltered ("[%d] %s\n", i + 2, iter);
  prompt = getenv ("PS2");
  if (prompt == NULL)
    {
      prompt = "> ";
    }
  args = command_line_input (prompt, 0, "overload-choice");
  if (args == 0 || *args == 0)
    error_no_arg (_("one or more choice numbers"));
  init_number_or_range (&state, args);
  while (!state.finished)
    {
      int num;
      num = get_number_or_range (&state);
      if (num == 0)
	error (_("canceled"));
      else if (num == 1)
	{
	  do_cleanups (old_chain);
	  convert_results_to_lsals (self, result);
	  return;
	}
      num -= 2;
      if (num >= VEC_length (const_char_ptr, item_names))
	printf_unfiltered (_("No choice number %d.\n"), num);
      else
	{
	  const char *elt = VEC_index (const_char_ptr, item_names, num);
	  if (elt != NULL)
	    {
	      VEC_safe_push (const_char_ptr, filters, elt);
	      VEC_replace (const_char_ptr, item_names, num, NULL);
	    }
	  else
	    {
	      printf_unfiltered (_("duplicate request for %d ignored.\n"),
				 num);
	    }
	}
    }
  filter_results (self, result, filters);
  do_cleanups (old_chain);
}
static void decode_line_2 ( struct linespec_state * self , struct symtabs_and_lines * result , const char * select_mode ) { const char * iter ; char * args , * prompt ; int i ; struct cleanup * old_chain ; VEC ( const_char_ptr ) * item_names = NULL , * filters = NULL ; struct get_number_or_range_state state ; gdb_assert ( select_mode != multiple_symbols_all ) ; gdb_assert ( self -> canonical != NULL ) ; old_chain = make_cleanup ( VEC_cleanup ( const_char_ptr ) , & item_names ) ; make_cleanup ( VEC_cleanup ( const_char_ptr ) , & filters ) ; for ( i = 0 ; i < result -> nelts ; ++ i ) { int j , found = 0 ; const char * iter ; gdb_assert ( self -> canonical_names [ i ] != NULL ) ; for ( j = 0 ; VEC_iterate ( const_char_ptr , item_names , j , iter ) ; ++ j ) { if ( strcmp ( iter , self -> canonical_names [ i ] ) == 0 ) { found = 1 ; break ; } } if ( ! found ) VEC_safe_push ( const_char_ptr , item_names , self -> canonical_names [ i ] ) ; } if ( select_mode == multiple_symbols_cancel && VEC_length ( const_char_ptr , item_names ) > 1 ) error ( _ ( " \n " " " ) ) ; if ( select_mode == multiple_symbols_all || VEC_length ( const_char_ptr , item_names ) == 1 ) { do_cleanups ( old_chain ) ; convert_results_to_lsals ( self , result ) ; return ; } printf_unfiltered ( _ ( " \n \n " ) ) ; for ( i = 0 ; VEC_iterate ( const_char_ptr , item_names , i , iter ) ; ++ i ) printf_unfiltered ( " \n " , i + 2 , iter ) ; prompt = getenv ( " " ) ; if ( prompt == NULL ) { prompt = " " ; } args = command_line_input ( prompt , 0 , " " ) ; if ( args == 0 || * args == 0 ) error_no_arg ( _ ( " " ) ) ; init_number_or_range ( & state , args ) ; while ( ! state . finished ) { int num ; num = get_number_or_range ( & state ) ; if ( num == 0 ) error ( _ ( " " ) ) ; else if ( num == 1 ) { do_cleanups ( old_chain ) ; convert_results_to_lsals ( self , result ) ; return ; } num -= 2 ; if ( num >= VEC_length ( const_char_ptr , item_names ) ) printf_unfiltered ( _ ( " \n " ) , num ) ; else { const char * elt = VEC_index ( const_char_ptr , item_names , num ) ; if ( elt != NULL ) { VEC_safe_push ( const_char_ptr , filters , elt ) ; VEC_replace ( const_char_ptr , item_names , num , NULL ) ; } else { printf_unfiltered ( _ ( " \n " ) , num ) ; } } } filter_results ( self , result , filters ) ; do_cleanups ( old_chain ) ; }
Handle multiple results in RESULT depending on SELECT_MODE.
Handle multiple results in RESULT depending on SELECT_MODE .
/* We intentionally make this result in a single breakpoint,
	     contrary to what older versions of gdb did.  The
	     rationale is that this lets a user get the
	     multiple_symbols_all behavior even with the 'ask'
	     setting; and he can get separate breakpoints by entering
	     "2-57" at the query.  */