diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-18 17:44:00 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-18 17:44:00 -0400 |
commit | 443ae9b89e9e1534407c2dd273a4e47ddb3610c7 (patch) | |
tree | 174fb2183b500ef9f622dab0cff43d7616730016 | |
parent | More patches for wlc compat (diff) | |
parent | added sway_assert function (diff) | |
download | sway-443ae9b89e9e1534407c2dd273a4e47ddb3610c7.tar.gz sway-443ae9b89e9e1534407c2dd273a4e47ddb3610c7.tar.zst sway-443ae9b89e9e1534407c2dd273a4e47ddb3610c7.zip |
Merge pull request #72 from minus7/assert
added sway_assert function
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/log.h | 6 | ||||
-rw-r--r-- | sway/log.c | 22 |
3 files changed, 24 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ba2f8be3..d190cd8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -3,7 +3,6 @@ project(sway C) | |||
3 | set(CMAKE_C_FLAGS "-g") | 3 | set(CMAKE_C_FLAGS "-g") |
4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") | 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") |
5 | add_definitions("-Wall") | 5 | add_definitions("-Wall") |
6 | set(CMAKE_BUILD_TYPE Debug) | ||
7 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) | 6 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) |
8 | 7 | ||
9 | find_package(XKBCommon REQUIRED) | 8 | find_package(XKBCommon REQUIRED) |
diff --git a/include/log.h b/include/log.h index d35b2a54..44f84940 100644 --- a/include/log.h +++ b/include/log.h | |||
@@ -1,5 +1,6 @@ | |||
1 | #ifndef _SWAY_LOG_H | 1 | #ifndef _SWAY_LOG_H |
2 | #define _SWAY_LOG_H | 2 | #define _SWAY_LOG_H |
3 | #include <stdbool.h> | ||
3 | 4 | ||
4 | typedef enum { | 5 | typedef enum { |
5 | L_SILENT = 0, | 6 | L_SILENT = 0, |
@@ -10,7 +11,8 @@ typedef enum { | |||
10 | 11 | ||
11 | void init_log(int verbosity); | 12 | void init_log(int verbosity); |
12 | void sway_log_colors(int mode); | 13 | void sway_log_colors(int mode); |
13 | void sway_log(int verbosity, char* format, ...) __attribute__((format(printf,2,3))); | 14 | void sway_log(int verbosity, const char* format, ...) __attribute__((format(printf,2,3))); |
14 | void sway_abort(char* format, ...)__attribute__((format(printf,1,2))); | 15 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); |
16 | bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); | ||
15 | 17 | ||
16 | #endif | 18 | #endif |
@@ -4,6 +4,7 @@ | |||
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <signal.h> | ||
7 | 8 | ||
8 | int colored = 1; | 9 | int colored = 1; |
9 | int v = 0; | 10 | int v = 0; |
@@ -32,7 +33,7 @@ void sway_log_colors(int mode) { | |||
32 | colored = (mode == 1) ? 1 : 0; | 33 | colored = (mode == 1) ? 1 : 0; |
33 | } | 34 | } |
34 | 35 | ||
35 | void sway_abort(char *format, ...) { | 36 | void sway_abort(const char *format, ...) { |
36 | fprintf(stderr, "ERROR: "); | 37 | fprintf(stderr, "ERROR: "); |
37 | va_list args; | 38 | va_list args; |
38 | va_start(args, format); | 39 | va_start(args, format); |
@@ -42,7 +43,7 @@ void sway_abort(char *format, ...) { | |||
42 | exit(1); | 43 | exit(1); |
43 | } | 44 | } |
44 | 45 | ||
45 | void sway_log(int verbosity, char* format, ...) { | 46 | void sway_log(int verbosity, const char* format, ...) { |
46 | if (verbosity <= v) { | 47 | if (verbosity <= v) { |
47 | int c = verbosity; | 48 | int c = verbosity; |
48 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { | 49 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { |
@@ -64,3 +65,20 @@ void sway_log(int verbosity, char* format, ...) { | |||
64 | fprintf(stderr, "\n"); | 65 | fprintf(stderr, "\n"); |
65 | } | 66 | } |
66 | } | 67 | } |
68 | |||
69 | bool sway_assert(bool condition, const char* format, ...) { | ||
70 | if (condition) { | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | #ifndef NDEBUG | ||
75 | raise(SIGABRT); | ||
76 | #endif | ||
77 | |||
78 | va_list args; | ||
79 | va_start(args, format); | ||
80 | sway_log(L_ERROR, format, args); | ||
81 | va_end(args); | ||
82 | |||
83 | return false; | ||
84 | } | ||