Make the context available to the parser We will need the context to remove some global state. Also make the Parse* function just return bool while wer'e at it. 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
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 7e163fa..7072adc 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -59,8 +59,9 @@ ProcessIncludeFile(struct xkb_context *context,
XkbDirectoryForInclude(file_type));
return false;
}
- /* parse the file */
- if ((XKBParseFile(file, stmt->file, &rtrn) == 0) || (rtrn == NULL))
+
+
+ if (!XKBParseFile(context, file, stmt->file, &rtrn))
{
ERROR("Error interpreting include file \"%s\"\n", stmt->file);
fclose(file);
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index dc9d432..9bcc9fb 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -24,8 +24,8 @@
********************************************************/
-#ifndef XKBPARSE_H
-#define XKBPARSE_H 1
+#ifndef PARSEUTILS_H
+#define PARSEUTILS_H
#include <stdio.h>
@@ -33,6 +33,7 @@
#include "parser.h"
struct parser_param {
+ struct xkb_context *context;
void *scanner;
XkbFile *rtrn;
};
@@ -118,14 +119,17 @@ StmtSetMerge(ParseCommon *stmt, unsigned merge, struct YYLTYPE *loc, void *scann
extern void
CheckDefaultMap(XkbFile *maps, const char *fileName);
-extern int
-XKBParseFile(FILE *file, const char *fileName, XkbFile **pRtrn);
+extern XkbFile *
+CreateXKBFile(int type, char *name,
+ ParseCommon *defs, unsigned flags);
-extern int
-XKBParseString(const char *string, const char *fileName, XkbFile **pRtrn);
+extern bool
+XKBParseFile(struct xkb_context *context, FILE *file,
+ const char *file_name, XkbFile **out);
-extern XkbFile *
-CreateXKBFile(int type, char *name, ParseCommon *defs, unsigned flags);
+extern bool
+XKBParseString(struct xkb_context *contex, const char *string,
+ const char *file_name, XkbFile **out);
extern void
FreeXKBFile(XkbFile *file);
@@ -136,4 +140,4 @@ FreeStmt(ParseCommon *stmt);
extern void
yyerror(struct YYLTYPE *loc, void *scanner, const char *msg);
-#endif /* XKBPARSE_H */
+#endif /* PARSEUTILS_H */
diff --git a/src/xkbcomp/scanner.l b/src/xkbcomp/scanner.l
index b8f9be2..7711d82 100644
--- a/src/xkbcomp/scanner.l
+++ b/src/xkbcomp/scanner.l
@@ -204,62 +204,72 @@ yyerror(struct YYLTYPE *loc, void *scanner, const char *msg)
}
}
-int
-XKBParseString(const char *string, const char *fileName, XkbFile **pRtrn)
+bool
+XKBParseString(struct xkb_context *context, const char *string,
+ const char *file_name, XkbFile **out)
{
- YY_BUFFER_STATE state;
+ int ret;
struct parser_param param;
struct scanner_extra extra;
- int ret;
+ YY_BUFFER_STATE state;
- *pRtrn = NULL;
if (string == NULL)
- return 1;
+ return false;
+
+ param.context = context;
memset(&extra, 0, sizeof(extra));
ret = yylex_init_extra(&extra, ¶m.scanner);
if (ret != 0)
- return 0;
- extra.scanFile = strdup(fileName);
+ return false;
+
+ extra.scanFile = strdup(file_name);
+ if (!extra.scanFile)
+ return false;
state = yy_scan_string(string, param.scanner);
ret = yyparse(¶m);
yy_delete_buffer(state, param.scanner);
yylex_destroy(param.scanner);
free(extra.scanFile);
- if (ret)
- return 0;
-
- CheckDefaultMap(param.rtrn, fileName);
- *pRtrn = param.rtrn;
+ if (ret != 0)
+ return false;
- return 1;
+ CheckDefaultMap(param.rtrn, file_name);
+ *out = param.rtrn;
+ return true;
}
-int
-XKBParseFile(FILE * file, const char *fileName, XkbFile ** pRtrn)
+bool
+XKBParseFile(struct xkb_context *context, FILE *file,
+ const char *file_name, XkbFile **out)
{
int ret;
struct parser_param param;
struct scanner_extra extra;
- *pRtrn = NULL;
if (!file)
- return 1;
+ return false;
+
+ param.context = context;
memset(&extra, 0, sizeof(extra));
- if (yylex_init_extra(&extra, ¶m.scanner) != 0)
- return 0;
- extra.scanFile = strdup(fileName);
+ ret = yylex_init_extra(&extra, ¶m.scanner);
+ if (ret != 0)
+ return false;
+
+ extra.scanFile = strdup(file_name);
+ if (!extra.scanFile)
+ return false;
yyset_in(file, param.scanner);
ret = yyparse(¶m);
yylex_destroy(param.scanner);
free(extra.scanFile);
- if (ret)
- return 0;
+ if (ret != 0)
+ return false;
- CheckDefaultMap(param.rtrn, fileName);
- *pRtrn = param.rtrn;
- return 1;
+ CheckDefaultMap(param.rtrn, file_name);
+ *out = param.rtrn;
+ return true;
}
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 1912dd5..c1b7bd0 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -275,7 +275,7 @@ xkb_map_new_from_string(struct xkb_context *context,
return NULL;
}
- if (!XKBParseString(string, "input", &file) || !file) {
+ if (!XKBParseString(context, string, "input", &file)) {
ERROR("failed to parse input xkb file\n");
return NULL;
}
@@ -308,9 +308,9 @@ xkb_map_new_from_fd(struct xkb_context *context,
return NULL;
}
- if (!XKBParseFile(fptr, "(unknown file)", &file) || !file) {
+ if (!XKBParseFile(context, fptr, "(unknown file)", &file)) {
ERROR("failed to parse input xkb file\n");
- return NULL;
+ return NULL;
}
return compile_keymap(context, file);