aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-04 16:48:26 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-04 16:48:26 +0000
commitbe0ed3d0b94489e08cc9280f65075c42ba80bf8c (patch)
treefb291c675efaad4088d51132c4835913ba2a2eb4 /libbb
parent6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e (diff)
downloadbusybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.gz
busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.bz2
busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.zip
use updated bb_getopt_ulflags() for ps applet
Diffstat (limited to 'libbb')
-rw-r--r--libbb/getopt_ulflags.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
index 58077c55f..8c03214a9 100644
--- a/libbb/getopt_ulflags.c
+++ b/libbb/getopt_ulflags.c
@@ -110,6 +110,22 @@ 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:
114 if w is given once, GNU ps sets the width to 132,
115 if w is given more than once, it is "unlimited"
116
117 int w_counter = 0;
118 bb_opt_complementally = "ww";
119 flags = bb_getopt_ulflags(argc, argv, "w", &w_counter);
120
121 if((flags & 1))
122 width = (w_counter == 1) ? 132 : INT_MAX;
123 else
124 get_terminal_width(...&width...);
125
126 w_counter - have counter -w usaging, must set int pointer
127 to bb_getopt_ulflags() after all other requires
128
113Special characters: 129Special characters:
114 130
115 "-" A dash between two options causes the second of the two 131 "-" A dash between two options causes the second of the two
@@ -188,6 +204,7 @@ typedef struct {
188 unsigned long switch_off; 204 unsigned long switch_off;
189 unsigned long incongruously; 205 unsigned long incongruously;
190 void **optarg; /* char **optarg or llist_t **optarg */ 206 void **optarg; /* char **optarg or llist_t **optarg */
207 int *counter;
191} t_complementally; 208} t_complementally;
192 209
193/* You can set bb_applet_long_options for parse called long options */ 210/* You can set bb_applet_long_options for parse called long options */
@@ -221,7 +238,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
221 c = 0; 238 c = 0;
222 on_off = complementally; 239 on_off = complementally;
223 for (; *s; s++) { 240 for (; *s; s++) {
224 if(c >= (sizeof(flags)*8)) 241 if(c >= (int)(sizeof(flags)*8))
225 break; 242 break;
226 on_off->opt = *s; 243 on_off->opt = *s;
227 on_off->switch_on = (1 << c); 244 on_off->switch_on = (1 << c);
@@ -229,6 +246,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
229 on_off->switch_off = 0; 246 on_off->switch_off = 0;
230 on_off->incongruously = 0; 247 on_off->incongruously = 0;
231 on_off->optarg = NULL; 248 on_off->optarg = NULL;
249 on_off->counter = NULL;
232 if (s[1] == ':') { 250 if (s[1] == ':') {
233 on_off->optarg = va_arg (p, void **); 251 on_off->optarg = va_arg (p, void **);
234 do 252 do
@@ -245,13 +263,14 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
245 if(on_off->opt == l_o->val) 263 if(on_off->opt == l_o->val)
246 break; 264 break;
247 if(on_off->opt == 0) { 265 if(on_off->opt == 0) {
248 if(c >= (sizeof(flags)*8)) 266 if(c >= (int)(sizeof(flags)*8))
249 break; 267 break;
250 on_off->opt = l_o->val; 268 on_off->opt = l_o->val;
251 on_off->switch_on = (1 << c); 269 on_off->switch_on = (1 << c);
252 on_off->list_flg = 0; 270 on_off->list_flg = 0;
253 on_off->switch_off = 0; 271 on_off->switch_off = 0;
254 on_off->incongruously = 0; 272 on_off->incongruously = 0;
273 on_off->counter = NULL;
255 if(l_o->has_arg != no_argument) 274 if(l_o->has_arg != no_argument)
256 on_off->optarg = va_arg (p, void **); 275 on_off->optarg = va_arg (p, void **);
257 else 276 else
@@ -290,7 +309,10 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
290 pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously); 309 pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously);
291 for (on_off = complementally; on_off->opt; on_off++) 310 for (on_off = complementally; on_off->opt; on_off++)
292 if (on_off->opt == *s) { 311 if (on_off->opt == *s) {
293 *pair_switch |= on_off->switch_on; 312 if(pair_switch == &(on_off->switch_on))
313 on_off->counter = va_arg (p, int *);
314 else
315 *pair_switch |= on_off->switch_on;
294 break; 316 break;
295 } 317 }
296 } 318 }
@@ -315,6 +337,8 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
315 flags &= ~(on_off->switch_off ^ trigger); 337 flags &= ~(on_off->switch_off ^ trigger);
316 flags |= on_off->switch_on ^ trigger; 338 flags |= on_off->switch_on ^ trigger;
317 flags ^= trigger; 339 flags ^= trigger;
340 if(on_off->counter)
341 (*(on_off->counter))++;
318 if(on_off->list_flg) { 342 if(on_off->list_flg) {
319 *(llist_t **)(on_off->optarg) = 343 *(llist_t **)(on_off->optarg) =
320 llist_add_to(*(llist_t **)(on_off->optarg), optarg); 344 llist_add_to(*(llist_t **)(on_off->optarg), optarg);