src/main.c
changeset 33 56571d34d754
parent 31 bbcb8a3366b4
child 47 a689b6a8e6ed
equal deleted inserted replaced
32:89fb9c6611ca 33:56571d34d754
    12 #include <locale.h>
    12 #include <locale.h>
    13 #include <libintl.h>
    13 #include <libintl.h>
    14 
    14 
    15 #include <mcbot.h>
    15 #include <mcbot.h>
    16 #include <config.h>
    16 #include <config.h>
       
    17 #include "common.h"
    17 
    18 
    18 #ifndef CONFIG_FILE
    19 #ifndef CONFIG_FILE
    19 #define CONFIG_FILE "/var/lib/mcbot/.mcbotrc"
    20 #define CONFIG_FILE "/var/lib/mcbot/.mcbotrc"
    20 #endif
    21 #endif
    21 
    22 
    33 
    34 
    34 int main (int argc, char **argv)
    35 int main (int argc, char **argv)
    35 {
    36 {
    36     UC uc;
    37     UC uc;
    37     MSG message;
    38     MSG message;
    38     char buf[513];
    39     char buf[DEFAULT_BUF_SIZE];
    39     char *msg;
    40     char *msg;
    40     char *command;
    41     char *command;
    41     int len;
    42     int len;
    42 
    43 
    43     if (bindtextdomain ("mcbot", LOCALE_PATH) != NULL) {
    44     if (bindtextdomain ("mcbot", LOCALE_PATH) != NULL) {
    89         if (uc.topic)
    90         if (uc.topic)
    90             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
    91             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
    91     }
    92     }
    92 
    93 
    93     while (!feof (message.stream)) {
    94     while (!feof (message.stream)) {
    94         *buf = '\0';
    95         fgets (buf, sizeof (buf), message.stream);
    95         fgets (buf, 512, message.stream);
       
    96 
    96 
    97         if (!active)            /* the bot was killed with SIGTERM */
    97         if (!active)            /* the bot was killed with SIGTERM */
    98             break;
    98             break;
    99 
    99 
   100         if ((command = irc_parsemessage (buf, &message))) {
   100         if ((command = irc_parsemessage (buf, &message))) {
       
   101             if (!strcmp (command, "ERROR") || !strcmp (command, "ENOMEM"))
       
   102                 break;
   101             printf ("%10s %s %s\n", command, message.channel, message.line);
   103             printf ("%10s %s %s\n", command, message.channel, message.line);
   102             if (!strcmp (command, "ERROR") || !strcmp (command, "ENOMEM")) {
       
   103                 break;
       
   104             }
       
   105         } else {
   104         } else {
   106             if ((msg = parse (&message)) != NULL) {
   105             if ((msg = parse (&message)) != NULL) {
   107                 fprintf (message.stream, "%s\r\n", msg);
   106                 fprintf (message.stream, "%s\r\n", msg);
   108                 fflush (message.stream);
   107                 fflush (message.stream);
   109                 printf ("%10s %s", "WRITE", msg);
   108                 printf ("%10s %s", "WRITE", msg);
   110             }
   109             }
   111         }
   110         }
       
   111         fflush (stdout);
   112     }
   112     }
   113     printf ("\n\nClosing Connection\n\n");
   113     printf ("\n\nClosing Connection\n\n");
   114     fclose (message.stream);
   114     fclose (message.stream);
   115 
   115 
   116     /*
   116     /*