aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-05 10:52:47 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-05 10:52:47 +0000
commit35939d93783230998439848b2798865c598723e2 (patch)
tree188f195a595c4f494fdc1d8d27da67a2e5b42b5d /libbb
parent7abe7098676aeb0654ef0159f589484b4cf520e8 (diff)
downloadbusybox-w32-35939d93783230998439848b2798865c598723e2.tar.gz
busybox-w32-35939d93783230998439848b2798865c598723e2.tar.bz2
busybox-w32-35939d93783230998439848b2798865c598723e2.zip
update bb_getopt_ulflags special for 'ps' applet, usaging '-' as first group char from bb_opt_complementally is new feature: set argv is options;
use new bb_getopt_ulflags for ps # define terminal_width 80->79 for unwide use stdout file descriptor for get_terminal_width_height. (its must)
Diffstat (limited to 'libbb')
-rw-r--r--libbb/getopt_ulflags.c56
1 files changed, 42 insertions, 14 deletions
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
index 8c03214a9..410f4d57d 100644
--- a/libbb/getopt_ulflags.c
+++ b/libbb/getopt_ulflags.c
@@ -110,7 +110,7 @@ const char *bb_opt_complementally
110 bb_getopt_ulflags's return value will be as if "-a -b -c" were 110 bb_getopt_ulflags's return value will be as if "-a -b -c" were
111 found. 111 found.
112 112
113 "ww" Option have int counter usaging. For example ps applet: 113 "ww" Double option have int counter usaging. For example ps applet:
114 if w is given once, GNU ps sets the width to 132, 114 if w is given once, GNU ps sets the width to 132,
115 if w is given more than once, it is "unlimited" 115 if w is given more than once, it is "unlimited"
116 116
@@ -175,6 +175,9 @@ Special characters:
175 "!" If previous point set BB_GETOPT_ERROR, don`t return and call 175 "!" If previous point set BB_GETOPT_ERROR, don`t return and call
176 previous example internally 176 previous example internally
177 177
178 "-" A minus as one char in bb_opt_complementally group means that
179 convert the arguments as option, specail for "ps" applet.
180
178 "*" A star after a char in bb_opt_complementally means that the 181 "*" A star after a char in bb_opt_complementally means that the
179 option can occur multiple times: 182 option can occur multiple times:
180 183
@@ -227,6 +230,9 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
227 va_list p; 230 va_list p;
228 const struct option *l_o; 231 const struct option *l_o;
229 char flg_show_usage_if_error = 0; 232 char flg_show_usage_if_error = 0;
233 char flg_argv_is_opts = 0;
234 unsigned long trigger;
235 char **pargv = NULL;
230 236
231 va_start (p, applet_opts); 237 va_start (p, applet_opts);
232 238
@@ -294,6 +300,10 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
294 flg_show_usage_if_error = '!'; 300 flg_show_usage_if_error = '!';
295 continue; 301 continue;
296 } 302 }
303 if(*s == '-') {
304 flg_argv_is_opts = '-';
305 continue;
306 }
297 for (on_off = complementally; on_off->opt; on_off++) 307 for (on_off = complementally; on_off->opt; on_off++)
298 if (on_off->opt == *s) 308 if (on_off->opt == *s)
299 break; 309 break;
@@ -304,17 +314,17 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
304 } else if(*s == '*') { 314 } else if(*s == '*') {
305 pair->list_flg++; 315 pair->list_flg++;
306 } else { 316 } else {
307 unsigned long *pair_switch = &(pair->switch_on); 317 unsigned long *pair_switch = &(pair->switch_on);
308 if(c) 318 if(c)
309 pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously); 319 pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously);
310 for (on_off = complementally; on_off->opt; on_off++) 320 for (on_off = complementally; on_off->opt; on_off++)
311 if (on_off->opt == *s) { 321 if (on_off->opt == *s) {
312 if(pair_switch == &(on_off->switch_on)) 322 if(pair_switch == &(on_off->switch_on))
313 on_off->counter = va_arg (p, int *); 323 on_off->counter = va_arg (p, int *);
314 else 324 else
315 *pair_switch |= on_off->switch_on; 325 *pair_switch |= on_off->switch_on;
316 break; 326 break;
317 } 327 }
318 } 328 }
319 } 329 }
320 s--; 330 s--;
@@ -322,8 +332,8 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
322 332
323 while ((c = getopt_long (argc, argv, applet_opts, 333 while ((c = getopt_long (argc, argv, applet_opts,
324 bb_applet_long_options, NULL)) > 0) { 334 bb_applet_long_options, NULL)) > 0) {
325 unsigned long trigger;
326 335
336loop_arg_is_opt:
327 for (on_off = complementally; on_off->opt != c; on_off++) { 337 for (on_off = complementally; on_off->opt != c; on_off++) {
328 if(!on_off->opt) 338 if(!on_off->opt)
329 bb_show_usage (); 339 bb_show_usage ();
@@ -341,10 +351,28 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
341 (*(on_off->counter))++; 351 (*(on_off->counter))++;
342 if(on_off->list_flg) { 352 if(on_off->list_flg) {
343 *(llist_t **)(on_off->optarg) = 353 *(llist_t **)(on_off->optarg) =
344 llist_add_to(*(llist_t **)(on_off->optarg), optarg); 354 llist_add_to(*(llist_t **)(on_off->optarg), optarg);
345 } else if (on_off->optarg) { 355 } else if (on_off->optarg) {
346 *(char **)(on_off->optarg) = optarg; 356 *(char **)(on_off->optarg) = optarg;
347 } 357 }
358 if(flg_argv_is_opts == 'p')
359 break;
360 }
361 if(flg_argv_is_opts) {
362 /* process argv is option, for example "ps" applet */
363 if(flg_argv_is_opts == '-') {
364 flg_argv_is_opts = 'p';
365 pargv = argv + optind;
366 }
367 while(*pargv) {
368 c = **pargv;
369 if(c == '\0') {
370 pargv++;
371 } else {
372 (*pargv)++;
373 goto loop_arg_is_opt;
374 }
375 }
348 } 376 }
349 377
350 return flags; 378 return flags;