aboutsummaryrefslogtreecommitdiff
path: root/doc/nx-X11_vs_XOrg69_patches/oscolor.c.NX.patch
blob: 88acc878a70b67d9678a5537ccf2892670a08ffc (plain)
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
--- ./nx-X11/programs/Xserver/os/oscolor.c.X.original	2015-02-13 14:03:44.788440645 +0100
+++ ./nx-X11/programs/Xserver/os/oscolor.c	2015-02-13 14:03:44.788440645 +0100
@@ -47,6 +47,17 @@
 ******************************************************************/
 /* $Xorg: oscolor.c,v 1.4 2001/02/09 02:05:23 xorgcvs Exp $ */
 
+#ifdef NX_TRANS_SOCKET
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static char* nxAltRgbPaths[] = {"/usr/NX/share/rgb", "/usr/share/X11/rgb", "/etc/X11/rgb"};
+static char _NXRgbPath[1024];
+
+#endif
+
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
@@ -174,6 +185,154 @@
 
 static dbEntryPtr hashTab[HASHSIZE];
 
+#ifdef NX_TRANS_SOCKET
+
+static int NXVerifyRgbPath(char *path)
+{
+  int size;
+  char *rgbPath;
+  struct stat rgbFileStat;
+
+  /*
+   * Check if rgb file is present.
+   */
+
+  size = strlen(path) + strlen(".txt") + 1;
+
+  rgbPath = (char *) ALLOCATE_LOCAL(size + 1);
+
+  strcpy(rgbPath, path);
+
+  #ifdef NX_TRANS_TEST
+  fprintf(stderr, "NXVerifyRgbPath: Looking for [%s] file.\n",
+              rgbPath);
+  #endif
+
+  if (stat(rgbPath, &rgbFileStat) != 0)
+  {
+
+    #ifdef NX_TRANS_TEST
+    fprintf(stderr, "NXVerifyRgbPath: Can't find the rgb file [%s].\n",
+                rgbPath);
+    #endif
+
+    strcat(rgbPath, ".txt");
+
+    #ifdef NX_TRANS_TEST
+    fprintf(stderr, "NXVerifyRgbPath: Looking for [%s] file.\n",
+                rgbPath);
+    #endif
+
+    if (stat(rgbPath, &rgbFileStat) != 0)
+    {
+
+      #ifdef NX_TRANS_TEST
+      fprintf(stderr, "NXVerifyRgbPath: Can't find the rgb file [%s].\n",
+                  rgbPath);
+      #endif
+
+      DEALLOCATE_LOCAL(rgbPath);
+
+      return 0;
+    }
+  }
+
+  #ifdef NX_TRANS_TEST
+  fprintf(stderr, "NXVerifyRgbPath: rgb path [%s] is valid.\n",
+              path);
+  #endif
+
+  DEALLOCATE_LOCAL(rgbPath);
+
+  return 1;
+}
+
+static const char *_NXGetRgbPath(const char *path)
+{
+  const char *systemEnv;
+  char rgbPath[1024];
+  int numAltRgbPaths;
+  int i;
+
+  /*
+   * Check the environment only once.
+   */
+
+  if (*_NXRgbPath != '\0')
+  {
+    return _NXRgbPath;
+  }
+
+  systemEnv = getenv("NX_SYSTEM");
+
+  if (systemEnv != NULL && *systemEnv != '\0')
+  {
+    if (strlen(systemEnv) + strlen("/share/rgb") + 1 > 1024)
+    {
+
+      #ifdef NX_TRANS_TEST
+      fprintf(stderr, "_NXGetRgbPath: WARNING! Maximum length of rgb file path exceeded.\n");
+      #endif
+
+      goto _NXGetRgbPathError;
+    }
+
+    strcpy(rgbPath, systemEnv);
+    strcat(rgbPath, "/share/rgb");
+
+    if (NXVerifyRgbPath(rgbPath) == 1)
+    {
+      strcpy(_NXRgbPath, systemEnv);
+      strcat(_NXRgbPath, "/share/rgb");
+
+      #ifdef NX_TRANS_TEST
+      fprintf(stderr, "_NXGetRgbPath: Using rgb file path [%s].\n",
+                  _NXRgbPath);
+      #endif
+
+      return _NXRgbPath;
+    }
+  }
+
+  numAltRgbPaths = sizeof(nxAltRgbPaths) / sizeof(*nxAltRgbPaths);
+
+  for (i = 0; i < numAltRgbPaths; i++)
+  {
+    if (NXVerifyRgbPath(nxAltRgbPaths[i]) == 1)
+    {
+      if (strlen(nxAltRgbPaths[i]) + 1 > 1024)
+      {
+        #ifdef NX_TRANS_TEST
+        fprintf(stderr, "_NXGetRgbPath: WARNING! Maximum length of rgb file path exceeded.\n");
+        #endif
+
+        goto _NXGetRgbPathError;
+      }
+
+      strcpy(_NXRgbPath, nxAltRgbPaths[i]);
+
+      #ifdef NX_TRANS_TEST
+      fprintf(stderr, "_NXGetRgbPath: Using rgb file path [%s].\n",
+                  _NXRgbPath);
+      #endif
+
+      return _NXRgbPath;
+    }
+  }
+
+_NXGetRgbPathError:
+
+  strcpy(_NXRgbPath, path);
+
+  #ifdef NX_TRANS_TEST
+  fprintf(stderr, "_NXGetRgbPath: Using default rgb file path [%s].\n",
+              _NXRgbPath);
+  #endif
+
+  return _NXRgbPath;
+}
+
+#endif
 
 static dbEntryPtr
 lookup(char *name, int len, Bool create)
@@ -229,9 +388,26 @@
   if (!was_here)
     {
 #ifndef __UNIXOS2__
+#ifdef NX_TRANS_SOCKET
+      /*
+       * Add the trailing '.txt' if a
+       * 'rgb' file is not found.
+       */
+
+      struct stat statbuf;
+
+      path = (char*)ALLOCATE_LOCAL(strlen(_NXGetRgbPath(rgbPath)) + 5);
+      strcpy(path, _NXGetRgbPath(rgbPath));
+
+      if (stat(path, &statbuf) != 0)
+      {
+          strcat(path, ".txt");
+      }
+#else
       path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5);
       strcpy(path, rgbPath);
       strcat(path, ".txt");
+#endif
 #else
       char *tmp = (char*)__XOS2RedirRoot(rgbPath);
       path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5);
@@ -240,7 +416,11 @@
 #endif
       if (!(rgb = fopen(path, "r")))
         {
+#ifdef NX_TRANS_SOCKET
+           ErrorF( "Couldn't open RGB_DB '%s'\n", _NXGetRgbPath(rgbPath));
+#else
 	   ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
+#endif
 	   DEALLOCATE_LOCAL(path);
 	   return FALSE;
 	}