ps: reduce #ifdef forest

This commit is contained in:
Denis Vlasenko 2006-11-01 09:14:52 +00:00
parent 966ec7c067
commit d3ada32285

View File

@ -13,31 +13,19 @@ int ps_main(int argc, char **argv)
{
procps_status_t * p;
int i, len;
#if ENABLE_SELINUX
int use_selinux = 0;
security_context_t sid = NULL;
#endif
#if ENABLE_FEATURE_PS_WIDE
SKIP_SELINUX(const) int use_selinux = 0;
USE_SELINUX(security_context_t sid = NULL;)
#if !ENABLE_FEATURE_PS_WIDE
enum { terminal_width = 79 };
#else
int terminal_width;
int w_count = 0;
opt_complementary = "-:ww";
#else
# define terminal_width 79
#endif
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
/* handle arguments */
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
i = getopt32(argc, argv, "wc", &w_count);
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
getopt32(argc, argv, "w", &w_count);
#else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */
i = getopt32(argc, argv, "c");
#endif
#if ENABLE_FEATURE_PS_WIDE
opt_complementary = "-:ww";
USE_SELINUX(i =) getopt32(argc, argv, "w" USE_SELINUX("c"), &w_count);
/* if w is given once, GNU ps sets the width to 132,
* if w is given more than once, it is "unlimited"
*/
@ -48,6 +36,8 @@ int ps_main(int argc, char **argv)
/* Go one less... */
terminal_width--;
}
#else /* only ENABLE_SELINUX */
i = getopt32(argc, argv, "c");
#endif
#if ENABLE_SELINUX
if ((i & (1+ENABLE_FEATURE_PS_WIDE)) && is_selinux_enabled())
@ -55,11 +45,9 @@ int ps_main(int argc, char **argv)
#endif
#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
#if ENABLE_SELINUX
if (use_selinux)
puts(" PID Context Stat Command");
else
#endif
puts(" PID Uid VmSize Stat Command");
while ((p = procps_scan(1)) != 0) {
@ -75,7 +63,7 @@ int ps_main(int argc, char **argv)
}
if (sid) {
/* I assume sid initilized with NULL */
/* I assume sid initialized with NULL */
len = strlen(sid)+1;
safe_strncpy(sbuf, sid, len);
freecon(sid);
@ -99,7 +87,7 @@ int ps_main(int argc, char **argv)
i = 0;
if (strlen(namecmd) > (size_t)i)
namecmd[i] = 0;
printf("%s\n", namecmd);
puts(namecmd);
} else {
namecmd = p->short_cmd;
if (i < 2)