New common function "startswith"

This commit introduces a new inline common function "startswith"
which takes two string arguments and returns nonzero if the first
string starts with the second.  It also updates the 295 places
where this logic was written out longhand to use the new function.

gdb/ChangeLog:

	* common/common-utils.h (startswith): New inline function.
	All places where this logic was used updated to use the above.
This commit is contained in:
Gary Benson
2015-03-06 09:42:06 +00:00
parent e80417caef
commit 61012eef84
77 changed files with 309 additions and 329 deletions

View File

@ -9729,7 +9729,7 @@ parse_breakpoint_sals (char **address,
/* If no arg given, or if first arg is 'if ', use the default
breakpoint. */
if ((*address) == NULL
|| (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
|| (startswith ((*address), "if") && isspace ((*address)[2])))
{
/* The last displayed codepoint, if it's valid, is our default breakpoint
address. */
@ -11401,7 +11401,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
tok++;
toklen = end_tok - tok + 1;
if (toklen == 6 && !strncmp (tok, "thread", 6))
if (toklen == 6 && startswith (tok, "thread"))
{
/* At this point we've found a "thread" token, which means
the user is trying to set a watchpoint that triggers
@ -11423,7 +11423,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
if (!valid_thread_id (thread))
invalid_thread_id_error (thread);
}
else if (toklen == 4 && !strncmp (tok, "mask", 4))
else if (toklen == 4 && startswith (tok, "mask"))
{
/* We've found a "mask" token, which means the user wants to
create a hardware watchpoint that is going to have the mask
@ -15493,7 +15493,7 @@ strace_command (char *arg, int from_tty)
/* Decide if we are dealing with a static tracepoint marker (`-m'),
or with a normal static tracepoint. */
if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
if (arg && startswith (arg, "-m") && isspace (arg[2]))
ops = &strace_marker_breakpoint_ops;
else
ops = &tracepoint_breakpoint_ops;