static void LOCALE_Init(void) { /* extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp, const union cptable *unix_cp ); */ // UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp; UINT unix_cp = 0; #ifdef __APPLE__ /* MacOS doesn't set the locale environment variables so we have to do it ourselves */ CFArrayRef preferred_locales, all_locales; CFStringRef user_language_string_ref = NULL; char user_locale[50]; CFLocaleRef user_locale_ref = CFLocaleCopyCurrent(); CFStringRef user_locale_string_ref = CFLocaleGetIdentifier( user_locale_ref ); CFStringGetCString( user_locale_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 ); CFRelease( user_locale_ref ); if (!strchr( user_locale, '.' )) strcat( user_locale, ".UTF-8" ); unix_cp = CP_UTF8; /* default to utf-8 even if we don't get a valid locale */ setenv( "LANG", user_locale, 0 ); // TRACE( "setting locale to '%s'\n", user_locale ); /* We still want to set the retrieve the preferred language as chosen in System Preferences.app, because it can differ from CFLocaleCopyCurrent(). */ all_locales = CFLocaleCopyAvailableLocaleIdentifiers(); preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL ); if (preferred_locales && CFArrayGetCount( preferred_locales )) user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 ); CFRelease( all_locales ); #endif /* __APPLE__ */ // FIXME setlocale( LC_ALL, "" ); unix_cp = setup_unix_locales(); if (!lcid_LC_MESSAGES) lcid_LC_MESSAGES = lcid_LC_CTYPE; #if 0 #ifdef __APPLE__ /* Override lcid_LC_MESSAGES with user_language if LC_MESSAGES is set to default */ if (lcid_LC_MESSAGES == lcid_LC_CTYPE && user_language_string_ref) { struct locale_name locale_name; WCHAR buffer[128]; CFStringGetCString( user_language_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 ); strcpynAtoW( buffer, user_locale, sizeof(buffer)/sizeof(WCHAR) ); parse_locale_name( buffer, &locale_name ); lcid_LC_MESSAGES = locale_name.lcid; TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale ); } if (preferred_locales) CFRelease( preferred_locales ); #endif NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES) ); NtSetDefaultLocale( TRUE, lcid_LC_MESSAGES ); NtSetDefaultLocale( FALSE, lcid_LC_CTYPE ); ansi_cp = get_lcid_codepage( LOCALE_USER_DEFAULT ); GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) ); GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) ); if (!unix_cp) GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) ); if (!(ansi_cptable = wine_cp_get_table( ansi_cp ))) ansi_cptable = wine_cp_get_table( 1252 ); if (!(oem_cptable = wine_cp_get_table( oem_cp ))) oem_cptable = wine_cp_get_table( 437 ); if (!(mac_cptable = wine_cp_get_table( mac_cp ))) mac_cptable = wine_cp_get_table( 10000 ); if (unix_cp != CP_UTF8) { if (!(unix_cptable = wine_cp_get_table( unix_cp ))) unix_cptable = wine_cp_get_table( 28591 ); } __wine_init_codepages( ansi_cptable, oem_cptable, unix_cptable ); TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n", ansi_cptable->info.codepage, oem_cptable->info.codepage, mac_cptable->info.codepage, unix_cp ); setlocale(LC_NUMERIC, "C"); /* FIXME: oleaut32 depends on this */ #endif }
/* MyPrintDirectoryListing prints a FTP directory entry, represented by a CFDictionary as returned by CFFTPCreateParsedResourceListing, as a single line of text, much like you'd get from "ls -l". */ static void MyPrintDirectoryListing(CFDictionaryRef dictionary) { CFDateRef cfModDate; CFNumberRef cfType, cfMode, cfSize; CFStringRef cfOwner, cfName, cfLink, cfGroup; char owner[256], group[256], name[256]; char permString[12], link[1024]; SInt64 size; SInt32 mode, type; assert(dictionary != NULL); /* You should not assume that the directory entry dictionary will contain all the possible keys. Most of the time it will, however, depending on the FTP server, some of the keys may be missing. */ cfType = CFDictionaryGetValue(dictionary, kCFFTPResourceType); if (cfType) { assert(CFGetTypeID(cfType) == CFNumberGetTypeID()); CFNumberGetValue(cfType, kCFNumberSInt32Type, &type); cfMode = CFDictionaryGetValue(dictionary, kCFFTPResourceMode); if (cfMode) { assert(CFGetTypeID(cfMode) == CFNumberGetTypeID()); CFNumberGetValue(cfMode, kCFNumberSInt32Type, &mode); /* Converts inode status information into a symbolic string */ strmode(mode + DTTOIF(type), permString); fprintf(stderr, "%s ", permString); } } cfOwner = CFDictionaryGetValue(dictionary, kCFFTPResourceOwner); if (cfOwner) { assert(CFGetTypeID(cfOwner) == CFStringGetTypeID()); CFStringGetCString(cfOwner, owner, sizeof(owner), kCFStringEncodingASCII); fprintf(stderr, "%9s", owner); } cfGroup = CFDictionaryGetValue(dictionary, kCFFTPResourceGroup); if (cfGroup) { assert(CFGetTypeID(cfGroup) == CFStringGetTypeID()); CFStringGetCString(cfGroup, group, sizeof(group), kCFStringEncodingASCII); fprintf(stderr, "%9s", group); } cfSize = CFDictionaryGetValue(dictionary, kCFFTPResourceSize); if (cfSize) { assert(CFGetTypeID(cfSize) == CFNumberGetTypeID()); CFNumberGetValue(cfSize, kCFNumberSInt64Type, &size); fprintf(stderr, "%9lld ", size); } cfModDate = CFDictionaryGetValue(dictionary, kCFFTPResourceModDate); if (cfModDate) { CFLocaleRef locale; CFDateFormatterRef formatDate; CFDateFormatterRef formatTime; CFStringRef cfDate; CFStringRef cfTime; char date[256]; char time[256]; assert(CFGetTypeID(cfModDate) == CFDateGetTypeID()); locale = CFLocaleCopyCurrent(); assert(locale != NULL); formatDate = CFDateFormatterCreate(kCFAllocatorDefault, locale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle ); assert(formatDate != NULL); formatTime = CFDateFormatterCreate(kCFAllocatorDefault, locale, kCFDateFormatterNoStyle, kCFDateFormatterShortStyle); assert(formatTime != NULL); cfDate = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, formatDate, cfModDate); assert(cfDate != NULL); cfTime = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, formatTime, cfModDate); assert(cfTime != NULL); CFStringGetCString(cfDate, date, sizeof(date), kCFStringEncodingUTF8); CFStringGetCString(cfTime, time, sizeof(time), kCFStringEncodingUTF8); fprintf(stderr, "%10s %5s ", date, time); CFRelease(cfTime); CFRelease(cfDate); CFRelease(formatTime); CFRelease(formatDate); CFRelease(locale); } /* Note that this sample assumes UTF-8 since that's what the Mac OS X FTP server returns, however, some servers may use a different encoding. */ cfName = CFDictionaryGetValue(dictionary, kCFFTPResourceName); if (cfName) { assert(CFGetTypeID(cfName) == CFStringGetTypeID()); CFStringGetCString(cfName, name, sizeof(name), kCFStringEncodingUTF8); fprintf(stderr, "%s", name); cfLink = CFDictionaryGetValue(dictionary, kCFFTPResourceLink); if (cfLink) { assert(CFGetTypeID(cfLink) == CFStringGetTypeID()); CFStringGetCString(cfLink, link, sizeof(link), kCFStringEncodingUTF8); if (strlen(link) > 0) fprintf(stderr, " -> %s", link); } } fprintf(stderr, "\n"); }
void TclpSetVariables( Tcl_Interp *interp) { #ifndef NO_UNAME struct utsname name; #endif int unameOK; Tcl_DString ds; #ifdef HAVE_COREFOUNDATION char tclLibPath[MAXPATHLEN + 1]; #if MAC_OS_X_VERSION_MAX_ALLOWED > 1020 /* * Set msgcat fallback locale to current CFLocale identifier. */ CFLocaleRef localeRef; if (CFLocaleCopyCurrent != NULL && CFLocaleGetIdentifier != NULL && (localeRef = CFLocaleCopyCurrent())) { CFStringRef locale = CFLocaleGetIdentifier(localeRef); if (locale) { char loc[256]; if (CFStringGetCString(locale, loc, 256, kCFStringEncodingUTF8)) { if (!Tcl_CreateNamespace(interp, "::tcl::mac", NULL, NULL)) { Tcl_ResetResult(interp); } Tcl_SetVar(interp, "::tcl::mac::locale", loc, TCL_GLOBAL_ONLY); } } CFRelease(localeRef); } #endif /* MAC_OS_X_VERSION_MAX_ALLOWED > 1020 */ if (MacOSXGetLibraryPath(interp, MAXPATHLEN, tclLibPath) == TCL_OK) { CONST char *str; CFBundleRef bundleRef; Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "tcl_pkgPath", " ", TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); str = TclGetEnv("DYLD_FRAMEWORK_PATH", &ds); if ((str != NULL) && (str[0] != '\0')) { char *p = Tcl_DStringValue(&ds); /* * Convert DYLD_FRAMEWORK_PATH from colon to space separated. */ do { if (*p == ':') { *p = ' '; } } while (*p++); Tcl_SetVar(interp, "tcl_pkgPath", Tcl_DStringValue(&ds), TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); Tcl_SetVar(interp, "tcl_pkgPath", " ", TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); Tcl_DStringFree(&ds); } bundleRef = CFBundleGetMainBundle(); if (bundleRef) { CFURLRef frameworksURL; Tcl_StatBuf statBuf; frameworksURL = CFBundleCopyPrivateFrameworksURL(bundleRef); if (frameworksURL) { if (CFURLGetFileSystemRepresentation(frameworksURL, TRUE, (unsigned char*) tclLibPath, MAXPATHLEN) && ! TclOSstat(tclLibPath, &statBuf) && S_ISDIR(statBuf.st_mode)) { Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); Tcl_SetVar(interp, "tcl_pkgPath", " ", TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); } CFRelease(frameworksURL); } frameworksURL = CFBundleCopySharedFrameworksURL(bundleRef); if (frameworksURL) { if (CFURLGetFileSystemRepresentation(frameworksURL, TRUE, (unsigned char*) tclLibPath, MAXPATHLEN) && ! TclOSstat(tclLibPath, &statBuf) && S_ISDIR(statBuf.st_mode)) { Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); Tcl_SetVar(interp, "tcl_pkgPath", " ", TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); } CFRelease(frameworksURL); } } Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, TCL_GLOBAL_ONLY | TCL_APPEND_VALUE); } else #endif /* HAVE_COREFOUNDATION */ { Tcl_SetVar(interp, "tcl_pkgPath", pkgPath, TCL_GLOBAL_ONLY); } #ifdef DJGPP Tcl_SetVar2(interp, "tcl_platform", "platform", "dos", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "tcl_platform", "platform", "unix", TCL_GLOBAL_ONLY); #endif unameOK = 0; #ifndef NO_UNAME if (uname(&name) >= 0) { CONST char *native; unameOK = 1; native = Tcl_ExternalToUtfDString(NULL, name.sysname, -1, &ds); Tcl_SetVar2(interp, "tcl_platform", "os", native, TCL_GLOBAL_ONLY); Tcl_DStringFree(&ds); /* * The following code is a special hack to handle differences in the * way version information is returned by uname. On most systems the * full version number is available in name.release. However, under * AIX the major version number is in name.version and the minor * version number is in name.release. */ if ((strchr(name.release, '.') != NULL) || !isdigit(UCHAR(name.version[0]))) { /* INTL: digit */ Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, TCL_GLOBAL_ONLY); } else { #ifdef DJGPP /* * For some obscure reason DJGPP puts major version into * name.release and minor into name.version. As of DJGPP 2.04 this * is documented in djgpp libc.info file. */ Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "tcl_platform", "osVersion", ".", TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.version, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); #else Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.version, TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "tcl_platform", "osVersion", ".", TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE); #endif /* DJGPP */ } Tcl_SetVar2(interp, "tcl_platform", "machine", name.machine, TCL_GLOBAL_ONLY); } #endif /* !NO_UNAME */ if (!unameOK) { Tcl_SetVar2(interp, "tcl_platform", "os", "", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "tcl_platform", "osVersion", "", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "tcl_platform", "machine", "", TCL_GLOBAL_ONLY); } /* * Copy the username of the real user (according to getuid()) into * tcl_platform(user). */ { struct passwd *pwEnt = TclpGetPwUid(getuid()); const char *user; if (pwEnt == NULL) { user = ""; Tcl_DStringInit(&ds); /* ensure cleanliness */ } else { user = Tcl_ExternalToUtfDString(NULL, pwEnt->pw_name, -1, &ds); } Tcl_SetVar2(interp, "tcl_platform", "user", user, TCL_GLOBAL_ONLY); Tcl_DStringFree(&ds); } }
CFStringRef getBuffer() { kern_return_t kernResult; bufferStruct myBufStruct; size_t structSize = sizeof(myBufStruct); kernResult = IOConnectCallMethod(userClient, klogKextBuffer, NULL, 0, NULL, NULL, NULL, NULL, &myBufStruct, &structSize); CFDataRef result = CFDataCreate(kCFAllocatorDefault,myBufStruct.buffer,myBufStruct.bufLen); CFMutableStringRef decodedData = CFStringCreateMutable(kCFAllocatorDefault,0); if (!keymap) return decodedData; CFDictionaryRef flagsDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Flags")); if (!flagsDict) return decodedData; CFDictionaryRef ucDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Uppercase")); if (!ucDict) return decodedData; CFDictionaryRef lcDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Lowercase")); if (!lcDict) return decodedData; CFNumberFormatterRef myNF = CFNumberFormatterCreate(kCFAllocatorDefault,CFLocaleCopyCurrent(),kCFNumberFormatterNoStyle); for (int i=0; i<CFDataGetLength(result);i+=2) { u_int16_t curChar; CFDataGetBytes(result,CFRangeMake(i,2),(UInt8*)&curChar); bool isUpper = false; if (CFBooleanGetValue(showMods)) { char flagTmp = (curChar >> 11); if (flagTmp & 0x01) CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x01"))); if (flagTmp & 0x02) CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x02"))); if (flagTmp & 0x04) CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x04"))); if (flagTmp & 0x08) CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x08"))); if (flagTmp & 0x10) isUpper = true; } curChar &= 0x07ff; CFStringRef keyChar = CFNumberFormatterCreateStringWithValue(kCFAllocatorDefault,myNF,kCFNumberShortType,&curChar); CFStringRef text; if (isUpper) text = (CFStringRef)CFDictionaryGetValue(ucDict,keyChar); else text = (CFStringRef)CFDictionaryGetValue(lcDict,keyChar); if (text) { if (CFStringCompare(text,CFSTR("\\n"),0)==kCFCompareEqualTo) text = CFSTR("\n"); CFStringAppend(decodedData,text); } else syslog(LOG_ERR,"Unmapped key %d",curChar); } return decodedData; }
Boolean APSetKey(CFStringRef key) { hash = CFSTR(""); blacklist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); CFMutableStringRef mutableKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key); CFStringRef preparedKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key); CFLocaleRef currentLocale = CFLocaleCopyCurrent(); CFStringLowercase(mutableKey, currentLocale); CFRelease(currentLocale); if (CFStringHasPrefix(mutableKey, CFSTR("0x")) && CFStringGetLength(mutableKey) > 2) { CFStringDelete(mutableKey, CFRangeMake(0, 2)); } if (CFStringGetLength(mutableKey) == 1024/8*2) { CFRelease(preparedKey); preparedKey = APPEMKeyCreateFromHexKey(mutableKey); } CFRelease(mutableKey); SecItemImportExportKeyParameters params = {0}; params.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION; params.flags = kSecKeyNoAccessControl; SecExternalItemType itemType = kSecItemTypePublicKey; SecExternalFormat externalFormat = kSecFormatPEMSequence; CFArrayRef tempArray = NULL; OSStatus oserr = noErr; // Set the key as extractable. Looking through the source code in SecImportExportUtils.cpp // it looks like this isn't handled, yet it seems to be documented to me. One day the code // may catch up, so I'm leaving this here to show the intention. CFNumberRef attributeFlags[1]; uint32 flag0value = CSSM_KEYATTR_EXTRACTABLE; CFNumberRef flag0 = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &flag0value); attributeFlags[0] = flag0; CFArrayRef keyAttributes = CFArrayCreate(kCFAllocatorDefault, (const void **)attributeFlags, 1, &kCFTypeArrayCallBacks); CFRelease(flag0); params.keyAttributes = keyAttributes; CFDataRef keyData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, preparedKey, kCFStringEncodingUTF8, 0); CFRelease(preparedKey); oserr = SecItemImport(keyData, NULL, &externalFormat, &itemType, 0, ¶ms, NULL, &tempArray); CFRelease(keyAttributes); CFRelease(keyData); if (oserr != noErr) { CFStringRef errorString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("Unable to import key. Error %d"), oserr); CFShow(errorString); CFRelease(errorString); return FALSE; } publicKeyRef = (SecKeyRef)CFArrayGetValueAtIndex(tempArray, 0); CFRetain(publicKeyRef); CFRelease(tempArray); return TRUE; }
char *rktio_system_language_country(rktio_t *rktio) { #ifdef MACOS_UNICODE_SUPPORT /* Mac OS */ CFLocaleRef l; CFStringRef s; int len; char *r; l = CFLocaleCopyCurrent(); s = CFLocaleGetIdentifier(l); len = CFStringGetLength(s); r = malloc(len * 6 + 1); CFStringGetCString(s, r, len * 6 + 1, kCFStringEncodingUTF8); CFRelease(l); r[5] = 0; return r; #elif defined(RKTIO_SYSTEM_WINDOWS) /* Windows */ LCID l; int llen, clen; wchar_t *lang, *country, *s; l = GetUserDefaultLCID(); llen = GetLocaleInfoW(l, LOCALE_SENGLANGUAGE, NULL, 0); lang = malloc(llen * sizeof(wchar_t)); GetLocaleInfoW(l, LOCALE_SENGLANGUAGE, lang, llen); if (llen) llen -= 1; /* drop nul terminator */ clen = GetLocaleInfoW(l, LOCALE_SENGCOUNTRY, NULL, 0); country = malloc(clen * sizeof(wchar_t)); GetLocaleInfoW(l, LOCALE_SENGCOUNTRY, country, clen); if (clen) clen -= 1; /* drop nul terminator */ s = malloc((clen + llen + 2) * sizeof(wchar_t)); memcpy(s, lang, llen * sizeof(wchar_t)); memcpy(s + 1 + llen, country, clen * sizeof(wchar_t)); s[llen] = '_'; s[clen + llen + 1] = 0; free(lang); free(country); return NARROW_PATH_copy_then_free(s); #else /* Unix */ char *s; s = getenv("LC_ALL"); if (!s) s = getenv("LC_CTYPE"); if (!s) s = getenv("LANG"); if (s) { /* Check that the environment variable has the form xx_XX[.ENC] */ if ((s[0] >= 'a') && (s[0] <= 'z') && (s[1] >= 'a') && (s[1] <= 'z') && (s[2] == '_') && (s[3] >= 'A') && (s[3] <= 'Z') && (s[4] >= 'A') && (s[4] <= 'Z') && (!s[5] || s[5] == '.')) { /* Good */ } else s = NULL; } if (!s) s = "en_US"; return MSC_IZE(strdup)(s); #endif }