simpler log functions - ploot - simple plotting tools | |
git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
commit 1d056caf74acaf182318297e2911fa8595fbd45c | |
parent f57e3eaca390e814349d3f6bcafde07b82041217 | |
Author: Josuah Demangeon <[email protected]> | |
Date: Tue, 25 Feb 2020 23:36:06 +0100 | |
simpler log functions | |
Diffstat: | |
M ploot-braille.c | 6 +++--- | |
M ploot-farbfeld.c | 6 +++--- | |
M ploot-feed.c | 18 +++++++++--------- | |
M src/csv.c | 20 ++++++++++---------- | |
M src/log.c | 22 ++++++++++------------ | |
M src/log.h | 4 ++-- | |
M src/scale.c | 2 +- | |
7 files changed, 38 insertions(+), 40 deletions(-) | |
--- | |
diff --git a/ploot-braille.c b/ploot-braille.c | |
@@ -123,13 +123,13 @@ plot(struct csv *vl, FILE *fp, size_t ncol, int row, int … | |
assert(drw = drawille_new(row, col)); | |
fprintf(fp, " %s\n", vl->label); | |
if (braille_histogram(vl, drw, tmin, tmax, vmin, vmax) == -1) | |
- fatal(1, "allocating drawille canvas"); | |
+ die(1, "allocating drawille canvas"); | |
if (braille_render(drw, fp, vmin, vmax) == -1) | |
- fatal(1, "rendering braille canvas"); | |
+ die(1, "rendering braille canvas"); | |
free(drw); | |
} | |
if (braille_axis_x(fp, tmin, tmax, tstep, col) == -1) | |
- fatal(1, "printing x axis");; | |
+ die(1, "printing x axis");; | |
} | |
diff --git a/ploot-farbfeld.c b/ploot-farbfeld.c | |
@@ -262,7 +262,7 @@ argv_to_color(struct ffcolor **cl, char **argv) | |
{ | |
for (; *argv != NULL; cl++, argv++) | |
if ((*cl = name_to_color(*argv)) == NULL) | |
- fatal(1, "unknown color name: %s", *argv); | |
+ die(1, "unknown color name: %s", *argv); | |
} | |
static void | |
@@ -307,9 +307,9 @@ main(int argc, char **argv) | |
csv_labels(stdin, &vl, &ncol); | |
if (ncol > (size_t)argc) | |
- fatal(1, "too many columns or not enough arguments"); | |
+ die(1, "too many columns or not enough arguments"); | |
else if (ncol < (size_t)argc) | |
- fatal(1, "too many arguments or not enough columns"); | |
+ die(1, "too many arguments or not enough columns"); | |
csv_values(stdin, vl, ncol); | |
argv_to_color(cl, argv); | |
diff --git a/ploot-feed.c b/ploot-feed.c | |
@@ -60,19 +60,19 @@ plot_row(long *out, char *line, double *max, int nrow, int … | |
tok = strsep(&line, ","); | |
if (!tok) | |
- fatal(100, "*** missing epoch value"); | |
+ die(100, "*** missing epoch value"); | |
epoch = strtol(tok, NULL, 10); | |
if (errno) | |
error("*** parsing epoch '%s'", tok); | |
for (n = 0; (tok = strsep(&line, ",")) != NULL; n++) { | |
if (n >= ncol) | |
- fatal(100, "too many values"); | |
+ die(100, "too many values"); | |
val = atof(tok); | |
plot_val(out + n * width, val, max[n], nrow); | |
} | |
if (n < ncol) | |
- fatal(100, "not enough values"); | |
+ die(100, "not enough values"); | |
return epoch; | |
} | |
@@ -100,7 +100,7 @@ plot_line(long *out, double *max, int ncol) | |
for (nrow = 0; nrow < 4; nrow++) { | |
if (getline(&line, &sz, stdin) == -1) { | |
if (ferror(stdin)) | |
- fatal(111, "reading row from stdin"); | |
+ die(111, "reading row from stdin"); | |
exit(0); | |
} | |
epoch = plot_row(out, line, max, nrow, ncol); | |
@@ -179,21 +179,21 @@ read_labels(char **labv) | |
line = NULL, sz = 0; | |
if (getline(&line, &sz, stdin) == -1) { | |
if (ferror(stdin)) | |
- fatal(111, "reading labels from stdin"); | |
- fatal(100, "missing label line", stderr); | |
+ die(111, "reading labels from stdin"); | |
+ die(100, "missing label line", stderr); | |
} | |
strchomp(line); | |
cp = line; | |
if (strcmp(strsep(&cp, ","), "epoch") != 0) | |
- fatal(100, "first label must be 'epoch'"); | |
+ die(100, "first label must be 'epoch'"); | |
for (ncol = 0; (tok = strsep(&cp, ",")) != NULL; ncol++, labv++) | |
*labv = tok; | |
*labv = NULL; | |
if (ncol < 1) | |
- fatal(100, "no label found"); | |
+ die(100, "no label found"); | |
return ncol; | |
} | |
@@ -250,7 +250,7 @@ main(int argc, char **argv) | |
width = (wflag - sizeof("XXxXXxXX _")) / ncol - sizeof("|"); | |
fmt_labels(labels, ncol, labv); | |
if (ncol != nmax) | |
- fatal(100, "not as many labels and arguments"); | |
+ die(100, "not as many labels and arguments"); | |
plot(labels, max, ncol); | |
return 0; | |
diff --git a/src/csv.c b/src/csv.c | |
@@ -43,24 +43,24 @@ csv_addrow(struct csv *vl, size_t ncol, char *line) | |
field = strsep(&line, ","); | |
if (!field) | |
- fatal(1, "missing epoch at row %zu", vl->n); | |
+ die(1, "missing epoch at row %zu", vl->n); | |
l = strtol(field, NULL, 10); | |
if (errno) | |
- fatal(100, "parsing number '%s'", field); | |
+ die(100, "parsing number '%s'", field); | |
csv_addtime(vl, l); | |
tbuf = vl[0].t; | |
for (; (field = strsep(&line, ",")); ncol--, vl->n++, vl++) { | |
if (ncol == 0) | |
- fatal(1, "too many fields at line %zu", vl->n); | |
+ die(1, "too many fields at line %zu", vl->n); | |
d = strtod(field, NULL); | |
if (errno) | |
- fatal(100, "parsing double '%s'", field); | |
+ die(100, "parsing double '%s'", field); | |
csv_addval(vl, d); | |
vl->t = tbuf; | |
} | |
if (ncol > 0) | |
- fatal(1, "too few fields at line %zu", vl->n); | |
+ die(1, "too few fields at line %zu", vl->n); | |
} | |
/* | |
@@ -78,14 +78,14 @@ csv_labels(FILE *fp, struct csv **vl, size_t *ncol) | |
sz = 0, line = NULL; | |
r = getline(&line, &sz, fp); | |
if (ferror(fp)) | |
- fatal(111, "error while reading from file"); | |
+ die(111, "error while reading from file"); | |
if (r == -1) | |
- fatal(100, "missing label line"); | |
+ die(100, "missing label line"); | |
strchomp(line); | |
cp = line; | |
if (strcmp(strsep(&cp, ","), "epoch") != 0) | |
- fatal(1, "first label must be 'epoch'"); | |
+ die(1, "first label must be 'epoch'"); | |
*vl = NULL; | |
*ncol = 0; | |
@@ -114,9 +114,9 @@ csv_values(FILE *fp, struct csv *vl, size_t ncol) | |
while (getline(&line, &sz, fp) > -1) | |
csv_addrow(vl, ncol, line); | |
if (vl->n == 0) | |
- fatal(1, "no value could be read"); | |
+ die(1, "no value could be read"); | |
if (vl->n == 1) | |
- fatal(1, "only one value could be read"); | |
+ die(1, "only one value could be read"); | |
free(line); | |
} | |
diff --git a/src/log.c b/src/log.c | |
@@ -16,12 +16,12 @@ | |
#include <stdlib.h> | |
#include <stdio.h> | |
-#define LOG_DEFAULT 3 | |
+#define LOG_DEFAULT 2 /* info */ | |
int log_level = -1; | |
void | |
-vlogf(int exitcode, int level, char const *flag, char const *fmt, va_list va) | |
+vlogf(int level, char const *flag, char const *fmt, va_list va) | |
{ | |
char *env; | |
@@ -32,7 +32,7 @@ vlogf(int exitcode, int level, char const *flag, char const *… | |
} | |
if (log_level < level) | |
- goto end; | |
+ return; | |
fprintf(stderr, "%s: ", flag); | |
vfprintf(stderr, fmt, va); | |
@@ -43,19 +43,17 @@ vlogf(int exitcode, int level, char const *flag, char const… | |
fprintf(stderr, "\n"); | |
fflush(stderr); | |
-end: | |
- if (exitcode) | |
- exit(exitcode); | |
} | |
void | |
-fatal(int exitcode, char const *fmt, ...) | |
+die(int exitcode, char const *fmt, ...) | |
{ | |
va_list va; | |
va_start(va, fmt); | |
- vlogf(exitcode, 0, "fatal", fmt, va); | |
+ vlogf(0, "error", fmt, va); | |
va_end(va); | |
+ exit(exitcode); | |
} | |
void | |
@@ -64,7 +62,7 @@ error(char const *fmt, ...) | |
va_list va; | |
va_start(va, fmt); | |
- vlogf(0, 1, "error", fmt, va); | |
+ vlogf(0, "error", fmt, va); | |
va_end(va); | |
} | |
@@ -74,7 +72,7 @@ warn(char const *fmt, ...) | |
va_list va; | |
va_start(va, fmt); | |
- vlogf(0, 2, "warn", fmt, va); | |
+ vlogf(1, "warn", fmt, va); | |
va_end(va); | |
} | |
@@ -84,7 +82,7 @@ info(char const *fmt, ...) | |
va_list va; | |
va_start(va, fmt); | |
- vlogf(0, 3, "info", fmt, va); | |
+ vlogf(2, "info", fmt, va); | |
va_end(va); | |
} | |
@@ -94,6 +92,6 @@ debug(char const *fmt, ...) | |
va_list va; | |
va_start(va, fmt); | |
- vlogf(0, 4, "debug", fmt, va); | |
+ vlogf(3, "debug", fmt, va); | |
va_end(va); | |
} | |
diff --git a/src/log.h b/src/log.h | |
@@ -5,8 +5,8 @@ | |
/**/ | |
int log_level; | |
-void vlogf (int, int, char const *, char… | |
-void fatal (int, char const *, ...); | |
+void vlogf (int, char const *, char cons… | |
+void die (int, char const *, ...); | |
void error (char const *, ...); | |
void warn (char const *, ...); | |
void info (char const *, ...); | |
diff --git a/src/scale.c b/src/scale.c | |
@@ -53,7 +53,7 @@ scale_minmax(struct csv *vl, int ncol, | |
} | |
if (*tmin == *tmax) | |
- fatal(1, "invalid time scale: min=%lld max=%lld", *tmin, *tmax… | |
+ die(1, "invalid time scale: min=%lld max=%lld", *tmin, *tmax); | |
} | |
static time_t |