strtoken -> rb_strtok_r (with arguments order changes)

This commit is contained in:
Valery Yatsko 2008-04-20 09:20:25 +04:00
parent cbe4e1ba31
commit 4a2651e520
9 changed files with 15 additions and 52 deletions

View file

@ -98,8 +98,6 @@ char *strip_tabs(char *dest, const unsigned char *src, size_t len);
#define EmptyString(x) ((x) == NULL || *(x) == '\0') #define EmptyString(x) ((x) == NULL || *(x) == '\0')
#define CheckEmpty(x) EmptyString(x) ? "" : x #define CheckEmpty(x) EmptyString(x) ? "" : x
char *strtoken(char **save, char *str, const char *fs);
/* /*
* character macros * character macros
*/ */

View file

@ -148,7 +148,7 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p
* this code has a side effect of losing keys, but.. * this code has a side effect of losing keys, but..
*/ */
chanlist = LOCAL_COPY(parv[1]); chanlist = LOCAL_COPY(parv[1]);
for(name = strtoken(&p, chanlist, ","); name; name = strtoken(&p, NULL, ",")) for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p))
{ {
/* check the length and name of channel is ok */ /* check the length and name of channel is ok */
if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN))
@ -210,11 +210,11 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p
if(parc > 2) if(parc > 2)
{ {
mykey = LOCAL_COPY(parv[2]); mykey = LOCAL_COPY(parv[2]);
key = strtoken(&p2, mykey, ","); key = rb_strtok_r(mykey, ",", &p2);
} }
for(name = strtoken(&p, jbuf, ","); name; for(name = rb_strtok_r(jbuf, ",", &p); name;
key = (key) ? strtoken(&p2, NULL, ",") : NULL, name = strtoken(&p, NULL, ",")) key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p))
{ {
hook_data_channel_activity hook_info; hook_data_channel_activity hook_info;

View file

@ -250,7 +250,7 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
ntargets = 0; ntargets = 0;
for(nick = strtoken(&p, target_list, ","); nick; nick = strtoken(&p, NULL, ",")) for(nick = rb_strtok_r(target_list, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p))
{ {
char *with_prefix; char *with_prefix;
/* /*

View file

@ -73,7 +73,7 @@ m_part(struct Client *client_p, struct Client *source_p, int parc, const char *p
if(parc > 2) if(parc > 2)
rb_strlcpy(reason, parv[2], sizeof(reason)); rb_strlcpy(reason, parv[2], sizeof(reason));
name = strtoken(&p, s, ","); name = rb_strtok_r(s, ",", &p);
/* Finish the flood grace period... */ /* Finish the flood grace period... */
if(MyClient(source_p) && !IsFloodDone(source_p)) if(MyClient(source_p) && !IsFloodDone(source_p))
@ -84,7 +84,7 @@ m_part(struct Client *client_p, struct Client *source_p, int parc, const char *p
while(name) while(name)
{ {
part_one_client(client_p, source_p, name, reason); part_one_client(client_p, source_p, name, reason);
name = strtoken(&p, NULL, ","); name = rb_strtok_r(NULL, ",", &p);
} }
return 0; return 0;
} }

View file

@ -76,7 +76,7 @@ m_accept(struct Client *client_p, struct Client *source_p, int parc, const char
build_nicklist(source_p, addbuf, delbuf, parv[1]); build_nicklist(source_p, addbuf, delbuf, parv[1]);
/* parse the delete list */ /* parse the delete list */
for (nick = strtoken(&p, delbuf, ","); nick != NULL; nick = strtoken(&p, NULL, ",")) for (nick = rb_strtok_r(delbuf, ",", &p); nick != NULL; nick = rb_strtok_r(NULL, ",", &p))
{ {
/* shouldnt happen, but lets be paranoid */ /* shouldnt happen, but lets be paranoid */
if((target_p = find_named_person(nick)) == NULL) if((target_p = find_named_person(nick)) == NULL)
@ -102,7 +102,7 @@ m_accept(struct Client *client_p, struct Client *source_p, int parc, const char
accept_num = rb_dlink_list_length(&source_p->localClient->allow_list); accept_num = rb_dlink_list_length(&source_p->localClient->allow_list);
/* parse the add list */ /* parse the add list */
for (nick = strtoken(&p, addbuf, ","); nick; nick = strtoken(&p, NULL, ",")) for (nick = rb_strtok_r(addbuf, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p), accept_num++)
{ {
/* shouldnt happen, but lets be paranoid */ /* shouldnt happen, but lets be paranoid */
if((target_p = find_named_person(nick)) == NULL) if((target_p = find_named_person(nick)) == NULL)
@ -129,7 +129,6 @@ m_accept(struct Client *client_p, struct Client *source_p, int parc, const char
/* why is this here? */ /* why is this here? */
/* del_from accept(target_p, source_p); */ /* del_from accept(target_p, source_p); */
add_accept(source_p, target_p); add_accept(source_p, target_p);
accept_num++;
} }
return 0; return 0;
@ -160,7 +159,7 @@ build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char *
del = lenadd = lendel = 0; del = lenadd = lendel = 0;
/* build list of clients to add into addbuf, clients to remove in delbuf */ /* build list of clients to add into addbuf, clients to remove in delbuf */
for (name = strtoken(&p, n, ","); name; name = strtoken(&p, NULL, ","), del = 0) for (name = rb_strtok_r(n, ",", &p); name; name = rb_strtok_r(NULL, ",", &p), del = 0)
{ {
if(*name == '-') if(*name == '-')
{ {

View file

@ -84,7 +84,7 @@ mr_capab(struct Client *client_p, struct Client *source_p, int parc, const char
for (i = 1; i < parc; i++) for (i = 1; i < parc; i++)
{ {
char *t = LOCAL_COPY(parv[i]); char *t = LOCAL_COPY(parv[i]);
for (s = strtoken(&p, t, " "); s; s = strtoken(&p, NULL, " ")) for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
{ {
for (cap = captab; cap->name; cap++) for (cap = captab; cap->name; cap++)
{ {
@ -121,7 +121,7 @@ me_gcap(struct Client *client_p, struct Client *source_p,
source_p->serv->fullcaps = rb_strdup(parv[1]); source_p->serv->fullcaps = rb_strdup(parv[1]);
for (s = strtoken(&p, t, " "); s; s = strtoken(&p, NULL, " ")) for (s = rb_strtok_r(t, " ", &p); s; s = rb_strtok_r(NULL, " ", &p))
{ {
for (cap = captab; cap->name; cap++) for (cap = captab; cap->name; cap++)
{ {

View file

@ -86,7 +86,7 @@ m_ison(struct Client *client_p, struct Client *source_p, int parc, const char *p
for (i = 1; i < parc; i++) for (i = 1; i < parc; i++)
{ {
char *cs = LOCAL_COPY(parv[i]); char *cs = LOCAL_COPY(parv[i]);
for (nick = strtoken(&p, cs, " "); nick; nick = strtoken(&p, NULL, " ")) for (nick = rb_strtok_r(cs, " ", &p); nick; nick = rb_strtok_r(NULL, " ", &p))
{ {
target_p = find_named_client(nick); target_p = find_named_client(nick);

View file

@ -73,7 +73,7 @@ add_monitor(struct Client *client_p, const char *nicks)
tmp = LOCAL_COPY(nicks); tmp = LOCAL_COPY(nicks);
for(name = strtoken(&p, tmp, ","); name; name = strtoken(&p, NULL, ",")) for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p))
{ {
if(EmptyString(name) || strlen(name) > NICKLEN-1) if(EmptyString(name) || strlen(name) > NICKLEN-1)
continue; continue;
@ -170,7 +170,7 @@ del_monitor(struct Client *client_p, const char *nicks)
tmp = LOCAL_COPY(nicks); tmp = LOCAL_COPY(nicks);
for(name = strtoken(&p, tmp, ","); name; name = strtoken(&p, NULL, ",")) for(name = rb_strtok_r(tmp, ",", &p); name; name = rb_strtok_r(NULL, ",", &p))
{ {
if(EmptyString(name)) if(EmptyString(name))
continue; continue;

View file

@ -109,40 +109,6 @@ strip_tabs(char *dest, const unsigned char *src, size_t len)
return dest; return dest;
} }
/*
* strtoken - walk through a string of tokens, using a set of separators
* argv 9/90
*
*/
char *
strtoken(char **save, char *str, const char *fs)
{
char *pos = *save; /* keep last position across calls */
char *tmp;
if(str)
pos = str; /* new string scan */
while(pos && *pos && strchr(fs, *pos) != NULL)
++pos; /* skip leading separators */
if(!pos || !*pos)
return (pos = *save = NULL); /* string contains only sep's */
tmp = pos; /* now, keep position of the token */
while(*pos && strchr(fs, *pos) == NULL)
++pos; /* skip content of the token */
if(*pos)
*pos++ = '\0'; /* remove first sep after the token */
else
pos = NULL; /* end of string */
*save = pos;
return tmp;
}
char * char *
strip_colour(char *string) strip_colour(char *string)
{ {