Exemple #1
0
void
bosh_readline_cb (char *user_line)
{
  char *line = user_line;
  struct cmd_list_element *c;
  int from_tty = 1;
  char *arg;
  GError *error = NULL;

  bosh_utils_disable_prompt ();

  /* Repeat the last command if the user simply presses <enter>... */
  if (strcmp (line, "") == 0 && last_command)
    {
      line = last_command;
      c = bosh_lookup_command (&line, cmdlist, "", 1, &error);
    }
  else
    {
      /* Save the line for possible repeating later via <enter> later */
      if (last_command)
        g_free (last_command);
      last_command = strdup (user_line);
      c = bosh_lookup_command (&line, cmdlist, "", 1, &error);
    }

  if (!c)
    {
      bosh_utils_enable_prompt ();
      return;
    }

  /* NB: If a command is found line will be updated to point at the first
   * argument */

  /* Pass null arg rather than an empty one.  */
  arg = *line ? line : 0;

  if (c->flags & DEPRECATED_WARN_USER)
    deprecated_cmd_warning (&line);

  if (c->type == set_cmd || c->type == show_cmd)
    do_setshow_command (arg, from_tty, c);
  else if (!bosh_command_has_callback (c))
    g_print (_("That is not a command, just a help topic."));
  else
    bosh_command_call (c, arg, from_tty);

  bosh_utils_enable_prompt ();
}
Exemple #2
0
void
cmd_show_list (struct cmd_list_element *list, int from_tty, char *prefix)
{
  for (; list != NULL; list = list->next)
    {
      /* If we find a prefix, run its list, prefixing our output by its
         prefix (with "show " skipped).  */
      if (list->prefixlist && !list->abbrev_flag)
	{
	  char *new_prefix = strstr (list->prefixname, "show ") + 5;
	  cmd_show_list (*list->prefixlist, from_tty, new_prefix);
	}
      else
	{
	  g_print ("%s%s:", prefix, list->name);
	  if (list->type == show_cmd)
	    do_setshow_command ((char *) NULL, from_tty, list);
	  else
	    bosh_command_call (list, NULL, from_tty);
	}
    }
}
/* Show all the settings in a list of show commands: */
void
cmd_show_list(struct cmd_list_element *list, int from_tty, char *prefix)
{
  struct cleanup *showlist_chain;

  showlist_chain = make_cleanup_ui_out_tuple_begin_end(uiout, "showlist");
  for (; list != NULL; list = list->next)
    {
      /* If we find a prefix, run its list, prefixing our output by its
         prefix (with "show " skipped).  */
      if (list->prefixlist && !list->abbrev_flag)
	{
	  struct cleanup *optionlist_chain
	    = make_cleanup_ui_out_tuple_begin_end (uiout, "optionlist");
	  char *new_prefix = strstr (list->prefixname, "show ") + 5;
	  if (ui_out_is_mi_like_p (uiout))
	    ui_out_field_string (uiout, "prefix", new_prefix);
	  cmd_show_list (*list->prefixlist, from_tty, new_prefix);
	  /* Close the tuple: */
	  do_cleanups(optionlist_chain);
	}
      if (list->type == show_cmd)
	{
	  struct cleanup *option_chain
	    = make_cleanup_ui_out_tuple_begin_end(uiout, "option");
	  ui_out_text(uiout, prefix);
	  ui_out_field_string(uiout, "name", list->name);
	  ui_out_text(uiout, ":  ");
	  do_setshow_command((char *)NULL, from_tty, list);
          /* Close the tuple: */
	  do_cleanups(option_chain);
	}
    }
  /* Close the tuple: */
  do_cleanups(showlist_chain);
}