src/config.c
changeset 13 d3554afaa768
parent 11 a769385a59c6
child 18 4435146391ae
equal deleted inserted replaced
12:213c3d4abc66 13:d3554afaa768
     6 
     6 
     7 #include <stdio.h>
     7 #include <stdio.h>
     8 #include <stdlib.h>
     8 #include <stdlib.h>
     9 #include <string.h>
     9 #include <string.h>
    10 
    10 
       
    11 #include <compat.h>
    11 #include <config.h>
    12 #include <config.h>
    12 
    13 
    13 const
    14 const
    14 char *CONFIG_OPTIONS[] = {
    15 char *CONFIG_OPTIONS[] = {
    15     "NICK", "PASSWORD", "SERVER", "PORT",
    16     "NICK", "PASSWORD", "SERVER", "PORT",
    55             value = strtok (NULL, "\n");
    56             value = strtok (NULL, "\n");
    56             i = 0;
    57             i = 0;
    57             while (CONFIG_OPTIONS[i] != NULL) {
    58             while (CONFIG_OPTIONS[i] != NULL) {
    58                 if (!strcmp (CONFIG_OPTIONS[i], token)) {
    59                 if (!strcmp (CONFIG_OPTIONS[i], token)) {
    59                     if (value)
    60                     if (value)
    60                         line[i] = strdup (value);
    61                         line[i] = compat_strdup (value);
    61                 }
    62                 }
    62                 i++;
    63                 i++;
    63             }
    64             }
    64         }
    65         }
    65     }
    66     }
    70     i = 0;
    71     i = 0;
    71     while (CONFIG_OPTIONS[i] != NULL) {
    72     while (CONFIG_OPTIONS[i] != NULL) {
    72         if (line[i] != NULL)
    73         if (line[i] != NULL)
    73             switch (i) {
    74             switch (i) {
    74             case 0:            /* NICK */
    75             case 0:            /* NICK */
    75                 uc->nick = strdup (line[i]);
    76                 uc->nick = compat_strdup (line[i]);
    76                 free (line[i]);
    77                 free (line[i]);
    77                 break;
    78                 break;
    78             case 1:            /* PASSWORD */
    79             case 1:            /* PASSWORD */
    79                 uc->pass = strdup (line[i]);
    80                 uc->pass = compat_strdup (line[i]);
    80                 free (line[i]);
    81                 free (line[i]);
    81                 break;
    82                 break;
    82             case 2:            /* SERVER */
    83             case 2:            /* SERVER */
    83                 uc->server = strdup (line[i]);
    84                 uc->server = compat_strdup (line[i]);
    84                 free (line[i]);
    85                 free (line[i]);
    85                 break;
    86                 break;
    86             case 3:            /* PORT */
    87             case 3:            /* PORT */
    87                 uc->port = atoi (line[i]);
    88                 uc->port = atoi (line[i]);
    88                 free (line[i]);
    89                 free (line[i]);
    89                 break;
    90                 break;
    90             case 4:            /* CHANNEL */
    91             case 4:            /* CHANNEL */
    91                 uc->channel = strdup (line[i]);
    92                 uc->channel = compat_strdup (line[i]);
    92                 free (line[i]);
    93                 free (line[i]);
    93                 break;
    94                 break;
    94             case 5:            /* TOPIC */
    95             case 5:            /* TOPIC */
    95                 uc->topic = strdup (line[i]);
    96                 uc->topic = compat_strdup (line[i]);
    96                 free (line[i]);
    97                 free (line[i]);
    97                 break;
    98                 break;
    98             }
    99             }
    99         i++;
   100         i++;
   100     }
   101     }