Code:
int buildWords(WORDS* w, char* buf)
{
char *token, holdster[1024], reBuf[1024];
int position=0, i, x;
strcpy(reBuf, buf);
token = strtok( buf, " " );
while( token != NULL )
{
//While there are tokens in buf
strcpy(w->ords[position], token);
//Get next token:
token = strtok( NULL, " ");
position++;
}
//get rid of symbols and re-build the line (buf)
if(w->ords[1][0]=='<')
{
i=0;
while(w->ords[1][i+1]!='>')
{
w->ords[1][i]=w->ords[1][i+1];
i++;
}
w->ords[1][i]='\0';
}
if(strstr(w->ords[1], "+")||strstr(w->ords[1], "%")||strstr(w->ords[1], "@"))
{
i=0;
while(w->ords[1][i]!='\0')
{
w->ords[1][i]=w->ords[1][i+1];
i++;
}
w->ords[1][i]='\0';
}
if(strstr(w->ords[2], "+")||strstr(w->ords[2], "%")||strstr(w->ords[2], "@"))
{
i=0;
while(w->ords[2][i]!='\0')
{
w->ords[2][i]=w->ords[2][i+1];
i++;
}
w->ords[2][i]='\0';
}
//change nicknames, look for either in group file or changed in log file
//////////////////////////////////////////////////////////////////////////
//if a nick was changed, keep track of it
if(strstr(reBuf,"is now known as"))
{
for(i=0, x=1; i<totalGroupNames/2; i++)
{
if(strstr(w->ords[2], changeNick[i]) || strstr(w->ords[2], groups[x]))
{
fprintf(grouping, "Name change: %s was found and turned into ", changeNick[i]);
x=0;
while(w->ords[7][x]!='\0')
x++;
if(x>2)
w->ords[7][x-2]='\0';
strcpy(changeNick[i], w->ords[7]);
fprintf(grouping, "%s\n", changeNick[i]);
i=5000;
}
x+=2;
}
}
for(i=1, x=0; i<totalGroupNames; i+=2)
{
if(strstr(w->ords[1], groups[i]) || strstr(w->ords[1], changeNick[x]))
{
fprintf(grouping, "Nick grouping: %s was turned into", w->ords[1]);
strcpy(w->ords[1], groups[i-1]);
fprintf(grouping, " %s\n", w->ords[1]);
}
x++;
}
for(i=1, x=0; i<totalGroupNames; i+=2)
{
if((strstr(w->ords[2], groups[i]) || strstr( w->ords[2], changeNick[x])) && !strcmp(w->ords[1], "*"))
{
fprintf(grouping, "Nick grouping: %s was turned into", w->ords[2]);
strcpy(w->ords[2], groups[i-1]);
fprintf(grouping, " %s\n", w->ords[2]);
}
x++;
}
//////////////////////////////////////////////////////////////////////////
//Select changes, for certain modes
//////////////////////////////////////////////////////////////////////////
if(strstr(reBuf, "sets mode:") && !strcmp(w->ords[1], "***"))
{
for(i=1; i<totalGroupNames; i+=2)
if(strstr(w->ords[1], groups[i]))
strcpy(w->ords[1], groups[i-1]);
}
if(strstr(reBuf, "was kicked by") && !strcmp(w->ords[1], "***"))
{
for(i=1; i<totalGroupNames; i+=2)
if(strstr(w->ords[6], groups[i]))
strcpy(w->ords[6], groups[i-1]);
}
strcpy(buf, w->ords[0]);
for(i=1; i<position; i++)
{
sprintf(holdster, " %s", w->ords[i]);
strcat(buf, holdster);
}
return(position);
}
w->ords is simply a string. I have it set up as a structure because of earlier things I was doing with the program, but now it's not neccessary, I just haven't seen a reason to change it back.