use updated bb_getopt_ulflags() for ps applet
This commit is contained in:
parent
6d6a40cc4b
commit
be0ed3d0b9
@ -110,6 +110,22 @@ const char *bb_opt_complementally
|
|||||||
bb_getopt_ulflags's return value will be as if "-a -b -c" were
|
bb_getopt_ulflags's return value will be as if "-a -b -c" were
|
||||||
found.
|
found.
|
||||||
|
|
||||||
|
"ww" Option have int counter usaging. For example ps applet:
|
||||||
|
if w is given once, GNU ps sets the width to 132,
|
||||||
|
if w is given more than once, it is "unlimited"
|
||||||
|
|
||||||
|
int w_counter = 0;
|
||||||
|
bb_opt_complementally = "ww";
|
||||||
|
flags = bb_getopt_ulflags(argc, argv, "w", &w_counter);
|
||||||
|
|
||||||
|
if((flags & 1))
|
||||||
|
width = (w_counter == 1) ? 132 : INT_MAX;
|
||||||
|
else
|
||||||
|
get_terminal_width(...&width...);
|
||||||
|
|
||||||
|
w_counter - have counter -w usaging, must set int pointer
|
||||||
|
to bb_getopt_ulflags() after all other requires
|
||||||
|
|
||||||
Special characters:
|
Special characters:
|
||||||
|
|
||||||
"-" A dash between two options causes the second of the two
|
"-" A dash between two options causes the second of the two
|
||||||
@ -188,6 +204,7 @@ typedef struct {
|
|||||||
unsigned long switch_off;
|
unsigned long switch_off;
|
||||||
unsigned long incongruously;
|
unsigned long incongruously;
|
||||||
void **optarg; /* char **optarg or llist_t **optarg */
|
void **optarg; /* char **optarg or llist_t **optarg */
|
||||||
|
int *counter;
|
||||||
} t_complementally;
|
} t_complementally;
|
||||||
|
|
||||||
/* You can set bb_applet_long_options for parse called long options */
|
/* 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, ...)
|
|||||||
c = 0;
|
c = 0;
|
||||||
on_off = complementally;
|
on_off = complementally;
|
||||||
for (; *s; s++) {
|
for (; *s; s++) {
|
||||||
if(c >= (sizeof(flags)*8))
|
if(c >= (int)(sizeof(flags)*8))
|
||||||
break;
|
break;
|
||||||
on_off->opt = *s;
|
on_off->opt = *s;
|
||||||
on_off->switch_on = (1 << c);
|
on_off->switch_on = (1 << c);
|
||||||
@ -229,6 +246,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
on_off->switch_off = 0;
|
on_off->switch_off = 0;
|
||||||
on_off->incongruously = 0;
|
on_off->incongruously = 0;
|
||||||
on_off->optarg = NULL;
|
on_off->optarg = NULL;
|
||||||
|
on_off->counter = NULL;
|
||||||
if (s[1] == ':') {
|
if (s[1] == ':') {
|
||||||
on_off->optarg = va_arg (p, void **);
|
on_off->optarg = va_arg (p, void **);
|
||||||
do
|
do
|
||||||
@ -245,13 +263,14 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
if(on_off->opt == l_o->val)
|
if(on_off->opt == l_o->val)
|
||||||
break;
|
break;
|
||||||
if(on_off->opt == 0) {
|
if(on_off->opt == 0) {
|
||||||
if(c >= (sizeof(flags)*8))
|
if(c >= (int)(sizeof(flags)*8))
|
||||||
break;
|
break;
|
||||||
on_off->opt = l_o->val;
|
on_off->opt = l_o->val;
|
||||||
on_off->switch_on = (1 << c);
|
on_off->switch_on = (1 << c);
|
||||||
on_off->list_flg = 0;
|
on_off->list_flg = 0;
|
||||||
on_off->switch_off = 0;
|
on_off->switch_off = 0;
|
||||||
on_off->incongruously = 0;
|
on_off->incongruously = 0;
|
||||||
|
on_off->counter = NULL;
|
||||||
if(l_o->has_arg != no_argument)
|
if(l_o->has_arg != no_argument)
|
||||||
on_off->optarg = va_arg (p, void **);
|
on_off->optarg = va_arg (p, void **);
|
||||||
else
|
else
|
||||||
@ -290,6 +309,9 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously);
|
pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously);
|
||||||
for (on_off = complementally; on_off->opt; on_off++)
|
for (on_off = complementally; on_off->opt; on_off++)
|
||||||
if (on_off->opt == *s) {
|
if (on_off->opt == *s) {
|
||||||
|
if(pair_switch == &(on_off->switch_on))
|
||||||
|
on_off->counter = va_arg (p, int *);
|
||||||
|
else
|
||||||
*pair_switch |= on_off->switch_on;
|
*pair_switch |= on_off->switch_on;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -315,6 +337,8 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
flags &= ~(on_off->switch_off ^ trigger);
|
flags &= ~(on_off->switch_off ^ trigger);
|
||||||
flags |= on_off->switch_on ^ trigger;
|
flags |= on_off->switch_on ^ trigger;
|
||||||
flags ^= trigger;
|
flags ^= trigger;
|
||||||
|
if(on_off->counter)
|
||||||
|
(*(on_off->counter))++;
|
||||||
if(on_off->list_flg) {
|
if(on_off->list_flg) {
|
||||||
*(llist_t **)(on_off->optarg) =
|
*(llist_t **)(on_off->optarg) =
|
||||||
llist_add_to(*(llist_t **)(on_off->optarg), optarg);
|
llist_add_to(*(llist_t **)(on_off->optarg), optarg);
|
||||||
|
51
procps/ps.c
51
procps/ps.c
@ -22,42 +22,50 @@
|
|||||||
#include <selinux/selinux.h> /* for is_selinux_enabled() */
|
#include <selinux/selinux.h> /* for is_selinux_enabled() */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TERMINAL_WIDTH 80
|
|
||||||
|
|
||||||
extern int ps_main(int argc, char **argv)
|
extern int ps_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
procps_status_t * p;
|
procps_status_t * p;
|
||||||
int i, len, terminal_width;
|
int i, len;
|
||||||
#if ENABLE_SELINUX
|
#if ENABLE_SELINUX
|
||||||
int use_selinux = 0;
|
int use_selinux = 0;
|
||||||
security_context_t sid=NULL;
|
security_context_t sid=NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLE_FEATURE_PS_WIDE
|
||||||
get_terminal_width_height(0, &terminal_width, NULL);
|
int terminal_width;
|
||||||
|
int w_count = 0;
|
||||||
|
#else
|
||||||
|
# define terminal_width 80
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
||||||
/* handle arguments */
|
/* handle arguments */
|
||||||
/* bb_getopt_ulflags(argc, argv,) would force a leading dash */
|
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
|
||||||
for (len = 1; len < argc; len++) {
|
bb_opt_complementally="ww";
|
||||||
char *c = argv[len];
|
i = bb_getopt_ulflags(argc, argv, "wc", &w_count);
|
||||||
while (*c) {
|
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
|
||||||
if (ENABLE_FEATURE_PS_WIDE && *c == 'w')
|
bb_opt_complementally="ww";
|
||||||
|
i = bb_getopt_ulflags(argc, argv, "w", &w_count);
|
||||||
|
#else /* !ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX */
|
||||||
|
i = bb_getopt_ulflags(argc, argv, "c");
|
||||||
|
#endif
|
||||||
|
#if ENABLE_FEATURE_PS_WIDE
|
||||||
/* if w is given once, GNU ps sets the width to 132,
|
/* if w is given once, GNU ps sets the width to 132,
|
||||||
* if w is given more than once, it is "unlimited"
|
* if w is given more than once, it is "unlimited"
|
||||||
*/
|
*/
|
||||||
terminal_width =
|
if((i & 1)) {
|
||||||
(terminal_width==TERMINAL_WIDTH) ? 132 : INT_MAX;
|
terminal_width = (w_count==1) ? 132 : INT_MAX;
|
||||||
#if ENABLE_SELINUX
|
} else {
|
||||||
if (*c == 'c' && is_selinux_enabled())
|
get_terminal_width_height(0, &terminal_width, NULL);
|
||||||
use_selinux = 1;
|
|
||||||
#endif
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Go one less... */
|
/* Go one less... */
|
||||||
terminal_width--;
|
terminal_width--;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if ENABLE_SELINUX
|
||||||
|
if ((i & 2) && is_selinux_enabled())
|
||||||
|
use_selinux = 1;
|
||||||
|
#endif
|
||||||
|
#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
|
||||||
|
|
||||||
#if ENABLE_SELINUX
|
#if ENABLE_SELINUX
|
||||||
if (use_selinux)
|
if (use_selinux)
|
||||||
printf(" PID Context Stat Command\n");
|
printf(" PID Context Stat Command\n");
|
||||||
@ -118,4 +126,3 @@ extern int ps_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user