wte.h, file.c: refactor colors, add info-makro
This commit is contained in:
parent
49fe655474
commit
07dff4f2d2
2 changed files with 20 additions and 6 deletions
|
@ -24,10 +24,11 @@ int create_data_dir()
|
|||
struct stat st;
|
||||
int dir_exists = stat(DATA_DIR, &st);
|
||||
if (-1 == dir_exists) {
|
||||
dbg("%s", "creating data dir");
|
||||
char *path = get_path();
|
||||
if (path && 0 != (ret = mkdir(path, 0700))) {
|
||||
error("%s", "failed to create directory");
|
||||
} else {
|
||||
info("%s", "created data directory");
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
|
@ -48,6 +49,11 @@ int remove_data_dir()
|
|||
if (path) {
|
||||
// here: for loop to delete all entries in directory
|
||||
ret = remove(path);
|
||||
if (0 == ret) {
|
||||
info("%s", "removed data directory");
|
||||
} else {
|
||||
error("%s", "failed to remove data directory");
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
dbg("ret: %d", ret);
|
||||
|
|
18
src/wte.h
18
src/wte.h
|
@ -1,19 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#define error(format, ...) do {\
|
||||
fprintf(stderr, c_red "[ERROR] "format c_end"\n", __VA_ARGS__); \
|
||||
fprintf(stderr, c_red format c_end"\n", __VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#define info(format, ...) do {\
|
||||
fprintf(stdout, c_blue format c_end "\n", __VA_ARGS__); \
|
||||
} while(0);
|
||||
|
||||
#ifdef DEBUG
|
||||
#define dbg(format, ...) do { \
|
||||
printf("\033[1;35m[DEBUG] (func: %s) msg:\033[0;35m " format "\033[0m\n",__func__, __VA_ARGS__); \
|
||||
printf(c_bold c_lila"[DEBUG] (func: %s) msg: " c_end c_lila format c_end "\n",__func__, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#else
|
||||
#define dbg(format, ...)
|
||||
#endif
|
||||
|
||||
#define c_red "\033[1;31m"
|
||||
#define c_green "\033[1;32m"
|
||||
#define c_yellow "\033[1;33m"
|
||||
/* easy colors */
|
||||
#define c_red "\033[31m"
|
||||
#define c_green "\033[32m"
|
||||
#define c_yellow "\033[33m"
|
||||
#define c_blue "\033[34m"
|
||||
#define c_lila "\033[35m"
|
||||
#define c_bold "\033[1m"
|
||||
#define c_end "\033[0m"
|
||||
|
||||
/* path to data storage */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue