OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkRTConf.h" | 8 #include "SkRTConf.h" |
9 #include "SkOSFile.h" | 9 #include "SkOSFile.h" |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 static inline void str_replace(char *s, char search, char replace) { | 207 static inline void str_replace(char *s, char search, char replace) { |
208 for (char *ptr = s ; *ptr ; ptr++) { | 208 for (char *ptr = s ; *ptr ; ptr++) { |
209 if (*ptr == search) { | 209 if (*ptr == search) { |
210 *ptr = replace; | 210 *ptr = replace; |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) { | 215 template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) { |
216 SkString *str = NULL; | 216 SkString *str = NULL; |
| 217 SkString tmp; |
217 | 218 |
218 for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) { | 219 for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) { |
219 if (fConfigFileKeys[i]->equals(name)) { | 220 if (fConfigFileKeys[i]->equals(name)) { |
220 str = fConfigFileValues[i]; | 221 str = fConfigFileValues[i]; |
221 break; | 222 break; |
222 } | 223 } |
223 } | 224 } |
224 | 225 |
225 SkString environment_variable("skia."); | 226 SkString environment_variable("skia."); |
226 environment_variable.append(name); | 227 environment_variable.append(name); |
227 | 228 |
228 const char *environment_value = getenv(environment_variable.c_str()); | 229 const char *environment_value = getenv(environment_variable.c_str()); |
229 if (environment_value) { | 230 if (environment_value) { |
| 231 if (NULL == str) { |
| 232 str = &tmp; |
| 233 } |
230 str->set(environment_value); | 234 str->set(environment_value); |
231 } else { | 235 } else { |
232 // apparently my shell doesn't let me have environment variables that | 236 // apparently my shell doesn't let me have environment variables that |
233 // have periods in them, so also let the user substitute underscores. | 237 // have periods in them, so also let the user substitute underscores. |
234 SkString underscore_environment_variable("skia_"); | 238 SkString underscore_environment_variable("skia_"); |
235 char *underscore_name = SkStrDup(name); | 239 char *underscore_name = SkStrDup(name); |
236 str_replace(underscore_name,'.','_'); | 240 str_replace(underscore_name,'.','_'); |
237 underscore_environment_variable.append(underscore_name); | 241 underscore_environment_variable.append(underscore_name); |
238 sk_free(underscore_name); | 242 sk_free(underscore_name); |
239 environment_value = getenv(underscore_environment_variable.c_str()); | 243 environment_value = getenv(underscore_environment_variable.c_str()); |
240 if (environment_value) { | 244 if (environment_value) { |
| 245 if (NULL == str) { |
| 246 str = &tmp; |
| 247 } |
241 str->set(environment_value); | 248 str->set(environment_value); |
242 } | 249 } |
243 } | 250 } |
244 | 251 |
245 if (!str) { | 252 if (!str) { |
246 return false; | 253 return false; |
247 } | 254 } |
248 | 255 |
249 bool success; | 256 bool success; |
250 T new_value = doParse<T>(str->c_str(),&success); | 257 T new_value = doParse<T>(str->c_str(),&success); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 template void SkRTConfRegistry::set(const char *name, int value); | 294 template void SkRTConfRegistry::set(const char *name, int value); |
288 template void SkRTConfRegistry::set(const char *name, unsigned int value); | 295 template void SkRTConfRegistry::set(const char *name, unsigned int value); |
289 template void SkRTConfRegistry::set(const char *name, float value); | 296 template void SkRTConfRegistry::set(const char *name, float value); |
290 template void SkRTConfRegistry::set(const char *name, double value); | 297 template void SkRTConfRegistry::set(const char *name, double value); |
291 template void SkRTConfRegistry::set(const char *name, char * value); | 298 template void SkRTConfRegistry::set(const char *name, char * value); |
292 | 299 |
293 SkRTConfRegistry &skRTConfRegistry() { | 300 SkRTConfRegistry &skRTConfRegistry() { |
294 static SkRTConfRegistry r; | 301 static SkRTConfRegistry r; |
295 return r; | 302 return r; |
296 } | 303 } |
| 304 |
| 305 #ifdef SK_SUPPORT_UNITTEST |
| 306 void SkRTConfRegistry::UnitTest() { |
| 307 SkRTConfRegistry registryWithoutContents(true); |
| 308 |
| 309 setenv("skia_nonexistent_item", "132", 1); |
| 310 int result = 0; |
| 311 registryWithoutContents.parse("nonexistent.item", &result); |
| 312 SkASSERT(result == 132); |
| 313 } |
| 314 |
| 315 SkRTConfRegistry::SkRTConfRegistry(bool) |
| 316 : fConfs(100) { |
| 317 } |
| 318 #endif |
OLD | NEW |