Added .clang-format and formatted source code
This commit is contained in:
1 parent
26fa80f7e0
commit
359f282784
20 files changed
+16268
-15478
No files matched your search
+1243
-1178
File diff suppressed because it is too large.
Load diff
+667
-649
File diff suppressed because it is too large.
Load diff
+985
-932
File diff suppressed because it is too large.
Load diff
+1109
-1037
File diff suppressed because it is too large.
Load diff
+639
-629
File diff suppressed because it is too large.
Load diff
+1011
-986
File diff suppressed because it is too large.
Load diff
+931
-911
File diff suppressed because it is too large.
Load diff
+812
-791
File diff suppressed because it is too large.
Load diff
+1177
-1113
File diff suppressed because it is too large.
Load diff
+1317
-1234
File diff suppressed because it is too large.
Load diff
+615
-600
File diff suppressed because it is too large.
Load diff
+734
-719
File diff suppressed because it is too large.
Load diff
+544
-533
File diff suppressed because it is too large.
Load diff
+1042
-1027
File diff suppressed because it is too large.
Load diff
+1199
-1171
File diff suppressed because it is too large.
Load diff
+2121
-1887
File diff suppressed because it is too large.
Load diff
+24
-14
@@ -11,22 +11,32 @@
|
||||
#ifndef CMC_FOR_EACH_H
|
||||
#define CMC_FOR_EACH_H
|
||||
|
||||
#define CMC_FOR_EACH(PFX, SNAME, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
for (struct SNAME##_iter iter = (TARGET)->it_start(TARGET); !PFX##_iter_end(&iter); PFX##_iter_next(&iter)) \
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
#define CMC_FOR_EACH(PFX, SNAME, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
for (struct SNAME##_iter iter = (TARGET)->it_start(TARGET); \
|
||||
!PFX##_iter_end(&iter); PFX##_iter_next(&iter)) \
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CMC_FOR_EACH_REV(PFX, SNAME, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
for (struct SNAME##_iter iter = (TARGET)->it_end(TARGET); !PFX##_iter_start(&iter); PFX##_iter_prev(&iter)) \
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
#define CMC_FOR_EACH_REV(PFX, SNAME, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
for (struct SNAME##_iter iter = (TARGET)->it_end(TARGET); \
|
||||
!PFX##_iter_start(&iter); PFX##_iter_prev(&iter)) \
|
||||
{ \
|
||||
BODY; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET) \
|
||||
for (struct SNAME##_iter ITERNAME = (TARGET)->it_start(TARGET); \
|
||||
!PFX##_iter_end(&ITERNAME); PFX##_iter_next(&ITERNAME))
|
||||
|
||||
#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET) \
|
||||
for (struct SNAME##_iter ITERNAME = (TARGET)->it_end(TARGET); \
|
||||
!PFX##_iter_start(&ITERNAME); PFX##_iter_prev(&ITERNAME))
|
||||
|
||||
#endif /* CMC_FOR_EACH_H */
|
||||
+31
-21
@@ -59,16 +59,18 @@
|
||||
#ifndef CMC_LOG_H
|
||||
#define CMC_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
static const char *cmc_log_names[] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
|
||||
static const char *cmc_log_names[] = { "TRACE", "DEBUG", "INFO",
|
||||
"WARN", "ERROR", "FATAL" };
|
||||
|
||||
#ifdef CMC_LOG_COLOR
|
||||
|
||||
static const char *cmc_log_color[] = {"\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"};
|
||||
static const char *cmc_log_color[] = { "\x1b[94m", "\x1b[36m", "\x1b[32m",
|
||||
"\x1b[33m", "\x1b[31m", "\x1b[35m" };
|
||||
|
||||
#endif
|
||||
|
||||
@@ -81,7 +83,7 @@ static struct
|
||||
FILE *file; /* File for Output */
|
||||
bool enabled; /* Logging enabled */
|
||||
|
||||
} cmc_log_config = {0, 0, true, true, NULL, true};
|
||||
} cmc_log_config = { 0, 0, true, true, NULL, true };
|
||||
|
||||
enum cmc_log_type
|
||||
{
|
||||
@@ -93,21 +95,29 @@ enum cmc_log_type
|
||||
CMC_LOG_FATAL = 6
|
||||
};
|
||||
|
||||
#define cmc_log_trace(fmt, ...) cmc_log(CMC_LOG_TRACE, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_debug(fmt, ...) cmc_log(CMC_LOG_DEBUG, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_info(fmt, ...) cmc_log(CMC_LOG_INFO, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_warn(fmt, ...) cmc_log(CMC_LOG_WARN, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_error(fmt, ...) cmc_log(CMC_LOG_ERROR, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_fatal(fmt, ...) cmc_log(CMC_LOG_FATAL, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_trace(fmt, ...) \
|
||||
cmc_log(CMC_LOG_TRACE, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_debug(fmt, ...) \
|
||||
cmc_log(CMC_LOG_DEBUG, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_info(fmt, ...) \
|
||||
cmc_log(CMC_LOG_INFO, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_warn(fmt, ...) \
|
||||
cmc_log(CMC_LOG_WARN, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_error(fmt, ...) \
|
||||
cmc_log(CMC_LOG_ERROR, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
#define cmc_log_fatal(fmt, ...) \
|
||||
cmc_log(CMC_LOG_FATAL, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
|
||||
|
||||
static void cmc_log(enum cmc_log_type log, const char *filename, const char *funcname, int line, const char *fmt, ...)
|
||||
static void cmc_log(enum cmc_log_type log, const char *filename,
|
||||
const char *funcname, int line, const char *fmt, ...)
|
||||
{
|
||||
if (!cmc_log_config.enabled)
|
||||
return;
|
||||
|
||||
if (cmc_log_config.tenabled)
|
||||
{
|
||||
if (cmc_log_config.tlevel < 0 && ((int)log * -1) < cmc_log_config.tlevel)
|
||||
if (cmc_log_config.tlevel < 0 &&
|
||||
((int)log * -1) < cmc_log_config.tlevel)
|
||||
return;
|
||||
else if (cmc_log_config.tlevel > 0 && (int)log < cmc_log_config.tlevel)
|
||||
return;
|
||||
@@ -121,13 +131,11 @@ static void cmc_log(enum cmc_log_type log, const char *filename, const char *fun
|
||||
time[strftime(time, sizeof(time), "%H:%M:%S", lt)] = '\0';
|
||||
|
||||
#ifdef CMC_LOG_COLOR
|
||||
fprintf(stderr,
|
||||
"%s %s%5s\x1b[0m \x1b[90m%s at %s:%d:\x1b[0m ",
|
||||
time, cmc_log_color[i], cmc_log_names[i], filename, funcname, line);
|
||||
fprintf(stderr, "%s %s%5s\x1b[0m \x1b[90m%s at %s:%d:\x1b[0m ", time,
|
||||
cmc_log_color[i], cmc_log_names[i], filename, funcname, line);
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"%s %5s %s at %s:%d: ",
|
||||
time, cmc_log_names[i], filename, funcname, line);
|
||||
fprintf(stderr, "%s %5s %s at %s:%d: ", time, cmc_log_names[i],
|
||||
filename, funcname, line);
|
||||
#endif
|
||||
|
||||
va_list args;
|
||||
@@ -141,7 +149,8 @@ static void cmc_log(enum cmc_log_type log, const char *filename, const char *fun
|
||||
|
||||
if (cmc_log_config.file && cmc_log_config.fenabled)
|
||||
{
|
||||
if (cmc_log_config.flevel < 0 && ((int)log * -1) < cmc_log_config.flevel)
|
||||
if (cmc_log_config.flevel < 0 &&
|
||||
((int)log * -1) < cmc_log_config.flevel)
|
||||
return;
|
||||
else if (cmc_log_config.flevel > 0 && (int)log < cmc_log_config.flevel)
|
||||
return;
|
||||
@@ -154,7 +163,8 @@ static void cmc_log(enum cmc_log_type log, const char *filename, const char *fun
|
||||
char time[32];
|
||||
time[strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", lt)] = '\0';
|
||||
|
||||
fprintf(cmc_log_config.file, "%s %5s %s at %s:%d: ", time, cmc_log_names[i], filename, funcname, line);
|
||||
fprintf(cmc_log_config.file, "%s %5s %s at %s:%d: ", time,
|
||||
cmc_log_names[i], filename, funcname, line);
|
||||
|
||||
va_list file_args;
|
||||
va_start(file_args, fmt);
|
||||
|
||||
+48
-46
@@ -56,7 +56,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#ifdef CMC_TEST_COLOR
|
||||
static const char *cmc_test_color[] = {"\x1b[32m", "\x1b[31m", "\x1b[35m"};
|
||||
static const char *cmc_test_color[] = { "\x1b[32m", "\x1b[31m", "\x1b[35m" };
|
||||
#endif
|
||||
|
||||
struct cmc_test_info
|
||||
@@ -69,15 +69,14 @@ struct cmc_test_info
|
||||
};
|
||||
|
||||
/* Logging function */
|
||||
static void cmc_test_log(const char *unit_name, const char *current_test, bool aborted, bool passed)
|
||||
static void cmc_test_log(const char *unit_name, const char *current_test,
|
||||
bool aborted, bool passed)
|
||||
{
|
||||
if (aborted)
|
||||
{
|
||||
#ifdef CMC_TEST_COLOR
|
||||
printf("UNIT_TEST %s %sABORTED\x1b[0m AT %s\n",
|
||||
unit_name,
|
||||
cmc_test_color[2],
|
||||
current_test);
|
||||
printf("UNIT_TEST %s %sABORTED\x1b[0m AT %s\n", unit_name,
|
||||
cmc_test_color[2], current_test);
|
||||
#else
|
||||
printf("UNIT_TEST %s ABORTED at %s\n", unit_name, current_test);
|
||||
#endif
|
||||
@@ -85,52 +84,55 @@ static void cmc_test_log(const char *unit_name, const char *current_test, bool a
|
||||
else
|
||||
{
|
||||
#ifdef CMC_TEST_COLOR
|
||||
printf("Test from %s %s%7s\x1b[0m %s\n",
|
||||
unit_name,
|
||||
printf("Test from %s %s%7s\x1b[0m %s\n", unit_name,
|
||||
passed ? cmc_test_color[0] : cmc_test_color[1],
|
||||
passed ? "PASSED" : "FAILED",
|
||||
current_test);
|
||||
passed ? "PASSED" : "FAILED", current_test);
|
||||
#else
|
||||
printf("Test from %s %7s %s\n", unit_name, passed ? "PASSED" : "FAILED", current_test);
|
||||
printf("Test from %s %7s %s\n", unit_name, passed ? "PASSED" : "FAILED",
|
||||
current_test);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
|
||||
uintmax_t UNAME(void) \
|
||||
{ \
|
||||
const char *unit_name = #UNAME; \
|
||||
const char *current_test = NULL; \
|
||||
\
|
||||
struct cmc_test_info tinfo = {0}; \
|
||||
struct cmc_timer timer = {0}; \
|
||||
\
|
||||
tinfo.verbose = VERBOSE; \
|
||||
\
|
||||
/* Tests */ \
|
||||
cmc_timer_start(timer); \
|
||||
\
|
||||
BODY; \
|
||||
\
|
||||
cmc_timer_stop(timer); \
|
||||
cmc_timer_calc(timer); \
|
||||
\
|
||||
unittest_abort: \
|
||||
if (tinfo.aborted) \
|
||||
{ \
|
||||
cmc_test_log(unit_name, current_test, true, false); \
|
||||
} \
|
||||
\
|
||||
printf("+--------------------------------------------------+\n"); \
|
||||
printf("| Unit Test Report : %-30s|\n", unit_name); \
|
||||
printf("| TOTAL : %10" PRIuMAX " |\n", tinfo.total); \
|
||||
printf("| PASSED : %10" PRIuMAX " |\n", tinfo.passed); \
|
||||
printf("| FAILED : %10" PRIuMAX " |\n", tinfo.failed); \
|
||||
printf("| |\n"); \
|
||||
printf("| Total Unit Test Runtime : %9.0f milliseconds |\n", timer.result); \
|
||||
printf("+--------------------------------------------------+\n"); \
|
||||
\
|
||||
return tinfo.failed; \
|
||||
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
|
||||
uintmax_t UNAME(void) \
|
||||
{ \
|
||||
const char *unit_name = #UNAME; \
|
||||
const char *current_test = NULL; \
|
||||
\
|
||||
struct cmc_test_info tinfo = { 0 }; \
|
||||
struct cmc_timer timer = { 0 }; \
|
||||
\
|
||||
tinfo.verbose = VERBOSE; \
|
||||
\
|
||||
/* Tests */ \
|
||||
cmc_timer_start(timer); \
|
||||
\
|
||||
BODY; \
|
||||
\
|
||||
cmc_timer_stop(timer); \
|
||||
cmc_timer_calc(timer); \
|
||||
\
|
||||
unittest_abort: \
|
||||
if (tinfo.aborted) \
|
||||
{ \
|
||||
cmc_test_log(unit_name, current_test, true, false); \
|
||||
} \
|
||||
\
|
||||
printf("+--------------------------------------------------+\n"); \
|
||||
printf("| Unit Test Report : %-30s|\n", unit_name); \
|
||||
printf("| TOTAL : %10" PRIuMAX " |\n", \
|
||||
tinfo.total); \
|
||||
printf("| PASSED : %10" PRIuMAX " |\n", \
|
||||
tinfo.passed); \
|
||||
printf("| FAILED : %10" PRIuMAX " |\n", \
|
||||
tinfo.failed); \
|
||||
printf("| |\n"); \
|
||||
printf("| Total Unit Test Runtime : %9.0f milliseconds |\n", \
|
||||
timer.result); \
|
||||
printf("+--------------------------------------------------+\n"); \
|
||||
\
|
||||
return tinfo.failed; \
|
||||
}
|
||||
|
||||
#define CMC_CREATE_TEST(TNAME, BODY) \
|
||||
|
||||
Reference in new issue
Block a user