src/main.c
changeset 6 7eb12be31bb5
parent 0 586472add385
child 8 3152de03758e
equal deleted inserted replaced
5:7c7fc8906920 6:7eb12be31bb5
    38 }
    38 }
    39 
    39 
    40 int main (int argc, char **argv)
    40 int main (int argc, char **argv)
    41 {
    41 {
    42     UC uc;
    42     UC uc;
    43     MSG message;
    43     MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
    44     char buf[513];
    44     char buf[513];
    45     char *msg;
    45     char *msg;
    46     char *command;
    46     char *command;
    47     int len;
    47     int len;
    48 
    48 
    73         return -1;
    73         return -1;
    74 
    74 
    75     if (!(message.stream = irc_connect (uc.server, uc.port)))
    75     if (!(message.stream = irc_connect (uc.server, uc.port)))
    76         return EXIT_FAILURE;
    76         return EXIT_FAILURE;
    77 
    77 
    78     if ((len = irc_login (message.stream, uc.nick, uc.pass)) != 0) {
    78     if ((len = irc_login (message.stream, uc.server, uc.nick, uc.pass)) != 0) {
    79         switch (len) {
    79         switch (len) {
    80         case IRC_GENERAL_ERROR:
    80         case IRC_GENERAL_ERROR:
    81             printf ("GENERAL ERROR\n");
    81             printf ("GENERAL ERROR\n");
    82             break;
    82             break;
    83         case IRC_LOGIN_ERROR:
    83         case IRC_LOGIN_ERROR:
    95         fprintf (message.stream, "JOIN :%s\r\n", uc.channel);
    95         fprintf (message.stream, "JOIN :%s\r\n", uc.channel);
    96         if (uc.topic)
    96         if (uc.topic)
    97             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
    97             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
    98     }
    98     }
    99 
    99 
   100     while (active) {
   100     while (!feof (message.stream)) {
   101         if (fgets (buf, 512, message.stream) == NULL) {
   101         message.line = NULL;
   102             active = 0;
   102         *buf = 0;
   103             break;
   103         fgets (buf, 512, message.stream);
   104         }
       
   105 
   104 
   106         if ((command = irc_parsemessage (buf, &message))) {
   105         if ((command = irc_parsemessage (buf, &message))) {
   107             printf ("%10s %s %s\n", command, message.channel, message.line);
   106             printf ("%10s %s %s\n", command, message.channel, message.line);
   108         } else {
   107         } else {
   109             if ((msg = parse (&message, &active)) != NULL) {
   108             if ((msg = parse (&message, &active)) != NULL) {
   110                 fprintf (message.stream, "%s\r\n", msg);
   109                 fprintf (message.stream, "%s\r\n", msg);
   111                 printf ("%10s %s", "WRITE", msg);
   110                 printf ("%10s %s", "WRITE", msg);
   112             }
   111             }
   113         }
   112         }
   114         *buf = 0;
       
   115     }
   113     }
   116     printf ("\n\nClosing Connection\n\n");
   114     printf ("\n\nClosing Connection\n\n");
   117     fclose (message.stream);
   115     fclose (message.stream);
   118 
   116 
   119     /*
   117     /*