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)
This commit is contained in:
parent
7abe709867
commit
35939d9378
@ -110,7 +110,7 @@ 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:
|
"ww" Double 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 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"
|
||||||
|
|
||||||
@ -175,6 +175,9 @@ Special characters:
|
|||||||
"!" If previous point set BB_GETOPT_ERROR, don`t return and call
|
"!" If previous point set BB_GETOPT_ERROR, don`t return and call
|
||||||
previous example internally
|
previous example internally
|
||||||
|
|
||||||
|
"-" A minus as one char in bb_opt_complementally group means that
|
||||||
|
convert the arguments as option, specail for "ps" applet.
|
||||||
|
|
||||||
"*" A star after a char in bb_opt_complementally means that the
|
"*" A star after a char in bb_opt_complementally means that the
|
||||||
option can occur multiple times:
|
option can occur multiple times:
|
||||||
|
|
||||||
@ -227,6 +230,9 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
va_list p;
|
va_list p;
|
||||||
const struct option *l_o;
|
const struct option *l_o;
|
||||||
char flg_show_usage_if_error = 0;
|
char flg_show_usage_if_error = 0;
|
||||||
|
char flg_argv_is_opts = 0;
|
||||||
|
unsigned long trigger;
|
||||||
|
char **pargv = NULL;
|
||||||
|
|
||||||
va_start (p, applet_opts);
|
va_start (p, applet_opts);
|
||||||
|
|
||||||
@ -294,6 +300,10 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
flg_show_usage_if_error = '!';
|
flg_show_usage_if_error = '!';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(*s == '-') {
|
||||||
|
flg_argv_is_opts = '-';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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)
|
||||||
break;
|
break;
|
||||||
@ -304,17 +314,17 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
} else if(*s == '*') {
|
} else if(*s == '*') {
|
||||||
pair->list_flg++;
|
pair->list_flg++;
|
||||||
} else {
|
} else {
|
||||||
unsigned long *pair_switch = &(pair->switch_on);
|
unsigned long *pair_switch = &(pair->switch_on);
|
||||||
if(c)
|
if(c)
|
||||||
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))
|
if(pair_switch == &(on_off->switch_on))
|
||||||
on_off->counter = va_arg (p, int *);
|
on_off->counter = va_arg (p, int *);
|
||||||
else
|
else
|
||||||
*pair_switch |= on_off->switch_on;
|
*pair_switch |= on_off->switch_on;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s--;
|
s--;
|
||||||
@ -322,8 +332,8 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
|
|
||||||
while ((c = getopt_long (argc, argv, applet_opts,
|
while ((c = getopt_long (argc, argv, applet_opts,
|
||||||
bb_applet_long_options, NULL)) > 0) {
|
bb_applet_long_options, NULL)) > 0) {
|
||||||
unsigned long trigger;
|
|
||||||
|
|
||||||
|
loop_arg_is_opt:
|
||||||
for (on_off = complementally; on_off->opt != c; on_off++) {
|
for (on_off = complementally; on_off->opt != c; on_off++) {
|
||||||
if(!on_off->opt)
|
if(!on_off->opt)
|
||||||
bb_show_usage ();
|
bb_show_usage ();
|
||||||
@ -341,10 +351,28 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
|
|||||||
(*(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);
|
||||||
} else if (on_off->optarg) {
|
} else if (on_off->optarg) {
|
||||||
*(char **)(on_off->optarg) = optarg;
|
*(char **)(on_off->optarg) = optarg;
|
||||||
}
|
}
|
||||||
|
if(flg_argv_is_opts == 'p')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(flg_argv_is_opts) {
|
||||||
|
/* process argv is option, for example "ps" applet */
|
||||||
|
if(flg_argv_is_opts == '-') {
|
||||||
|
flg_argv_is_opts = 'p';
|
||||||
|
pargv = argv + optind;
|
||||||
|
}
|
||||||
|
while(*pargv) {
|
||||||
|
c = **pargv;
|
||||||
|
if(c == '\0') {
|
||||||
|
pargv++;
|
||||||
|
} else {
|
||||||
|
(*pargv)++;
|
||||||
|
goto loop_arg_is_opt;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
|
13
procps/ps.c
13
procps/ps.c
@ -26,16 +26,19 @@ extern int ps_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
procps_status_t * p;
|
procps_status_t * p;
|
||||||
int i, len;
|
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
|
#if ENABLE_FEATURE_PS_WIDE
|
||||||
int terminal_width;
|
int terminal_width;
|
||||||
int w_count = 0;
|
int w_count = 0;
|
||||||
bb_opt_complementally="ww";
|
|
||||||
|
bb_opt_complementally="-:ww";
|
||||||
#else
|
#else
|
||||||
# define terminal_width 80
|
# define terminal_width 79
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
||||||
@ -43,7 +46,7 @@ extern int ps_main(int argc, char **argv)
|
|||||||
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
|
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
|
||||||
i = bb_getopt_ulflags(argc, argv, "wc", &w_count);
|
i = bb_getopt_ulflags(argc, argv, "wc", &w_count);
|
||||||
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
|
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
|
||||||
i = bb_getopt_ulflags(argc, argv, "w", &w_count);
|
bb_getopt_ulflags(argc, argv, "w", &w_count);
|
||||||
#else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */
|
#else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */
|
||||||
i = bb_getopt_ulflags(argc, argv, "c");
|
i = bb_getopt_ulflags(argc, argv, "c");
|
||||||
#endif
|
#endif
|
||||||
@ -51,10 +54,10 @@ extern int ps_main(int argc, char **argv)
|
|||||||
/* 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"
|
||||||
*/
|
*/
|
||||||
if((i & 1)) {
|
if(w_count) {
|
||||||
terminal_width = (w_count==1) ? 132 : INT_MAX;
|
terminal_width = (w_count==1) ? 132 : INT_MAX;
|
||||||
} else {
|
} else {
|
||||||
get_terminal_width_height(0, &terminal_width, NULL);
|
get_terminal_width_height(1, &terminal_width, NULL);
|
||||||
/* Go one less... */
|
/* Go one less... */
|
||||||
terminal_width--;
|
terminal_width--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user