gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / patches / libxt-guix-search-paths.patch
1 diff --git a/src/Intrinsic.c b/src/Intrinsic.c
2 index c9624ec..addcdba 100644
3 --- a/src/Intrinsic.c
4 +++ b/src/Intrinsic.c
5 @@ -1312,21 +1312,101 @@ static void FillInLangSubs(
6 } else (void) strcpy(*rest, string);
7 }
8
9 +
10 +
11 /*
12 - * default path used if environment variable XFILESEARCHPATH
13 - * is not defined. Also substitued for %D.
14 - * The exact value should be documented in the implementation
15 - * notes for any Xt implementation.
16 + Return the default search path for the function
17 + XtResolvePathname to use if XFILESEARCHPATH is
18 + not defined.
19 +
20 + It returns the combination the set of values which are the 6 "stems" below,
21 + prepended with "/run/current-system/profile", and $GUIX_PROFILE and
22 + "$HOME/.guix-profile"
23 +
24 + These values provide the default paths where Guix/GuixSD can expect
25 + to find resources for installed packages.
26 */
27 -static const char *implementation_default_path(void)
28 +static const char *guix_default_path(void)
29 {
30 -#if defined(WIN32)
31 - static char xfilesearchpath[] = "";
32 + static const char *search_path_default_stem[] = {
33 + "/lib/X11/%L/%T/%N%C%S",
34 + "/lib/X11/%l/%T/%N%C%S",
35 + "/lib/X11/%T/%N%C%S",
36 + "/lib/X11/%L/%T/%N%S",
37 + "/lib/X11/%l/%T/%N%S",
38 + "/lib/X11/%T/%N%S"
39 + };
40 +
41 +#define SIZEOF_STEMS (strlen (search_path_default_stem[0]) \
42 + + strlen (search_path_default_stem[1]) \
43 + + strlen (search_path_default_stem[2]) \
44 + + strlen (search_path_default_stem[3]) \
45 + + strlen (search_path_default_stem[4]) \
46 + + strlen (search_path_default_stem[5]))
47 +
48 +
49 + int i;
50 + const char *current_profile = "/run/current-system/profile";
51 + char *home = getenv ("HOME");
52 + char *guix_profile = getenv ("GUIX_PROFILE");
53 +
54 + size_t bytesAllocd = SIZEOF_STEMS + 1;
55 +
56 + /* This function is evaluated multiple times and the calling
57 + code assumes that it is idempotent. So we must not allow
58 + (say) a changed environment variable to cause it to return
59 + something different. */
60 + static char *path = NULL;
61 + if (path)
62 + return path;
63 +
64 + bytesAllocd += 6 * (1 + strlen (current_profile));
65 +
66 + if (guix_profile != NULL)
67 + {
68 + bytesAllocd += SIZEOF_STEMS;
69 + bytesAllocd += 6 * (1 + strlen (guix_profile));
70 + }
71
72 - return xfilesearchpath;
73 -#else
74 - return XFILESEARCHPATHDEFAULT;
75 -#endif
76 + if (home != NULL)
77 + {
78 + bytesAllocd += SIZEOF_STEMS;
79 + bytesAllocd += 6 * (1 + strlen(home) + strlen ("/.guix-profile"));
80 + }
81 +
82 + path = XtMalloc(bytesAllocd);
83 + if (path == NULL) _XtAllocError(NULL);
84 +
85 + memset (path, 0, bytesAllocd);
86 +
87 + for (i = 0 ; i < 6 ; ++i)
88 + {
89 + strcat (path, current_profile);
90 + strcat (path, search_path_default_stem[i]);
91 + strcat (path, ":");
92 + }
93 +
94 + if (guix_profile != NULL)
95 + for (i = 0 ; i < 6 ; ++i)
96 + {
97 + strcat (path, guix_profile);
98 + strcat (path, search_path_default_stem[i]);
99 + strcat (path, ":");
100 + }
101 +
102 + if (home != NULL)
103 + for (i = 0 ; i < 6 ; ++i)
104 + {
105 + strcat (path, home);
106 + strcat (path, "/.guix-profile");
107 + strcat (path, search_path_default_stem[i]);
108 + strcat (path, ":");
109 + }
110 +
111 + /* Remove final : */
112 + path[strlen(path) - 1] = '\0';
113 +
114 + return path;
115 }
116
117
118 @@ -1354,7 +1434,7 @@ _XtString XtResolvePathname(
119 {
120 XtPerDisplay pd;
121 static const char *defaultPath = NULL;
122 - const char *impl_default = implementation_default_path();
123 + const char *impl_default = guix_default_path();
124 int idef_len = (int) strlen(impl_default);
125 char *massagedPath;
126 int bytesAllocd, bytesLeft;