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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h
index e15dbac..d5d009f 100644
--- a/include/xkbcommon/xkbcommon.h
+++ b/include/xkbcommon/xkbcommon.h
@@ -237,6 +237,18 @@ _X_EXPORT void
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
@@ -265,7 +277,8 @@ xkb_context_unref(struct xkb_context *context);
* 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
@@ -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.
*/
_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. */
@@ -290,14 +304,17 @@ enum xkb_keymap_format {
* 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.
diff --git a/src/XKBcommonint.h b/src/XKBcommonint.h
index f900a69..b270f28 100644
--- a/src/XKBcommonint.h
+++ b/src/XKBcommonint.h
@@ -392,6 +392,8 @@ struct xkb_controls {
/* Common keyboard description structure */
struct xkb_desc {
+ struct xkb_context *context;
+
unsigned int refcnt;
unsigned int defined;
unsigned short flags;
diff --git a/src/alloc.c b/src/alloc.c
index 66e2b76..30af089 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -257,15 +257,18 @@ XkbcFreeIndicatorMaps(struct xkb_desc * xkb)
}
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;
}
@@ -282,5 +285,6 @@ XkbcFreeKeyboard(struct xkb_desc * xkb)
XkbcFreeIndicatorMaps(xkb);
XkbcFreeNames(xkb);
XkbcFreeControls(xkb);
+ xkb_context_unref(xkb->context);
free(xkb);
}
diff --git a/src/context.c b/src/context.c
index 20f8c79..0c5da91 100644
--- a/src/context.c
+++ b/src/context.c
@@ -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.
*/
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.
*/
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];
diff --git a/src/xkballoc.h b/src/xkballoc.h
index d16c58b..278f65d 100644
--- a/src/xkballoc.h
+++ b/src/xkballoc.h
@@ -44,7 +44,7 @@ extern int
XkbcAllocIndicatorMaps(struct xkb_desc * xkb);
extern struct xkb_desc *
-XkbcAllocKeyboard(void);
+XkbcAllocKeyboard(struct xkb_context *context);
extern void
XkbcFreeKeyboard(struct xkb_desc * xkb);
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 38cd013..0ba08d5 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -409,7 +409,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
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;
@@ -449,7 +450,8 @@ HandleIncludeCompatMap(IncludeStmt * stmt,
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;
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index bfe7d13..f9ac62c 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -568,7 +568,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
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);
@@ -600,7 +601,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
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);
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 897ff41..df6fd36 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -39,7 +39,7 @@
* XkmKeyNamesIdx, etc.)
*/
struct xkb_desc *
-CompileKeymap(XkbFile *file, unsigned merge)
+CompileKeymap(struct xkb_context *context, XkbFile *file, unsigned merge)
{
unsigned have;
Bool ok;
@@ -47,7 +47,7 @@ CompileKeymap(XkbFile *file, unsigned merge)
unsigned mainType;
const char *mainName;
LEDInfo *unbound = NULL;
- struct xkb_desc *xkb = XkbcAllocKeyboard();
+ struct xkb_desc *xkb = XkbcAllocKeyboard(context);
struct {
XkbFile *keycodes;
XkbFile *types;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 0a03afc..3c6628a 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -378,7 +378,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
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;
@@ -412,7 +413,8 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
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;
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index dd480f1..5c9c13a 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -40,6 +40,7 @@
* 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.
@@ -48,7 +49,8 @@
* @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)
{
@@ -57,7 +59,7 @@ ProcessIncludeFile(IncludeStmt * stmt,
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,
diff --git a/src/xkbcomp/misc.h b/src/xkbcomp/misc.h
index 197721f..7588cb3 100644
--- a/src/xkbcomp/misc.h
+++ b/src/xkbcomp/misc.h
@@ -69,7 +69,8 @@ extern int ReportBadField(const char * /* type */ ,
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 */
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index b3953c1..a1980bf 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -757,7 +757,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
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;
@@ -798,7 +799,8 @@ HandleIncludeSymbols(IncludeStmt * stmt,
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;
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 991ec60..bf03626 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -59,19 +59,22 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
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;
@@ -112,11 +115,12 @@ unwind_file:
}
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");
@@ -128,14 +132,14 @@ xkb_map_new_from_names(const struct xkb_rule_names *rmlvo)
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);
@@ -182,7 +186,7 @@ XkbChooseMap(XkbFile *file, const char *name)
}
static struct xkb_desc *
-compile_keymap(XkbFile *file)
+compile_keymap(struct xkb_context *context, XkbFile *file)
{
XkbFile *mapToUse;
struct xkb_desc * xkb = NULL;
@@ -202,20 +206,20 @@ compile_keymap(XkbFile *file)
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;
@@ -249,11 +253,13 @@ xkb_map_new_from_kccgst(const struct xkb_component_names *kccgst)
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;
@@ -273,11 +279,13 @@ xkb_map_new_from_string(const char *string, enum xkb_keymap_format format)
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;
@@ -304,7 +312,7 @@ xkb_map_new_from_fd(int fd, enum xkb_keymap_format format)
return NULL;
}
- return compile_keymap(file);
+ return compile_keymap(context, file);
}
void
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index baab968..4a6212b 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -253,7 +253,7 @@ typedef struct _XkbFile
} 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);
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index dfeab2f..12aaf3a 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -24,31 +24,13 @@
********************************************************/
-#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.
@@ -157,115 +139,6 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
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.
*
+ * @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;
@@ -321,28 +196,23 @@ XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
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;
}
diff --git a/src/xkbcomp/xkbpath.h b/src/xkbcomp/xkbpath.h
index 3632cbb..e48cf41 100644
--- a/src/xkbcomp/xkbpath.h
+++ b/src/xkbcomp/xkbpath.h
@@ -28,12 +28,14 @@
#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 */
);
@@ -45,6 +47,4 @@ extern Bool XkbParseIncludeMap(char ** /* str_inout */ ,
char ** /* extra_data */
);
-extern void XkbFreeIncludePath(void);
-
#endif /* _XKBPATH_H_ */
diff --git a/test/filecomp.c b/test/filecomp.c
index 370c4b2..3ba1b57 100644
--- a/test/filecomp.c
+++ b/test/filecomp.c
@@ -26,6 +26,7 @@ authorization from the authors.
#include <sys/types.h>
#include <sys/stat.h>
+#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@@ -39,9 +40,10 @@ static char buffer[8192];
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 */
@@ -67,12 +69,17 @@ int main(int argc, char *argv[])
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);
@@ -82,6 +89,7 @@ int main(int argc, char *argv[])
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
diff --git a/test/namescomp.c b/test/namescomp.c
index bd81447..4e8bf5c 100644
--- a/test/namescomp.c
+++ b/test/namescomp.c
@@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
authorization from the authors.
*/
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "xkbcommon/xkbcommon.h"
@@ -31,8 +32,9 @@ authorization from the authors.
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) {
@@ -48,7 +50,10 @@ int main(int argc, char *argv[])
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");
@@ -56,6 +61,7 @@ int main(int argc, char *argv[])
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
diff --git a/test/rulescomp.c b/test/rulescomp.c
index c761a49..a25b0a9 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -24,6 +24,7 @@ sale, use or other dealings in this Software without prior written
authorization from the authors.
*/
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xdefs.h>
@@ -32,8 +33,9 @@ authorization from the authors.
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) {
@@ -49,7 +51,10 @@ int main(int argc, char *argv[])
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");
@@ -57,6 +62,7 @@ int main(int argc, char *argv[])
}
xkb_map_unref(xkb);
+ xkb_context_unref(context);
return 0;
}
diff --git a/test/state.c b/test/state.c
index 5c6d1f5..231a8c0 100644
--- a/test/state.c
+++ b/test/state.c
@@ -205,8 +205,9 @@ test_serialisation(struct xkb_desc *xkb)
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";
@@ -214,11 +215,15 @@ main(int argc, char *argv[])
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);
}