summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-07-21 15:44:48 +0300
committerRan Benita <ran234@gmail.com>2012-07-23 00:45:35 +0300
commitf48ee2d2afe698419adcd96346f42c556e94ecf5 (patch)
treee5ce33ff23b2a29d6d1f8061833be5d599dca44b /src
parent8e3958032cc359296cb4106ff887c3943b0619d6 (diff)
parse: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/xkbcomp/parser.y8
-rw-r--r--src/xkbcomp/parseutils.c49
-rw-r--r--src/xkbcomp/parseutils.h9
-rw-r--r--src/xkbcomp/scanner.l40
-rw-r--r--src/xkbcomp/xkbcomp.c8
5 files changed, 68 insertions, 46 deletions
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);