]> granicus.if.org Git - sysstat/commitdiff
Cosmetic changes in code
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 22 Jul 2017 15:15:04 +0000 (17:15 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 22 Jul 2017 15:15:04 +0000 (17:15 +0200)
This is a bit more compact.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
iostat.c
mpstat.c
pidstat.c
sa_common.c
sadc.c
sadf.c
sar.c

index 7b346e275193822d749df9db996ba41397c59273..6ccaa56ec6599a224533f7e045c38812e8a61c50 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -1781,16 +1781,14 @@ int main(int argc, char **argv)
                        if (group_nr > 0) {
                                update_dev_list(&dlist_idx, group_name);
                        }
-                       if (argv[++opt]) {
-                               /*
-                                * MAX_NAME_LEN - 2: one char for the heading space,
-                                * and one for the trailing '\0'.
-                                */
-                               snprintf(group_name, MAX_NAME_LEN, " %-.*s", MAX_NAME_LEN - 2, argv[opt++]);
-                       }
-                       else {
+                       if (!argv[++opt]) {
                                usage(argv[0]);
                        }
+                       /*
+                        * MAX_NAME_LEN - 2: one char for the heading space,
+                        * and one for the trailing '\0'.
+                        */
+                       snprintf(group_name, MAX_NAME_LEN, " %-.*s", MAX_NAME_LEN - 2, argv[opt++]);
                        group_nr++;
                }
 
@@ -1800,28 +1798,26 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-j")) {
-                       if (argv[++opt]) {
-                               if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) {
-                                       usage(argv[0]);
-                               }
-                               strncpy(persistent_name_type, argv[opt], MAX_FILE_LEN - 1);
-                               persistent_name_type[MAX_FILE_LEN - 1] = '\0';
-                               strtolower(persistent_name_type);
-                               /* Check that this is a valid type of persistent device name */
-                               if (!get_persistent_type_dir(persistent_name_type)) {
-                                       fprintf(stderr, _("Invalid type of persistent device name\n"));
-                                       exit(1);
-                               }
-                               /*
-                                * Persistent names are usually long: Display
-                                * them as human readable by default.
-                                */
-                               flags |= I_D_PERSIST_NAME + I_D_HUMAN_READ;
-                               opt++;
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) {
                                usage(argv[0]);
                        }
+                       strncpy(persistent_name_type, argv[opt], MAX_FILE_LEN - 1);
+                       persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+                       strtolower(persistent_name_type);
+                       /* Check that this is a valid type of persistent device name */
+                       if (!get_persistent_type_dir(persistent_name_type)) {
+                               fprintf(stderr, _("Invalid type of persistent device name\n"));
+                               exit(1);
+                       }
+                       /*
+                        * Persistent names are usually long: Display
+                        * them as human readable by default.
+                        */
+                       flags |= I_D_PERSIST_NAME + I_D_HUMAN_READ;
+                       opt++;
                }
 
                else if (!strcmp(argv[opt], "-o")) {
index 1c83ea23f76e5b7141f872d61d91462f0a1c6d49..f8eca84041e975cdfb6dd93ed82e1e7f6d89cc72 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -2042,32 +2042,30 @@ int main(int argc, char **argv)
        while (++opt < argc) {
 
                if (!strcmp(argv[opt], "-I")) {
-                       if (argv[++opt]) {
-                               actset = TRUE;
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
+                       }
+                       actset = TRUE;
 
-                               for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
-                                       if (!strcmp(t, K_SUM)) {
-                                               /* Display total number of interrupts per CPU */
-                                               actflags |= M_D_IRQ_SUM;
-                                       }
-                                       else if (!strcmp(t, K_CPU)) {
-                                               /* Display interrupts per CPU */
-                                               actflags |= M_D_IRQ_CPU;
-                                       }
-                                       else if (!strcmp(t, K_SCPU)) {
-                                               /* Display soft interrupts per CPU */
-                                               actflags |= M_D_SOFTIRQS;
-                                       }
-                                       else if (!strcmp(t, K_ALL)) {
-                                               actflags |= M_D_IRQ_SUM + M_D_IRQ_CPU + M_D_SOFTIRQS;
-                                       }
-                                       else {
-                                               usage(argv[0]);
-                                       }
+                       for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
+                               if (!strcmp(t, K_SUM)) {
+                                       /* Display total number of interrupts per CPU */
+                                       actflags |= M_D_IRQ_SUM;
+                               }
+                               else if (!strcmp(t, K_CPU)) {
+                                       /* Display interrupts per CPU */
+                                       actflags |= M_D_IRQ_CPU;
+                               }
+                               else if (!strcmp(t, K_SCPU)) {
+                                       /* Display soft interrupts per CPU */
+                                       actflags |= M_D_SOFTIRQS;
+                               }
+                               else if (!strcmp(t, K_ALL)) {
+                                       actflags |= M_D_IRQ_SUM + M_D_IRQ_CPU + M_D_SOFTIRQS;
+                               }
+                               else {
+                                       usage(argv[0]);
                                }
-                       }
-                       else {
-                               usage(argv[0]);
                        }
                }
 
@@ -2082,38 +2080,34 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-N")) {
-                       if (argv[++opt]) {
-                               if (node_nr >= 0) {
-                                       flags |= F_N_OPTION;
-                                       actflags |= M_D_NODE;
-                                       actset = TRUE;
-                                       dis_hdr = 9;
-                                       if (parse_values(argv[opt], node_bitmap, node_nr + 1, K_LOWERALL)) {
-                                               usage(argv[0]);
-                                       }
-                               }
-                       }
-                       else {
+                       if (!argv[++opt]) {
                                usage(argv[0]);
                        }
+                       if (node_nr >= 0) {
+                               flags |= F_N_OPTION;
+                               actflags |= M_D_NODE;
+                               actset = TRUE;
+                               dis_hdr = 9;
+                               if (parse_values(argv[opt], node_bitmap, node_nr + 1, K_LOWERALL)) {
+                                       usage(argv[0]);
+                               }
+                       }
                }
 
                else if (!strcmp(argv[opt], "-P")) {
                        /* '-P ALL' can be used on UP machines */
-                       if (argv[++opt]) {
-                               flags |= F_P_OPTION;
-                               dis_hdr = 9;
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
+                       }
+                       flags |= F_P_OPTION;
+                       dis_hdr = 9;
 
-                               if (!strcmp(argv[opt], K_ON)) {
-                                       /* Display stats for all online CPU */
-                                       flags |= F_P_ON;
-                                       memset(cpu_bitmap, ~0, BITMAP_SIZE(cpu_nr));
-                               }
-                               else if (parse_values(argv[opt], cpu_bitmap, cpu_nr, K_LOWERALL)) {
-                                       usage(argv[0]);
-                               }
+                       if (!strcmp(argv[opt], K_ON)) {
+                               /* Display stats for all online CPU */
+                               flags |= F_P_ON;
+                               memset(cpu_bitmap, ~0, BITMAP_SIZE(cpu_nr));
                        }
-                       else {
+                       else if (parse_values(argv[opt], cpu_bitmap, cpu_nr, K_LOWERALL)) {
                                usage(argv[0]);
                        }
                }
index c512b474c8cfec0780084b4a261aa1a4c5ba75af..820318b30560ec558c2bcf1d85e3ff1fb1d6303e 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -2686,57 +2686,51 @@ int main(int argc, char **argv)
 
                else if (!strcmp(argv[opt], "-p")) {
                        pidflag |= P_D_PID;
-                       if (argv[++opt]) {
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
+                       }
 
-                               for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
-                                       if (!strcmp(t, K_ALL)) {
-                                               pidflag |= P_D_ALL_PID;
-                                       }
-                                       else if (!strcmp(t, K_SELF)) {
-                                               update_pid_array(&pid_array_nr, getpid());
+                       for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
+                               if (!strcmp(t, K_ALL)) {
+                                       pidflag |= P_D_ALL_PID;
+                               }
+                               else if (!strcmp(t, K_SELF)) {
+                                       update_pid_array(&pid_array_nr, getpid());
+                               }
+                               else {
+                                       if (strspn(t, DIGITS) != strlen(t)) {
+                                               usage(argv[0]);
                                        }
-                                       else {
-                                               if (strspn(t, DIGITS) != strlen(t)) {
-                                                       usage(argv[0]);
-                                               }
-                                               pid = atoi(t);
-                                               if (pid < 1) {
-                                                       usage(argv[0]);
-                                               }
-                                               update_pid_array(&pid_array_nr, pid);
+                                       pid = atoi(t);
+                                       if (pid < 1) {
+                                               usage(argv[0]);
                                        }
+                                       update_pid_array(&pid_array_nr, pid);
                                }
-                               opt++;
-                       }
-                       else {
-                               usage(argv[0]);
                        }
+                       opt++;
                }
 
                else if (!strcmp(argv[opt], "-C")) {
-                       if (argv[++opt]) {
-                               strncpy(commstr, argv[opt++], MAX_COMM_LEN);
-                               commstr[MAX_COMM_LEN - 1] = '\0';
-                               pidflag |= P_F_COMMSTR;
-                               if (!strlen(commstr)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       strncpy(commstr, argv[opt++], MAX_COMM_LEN);
+                       commstr[MAX_COMM_LEN - 1] = '\0';
+                       pidflag |= P_F_COMMSTR;
+                       if (!strlen(commstr)) {
                                usage(argv[0]);
                        }
                }
 
                else if (!strcmp(argv[opt], "-G")) {
-                       if (argv[++opt]) {
-                               strncpy(procstr, argv[opt++], MAX_COMM_LEN);
-                               procstr[MAX_COMM_LEN - 1] = '\0';
-                               pidflag |= P_F_PROCSTR;
-                               if (!strlen(procstr)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       strncpy(procstr, argv[opt++], MAX_COMM_LEN);
+                       procstr[MAX_COMM_LEN - 1] = '\0';
+                       pidflag |= P_F_PROCSTR;
+                       if (!strlen(procstr)) {
                                usage(argv[0]);
                        }
                }
@@ -2747,28 +2741,26 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-T")) {
-                       if (argv[++opt]) {
-                               if (tskflag) {
-                                       dis_hdr++;
-                               }
-                               if (!strcmp(argv[opt], K_P_TASK)) {
-                                       tskflag |= P_TASK;
-                               }
-                               else if (!strcmp(argv[opt], K_P_CHILD)) {
-                                       tskflag |= P_CHILD;
-                               }
-                               else if (!strcmp(argv[opt], K_P_ALL)) {
-                                       tskflag |= P_TASK + P_CHILD;
-                                       dis_hdr++;
-                               }
-                               else {
-                                       usage(argv[0]);
-                               }
-                               opt++;
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
+                       }
+                       if (tskflag) {
+                               dis_hdr++;
+                       }
+                       if (!strcmp(argv[opt], K_P_TASK)) {
+                               tskflag |= P_TASK;
+                       }
+                       else if (!strcmp(argv[opt], K_P_CHILD)) {
+                               tskflag |= P_CHILD;
+                       }
+                       else if (!strcmp(argv[opt], K_P_ALL)) {
+                               tskflag |= P_TASK + P_CHILD;
+                               dis_hdr++;
                        }
                        else {
                                usage(argv[0]);
                        }
+                       opt++;
                }
 
                /* Option used individually. See below for grouped option */
index 5e971e2b6f21abb76a0cda0007d0be54bff30e78..07bff87c558cf3c76231b26934920d11bcf9e8b5 100644 (file)
@@ -1576,28 +1576,26 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                        break;
 
                case 'j':
-                       if (argv[*opt + 1]) {
-                               (*opt)++;
-                               if (strnlen(argv[*opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1)
-                                       return 1;
-
-                               strncpy(persistent_name_type, argv[*opt], MAX_FILE_LEN - 1);
-                               persistent_name_type[MAX_FILE_LEN - 1] = '\0';
-                               strtolower(persistent_name_type);
-                               if (!get_persistent_type_dir(persistent_name_type)) {
-                                       fprintf(stderr, _("Invalid type of persistent device name\n"));
-                                       return 2;
-                               }
-                               /*
-                                * If persistent device name doesn't exist for device, use
-                                * its pretty name.
-                                */
-                               *flags |= S_F_PERSIST_NAME + S_F_DEV_PRETTY;
-                               return 0;
+                       if (!argv[*opt + 1]) {
+                               return 1;
                        }
-                       else {
+                       (*opt)++;
+                       if (strnlen(argv[*opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1)
                                return 1;
+
+                       strncpy(persistent_name_type, argv[*opt], MAX_FILE_LEN - 1);
+                       persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+                       strtolower(persistent_name_type);
+                       if (!get_persistent_type_dir(persistent_name_type)) {
+                               fprintf(stderr, _("Invalid type of persistent device name\n"));
+                               return 2;
                        }
+                       /*
+                        * If persistent device name doesn't exist for device, use
+                        * its pretty name.
+                        */
+                       *flags |= S_F_PERSIST_NAME + S_F_DEV_PRETTY;
+                       return 0;
                        break;
 
                case 'p':
@@ -1632,11 +1630,10 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                         * But sadf option -t is checked in sadf.c as it won't
                         * be entered as a sar option after "--".
                         */
-                       if (caller == C_SAR) {
-                               *flags |= S_F_TRUE_TIME;
-                       }
-                       else
+                       if (caller != C_SAR) {
                                return 1;
+                       }
+                       *flags |= S_F_TRUE_TIME;
                        break;
 
                case 'u':
diff --git a/sadc.c b/sadc.c
index 7cdbc3806e50acc9c52ade075c18968f31ba1789..96af66f4557188ce586d7f560190b2620f4d1d25 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -1238,12 +1238,10 @@ int main(int argc, char **argv)
        while (++opt < argc) {
 
                if (!strcmp(argv[opt], "-S")) {
-                       if (argv[++opt]) {
-                               parse_sadc_S_option(argv, opt);
-                       }
-                       else {
+                       if (!argv[++opt]) {
                                usage(argv[0]);
                        }
+                       parse_sadc_S_option(argv, opt);
                }
 
                else if (!strcmp(argv[opt], "-D")) {
@@ -1268,14 +1266,12 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-C")) {
-                       if (argv[++opt]) {
-                               strncpy(comment, argv[opt], MAX_COMMENT_LEN);
-                               comment[MAX_COMMENT_LEN - 1] = '\0';
-                               if (!strlen(comment)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       strncpy(comment, argv[opt], MAX_COMMENT_LEN);
+                       comment[MAX_COMMENT_LEN - 1] = '\0';
+                       if (!strlen(comment)) {
                                usage(argv[0]);
                        }
                }
diff --git a/sadf.c b/sadf.c
index 160b48502ac3b18d40d6f69042cfc3b4050aa875..b549ea8aa252184a6c62da3f14c7e431c52ad340 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -1487,12 +1487,10 @@ int main(int argc, char **argv)
        while (opt < argc) {
 
                if (!strcmp(argv[opt], "-I")) {
-                       if (sar_options) {
-                               if (parse_sar_I_opt(argv, &opt, act)) {
-                                       usage(argv[0]);
-                               }
+                       if (!sar_options) {
+                               usage(argv[0]);
                        }
-                       else {
+                       if (parse_sar_I_opt(argv, &opt, act)) {
                                usage(argv[0]);
                        }
                }
@@ -1576,25 +1574,21 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-m")) {
-                       if (argv[++opt] && sar_options) {
-                               /* Parse sar's option -m */
-                               if (parse_sar_m_opt(argv, &opt, act)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt] || !sar_options) {
+                               usage(argv[0]);
                        }
-                       else {
+                       /* Parse sar's option -m */
+                       if (parse_sar_m_opt(argv, &opt, act)) {
                                usage(argv[0]);
                        }
                }
 
                else if (!strcmp(argv[opt], "-n")) {
-                       if (argv[++opt] && sar_options) {
-                               /* Parse sar's option -n */
-                               if (parse_sar_n_opt(argv, &opt, act)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt] || !sar_options) {
+                               usage(argv[0]);
                        }
-                       else {
+                       /* Parse sar's option -n */
+                       if (parse_sar_n_opt(argv, &opt, act)) {
                                usage(argv[0]);
                        }
                }
diff --git a/sar.c b/sar.c
index 579e4ac49daea08da8b5f847ed70b556e63db503..ee1c9fc42cc5bdf23c58ac3b516543d9ecdea1f4 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1260,25 +1260,21 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-m")) {
-                       if (argv[++opt]) {
-                               /* Parse option -m */
-                               if (parse_sar_m_opt(argv, &opt, act)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       /* Parse option -m */
+                       if (parse_sar_m_opt(argv, &opt, act)) {
                                usage(argv[0]);
                        }
                }
 
                else if (!strcmp(argv[opt], "-n")) {
-                       if (argv[++opt]) {
-                               /* Parse option -n */
-                               if (parse_sar_n_opt(argv, &opt, act)) {
-                                       usage(argv[0]);
-                               }
+                       if (!argv[++opt]) {
+                               usage(argv[0]);
                        }
-                       else {
+                       /* Parse option -n */
+                       if (parse_sar_n_opt(argv, &opt, act)) {
                                usage(argv[0]);
                        }
                }