From e42e9007121336ad7d5d079cf2b12c6996f6c157 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 3 Mar 2018 10:51:08 +0100 Subject: [PATCH] sar: Allow options -h and -z to be coalesced With this patch it is now possible to enter, e.g. "sar -dhz" instead of "sar -d -h -z". Signed-off-by: Sebastien GODARD --- sa.h | 3 +-- sa_common.c | 12 ++++++++++++ sar.c | 14 -------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/sa.h b/sa.h index f08f8f8..871c578 100644 --- a/sa.h +++ b/sa.h @@ -98,8 +98,6 @@ #define S_F_LOCAL_TIME 0x00004000 #define S_F_PREFD_TIME_OUTPUT 0x00008000 #define S_F_SVG_SKIP 0x00010000 -/* Same value as S_F_SVG_SKIP above. Used for sar */ -#define S_F_ZERO_OMIT 0x00010000 /* Same value as S_F_SVG_SKIP above. Used for a different output format */ #define S_F_RAW_DEBUG_MODE 0x00010000 #define S_F_SVG_AUTOSCALE 0x00020000 @@ -110,6 +108,7 @@ #define S_F_SVG_PACKED 0x00400000 #define S_F_SVG_SHOW_INFO 0x00800000 #define S_F_HUMAN_READ 0x01000000 +#define S_F_ZERO_OMIT 0x02000000 #define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT) #define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT) diff --git a/sa_common.c b/sa_common.c index b75fc7e..b274d32 100644 --- a/sa_common.c +++ b/sa_common.c @@ -2016,6 +2016,14 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[], act[p]->options |= AO_SELECTED; break; + case 'h': + /* + * Make output easier to read by a human. + * Option -h implies --human and -p (pretty-print). + */ + *flags |= S_F_HUMAN_READ + S_F_UNIT + S_F_DEV_PRETTY; + break; + case 'j': if (!argv[*opt + 1]) { return 1; @@ -2106,6 +2114,10 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[], SELECT_ACTIVITY(A_SERIAL); break; + case 'z': + *flags |= S_F_ZERO_OMIT; + break; + case 'V': print_version(); break; diff --git a/sar.c b/sar.c index e6b8cc9..8ba575a 100644 --- a/sar.c +++ b/sar.c @@ -1279,15 +1279,6 @@ int main(int argc, char **argv) opt++; } - else if (!strcmp(argv[opt], "-h")) { - /* - * Make output easier to read by a human. - * Option -h implies --human and -p (pretty-print). - */ - flags |= S_F_HUMAN_READ + S_F_UNIT + S_F_DEV_PRETTY; - opt++; - } - else if (!strcmp(argv[opt], "-I")) { /* Parse -I option */ if (parse_sar_I_opt(argv, &opt, act)) { @@ -1387,11 +1378,6 @@ int main(int argc, char **argv) } } - else if (!strcmp(argv[opt], "-z")) { - flags |= S_F_ZERO_OMIT; - opt++; - } - else if ((strlen(argv[opt]) > 1) && (strlen(argv[opt]) < 4) && !strncmp(argv[opt], "-", 1) && -- 2.40.0