- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- typedef struct IRCLINE
- {
- char sender[64]; // :jack!busta@aol-C490E8E0 ou :irc.aol.com
- char action[8]; // PRIVMSG JOIN PART etc....
- char message[512]; // : salut mon gars
- char channel[32]; // #chanell
- char nick[32]; // bustabot
- char numeric[4]; // 401 succeful joined
- char mode[16]; // +MmuCcRitpv
- }IRCLINE;
-
- int IsUpperCase(char chaine[]){
- int i=0;
- while(chaine[i]!= '\0'){
- if(chaine[i] < 'A' || chaine[i] > 'Z') return 0;
- i++;
- }
- return 1;
- }
-
- int IsNumeric(const char number[]){
- int i=0;
- while(number[i]!='\0'){
- if(number[i] < '0' || number[i] > '9') return 0;
- i++;
- }
- return i == 3 ?1 : 0;
- }
-
- int parseline(const char ircline[BUFSIZ],char tab[][512]){
-
- int nb_mot=1,i=0,j=0;
- char *pointeur,*buffer;
-
- buffer = strdup(ircline);
- pointeur = strtok( buffer, " " );
- strcpy(tab[0],pointeur);
-
- while( pointeur != NULL ) {
-
- pointeur = strtok( NULL, " " );
- if ( pointeur != NULL ) {
- nb_mot++;
- strcpy(tab[nb_mot-1],pointeur);
- }
-
- }
- /*********** on 'recolle' la partie message ******************/
- for(i=1;i<(nb_mot+1);i++){
- if(tab[i][0]==':'){
- for(j=1;j<(nb_mot-i);j++){
- strcat(tab[i]," ");
- strcat(tab[i],tab[i+j]);
- strcpy(tab[i+j],"\0");
- }
- }
- }
-
- return nb_mot-(j-1);
- }
-
- void GetIrcParam(const char imgline[],IRCLINE* irc){
-
- int nb_mot=0,i=0,j=0;
- char tab[10][512];
- memset(&tab, 0, sizeof(tab));
- nb_mot=parseline(imgline,tab);
- if(nb_mot==2){
- strcpy(irc->action,tab[0]);
- strcpy(irc->message,tab[1]+1);
- }
- else {
- strcpy(irc->sender,tab[0]+1);
- for(i=1;i<(nb_mot);i++){
- if(IsUpperCase(tab[i]))strcpy(irc->action,tab[i]);
- //else if(IsNumeric(tab[i]))infoirc.numeric=atoi(tab[i]);
- else if(IsNumeric(tab[i]))strcpy(irc->numeric,tab[i]);
- else if(tab[i][0]=='#')strcpy(irc->channel,tab[i]);
- else if(tab[i][0]==':')strcpy(irc->message,tab[i]+1);
- else if((tab[i][0]==('-'))||(tab[i][0]=='+'))strcpy(irc->mode,tab[i]);
- else {
- if(tab[i][0]!='@')strcpy(irc->nick,tab[i]);
- }
- }
- }
-
-
- }
-
- int main(){
- const char line[]=":jack!busta@aol-C490E8E0 TOPIC #bustabot :salut busta";
- IRCLINE infoirc;
- memset(&infoirc, 0, sizeof(infoirc));
- GetIrcParam(line,&infoirc);
-
- printf("Sender %s\n"
- "Action %s\n"
- "Message %s\n"
- "Channel %s\n"
- "Nick %s\n"
- "Numeric %s\n"
- "Mode %s\n",infoirc.sender,infoirc.action,infoirc.message,infoirc.channel,infoirc.nick,infoirc.numeric,infoirc.mode);
-
-
- getch();
- return 0;
- }
-
-
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct IRCLINE
{
char sender[64]; // :jack!busta@aol-C490E8E0 ou :irc.aol.com
char action[8]; // PRIVMSG JOIN PART etc....
char message[512]; // : salut mon gars
char channel[32]; // #chanell
char nick[32]; // bustabot
char numeric[4]; // 401 succeful joined
char mode[16]; // +MmuCcRitpv
}IRCLINE;
int IsUpperCase(char chaine[]){
int i=0;
while(chaine[i]!= '\0'){
if(chaine[i] < 'A' || chaine[i] > 'Z') return 0;
i++;
}
return 1;
}
int IsNumeric(const char number[]){
int i=0;
while(number[i]!='\0'){
if(number[i] < '0' || number[i] > '9') return 0;
i++;
}
return i == 3 ?1 : 0;
}
int parseline(const char ircline[BUFSIZ],char tab[][512]){
int nb_mot=1,i=0,j=0;
char *pointeur,*buffer;
buffer = strdup(ircline);
pointeur = strtok( buffer, " " );
strcpy(tab[0],pointeur);
while( pointeur != NULL ) {
pointeur = strtok( NULL, " " );
if ( pointeur != NULL ) {
nb_mot++;
strcpy(tab[nb_mot-1],pointeur);
}
}
/*********** on 'recolle' la partie message ******************/
for(i=1;i<(nb_mot+1);i++){
if(tab[i][0]==':'){
for(j=1;j<(nb_mot-i);j++){
strcat(tab[i]," ");
strcat(tab[i],tab[i+j]);
strcpy(tab[i+j],"\0");
}
}
}
return nb_mot-(j-1);
}
void GetIrcParam(const char imgline[],IRCLINE* irc){
int nb_mot=0,i=0,j=0;
char tab[10][512];
memset(&tab, 0, sizeof(tab));
nb_mot=parseline(imgline,tab);
if(nb_mot==2){
strcpy(irc->action,tab[0]);
strcpy(irc->message,tab[1]+1);
}
else {
strcpy(irc->sender,tab[0]+1);
for(i=1;i<(nb_mot);i++){
if(IsUpperCase(tab[i]))strcpy(irc->action,tab[i]);
//else if(IsNumeric(tab[i]))infoirc.numeric=atoi(tab[i]);
else if(IsNumeric(tab[i]))strcpy(irc->numeric,tab[i]);
else if(tab[i][0]=='#')strcpy(irc->channel,tab[i]);
else if(tab[i][0]==':')strcpy(irc->message,tab[i]+1);
else if((tab[i][0]==('-'))||(tab[i][0]=='+'))strcpy(irc->mode,tab[i]);
else {
if(tab[i][0]!='@')strcpy(irc->nick,tab[i]);
}
}
}
}
int main(){
const char line[]=":jack!busta@aol-C490E8E0 TOPIC #bustabot :salut busta";
IRCLINE infoirc;
memset(&infoirc, 0, sizeof(infoirc));
GetIrcParam(line,&infoirc);
printf("Sender %s\n"
"Action %s\n"
"Message %s\n"
"Channel %s\n"
"Nick %s\n"
"Numeric %s\n"
"Mode %s\n",infoirc.sender,infoirc.action,infoirc.message,infoirc.channel,infoirc.nick,infoirc.numeric,infoirc.mode);
getch();
return 0;
}