291
|
1 /**
|
|
2 * Copyright 1993-2013 NVIDIA Corporation. All rights reserved.
|
|
3 *
|
|
4 * Please refer to the NVIDIA end user license agreement (EULA) associated
|
|
5 * with this source code for terms and conditions that govern your use of
|
|
6 * this software. Any use, reproduction, disclosure, or distribution of
|
|
7 * this software and related documentation outside the terms of the EULA
|
|
8 * is strictly prohibited.
|
|
9 *
|
|
10 */
|
|
11
|
|
12 // These are helper functions for the SDK samples (string parsing, timers, etc)
|
|
13 #ifndef STRING_HELPER_H
|
|
14 #define STRING_HELPER_H
|
|
15
|
|
16 #include <stdio.h>
|
|
17 #include <stdlib.h>
|
303
|
18 #include <fstream.h>
|
|
19 #include <string.h>
|
291
|
20
|
|
21 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
|
22 #ifndef _CRT_SECURE_NO_DEPRECATE
|
|
23 #define _CRT_SECURE_NO_DEPRECATE
|
|
24 #endif
|
|
25 #ifndef STRCASECMP
|
|
26 #define STRCASECMP _stricmp
|
|
27 #endif
|
|
28 #ifndef STRNCASECMP
|
|
29 #define STRNCASECMP _strnicmp
|
|
30 #endif
|
|
31 #ifndef STRCPY
|
|
32 #define STRCPY(sFilePath, nLength, sPath) strcpy_s(sFilePath, nLength, sPath)
|
|
33 #endif
|
|
34
|
|
35 #ifndef FOPEN
|
|
36 #define FOPEN(fHandle,filename,mode) fopen_s(&fHandle, filename, mode)
|
|
37 #endif
|
|
38 #ifndef FOPEN_FAIL
|
|
39 #define FOPEN_FAIL(result) (result != 0)
|
|
40 #endif
|
|
41 #ifndef SSCANF
|
|
42 #define SSCANF sscanf_s
|
|
43 #endif
|
|
44 #ifndef SPRINTF
|
|
45 #define SPRINTF sprintf_s
|
|
46 #endif
|
|
47 #else // Linux Includes
|
|
48 #include <string.h>
|
|
49 #include <strings.h>
|
|
50
|
|
51 #ifndef STRCASECMP
|
|
52 #define STRCASECMP strcasecmp
|
|
53 #endif
|
|
54 #ifndef STRNCASECMP
|
|
55 #define STRNCASECMP strncasecmp
|
|
56 #endif
|
|
57 #ifndef STRCPY
|
|
58 #define STRCPY(sFilePath, nLength, sPath) strcpy(sFilePath, sPath)
|
|
59 #endif
|
|
60
|
|
61 #ifndef FOPEN
|
|
62 #define FOPEN(fHandle,filename,mode) (fHandle = fopen(filename, mode))
|
|
63 #endif
|
|
64 #ifndef FOPEN_FAIL
|
|
65 #define FOPEN_FAIL(result) (result == NULL)
|
|
66 #endif
|
|
67 #ifndef SSCANF
|
|
68 #define SSCANF sscanf
|
|
69 #endif
|
|
70 #ifndef SPRINTF
|
|
71 #define SPRINTF sprintf
|
|
72 #endif
|
|
73 #endif
|
|
74
|
|
75 #ifndef EXIT_WAIVED
|
|
76 #define EXIT_WAIVED 2
|
|
77 #endif
|
|
78
|
|
79 // CUDA Utility Helper Functions
|
|
80 inline int stringRemoveDelimiter(char delimiter, const char *string)
|
|
81 {
|
|
82 int string_start = 0;
|
|
83
|
|
84 while (string[string_start] == delimiter)
|
|
85 {
|
|
86 string_start++;
|
|
87 }
|
|
88
|
|
89 if (string_start >= (int)strlen(string)-1)
|
|
90 {
|
|
91 return 0;
|
|
92 }
|
|
93
|
|
94 return string_start;
|
|
95 }
|
|
96
|
|
97 inline int getFileExtension(char *filename, char **extension)
|
|
98 {
|
|
99 int string_length = (int)strlen(filename);
|
|
100
|
|
101 while (filename[string_length--] != '.')
|
|
102 {
|
|
103 if (string_length == 0)
|
|
104 break;
|
|
105 }
|
|
106
|
|
107 if (string_length > 0) string_length += 2;
|
|
108
|
|
109 if (string_length == 0)
|
|
110 *extension = NULL;
|
|
111 else
|
|
112 *extension = &filename[string_length];
|
|
113
|
|
114 return string_length;
|
|
115 }
|
|
116
|
|
117
|
|
118 inline bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref)
|
|
119 {
|
|
120 bool bFound = false;
|
|
121
|
|
122 if (argc >= 1)
|
|
123 {
|
|
124 for (int i=1; i < argc; i++)
|
|
125 {
|
|
126 int string_start = stringRemoveDelimiter('-', argv[i]);
|
|
127 const char *string_argv = &argv[i][string_start];
|
|
128
|
|
129 const char *equal_pos = strchr(string_argv, '=');
|
|
130 int argv_length = (int)(equal_pos == 0 ? strlen(string_argv) : equal_pos - string_argv);
|
|
131
|
|
132 int length = (int)strlen(string_ref);
|
|
133
|
|
134 if (length == argv_length && !STRNCASECMP(string_argv, string_ref, length))
|
|
135 {
|
|
136 bFound = true;
|
|
137 continue;
|
|
138 }
|
|
139 }
|
|
140 }
|
|
141
|
|
142 return bFound;
|
|
143 }
|
|
144
|
|
145 // This function wraps the CUDA Driver API into a template function
|
|
146 template <class T>
|
|
147 inline bool getCmdLineArgumentValue(const int argc, const char **argv, const char *string_ref, T *value)
|
|
148 {
|
|
149 bool bFound = false;
|
|
150
|
|
151 if (argc >= 1)
|
|
152 {
|
|
153 for (int i=1; i < argc; i++)
|
|
154 {
|
|
155 int string_start = stringRemoveDelimiter('-', argv[i]);
|
|
156 const char *string_argv = &argv[i][string_start];
|
|
157 int length = (int)strlen(string_ref);
|
|
158
|
|
159 if (!STRNCASECMP(string_argv, string_ref, length))
|
|
160 {
|
|
161 if (length+1 <= (int)strlen(string_argv))
|
|
162 {
|
|
163 int auto_inc = (string_argv[length] == '=') ? 1 : 0;
|
|
164 *value = (T)atoi(&string_argv[length + auto_inc]);
|
|
165 }
|
|
166
|
|
167 bFound = true;
|
|
168 i=argc;
|
|
169 }
|
|
170 }
|
|
171 }
|
|
172
|
|
173 return bFound;
|
|
174 }
|
|
175
|
|
176 inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref)
|
|
177 {
|
|
178 bool bFound = false;
|
|
179 int value = -1;
|
|
180
|
|
181 if (argc >= 1)
|
|
182 {
|
|
183 for (int i=1; i < argc; i++)
|
|
184 {
|
|
185 int string_start = stringRemoveDelimiter('-', argv[i]);
|
|
186 const char *string_argv = &argv[i][string_start];
|
|
187 int length = (int)strlen(string_ref);
|
|
188
|
|
189 if (!STRNCASECMP(string_argv, string_ref, length))
|
|
190 {
|
|
191 if (length+1 <= (int)strlen(string_argv))
|
|
192 {
|
|
193 int auto_inc = (string_argv[length] == '=') ? 1 : 0;
|
|
194 value = atoi(&string_argv[length + auto_inc]);
|
|
195 }
|
|
196 else
|
|
197 {
|
|
198 value = 0;
|
|
199 }
|
|
200
|
|
201 bFound = true;
|
|
202 continue;
|
|
203 }
|
|
204 }
|
|
205 }
|
|
206
|
|
207 if (bFound)
|
|
208 {
|
|
209 return value;
|
|
210 }
|
|
211 else
|
|
212 {
|
|
213 return 0;
|
|
214 }
|
|
215 }
|
|
216
|
|
217 inline float getCmdLineArgumentFloat(const int argc, const char **argv, const char *string_ref)
|
|
218 {
|
|
219 bool bFound = false;
|
|
220 float value = -1;
|
|
221
|
|
222 if (argc >= 1)
|
|
223 {
|
|
224 for (int i=1; i < argc; i++)
|
|
225 {
|
|
226 int string_start = stringRemoveDelimiter('-', argv[i]);
|
|
227 const char *string_argv = &argv[i][string_start];
|
|
228 int length = (int)strlen(string_ref);
|
|
229
|
|
230 if (!STRNCASECMP(string_argv, string_ref, length))
|
|
231 {
|
|
232 if (length+1 <= (int)strlen(string_argv))
|
|
233 {
|
|
234 int auto_inc = (string_argv[length] == '=') ? 1 : 0;
|
|
235 value = (float)atof(&string_argv[length + auto_inc]);
|
|
236 }
|
|
237 else
|
|
238 {
|
|
239 value = 0.f;
|
|
240 }
|
|
241
|
|
242 bFound = true;
|
|
243 continue;
|
|
244 }
|
|
245 }
|
|
246 }
|
|
247
|
|
248 if (bFound)
|
|
249 {
|
|
250 return value;
|
|
251 }
|
|
252 else
|
|
253 {
|
|
254 return 0;
|
|
255 }
|
|
256 }
|
|
257
|
|
258 inline bool getCmdLineArgumentString(const int argc, const char **argv,
|
|
259 const char *string_ref, char **string_retval)
|
|
260 {
|
|
261 bool bFound = false;
|
|
262
|
|
263 if (argc >= 1)
|
|
264 {
|
|
265 for (int i=1; i < argc; i++)
|
|
266 {
|
|
267 int string_start = stringRemoveDelimiter('-', argv[i]);
|
|
268 char *string_argv = (char *)&argv[i][string_start];
|
|
269 int length = (int)strlen(string_ref);
|
|
270
|
|
271 if (!STRNCASECMP(string_argv, string_ref, length))
|
|
272 {
|
|
273 *string_retval = &string_argv[length+1];
|
|
274 bFound = true;
|
|
275 continue;
|
|
276 }
|
|
277 }
|
|
278 }
|
|
279
|
|
280 if (!bFound)
|
|
281 {
|
|
282 *string_retval = NULL;
|
|
283 }
|
|
284
|
|
285 return bFound;
|
|
286 }
|
|
287
|
|
288 //////////////////////////////////////////////////////////////////////////////
|
|
289 //! Find the path for a file assuming that
|
|
290 //! files are found in the searchPath.
|
|
291 //!
|
|
292 //! @return the path if succeeded, otherwise 0
|
|
293 //! @param filename name of the file
|
|
294 //! @param executable_path optional absolute path of the executable
|
|
295 //////////////////////////////////////////////////////////////////////////////
|
|
296 inline char *sdkFindFilePath(const char *filename, const char *executable_path)
|
|
297 {
|
|
298 // <executable_name> defines a variable that is replaced with the name of the executable
|
|
299
|
|
300 // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files)
|
|
301 // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc
|
|
302 const char *searchPath[] =
|
|
303 {
|
|
304 "./", // same dir
|
|
305 "./<executable_name>_data_files/",
|
|
306 "./common/", // "/common/" subdir
|
|
307 "./common/data/", // "/common/data/" subdir
|
|
308 "./data/", // "/data/" subdir
|
|
309 "./src/", // "/src/" subdir
|
|
310 "./src/<executable_name>/data/", // "/src/<executable_name>/data/" subdir
|
|
311 "./inc/", // "/inc/" subdir
|
|
312 "./0_Simple/", // "/0_Simple/" subdir
|
|
313 "./1_Utilities/", // "/1_Utilities/" subdir
|
|
314 "./2_Graphics/", // "/2_Graphics/" subdir
|
|
315 "./3_Imaging/", // "/3_Imaging/" subdir
|
|
316 "./4_Finance/", // "/4_Finance/" subdir
|
|
317 "./5_Simulations/", // "/5_Simulations/" subdir
|
|
318 "./6_Advanced/", // "/6_Advanced/" subdir
|
|
319 "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir
|
|
320 "./8_Android/", // "/8_Android/" subdir
|
|
321 "./samples/", // "/samples/" subdir
|
|
322
|
|
323 "./0_Simple/<executable_name>/data/", // "/0_Simple/<executable_name>/data/" subdir
|
|
324 "./1_Utilities/<executable_name>/data/", // "/1_Utilities/<executable_name>/data/" subdir
|
|
325 "./2_Graphics/<executable_name>/data/", // "/2_Graphics/<executable_name>/data/" subdir
|
|
326 "./3_Imaging/<executable_name>/data/", // "/3_Imaging/<executable_name>/data/" subdir
|
|
327 "./4_Finance/<executable_name>/data/", // "/4_Finance/<executable_name>/data/" subdir
|
|
328 "./5_Simulations/<executable_name>/data/", // "/5_Simulations/<executable_name>/data/" subdir
|
|
329 "./6_Advanced/<executable_name>/data/", // "/6_Advanced/<executable_name>/data/" subdir
|
|
330 "./7_CUDALibraries/<executable_name>/", // "/7_CUDALibraries/<executable_name>/" subdir
|
|
331 "./7_CUDALibraries/<executable_name>/data/", // "/7_CUDALibraries/<executable_name>/data/" subdir
|
|
332
|
|
333 "../", // up 1 in tree
|
|
334 "../common/", // up 1 in tree, "/common/" subdir
|
|
335 "../common/data/", // up 1 in tree, "/common/data/" subdir
|
|
336 "../data/", // up 1 in tree, "/data/" subdir
|
|
337 "../src/", // up 1 in tree, "/src/" subdir
|
|
338 "../inc/", // up 1 in tree, "/inc/" subdir
|
|
339
|
|
340 "../0_Simple/<executable_name>/data/", // up 1 in tree, "/0_Simple/<executable_name>/" subdir
|
|
341 "../1_Utilities/<executable_name>/data/", // up 1 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
342 "../2_Graphics/<executable_name>/data/", // up 1 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
343 "../3_Imaging/<executable_name>/data/", // up 1 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
344 "../4_Finance/<executable_name>/data/", // up 1 in tree, "/4_Finance/<executable_name>/" subdir
|
|
345 "../5_Simulations/<executable_name>/data/", // up 1 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
346 "../6_Advanced/<executable_name>/data/", // up 1 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
347 "../7_CUDALibraries/<executable_name>/data/",// up 1 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
348 "../8_Android/<executable_name>/data/", // up 1 in tree, "/8_Android/<executable_name>/" subdir
|
|
349 "../samples/<executable_name>/data/", // up 1 in tree, "/samples/<executable_name>/" subdir
|
|
350 "../../", // up 2 in tree
|
|
351 "../../common/", // up 2 in tree, "/common/" subdir
|
|
352 "../../common/data/", // up 2 in tree, "/common/data/" subdir
|
|
353 "../../data/", // up 2 in tree, "/data/" subdir
|
|
354 "../../src/", // up 2 in tree, "/src/" subdir
|
|
355 "../../inc/", // up 2 in tree, "/inc/" subdir
|
|
356 "../../sandbox/<executable_name>/data/", // up 2 in tree, "/sandbox/<executable_name>/" subdir
|
|
357 "../../0_Simple/<executable_name>/data/", // up 2 in tree, "/0_Simple/<executable_name>/" subdir
|
|
358 "../../1_Utilities/<executable_name>/data/", // up 2 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
359 "../../2_Graphics/<executable_name>/data/", // up 2 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
360 "../../3_Imaging/<executable_name>/data/", // up 2 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
361 "../../4_Finance/<executable_name>/data/", // up 2 in tree, "/4_Finance/<executable_name>/" subdir
|
|
362 "../../5_Simulations/<executable_name>/data/", // up 2 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
363 "../../6_Advanced/<executable_name>/data/", // up 2 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
364 "../../7_CUDALibraries/<executable_name>/data/", // up 2 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
365 "../../8_Android/<executable_name>/data/", // up 2 in tree, "/8_Android/<executable_name>/" subdir
|
|
366 "../../samples/<executable_name>/data/", // up 2 in tree, "/samples/<executable_name>/" subdir
|
|
367 "../../../", // up 3 in tree
|
|
368 "../../../src/<executable_name>/", // up 3 in tree, "/src/<executable_name>/" subdir
|
|
369 "../../../src/<executable_name>/data/", // up 3 in tree, "/src/<executable_name>/data/" subdir
|
|
370 "../../../src/<executable_name>/src/", // up 3 in tree, "/src/<executable_name>/src/" subdir
|
|
371 "../../../src/<executable_name>/inc/", // up 3 in tree, "/src/<executable_name>/inc/" subdir
|
|
372 "../../../sandbox/<executable_name>/", // up 3 in tree, "/sandbox/<executable_name>/" subdir
|
|
373 "../../../sandbox/<executable_name>/data/", // up 3 in tree, "/sandbox/<executable_name>/data/" subdir
|
|
374 "../../../sandbox/<executable_name>/src/", // up 3 in tree, "/sandbox/<executable_name>/src/" subdir
|
|
375 "../../../sandbox/<executable_name>/inc/", // up 3 in tree, "/sandbox/<executable_name>/inc/" subdir
|
|
376 "../../../0_Simple/<executable_name>/data/", // up 3 in tree, "/0_Simple/<executable_name>/" subdir
|
|
377 "../../../1_Utilities/<executable_name>/data/", // up 3 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
378 "../../../2_Graphics/<executable_name>/data/", // up 3 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
379 "../../../3_Imaging/<executable_name>/data/", // up 3 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
380 "../../../4_Finance/<executable_name>/data/", // up 3 in tree, "/4_Finance/<executable_name>/" subdir
|
|
381 "../../../5_Simulations/<executable_name>/data/", // up 3 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
382 "../../../6_Advanced/<executable_name>/data/", // up 3 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
383 "../../../7_CUDALibraries/<executable_name>/data/", // up 3 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
384 "../../../8_Android/<executable_name>/data/", // up 3 in tree, "/8_Android/<executable_name>/" subdir
|
|
385 "../../../0_Simple/<executable_name>/", // up 3 in tree, "/0_Simple/<executable_name>/" subdir
|
|
386 "../../../1_Utilities/<executable_name>/", // up 3 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
387 "../../../2_Graphics/<executable_name>/", // up 3 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
388 "../../../3_Imaging/<executable_name>/", // up 3 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
389 "../../../4_Finance/<executable_name>/", // up 3 in tree, "/4_Finance/<executable_name>/" subdir
|
|
390 "../../../5_Simulations/<executable_name>/", // up 3 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
391 "../../../6_Advanced/<executable_name>/", // up 3 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
392 "../../../7_CUDALibraries/<executable_name>/", // up 3 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
393 "../../../8_Android/<executable_name>/", // up 3 in tree, "/8_Android/<executable_name>/" subdir
|
|
394 "../../../samples/<executable_name>/data/", // up 3 in tree, "/samples/<executable_name>/" subdir
|
|
395 "../../../common/", // up 3 in tree, "../../../common/" subdir
|
|
396 "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir
|
|
397 "../../../data/", // up 3 in tree, "../../../data/" subdir
|
|
398 "../../../../", // up 4 in tree
|
|
399 "../../../../src/<executable_name>/", // up 4 in tree, "/src/<executable_name>/" subdir
|
|
400 "../../../../src/<executable_name>/data/", // up 4 in tree, "/src/<executable_name>/data/" subdir
|
|
401 "../../../../src/<executable_name>/src/", // up 4 in tree, "/src/<executable_name>/src/" subdir
|
|
402 "../../../../src/<executable_name>/inc/", // up 4 in tree, "/src/<executable_name>/inc/" subdir
|
|
403 "../../../../sandbox/<executable_name>/", // up 4 in tree, "/sandbox/<executable_name>/" subdir
|
|
404 "../../../../sandbox/<executable_name>/data/", // up 4 in tree, "/sandbox/<executable_name>/data/" subdir
|
|
405 "../../../../sandbox/<executable_name>/src/", // up 4 in tree, "/sandbox/<executable_name>/src/" subdir
|
|
406 "../../../../sandbox/<executable_name>/inc/", // up 4 in tree, "/sandbox/<executable_name>/inc/" subdir
|
|
407 "../../../../0_Simple/<executable_name>/data/", // up 4 in tree, "/0_Simple/<executable_name>/" subdir
|
|
408 "../../../../1_Utilities/<executable_name>/data/", // up 4 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
409 "../../../../2_Graphics/<executable_name>/data/", // up 4 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
410 "../../../../3_Imaging/<executable_name>/data/", // up 4 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
411 "../../../../4_Finance/<executable_name>/data/", // up 4 in tree, "/4_Finance/<executable_name>/" subdir
|
|
412 "../../../../5_Simulations/<executable_name>/data/",// up 4 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
413 "../../../../6_Advanced/<executable_name>/data/", // up 4 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
414 "../../../../7_CUDALibraries/<executable_name>/data/", // up 4 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
415 "../../../../8_Android/<executable_name>/data/", // up 4 in tree, "/8_Android/<executable_name>/" subdir
|
|
416 "../../../../0_Simple/<executable_name>/", // up 4 in tree, "/0_Simple/<executable_name>/" subdir
|
|
417 "../../../../1_Utilities/<executable_name>/", // up 4 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
418 "../../../../2_Graphics/<executable_name>/", // up 4 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
419 "../../../../3_Imaging/<executable_name>/", // up 4 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
420 "../../../../4_Finance/<executable_name>/", // up 4 in tree, "/4_Finance/<executable_name>/" subdir
|
|
421 "../../../../5_Simulations/<executable_name>/",// up 4 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
422 "../../../../6_Advanced/<executable_name>/", // up 4 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
423 "../../../../7_CUDALibraries/<executable_name>/", // up 4 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
424 "../../../../8_Android/<executable_name>/", // up 4 in tree, "/8_Android/<executable_name>/" subdir
|
|
425 "../../../../samples/<executable_name>/data/", // up 4 in tree, "/samples/<executable_name>/" subdir
|
|
426 "../../../../common/", // up 4 in tree, "../../../common/" subdir
|
|
427 "../../../../common/data/", // up 4 in tree, "../../../common/data/" subdir
|
|
428 "../../../../data/", // up 4 in tree, "../../../data/" subdir
|
|
429 "../../../../../", // up 5 in tree
|
|
430 "../../../../../src/<executable_name>/", // up 5 in tree, "/src/<executable_name>/" subdir
|
|
431 "../../../../../src/<executable_name>/data/", // up 5 in tree, "/src/<executable_name>/data/" subdir
|
|
432 "../../../../../src/<executable_name>/src/", // up 5 in tree, "/src/<executable_name>/src/" subdir
|
|
433 "../../../../../src/<executable_name>/inc/", // up 5 in tree, "/src/<executable_name>/inc/" subdir
|
|
434 "../../../../../sandbox/<executable_name>/", // up 5 in tree, "/sandbox/<executable_name>/" subdir
|
|
435 "../../../../../sandbox/<executable_name>/data/", // up 5 in tree, "/sandbox/<executable_name>/data/" subdir
|
|
436 "../../../../../sandbox/<executable_name>/src/", // up 5 in tree, "/sandbox/<executable_name>/src/" subdir
|
|
437 "../../../../../sandbox/<executable_name>/inc/", // up 5 in tree, "/sandbox/<executable_name>/inc/" subdir
|
|
438 "../../../../../0_Simple/<executable_name>/data/", // up 5 in tree, "/0_Simple/<executable_name>/" subdir
|
|
439 "../../../../../1_Utilities/<executable_name>/data/", // up 5 in tree, "/1_Utilities/<executable_name>/" subdir
|
|
440 "../../../../../2_Graphics/<executable_name>/data/", // up 5 in tree, "/2_Graphics/<executable_name>/" subdir
|
|
441 "../../../../../3_Imaging/<executable_name>/data/", // up 5 in tree, "/3_Imaging/<executable_name>/" subdir
|
|
442 "../../../../../4_Finance/<executable_name>/data/", // up 5 in tree, "/4_Finance/<executable_name>/" subdir
|
|
443 "../../../../../5_Simulations/<executable_name>/data/",// up 5 in tree, "/5_Simulations/<executable_name>/" subdir
|
|
444 "../../../../../6_Advanced/<executable_name>/data/", // up 5 in tree, "/6_Advanced/<executable_name>/" subdir
|
|
445 "../../../../../7_CUDALibraries/<executable_name>/data/", // up 5 in tree, "/7_CUDALibraries/<executable_name>/" subdir
|
|
446 "../../../../../8_Android/<executable_name>/data/", // up 5 in tree, "/8_Android/<executable_name>/" subdir
|
|
447 "../../../../../samples/<executable_name>/data/", // up 5 in tree, "/samples/<executable_name>/" subdir
|
|
448 "../../../../../common/", // up 5 in tree, "../../../common/" subdir
|
|
449 "../../../../../common/data/", // up 5 in tree, "../../../common/data/" subdir
|
|
450 };
|
|
451
|
|
452 // Extract the executable name
|
|
453 std::string executable_name;
|
|
454
|
|
455 if (executable_path != 0)
|
|
456 {
|
|
457 executable_name = std::string(executable_path);
|
|
458
|
|
459 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
|
460 // Windows path delimiter
|
|
461 size_t delimiter_pos = executable_name.find_last_of('\\');
|
|
462 executable_name.erase(0, delimiter_pos + 1);
|
|
463
|
|
464 if (executable_name.rfind(".exe") != std::string::npos)
|
|
465 {
|
|
466 // we strip .exe, only if the .exe is found
|
|
467 executable_name.resize(executable_name.size() - 4);
|
|
468 }
|
|
469
|
|
470 #else
|
|
471 // Linux & OSX path delimiter
|
|
472 size_t delimiter_pos = executable_name.find_last_of('/');
|
|
473 executable_name.erase(0,delimiter_pos+1);
|
|
474 #endif
|
|
475 }
|
|
476
|
|
477 // Loop over all search paths and return the first hit
|
|
478 for (unsigned int i = 0; i < sizeof(searchPath)/sizeof(char *); ++i)
|
|
479 {
|
|
480 std::string path(searchPath[i]);
|
|
481 size_t executable_name_pos = path.find("<executable_name>");
|
|
482
|
|
483 // If there is executable_name variable in the searchPath
|
|
484 // replace it with the value
|
|
485 if (executable_name_pos != std::string::npos)
|
|
486 {
|
|
487 if (executable_path != 0)
|
|
488 {
|
|
489 path.replace(executable_name_pos, strlen("<executable_name>"), executable_name);
|
|
490 }
|
|
491 else
|
|
492 {
|
|
493 // Skip this path entry if no executable argument is given
|
|
494 continue;
|
|
495 }
|
|
496 }
|
|
497
|
|
498 #ifdef _DEBUG
|
|
499 printf("sdkFindFilePath <%s> in %s\n", filename, path.c_str());
|
|
500 #endif
|
|
501
|
|
502 // Test if the file exists
|
|
503 path.append(filename);
|
|
504 FILE *fp;
|
|
505 FOPEN(fp, path.c_str(), "rb");
|
|
506
|
|
507 if (fp != NULL)
|
|
508 {
|
|
509 fclose(fp);
|
|
510 // File found
|
|
511 // returning an allocated array here for backwards compatibility reasons
|
|
512 char *file_path = (char *) malloc(path.length() + 1);
|
|
513 STRCPY(file_path, path.length() + 1, path.c_str());
|
|
514 return file_path;
|
|
515 }
|
|
516
|
|
517 if (fp)
|
|
518 {
|
|
519 fclose(fp);
|
|
520 }
|
|
521 }
|
|
522
|
|
523 // File not found
|
|
524 return 0;
|
|
525 }
|
|
526
|
|
527 #endif
|