summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/Makemodule.am1
-rw-r--r--include/color-names.h40
-rw-r--r--include/colors.h33
-rw-r--r--lib/Makemodule.am3
-rw-r--r--lib/color-names.c52
-rw-r--r--lib/colors.c35
-rw-r--r--libsmartcols/src/Makemodule.am3
-rw-r--r--libsmartcols/src/smartcolsP.h2
8 files changed, 98 insertions, 71 deletions
diff --git a/include/Makemodule.am b/include/Makemodule.am
index 48a19541e..f0bb898c3 100644
--- a/include/Makemodule.am
+++ b/include/Makemodule.am
@@ -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
index 000000000..f04bc2ee2
--- /dev/null
+++ b/include/color-names.h
@@ -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 */
diff --git a/include/colors.h b/include/colors.h
index df6feb739..fda1ca98d 100644
--- a/include/colors.h
+++ b/include/colors.h
@@ -11,34 +11,7 @@
#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 */
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 6ef69570f..e81ca770a 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -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
index 000000000..923b2f039
--- /dev/null
+++ b/lib/color-names.c
@@ -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;
+}
diff --git a/lib/colors.c b/lib/colors.c
index da5a3e1f4..933bb810a 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -113,41 +113,6 @@ static int cmp_scheme_name(const void *a0, const void *b0)
}
/*
- * 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)
*/
static void colors_reset(struct ul_color_ctl *cc)
diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am
index 49ffea65f..45a7eeab4 100644
--- a/libsmartcols/src/Makemodule.am
+++ b/libsmartcols/src/Makemodule.am
@@ -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
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index c4fe725d0..95c00db8f 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -13,7 +13,7 @@
#include "c.h"
#include "list.h"
-#include "colors.h"
+#include "color-names.h"
#include "debug.h"
#include "libsmartcols.h"