Primarily for the include path, but also for the logging in future.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
xkb_context_include_path_clear(struct xkb_context *context);
/**
+ * Returns the number of include paths currently active in the context.
+ */
+_X_EXPORT unsigned int
+xkb_context_num_include_paths(struct xkb_context *context);
+
+/**
+ * Returns the include path at the specified index within the context.
+ */
+_X_EXPORT const char *
+xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
+
+/**
* Takes a new reference on an XKB context.
*/
_X_EXPORT void
* keymaps.
*/
_X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_names(const struct xkb_rule_names *names);
+xkb_map_new_from_names(struct xkb_context *context,
+ const struct xkb_rule_names *names);
/**
* Deprecated entrypoint for legacy users who need to be able to compile
* Geometry will be ignored since xkbcommon does not support it in any way.
*/
_X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst);
+xkb_map_new_from_kccgst(struct xkb_context *context,
+ const struct xkb_component_names *kccgst);
enum xkb_keymap_format {
/** The current/classic XKB text format, as generated by xkbcomp -xkb. */
* file descriptor.
*/
_X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_fd(int fd, enum xkb_keymap_format format);
+xkb_map_new_from_fd(struct xkb_context *context,
+ int fd, enum xkb_keymap_format format);
/**
* Creates an XKB keymap from a full text XKB keymap serialised into one
* enormous string.
*/
_X_EXPORT extern struct xkb_desc *
-xkb_map_new_from_string(const char *string, enum xkb_keymap_format format);
+xkb_map_new_from_string(struct xkb_context *context,
+ const char *string,
+ enum xkb_keymap_format format);
/**
* Takes a new reference on a keymap.
/* Common keyboard description structure */
struct xkb_desc {
+ struct xkb_context *context;
+
unsigned int refcnt;
unsigned int defined;
unsigned short flags;
}
struct xkb_desc *
-XkbcAllocKeyboard(void)
+XkbcAllocKeyboard(struct xkb_context *context)
{
struct xkb_desc *xkb;
xkb = uTypedCalloc(1, struct xkb_desc);
- if (xkb) {
- xkb->device_spec = XkbUseCoreKbd;
- xkb->refcnt = 1;
- }
+ if (!xkb)
+ return NULL;
+
+ xkb->refcnt = 1;
+ xkb_context_ref(context);
+ xkb->context = context;
+ xkb->device_spec = XkbUseCoreKbd;
return xkb;
}
XkbcFreeIndicatorMaps(xkb);
XkbcFreeNames(xkb);
XkbcFreeControls(xkb);
+ xkb_context_unref(xkb->context);
free(xkb);
}
* Returns the number of entries in the context's include path.
*/
unsigned int
-xkb_context_include_path_num_entries(struct xkb_context *context)
+xkb_context_num_include_paths(struct xkb_context *context)
{
- return context->size_include_paths;
+ return context->num_include_paths;
}
/**
* invalid index is passed.
*/
const char *
-xkb_context_include_path_get_entry(struct xkb_context *context,
- unsigned int index)
+xkb_context_include_path_get(struct xkb_context *context, unsigned int index)
{
- if (index >= xkb_context_include_path_num_entries(context))
+ if (index >= xkb_context_num_include_paths(context))
return NULL;
return context->include_paths[index];
XkbcAllocIndicatorMaps(struct xkb_desc * xkb);
extern struct xkb_desc *
-XkbcAllocKeyboard(void);
+XkbcAllocKeyboard(struct xkb_context *context);
extern void
XkbcFreeKeyboard(struct xkb_desc * xkb);
included = *info;
memset(info, 0, sizeof(CompatInfo));
}
- else if (ProcessIncludeFile(stmt, XkmCompatMapIndex, &rtrn, &newMerge))
+ else if (ProcessIncludeFile(xkb->context, stmt, XkmCompatMapIndex, &rtrn,
+ &newMerge))
{
InitCompatInfo(&included, xkb);
included.fileID = rtrn->id;
MergeIncludedCompatMaps(&included, info, next->merge);
ClearCompatInfo(info, xkb);
}
- else if (ProcessIncludeFile(next, XkmCompatMapIndex, &rtrn, &op))
+ else if (ProcessIncludeFile(xkb->context, next, XkmCompatMapIndex,
+ &rtrn, &op))
{
InitCompatInfo(&next_incl, xkb);
next_incl.fileID = rtrn->id;
info->explicitMax = XKB_KEYCODE_MAX;
return (info->errorCount == 0);
} /* parse file, store returned info in the xkb struct */
- else if (ProcessIncludeFile(stmt, XkmKeyNamesIndex, &rtrn, &newMerge))
+ else if (ProcessIncludeFile(xkb->context, stmt, XkmKeyNamesIndex, &rtrn,
+ &newMerge))
{
InitKeyNamesInfo(&included);
HandleKeycodesFile(rtrn, xkb, MergeOverride, &included);
MergeIncludedKeycodes(&included, info, next->merge);
ClearKeyNamesInfo(info);
}
- else if (ProcessIncludeFile(next, XkmKeyNamesIndex, &rtrn, &op))
+ else if (ProcessIncludeFile(xkb->context, next, XkmKeyNamesIndex,
+ &rtrn, &op))
{
InitKeyNamesInfo(&next_incl);
HandleKeycodesFile(rtrn, xkb, MergeOverride, &next_incl);
* XkmKeyNamesIdx, etc.)
*/
struct xkb_desc *
-CompileKeymap(XkbFile *file, unsigned merge)
+CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
{
unsigned have;
Bool ok;
unsigned mainType;
const char *mainName;
LEDInfo *unbound = NULL;
- struct xkb_desc *xkb = XkbcAllocKeyboard();
+ struct xkb_desc *xkb = XkbcAllocKeyboard(context);
struct {
XkbFile *keycodes;
XkbFile *types;
included = *info;
memset(info, 0, sizeof(KeyTypesInfo));
}
- else if (ProcessIncludeFile(stmt, XkmTypesIndex, &rtrn, &newMerge))
+ else if (ProcessIncludeFile(xkb->context, stmt, XkmTypesIndex, &rtrn,
+ &newMerge))
{
InitKeyTypesInfo(&included, xkb, info);
included.fileID = included.dflt.defs.fileID = rtrn->id;
MergeIncludedKeyTypes(&included, info, next->merge, xkb);
FreeKeyTypesInfo(info);
}
- else if (ProcessIncludeFile(next, XkmTypesIndex, &rtrn, &op))
+ else if (ProcessIncludeFile(xkb->context, next, XkmTypesIndex,
+ &rtrn, &op))
{
InitKeyTypesInfo(&next_incl, xkb, &included);
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
* If the statement defines a specific map to use, this map is returned in
* file_rtrn. Otherwise, the default map is returned.
*
+ * @param context The context containing include paths
* @param stmt The include statement, specifying the file name to look for.
* @param file_type Type of file (XkmKeyNamesIdx, etc.)
* @param file_rtrn Returns the key map to be used.
* @return True on success or False otherwise.
*/
Bool
-ProcessIncludeFile(IncludeStmt * stmt,
+ProcessIncludeFile(struct xkb_context *context,
+ IncludeStmt * stmt,
unsigned file_type,
XkbFile ** file_rtrn, unsigned *merge_rtrn)
{
char oldFile[1024] = {0};
int oldLine = lineNum;
- file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
+ file = XkbFindFileInPath(context, stmt->file, file_type, &stmt->path);
if (file == NULL)
{
ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
const char * /* name */
);
-extern Bool ProcessIncludeFile(IncludeStmt * /* stmt */ ,
+extern Bool ProcessIncludeFile(struct xkb_context * /* context */,
+ IncludeStmt * /* stmt */ ,
unsigned /* file_type */ ,
XkbFile ** /* file_rtrn */ ,
unsigned * /* merge_rtrn */
included = *info;
memset(info, 0, sizeof(SymbolsInfo));
}
- else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
+ else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
+ &newMerge))
{
InitSymbolsInfo(&included, xkb);
included.fileID = included.dflt.defs.fileID = rtrn->id;
MergeIncludedSymbols(&included, info, next->merge, xkb);
FreeSymbolsInfo(info);
}
- else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
+ else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
+ &rtrn, &op))
{
InitSymbolsInfo(&next_incl, xkb);
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0);
AppendStmt(&keycodes->common, &symbols->common);
- return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""),
+ return CreateXKBFile(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 *context,
+ const char *rules,
+ const XkbRF_VarDefsPtr defs)
{
FILE *rulesFile = NULL;
char *rulesPath = NULL;
XkbRF_RulesPtr loaded = NULL;
struct xkb_component_names * names = NULL;
- rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath);
+ rulesFile = XkbFindFileInPath(context, rules, XkmRulesFile, &rulesPath);
if (!rulesFile) {
ERROR("could not find \"%s\" rules in XKB path\n", rules);
return NULL;
}
struct xkb_desc *
-xkb_map_new_from_names(const struct xkb_rule_names *rmlvo)
+xkb_map_new_from_names(struct xkb_context *context,
+ const struct xkb_rule_names *rmlvo)
{
XkbRF_VarDefsRec defs;
- struct xkb_component_names * names;
- struct xkb_desc * xkb;
+ struct xkb_component_names *names;
+ struct xkb_desc *xkb;
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(context, rmlvo->rules, &defs);
if (!names) {
ERROR("failed to generate XKB components from rules \"%s\"\n",
rmlvo->rules);
return NULL;
}
- xkb = xkb_map_new_from_kccgst(names);
+ xkb = xkb_map_new_from_kccgst(context, names);
free(names->keymap);
free(names->keycodes);
}
static struct xkb_desc *
-compile_keymap(XkbFile *file)
+compile_keymap(struct xkb_context *context, XkbFile *file)
{
XkbFile *mapToUse;
struct xkb_desc * xkb = NULL;
goto err;
}
- xkb = CompileKeymap(mapToUse, MergeReplace);
+ xkb = CompileKeymap(context, mapToUse, MergeReplace);
if (!xkb)
goto err;
err:
FreeXKBFile(file);
free(scanFile);
- XkbFreeIncludePath();
XkbcFreeAllAtoms();
return xkb;
}
struct xkb_desc *
-xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst)
+xkb_map_new_from_kccgst(struct xkb_context *context,
+ const struct xkb_component_names *kccgst)
{
XkbFile *file;
return NULL;
}
- return compile_keymap(file);
+ return compile_keymap(context, file);
}
struct xkb_desc *
-xkb_map_new_from_string(const char *string, enum xkb_keymap_format format)
+xkb_map_new_from_string(struct xkb_context *context,
+ const char *string,
+ enum xkb_keymap_format format)
{
XkbFile *file;
return NULL;
}
- return compile_keymap(file);
+ return compile_keymap(context, file);
}
struct xkb_desc *
-xkb_map_new_from_fd(int fd, enum xkb_keymap_format format)
+xkb_map_new_from_fd(struct xkb_context *context,
+ int fd,
+ enum xkb_keymap_format format)
{
XkbFile *file;
FILE *fptr;
return NULL;
}
- return compile_keymap(file);
+ return compile_keymap(context, file);
}
void
} XkbFile;
extern struct xkb_desc *
-CompileKeymap(XkbFile *file, unsigned merge);
+CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge);
extern Bool
CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge);
********************************************************/
-#include "utils.h"
#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
-#include "xkbpath.h"
#include "xkbcommon/xkbcommon.h"
#include "XKBcommonint.h"
-
-#ifndef DFLT_XKB_CONFIG_ROOT
-#define DFLT_XKB_CONFIG_ROOT "/usr/lib/X11/xkb"
-#endif
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024
-#endif
-
-/* initial szPath */
-#define PATH_CHUNK 8
-
-static Bool noDefaultPath = False;
-/* number of entries allocated for includePath */
-static size_t szPath;
-/* number of actual entries in includePath */
-static size_t nPathEntries;
-/* Holds all directories we might be including data from */
-static char **includePath = NULL;
+#include "utils.h"
+#include "xkbpath.h"
/**
* Extract the first token from an include statement.
return True;
}
-static void
-XkbAddDefaultDirectoriesToPath(void);
-
-/**
- * Init memory for include paths.
- */
-static Bool
-XkbInitIncludePath(void)
-{
- if (includePath)
- return True;
-
- szPath = PATH_CHUNK;
- includePath = calloc(szPath, sizeof(char *));
- if (!includePath)
- return False;
-
- XkbAddDefaultDirectoriesToPath();
- return True;
-}
-
-/**
- * Remove all entries from the global includePath.
- */
-static void
-XkbClearIncludePath(void)
-{
- size_t i;
-
- if (szPath > 0)
- {
- for (i = 0; i < nPathEntries; i++)
- {
- if (includePath[i] != NULL)
- {
- free(includePath[i]);
- includePath[i] = NULL;
- }
- }
- nPathEntries = 0;
- }
- noDefaultPath = True;
-}
-
-void
-XkbFreeIncludePath(void)
-{
- XkbClearIncludePath();
- free(includePath);
- includePath = NULL;
-}
-
-/**
- * Add the given path to the global includePath variable.
- * If dir is NULL, the includePath is emptied.
- */
-static Bool
-XkbAddDirectoryToPath(const char *dir)
-{
- int len;
-
- if (!XkbInitIncludePath())
- return False;
-
- if ((dir == NULL) || (dir[0] == '\0'))
- {
- XkbClearIncludePath();
- return True;
- }
-#ifdef __UNIXOS2__
- dir = (char *) __XOS2RedirRoot(dir);
-#endif
- len = strlen(dir);
- if (len + 2 >= PATH_MAX)
- { /* allow for '/' and at least one character */
- ERROR("Path entry (%s) too long (maxiumum length is %d)\n",
- dir, PATH_MAX - 3);
- return False;
- }
- if (nPathEntries >= szPath)
- {
- szPath += PATH_CHUNK;
- includePath = realloc(includePath, szPath * sizeof(char *));
- if (includePath == NULL)
- {
- WSGO("Allocation failed (includePath)\n");
- return False;
- }
- }
- includePath[nPathEntries] = strdup(dir);
- if (includePath[nPathEntries] == NULL)
- {
- WSGO("Allocation failed (includePath[%zd])\n", nPathEntries);
- return False;
- }
- nPathEntries++;
- return True;
-}
-
-static void
-XkbAddDefaultDirectoriesToPath(void)
-{
- if (!XkbInitIncludePath())
- return;
- if (noDefaultPath)
- return;
- XkbAddDirectoryToPath(DFLT_XKB_CONFIG_ROOT);
-}
-
/***====================================================================***/
/**
/**
* Search for the given file name in the include directories.
*
+ * @param context the XKB context containing the include paths
* @param type one of XkbTypesIndex, XkbCompatMapIndex, ..., or
- * XkbSemanticsFile, XkmKeymapFile, ...
+ * XkbSemanticsFile, XkmKeymapFile, ...
* @param pathReturn is set to the full path of the file if found.
*
* @return an FD to the file or NULL. If NULL is returned, the value of
* pathRtrn is undefined.
*/
FILE *
-XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
+XkbFindFileInPath(struct xkb_context *context,
+ const char *name, unsigned type, char **pathRtrn)
{
size_t i;
int ret;
char buf[PATH_MAX];
const char *typeDir;
- if (!XkbInitIncludePath())
- return NULL;
-
typeDir = XkbDirectoryForInclude(type);
- for (i = 0; i < nPathEntries; i++)
+ for (i = 0; i < xkb_context_num_include_paths(context); i++)
{
- if (includePath[i] == NULL || *includePath[i] == '\0')
- continue;
-
ret = snprintf(buf, sizeof(buf), "%s/%s/%s",
- includePath[i], typeDir, name);
+ xkb_context_include_path_get(context, i), typeDir, name);
if (ret >= (ssize_t)sizeof(buf))
{
- ERROR("File name (%s/%s/%s) too long\n", includePath[i],
- typeDir, name);
+ ERROR("File name (%s/%s/%s) too long\n",
+ xkb_context_include_path_get(context, i), typeDir, name);
ACTION("Ignored\n");
continue;
}
file = fopen(buf, "r");
if (file == NULL) {
- ERROR("Couldn't open file (%s/%s/%s): %s\n", includePath[i],
- typeDir, name, strerror(-errno));
+ ERROR("Couldn't open file (%s/%s/%s): %s\n",
+ xkb_context_include_path_get(context, i), typeDir, name,
+ strerror(-errno));
ACTION("Ignored\n");
continue;
}
#define _XKBPATH_H_ 1
#include <stdio.h>
-#include <X11/Xdefs.h>
+
+#include "XKBcommonint.h"
extern const char *XkbDirectoryForInclude(unsigned /* type */
);
-extern FILE *XkbFindFileInPath(const char * /* name */ ,
+extern FILE *XkbFindFileInPath(struct xkb_context * /* context */,
+ const char * /* name */ ,
unsigned /* type */ ,
char ** /* pathRtrn */
);
char ** /* extra_data */
);
-extern void XkbFreeIncludePath(void);
-
#endif /* _XKBPATH_H_ */
#include <sys/types.h>
#include <sys/stat.h>
+#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
+ struct xkb_context *context;
+ struct xkb_desc *xkb;
char *path;
int fd;
- struct xkb_desc * xkb;
int i, len, from_string = 0;
/* Require xkb file */
exit(1);
}
+ context = xkb_context_new();
+ assert(context);
+
if (from_string) {
len = read(fd, buffer, sizeof(buffer));
buffer[len] = '\0';
- xkb = xkb_map_new_from_string(buffer, XKB_KEYMAP_FORMAT_TEXT_V1);
+ xkb = xkb_map_new_from_string(context, buffer,
+ XKB_KEYMAP_FORMAT_TEXT_V1);
} else {
- xkb = xkb_map_new_from_fd(fd, XKB_KEYMAP_FORMAT_TEXT_V1);
+ xkb = xkb_map_new_from_fd(context, fd,
+ XKB_KEYMAP_FORMAT_TEXT_V1);
}
close(fd);
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
authorization from the authors.
*/
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "xkbcommon/xkbcommon.h"
int main(int argc, char *argv[])
{
- struct xkb_component_names kccgst;
+ struct xkb_context *context;
struct xkb_desc *xkb;
+ struct xkb_component_names kccgst;
/* Require Kc + T + C + S */
if (argc < 5) {
kccgst.compat = argv[3];
kccgst.symbols = argv[4];
- xkb = xkb_map_new_from_kccgst(&kccgst);
+ context = xkb_context_new();
+ assert(context);
+
+ xkb = xkb_map_new_from_kccgst(context, &kccgst);
if (!xkb) {
fprintf(stderr, "Failed to compile keymap\n");
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
authorization from the authors.
*/
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xdefs.h>
int main(int argc, char *argv[])
{
- struct xkb_rule_names rmlvo;
+ struct xkb_context *context;
struct xkb_desc *xkb;
+ struct xkb_rule_names rmlvo;
/* Require rmlvo */
if (argc < 6) {
rmlvo.variant = argv[4];
rmlvo.options = argv[5];
- xkb = xkb_map_new_from_names(&rmlvo);
+ context = xkb_context_new();
+ assert(context);
+
+ xkb = xkb_map_new_from_names(context, &rmlvo);
if (!xkb) {
fprintf(stderr, "Failed to compile keymap\n");
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
int
main(int argc, char *argv[])
{
- struct xkb_rule_names rmlvo;
+ struct xkb_context *context;
struct xkb_desc *xkb;
+ struct xkb_rule_names rmlvo;
rmlvo.rules = "evdev";
rmlvo.model = "pc104";
rmlvo.variant = NULL;
rmlvo.options = NULL;
- xkb = xkb_map_new_from_names(&rmlvo);
+ context = xkb_context_new();
+ assert(context);
+
+ xkb = xkb_map_new_from_names(context, &rmlvo);
assert(xkb);
test_update_key(xkb);
test_serialisation(xkb);
xkb_map_unref(xkb);
+ xkb_context_unref(context);
}