diff options
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 |
commit | be0ed3d0b94489e08cc9280f65075c42ba80bf8c (patch) | |
tree | fb291c675efaad4088d51132c4835913ba2a2eb4 | |
parent | 6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e (diff) | |
download | busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.gz busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.bz2 busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.zip |
use updated bb_getopt_ulflags() for ps applet
-rw-r--r-- | libbb/getopt_ulflags.c | 30 | ||||
-rw-r--r-- | procps/ps.c | 55 |
2 files changed, 58 insertions, 27 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 | |||
113 | Special characters: | 129 | Special 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); |
diff --git a/procps/ps.c b/procps/ps.c index a610bb218..a0081c839 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -22,42 +22,50 @@ | |||
22 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ | 22 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #define TERMINAL_WIDTH 80 | ||
26 | |||
27 | extern int ps_main(int argc, char **argv) | 25 | extern int ps_main(int argc, char **argv) |
28 | { | 26 | { |
29 | procps_status_t * p; | 27 | procps_status_t * p; |
30 | int i, len, terminal_width; | 28 | int i, len; |
31 | #if ENABLE_SELINUX | 29 | #if ENABLE_SELINUX |
32 | int use_selinux = 0; | 30 | int use_selinux = 0; |
33 | security_context_t sid=NULL; | 31 | security_context_t sid=NULL; |
34 | #endif | 32 | #endif |
35 | 33 | #if ENABLE_FEATURE_PS_WIDE | |
36 | get_terminal_width_height(0, &terminal_width, NULL); | 34 | int terminal_width; |
35 | int w_count = 0; | ||
36 | #else | ||
37 | # define terminal_width 80 | ||
38 | #endif | ||
37 | 39 | ||
38 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX | 40 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX |
39 | /* handle arguments */ | 41 | /* handle arguments */ |
40 | /* bb_getopt_ulflags(argc, argv,) would force a leading dash */ | 42 | #if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX |
41 | for (len = 1; len < argc; len++) { | 43 | bb_opt_complementally="ww"; |
42 | char *c = argv[len]; | 44 | i = bb_getopt_ulflags(argc, argv, "wc", &w_count); |
43 | while (*c) { | 45 | #elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX |
44 | if (ENABLE_FEATURE_PS_WIDE && *c == 'w') | 46 | bb_opt_complementally="ww"; |
45 | /* if w is given once, GNU ps sets the width to 132, | 47 | i = bb_getopt_ulflags(argc, argv, "w", &w_count); |
46 | * if w is given more than once, it is "unlimited" | 48 | #else /* !ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX */ |
47 | */ | 49 | i = bb_getopt_ulflags(argc, argv, "c"); |
48 | terminal_width = | ||
49 | (terminal_width==TERMINAL_WIDTH) ? 132 : INT_MAX; | ||
50 | #if ENABLE_SELINUX | ||
51 | if (*c == 'c' && is_selinux_enabled()) | ||
52 | use_selinux = 1; | ||
53 | #endif | 50 | #endif |
54 | c++; | 51 | #if ENABLE_FEATURE_PS_WIDE |
55 | } | 52 | /* if w is given once, GNU ps sets the width to 132, |
53 | * if w is given more than once, it is "unlimited" | ||
54 | */ | ||
55 | if((i & 1)) { | ||
56 | terminal_width = (w_count==1) ? 132 : INT_MAX; | ||
57 | } else { | ||
58 | get_terminal_width_height(0, &terminal_width, NULL); | ||
59 | /* Go one less... */ | ||
60 | terminal_width--; | ||
56 | } | 61 | } |
57 | #endif | 62 | #endif |
63 | #if ENABLE_SELINUX | ||
64 | if ((i & 2) && is_selinux_enabled()) | ||
65 | use_selinux = 1; | ||
66 | #endif | ||
67 | #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ | ||
58 | 68 | ||
59 | /* Go one less... */ | ||
60 | terminal_width--; | ||
61 | #if ENABLE_SELINUX | 69 | #if ENABLE_SELINUX |
62 | if (use_selinux) | 70 | if (use_selinux) |
63 | printf(" PID Context Stat Command\n"); | 71 | printf(" PID Context Stat Command\n"); |
@@ -68,7 +76,7 @@ extern int ps_main(int argc, char **argv) | |||
68 | while ((p = procps_scan(1)) != 0) { | 76 | while ((p = procps_scan(1)) != 0) { |
69 | char *namecmd = p->cmd; | 77 | char *namecmd = p->cmd; |
70 | #if ENABLE_SELINUX | 78 | #if ENABLE_SELINUX |
71 | if (use_selinux ) | 79 | if (use_selinux) |
72 | { | 80 | { |
73 | char sbuf[128]; | 81 | char sbuf[128]; |
74 | len = sizeof(sbuf); | 82 | len = sizeof(sbuf); |
@@ -118,4 +126,3 @@ extern int ps_main(int argc, char **argv) | |||
118 | } | 126 | } |
119 | return EXIT_SUCCESS; | 127 | return EXIT_SUCCESS; |
120 | } | 128 | } |
121 | |||