@@ -37,10 +37,11 @@ #import "OFPair.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSandbox.h" #import "OFString.h" +#import "OFSystemInfo.h" #import "OFThread+Private.h" #import "OFThread.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" @@ -110,18 +111,19 @@ [[OFLocale alloc] init]; app = [[OFApplication alloc] of_init]; - [app of_setArgumentCount: argc - andArgumentValues: argv]; - #ifdef OF_WINDOWS - __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); - [app of_setArgumentCount: wargc - andWideArgumentValues: wargv]; + if ([OFSystemInfo isWindowsNT]) { + __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); + [app of_setArgumentCount: wargc + andWideArgumentValues: wargv]; + } else #endif + [app of_setArgumentCount: argc + andArgumentValues: argv]; app.delegate = delegate; [app of_run]; @@ -222,51 +224,101 @@ _environment = [[OFMutableDictionary alloc] init]; atexit(atexitHandler); #if defined(OF_WINDOWS) - of_char16_t *env, *env0; - env = env0 = GetEnvironmentStringsW(); - - while (*env != 0) { - void *pool = objc_autoreleasePoolPush(); - OFString *tmp, *key, *value; - size_t length, pos; - - length = of_string_utf16_length(env); - tmp = [OFString stringWithUTF16String: env - length: length]; - env += length + 1; - - /* - * cmd.exe seems to add some special variables which - * start with a "=", even though variable names are not - * allowed to contain a "=". - */ - if ([tmp hasPrefix: @"="]) { - objc_autoreleasePoolPop(pool); - continue; - } - - pos = [tmp rangeOfString: @"="].location; - if (pos == OF_NOT_FOUND) { - fprintf(stderr, "Warning: Invalid environment " - "variable: %s\n", [tmp UTF8String]); - continue; - } - - key = [tmp substringWithRange: of_range(0, pos)]; - value = [tmp substringWithRange: - of_range(pos + 1, tmp.length - pos - 1)]; - - [_environment setObject: value - forKey: key]; - - objc_autoreleasePoolPop(pool); - } - - FreeEnvironmentStringsW(env0); + if ([OFSystemInfo isWindowsNT]) { + of_char16_t *env, *env0; + env = env0 = GetEnvironmentStringsW(); + + while (*env != 0) { + void *pool = objc_autoreleasePoolPush(); + OFString *tmp, *key, *value; + size_t length, pos; + + length = of_string_utf16_length(env); + tmp = [OFString stringWithUTF16String: env + length: length]; + env += length + 1; + + /* + * cmd.exe seems to add some special variables + * which start with a "=", even though variable + * names are not allowed to contain a "=". + */ + if ([tmp hasPrefix: @"="]) { + objc_autoreleasePoolPop(pool); + continue; + } + + pos = [tmp rangeOfString: @"="].location; + if (pos == OF_NOT_FOUND) { + fprintf(stderr, + "Warning: Invalid environment " + "variable: %s\n", tmp.UTF8String); + continue; + } + + key = [tmp substringWithRange: + of_range(0, pos)]; + value = [tmp substringWithRange: + of_range(pos + 1, tmp.length - pos - 1)]; + + [_environment setObject: value + forKey: key]; + + objc_autoreleasePoolPop(pool); + } + + FreeEnvironmentStringsW(env0); + } else { + char *env, *env0; + env = env0 = GetEnvironmentStringsA(); + + while (*env != 0) { + void *pool = objc_autoreleasePoolPush(); + OFString *tmp, *key, *value; + size_t length, pos; + + length = strlen(env); + tmp = [OFString + stringWithCString: env + encoding: [OFLocale encoding] + length: length]; + env += length + 1; + + /* + * cmd.exe seems to add some special variables + * which start with a "=", even though variable + * names are not allowed to contain a "=". + */ + if ([tmp hasPrefix: @"="]) { + objc_autoreleasePoolPop(pool); + continue; + } + + pos = [tmp rangeOfString: @"="].location; + if (pos == OF_NOT_FOUND) { + fprintf(stderr, + "Warning: Invalid environment " + "variable: %s\n", tmp.UTF8String); + continue; + } + + key = [tmp substringWithRange: + of_range(0, pos)]; + value = [tmp substringWithRange: + of_range(pos + 1, tmp.length - pos - 1)]; + + [_environment setObject: value + forKey: key]; + + objc_autoreleasePoolPop(pool); + } + + FreeEnvironmentStringsA(env0); + } #elif defined(OF_AMIGAOS) void *pool = objc_autoreleasePoolPush(); OFFileManager *fileManager = [OFFileManager defaultManager]; OFArray *envContents = [fileManager contentsOfDirectoryAtPath: @"ENV:"]; @@ -436,26 +488,24 @@ } - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char ***)argv { -#ifndef OF_WINDOWS void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; of_string_encoding_t encoding; _argc = argc; _argv = argv; encoding = [OFLocale encoding]; -# ifndef OF_NINTENDO_DS +#ifndef OF_NINTENDO_DS if (*argc > 0) { -# else - if (__system_argv->argvMagic == ARGV_MAGIC && - __system_argv->argc > 0) { -# endif +#else + if (__system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc > 0) { +#endif _programName = [[OFString alloc] initWithCString: (*argv)[0] encoding: encoding]; arguments = [[OFMutableArray alloc] init]; _arguments = arguments; @@ -466,14 +516,10 @@ [arguments makeImmutable]; } objc_autoreleasePoolPop(pool); -#else - _argc = argc; - _argv = argv; -#endif } #ifdef OF_WINDOWS - (void)of_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t **)argv