]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: don't link with tinfo
authorKarel Zak <kzak@redhat.com>
Fri, 24 Jul 2015 10:57:46 +0000 (12:57 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 24 Jul 2015 10:57:46 +0000 (12:57 +0200)
Let's move color names to sequence translation to separate file to
make it usable without all the stuff in lib/colors.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/Makemodule.am
include/color-names.h [new file with mode: 0644]
include/colors.h
lib/Makemodule.am
lib/color-names.c [new file with mode: 0644]
lib/colors.c
libsmartcols/src/Makemodule.am
libsmartcols/src/smartcolsP.h

index 48a19541efc51aacc2c306d3c7516930492feb2d..f0bb898c32383613ca1c8720c4a3077614db1a13 100644 (file)
@@ -9,6 +9,7 @@ dist_noinst_HEADERS += \
        include/c.h \
        include/closestream.h \
        include/colors.h \
+       include/color-names.h \
        include/cpuset.h \
        include/crc32.h \
        include/crc64.h \
diff --git a/include/color-names.h b/include/color-names.h
new file mode 100644 (file)
index 0000000..f04bc2e
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012-2015 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be distributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#ifndef UTIL_LINUX_COLOR_NAMES_H
+#define UTIL_LINUX_COLOR_NAMES_H
+
+#define UL_COLOR_RESET         "\033[0m"
+#define UL_COLOR_BOLD          "\033[1m"
+#define UL_COLOR_HALFBRIGHT    "\033[2m"
+#define UL_COLOR_UNDERSCORE    "\033[4m"
+#define UL_COLOR_BLINK         "\033[5m"
+#define UL_COLOR_REVERSE       "\033[7m"
+
+/* Standard colors */
+#define UL_COLOR_BLACK         "\033[30m"
+#define UL_COLOR_RED           "\033[31m"
+#define UL_COLOR_GREEN         "\033[32m"
+#define UL_COLOR_BROWN         "\033[33m"      /* well, brown */
+#define UL_COLOR_BLUE          "\033[34m"
+#define UL_COLOR_MAGENTA       "\033[35m"
+#define UL_COLOR_CYAN          "\033[36m"
+#define UL_COLOR_GRAY          "\033[37m"
+
+/* Bold variants */
+#define UL_COLOR_DARK_GRAY     "\033[1;30m"
+#define UL_COLOR_BOLD_RED      "\033[1;31m"
+#define UL_COLOR_BOLD_GREEN    "\033[1;32m"
+#define UL_COLOR_BOLD_YELLOW   "\033[1;33m"
+#define UL_COLOR_BOLD_BLUE     "\033[1;34m"
+#define UL_COLOR_BOLD_MAGENTA  "\033[1;35m"
+#define UL_COLOR_BOLD_CYAN     "\033[1;36m"
+
+#define UL_COLOR_WHITE         "\033[1;37m"
+
+extern const char *color_sequence_from_colorname(const char *str);
+
+#endif /* UTIL_LINUX_COLOR_NAMES_H */
index df6feb7394b96ff1ae0ed26eb465fcda6a18b42b..fda1ca98d7f0dd318f926f34d3923ea10972e37f 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-#define UL_COLOR_RESET         "\033[0m"
-#define UL_COLOR_BOLD          "\033[1m"
-#define UL_COLOR_HALFBRIGHT    "\033[2m"
-#define UL_COLOR_UNDERSCORE    "\033[4m"
-#define UL_COLOR_BLINK         "\033[5m"
-#define UL_COLOR_REVERSE       "\033[7m"
-
-/* Standard colors */
-#define UL_COLOR_BLACK         "\033[30m"
-#define UL_COLOR_RED           "\033[31m"
-#define UL_COLOR_GREEN         "\033[32m"
-#define UL_COLOR_BROWN         "\033[33m"      /* well, brown */
-#define UL_COLOR_BLUE          "\033[34m"
-#define UL_COLOR_MAGENTA       "\033[35m"
-#define UL_COLOR_CYAN          "\033[36m"
-#define UL_COLOR_GRAY          "\033[37m"
-
-/* Bold variants */
-#define UL_COLOR_DARK_GRAY     "\033[1;30m"
-#define UL_COLOR_BOLD_RED      "\033[1;31m"
-#define UL_COLOR_BOLD_GREEN    "\033[1;32m"
-#define UL_COLOR_BOLD_YELLOW   "\033[1;33m"
-#define UL_COLOR_BOLD_BLUE     "\033[1;34m"
-#define UL_COLOR_BOLD_MAGENTA  "\033[1;35m"
-#define UL_COLOR_BOLD_CYAN     "\033[1;36m"
-
-#define UL_COLOR_WHITE         "\033[1;37m"
-
+#include "color-names.h"
 
 /* --color[=WHEN] */
 enum colortmode {
@@ -94,8 +67,4 @@ static inline void color_disable(void)
        color_fdisable(stdout);
 }
 
-/* converts "red" to UL_COLOR_RED, etc. */
-extern const char *color_sequence_from_colorname(const char *str);
-
-
 #endif /* UTIL_LINUX_COLORS_H */
index 6ef69570fb675d9f10e7f9b685c32364f621dfae..e81ca770a9811c96e27bad2ec834c0c48ea57e89 100644 (file)
@@ -10,6 +10,7 @@ libcommon_la_SOURCES = \
        lib/env.c \
        lib/fileutils.c \
        lib/ismounted.c \
+       lib/color-names.c \
        lib/mangle.c \
        lib/match.c \
        lib/mbsalign.c \
@@ -44,7 +45,7 @@ endif
 noinst_LTLIBRARIES += libtcolors.la
 libtcolors_la_CFLAGS = $(AM_CFLAGS) $(TINFO_CFLAGS)
 libtcolors_la_LIBADD = $(TINFO_LIBS)
-libtcolors_la_SOURCES = lib/colors.c include/colors.h
+libtcolors_la_SOURCES = lib/colors.c lib/color-names.c include/colors.h include/color-names.h
 
 dist_man_MANS += lib/terminal-colors.d.5
 
diff --git a/lib/color-names.c b/lib/color-names.c
new file mode 100644 (file)
index 0000000..923b2f0
--- /dev/null
@@ -0,0 +1,52 @@
+
+#include "c.h"
+#include "color-names.h"
+
+struct ul_color_name {
+       const char *name;
+       const char *seq;
+};
+
+/*
+ * qsort/bsearch buddy
+ */
+static int cmp_color_name(const void *a0, const void *b0)
+{
+       struct ul_color_name    *a = (struct ul_color_name *) a0,
+                               *b = (struct ul_color_name *) b0;
+       return strcmp(a->name, b->name);
+}
+
+/*
+ * Maintains human readable color names
+ */
+const char *color_sequence_from_colorname(const char *str)
+{
+       static const struct ul_color_name basic_schemes[] = {
+               { "black",      UL_COLOR_BLACK           },
+               { "blue",       UL_COLOR_BLUE            },
+               { "brown",      UL_COLOR_BROWN           },
+               { "cyan",       UL_COLOR_CYAN            },
+               { "darkgray",   UL_COLOR_DARK_GRAY       },
+               { "gray",       UL_COLOR_GRAY            },
+               { "green",      UL_COLOR_GREEN           },
+               { "lightblue",  UL_COLOR_BOLD_BLUE       },
+               { "lightcyan",  UL_COLOR_BOLD_CYAN       },
+               { "lightgray,", UL_COLOR_GRAY            },
+               { "lightgreen", UL_COLOR_BOLD_GREEN      },
+               { "lightmagenta", UL_COLOR_BOLD_MAGENTA  },
+               { "lightred",   UL_COLOR_BOLD_RED        },
+               { "magenta",    UL_COLOR_MAGENTA         },
+               { "red",        UL_COLOR_RED             },
+               { "yellow",     UL_COLOR_BOLD_YELLOW     },
+       };
+       struct ul_color_name key = { .name = (char *) str }, *res;
+
+       if (!str)
+               return NULL;
+
+       res = bsearch(&key, basic_schemes, ARRAY_SIZE(basic_schemes),
+                               sizeof(struct ul_color_name),
+                               cmp_color_name);
+       return res ? res->seq : NULL;
+}
index da5a3e1f41eb6fac55839eb5809e63ce57ff0bde..933bb810ad5620647322cb0480cb23dd0133896b 100644 (file)
@@ -112,41 +112,6 @@ static int cmp_scheme_name(const void *a0, const void *b0)
        return strcmp(a->name, b->name);
 }
 
-/*
- * Maintains human readable color names
- */
-const char *color_sequence_from_colorname(const char *str)
-{
-       static const struct ul_color_scheme basic_schemes[] = {
-               { "black",      UL_COLOR_BLACK           },
-               { "blue",       UL_COLOR_BLUE            },
-               { "brown",      UL_COLOR_BROWN           },
-               { "cyan",       UL_COLOR_CYAN            },
-               { "darkgray",   UL_COLOR_DARK_GRAY       },
-               { "gray",       UL_COLOR_GRAY            },
-               { "green",      UL_COLOR_GREEN           },
-               { "lightblue",  UL_COLOR_BOLD_BLUE       },
-               { "lightcyan",  UL_COLOR_BOLD_CYAN       },
-               { "lightgray,", UL_COLOR_GRAY            },
-               { "lightgreen", UL_COLOR_BOLD_GREEN      },
-               { "lightmagenta", UL_COLOR_BOLD_MAGENTA  },
-               { "lightred",   UL_COLOR_BOLD_RED        },
-               { "magenta",    UL_COLOR_MAGENTA         },
-               { "red",        UL_COLOR_RED             },
-               { "yellow",     UL_COLOR_BOLD_YELLOW     },
-       };
-       struct ul_color_scheme key = { .name = (char *) str }, *res;
-
-       if (!str)
-               return NULL;
-
-       res = bsearch(&key, basic_schemes, ARRAY_SIZE(basic_schemes),
-                               sizeof(struct ul_color_scheme),
-                               cmp_scheme_name);
-       return res ? res->seq : NULL;
-}
-
-
 /*
  * Resets control struct (note that we don't allocate the struct)
  */
index 49ffea65f2d5c46c3f2df3d7e0d8d3e8cff466e9..45a7eeab4c63f25a9bd4b3026bd9fe446fcd5139 100644 (file)
@@ -22,7 +22,7 @@ libsmartcols_la_SOURCES= \
 
 nodist_libsmartcols_la_SOURCES = libsmartcols/src/smartcolsP.h
 
-libsmartcols_la_LIBADD = libcommon.la libtcolors.la
+libsmartcols_la_LIBADD = libcommon.la
 
 libsmartcols_la_CFLAGS = \
        $(SOLIB_CFLAGS) \
@@ -31,7 +31,6 @@ libsmartcols_la_CFLAGS = \
 
 libsmartcols_la_DEPENDENCIES = \
        libcommon.la \
-       libtcolors.la \
        libsmartcols/src/libsmartcols.sym \
        libsmartcols/src/libsmartcols.h.in
 
index c4fe725d0b1253e38c78e102221f52207a272cd7..95c00db8fdf1c92117395e1cf090d940c9ba6bc8 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "c.h"
 #include "list.h"
-#include "colors.h"
+#include "color-names.h"
 #include "debug.h"
 
 #include "libsmartcols.h"