Replace uses of sindex() with constant accept strings with strpbrk() / strchr()
sindex(), where neither argument is NULL and the accept string does not start with ^, is exactly equivalent to the standard function strpbrk(). Further, strpbrk() where the accept string is only one character long, is exactly equivalent to strchr().
This commit is contained in:
@@ -4352,8 +4352,7 @@ void BX_parse_line (const char *name, char *org_line, const char *args, int hist
|
|||||||
{
|
{
|
||||||
char *line = NULL,
|
char *line = NULL,
|
||||||
*stuff,
|
*stuff,
|
||||||
*s,
|
*s;
|
||||||
*t;
|
|
||||||
int args_flag = 0,
|
int args_flag = 0,
|
||||||
die = 0;
|
die = 0;
|
||||||
|
|
||||||
@@ -4416,13 +4415,10 @@ void BX_parse_line (const char *name, char *org_line, const char *args, int hist
|
|||||||
{
|
{
|
||||||
while ((s = line))
|
while ((s = line))
|
||||||
{
|
{
|
||||||
if ((t = sindex(line, "\r\n")))
|
line = strpbrk(line, "\r\n");
|
||||||
{
|
if (line)
|
||||||
*t++ = '\0';
|
*line++ = '\0';
|
||||||
line = t;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
line = NULL;
|
|
||||||
parse_command(s, hist_flag, (char *)args);
|
parse_command(s, hist_flag, (char *)args);
|
||||||
|
|
||||||
if ((will_catch_break_exceptions && break_exception) ||
|
if ((will_catch_break_exceptions && break_exception) ||
|
||||||
@@ -4945,7 +4941,7 @@ BUILT_IN_COMMAND(BX_load)
|
|||||||
char *optr = start;
|
char *optr = start;
|
||||||
|
|
||||||
/* Skip slashed brackets */
|
/* Skip slashed brackets */
|
||||||
while ((ptr = sindex(optr, "{};/")) &&
|
while ((ptr = strpbrk(optr, "{};/")) &&
|
||||||
ptr != optr && ptr[-1] == '\\')
|
ptr != optr && ptr[-1] == '\\')
|
||||||
optr = ptr+1;
|
optr = ptr+1;
|
||||||
|
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ void add_to_history(char *line)
|
|||||||
{
|
{
|
||||||
while (line && *line)
|
while (line && *line)
|
||||||
{
|
{
|
||||||
if ((ptr = sindex(line, "\n\r")) != NULL)
|
if ((ptr = strpbrk(line, "\r\n")) != NULL)
|
||||||
*(ptr++) = '\0';
|
*ptr++ = '\0';
|
||||||
add_to_history_list(hist_count, line);
|
add_to_history_list(hist_count, line);
|
||||||
last_dir = PREV;
|
last_dir = PREV;
|
||||||
hist_count++;
|
hist_count++;
|
||||||
|
|||||||
@@ -832,11 +832,11 @@ static char *cut_n_fix_glob ( char *nickuserhost )
|
|||||||
/* doh! */
|
/* doh! */
|
||||||
user = userhost;
|
user = userhost;
|
||||||
|
|
||||||
if ((host = sindex(userhost, "@")))
|
if ((host = strchr(userhost, '@')))
|
||||||
/* USER IS CORRECT HERE */
|
/* USER IS CORRECT HERE */
|
||||||
*host++ = 0;
|
*host++ = 0;
|
||||||
|
|
||||||
else if (sindex(userhost, "."))
|
else if (strchr(userhost, '.'))
|
||||||
{
|
{
|
||||||
user = "*";
|
user = "*";
|
||||||
host = userhost;
|
host = userhost;
|
||||||
@@ -850,14 +850,14 @@ static char *cut_n_fix_glob ( char *nickuserhost )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
user = copy;
|
user = copy;
|
||||||
if ((host = sindex(user, "@")))
|
if ((host = strchr(user, '@')))
|
||||||
{
|
{
|
||||||
nick = "*";
|
nick = "*";
|
||||||
*host++ = 0;
|
*host++ = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (sindex(user, "."))
|
if (strchr(user, '.'))
|
||||||
{
|
{
|
||||||
nick = "*";
|
nick = "*";
|
||||||
host = user;
|
host = user;
|
||||||
|
|||||||
@@ -460,25 +460,28 @@ extern int word_scount (char *str)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *BX_next_arg (char *str, char **new_ptr)
|
char *BX_next_arg(char *str, char **new_ptr)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
/* added by Sheik (kilau@prairie.nodak.edu) -- sanity */
|
if (!str)
|
||||||
if (!str || !*str)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((ptr = sindex(str, "^ ")) != NULL)
|
if ((ptr = sindex(str, "^ ")) != NULL)
|
||||||
{
|
{
|
||||||
if ((str = sindex(ptr, space)) != NULL)
|
if ((str = strchr(ptr, ' ')) != NULL)
|
||||||
*str++ = (char) 0;
|
*str++ = 0;
|
||||||
else
|
else
|
||||||
str = empty_string;
|
str = empty_string;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
str = empty_string;
|
str = empty_string;
|
||||||
|
}
|
||||||
|
|
||||||
if (new_ptr)
|
if (new_ptr)
|
||||||
*new_ptr = str;
|
*new_ptr = str;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,7 +619,7 @@ char *safe_new_next_arg (char *str, char **new_ptr)
|
|||||||
if (*ptr == '"')
|
if (*ptr == '"')
|
||||||
{
|
{
|
||||||
start = ++ptr;
|
start = ++ptr;
|
||||||
while ((str = sindex(ptr, "\"\\")) != NULL)
|
while ((str = strpbrk(ptr, "\"\\")) != NULL)
|
||||||
{
|
{
|
||||||
switch (*str)
|
switch (*str)
|
||||||
{
|
{
|
||||||
@@ -637,7 +640,7 @@ char *safe_new_next_arg (char *str, char **new_ptr)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((str = sindex(ptr, " \t")) != NULL)
|
if ((str = strpbrk(ptr, " \t")) != NULL)
|
||||||
*str++ = '\0';
|
*str++ = '\0';
|
||||||
else
|
else
|
||||||
str = empty_string;
|
str = empty_string;
|
||||||
@@ -667,14 +670,11 @@ char *BX_new_new_next_arg (char *str, char **new_ptr, char *type)
|
|||||||
{
|
{
|
||||||
if ((*ptr == '"') || (*ptr == '\''))
|
if ((*ptr == '"') || (*ptr == '\''))
|
||||||
{
|
{
|
||||||
char blah[3];
|
char accept[] = { *ptr, '\\', 0 };
|
||||||
blah[0] = *ptr;
|
|
||||||
blah[1] = '\\';
|
|
||||||
blah[2] = '\0';
|
|
||||||
|
|
||||||
*type = *ptr;
|
*type = *ptr;
|
||||||
start = ++ptr;
|
start = ++ptr;
|
||||||
while ((str = sindex(ptr, blah)) != NULL)
|
while ((str = strpbrk(ptr, accept)) != NULL)
|
||||||
{
|
{
|
||||||
switch (*str)
|
switch (*str)
|
||||||
{
|
{
|
||||||
@@ -697,7 +697,7 @@ char *BX_new_new_next_arg (char *str, char **new_ptr, char *type)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
*type = '\"';
|
*type = '\"';
|
||||||
if ((str = sindex(ptr, " \t")) != NULL)
|
if ((str = strpbrk(ptr, " \t")) != NULL)
|
||||||
*str++ = 0;
|
*str++ = 0;
|
||||||
else
|
else
|
||||||
str = empty_string;
|
str = empty_string;
|
||||||
|
|||||||
Reference in New Issue
Block a user