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>
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);
********************************************************/
-#ifndef XKBPARSE_H
-#define XKBPARSE_H 1
+#ifndef PARSEUTILS_H
+#define PARSEUTILS_H
#include <stdio.h>
#include "parser.h"
struct parser_param {
+ struct xkb_context *context;
void *scanner;
XkbFile *rtrn;
};
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);
extern void
yyerror(struct YYLTYPE *loc, void *scanner, const char *msg);
-#endif /* XKBPARSE_H */
+#endif /* PARSEUTILS_H */
}
}
-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;
}
return NULL;
}
- if (!XKBParseString(string, "input", &file) || !file) {
+ if (!XKBParseString(context, string, "input", &file)) {
ERROR("failed to parse input xkb file\n");
return NULL;
}
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);