authorization from the authors.
*/
-#include <limits.h>
-#include "xkbcomp.h"
-#include "xkballoc.h"
-#include "xkbrules.h"
-#include "xkbpath.h"
-#include "xkbmisc.h"
+#include "xkbcomp-priv.h"
+#include "rules.h"
#include "parseutils.h"
-#include "utils.h"
+#include "path.h"
-/* Global debugging flags */
-unsigned int debugFlags = 0;
+/* Global warning level */
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, ktcsg->keymap ? ktcsg->keymap : strdup(""),
+ return CreateXKBFile(ctx, XkmKeymapFile,
+ ktcsg->keymap ? ktcsg->keymap : strdup(""),
&keycodes->common, 0);
}
static struct xkb_component_names *
-XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
+XkbComponentsFromRules(struct xkb_context *ctx,
+ const char *rules,
+ const XkbRF_VarDefsPtr defs)
{
FILE *rulesFile = NULL;
char *rulesPath = NULL;
XkbRF_RulesPtr loaded = NULL;
struct xkb_component_names * names = NULL;
+ int i;
- rulesFile = XkbFindFileInPath(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(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;
}
- if (!(loaded = _XkbTypedCalloc(1, XkbRF_RulesRec))) {
+ if (!(loaded = uTypedCalloc(1, XkbRF_RulesRec))) {
ERROR("failed to allocate XKB rules\n");
goto unwind_file;
}
goto unwind_file;
}
- if (!(names = _XkbTypedCalloc(1, struct xkb_component_names))) {
+ if (!(names = uTypedCalloc(1, struct xkb_component_names))) {
ERROR("failed to allocate XKB components\n");
goto unwind_file;
}
return names;
}
-struct xkb_desc *
-xkb_compile_keymap_from_rules(const struct xkb_rule_names *rmlvo)
+_X_EXPORT struct xkb_keymap *
+xkb_map_new_from_names(struct xkb_context *ctx,
+ const struct xkb_rule_names *rmlvo,
+ enum xkb_map_compile_flags flags)
{
XkbRF_VarDefsRec defs;
- struct xkb_component_names * names;
- struct xkb_desc * xkb;
+ struct xkb_component_names *names;
+ struct xkb_keymap *keymap;
if (!rmlvo || ISEMPTY(rmlvo->rules) || ISEMPTY(rmlvo->layout)) {
ERROR("rules and layout required to generate XKB keymap\n");
defs.variant = rmlvo->variant;
defs.options = rmlvo->options;
- names = XkbComponentsFromRules(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;
}
- xkb = xkb_compile_keymap_from_components(names);
+ keymap = xkb_map_new_from_kccgst(ctx, names, 0);
free(names->keymap);
free(names->keycodes);
free(names->symbols);
free(names);
- return xkb;
+ return keymap;
}
static XkbFile *
return map;
}
-static struct xkb_desc *
-compile_keymap(XkbFile *file, const char *mapName)
+static struct xkb_keymap *
+compile_keymap(struct xkb_context *ctx, XkbFile *file)
{
XkbFile *mapToUse;
- struct xkb_desc * xkb = NULL;
+ struct xkb_keymap *keymap = NULL;
/* Find map to use */
- if (!(mapToUse = XkbChooseMap(file, mapName)))
- goto unwind_file;
+ mapToUse = XkbChooseMap(file, NULL);
+ 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 unwind_file;
- }
-
- /* Compile the keyboard */
- if (!(xkb = XkbcAllocKeyboard())) {
- ERROR("could not allocate keyboard description\n");
- goto unwind_file;
+ goto err;
}
- if (!CompileKeymap(mapToUse, xkb, MergeReplace)) {
- ERROR("failed to compile keymap\n");
- XkbcFreeKeyboard(xkb);
- xkb = NULL;
- }
+ keymap = CompileKeymap(ctx, mapToUse);
+ if (!keymap)
+ goto err;
-unwind_file:
+err:
FreeXKBFile(file);
- free(scanFile);
- XkbFreeIncludePath();
- return xkb;
+ return keymap;
}
-struct xkb_desc *
-xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg)
+_X_EXPORT struct xkb_keymap *
+xkb_map_new_from_kccgst(struct xkb_context *ctx,
+ const struct xkb_component_names *kccgst,
+ enum xkb_map_compile_flags flags)
{
XkbFile *file;
- if (!ktcsg) {
+ if (!kccgst) {
ERROR("no components specified\n");
return NULL;
}
- if (ISEMPTY(ktcsg->keycodes)) {
+ if (ISEMPTY(kccgst->keycodes)) {
ERROR("keycodes required to generate XKB keymap\n");
return NULL;
}
- if (ISEMPTY(ktcsg->compat)) {
+ if (ISEMPTY(kccgst->compat)) {
ERROR("compat map required to generate XKB keymap\n");
return NULL;
}
- if (ISEMPTY(ktcsg->types)) {
+ if (ISEMPTY(kccgst->types)) {
ERROR("types required to generate XKB keymap\n");
return NULL;
}
- if (ISEMPTY(ktcsg->symbols)) {
+ if (ISEMPTY(kccgst->symbols)) {
ERROR("symbols required to generate XKB keymap\n");
return NULL;
}
- if (!(file = XkbKeymapFileFromComponents(ktcsg))) {
+ if (!(file = XkbKeymapFileFromComponents(ctx, kccgst))) {
ERROR("failed to generate parsed XKB file from components\n");
return NULL;
}
- return compile_keymap(file, NULL);
+ return compile_keymap(ctx, file);
}
-struct xkb_desc *
-xkb_compile_keymap_from_string(const char *string, const char *mapName)
+_X_EXPORT struct xkb_keymap *
+xkb_map_new_from_string(struct xkb_context *ctx,
+ const char *string,
+ enum xkb_keymap_format format,
+ enum xkb_map_compile_flags flags)
{
XkbFile *file;
+ if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
+ ERROR("unsupported keymap format %d\n", format);
+ return NULL;
+ }
+
if (!string) {
ERROR("no string specified to generate XKB keymap\n");
return NULL;
}
- setScanState("input", 1);
- if (!XKBParseString(string, &file) || !file) {
+ if (!XKBParseString(ctx, string, "input", &file)) {
ERROR("failed to parse input xkb file\n");
return NULL;
}
- return compile_keymap(file, mapName);
+ return compile_keymap(ctx, file);
}
-struct xkb_desc *
-xkb_compile_keymap_from_file(FILE *inputFile, const char *mapName)
+_X_EXPORT struct xkb_keymap *
+xkb_map_new_from_file(struct xkb_context *ctx,
+ FILE *file,
+ enum xkb_keymap_format format,
+ enum xkb_map_compile_flags flags)
{
- XkbFile *file;
+ XkbFile *xkb_file;
- if (!inputFile) {
+ if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
+ ERROR("unsupported keymap format %d\n", format);
+ return NULL;
+ }
+
+ if (!file) {
ERROR("no file specified to generate XKB keymap\n");
- return NULL;
+ return NULL;
}
- setScanState("input", 1);
- if (!XKBParseFile(inputFile, &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(file, mapName);
+ return compile_keymap(ctx, xkb_file);
}
-void
-xkb_free_keymap(struct xkb_desc *xkb)
+_X_EXPORT struct xkb_keymap *
+xkb_map_ref(struct xkb_keymap *keymap)
{
- XkbcFreeKeyboard(xkb);
- XkbcFreeAllAtoms();
+ keymap->refcnt++;
+ return keymap;
+}
+
+_X_EXPORT void
+xkb_map_unref(struct xkb_keymap *keymap)
+{
+ if (--keymap->refcnt > 0)
+ return;
+
+ XkbcFreeKeyboard(keymap);
}