parse: use new log functions Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index ba26fde..9630c17 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -32,6 +32,12 @@
extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
+static void
+yyerror(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
+{
+ scanner_error(loc, param->scanner, msg);
+}
+
#define scanner param->scanner
%}
@@ -331,7 +337,7 @@ Decl : OptMergeMode VarDecl
}
| MergeMode STRING
{
- $$= &IncludeCreate($2,$1)->common;
+ $$= &IncludeCreate(param->ctx, $2, $1)->common;
free($2);
}
;
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index ab8a539..6ec3b08 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -384,7 +384,7 @@ static void
FreeInclude(IncludeStmt *incl);
IncludeStmt *
-IncludeCreate(char *str, enum merge_mode merge)
+IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
{
IncludeStmt *incl, *first;
char *file, *map, *stmt, *tmp, *extra_data;
@@ -407,8 +407,9 @@ IncludeCreate(char *str, enum merge_mode merge)
}
if (!incl) {
- WSGO("Allocation failure in IncludeCreate\n");
- ACTION("Using only part of the include\n");
+ log_wsgo(ctx,
+ "Allocation failure in IncludeCreate; "
+ "Using only part of the include\n");
break;
}
@@ -436,35 +437,33 @@ IncludeCreate(char *str, enum merge_mode merge)
return first;
err:
- ERROR("Illegal include statement \"%s\"\n", stmt);
- ACTION("Ignored\n");
+ log_err(ctx, "Illegal include statement \"%s\"; Ignored\n", stmt);
FreeInclude(first);
free(stmt);
return NULL;
}
void
-CheckDefaultMap(XkbFile * maps, const char *fileName)
+CheckDefaultMap(struct xkb_context *ctx, XkbFile *maps, const char *fileName)
{
- XkbFile *dflt, *tmp;
-
- dflt = NULL;
- for (tmp = maps, dflt = NULL; tmp != NULL;
- tmp = (XkbFile *) tmp->common.next) {
- if (tmp->flags & XkbLC_Default) {
- if (dflt == NULL)
- dflt = tmp;
- else {
- if (warningLevel > 2) {
- WARN("Multiple default components in %s\n",
- (fileName ? fileName : "(unknown)"));
- ACTION("Using %s, ignoring %s\n",
- (dflt->name ? dflt->name : "(first)"),
- (tmp->name ? tmp->name : "(subsequent)"));
- }
- tmp->flags &= (~XkbLC_Default);
- }
+ XkbFile *dflt = NULL, *tmp;
+
+ for (tmp = maps; tmp; tmp = (XkbFile *) tmp->common.next) {
+ if (!(tmp->flags & XkbLC_Default))
+ continue;
+ if (!dflt) {
+ dflt = tmp;
+ continue;
}
+
+ log_lvl(ctx, 3,
+ "Multiple default components in %s; "
+ "Using %s, ignoring %s\n",
+ (fileName ? fileName : "(unknown)"),
+ (dflt->name ? dflt->name : "(first)"),
+ (tmp->name ? tmp->name : "(subsequent)"));
+
+ tmp->flags &= (~XkbLC_Default);
}
}
@@ -548,7 +547,7 @@ FreeExpr(ExprDef *expr)
case ExprKeysymList:
darray_foreach(sym, expr->value.list.syms)
- free(*sym);
+ free(*sym);
darray_free(expr->value.list.syms);
darray_free(expr->value.list.symsMapIndex);
darray_free(expr->value.list.symsNumEntries);
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index 02501f1..252d8d8 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -40,6 +40,7 @@ struct parser_param {
#include "parser.h"
struct scanner_extra {
+ struct xkb_context *ctx;
char *scanFile;
char scanBuf[1024];
char *s;
@@ -112,10 +113,10 @@ extern int
LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn);
extern IncludeStmt *
-IncludeCreate(char *str, enum merge_mode merge);
+IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge);
extern void
-CheckDefaultMap(XkbFile *maps, const char *fileName);
+CheckDefaultMap(struct xkb_context *ctx, XkbFile *maps, const char *fileName);
extern XkbFile *
CreateXKBFile(struct xkb_context *ctx, enum xkb_file_type type, char *name,
@@ -137,7 +138,7 @@ FreeXKBFile(XkbFile *file);
extern void
FreeStmt(ParseCommon *stmt);
-extern void
-yyerror(struct YYLTYPE *loc, void *scanner, const char *msg);
+void
+scanner_error(struct YYLTYPE *loc, void *scanner, const char *msg);
#endif /* PARSEUTILS_H */
diff --git a/src/xkbcomp/scanner.l b/src/xkbcomp/scanner.l
index 39e8759..6484a1c 100644
--- a/src/xkbcomp/scanner.l
+++ b/src/xkbcomp/scanner.l
@@ -35,6 +35,10 @@
extern int yyparse(struct parser_param *param);
+static void
+scanner_error_extra(struct YYLTYPE *loc, struct scanner_extra *extra,
+ const char *msg);
+
#define YY_USER_ACTION { \
yylloc->first_line = yylineno; \
yylloc->last_line = yylineno; \
@@ -85,7 +89,8 @@ extern int yyparse(struct parser_param *param);
(void) sscanf( yytext + 1, "%o", &result );
if (result > 0xff) {
- fprintf(stderr, "Illegal octal escape %s\n", yytext);
+ scanner_error_extra(yylloc, yyextra,
+ "Illegal octal escape");
return ERROR_TOK;
}
@@ -93,7 +98,8 @@ extern int yyparse(struct parser_param *param);
}
<S_STR,S_KEY>\\[0-9]+ {
- fprintf(stderr, "Illegal octal escape %s\n", yytext);
+ scanner_error_extra(yylloc, yyextra,
+ "Illegal octal escape");
return ERROR_TOK;
}
@@ -194,17 +200,23 @@ alternate_group return ALTERNATE_GROUP;
%%
+static void
+scanner_error_extra(struct YYLTYPE *loc, struct scanner_extra *extra,
+ const char *msg)
+{
+ log_err(extra->ctx, "%s: line %d of %s\n", msg,
+ loc->first_line,
+ extra->scanFile ? extra->scanFile : "(unknown)");
+
+ log_err(extra->ctx, "last scanned symbol was: %s\n",
+ extra->scanBuf);
+}
+
void
-yyerror(struct YYLTYPE *loc, void *scanner, const char *msg)
+scanner_error(struct YYLTYPE *loc, void *scanner, const char *msg)
{
struct scanner_extra *extra = yyget_extra(scanner);
-
- if (warningLevel > 0) {
- fprintf(stderr, "%s: line %d of %s\n", msg, loc->first_line,
- extra->scanFile ? extra->scanFile : "(unknown)");
- if (warningLevel > 3)
- fprintf(stderr, "last scanned symbol is: %s\n", extra->scanBuf);
- }
+ scanner_error_extra(loc, extra, msg);
}
bool
@@ -226,6 +238,8 @@ XKBParseString(struct xkb_context *ctx, const char *string,
if (ret != 0)
return false;
+ extra.ctx = ctx;
+
extra.scanFile = strdup(file_name);
if (!extra.scanFile)
return false;
@@ -238,7 +252,7 @@ XKBParseString(struct xkb_context *ctx, const char *string,
if (ret != 0)
return false;
- CheckDefaultMap(param.rtrn, file_name);
+ CheckDefaultMap(param.ctx, param.rtrn, file_name);
*out = param.rtrn;
return true;
}
@@ -261,6 +275,8 @@ XKBParseFile(struct xkb_context *ctx, FILE *file,
if (ret != 0)
return false;
+ extra.ctx = ctx;
+
extra.scanFile = strdup(file_name);
if (!extra.scanFile)
return false;
@@ -272,7 +288,7 @@ XKBParseFile(struct xkb_context *ctx, FILE *file,
if (ret != 0)
return false;
- CheckDefaultMap(param.rtrn, file_name);
+ CheckDefaultMap(param.ctx, param.rtrn, file_name);
*out = param.rtrn;
return true;
}
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 32eab6d..7adb35c 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -40,21 +40,21 @@ keymap_file_from_components(struct xkb_context *ctx,
XkbFile *keycodes, *types, *compat, *symbols;
IncludeStmt *inc;
- inc = IncludeCreate(ktcsg->keycodes, MERGE_DEFAULT);
+ inc = IncludeCreate(ctx, ktcsg->keycodes, MERGE_DEFAULT);
keycodes = CreateXKBFile(ctx, FILE_TYPE_KEYCODES, NULL,
(ParseCommon *) inc, 0);
- inc = IncludeCreate(ktcsg->types, MERGE_DEFAULT);
+ inc = IncludeCreate(ctx, ktcsg->types, MERGE_DEFAULT);
types = CreateXKBFile(ctx, FILE_TYPE_TYPES, NULL,
(ParseCommon *) inc, 0);
AppendStmt(&keycodes->common, &types->common);
- inc = IncludeCreate(ktcsg->compat, MERGE_DEFAULT);
+ inc = IncludeCreate(ctx, ktcsg->compat, MERGE_DEFAULT);
compat = CreateXKBFile(ctx, FILE_TYPE_COMPAT, NULL,
(ParseCommon *) inc, 0);
AppendStmt(&keycodes->common, &compat->common);
- inc = IncludeCreate(ktcsg->symbols, MERGE_DEFAULT);
+ inc = IncludeCreate(ctx, ktcsg->symbols, MERGE_DEFAULT);
symbols = CreateXKBFile(ctx, FILE_TYPE_SYMBOLS, NULL,
(ParseCommon *) inc, 0);
AppendStmt(&keycodes->common, &symbols->common);