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