diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-10 23:03:30 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-10 23:03:30 +0000 |
commit | 80d14beae9ebe64d3be1e6c2771f292977cf6d2c (patch) | |
tree | d0dd803ca8b6c70521895fd5ec71ef532861b8e4 /util-linux | |
parent | 89054964443b5cb14cba673b86306f534810404a (diff) | |
download | busybox-w32-80d14beae9ebe64d3be1e6c2771f292977cf6d2c.tar.gz busybox-w32-80d14beae9ebe64d3be1e6c2771f292977cf6d2c.tar.bz2 busybox-w32-80d14beae9ebe64d3be1e6c2771f292977cf6d2c.zip |
Rename two config options:
FEATURE_SH_STANDALONE_SHELL => FEATURE_SH_STANDALONE
FEATURE_EXEC_PREFER_APPLETS => FEATURE_PREFER_APPLETS
Make SH_STANDALONE depend on PREFER_APPLETS.
getopt.c: more randomconfig-induced fixes
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/getopt.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index 85a1d4410..68e69de5c 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -38,8 +38,10 @@ | |||
38 | mode */ | 38 | mode */ |
39 | enum { | 39 | enum { |
40 | NON_OPT = 1, | 40 | NON_OPT = 1, |
41 | #if ENABLE_GETOPT_LONG | ||
41 | /* LONG_OPT is the code that is returned when a long option is found. */ | 42 | /* LONG_OPT is the code that is returned when a long option is found. */ |
42 | LONG_OPT = 2 | 43 | LONG_OPT = 2 |
44 | #endif | ||
43 | }; | 45 | }; |
44 | 46 | ||
45 | /* For finding activated option flags. Must match getopt32 call! */ | 47 | /* For finding activated option flags. Must match getopt32 call! */ |
@@ -51,8 +53,10 @@ enum { | |||
51 | OPT_s = 0x10, // -s | 53 | OPT_s = 0x10, // -s |
52 | OPT_T = 0x20, // -T | 54 | OPT_T = 0x20, // -T |
53 | OPT_u = 0x40, // -u | 55 | OPT_u = 0x40, // -u |
56 | #if ENABLE_GETOPT_LONG | ||
54 | OPT_a = 0x80, // -a | 57 | OPT_a = 0x80, // -a |
55 | OPT_l = 0x100, // -l | 58 | OPT_l = 0x100, // -l |
59 | #endif | ||
56 | SHELL_IS_TCSH = 0x8000, /* hijack this bit for other purposes */ | 60 | SHELL_IS_TCSH = 0x8000, /* hijack this bit for other purposes */ |
57 | }; | 61 | }; |
58 | 62 | ||
@@ -137,31 +141,45 @@ static const char *normalize(const char *arg) | |||
137 | * optstr must contain the short options, and longopts the long options. | 141 | * optstr must contain the short options, and longopts the long options. |
138 | * Other settings are found in global variables. | 142 | * Other settings are found in global variables. |
139 | */ | 143 | */ |
140 | static int generate_output(char * argv[],int argc,const char *optstr, | 144 | #if !ENABLE_GETOPT_LONG |
141 | const struct option *longopts) | 145 | #define generate_output(argv,argc,optstr,longopts) generate_output(argv,argc,optstr) |
146 | #endif | ||
147 | static int generate_output(char **argv, int argc, const char *optstr, const struct option *longopts) | ||
142 | { | 148 | { |
143 | int exit_code = 0; /* We assume everything will be OK */ | 149 | int exit_code = 0; /* We assume everything will be OK */ |
144 | unsigned opt; | 150 | unsigned opt; |
151 | #if ENABLE_GETOPT_LONG | ||
145 | int longindex; | 152 | int longindex; |
153 | #endif | ||
146 | const char *charptr; | 154 | const char *charptr; |
147 | 155 | ||
148 | if (quiet_errors) /* No error reporting from getopt(3) */ | 156 | if (quiet_errors) /* No error reporting from getopt(3) */ |
149 | opterr = 0; | 157 | opterr = 0; |
150 | optind = 0; /* Reset getopt(3) */ | 158 | optind = 0; /* Reset getopt(3) */ |
151 | 159 | ||
152 | while ((opt = (alternative ? | 160 | while (1) { |
153 | getopt_long_only(argc,argv,optstr,longopts,&longindex) : | 161 | opt = |
154 | getopt_long(argc,argv,optstr,longopts,&longindex))) | 162 | #if ENABLE_GETOPT_LONG |
155 | != EOF) | 163 | alternative ? |
164 | getopt_long_only(argc, argv, optstr, longopts, &longindex) : | ||
165 | getopt_long(argc, argv, optstr, longopts, &longindex); | ||
166 | #else | ||
167 | getopt(argc, argv, optstr); | ||
168 | #endif | ||
169 | if (opt == EOF) | ||
170 | break; | ||
156 | if (opt == '?' || opt == ':' ) | 171 | if (opt == '?' || opt == ':' ) |
157 | exit_code = 1; | 172 | exit_code = 1; |
158 | else if (!quiet_output) { | 173 | else if (!quiet_output) { |
174 | #if ENABLE_GETOPT_LONG | ||
159 | if (opt == LONG_OPT) { | 175 | if (opt == LONG_OPT) { |
160 | printf(" --%s", longopts[longindex].name); | 176 | printf(" --%s", longopts[longindex].name); |
161 | if (longopts[longindex].has_arg) | 177 | if (longopts[longindex].has_arg) |
162 | printf(" %s", | 178 | printf(" %s", |
163 | normalize(optarg ? optarg : "")); | 179 | normalize(optarg ? optarg : "")); |
164 | } else if (opt == NON_OPT) | 180 | } else |
181 | #endif | ||
182 | if (opt == NON_OPT) | ||
165 | printf(" %s", normalize(optarg)); | 183 | printf(" %s", normalize(optarg)); |
166 | else { | 184 | else { |
167 | printf(" -%c", opt); | 185 | printf(" -%c", opt); |
@@ -171,6 +189,7 @@ static int generate_output(char * argv[],int argc,const char *optstr, | |||
171 | normalize(optarg ? optarg : "")); | 189 | normalize(optarg ? optarg : "")); |
172 | } | 190 | } |
173 | } | 191 | } |
192 | } | ||
174 | 193 | ||
175 | if (!quiet_output) { | 194 | if (!quiet_output) { |
176 | printf(" --"); | 195 | printf(" --"); |
@@ -181,6 +200,7 @@ static int generate_output(char * argv[],int argc,const char *optstr, | |||
181 | return exit_code; | 200 | return exit_code; |
182 | } | 201 | } |
183 | 202 | ||
203 | #if ENABLE_GETOPT_LONG | ||
184 | /* | 204 | /* |
185 | * Register several long options. options is a string of long options, | 205 | * Register several long options. options is a string of long options, |
186 | * separated by commas or whitespace. | 206 | * separated by commas or whitespace. |
@@ -224,6 +244,7 @@ static struct option *add_long_options(struct option *long_options, char *option | |||
224 | } | 244 | } |
225 | return long_options; | 245 | return long_options; |
226 | } | 246 | } |
247 | #endif | ||
227 | 248 | ||
228 | static void set_shell(const char *new_shell) | 249 | static void set_shell(const char *new_shell) |
229 | { | 250 | { |
@@ -262,13 +283,13 @@ static const struct option longopts[] = { | |||
262 | int getopt_main(int argc, char *argv[]); | 283 | int getopt_main(int argc, char *argv[]); |
263 | int getopt_main(int argc, char *argv[]) | 284 | int getopt_main(int argc, char *argv[]) |
264 | { | 285 | { |
265 | struct option *long_options = NULL; | ||
266 | char *optstr = NULL; | 286 | char *optstr = NULL; |
267 | char *name = NULL; | 287 | char *name = NULL; |
268 | unsigned opt; | 288 | unsigned opt; |
269 | const char *compatible; | 289 | const char *compatible; |
270 | char *s_arg; | 290 | char *s_arg; |
271 | #if ENABLE_GETOPT_LONG | 291 | #if ENABLE_GETOPT_LONG |
292 | struct option *long_options = NULL; | ||
272 | llist_t *l_arg = NULL; | 293 | llist_t *l_arg = NULL; |
273 | #endif | 294 | #endif |
274 | 295 | ||