annotate src/parallel_execution/helper_string.h @ 303:1dbaef86593b

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