DECLARE_TEST(environment, builtin) { const string_const_t* cmdline = environment_command_line(); EXPECT_GE(array_size(cmdline), 1); #if !BUILD_MONOLITHIC EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("test-environment"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); EXPECT_CONSTSTRINGEQ(environment_executable_name(), string_const(STRING_CONST("test-environment"))); #elif FOUNDATION_PLATFORM_ANDROID EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("com.rampantpixels.foundation.test"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); #elif !FOUNDATION_PLATFORM_PNACL EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("test-all"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); EXPECT_CONSTSTRINGEQ(environment_executable_name(), string_const(STRING_CONST("test-all"))); #endif EXPECT_NE(environment_initial_working_directory().str, 0); EXPECT_NE(environment_initial_working_directory().length, 0); EXPECT_CONSTSTRINGEQ(environment_initial_working_directory(), environment_current_working_directory()); EXPECT_NE(environment_home_directory().str, 0); EXPECT_NE(environment_home_directory().length, 0); EXPECT_NE(environment_temporary_directory().str, 0); EXPECT_NE(environment_temporary_directory().length, 0); #if !FOUNDATION_PLATFORM_PNACL EXPECT_NE(environment_variable(STRING_CONST("PATH")).str, 0); EXPECT_NE(environment_variable(STRING_CONST("PATH")).length, 0); #endif return 0; }
DECLARE_TEST( environment, builtin ) { char const* const* cmdline = environment_command_line(); EXPECT_GE( array_size( cmdline ), 1 ); #if !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_IOS EXPECT_NE( string_find_string( cmdline[0], "test-environment", 0 ), STRING_NPOS ); EXPECT_STREQ( environment_executable_name(), "test-environment" ); #endif EXPECT_NE( environment_initial_working_directory(), 0 ); EXPECT_NE( string_length( environment_initial_working_directory() ), 0 ); EXPECT_STREQ( environment_initial_working_directory(), environment_current_working_directory() ); EXPECT_NE( environment_home_directory(), 0 ); EXPECT_NE( string_length( environment_home_directory() ), 0 ); EXPECT_NE( environment_temporary_directory(), 0 ); EXPECT_NE( string_length( environment_temporary_directory() ), 0 ); EXPECT_NE( environment_variable( "PATH" ), 0 ); EXPECT_NE( string_length( environment_variable( "PATH" ) ), 0 ); return 0; }
DECLARE_TEST( environment, builtin ) { char const* const* cmdline = environment_command_line(); EXPECT_GE( array_size( cmdline ), 1 ); #if !BUILD_MONOLITHIC EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "test-environment", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); EXPECT_STREQ( environment_executable_name(), "test-environment" ); #elif FOUNDATION_PLATFORM_ANDROID EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "com.rampantpixels.foundation.test", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); #elif !FOUNDATION_PLATFORM_PNACL EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "test-all", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); EXPECT_STREQ( environment_executable_name(), "test-all" ); #endif EXPECT_NE( environment_initial_working_directory(), 0 ); EXPECT_NE( string_length( environment_initial_working_directory() ), 0 ); EXPECT_STREQ( environment_initial_working_directory(), environment_current_working_directory() ); EXPECT_NE( environment_home_directory(), 0 ); EXPECT_NE( string_length( environment_home_directory() ), 0 ); EXPECT_NE( environment_temporary_directory(), 0 ); EXPECT_NE( string_length( environment_temporary_directory() ), 0 ); #if !FOUNDATION_PLATFORM_PNACL EXPECT_NE( environment_variable( "PATH" ), 0 ); EXPECT_NE( string_length( environment_variable( "PATH" ) ), 0 ); #endif return 0; }
static NOINLINE const char* _expand_environment( hash_t key, char* var ) { if( key == HASH_EXECUTABLE_NAME ) return environment_executable_name(); else if( key == HASH_EXECUTABLE_DIRECTORY ) return environment_executable_directory(); else if( key == HASH_EXECUTABLE_PATH ) return environment_executable_path(); else if( key == HASH_INITIAL_WORKING_DIRECTORY ) return environment_initial_working_directory(); else if( key == HASH_CURRENT_WORKING_DIRECTORY ) return environment_current_working_directory(); else if( key == HASH_HOME_DIRECTORY ) return environment_home_directory(); else if( key == HASH_TEMPORARY_DIRECTORY ) return environment_temporary_directory(); else if( string_equal_substr( var, "variable[", 9 ) ) //variable[varname] - Environment variable named "varname" { const char* value; unsigned int end_pos = string_find( var, ']', 9 ); if( end_pos != STRING_NPOS ) var[end_pos] = 0; value = environment_variable( var ); if( end_pos != STRING_NPOS ) var[end_pos] = ']'; return value; } return ""; }
template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) { SkString *str = NULL; for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) { if (fConfigFileKeys[i]->equals(name)) { str = fConfigFileValues[i]; break; } } SkString environment_variable("skia."); environment_variable.append(name); const char *environment_value = getenv(environment_variable.c_str()); if (environment_value) { str->set(environment_value); } else { // apparently my shell doesn't let me have environment variables that // have periods in them, so also let the user substitute underscores. SkString underscore_environment_variable("skia_"); char *underscore_name = SkStrDup(name); str_replace(underscore_name,'.','_'); underscore_environment_variable.append(underscore_name); sk_free(underscore_name); environment_value = getenv(underscore_environment_variable.c_str()); if (environment_value) { str->set(environment_value); } } if (!str) { return false; } bool success; T new_value = doParse<T>(str->c_str(),&success); if (success) { *value = new_value; } else { SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n", str->c_str(), name); } return success; }
const char* environment_home_directory( void ) { if( _environment_home_dir[0] ) return _environment_home_dir; #if FOUNDATION_PLATFORM_WINDOWS { char* path; wchar_t* wpath = memory_allocate_zero( sizeof( wchar_t ) * FOUNDATION_MAX_PATHLEN, 0, MEMORY_TEMPORARY ); SHGetFolderPathW( 0, CSIDL_LOCAL_APPDATA, 0, 0, wpath ); path = path_clean( string_allocate_from_wstring( wpath, 0 ), true ); string_copy( _environment_home_dir, path, FOUNDATION_MAX_PATHLEN ); string_deallocate( path ); memory_deallocate( wpath ); } #elif FOUNDATION_PLATFORM_LINUX string_copy( _environment_home_dir, environment_variable( "HOME" ), FOUNDATION_MAX_PATHLEN ); #elif FOUNDATION_PLATFORM_APPLE if( environment_application()->flags & APPLICATION_UTILITY ) { CFStringRef home = NSHomeDirectory(); CFStringGetCString( home, _environment_home_dir, FOUNDATION_MAX_PATHLEN, kCFStringEncodingUTF8 ); } else { char bundle_identifier[FOUNDATION_MAX_PATHLEN+1]; environment_bundle_identifier( bundle_identifier ); char* path = path_append( path_merge( _environment_home_dir, "/Library/Application Support" ), bundle_identifier ); string_copy( _environment_home_dir, path, FOUNDATION_MAX_PATHLEN ); string_deallocate( path ); } #elif FOUNDATION_PLATFORM_ANDROID string_copy( _environment_home_dir, android_app()->activity->internalDataPath, FOUNDATION_MAX_PATHLEN ); #else # error Not implemented #endif return _environment_home_dir; }