freeargv (argv);
}
+/* See mi-parse.h. */
+
+void
+mi_parse::set_thread_group (const char *arg, char **endp)
+{
+ if (thread_group != -1)
+ error (_("Duplicate '--thread-group' option"));
+ if (*arg != 'i')
+ error (_("Invalid thread group id"));
+ arg += 1;
+ thread_group = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_thread (const char *arg, char **endp)
+{
+ if (thread != -1)
+ error (_("Duplicate '--thread' option"));
+ thread = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_frame (const char *arg, char **endp)
+{
+ if (frame != -1)
+ error (_("Duplicate '--frame' option"));
+ frame = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_language (const char *arg, const char **endp)
+{
+ std::string lang_name = extract_arg (&arg);
+
+ language = language_enum (lang_name.c_str ());
+ if (language == language_unknown)
+ error (_("Invalid --language argument: %s"), lang_name.c_str ());
+
+ if (endp != nullptr)
+ *endp = arg;
+}
+
std::unique_ptr<struct mi_parse>
mi_parse::make (const char *cmd, char **token)
{
char *endp;
option = "--thread-group";
- if (parse->thread_group != -1)
- error (_("Duplicate '--thread-group' option"));
chp += tgs;
- if (*chp != 'i')
- error (_("Invalid thread group id"));
- chp += 1;
- parse->thread_group = strtol (chp, &endp, 10);
+ parse->set_thread_group (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--thread ", ts) == 0)
char *endp;
option = "--thread";
- if (parse->thread != -1)
- error (_("Duplicate '--thread' option"));
chp += ts;
- parse->thread = strtol (chp, &endp, 10);
+ parse->set_thread (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--frame ", fs) == 0)
char *endp;
option = "--frame";
- if (parse->frame != -1)
- error (_("Duplicate '--frame' option"));
chp += fs;
- parse->frame = strtol (chp, &endp, 10);
+ parse->set_frame (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--language ", ls) == 0)
{
option = "--language";
chp += ls;
- std::string lang_name = extract_arg (&chp);
-
- parse->language = language_enum (lang_name.c_str ());
- if (parse->language == language_unknown)
- error (_("Invalid --language argument: %s"), lang_name.c_str ());
+ parse->set_language (chp, &chp);
}
else
break;
mi_parse () = default;
+ /* Helper methods for parsing arguments. Each takes the argument
+ to be parsed. It will either set a member of this object, or
+ throw an exception on error. In each case, *ENDP, if non-NULL,
+ will be updated to just after the argument text. */
+ void set_thread_group (const char *arg, char **endp);
+ void set_thread (const char *arg, char **endp);
+ void set_frame (const char *arg, char **endp);
+ void set_language (const char *arg, const char **endp);
+
std::string m_args;
};