diff --git a/doc/message-registry.md b/doc/message-registry.md index 8bf15aa8..b126aee1 100644 --- a/doc/message-registry.md +++ b/doc/message-registry.md @@ -307,7 +307,7 @@ keysyms (`Unnnn`) if relevant.
Summary
A keysym name has been deprecated: use the corresponding canonical name instead
-Some keysym names have typos, unconventional names or historical aliases of a reference name. +Some keysym names have typos, unconventional names or are historical aliases. Please consider migrating to the reference name reported in the warning message. diff --git a/meson.build b/meson.build index e819a20f..552e816b 100644 --- a/meson.build +++ b/meson.build @@ -386,6 +386,7 @@ if get_option('enable-xkbregistry') deps_libxkbregistry = [dep_libxml] libxkbregistry_sources = [ 'src/registry.c', + 'src/messages-codes.h', 'src/utils.h', 'src/utils.c', 'src/util-list.h', diff --git a/src/context.h b/src/context.h index 6b0ddb0c..3b513da5 100644 --- a/src/context.h +++ b/src/context.h @@ -109,35 +109,6 @@ void xkb_context_sanitize_rule_names(struct xkb_context *ctx, struct xkb_rule_names *rmlvo); -/* - * Macro sorcery: PREPEND_MESSAGE_ID enables the log functions to format messages - * with the message ID only if the ID is not 0 (XKB_LOG_MESSAGE_NO_ID). - * This avoid checking the ID value at run time. - * - * The trick resides in CHECK_ID: - * • CHECK_ID(0) expands to: - * ‣ SECOND(MATCH0, WITH_ID, unused) - * ‣ SECOND(unused,WITHOUT_ID, WITH_ID, unused) - * ‣ WITHOUT_ID - * • CHECK_ID(123) expands to: - * ‣ SECOND(MATCH123, WITH_ID, unused) - * ‣ WITH_ID -*/ -#define EXPAND(...) __VA_ARGS__ /* needed for MSVC compatibility */ - -#define JOIN_EXPAND(a, b) a##b -#define JOIN(a, b) JOIN_EXPAND(a, b) - -#define SECOND_EXPAND(a, b, ...) b -#define SECOND(...) EXPAND(SECOND_EXPAND(__VA_ARGS__)) - -#define MATCH0 unused,WITHOUT_ID -#define CHECK_ID(value) SECOND(JOIN(MATCH, value), WITH_ID, unused) - -#define FORMAT_MESSAGE_WITHOUT_ID(id, fmt) fmt -#define FORMAT_MESSAGE_WITH_ID(id, fmt) "[XKB-%03d] " fmt, id -#define PREPEND_MESSAGE_ID(id, fmt) JOIN(FORMAT_MESSAGE_, CHECK_ID(id))(id, fmt) - /* * The format is not part of the argument list in order to avoid the * "ISO C99 requires rest arguments to be used" warning when only the diff --git a/src/messages-codes.h b/src/messages-codes.h index e6637266..a60c5430 100644 --- a/src/messages-codes.h +++ b/src/messages-codes.h @@ -6,6 +6,35 @@ #include +/* + * Macro sorcery: PREPEND_MESSAGE_ID enables the log functions to format messages + * with the message ID only if the ID is not 0 (XKB_LOG_MESSAGE_NO_ID). + * This avoid checking the ID value at run time. + * + * The trick resides in CHECK_ID: + * • CHECK_ID(0) expands to: + * ‣ SECOND(MATCH0, WITH_ID, unused) + * ‣ SECOND(unused,WITHOUT_ID, WITH_ID, unused) + * ‣ WITHOUT_ID + * • CHECK_ID(123) expands to: + * ‣ SECOND(MATCH123, WITH_ID, unused) + * ‣ WITH_ID +*/ +#define EXPAND(...) __VA_ARGS__ /* needed for MSVC compatibility */ + +#define JOIN_EXPAND(a, b) a##b +#define JOIN(a, b) JOIN_EXPAND(a, b) + +#define SECOND_EXPAND(a, b, ...) b +#define SECOND(...) EXPAND(SECOND_EXPAND(__VA_ARGS__)) + +#define MATCH0 unused,WITHOUT_ID +#define CHECK_ID(value) SECOND(JOIN(MATCH, value), WITH_ID, unused) + +#define FORMAT_MESSAGE_WITHOUT_ID(id, fmt) fmt +#define FORMAT_MESSAGE_WITH_ID(id, fmt) "[XKB-%03d] " fmt, id +#define PREPEND_MESSAGE_ID(id, fmt) JOIN(FORMAT_MESSAGE_, CHECK_ID(id))(id, fmt) + /** * Special case when no message identifier is defined. */ diff --git a/src/messages-codes.h.jinja b/src/messages-codes.h.jinja index 468a6ded..62ba2594 100644 --- a/src/messages-codes.h.jinja +++ b/src/messages-codes.h.jinja @@ -6,6 +6,35 @@ #include +/* + * Macro sorcery: PREPEND_MESSAGE_ID enables the log functions to format messages + * with the message ID only if the ID is not 0 (XKB_LOG_MESSAGE_NO_ID). + * This avoid checking the ID value at run time. + * + * The trick resides in CHECK_ID: + * • CHECK_ID(0) expands to: + * ‣ SECOND(MATCH0, WITH_ID, unused) + * ‣ SECOND(unused,WITHOUT_ID, WITH_ID, unused) + * ‣ WITHOUT_ID + * • CHECK_ID(123) expands to: + * ‣ SECOND(MATCH123, WITH_ID, unused) + * ‣ WITH_ID +*/ +#define EXPAND(...) __VA_ARGS__ /* needed for MSVC compatibility */ + +#define JOIN_EXPAND(a, b) a##b +#define JOIN(a, b) JOIN_EXPAND(a, b) + +#define SECOND_EXPAND(a, b, ...) b +#define SECOND(...) EXPAND(SECOND_EXPAND(__VA_ARGS__)) + +#define MATCH0 unused,WITHOUT_ID +#define CHECK_ID(value) SECOND(JOIN(MATCH, value), WITH_ID, unused) + +#define FORMAT_MESSAGE_WITHOUT_ID(id, fmt) fmt +#define FORMAT_MESSAGE_WITH_ID(id, fmt) "[XKB-%03d] " fmt, id +#define PREPEND_MESSAGE_ID(id, fmt) JOIN(FORMAT_MESSAGE_, CHECK_ID(id))(id, fmt) + /** * Special case when no message identifier is defined. */ diff --git a/src/registry.c b/src/registry.c index 19b2b36c..80b25513 100644 --- a/src/registry.c +++ b/src/registry.c @@ -32,6 +32,7 @@ #include #include "xkbcommon/xkbregistry.h" +#include "messages-codes.h" #include "utils.h" #include "util-list.h" #include "util-mem.h" @@ -156,16 +157,18 @@ rxkb_log(struct rxkb_context *ctx, enum rxkb_log_level level, * format is supplied without arguments. Not supplying it would still * result in an error, though. */ +#define rxkb_log_with_code(ctx, level, msg_id, fmt, ...) \ + rxkb_log(ctx, level, PREPEND_MESSAGE_ID(msg_id, fmt), ##__VA_ARGS__) #define log_dbg(ctx, ...) \ rxkb_log((ctx), RXKB_LOG_LEVEL_DEBUG, __VA_ARGS__) #define log_info(ctx, ...) \ rxkb_log((ctx), RXKB_LOG_LEVEL_INFO, __VA_ARGS__) -#define log_warn(ctx, ...) \ - rxkb_log((ctx), RXKB_LOG_LEVEL_WARNING, __VA_ARGS__) -#define log_err(ctx, ...) \ - rxkb_log((ctx), RXKB_LOG_LEVEL_ERROR, __VA_ARGS__) -#define log_wsgo(ctx, ...) \ - rxkb_log((ctx), RXKB_LOG_LEVEL_CRITICAL, __VA_ARGS__) +#define log_warn(ctx, id, ...) \ + rxkb_log_with_code((ctx), RXKB_LOG_LEVEL_WARNING, id, __VA_ARGS__) +#define log_err(ctx, id, ...) \ + rxkb_log_with_code((ctx), RXKB_LOG_LEVEL_ERROR, id, __VA_ARGS__) +#define log_wsgo(ctx, id, ...) \ + rxkb_log_with_code((ctx), RXKB_LOG_LEVEL_CRITICAL, id, __VA_ARGS__) #define DECLARE_REF_UNREF_FOR_TYPE(type_) \ @@ -561,7 +564,8 @@ rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path) char rules[PATH_MAX]; if (ctx->context_state != CONTEXT_NEW) { - log_err(ctx, "include paths can only be appended to a new context\n"); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "include paths can only be appended to a new context\n"); return false; } @@ -599,7 +603,8 @@ rxkb_context_include_path_append_default(struct rxkb_context *ctx) bool ret = false; if (ctx->context_state != CONTEXT_NEW) { - log_err(ctx, "include paths can only be appended to a new context\n"); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "include paths can only be appended to a new context\n"); return false; } @@ -648,7 +653,8 @@ rxkb_context_parse(struct rxkb_context *ctx, const char *ruleset) bool success = false; if (ctx->context_state != CONTEXT_NEW) { - log_err(ctx, "parse must only be called on a new context\n"); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "parse must only be called on a new context\n"); return false; } @@ -751,7 +757,7 @@ parse_config_item(struct rxkb_context *ctx, xmlNode *parent, else if (xmlStrEqual(raw_popularity, (const xmlChar*)"exotic")) config->popularity = RXKB_POPULARITY_EXOTIC; else - log_err(ctx, + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, "xml:%d: invalid popularity attribute: expected " "'standard' or 'exotic', got: '%s'\n", ci->line, raw_popularity); @@ -773,7 +779,8 @@ parse_config_item(struct rxkb_context *ctx, xmlNode *parent, } if (!config->name || !strlen(config->name)) { - log_err(ctx, "xml:%d: missing required element 'name'\n", + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "xml:%d: missing required element 'name'\n", ci->line); config_item_free(config); return false; @@ -1133,7 +1140,8 @@ xml_error_func(void *ctx, const char *msg, ...) /* This shouldn't really happen */ if (rc < 0) { - log_err(ctx, "+++ out of cheese error. redo from start +++\n"); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "+++ out of cheese error. redo from start +++\n"); slen = 0; memset(buf, 0, sizeof(buf)); return; @@ -1148,7 +1156,7 @@ xml_error_func(void *ctx, const char *msg, ...) /* We're assuming here that the last character is \n. */ if (buf[slen - 1] == '\n') { - log_err(ctx, "%s", buf); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, "%s", buf); memset(buf, 0, sizeof(buf)); slen = 0; } @@ -1204,7 +1212,7 @@ validate(struct rxkb_context *ctx, xmlDoc *doc) dtd = xmlIOParseDTD(NULL, buf, XML_CHAR_ENCODING_UTF8); if (!dtd) { - log_err(ctx, "Failed to load DTD\n"); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, "Failed to load DTD\n"); return false; } @@ -1240,7 +1248,8 @@ parse(struct rxkb_context *ctx, const char *path, return false; if (!validate(ctx, doc)) { - log_err(ctx, "XML error: failed to validate document at %s\n", path); + log_err(ctx, XKB_LOG_MESSAGE_NO_ID, + "XML error: failed to validate document at %s\n", path); goto error; }