X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxkbcomp%2Fxkbcomp.c;h=68e180f779132659d050b273d472788c3a5de394;hb=db3e8f2c0842aeaf1d00177c248ff908073fe73a;hp=1912dd5e46a690bd9d56e53d1339d2c182409903;hpb=38cb639082ec4b31725d4ce4e35af63938691631;p=profile%2Fivi%2Flibxkbcommon.git diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c index 1912dd5..68e180f 100644 --- a/src/xkbcomp/xkbcomp.c +++ b/src/xkbcomp/xkbcomp.c @@ -27,6 +27,7 @@ authorization from the authors. #include "xkbcomp-priv.h" #include "rules.h" #include "parseutils.h" +#include "path.h" /* Global warning level */ unsigned int warningLevel = 0; @@ -34,33 +35,38 @@ unsigned int warningLevel = 0; #define ISEMPTY(str) (!(str) || (strlen(str) == 0)) static XkbFile * -XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg) +XkbKeymapFileFromComponents(struct xkb_context *ctx, + const struct xkb_component_names *ktcsg) { XkbFile *keycodes, *types, *compat, *symbols; IncludeStmt *inc; inc = IncludeCreate(ktcsg->keycodes, MergeDefault); - keycodes = CreateXKBFile(XkmKeyNamesIndex, NULL, (ParseCommon *)inc, 0); + keycodes = CreateXKBFile(ctx, XkmKeyNamesIndex, NULL, + (ParseCommon *)inc, 0); inc = IncludeCreate(ktcsg->types, MergeDefault); - types = CreateXKBFile(XkmTypesIndex, NULL, (ParseCommon *)inc, 0); + types = CreateXKBFile(ctx, XkmTypesIndex, NULL, + (ParseCommon *)inc, 0); AppendStmt(&keycodes->common, &types->common); inc = IncludeCreate(ktcsg->compat, MergeDefault); - compat = CreateXKBFile(XkmCompatMapIndex, NULL, (ParseCommon *)inc, 0); + compat = CreateXKBFile(ctx, XkmCompatMapIndex, NULL, + (ParseCommon *)inc, 0); AppendStmt(&keycodes->common, &compat->common); inc = IncludeCreate(ktcsg->symbols, MergeDefault); - symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0); + symbols = CreateXKBFile(ctx, XkmSymbolsIndex, NULL, + (ParseCommon *)inc, 0); AppendStmt(&keycodes->common, &symbols->common); - return CreateXKBFile(XkmKeymapFile, + return CreateXKBFile(ctx, XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""), &keycodes->common, 0); } static struct xkb_component_names * -XkbComponentsFromRules(struct xkb_context *context, +XkbComponentsFromRules(struct xkb_context *ctx, const char *rules, const XkbRF_VarDefsPtr defs) { @@ -70,13 +76,13 @@ XkbComponentsFromRules(struct xkb_context *context, struct xkb_component_names * names = NULL; int i; - rulesFile = XkbFindFileInPath(context, rules, XkmRulesFile, &rulesPath); + rulesFile = XkbFindFileInPath(ctx, rules, XkmRulesFile, &rulesPath); if (!rulesFile) { ERROR("could not find \"%s\" rules in XKB path\n", rules); ERROR("%d include paths searched:\n", - xkb_context_num_include_paths(context)); - for (i = 0; i < xkb_context_num_include_paths(context); i++) - ERROR("\t%s\n", xkb_context_include_path_get(context, i)); + xkb_context_num_include_paths(ctx)); + for (i = 0; i < xkb_context_num_include_paths(ctx); i++) + ERROR("\t%s\n", xkb_context_include_path_get(ctx, i)); return NULL; } @@ -115,7 +121,7 @@ unwind_file: } _X_EXPORT struct xkb_keymap * -xkb_map_new_from_names(struct xkb_context *context, +xkb_map_new_from_names(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo, enum xkb_map_compile_flags flags) { @@ -133,14 +139,14 @@ xkb_map_new_from_names(struct xkb_context *context, defs.variant = rmlvo->variant; defs.options = rmlvo->options; - names = XkbComponentsFromRules(context, rmlvo->rules, &defs); + names = XkbComponentsFromRules(ctx, rmlvo->rules, &defs); if (!names) { ERROR("failed to generate XKB components from rules \"%s\"\n", rmlvo->rules); return NULL; } - keymap = xkb_map_new_from_kccgst(context, names, 0); + keymap = xkb_map_new_from_kccgst(ctx, names, 0); free(names->keymap); free(names->keycodes); @@ -187,7 +193,7 @@ XkbChooseMap(XkbFile *file, const char *name) } static struct xkb_keymap * -compile_keymap(struct xkb_context *context, XkbFile *file) +compile_keymap(struct xkb_context *ctx, XkbFile *file) { XkbFile *mapToUse; struct xkb_keymap *keymap = NULL; @@ -197,28 +203,22 @@ compile_keymap(struct xkb_context *context, XkbFile *file) if (!mapToUse) goto err; - switch (mapToUse->type) { - case XkmSemanticsFile: - case XkmLayoutFile: - case XkmKeymapFile: - break; - default: + if (mapToUse->type != XkmKeymapFile) { ERROR("file type %d not handled\n", mapToUse->type); goto err; } - keymap = CompileKeymap(context, mapToUse); + keymap = CompileKeymap(ctx, mapToUse); if (!keymap) goto err; err: FreeXKBFile(file); - XkbcFreeAllAtoms(); return keymap; } _X_EXPORT struct xkb_keymap * -xkb_map_new_from_kccgst(struct xkb_context *context, +xkb_map_new_from_kccgst(struct xkb_context *ctx, const struct xkb_component_names *kccgst, enum xkb_map_compile_flags flags) { @@ -249,16 +249,16 @@ xkb_map_new_from_kccgst(struct xkb_context *context, return NULL; } - if (!(file = XkbKeymapFileFromComponents(kccgst))) { + if (!(file = XkbKeymapFileFromComponents(ctx, kccgst))) { ERROR("failed to generate parsed XKB file from components\n"); return NULL; } - return compile_keymap(context, file); + return compile_keymap(ctx, file); } _X_EXPORT struct xkb_keymap * -xkb_map_new_from_string(struct xkb_context *context, +xkb_map_new_from_string(struct xkb_context *ctx, const char *string, enum xkb_keymap_format format, enum xkb_map_compile_flags flags) @@ -275,45 +275,38 @@ xkb_map_new_from_string(struct xkb_context *context, return NULL; } - if (!XKBParseString(string, "input", &file) || !file) { + if (!XKBParseString(ctx, string, "input", &file)) { ERROR("failed to parse input xkb file\n"); return NULL; } - return compile_keymap(context, file); + return compile_keymap(ctx, file); } _X_EXPORT struct xkb_keymap * -xkb_map_new_from_fd(struct xkb_context *context, - int fd, - enum xkb_keymap_format format, - enum xkb_map_compile_flags flags) +xkb_map_new_from_file(struct xkb_context *ctx, + FILE *file, + enum xkb_keymap_format format, + enum xkb_map_compile_flags flags) { - XkbFile *file; - FILE *fptr; + XkbFile *xkb_file; if (format != XKB_KEYMAP_FORMAT_TEXT_V1) { ERROR("unsupported keymap format %d\n", format); return NULL; } - if (fd < 0) { + if (!file) { ERROR("no file specified to generate XKB keymap\n"); - return NULL; - } - - fptr = fdopen(fd, "r"); - if (!fptr) { - ERROR("couldn't associate fd with file pointer\n"); return NULL; } - if (!XKBParseFile(fptr, "(unknown file)", &file) || !file) { + if (!XKBParseFile(ctx, file, "(unknown file)", &xkb_file)) { ERROR("failed to parse input xkb file\n"); - return NULL; + return NULL; } - return compile_keymap(context, file); + return compile_keymap(ctx, xkb_file); } _X_EXPORT struct xkb_keymap *