diff options
-rw-r--r-- | common.h | 13 | ||||
-rw-r--r-- | libfonts.h | 22 | ||||
-rw-r--r-- | libfonts_get_default_font.c | 10 | ||||
-rw-r--r-- | libfonts_get_default_rendering_settings.c | 15 | ||||
-rw-r--r-- | libfonts_get_output_rendering_settings.c | 17 | ||||
-rw-r--r-- | libfonts_parse_aa__.c | 2 | ||||
-rw-r--r-- | libfonts_parse_order__.c | 2 |
7 files changed, 64 insertions, 17 deletions
@@ -6,6 +6,7 @@ #include <inttypes.h> #include <limits.h> #include <pwd.h> +#include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -124,6 +125,18 @@ static inline void +warning(struct libfonts_context *ctx, int err, const char *function, const char *fmt, ...) +{ + va_list args; + if (ctx && ctx->warning) { + va_start(args, fmt); + ctx->warning(err, function, fmt, args, ctx->user); + va_end(args); + } +} + + +static inline void transform(double *x_out, double *y_out, double x, double y, const struct libfonts_transformation *transformation) { double a = transformation->m[0][0], b = transformation->m[0][1], c = transformation->m[0][2]; @@ -2,6 +2,7 @@ #ifndef LIBFONTS_H #define LIBFONTS_H +#include <stdarg.h> #include <stdint.h> #include <unistd.h> @@ -1622,6 +1623,27 @@ struct libfonts_context { * Only used if `.use_context_uid` is non-zero */ uid_t uid; + + /** + * Application data used in as the last argument + * in callback functions + */ + void *user; + + /** + * If non-`NULL` some function may call thing + * function to let the application print a + * warning + * + * @param err `errno` value for the warning, 0 if none + * @param function The name of the function the warning is emitted from (closest public function) + * @param fmt Formattable description of the warning, will start in lower case, + * and will end with a colon if and only if a description of `err` + * shall be appended to the message (with a preceding space) + * @param args Argument used into the description via formatting + * @param user `.user` as is + */ + void (*warning)(int err, const char *function, const char *fmt, va_list args, void *user); }; diff --git a/libfonts_get_default_font.c b/libfonts_get_default_font.c index 69d2729..e0ad9ab 100644 --- a/libfonts_get_default_font.c +++ b/libfonts_get_default_font.c @@ -25,6 +25,7 @@ getn(char **outp, const char *file_part1, size_t file_part1_len, const char *fil char *line, *buf = NULL; size_t size = 0, off = 0, avail = 0; char *value; + size_t lineno = 0; *outp = NULL; @@ -60,7 +61,7 @@ open_again: case ENODEV: case ENOTDIR: case ENXIO: - /* TODO print warning using `ctx` */ + warning(ctx, errno, "libfonts_get_default_font", "failed to open %s:", path); goto out; default: goto out; @@ -83,6 +84,7 @@ open_again: if (!len) break; line[len -= 1] = '\0'; + lineno++; while (isblank(*line)) { line++; @@ -96,13 +98,13 @@ open_again: value = libfonts_confsplit__(line); if (!value) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_default_font", "bad line in %s at line %zu", path, lineno); continue; } if (!strcmp(line, name)) { if (*outp) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_default_font", "duplicate definition in %s at line %zu", path, lineno); free(*outp); *outp = NULL; } @@ -110,7 +112,7 @@ open_again: if (!*outp) goto fail; } else if (strcmp(line, "sans-serif") && strcmp(line, "serif") && strcmp(line, "monospace")) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_default_font", "bad font class in %s at line %zu: %s", path, lineno, line); } } diff --git a/libfonts_get_default_rendering_settings.c b/libfonts_get_default_rendering_settings.c index ebdc51c..f40b1d1 100644 --- a/libfonts_get_default_rendering_settings.c +++ b/libfonts_get_default_rendering_settings.c @@ -15,6 +15,7 @@ getn(const char *file_part1, size_t file_part1_len, const char *file_part2, size_t size = 0, off = 0, avail = 0; char *value; unsigned int found_fields = 0; + size_t lineno = 0; if (file_part1_len > SIZE_MAX - file_part2_len - 1) goto enomem; @@ -48,7 +49,7 @@ open_again: case ENODEV: case ENOTDIR: case ENXIO: - /* TODO print warning using `ctx` */ + warning(ctx, errno, "libfonts_get_default_rendering_settings", "failed to open %s:", path); goto out; default: goto out; @@ -68,6 +69,7 @@ open_again: if (!len) break; line[len -= 1] = '\0'; + lineno++; while (isblank(*line)) line++; @@ -79,22 +81,25 @@ open_again: value = libfonts_confsplit__(line); if (!value) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_default_rendering_settings", "bad line in %s at line %zu", path, lineno); continue; } #define X(INDEX, CONFNAME, CNAME, DEFVAL, PARSER)\ if (!strcmp(line, CONFNAME)) {\ if (found_fields & (1U << INDEX)) {\ - /* TODO warning */\ + warning(ctx, 0, "libfonts_get_default_rendering_settings",\ + "duplicate definition in %s at line %zu", path, lineno); \ }\ found_fields |= (1U << INDEX);\ if (!PARSER(&settings->CNAME, value)) {\ - /* TODO warning */\ + warning(ctx, 0, "libfonts_get_default_rendering_settings",\ + "invalid value in %s at line %zu: %s", path, lineno, value);\ }\ } else LIST_RENDERING_SETTINGS(X,) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_default_rendering_settings",\ + "bad definition in %s at line %zu: %s", path, lineno, line);\ } #undef X } diff --git a/libfonts_get_output_rendering_settings.c b/libfonts_get_output_rendering_settings.c index 2cecf3c..b9c1efd 100644 --- a/libfonts_get_output_rendering_settings.c +++ b/libfonts_get_output_rendering_settings.c @@ -18,6 +18,7 @@ getn(const char *file_part1, size_t file_part1_len, const char *file_part2, int in_a_section = 0; char *value; unsigned int found_fields = 0; + size_t lineno = 0; if (file_part1_len > SIZE_MAX - file_part2_len - 1) goto enomem; @@ -51,7 +52,7 @@ open_again: case ENODEV: case ENOTDIR: case ENXIO: - /* TODO print warning using `ctx` */ + warning(ctx, errno, "libfonts_get_default_rendering_settings", "failed to open %s:", path); goto out; default: goto out; @@ -71,6 +72,7 @@ open_again: if (!len) break; line[len -= 1] = '\0'; + lineno++; while (isblank(*line)) { line++; @@ -93,7 +95,7 @@ open_again: } else if (!in_a_section) { value = libfonts_confsplit__(line); if (!value) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_output_rendering_settings", "bad line in %s at line %zu", path, lineno); continue; } /* TODO aliases should be declarable above the first "[%s]" */ @@ -101,21 +103,24 @@ open_again: } else if (in_the_section) { value = libfonts_confsplit__(line); if (!value) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_output_rendering_settings", "bad line in %s at line %zu", path, lineno); continue; } #define X(INDEX, CONFNAME, CNAME, DEFVAL, PARSER)\ if (!strcmp(line, CONFNAME)) {\ if (found_fields & (1U << INDEX)) {\ - /* TODO warning */\ + warning(ctx, 0, "libfonts_get_output_rendering_settings",\ + "duplicate definition in %s at line %zu", path, lineno); \ }\ found_fields |= (1U << INDEX);\ if (!PARSER(&settings->CNAME, value)) {\ - /* TODO warning */\ + warning(ctx, 0, "libfonts_get_output_rendering_settings",\ + "invalid value in %s at line %zu: %s", path, lineno, value);\ }\ } else LIST_RENDERING_SETTINGS(X,) { - /* TODO warning */ + warning(ctx, 0, "libfonts_get_output_rendering_settings",\ + "bad definition in %s at line %zu: %s", path, lineno, line);\ } #undef X } diff --git a/libfonts_parse_aa__.c b/libfonts_parse_aa__.c index 0ed9a3d..8394a56 100644 --- a/libfonts_parse_aa__.c +++ b/libfonts_parse_aa__.c @@ -36,7 +36,7 @@ main(void) ASSERT(res == C);\ strcpy(buf, S);\ for (i = 0; buf[i]; i++)\ - buf[i] = toupper(buf[i]);\ + buf[i] = (char)toupper(buf[i]);\ res = 999;\ ASSERT(libfonts_parse_aa__(&res, buf) == 1);\ ASSERT(res == C);\ diff --git a/libfonts_parse_order__.c b/libfonts_parse_order__.c index 349347e..906c4a9 100644 --- a/libfonts_parse_order__.c +++ b/libfonts_parse_order__.c @@ -37,7 +37,7 @@ main(void) ASSERT(res == C);\ strcpy(buf, S);\ for (i = 0; buf[i]; i++)\ - buf[i] = toupper(buf[i]);\ + buf[i] = (char)toupper(buf[i]);\ res = 999;\ ASSERT(libfonts_parse_order__(&res, buf) == 1);\ ASSERT(res == C);\ |