]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
tty: Move tty related functions to separate files
authorMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 14:20:29 +0000 (16:20 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 16 Apr 2015 12:50:04 +0000 (14:50 +0200)
src/libstrongswan/Android.mk
src/libstrongswan/Makefile.am
src/libstrongswan/utils/utils.c
src/libstrongswan/utils/utils.h
src/libstrongswan/utils/utils/tty.c [new file with mode: 0644]
src/libstrongswan/utils/utils/tty.h [new file with mode: 0644]

index 7111218c800ede822ebf400113ffc37d08f642bc..325fb3575a5d6bd2550fa1afb028bcbd20cea544 100644 (file)
@@ -40,7 +40,8 @@ settings/settings_parser.c settings/settings_lexer.c utils/cpu_feature.c \
 utils/utils.c utils/chunk.c utils/debug.c utils/enum.c utils/identification.c \
 utils/lexparser.c utils/optionsfrom.c utils/capabilities.c utils/backtrace.c \
 utils/parser_helper.c utils/test.c utils/process.c utils/utils/strerror.c \
-utils/utils/atomics.c utils/utils/string.c utils/utils/memory.c
+utils/utils/atomics.c utils/utils/string.c utils/utils/memory.c \
+utils/utils/tty.c
 
 libstrongswan_la_SOURCES += \
     threading/thread.c \
index 95e2b8282e6ee3e16f93d675073fea9d786a6e10..b894b9defc2fda75ff8fb9aa95c5991c4631a419 100644 (file)
@@ -38,7 +38,8 @@ settings/settings_parser.y settings/settings_lexer.l utils/cpu_feature.c \
 utils/utils.c utils/chunk.c utils/debug.c utils/enum.c utils/identification.c \
 utils/lexparser.c utils/optionsfrom.c utils/capabilities.c utils/backtrace.c \
 utils/parser_helper.c utils/test.c utils/process.c utils/utils/strerror.c \
-utils/utils/atomics.c utils/utils/string.c utils/utils/memory.c
+utils/utils/atomics.c utils/utils/string.c utils/utils/memory.c \
+utils/utils/tty.c
 
 if !USE_WINDOWS
   libstrongswan_la_SOURCES += \
@@ -109,7 +110,7 @@ utils/printf_hook/printf_hook_vstr.h utils/printf_hook/printf_hook_builtin.h \
 utils/parser_helper.h utils/test.h utils/integrity_checker.h utils/process.h \
 utils/utils/strerror.h utils/compat/windows.h utils/compat/apple.h \
 utils/utils/atomics.h utils/utils/types.h utils/utils/byteorder.h \
-utils/utils/string.h utils/utils/memory.h
+utils/utils/string.h utils/utils/memory.h utils/utils/tty.h
 endif
 
 library.lo :   $(top_builddir)/config.status
index 497e0516e1e798da3cc213f98104deecd0b904ca..5585f1457b37ccb216911593a66cb115d3a2aa23 100644 (file)
@@ -322,73 +322,6 @@ bool mkdir_p(const char *path, mode_t mode)
        return TRUE;
 }
 
-ENUM(tty_color_names, TTY_RESET, TTY_BG_DEF,
-       "\e[0m",
-       "\e[1m",
-       "\e[4m",
-       "\e[5m",
-       "\e[30m",
-       "\e[31m",
-       "\e[32m",
-       "\e[33m",
-       "\e[34m",
-       "\e[35m",
-       "\e[36m",
-       "\e[37m",
-       "\e[39m",
-       "\e[40m",
-       "\e[41m",
-       "\e[42m",
-       "\e[43m",
-       "\e[44m",
-       "\e[45m",
-       "\e[46m",
-       "\e[47m",
-       "\e[49m",
-);
-
-/**
- * Get the escape string for a given TTY color, empty string on non-tty FILE
- */
-char* tty_escape_get(int fd, tty_escape_t escape)
-{
-       if (!isatty(fd))
-       {
-               return "";
-       }
-       switch (escape)
-       {
-               case TTY_RESET:
-               case TTY_BOLD:
-               case TTY_UNDERLINE:
-               case TTY_BLINKING:
-#ifdef WIN32
-                       return "";
-#endif
-               case TTY_FG_BLACK:
-               case TTY_FG_RED:
-               case TTY_FG_GREEN:
-               case TTY_FG_YELLOW:
-               case TTY_FG_BLUE:
-               case TTY_FG_MAGENTA:
-               case TTY_FG_CYAN:
-               case TTY_FG_WHITE:
-               case TTY_FG_DEF:
-               case TTY_BG_BLACK:
-               case TTY_BG_RED:
-               case TTY_BG_GREEN:
-               case TTY_BG_YELLOW:
-               case TTY_BG_BLUE:
-               case TTY_BG_MAGENTA:
-               case TTY_BG_CYAN:
-               case TTY_BG_WHITE:
-               case TTY_BG_DEF:
-                       return enum_to_name(tty_color_names, escape);
-               /* warn if a escape code is missing */
-       }
-       return "";
-}
-
 #ifndef HAVE_CLOSEFROM
 /**
  * Described in header.
index 19d5a5f61f04fc9ac6dec5bbb2f956393d7d8c0a..4ecd0d39de46764d4b96289fc04db0fc5e25ab33 100644 (file)
@@ -81,6 +81,7 @@
 #include "utils/string.h"
 #include "utils/memory.h"
 #include "utils/strerror.h"
+#include "utils/tty.h"
 #ifdef __APPLE__
 # include "compat/apple.h"
 #endif
@@ -355,46 +356,6 @@ enum status_t {
  */
 extern enum_name_t *status_names;
 
-typedef enum tty_escape_t tty_escape_t;
-
-/**
- * Excape codes for tty colors
- */
-enum tty_escape_t {
-       /** text properties */
-       TTY_RESET,
-       TTY_BOLD,
-       TTY_UNDERLINE,
-       TTY_BLINKING,
-
-       /** foreground colors */
-       TTY_FG_BLACK,
-       TTY_FG_RED,
-       TTY_FG_GREEN,
-       TTY_FG_YELLOW,
-       TTY_FG_BLUE,
-       TTY_FG_MAGENTA,
-       TTY_FG_CYAN,
-       TTY_FG_WHITE,
-       TTY_FG_DEF,
-
-       /** background colors */
-       TTY_BG_BLACK,
-       TTY_BG_RED,
-       TTY_BG_GREEN,
-       TTY_BG_YELLOW,
-       TTY_BG_BLUE,
-       TTY_BG_MAGENTA,
-       TTY_BG_CYAN,
-       TTY_BG_WHITE,
-       TTY_BG_DEF,
-};
-
-/**
- * Get the escape string for a given TTY color, empty string on non-tty fd
- */
-char* tty_escape_get(int fd, tty_escape_t escape);
-
 /**
  * Handle struct timeval like an own type.
  */
diff --git a/src/libstrongswan/utils/utils/tty.c b/src/libstrongswan/utils/utils/tty.c
new file mode 100644 (file)
index 0000000..7cce71d
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2008-2014 Tobias Brunner
+ * Copyright (C) 2005-2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include <utils/utils.h>
+
+#include <unistd.h>
+
+ENUM(tty_color_names, TTY_RESET, TTY_BG_DEF,
+       "\e[0m",
+       "\e[1m",
+       "\e[4m",
+       "\e[5m",
+       "\e[30m",
+       "\e[31m",
+       "\e[32m",
+       "\e[33m",
+       "\e[34m",
+       "\e[35m",
+       "\e[36m",
+       "\e[37m",
+       "\e[39m",
+       "\e[40m",
+       "\e[41m",
+       "\e[42m",
+       "\e[43m",
+       "\e[44m",
+       "\e[45m",
+       "\e[46m",
+       "\e[47m",
+       "\e[49m",
+);
+
+/**
+ * Get the escape string for a given TTY color, empty string on non-tty FILE
+ */
+char* tty_escape_get(int fd, tty_escape_t escape)
+{
+       if (!isatty(fd))
+       {
+               return "";
+       }
+       switch (escape)
+       {
+               case TTY_RESET:
+               case TTY_BOLD:
+               case TTY_UNDERLINE:
+               case TTY_BLINKING:
+#ifdef WIN32
+                       return "";
+#endif
+               case TTY_FG_BLACK:
+               case TTY_FG_RED:
+               case TTY_FG_GREEN:
+               case TTY_FG_YELLOW:
+               case TTY_FG_BLUE:
+               case TTY_FG_MAGENTA:
+               case TTY_FG_CYAN:
+               case TTY_FG_WHITE:
+               case TTY_FG_DEF:
+               case TTY_BG_BLACK:
+               case TTY_BG_RED:
+               case TTY_BG_GREEN:
+               case TTY_BG_YELLOW:
+               case TTY_BG_BLUE:
+               case TTY_BG_MAGENTA:
+               case TTY_BG_CYAN:
+               case TTY_BG_WHITE:
+               case TTY_BG_DEF:
+                       return enum_to_name(tty_color_names, escape);
+               /* warn if a escape code is missing */
+       }
+       return "";
+}
diff --git a/src/libstrongswan/utils/utils/tty.h b/src/libstrongswan/utils/utils/tty.h
new file mode 100644 (file)
index 0000000..6cd285a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2008-2014 Tobias Brunner
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup tty_i tty
+ * @{ @ingroup utils_i
+ */
+
+#ifndef TTY_H_
+#define TTY_H_
+
+typedef enum tty_escape_t tty_escape_t;
+
+/**
+ * Excape codes for tty colors
+ */
+enum tty_escape_t {
+       /** text properties */
+       TTY_RESET,
+       TTY_BOLD,
+       TTY_UNDERLINE,
+       TTY_BLINKING,
+
+       /** foreground colors */
+       TTY_FG_BLACK,
+       TTY_FG_RED,
+       TTY_FG_GREEN,
+       TTY_FG_YELLOW,
+       TTY_FG_BLUE,
+       TTY_FG_MAGENTA,
+       TTY_FG_CYAN,
+       TTY_FG_WHITE,
+       TTY_FG_DEF,
+
+       /** background colors */
+       TTY_BG_BLACK,
+       TTY_BG_RED,
+       TTY_BG_GREEN,
+       TTY_BG_YELLOW,
+       TTY_BG_BLUE,
+       TTY_BG_MAGENTA,
+       TTY_BG_CYAN,
+       TTY_BG_WHITE,
+       TTY_BG_DEF,
+};
+
+/**
+ * Get the escape string for a given TTY color, empty string on non-tty fd
+ */
+char* tty_escape_get(int fd, tty_escape_t escape);
+
+#endif /** TTY_H_ @} */