diff options
author | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-10-04 17:20:37 +0300 |
---|---|---|
committer | Anastasis Grammenos <anastasis.gramm2@gmail.com> | 2018-10-04 17:20:37 +0300 |
commit | 764a205fe9676afcdb94998b5e553d650bda86ba (patch) | |
tree | d3d0650a60218e6a470a7a9d9e0bfbf9860a8833 /src/ckerrlog.c | |
parent | 9c24e438b689af042672182f6d87f824ef435492 (diff) | |
download | ck-764a205fe9676afcdb94998b5e553d650bda86ba.tar.gz ck-764a205fe9676afcdb94998b5e553d650bda86ba.tar.bz2 ck-764a205fe9676afcdb94998b5e553d650bda86ba.zip |
Errlog with cklist, verbose flag, bugfix in search
Diffstat (limited to 'src/ckerrlog.c')
-rw-r--r-- | src/ckerrlog.c | 116 |
1 files changed, 57 insertions, 59 deletions
diff --git a/src/ckerrlog.c b/src/ckerrlog.c index 9e1fc51..9a63ffd 100644 --- a/src/ckerrlog.c +++ b/src/ckerrlog.c @@ -12,13 +12,14 @@ #include "ckerrlog.h" #include "ckutil.h" +#include "cklist.h" -#define COMPONENT "ckerrlog" +ERRLOG(ckerrlog); static int loglvl; static char buf[STR_M]; -#define X(stream) static char *stream; +#define X(stream) static cklist *stream; CK_STREAMS #undef X @@ -39,53 +40,65 @@ void initialize_errlog() { cklog("%s Log session started", get_time()); } -void report_errlog() { - if (err) - printf("Errors:\n%s", err); - free(err); - if (log) - printf("Logs:\n%s", log); - free(log); -} +#define X(stream) \ + void add_ ## stream ## _with_delim(char *delim, char *txt, \ + va_list args) { \ + char tmp[STR_L]; \ + vsprintf(tmp, txt, args); \ + if (stream) { \ + list_add(stream, tmp); \ + list_add(stream, delim); \ + return; \ + } \ + stream = list_make_and_add(tmp); \ + list_add(stream, delim); \ + } +CK_STREAMS +#undef X -#define X(stream) \ - void add_ ## stream ## _with_delim(char *delim, char *txt, \ - va_list args) { \ - char tmp[STR_L]; \ - vsprintf(tmp, txt, args); \ - if (stream) { \ - stream = (char *)realloc(stream, strlen(stream) + \ - strlen(tmp) + strlen(delim) + 1); \ - strcat(stream, tmp); \ - strcat(stream, delim); \ - return; \ - } \ - stream = (char *)malloc(strlen(tmp) + strlen(delim) + 1); \ - strcpy(stream, tmp); \ - strcat(stream, delim); \ +#define X(stream) \ + void ck## stream(char *txt, ...) { \ + va_list args; \ + va_start(args, txt); \ + add_## stream ##_with_delim("\n", txt, args); \ + va_end(args); \ } CK_STREAMS #undef X -void ckerr(char *txt, ...) { - va_list args; - va_start(args, txt); - add_err_with_delim("\n", txt, args); - va_end(args); -} +#define X(stream) \ + void reset_## stream() { \ + list_free(stream); \ + stream = NULL; \ + } +CK_STREAMS +#undef X -void cklog(char *txt, ...) { - va_list args; - va_start(args, txt); - add_log_with_delim("\n", txt, args); - va_end(args); -} +#define X(stream) \ + void report_## stream() { \ + list_print_concat(stream); \ + reset_## stream(); \ + } +CK_STREAMS +#undef X -void ckhelp(char *txt, ...) { - va_list args; - va_start(args, txt); - add_help_with_delim("\n", txt, args); - va_end(args); +void report_errlog() { + if (!loglvl) { +#define X(stream) \ + if (stream) { \ + reset_##stream(); \ + } + CK_STREAMS +#undef X + return; + } +#define X(stream) \ + if (stream) { \ + printf("%s:\n", #stream); \ + report_##stream(); \ + } + CK_STREAMS +#undef X } void ckerr_add_component(char *txt, ...) { @@ -95,21 +108,6 @@ void ckerr_add_component(char *txt, ...) { va_end(args); } -void ckhelp_add_component(char *txt, ...) { - va_list args; - va_start(args, txt); - add_help_with_delim(" ", txt, args); - va_end(args); -} - -void report_err() { - printf("%s", err); - free(err); - err = NULL; -} - -void report_help() { - printf("%s", help); - free(help); - help = NULL; +extern void errlog_set_verbose(int level) { + loglvl = level; } |