/[pengfork]/pengfork/src/options.c
ViewVC logotype

Diff of /pengfork/src/options.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by chupa, Sat Nov 30 10:28:52 2002 UTC revision 1.24 by chupa, Sun Dec 1 01:19:07 2002 UTC
# Line 32  Line 32 
32  #include <errno.h>  #include <errno.h>
33    
34  #include "common.h"  #include "common.h"
35    #include "gettext.h"
36  #include "options.h"  #include "options.h"
37  #include "checkopt.h"  #include "checkopt.h"
38  #include "utils.h"  #include "utils.h"
39  #include "log.h"  #include "log.h"
40    
41  enum { __general, __auth, __modem, __cable, __tcpip, __netiface, __sect_end };  enum
42  const char *section_name[__sect_end] = {  { __general, __auth, __modem, __cable, __tcpip, __netiface, __sect_end };
43    "General properties",  char *section_name[__sect_end];
   "User authentification",  
   "Modem properties",  
   "Cable properties",  
   "TCP/IP properties",  
   "Network interface properties"  
 };  
   
 #define STR(s,l,n,v,d,p,e,c)  \  
    {s, l, n, string, false, false, {string: v}, d, p, e, {check_string: c} }  
 #define BOOL(s,l,n,v,d,p,e,c)  \  
    {s, l, n, boolean, false, false, {boolean: v}, d, p, e, {check_boolean: c} }  
 #define INT(s,l,n,v,d,p,e,c)  \  
    {s, l, n, integer, false, false, {integer: v}, d, p, e, {check_integer: c} }  
   
   
   
 param_t param[PARAM_MAX] = {  
   /* GENERAL CONFIGURATION */  
   STR('f', "config-file", NULL, CONFDIR "/pengfork.cfg",  
       "read configuration file PATH.", "PATH",  
       __general, NULL),  
   
   STR(0, "access-method", "access_method", "modem",  
       "set the media used to access AOL.", "METHOD",  
       __general, check_access_method),  
   
   STR(0, "protocol", "protocol", "p3",  
       "set the protocol used for communication with AOL.", "PROT",  
       __general, check_protocol),  
   
   STR('t', "interface-type", "interface_type", "tun",  
       "set the interface type.", "TYPE",  
       __netiface, check_iface_type),  
   
   STR('i', "interface", "interface_name", NULL,  
       "set the interface name.", "NAME",  
       __netiface, NULL),  
   
   STR(0, NULL, "secret_file", CONFDIR "/aol-secrets",  
       NULL, NULL,  
       __auth, NULL),  
   
   STR('s', "screen-name", "screen_name", NULL,  
       "set the screen-name to use.", "SN",  
       __auth, check_screen_name),  
   
   BOOL('r', "auto-reconnect", "auto_reconnect", false,  
        "enable autoreconnection.", NULL,  
        __general, NULL),  
   
   INT(0, "reconnect-delay", "reconnect_delay", 0,  
       "set the delay between reconnections.", "DELAY",  
       __general, check_natural),  
   
   BOOL('d', "daemon", "daemon", false,    
        "enable daemon mode, run in background.", NULL,  
        __general, NULL),  
   
   INT('D', "debug-level", "debug_level", 0,  
       "set the verbosity level of the debug.", "LEVEL",  
       __general, check_debug_level),  
   
   BOOL(0, "dns", "set_dns", true,  
        "set the dns when connected.", NULL,  
        __netiface, NULL),  
   
   STR(0, "pid-file", "pid_file", "/var/run/pengfork.pid",  
       "set the PID file to create", "PATH",  
       __general, NULL),  
   
   STR(0, "ip-up", "ip-up_script", CONFDIR "/ip-up",  
       "set the script automaticly called when IP is up.", "PATH",  
       __netiface, NULL),  
   
   STR(0, "ip-down", "ip-down_script", CONFDIR "/ip-down",  
       "set the script automaticly called when IP is down.", "PATH",  
       __netiface, NULL),  
   
   
 #ifdef WITH_MODEM  
   /* MODEM SPECIFIC */  
   STR('m', "modem", "modem_device", "/dev/modem",  
       "set the serial device to use for the modem.", "PATH",  
       __modem, NULL),  
   
   BOOL(0, "rtscts", "rtscts", true,  
        "enable hardware flow control", NULL,  
        __modem, NULL),  
   
   STR(0, "init-str", "initstr1", "ATZ",  
       "set the primary initialization string sent to the modem.", "STRING",  
       __modem, NULL),  
   
   STR(0, NULL, "initstr2", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr3", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr4", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr5", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr6", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr7", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr8", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "initstr9", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, "dial-str", "dialstr", "ATDT",  
       "set the string used to dial.", "STRING",  
       __modem, NULL),  
   
   STR(0, NULL, "dial_prefix", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR('n', "phone", "phone", NULL,  
       "set the primary phone number to use.", "NUMBER",  
       __modem, NULL),  
   
   STR(0, NULL, "phone1", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "phone2", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "phone3", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "phone4", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   STR(0, NULL, "phone5", NULL,  
       NULL, NULL,  
       __modem, NULL),  
   
   INT('s', "line-speed", "line_speed", 115200,  
       "set the serial line speed.", "SPEED",  
       __modem, check_line_speed),  
   
   STR('c', "chat-script", "chat_script", CHATDIR "/aolnet.scm",  
       "set the chat script used for logging into AOL.", "SCRIPT",  
       __modem, NULL),  
   
   INT(0, NULL, "dial_retry", 3,  
       NULL, NULL,  
       __modem, check_natural),  
   
   INT(0, NULL, "retry_delay", 0,  
       NULL, NULL,  
       __modem, check_natural),  
 #endif /* WITH_MODEM */  
   
   
 #ifdef WITH_TCPIP  
   /* CABLE SPECIFIC */  
   STR(0, NULL, "aol_host", "AmericaOnline.aol.com",  
       NULL, NULL,  
       __cable, NULL),  
   
   INT(0, NULL, "aol_port", 5190,  
       NULL, NULL,  
       __cable, check_port),  
 #endif /* WITH_TCPIP */  
 };  
44    
45    param_t param[PARAM_MAX];
46    
47  /*  /*
48   * Command line options   * Command line options
# Line 249  static struct option const long_options_ Line 65  static struct option const long_options_
65    {NULL, 0, NULL, 0}    {NULL, 0, NULL, 0}
66  };  };
67    
68    void
69    init_parameters (void)
70    {
71      char *sections[__sect_end] =  {
72        gettext ("General properties"),
73        gettext ("User authentification"),
74        gettext ("Modem properties"),
75        gettext ("Cable properties"),
76        gettext ("TCP/IP properties"),
77        gettext ("Network interface properties")
78      };
79    
80    #define STR(s,l,n,v,d,p,e,c)  \
81        {s, l, n, string, false, false, {string: v}, d, p, e, {check_string: c} }
82    #define BOOL(s,l,n,v,d,p,e,c)  \
83        {s, l, n, boolean, false, false, {boolean: v}, d, p, e, {check_boolean: c} }
84    #define INT(s,l,n,v,d,p,e,c)  \
85        {s, l, n, integer, false, false, {integer: v}, d, p, e, {check_integer: c} }
86    
87      param_t params[PARAM_MAX] =  {
88        /* GENERAL CONFIGURATION */
89        STR ('f', "config-file", NULL, CONFDIR "/pengfork.cfg",
90             gettext ("read configuration file PATH."), "PATH",
91             __general, NULL),
92        STR (0, "access-method", "access_method", "modem",
93             gettext ("set the media used to access AOL."), "METHOD",
94             __general, check_access_method),
95        STR (0, "protocol", "protocol", "p3",
96             gettext ("set the protocol used for communication with AOL."), "PROT",
97             __general, check_protocol),
98        STR ('t', "interface-type", "interface_type", "tun",
99             gettext ("set the interface type."), "TYPE",
100             __netiface, check_iface_type),
101        STR ('i', "interface", "interface_name", NULL,
102             gettext ("set the interface name."), "NAME",
103             __netiface, NULL),
104        STR (0, NULL, "secret_file", CONFDIR "/aol-secrets",
105             NULL, NULL,
106             __auth, NULL),
107        STR ('s', "screen-name", "screen_name", NULL,
108             gettext ("set the screen-name to use."), "SN",
109             __auth, check_screen_name),
110        BOOL ('r', "auto-reconnect", "auto_reconnect", false,
111            gettext ("enable autoreconnection."), NULL,
112            __general, NULL),
113        INT (0, "reconnect-delay", "reconnect_delay", 0,
114             gettext ("set the delay between reconnections."), "DELAY",
115             __general, check_natural),
116        BOOL ('d', "daemon", "daemon", false,
117            gettext ("enable daemon mode, run in background."), NULL,
118            __general, NULL),
119        INT ('D', "debug-level", "debug_level", 0,
120             gettext ("set the verbosity level of the debug."), "LEVEL",
121             __general, check_debug_level),
122        BOOL (0, "dns", "set_dns", true,
123            gettext ("set the dns when connected."), NULL,
124            __netiface, NULL),
125        STR (0, "pid-file", "pid_file", "/var/run/pengfork.pid",
126             gettext ("set the PID file to create"), "PATH",
127             __general, NULL),
128        STR (0, "ip-up", "ip-up_script", CONFDIR "/ip-up",
129             gettext ("set the script automaticly called when IP is up."), "PATH",
130             __netiface, NULL),
131        STR (0, "ip-down", "ip-down_script", CONFDIR "/ip-down",
132             gettext ("set the script automaticly called when IP is down."), "PATH",
133             __netiface, NULL)
134    
135    #ifdef WITH_MODEM
136        /* MODEM SPECIFIC */
137        , STR ('m', "modem", "modem_device", "/dev/modem",
138             gettext ("set the serial device to use for the modem."), "PATH",
139             __modem, NULL),
140        BOOL (0, "rtscts", "rtscts", true,
141            gettext ("enable hardware flow control"), NULL,
142            __modem, NULL),
143        STR (0, "init-str", "initstr1", "ATZ",
144             gettext ("set the primary initialization string sent to the modem."), "STRING",
145             __modem, NULL),
146        STR (0, NULL, "initstr2", NULL,
147             NULL, NULL,
148             __modem, NULL),
149        STR (0, NULL, "initstr3", NULL,
150             NULL, NULL,
151             __modem, NULL),
152        STR (0, NULL, "initstr4", NULL,
153             NULL, NULL,
154             __modem, NULL),
155        STR (0, NULL, "initstr5", NULL,
156             NULL, NULL,
157             __modem, NULL),
158        STR (0, NULL, "initstr6", NULL,
159             NULL, NULL,
160             __modem, NULL),
161        STR (0, NULL, "initstr7", NULL,
162             NULL, NULL,
163             __modem, NULL),
164        STR (0, NULL, "initstr8", NULL,
165             NULL, NULL,
166             __modem, NULL),
167        STR (0, NULL, "initstr9", NULL,
168             NULL, NULL,
169             __modem, NULL),
170        STR (0, "dial-str", "dialstr", "ATDT",
171             gettext ("set the string used to dial."), "STRING",
172             __modem, NULL),
173        STR (0, NULL, "dial_prefix", NULL,
174             NULL, NULL,
175             __modem, NULL),
176        STR ('n', "phone", "phone", NULL,
177             gettext ("set the primary phone number to use."), "NUMBER",
178             __modem, NULL),
179        STR (0, NULL, "phone1", NULL,
180             NULL, NULL,
181             __modem, NULL),
182        STR (0, NULL, "phone2", NULL,
183             NULL, NULL,
184             __modem, NULL),
185        STR (0, NULL, "phone3", NULL,
186             NULL, NULL,
187             __modem, NULL),
188        STR (0, NULL, "phone4", NULL,
189             NULL, NULL,
190             __modem, NULL),
191        STR (0, NULL, "phone5", NULL, NULL, NULL, __modem, NULL),
192        INT ('s', "line-speed", "line_speed", 115200,
193             gettext ("set the serial line speed."), "SPEED",
194             __modem, check_line_speed),
195        STR ('c', "chat-script", "chat_script", CHATDIR "/aolnet.scm",
196             gettext ("set the chat script used for logging into AOL."), "SCRIPT",
197             __modem, NULL),
198        INT (0, NULL, "dial_retry", 3,
199             NULL, NULL,
200             __modem, check_natural),
201        INT (0, NULL, "retry_delay", 0,
202             NULL, NULL,
203             __modem, check_natural)
204    #endif /* WITH_MODEM */
205    
206    #ifdef WITH_TCPIP
207        /* CABLE SPECIFIC */
208        , STR (0, NULL, "aol_host", "AmericaOnline.aol.com",
209             NULL, NULL,
210             __cable, NULL),
211        INT (0, NULL, "aol_port", 5190,
212             NULL, NULL,
213             __cable, check_port)
214    #endif /* WITH_TCPIP */
215      };
216    
217    #undef STR
218    #undef BOOL
219    #undef INT
220      
221      memcpy(section_name, sections, sizeof(section_name));
222      memcpy(param, params, sizeof(param));
223    }
224    
225    
226  static void  static void
227  usage ()  usage ()
228  {  {
229    int s,i,j,len,ok;    int s, i, j, len, ok;
230      
231    /* FIXME: wow this function is very BIG */    /* FIXME: wow this function is very BIG */
232    printf ("Usage : %s [OPTIONS]\n"    printf (gettext ("Usage : %s [OPTIONS]\n"
233          "Operation modes :\n"                   "Operation modes :\n"
234          "  -h, --help                       print this help, then exit.\n"                   "  -h, --help                       print this help, then exit.\n"
235          "  -V, --version                    print version, then exit.\n",                   "  -V, --version                    print version, then exit.\n"),
236          program_name);            program_name);
237    for(s=0; s<__sect_end; s++)    for (s = 0; s < __sect_end; s++)
238      {      {
239        /*        /*
240         * determine if there is at least one element to print in         * determine if there is at least one element to print in
241         * this section         * this section
242         */         */
243        for(i=0, ok=0; i<PARAM_MAX && !ok; i++)        for (i = 0, ok = 0; i < PARAM_MAX && !ok; i++)
244          if( param[i].section == s &&          if (param[i].section == s &&
245            (param[i].shortopt != 0 || param[i].longopt != NULL))              (param[i].shortopt != 0 || param[i].longopt != NULL))
246          ok=1;            ok = 1;
247    
248        if(ok)        if (ok)
249          {          {
250          printf("\n%s:\n", section_name[s] );            printf ("\n%s:\n", section_name[s]);
251          for(i=0; i<PARAM_MAX; i++)            for (i = 0; i < PARAM_MAX; i++)
252            {              {
253              if( param[i].section == s &&                if (param[i].section == s &&
254                  (param[i].shortopt != 0 || param[i].longopt != NULL))                    (param[i].shortopt != 0 || param[i].longopt != NULL))
255                {                  {
256                  /* First indentation */                    /* First indentation */
257                  printf("  ");                    printf ("  ");
258                  len=2;                    len = 2;
259                  /* Put the short option if any */                    /* Put the short option if any */
260                  if(param[i].shortopt != 0)                    if (param[i].shortopt != 0)
261                  {                      {
262                    printf("-%c",param[i].shortopt);                        printf ("-%c", param[i].shortopt);
263                    if(param[i].longopt != NULL)                        if (param[i].longopt != NULL)
264                      printf(", ");                          printf (", ");
265                    else printf("  ");                        else
266                  }                          printf ("  ");
267                  else printf("    ");                      }
268                  len+=4;                    else
269                  /* Put the long option if any */                      printf ("    ");
270                  if(param[i].longopt != NULL)                    len += 4;
271                  {                    /* Put the long option if any */
272                    printf("--%s",param[i].longopt);                    if (param[i].longopt != NULL)
273                    len += 2 + strlen(param[i].longopt);                      {
274                    if(param[i].type==integer || param[i].type==string)                        printf ("--%s", param[i].longopt);
275                      {                        len += 2 + strlen (param[i].longopt);
276                        /* Put the parameter name */                        if (param[i].type == integer || param[i].type == string)
277                        printf("=");                          {
278                        len++;                            /* Put the parameter name */
279                        if(param[i].param_name != NULL)                            printf ("=");
280                          {                            len++;
281                          printf ("%s",param[i].param_name);                            if (param[i].param_name != NULL)
282                          len += strlen(param[i].param_name);                              {
283                          }                                printf ("%s", param[i].param_name);
284                        else                                len += strlen (param[i].param_name);
285                          {                              }
286                          if(param[i].type==integer)                            else
287                            {                              {
288                              printf("INTEGER");                                if (param[i].type == integer)
289                              len += 7;                                  {
290                            }                                    printf ("INTEGER");
291                          else                                    len += 7;
292                            {                                  }
293                              printf("STRING");                                else
294                              len += 6;                                  {
295                            }                                    printf ("STRING");
296                          }                                    len += 6;
297                      }                                  }
298                                          }
299                    /*                          }
300                     * now complete with white space so the description start  
301                     * at col 35                        /*
302                     */                         * now complete with white space so the description start
303                    for(j=0;len+j < 35;j++)                         * at col 35
304                      printf(" ");                         */
305                          for (j = 0; len + j < 35; j++)
306                    /* Put the description */                          printf (" ");
307                    if(param[i].descr != NULL)  
308                      printf("%s\n",param[i].descr);                        /* Put the description */
309                    else                        if (param[i].descr != NULL)
310                      printf("(no description)\n");                          printf ("%s\n", param[i].descr);
311                  }                        else
312                }                          printf ("(no description)\n");
313            }                      }
314                    }
315                }
316          }          }
317      }      }
318    printf("\n");    printf ("\n");
319    exit (0);    exit (0);
320  }  }
321    
# Line 348  static void Line 324  static void
324  version (void)  version (void)
325  {  {
326    printf ("%s (" PACKAGE ") v" VERSION "\n", program_name);    printf ("%s (" PACKAGE ") v" VERSION "\n", program_name);
327    printf ("Compilation options :\n");    printf (gettext ("Compilation options :\n"));
328  #ifdef WITH_MODEM  #ifdef WITH_MODEM
329    printf("WITH_MODEM ");    printf ("WITH_MODEM ");
330  #endif  #endif
331  #ifdef WITH_CABLE  #ifdef WITH_CABLE
332    printf("WITH_CABLE ");    printf ("WITH_CABLE ");
333  #endif  #endif
334  #ifdef WITH_DSL  #ifdef WITH_DSL
335    printf("WITH_DSL ");    printf ("WITH_DSL ");
336  #endif  #endif
337  #ifdef WITH_TCPIP  #ifdef WITH_TCPIP
338    printf("WITH_TCPIP ");    printf ("WITH_TCPIP ");
339  #endif  #endif
340  #ifdef WITH_TUN  #ifdef WITH_TUN
341    printf("WITH_TUN ");    printf ("WITH_TUN ");
342  #endif  #endif
343    printf("\n");    printf ("\n");
344    exit (0);    exit (0);
345  }  }
346    
# Line 500  parse_command_line (argc, argv) Line 476  parse_command_line (argc, argv)
476        default:        default:
477          if (!set_opt_param (c))          if (!set_opt_param (c))
478            {            {
479              fprintf (stderr, "Try `%s --help' for more information.\n",              fprintf (stderr, gettext ("Try `%s --help' for more information.\n"),
480                       program_name);                       program_name);
481              exit (1);              exit (1);
482            }            }
# Line 517  parse_command_line (argc, argv) Line 493  parse_command_line (argc, argv)
493  int  int
494  check_config (void)  check_config (void)
495  {  {
496    int good = 1,i;    int good = 1, i;
497      
498    debug(5, "Checking options:\n");    debug (5, "Checking options:\n");
499    for (i = 0; i < PARAM_MAX; i++)    for (i = 0; i < PARAM_MAX; i++)
500      switch(param[i].type)      switch (param[i].type)
501        {        {
502        case boolean:        case boolean:
503          if(param[i].defined)          if (param[i].defined)
504          {            {
505            if(PARAM_BOOLEAN(i) == true)              if (PARAM_BOOLEAN (i) == true)
506              debug(5, "  %s = true\n", param[i].name);                debug (5, "  %s = true\n", param[i].name);
507            else              else
508              debug(5, "  %s = false\n", param[i].name);                debug (5, "  %s = false\n", param[i].name);
509          }            }
510          else          else
511          {            {
512            if(PARAM_BOOLEAN(i) == true)              if (PARAM_BOOLEAN (i) == true)
513              debug(8, "  %s = true (default)\n", param[i].name);                debug (8, "  %s = true (default)\n", param[i].name);
514            else              else
515              debug(8, "  %s = false (default)\n", param[i].name);                debug (8, "  %s = false (default)\n", param[i].name);
516          }            }
517    
518          if(param[i].checkfn.check_boolean != NULL)          if (param[i].checkfn.check_boolean != NULL)
519          good &= param[i].checkfn.check_boolean (param[i].name,            good &= param[i].checkfn.check_boolean (param[i].name,
520                                          PARAM_BOOLEAN(i));                                                    PARAM_BOOLEAN (i));
521          break;          break;
522        case integer:        case integer:
523          if(param[i].defined)          if (param[i].defined)
524          debug(5, "  %s = %d\n", param[i].name, PARAM_INTEGER(i));            debug (5, "  %s = %d\n", param[i].name, PARAM_INTEGER (i));
525          else          else
526          debug(8, "  %s = %d (default)\n", param[i].name, PARAM_INTEGER(i));            debug (8, "  %s = %d (default)\n", param[i].name,
527                     PARAM_INTEGER (i));
528    
529          if(param[i].checkfn.check_integer != NULL)          if (param[i].checkfn.check_integer != NULL)
530          good &= param[i].checkfn.check_integer (param[i].name,            good &= param[i].checkfn.check_integer (param[i].name,
531                                          PARAM_INTEGER(i));                                                    PARAM_INTEGER (i));
532          break;          break;
533        case string:        case string:
534          if(param[i].defined)          if (param[i].defined)
535          {            {
536            if(PARAM_STRING(i) != NULL)              if (PARAM_STRING (i) != NULL)
537              {                {
538                if(i != __screen_name)                  if (i != __screen_name)
539                  debug(5, "  %s = %s\n", param[i].name, PARAM_STRING(i));                    debug (5, "  %s = %s\n", param[i].name, PARAM_STRING (i));
540                else                  else
541                  debug(5, "  %s = (hidden)\n", param[i].name);                    debug (5, "  %s = (hidden)\n", param[i].name);
542              }                }
543            else              else
544              debug(5, "  %s = (undefined)\n", param[i].name);                debug (5, "  %s = (undefined)\n", param[i].name);
545          }            }
546          else          else
547          debug(8, "  %s = %s (default)\n", param[i].name,            debug (8, "  %s = %s (default)\n", param[i].name,
548                (PARAM_STRING(i)==NULL)?"(undefined)":PARAM_STRING(i));                   (PARAM_STRING (i) ==
549          if(param[i].checkfn.check_string != NULL)                    NULL) ? "(undefined)" : PARAM_STRING (i));
550          good &= param[i].checkfn.check_string (param[i].name,          if (param[i].checkfn.check_string != NULL)
551                                           PARAM_STRING(i));            good &= param[i].checkfn.check_string (param[i].name,
552                                                     PARAM_STRING (i));
553          break;          break;
554          }        }
555    debug(5,"\n");    debug (5, "\n");
556      
557    return good;    return good;
558  }  }
559    
# Line 586  int Line 564  int
564  parse_config ()  parse_config ()
565  {  {
566    if (!parse_config_file (PARAM_CONFIG_FILE))    if (!parse_config_file (PARAM_CONFIG_FILE))
567      debug (5,"Unable to open configuration file %s.\n",PARAM_CONFIG_FILE);      debug (5, "Unable to open configuration file %s.\n", PARAM_CONFIG_FILE);
568    
569    debug (5,"\n");    debug (5, "\n");
570    return 1;    return 1;
571  }  }
572    
# Line 604  parse_config_file (filename) Line 582  parse_config_file (filename)
582    f = fopen (filename, "r");    f = fopen (filename, "r");
583    if (f == NULL)    if (f == NULL)
584      {      {
585        debug (6,"%s: %s(%d)\n",filename, strerror(errno), errno);        debug (6, "%s: %s(%d)\n", filename, strerror (errno), errno);
586        return 0;        return 0;
587      }      }
588    else    else
589      debug(3, "Parsing config file: %s\n", filename);      debug (3, "Parsing config file: %s\n", filename);
590    while (!feof (f))    while (!feof (f))
591      {      {
592        lineno++;        lineno++;
# Line 617  parse_config_file (filename) Line 595  parse_config_file (filename)
595        strip_comments (line);        strip_comments (line);
596        trim (line);        trim (line);
597        if (strlen (line) > 0 && !tokenize_line (line, &name, &value))        if (strlen (line) > 0 && !tokenize_line (line, &name, &value))
598          log (LOG_WARNING, "%s:%d bad line format\n", filename, lineno);          log (LOG_WARNING, gettext ("%s:%d bad line format\n"), filename, lineno);
599        else        else
600          {          {
601          if (strlen (line) > 0) {            if (strlen (line) > 0)
602            for (i = 0, found = 0; i < PARAM_MAX && !found; i++)              {
603              found=try_param (&param[i], filename, lineno, name, value);                for (i = 0, found = 0; i < PARAM_MAX && !found; i++)
604            if(!found)                  found = try_param (&param[i], filename, lineno, name, value);
605              log (LOG_WARNING, "%s:%d unrecognized option - %s\n",                if (!found)
606                   filename, lineno, name);                  log (LOG_WARNING, gettext ("%s:%d unrecognized option - %s\n"),
607          }                       filename, lineno, name);
608                }
609          }          }
610      }      }
611    fclose(f);    fclose (f);
612    return 1;    return 1;
613  }  }
614    
# Line 644  try_param (param, filename, lineno, name Line 623  try_param (param, filename, lineno, name
623    
624    if (param->name && !strcmp (name, param->name))    if (param->name && !strcmp (name, param->name))
625      {      {
626        if (param->defined) return 1;        if (param->defined)
627            return 1;
628        else        else
629          {          {
630          switch (param->type)            switch (param->type)
631            {              {
632            case boolean:              case boolean:
633              if (get_boolean (&param->value.boolean, value))                if (get_boolean (&param->value.boolean, value))
634                param->defined = true;                  param->defined = true;
635              else                else
636                log (LOG_WARNING, "%s:%d bad boolean value\n", filename, lineno);                  log (LOG_WARNING, gettext ("%s:%d bad boolean value\n"), filename,
637              break;                       lineno);
638            case string:                break;
639              if (get_string (&param->value.string, value))              case string:
640                {                if (get_string (&param->value.string, value))
641                  param->defined = true;                  {
642                  param->allocated = true;                    param->defined = true;
643                }                    param->allocated = true;
644              else                  }
645                {                else
646                  log (LOG_CRIT, "%s:%d not enough memory to get the parameter\n",                  {
647                     filename, lineno);                    log (LOG_CRIT,
648                  exit(1);                         gettext ("%s:%d not enough memory to get the parameter\n"),
649                }                         filename, lineno);
650              break;                    exit (1);
651            case integer:                  }
652              if (get_integer (&param->value.integer, value))                break;
653                param->defined = true;              case integer:
654              else                if (get_integer (&param->value.integer, value))
655                log (LOG_WARNING, "%s:%d bad integer value\n", filename, lineno);                  param->defined = true;
656              break;                else
657            }                  log (LOG_WARNING, gettext ("%s:%d bad integer value\n"), filename,
658          return 1;                       lineno);
659                  break;
660                }
661              return 1;
662          }          }
663      }      }
664    else    else
665      return 0;      return 0;
666  }  }
667    

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26