Fix bug in '-d'
[kai/samba.git] / source3 / lib / popt_common.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Common popt routines
4
5    Copyright (C) Tim Potter 2001,2002
6    Copyright (C) Jelmer Vernooij 2002
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 /* Handle command line options:
26  *              -d,--debuglevel 
27  *              -s,--configfile 
28  *              -O,--socket-options 
29  */
30
31 extern pstring user_socket_options;
32 extern BOOL AllowDebugChange;
33 extern pstring global_myname;
34
35 static void popt_common_callback(poptContext con, 
36                            enum poptCallbackReason reason,
37                            const struct poptOption *opt,
38                            const char *arg, const void *data)
39 {
40         switch(opt->val) {
41         case 'd':
42                 if (arg) {
43                         debug_parse_levels(arg);
44                         AllowDebugChange = False;
45                 }
46                 break;
47
48         case 'V':
49                 printf( "Version %s\n", VERSION );
50                 exit(0);
51                 break;
52
53         case 'O':
54                 pstrcpy(user_socket_options,arg);
55                 break;
56
57         case 's':
58                 pstrcpy(dyn_CONFIGFILE, arg);
59                 break;
60
61         case 'n':
62                 pstrcpy(global_myname,arg);
63                 strupper(global_myname);
64                 break;
65         }
66 }
67
68 struct poptOption popt_common_debug[] = {
69         { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
70         { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", 
71           "DEBUGLEVEL" },
72         { 0 }
73 };
74
75 struct poptOption popt_common_configfile[] = {
76         { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
77         { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file" },
78         { 0 }
79 };
80
81 struct poptOption popt_common_socket_options[] = {
82         { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
83         {"socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use" },
84         { 0 }
85 };
86
87 struct poptOption popt_common_version[] = {
88         { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
89         {"version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
90         { 0 }
91 };
92
93 struct poptOption popt_common_netbios_name[] = {
94         { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
95         {"netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name"},
96         { 0 }
97 };