Refactor xkbpath so that it implicitly initializes Instead of requiring the user to call XkbInitIncludePath() and XkbAddDefaultDirectoriesToPath(), all the path entry points now implicitly initialize the path. When initializing, the default directories are added so it's useful. This provides normal operation without exposing the xkbpath API. That might happen later to allow apps to edit the XKB search path.
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
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index fb773b0..36228df 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -39,12 +39,16 @@
#define PATH_MAX 1024
#endif
-#define PATH_CHUNK 8 /* initial szPath */
+/* initial szPath */
+#define PATH_CHUNK 8
static Bool noDefaultPath = False;
-static int szPath; /* number of entries allocated for includePath */
-static int nPathEntries; /* number of actual entries in includePath */
-static char **includePath; /* Holds all directories we might be including data from */
+/* number of entries allocated for includePath */
+static int szPath;
+/* number of actual entries in includePath */
+static int nPathEntries;
+/* Holds all directories we might be including data from */
+static char **includePath = NULL;
/**
* Extract the first token from an include statement.
@@ -159,16 +163,23 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
Bool
XkbInitIncludePath(void)
{
+ if (includePath)
+ return True;
+
szPath = PATH_CHUNK;
includePath = (char **) calloc(szPath, sizeof(char *));
- if (includePath == NULL)
+ if (!includePath)
return False;
+
+ XkbAddDefaultDirectoriesToPath();
return True;
}
void
XkbAddDefaultDirectoriesToPath(void)
{
+ if (!XkbInitIncludePath())
+ return;
if (noDefaultPath)
return;
XkbAddDirectoryToPath(DFLT_XKB_CONFIG_ROOT);
@@ -206,6 +217,10 @@ Bool
XkbAddDirectoryToPath(const char *dir)
{
int len;
+
+ if (!XkbInitIncludePath())
+ return False;
+
if ((dir == NULL) || (dir[0] == '\0'))
{
XkbClearIncludePath();
@@ -386,6 +401,9 @@ XkbFindFileInPath(char *name, unsigned type, char **pathRtrn)
int nameLen, typeLen, pathLen;
char buf[PATH_MAX], *typeDir;
+ if (!XkbInitIncludePath())
+ return NULL;
+
typeDir = XkbDirectoryForInclude(type);
nameLen = strlen(name);
typeLen = strlen(typeDir);