]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: move parse_switch() from setterm(1) to library
authorSami Kerola <kerolasa@iki.fi>
Sun, 22 Feb 2015 14:41:37 +0000 (14:41 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Feb 2015 10:33:31 +0000 (11:33 +0100)
To allow sharing the code with other utilities.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h
lib/strutils.c
term-utils/setterm.c

index 4d8463a6d76fdc29591629676d6f8d8557429f55..ee8c7cbdade0380bf87ce49162548f6cfafd7911 100644 (file)
@@ -36,6 +36,8 @@ extern void strtotimeval_or_err(const char *str, struct timeval *tv,
 
 extern int isdigit_string(const char *str);
 
+extern int parse_switch(const char *arg, const char *a, const char *b);
+
 #ifndef HAVE_MEMPCPY
 extern void *mempcpy(void *restrict dest, const void *restrict src, size_t n);
 #endif
index c4f9600b0590a0ae28a5a5796a39ebe54afed7f8..f6154aaa494f7a1a62aad3c23050d7db2f26ce1f 100644 (file)
@@ -181,6 +181,14 @@ int isdigit_string(const char *str)
        return p && p > str && !*p;
 }
 
+int parse_switch(const char *arg, const char *a, const char *b)
+{
+       if (strcmp(arg, a) == 0)
+               return 1;
+       else if (strcmp(arg, b) == 0)
+               return 0;
+       errx(STRTOXX_EXIT_CODE, _("argument error: %s"), arg);
+}
 
 #ifndef HAVE_MEMPCPY
 void *mempcpy(void *restrict dest, const void *restrict src, size_t n)
index 76fedbae4fa392463a84319dadd5d85817a29499..fed25307cd45a94a9ef8ad688bd5cb6ac51d0307 100644 (file)
@@ -178,20 +178,6 @@ struct setterm_control {
            opt_powerdown:1, opt_blength:1, opt_bfreq:1;
 };
 
-/* Command line parsing routines.
- *
- * Note that it is an error for a given option to be invoked more than once.
- */
-
-static int parse_switch(const char *arg, const char *t, const char *f)
-{
-       if (strcmp(arg, t) == 0)
-               return 1;
-       else if (strcmp(arg, f) == 0)
-               return 0;
-       errx(EXIT_FAILURE, _("argument error: %s"), arg);
-}
-
 static int parse_febg_color(const char *arg)
 {
        int color;
@@ -687,8 +673,6 @@ static void parse_option(struct setterm_control *ctl, int argc, char **argv)
        }
 }
 
-/* End of command line parsing routines. */
-
 /* Return the specified terminfo string, or an empty string if no such
  * terminfo capability exists.  */
 static char *ti_entry(const char *name)