rules: use new log functions

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-21 15:19:27 +03:00
parent d659f2b46b
commit 3bb3e9c3a9
1 changed files with 54 additions and 45 deletions

View File

@ -31,7 +31,7 @@
#include "path.h" #include "path.h"
static bool static bool
input_line_get(FILE *file, darray_char *line) input_line_get(struct xkb_context *ctx, FILE *file, darray_char *line)
{ {
int ch; int ch;
bool end_of_file = false; bool end_of_file = false;
@ -100,8 +100,9 @@ input_line_get(FILE *file, darray_char *line)
if (ch == '!') { if (ch == '!') {
if (!darray_empty(*line)) { if (!darray_empty(*line)) {
WARN("The '!' is legal only at start of line\n"); log_warn(ctx,
ACTION("Line containing '!' ignored\n"); "The '!' is legal only at start of line; "
"Line containing '!' ignored\n");
darray_resize(*line, 0); darray_resize(*line, 0);
break; break;
} }
@ -259,7 +260,8 @@ get_index(char *str, int *ndx)
* mapping->map[3] = {.word = SYMBOLS, .index = 0} * mapping->map[3] = {.word = SYMBOLS, .index = 0}
*/ */
static void static void
match_mapping_line(darray_char *line, struct mapping *mapping) match_mapping_line(struct xkb_context *ctx, darray_char *line,
struct mapping *mapping)
{ {
char *tok; char *tok;
char *str = darray_mem(*line, 1); char *str = darray_mem(*line, 1);
@ -294,15 +296,17 @@ match_mapping_line(darray_char *line, struct mapping *mapping)
if ((i != LAYOUT && i != VARIANT) || if ((i != LAYOUT && i != VARIANT) ||
*end != '\0' || ndx == -1) { *end != '\0' || ndx == -1) {
WARN("Illegal %s index: %d\n", cname[i], ndx); log_warn(ctx,
WARN("Can only index layout and variant\n"); "Illegal %s index: %d\n", cname[i], ndx);
log_warn(ctx, "Can only index layout and variant\n");
break; break;
} }
if (ndx < 1 || ndx > XkbNumKbdGroups) { if (ndx < 1 || ndx > XkbNumKbdGroups) {
WARN("Illegal %s index: %d\n", cname[i], ndx); log_warn(ctx, "Illegal %s index: %d\n",
WARN("Index must be in range 1..%d\n", cname[i], ndx);
XkbNumKbdGroups); log_warn(ctx, "Index must be in range 1..%d\n",
XkbNumKbdGroups);
break; break;
} }
} }
@ -315,8 +319,9 @@ match_mapping_line(darray_char *line, struct mapping *mapping)
if (present & (1 << i)) { if (present & (1 << i)) {
if ((i == LAYOUT && layout_ndx_present & (1 << ndx)) || if ((i == LAYOUT && layout_ndx_present & (1 << ndx)) ||
(i == VARIANT && variant_ndx_present & (1 << ndx))) { (i == VARIANT && variant_ndx_present & (1 << ndx))) {
WARN("Component \"%s\" listed twice\n", tok); log_warn(ctx,
ACTION("Second definition ignored\n"); "Component \"%s\" listed twice; "
"Second definition ignored\n", tok);
break; break;
} }
} }
@ -334,22 +339,22 @@ match_mapping_line(darray_char *line, struct mapping *mapping)
} }
} }
if (!found) { if (!found)
WARN("Unknown component \"%s\"\n", tok); log_warn(ctx, "Unknown component \"%s\"; Ignored\n", tok);
ACTION("ignored\n");
}
} }
if ((present & PART_MASK) == 0) { if ((present & PART_MASK) == 0) {
WARN("Mapping needs at least one MLVO part\n"); log_warn(ctx,
ACTION("Illegal mapping ignored\n"); "Mapping needs at least one MLVO part; "
"Illegal mapping ignored\n");
mapping->num_maps = 0; mapping->num_maps = 0;
return; return;
} }
if ((present & COMPONENT_MASK) == 0) { if ((present & COMPONENT_MASK) == 0) {
WARN("Mapping needs at least one component\n"); log_warn(ctx,
ACTION("Illegal mapping ignored\n"); "Mapping needs at least one component; "
"Illegal mapping ignored\n");
mapping->num_maps = 0; mapping->num_maps = 0;
return; return;
} }
@ -399,8 +404,8 @@ match_group_line(darray_char *line, struct group *group)
/* Match lines following a mapping (see match_mapping_line comment). */ /* Match lines following a mapping (see match_mapping_line comment). */
static bool static bool
match_rule_line(darray_char *line, struct mapping *mapping, match_rule_line(struct xkb_context *ctx, darray_char *line,
struct rule *rule) struct mapping *mapping, struct rule *rule)
{ {
char *str, *tok; char *str, *tok;
int nread, i; int nread, i;
@ -409,8 +414,9 @@ match_rule_line(darray_char *line, struct mapping *mapping,
const char *names[MAX_WORDS] = { NULL }; const char *names[MAX_WORDS] = { NULL };
if (mapping->num_maps == 0) { if (mapping->num_maps == 0) {
WARN("Must have a mapping before first line of data\n"); log_warn(ctx,
ACTION("Illegal line of data ignored\n"); "Must have a mapping before first line of data; "
"Illegal line of data ignored\n");
return false; return false;
} }
@ -426,8 +432,9 @@ match_rule_line(darray_char *line, struct mapping *mapping,
} }
if (nread > mapping->num_maps) { if (nread > mapping->num_maps) {
WARN("Too many words on a line\n"); log_warn(ctx,
ACTION("Extra word \"%s\" ignored\n", tok); "Too many words on a line; "
"Extra word \"%s\" ignored\n", tok);
continue; continue;
} }
@ -437,8 +444,8 @@ match_rule_line(darray_char *line, struct mapping *mapping,
} }
if (nread < mapping->num_maps) { if (nread < mapping->num_maps) {
WARN("Too few words on a line: %s\n", darray_mem(*line, 0)); log_warn(ctx, "Too few words on a line: %s; Line ignored\n",
ACTION("line ignored\n"); darray_mem(*line, 0));
return false; return false;
} }
@ -476,17 +483,18 @@ match_rule_line(darray_char *line, struct mapping *mapping,
} }
static bool static bool
match_line(darray_char *line, struct mapping *mapping, match_line(struct xkb_context *ctx, darray_char *line,
struct rule *rule, struct group *group) struct mapping *mapping, struct rule *rule,
struct group *group)
{ {
if (darray_item(*line, 0) != '!') if (darray_item(*line, 0) != '!')
return match_rule_line(line, mapping, rule); return match_rule_line(ctx, line, mapping, rule);
if (darray_item(*line, 1) == '$' || if (darray_item(*line, 1) == '$' ||
(darray_item(*line, 1) == ' ' && darray_item(*line, 2) == '$')) (darray_item(*line, 1) == ' ' && darray_item(*line, 2) == '$'))
return match_group_line(line, group); return match_group_line(line, group);
match_mapping_line(line, mapping); match_mapping_line(ctx, line, mapping);
return false; return false;
} }
@ -782,7 +790,7 @@ clear_partial_matches(struct rules *rules)
struct rule *rule; struct rule *rule;
darray_foreach(rule, rules->rules) darray_foreach(rule, rules->rules)
rule->flags &= ~RULE_FLAG_PENDING_MATCH; rule->flags &= ~RULE_FLAG_PENDING_MATCH;
} }
static void static void
@ -791,8 +799,8 @@ apply_partial_matches(struct rules *rules, struct xkb_component_names *kccgst)
struct rule *rule; struct rule *rule;
darray_foreach(rule, rules->rules) darray_foreach(rule, rules->rules)
if (rule->flags & RULE_FLAG_PENDING_MATCH) if (rule->flags & RULE_FLAG_PENDING_MATCH)
apply_rule(rule, kccgst); apply_rule(rule, kccgst);
} }
static void static void
@ -973,7 +981,7 @@ get_components(struct rules *rules, const struct xkb_rule_names *mlvo,
} }
static struct rules * static struct rules *
load_rules(FILE *file) load_rules(struct xkb_context *ctx, FILE *file)
{ {
darray_char line; darray_char line;
struct mapping mapping; struct mapping mapping;
@ -992,8 +1000,8 @@ load_rules(FILE *file)
darray_init(line); darray_init(line);
darray_growalloc(line, 128); darray_growalloc(line, 128);
while (input_line_get(file, &line)) { while (input_line_get(ctx, file, &line)) {
if (match_line(&line, &mapping, &trule, &tgroup)) { if (match_line(ctx, &line, &mapping, &trule, &tgroup)) {
if (tgroup.number) { if (tgroup.number) {
darray_append(rules->groups, tgroup); darray_append(rules->groups, tgroup);
memset(&tgroup, 0, sizeof(tgroup)); memset(&tgroup, 0, sizeof(tgroup));
@ -1053,23 +1061,24 @@ xkb_components_from_rules(struct xkb_context *ctx,
file = XkbFindFileInPath(ctx, rmlvo->rules, FILE_TYPE_RULES, &path); file = XkbFindFileInPath(ctx, rmlvo->rules, FILE_TYPE_RULES, &path);
if (!file) { if (!file) {
ERROR("could not find \"%s\" rules in XKB path\n", rmlvo->rules); log_err(ctx, "could not find \"%s\" rules in XKB path\n",
ERROR("%d include paths searched:\n", rmlvo->rules);
xkb_context_num_include_paths(ctx)); log_err(ctx, "%d include paths searched:\n",
xkb_context_num_include_paths(ctx));
for (i = 0; i < xkb_context_num_include_paths(ctx); i++) for (i = 0; i < xkb_context_num_include_paths(ctx); i++)
ERROR("\t%s\n", xkb_context_include_path_get(ctx, i)); log_err(ctx, "\t%s\n", xkb_context_include_path_get(ctx, i));
return NULL; return NULL;
} }
rules = load_rules(file); rules = load_rules(ctx, file);
if (!rules) { if (!rules) {
ERROR("failed to load XKB rules \"%s\"\n", path); log_err(ctx, "failed to load XKB rules \"%s\"\n", path);
goto err; goto err;
} }
kccgst = calloc(1, sizeof(*kccgst)); kccgst = calloc(1, sizeof(*kccgst));
if (!kccgst) { if (!kccgst) {
ERROR("failed to allocate XKB components\n"); log_err(ctx, "failed to allocate XKB components\n");
goto err; goto err;
} }
@ -1080,7 +1089,7 @@ xkb_components_from_rules(struct xkb_context *ctx,
free(kccgst->symbols); free(kccgst->symbols);
free(kccgst); free(kccgst);
kccgst = NULL; kccgst = NULL;
ERROR("no components returned from XKB rules \"%s\"\n", path); log_err(ctx, "no components returned from XKB rules \"%s\"\n", path);
goto err; goto err;
} }