/* MI Command Set - MI parser.
- Copyright (C) 2000-2015 Free Software Foundation, Inc.
+ Copyright (C) 2000-2020 Free Software Foundation, Inc.
Contributed by Cygnus Solutions (a Red Hat company).
char *arg;
/* Skip leading white space. */
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
/* Three possibilities: EOF, quoted string, or other text. */
switch (*chp)
{
}
}
-void
-mi_parse_free (struct mi_parse *parse)
+mi_parse::mi_parse ()
+ : op (MI_COMMAND),
+ command (NULL),
+ token (NULL),
+ cmd (NULL),
+ cmd_start (NULL),
+ args (NULL),
+ argv (NULL),
+ argc (0),
+ all (0),
+ thread_group (-1),
+ thread (-1),
+ frame (-1),
+ language (language_unknown)
{
- if (parse == NULL)
- return;
- if (parse->command != NULL)
- xfree (parse->command);
- if (parse->token != NULL)
- xfree (parse->token);
- if (parse->args != NULL)
- xfree (parse->args);
- if (parse->argv != NULL)
- freeargv (parse->argv);
- xfree (parse);
}
-/* A cleanup that calls mi_parse_free. */
-
-static void
-mi_parse_cleanup (void *arg)
+mi_parse::~mi_parse ()
{
- mi_parse_free (arg);
+ xfree (command);
+ xfree (token);
+ xfree (args);
+ freeargv (argv);
}
-struct mi_parse *
+std::unique_ptr<struct mi_parse>
mi_parse (const char *cmd, char **token)
{
const char *chp;
- struct mi_parse *parse = XNEW (struct mi_parse);
- struct cleanup *cleanup;
- memset (parse, 0, sizeof (*parse));
- parse->all = 0;
- parse->thread_group = -1;
- parse->thread = -1;
- parse->frame = -1;
- parse->language = language_unknown;
-
- cleanup = make_cleanup (mi_parse_cleanup, parse);
+ std::unique_ptr<struct mi_parse> parse (new struct mi_parse);
/* Before starting, skip leading white space. */
- cmd = skip_spaces_const (cmd);
+ cmd = skip_spaces (cmd);
/* Find/skip any token and then extract it. */
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
/* This wasn't a real MI command. Return it as a CLI_COMMAND. */
if (*chp != '-')
{
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
parse->command = xstrdup (chp);
parse->op = CLI_COMMAND;
- discard_cleanups (cleanup);
-
return parse;
}
_("Undefined MI command: %s"), parse->command);
/* Skip white space following the command. */
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
/* Parse the --thread and --frame options, if present. At present,
some important commands, like '-break-*' are implemented by
}
else if (strncmp (chp, "--language ", ls) == 0)
{
- char *lang_name;
- struct cleanup *old_chain;
-
option = "--language";
chp += ls;
- lang_name = extract_arg_const (&chp);
- old_chain = make_cleanup (xfree, lang_name);
+ std::string lang_name = extract_arg (&chp);
- parse->language = language_enum (lang_name);
+ parse->language = language_enum (lang_name.c_str ());
if (parse->language == language_unknown
|| parse->language == language_auto)
- error (_("Invalid --language argument: %s"), lang_name);
-
- do_cleanups (old_chain);
+ error (_("Invalid --language argument: %s"), lang_name.c_str ());
}
else
break;
if (*chp != '\0' && !isspace (*chp))
error (_("Invalid value for the '%s' option"), option);
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
}
/* For new argv commands, attempt to return the parsed argument
list. */
if (parse->cmd->argv_func != NULL)
{
- mi_parse_argv (chp, parse);
+ mi_parse_argv (chp, parse.get ());
if (parse->argv == NULL)
error (_("Problem parsing arguments: %s %s"), parse->command, chp);
}
if (parse->cmd->cli.cmd != NULL)
parse->args = xstrdup (chp);
- discard_cleanups (cleanup);
-
/* Fully parsed, flag as an MI command. */
parse->op = MI_COMMAND;
return parse;