]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: use exclusive_option()
authorSami Kerola <kerolasa@iki.fi>
Fri, 15 Jun 2012 21:16:21 +0000 (23:16 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 15:59:59 +0000 (17:59 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/lscpu.c

index 1adc92bad35de5cdac40c75c47d5d62953744689..05a5fb43ad5f0baa0444baac9a8e9750f65b2425 100644 (file)
@@ -42,6 +42,7 @@
 #include "tt.h"
 #include "path.h"
 #include "closestream.h"
+#include "optutils.h"
 
 #define CACHE_MAX 100
 
@@ -1242,6 +1243,19 @@ int main(int argc, char *argv[])
        int c, i;
        int columns[ARRAY_SIZE(coldescs)], ncolumns = 0;
 
+       enum {
+               EXCL_NONE,
+
+               EXCL_ALL,
+               EXCL_ONLINE,
+               EXCL_OFFLINE,
+
+               EXCL_EXTENDED,
+               EXCL_PARSE
+       };
+       int excl_ep = EXCL_NONE;
+       int excl_abc = EXCL_NONE;
+
        static const struct option longopts[] = {
                { "all",        no_argument,       0, 'a' },
                { "online",     no_argument,       0, 'b' },
@@ -1261,28 +1275,27 @@ int main(int argc, char *argv[])
        atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "abce::hp::s:xV", longopts, NULL)) != -1) {
-
-               if (mod->mode != OUTPUT_SUMMARY && strchr("ep", c))
-                       errx(EXIT_FAILURE,
-                            _("extended and parsable formats are mutually exclusive"));
-               if ((mod->online || mod->offline) && strchr("abc", c))
-                       errx(EXIT_FAILURE,
-                            _("--all, --online and --offline options are mutually exclusive"));
-
                switch (c) {
                case 'a':
+                       exclusive_option(&excl_abc, EXCL_ALL, "--{all,online,offline}");
                        mod->online = mod->offline = 1;
                        break;
                case 'b':
+                       exclusive_option(&excl_abc, EXCL_ONLINE, "--{all,online,offline}");
                        mod->online = 1;
                        break;
                case 'c':
+                       exclusive_option(&excl_abc, EXCL_OFFLINE, "--{all,online,offline}");
                        mod->offline = 1;
                        break;
                case 'h':
                        usage(stdout);
                case 'p':
+                       exclusive_option(&excl_ep, EXCL_PARSE, "--{extended,parse}");
+                       goto hop_over;
                case 'e':
+                       exclusive_option(&excl_ep, EXCL_EXTENDED, "--{extended,parse}");
+                       hop_over:
                        if (optarg) {
                                if (*optarg == '=')
                                        optarg++;