From 048c93cc5593d53d6243c3e15dc8a5b0072a6083 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Wed, 1 Nov 2006 09:17:47 +0000 Subject: [PATCH] pidof: reduce #ifdef forest --- procps/pidof.c | 58 +++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/procps/pidof.c b/procps/pidof.c index 28c5c04e2..1d9718945 100644 --- a/procps/pidof.c +++ b/procps/pidof.c @@ -9,54 +9,38 @@ #include "busybox.h" -#if ENABLE_FEATURE_PIDOF_SINGLE -#define _SINGLE_COMPL(a) a -#define SINGLE (1<<0) -#else -#define _SINGLE_COMPL(a) -#define SINGLE 0 -#endif - -#if ENABLE_FEATURE_PIDOF_OMIT -# define _OMIT_COMPL(a) a -# define _OMIT(a) ,a -# if ENABLE_FEATURE_PIDOF_SINGLE -# define OMIT (1<<1) -# else -# define OMIT (1<<0) -# endif -#else -# define _OMIT_COMPL(a) "" -# define _OMIT(a) -# define OMIT (0) -# define omitted (0) -#endif +enum { + USE_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,) + USE_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,) + OPT_SINGLE = USE_FEATURE_PIDOF_SINGLE((1<data, "%PPID", 5)) { llist_pop(&omits_p); - snprintf(getppid_str, sizeof(getppid_str), "%ld", (long)getppid()); + snprintf(getppid_str, sizeof(getppid_str), "%u", (unsigned)getppid()); llist_add_to(&omits_p, getppid_str); } omits_p = omits_p->link; @@ -71,9 +55,9 @@ int pidof_main(int argc, char **argv) /* reverse the pidlist like GNU pidof does. */ pidList = pidlist_reverse(find_pid_by_name(argv[optind])); for (pl = pidList; *pl; pl++) { + SKIP_FEATURE_PIDOF_OMIT(const) unsigned omitted = 0; #if ENABLE_FEATURE_PIDOF_OMIT - unsigned omitted = 0; - if (opt & OMIT) { + if (opt & OPT_OMIT) { llist_t *omits_p = omits; while (omits_p) { if (xatoul(omits_p->data) == *pl) { @@ -85,16 +69,12 @@ int pidof_main(int argc, char **argv) } #endif if (!omitted) { - if (n) { - putchar(' '); - } else { - n = 1; - } - printf("%u", (unsigned)*pl); + printf(" %u" + first, (unsigned)*pl); + first = 0; } fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted); - if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & SINGLE)) + if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE)) break; } free(pidList); -- 2.25.1