Use xkb_contexts in keymap compilation
Primarily for the include path, but also for the logging in future. Signed-off-by: Daniel Stone <daniel@fooishbar.org>master
parent
3e9dd7512c
commit
034ffce664
|
@ -236,6 +236,18 @@ xkb_context_include_path_reset(struct xkb_context *context);
|
||||||
_X_EXPORT void
|
_X_EXPORT void
|
||||||
xkb_context_include_path_clear(struct xkb_context *context);
|
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.
|
* Takes a new reference on an XKB context.
|
||||||
*/
|
*/
|
||||||
|
@ -265,7 +277,8 @@ xkb_context_unref(struct xkb_context *context);
|
||||||
* keymaps.
|
* keymaps.
|
||||||
*/
|
*/
|
||||||
_X_EXPORT extern struct xkb_desc *
|
_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
|
* Deprecated entrypoint for legacy users who need to be able to compile
|
||||||
|
@ -278,7 +291,8 @@ xkb_map_new_from_names(const struct xkb_rule_names *names);
|
||||||
* Geometry will be ignored since xkbcommon does not support it in any way.
|
* Geometry will be ignored since xkbcommon does not support it in any way.
|
||||||
*/
|
*/
|
||||||
_X_EXPORT extern struct xkb_desc *
|
_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 {
|
enum xkb_keymap_format {
|
||||||
/** The current/classic XKB text format, as generated by xkbcomp -xkb. */
|
/** The current/classic XKB text format, as generated by xkbcomp -xkb. */
|
||||||
|
@ -290,14 +304,17 @@ enum xkb_keymap_format {
|
||||||
* file descriptor.
|
* file descriptor.
|
||||||
*/
|
*/
|
||||||
_X_EXPORT extern struct xkb_desc *
|
_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
|
* Creates an XKB keymap from a full text XKB keymap serialised into one
|
||||||
* enormous string.
|
* enormous string.
|
||||||
*/
|
*/
|
||||||
_X_EXPORT extern struct xkb_desc *
|
_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.
|
* Takes a new reference on a keymap.
|
||||||
|
|
|
@ -392,6 +392,8 @@ struct xkb_controls {
|
||||||
|
|
||||||
/* Common keyboard description structure */
|
/* Common keyboard description structure */
|
||||||
struct xkb_desc {
|
struct xkb_desc {
|
||||||
|
struct xkb_context *context;
|
||||||
|
|
||||||
unsigned int refcnt;
|
unsigned int refcnt;
|
||||||
unsigned int defined;
|
unsigned int defined;
|
||||||
unsigned short flags;
|
unsigned short flags;
|
||||||
|
|
14
src/alloc.c
14
src/alloc.c
|
@ -257,15 +257,18 @@ XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xkb_desc *
|
struct xkb_desc *
|
||||||
XkbcAllocKeyboard(void)
|
XkbcAllocKeyboard(struct xkb_context *context)
|
||||||
{
|
{
|
||||||
struct xkb_desc *xkb;
|
struct xkb_desc *xkb;
|
||||||
|
|
||||||
xkb = uTypedCalloc(1, struct xkb_desc);
|
xkb = uTypedCalloc(1, struct xkb_desc);
|
||||||
if (xkb) {
|
if (!xkb)
|
||||||
xkb->device_spec = XkbUseCoreKbd;
|
return NULL;
|
||||||
xkb->refcnt = 1;
|
|
||||||
}
|
xkb->refcnt = 1;
|
||||||
|
xkb_context_ref(context);
|
||||||
|
xkb->context = context;
|
||||||
|
xkb->device_spec = XkbUseCoreKbd;
|
||||||
|
|
||||||
return xkb;
|
return xkb;
|
||||||
}
|
}
|
||||||
|
@ -282,5 +285,6 @@ XkbcFreeKeyboard(struct xkb_desc * xkb)
|
||||||
XkbcFreeIndicatorMaps(xkb);
|
XkbcFreeIndicatorMaps(xkb);
|
||||||
XkbcFreeNames(xkb);
|
XkbcFreeNames(xkb);
|
||||||
XkbcFreeControls(xkb);
|
XkbcFreeControls(xkb);
|
||||||
|
xkb_context_unref(xkb->context);
|
||||||
free(xkb);
|
free(xkb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,9 +134,9 @@ xkb_context_include_path_reset_defaults(struct xkb_context *context)
|
||||||
* Returns the number of entries in the context's include path.
|
* Returns the number of entries in the context's include path.
|
||||||
*/
|
*/
|
||||||
unsigned int
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,10 +144,9 @@ xkb_context_include_path_num_entries(struct xkb_context *context)
|
||||||
* invalid index is passed.
|
* invalid index is passed.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
xkb_context_include_path_get_entry(struct xkb_context *context,
|
xkb_context_include_path_get(struct xkb_context *context, unsigned int index)
|
||||||
unsigned int index)
|
|
||||||
{
|
{
|
||||||
if (index >= xkb_context_include_path_num_entries(context))
|
if (index >= xkb_context_num_include_paths(context))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return context->include_paths[index];
|
return context->include_paths[index];
|
||||||
|
|
|
@ -44,7 +44,7 @@ extern int
|
||||||
XkbcAllocIndicatorMaps(struct xkb_desc * xkb);
|
XkbcAllocIndicatorMaps(struct xkb_desc * xkb);
|
||||||
|
|
||||||
extern struct xkb_desc *
|
extern struct xkb_desc *
|
||||||
XkbcAllocKeyboard(void);
|
XkbcAllocKeyboard(struct xkb_context *context);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
XkbcFreeKeyboard(struct xkb_desc * xkb);
|
XkbcFreeKeyboard(struct xkb_desc * xkb);
|
||||||
|
|
|
@ -409,7 +409,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
|
||||||
included = *info;
|
included = *info;
|
||||||
memset(info, 0, sizeof(CompatInfo));
|
memset(info, 0, sizeof(CompatInfo));
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(stmt, XkmCompatMapIndex, &rtrn, &newMerge))
|
else if (ProcessIncludeFile(xkb->context, stmt, XkmCompatMapIndex, &rtrn,
|
||||||
|
&newMerge))
|
||||||
{
|
{
|
||||||
InitCompatInfo(&included, xkb);
|
InitCompatInfo(&included, xkb);
|
||||||
included.fileID = rtrn->id;
|
included.fileID = rtrn->id;
|
||||||
|
@ -449,7 +450,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
|
||||||
MergeIncludedCompatMaps(&included, info, next->merge);
|
MergeIncludedCompatMaps(&included, info, next->merge);
|
||||||
ClearCompatInfo(info, xkb);
|
ClearCompatInfo(info, xkb);
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(next, XkmCompatMapIndex, &rtrn, &op))
|
else if (ProcessIncludeFile(xkb->context, next, XkmCompatMapIndex,
|
||||||
|
&rtrn, &op))
|
||||||
{
|
{
|
||||||
InitCompatInfo(&next_incl, xkb);
|
InitCompatInfo(&next_incl, xkb);
|
||||||
next_incl.fileID = rtrn->id;
|
next_incl.fileID = rtrn->id;
|
||||||
|
|
|
@ -568,7 +568,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
|
||||||
info->explicitMax = XKB_KEYCODE_MAX;
|
info->explicitMax = XKB_KEYCODE_MAX;
|
||||||
return (info->errorCount == 0);
|
return (info->errorCount == 0);
|
||||||
} /* parse file, store returned info in the xkb struct */
|
} /* 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);
|
InitKeyNamesInfo(&included);
|
||||||
HandleKeycodesFile(rtrn, xkb, MergeOverride, &included);
|
HandleKeycodesFile(rtrn, xkb, MergeOverride, &included);
|
||||||
|
@ -600,7 +601,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
|
||||||
MergeIncludedKeycodes(&included, info, next->merge);
|
MergeIncludedKeycodes(&included, info, next->merge);
|
||||||
ClearKeyNamesInfo(info);
|
ClearKeyNamesInfo(info);
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(next, XkmKeyNamesIndex, &rtrn, &op))
|
else if (ProcessIncludeFile(xkb->context, next, XkmKeyNamesIndex,
|
||||||
|
&rtrn, &op))
|
||||||
{
|
{
|
||||||
InitKeyNamesInfo(&next_incl);
|
InitKeyNamesInfo(&next_incl);
|
||||||
HandleKeycodesFile(rtrn, xkb, MergeOverride, &next_incl);
|
HandleKeycodesFile(rtrn, xkb, MergeOverride, &next_incl);
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
* XkmKeyNamesIdx, etc.)
|
* XkmKeyNamesIdx, etc.)
|
||||||
*/
|
*/
|
||||||
struct xkb_desc *
|
struct xkb_desc *
|
||||||
CompileKeymap(XkbFile *file, unsigned merge)
|
CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
|
||||||
{
|
{
|
||||||
unsigned have;
|
unsigned have;
|
||||||
Bool ok;
|
Bool ok;
|
||||||
|
@ -47,7 +47,7 @@ CompileKeymap(XkbFile *file, unsigned merge)
|
||||||
unsigned mainType;
|
unsigned mainType;
|
||||||
const char *mainName;
|
const char *mainName;
|
||||||
LEDInfo *unbound = NULL;
|
LEDInfo *unbound = NULL;
|
||||||
struct xkb_desc *xkb = XkbcAllocKeyboard();
|
struct xkb_desc *xkb = XkbcAllocKeyboard(context);
|
||||||
struct {
|
struct {
|
||||||
XkbFile *keycodes;
|
XkbFile *keycodes;
|
||||||
XkbFile *types;
|
XkbFile *types;
|
||||||
|
|
|
@ -378,7 +378,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
|
||||||
included = *info;
|
included = *info;
|
||||||
memset(info, 0, sizeof(KeyTypesInfo));
|
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);
|
InitKeyTypesInfo(&included, xkb, info);
|
||||||
included.fileID = included.dflt.defs.fileID = rtrn->id;
|
included.fileID = included.dflt.defs.fileID = rtrn->id;
|
||||||
|
@ -412,7 +413,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
|
||||||
MergeIncludedKeyTypes(&included, info, next->merge, xkb);
|
MergeIncludedKeyTypes(&included, info, next->merge, xkb);
|
||||||
FreeKeyTypesInfo(info);
|
FreeKeyTypesInfo(info);
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(next, XkmTypesIndex, &rtrn, &op))
|
else if (ProcessIncludeFile(xkb->context, next, XkmTypesIndex,
|
||||||
|
&rtrn, &op))
|
||||||
{
|
{
|
||||||
InitKeyTypesInfo(&next_incl, xkb, &included);
|
InitKeyTypesInfo(&next_incl, xkb, &included);
|
||||||
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
|
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
* If the statement defines a specific map to use, this map is returned in
|
* If the statement defines a specific map to use, this map is returned in
|
||||||
* file_rtrn. Otherwise, the default map is returned.
|
* 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 stmt The include statement, specifying the file name to look for.
|
||||||
* @param file_type Type of file (XkmKeyNamesIdx, etc.)
|
* @param file_type Type of file (XkmKeyNamesIdx, etc.)
|
||||||
* @param file_rtrn Returns the key map to be used.
|
* @param file_rtrn Returns the key map to be used.
|
||||||
|
@ -48,7 +49,8 @@
|
||||||
* @return True on success or False otherwise.
|
* @return True on success or False otherwise.
|
||||||
*/
|
*/
|
||||||
Bool
|
Bool
|
||||||
ProcessIncludeFile(IncludeStmt * stmt,
|
ProcessIncludeFile(struct xkb_context *context,
|
||||||
|
IncludeStmt * stmt,
|
||||||
unsigned file_type,
|
unsigned file_type,
|
||||||
XkbFile ** file_rtrn, unsigned *merge_rtrn)
|
XkbFile ** file_rtrn, unsigned *merge_rtrn)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +59,7 @@ ProcessIncludeFile(IncludeStmt * stmt,
|
||||||
char oldFile[1024] = {0};
|
char oldFile[1024] = {0};
|
||||||
int oldLine = lineNum;
|
int oldLine = lineNum;
|
||||||
|
|
||||||
file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
|
file = XkbFindFileInPath(context, stmt->file, file_type, &stmt->path);
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
|
ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
|
||||||
|
|
|
@ -69,7 +69,8 @@ extern int ReportBadField(const char * /* type */ ,
|
||||||
const char * /* name */
|
const char * /* name */
|
||||||
);
|
);
|
||||||
|
|
||||||
extern Bool ProcessIncludeFile(IncludeStmt * /* stmt */ ,
|
extern Bool ProcessIncludeFile(struct xkb_context * /* context */,
|
||||||
|
IncludeStmt * /* stmt */ ,
|
||||||
unsigned /* file_type */ ,
|
unsigned /* file_type */ ,
|
||||||
XkbFile ** /* file_rtrn */ ,
|
XkbFile ** /* file_rtrn */ ,
|
||||||
unsigned * /* merge_rtrn */
|
unsigned * /* merge_rtrn */
|
||||||
|
|
|
@ -757,7 +757,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
|
||||||
included = *info;
|
included = *info;
|
||||||
memset(info, 0, sizeof(SymbolsInfo));
|
memset(info, 0, sizeof(SymbolsInfo));
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
|
else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
|
||||||
|
&newMerge))
|
||||||
{
|
{
|
||||||
InitSymbolsInfo(&included, xkb);
|
InitSymbolsInfo(&included, xkb);
|
||||||
included.fileID = included.dflt.defs.fileID = rtrn->id;
|
included.fileID = included.dflt.defs.fileID = rtrn->id;
|
||||||
|
@ -798,7 +799,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
|
||||||
MergeIncludedSymbols(&included, info, next->merge, xkb);
|
MergeIncludedSymbols(&included, info, next->merge, xkb);
|
||||||
FreeSymbolsInfo(info);
|
FreeSymbolsInfo(info);
|
||||||
}
|
}
|
||||||
else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
|
else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
|
||||||
|
&rtrn, &op))
|
||||||
{
|
{
|
||||||
InitSymbolsInfo(&next_incl, xkb);
|
InitSymbolsInfo(&next_incl, xkb);
|
||||||
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
|
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
|
||||||
|
|
|
@ -59,19 +59,22 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
|
||||||
symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0);
|
symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0);
|
||||||
AppendStmt(&keycodes->common, &symbols->common);
|
AppendStmt(&keycodes->common, &symbols->common);
|
||||||
|
|
||||||
return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""),
|
return CreateXKBFile(XkmKeymapFile,
|
||||||
|
ktcsg->keymap ? ktcsg->keymap : strdup(""),
|
||||||
&keycodes->common, 0);
|
&keycodes->common, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xkb_component_names *
|
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;
|
FILE *rulesFile = NULL;
|
||||||
char *rulesPath = NULL;
|
char *rulesPath = NULL;
|
||||||
XkbRF_RulesPtr loaded = NULL;
|
XkbRF_RulesPtr loaded = NULL;
|
||||||
struct xkb_component_names * names = NULL;
|
struct xkb_component_names * names = NULL;
|
||||||
|
|
||||||
rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath);
|
rulesFile = XkbFindFileInPath(context, rules, XkmRulesFile, &rulesPath);
|
||||||
if (!rulesFile) {
|
if (!rulesFile) {
|
||||||
ERROR("could not find \"%s\" rules in XKB path\n", rules);
|
ERROR("could not find \"%s\" rules in XKB path\n", rules);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -112,11 +115,12 @@ unwind_file:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xkb_desc *
|
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;
|
XkbRF_VarDefsRec defs;
|
||||||
struct xkb_component_names * names;
|
struct xkb_component_names *names;
|
||||||
struct xkb_desc * xkb;
|
struct xkb_desc *xkb;
|
||||||
|
|
||||||
if (!rmlvo || ISEMPTY(rmlvo->rules) || ISEMPTY(rmlvo->layout)) {
|
if (!rmlvo || ISEMPTY(rmlvo->rules) || ISEMPTY(rmlvo->layout)) {
|
||||||
ERROR("rules and layout required to generate XKB keymap\n");
|
ERROR("rules and layout required to generate XKB keymap\n");
|
||||||
|
@ -128,14 +132,14 @@ xkb_map_new_from_names(const struct xkb_rule_names *rmlvo)
|
||||||
defs.variant = rmlvo->variant;
|
defs.variant = rmlvo->variant;
|
||||||
defs.options = rmlvo->options;
|
defs.options = rmlvo->options;
|
||||||
|
|
||||||
names = XkbComponentsFromRules(rmlvo->rules, &defs);
|
names = XkbComponentsFromRules(context, rmlvo->rules, &defs);
|
||||||
if (!names) {
|
if (!names) {
|
||||||
ERROR("failed to generate XKB components from rules \"%s\"\n",
|
ERROR("failed to generate XKB components from rules \"%s\"\n",
|
||||||
rmlvo->rules);
|
rmlvo->rules);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb = xkb_map_new_from_kccgst(names);
|
xkb = xkb_map_new_from_kccgst(context, names);
|
||||||
|
|
||||||
free(names->keymap);
|
free(names->keymap);
|
||||||
free(names->keycodes);
|
free(names->keycodes);
|
||||||
|
@ -182,7 +186,7 @@ XkbChooseMap(XkbFile *file, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xkb_desc *
|
static struct xkb_desc *
|
||||||
compile_keymap(XkbFile *file)
|
compile_keymap(struct xkb_context *context, XkbFile *file)
|
||||||
{
|
{
|
||||||
XkbFile *mapToUse;
|
XkbFile *mapToUse;
|
||||||
struct xkb_desc * xkb = NULL;
|
struct xkb_desc * xkb = NULL;
|
||||||
|
@ -202,20 +206,20 @@ compile_keymap(XkbFile *file)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb = CompileKeymap(mapToUse, MergeReplace);
|
xkb = CompileKeymap(context, mapToUse, MergeReplace);
|
||||||
if (!xkb)
|
if (!xkb)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
FreeXKBFile(file);
|
FreeXKBFile(file);
|
||||||
free(scanFile);
|
free(scanFile);
|
||||||
XkbFreeIncludePath();
|
|
||||||
XkbcFreeAllAtoms();
|
XkbcFreeAllAtoms();
|
||||||
return xkb;
|
return xkb;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xkb_desc *
|
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;
|
XkbFile *file;
|
||||||
|
|
||||||
|
@ -249,11 +253,13 @@ xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return compile_keymap(file);
|
return compile_keymap(context, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xkb_desc *
|
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;
|
XkbFile *file;
|
||||||
|
|
||||||
|
@ -273,11 +279,13 @@ xkb_map_new_from_string(const char *string, enum xkb_keymap_format format)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return compile_keymap(file);
|
return compile_keymap(context, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xkb_desc *
|
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;
|
XkbFile *file;
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
@ -304,7 +312,7 @@ xkb_map_new_from_fd(int fd, enum xkb_keymap_format format)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return compile_keymap(file);
|
return compile_keymap(context, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -253,7 +253,7 @@ typedef struct _XkbFile
|
||||||
} XkbFile;
|
} XkbFile;
|
||||||
|
|
||||||
extern struct xkb_desc *
|
extern struct xkb_desc *
|
||||||
CompileKeymap(XkbFile *file, unsigned merge);
|
CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge);
|
||||||
|
|
||||||
extern Bool
|
extern Bool
|
||||||
CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge);
|
CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge);
|
||||||
|
|
|
@ -24,31 +24,13 @@
|
||||||
|
|
||||||
********************************************************/
|
********************************************************/
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "xkbpath.h"
|
|
||||||
#include "xkbcommon/xkbcommon.h"
|
#include "xkbcommon/xkbcommon.h"
|
||||||
#include "XKBcommonint.h"
|
#include "XKBcommonint.h"
|
||||||
|
#include "utils.h"
|
||||||
#ifndef DFLT_XKB_CONFIG_ROOT
|
#include "xkbpath.h"
|
||||||
#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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the first token from an include statement.
|
* Extract the first token from an include statement.
|
||||||
|
@ -157,115 +139,6 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
|
||||||
return True;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***====================================================================***/
|
/***====================================================================***/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,15 +178,17 @@ XkbDirectoryForInclude(unsigned type)
|
||||||
/**
|
/**
|
||||||
* Search for the given file name in the include directories.
|
* 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
|
* @param type one of XkbTypesIndex, XkbCompatMapIndex, ..., or
|
||||||
* XkbSemanticsFile, XkmKeymapFile, ...
|
* XkbSemanticsFile, XkmKeymapFile, ...
|
||||||
* @param pathReturn is set to the full path of the file if found.
|
* @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
|
* @return an FD to the file or NULL. If NULL is returned, the value of
|
||||||
* pathRtrn is undefined.
|
* pathRtrn is undefined.
|
||||||
*/
|
*/
|
||||||
FILE *
|
FILE *
|
||||||
XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
|
XkbFindFileInPath(struct xkb_context *context,
|
||||||
|
const char *name, unsigned type, char **pathRtrn)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -321,28 +196,23 @@ XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
const char *typeDir;
|
const char *typeDir;
|
||||||
|
|
||||||
if (!XkbInitIncludePath())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
typeDir = XkbDirectoryForInclude(type);
|
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",
|
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))
|
if (ret >= (ssize_t)sizeof(buf))
|
||||||
{
|
{
|
||||||
ERROR("File name (%s/%s/%s) too long\n", includePath[i],
|
ERROR("File name (%s/%s/%s) too long\n",
|
||||||
typeDir, name);
|
xkb_context_include_path_get(context, i), typeDir, name);
|
||||||
ACTION("Ignored\n");
|
ACTION("Ignored\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
file = fopen(buf, "r");
|
file = fopen(buf, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
ERROR("Couldn't open file (%s/%s/%s): %s\n", includePath[i],
|
ERROR("Couldn't open file (%s/%s/%s): %s\n",
|
||||||
typeDir, name, strerror(-errno));
|
xkb_context_include_path_get(context, i), typeDir, name,
|
||||||
|
strerror(-errno));
|
||||||
ACTION("Ignored\n");
|
ACTION("Ignored\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,14 @@
|
||||||
#define _XKBPATH_H_ 1
|
#define _XKBPATH_H_ 1
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <X11/Xdefs.h>
|
|
||||||
|
#include "XKBcommonint.h"
|
||||||
|
|
||||||
extern const char *XkbDirectoryForInclude(unsigned /* type */
|
extern const char *XkbDirectoryForInclude(unsigned /* type */
|
||||||
);
|
);
|
||||||
|
|
||||||
extern FILE *XkbFindFileInPath(const char * /* name */ ,
|
extern FILE *XkbFindFileInPath(struct xkb_context * /* context */,
|
||||||
|
const char * /* name */ ,
|
||||||
unsigned /* type */ ,
|
unsigned /* type */ ,
|
||||||
char ** /* pathRtrn */
|
char ** /* pathRtrn */
|
||||||
);
|
);
|
||||||
|
@ -45,6 +47,4 @@ extern Bool XkbParseIncludeMap(char ** /* str_inout */ ,
|
||||||
char ** /* extra_data */
|
char ** /* extra_data */
|
||||||
);
|
);
|
||||||
|
|
||||||
extern void XkbFreeIncludePath(void);
|
|
||||||
|
|
||||||
#endif /* _XKBPATH_H_ */
|
#endif /* _XKBPATH_H_ */
|
||||||
|
|
|
@ -26,6 +26,7 @@ authorization from the authors.
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -39,9 +40,10 @@ static char buffer[8192];
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
struct xkb_context *context;
|
||||||
|
struct xkb_desc *xkb;
|
||||||
char *path;
|
char *path;
|
||||||
int fd;
|
int fd;
|
||||||
struct xkb_desc * xkb;
|
|
||||||
int i, len, from_string = 0;
|
int i, len, from_string = 0;
|
||||||
|
|
||||||
/* Require xkb file */
|
/* Require xkb file */
|
||||||
|
@ -67,12 +69,17 @@ int main(int argc, char *argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context = xkb_context_new();
|
||||||
|
assert(context);
|
||||||
|
|
||||||
if (from_string) {
|
if (from_string) {
|
||||||
len = read(fd, buffer, sizeof(buffer));
|
len = read(fd, buffer, sizeof(buffer));
|
||||||
buffer[len] = '\0';
|
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 {
|
} 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);
|
close(fd);
|
||||||
|
|
||||||
|
@ -82,6 +89,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb_map_unref(xkb);
|
xkb_map_unref(xkb);
|
||||||
|
xkb_context_unref(context);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
|
||||||
authorization from the authors.
|
authorization from the authors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "xkbcommon/xkbcommon.h"
|
#include "xkbcommon/xkbcommon.h"
|
||||||
|
@ -31,8 +32,9 @@ authorization from the authors.
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct xkb_component_names kccgst;
|
struct xkb_context *context;
|
||||||
struct xkb_desc *xkb;
|
struct xkb_desc *xkb;
|
||||||
|
struct xkb_component_names kccgst;
|
||||||
|
|
||||||
/* Require Kc + T + C + S */
|
/* Require Kc + T + C + S */
|
||||||
if (argc < 5) {
|
if (argc < 5) {
|
||||||
|
@ -48,7 +50,10 @@ int main(int argc, char *argv[])
|
||||||
kccgst.compat = argv[3];
|
kccgst.compat = argv[3];
|
||||||
kccgst.symbols = argv[4];
|
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) {
|
if (!xkb) {
|
||||||
fprintf(stderr, "Failed to compile keymap\n");
|
fprintf(stderr, "Failed to compile keymap\n");
|
||||||
|
@ -56,6 +61,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb_map_unref(xkb);
|
xkb_map_unref(xkb);
|
||||||
|
xkb_context_unref(context);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
|
||||||
authorization from the authors.
|
authorization from the authors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <X11/Xdefs.h>
|
#include <X11/Xdefs.h>
|
||||||
|
@ -32,8 +33,9 @@ authorization from the authors.
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct xkb_rule_names rmlvo;
|
struct xkb_context *context;
|
||||||
struct xkb_desc *xkb;
|
struct xkb_desc *xkb;
|
||||||
|
struct xkb_rule_names rmlvo;
|
||||||
|
|
||||||
/* Require rmlvo */
|
/* Require rmlvo */
|
||||||
if (argc < 6) {
|
if (argc < 6) {
|
||||||
|
@ -49,7 +51,10 @@ int main(int argc, char *argv[])
|
||||||
rmlvo.variant = argv[4];
|
rmlvo.variant = argv[4];
|
||||||
rmlvo.options = argv[5];
|
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) {
|
if (!xkb) {
|
||||||
fprintf(stderr, "Failed to compile keymap\n");
|
fprintf(stderr, "Failed to compile keymap\n");
|
||||||
|
@ -57,6 +62,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb_map_unref(xkb);
|
xkb_map_unref(xkb);
|
||||||
|
xkb_context_unref(context);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,8 +205,9 @@ test_serialisation(struct xkb_desc *xkb)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct xkb_rule_names rmlvo;
|
struct xkb_context *context;
|
||||||
struct xkb_desc *xkb;
|
struct xkb_desc *xkb;
|
||||||
|
struct xkb_rule_names rmlvo;
|
||||||
|
|
||||||
rmlvo.rules = "evdev";
|
rmlvo.rules = "evdev";
|
||||||
rmlvo.model = "pc104";
|
rmlvo.model = "pc104";
|
||||||
|
@ -214,11 +215,15 @@ main(int argc, char *argv[])
|
||||||
rmlvo.variant = NULL;
|
rmlvo.variant = NULL;
|
||||||
rmlvo.options = 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);
|
assert(xkb);
|
||||||
|
|
||||||
test_update_key(xkb);
|
test_update_key(xkb);
|
||||||
test_serialisation(xkb);
|
test_serialisation(xkb);
|
||||||
|
|
||||||
xkb_map_unref(xkb);
|
xkb_map_unref(xkb);
|
||||||
|
xkb_context_unref(context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue