BOOL WINAPI OnReadConsoleInputA(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead) { //typedef BOOL (WINAPI* OnReadConsoleInputA_t)(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead); SUPPRESSORIGINALSHOWCALL; ORIGINAL_KRNL(ReadConsoleInputA); //if (gpFarInfo && bMainThread) // TouchReadPeekConsoleInputs(0); BOOL lbRc = FALSE; #if defined(_DEBUG) #if 1 UINT nCp = GetConsoleCP(); UINT nOutCp = GetConsoleOutputCP(); UINT nOemCp = GetOEMCP(); UINT nAnsiCp = GetACP(); #endif #endif // To minimize startup duration and possible problems // hook server will start on first 'user interaction' CheckHookServer(); if (ph && ph->PreCallBack) { SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead); // Если функция возвращает FALSE - реальное чтение не будет вызвано if (!ph->PreCallBack(&args)) return lbRc; } CESERVER_CONSOLE_APP_MAPPING* pAppMap = NULL; PreReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_LLInput, &pAppMap); //#ifdef USE_INPUT_SEMAPHORE //DWORD nSemaphore = ghConInSemaphore ? WaitForSingleObject(ghConInSemaphore, INSEMTIMEOUT_READ) : 1; //_ASSERTE(nSemaphore<=1); //#endif lbRc = F(ReadConsoleInputA)(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead); PostReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_LLInput, pAppMap); //#ifdef USE_INPUT_SEMAPHORE //if ((nSemaphore == WAIT_OBJECT_0) && ghConInSemaphore) ReleaseSemaphore(ghConInSemaphore, 1, NULL); //#endif if (ph && ph->PostCallBack) { SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead); ph->PostCallBack(&args); } if (lbRc && lpNumberOfEventsRead && *lpNumberOfEventsRead && lpBuffer) { OnPeekReadConsoleInput('R', 'A', hConsoleInput, lpBuffer, *lpNumberOfEventsRead); } return lbRc; }
void console_appender::append_fixed_color( const logging_event& event ) { #if defined(WIN32) || defined(WIN64) SetConsoleTextAttribute( out_handle_, fixed_color_attributes_ ); if ( utf8_ ) { wchar_t wbuf[LOGGING_MAX_MESSAGE_SIZE]; char buf[LOGGING_MAX_MESSAGE_SIZE*4]; int len = MultiByteToWideChar( CP_UTF8, 0, event.get_message().c_str(), event.get_message().length(),wbuf,sizeof(wbuf) ); len = WideCharToMultiByte( GetOEMCP(),0,wbuf,len,buf,sizeof(buf),NULL,NULL ); buf[len] = 0; const_cast<logging_event&>(event).get_message().assign( buf, len ); } #else *stream_ << fixed_color_escape_string_; #endif _get_layout().format(event,*stream_); #if defined(WIN32) || defined(WIN64) stream_->flush(); SetConsoleTextAttribute( out_handle_, defualt_attributes_ ); #else *stream_ << "\033[0m"; *stream_ << suffix_; stream_->flush(); #endif }
//-------------------------------------------------------------------------- char *uniremap_init(char *table) { const char *cur = setlocale(LC_CTYPE, NULL); if(!cur) cur = "C"; // PARANOYA cur = qstrdup(cur); #ifdef __UNIX__ table = create_map("", &lm[0], table); lm[1] = lm[0]; #else { char s[16]; int oemcp, acp = get_codepages(&oemcp); if ( acp == CP_ACP ) acp = GetACP(); if ( oemcp == CP_OEMCP ) oemcp = GetOEMCP(); qsnprintf(s, sizeof(s), ".%u", oemcp); table = create_map(s, &lm[0], table); qsnprintf(s, sizeof(s), ".%u", acp); create_map(s, &lm[1], NULL); } #endif setlocale(LC_CTYPE, cur); // restore default locale qfree((void*)cur); return(table); }
static int getSystemCP (int codepage) { _locale_t plocinfo = nullptr; _LocaleUpdate _loc_update(plocinfo); fSystemSet = 0; /* get system code page values if requested */ if (codepage == _MB_CP_OEM) { fSystemSet = 1; return GetOEMCP(); } else if (codepage == _MB_CP_ANSI) { fSystemSet = 1; return GetACP(); } else if (codepage == _MB_CP_LOCALE) { fSystemSet = 1; return _loc_update.GetLocaleT()->locinfo->_public._locale_lc_codepage; } return codepage; }
PW32CP const struct php_win32_cp *php_win32_cp_get_by_id(DWORD id) {/*{{{*/ size_t i; if (id < php_win32_cp_map[0].id) { switch (id) { case CP_ACP: id = GetACP(); break; case CP_OEMCP: id = GetOEMCP(); break; } } for (i = 0; i < sizeof(php_win32_cp_map)/sizeof(struct php_win32_cp); i++) { if (php_win32_cp_map[i].id == id) { return &php_win32_cp_map[i]; } } SET_ERRNO_FROM_WIN32_CODE(ERROR_NOT_FOUND); return NULL; }/*}}}*/
/** * Prepare console on program initialization: change console font codepage * according to program options and hide cursor. */ void setup_console(void) { HANDLE hOut; CONSOLE_CURSOR_INFO cci; int cp = (opt.flags&OPT_UTF8 ? CP_UTF8 : opt.flags&OPT_ANSI ? GetACP() : GetOEMCP()); rhash_data.saved_console_codepage = -1; /* note: we are using numbers 1 = _fileno(stdout), 2 = _fileno(stderr) */ /* cause _fileno() is undefined, when compiling as strict ansi C. */ if(cp > 0 && IsValidCodePage(cp) && (isatty(1) || isatty(2)) ) { rhash_data.saved_console_codepage = GetConsoleOutputCP(); SetConsoleOutputCP(cp); setlocale(LC_CTYPE, opt.flags&OPT_UTF8 ? "C" : opt.flags&OPT_ANSI ? ".ACP" : ".OCP"); rsh_exit = rhash_exit; } if((opt.flags & OPT_PERCENTS) != 0) { hOut = GetStdHandle(STD_ERROR_HANDLE); if(hOut != INVALID_HANDLE_VALUE) { /* store current cursor size and visibility flag */ GetConsoleCursorInfo(hOut, &cci); rhash_data.saved_cursor_size = (cci.bVisible ? cci.dwSize : 0); /* now hide cursor */ cci.bVisible = 0; SetConsoleCursorInfo(hOut, &cci); /* hide cursor */ } } }
static int cmd_get(connection_context *c) { static const char* var_version = "version"; static const char* var_codepage = "codepage"; char *cmdline; int res = 0; cmdline = strchr(c->cmd, ' '); if (!cmdline) { goto finish; } ++cmdline; int l; if ((strstr(cmdline, var_version) == cmdline) && (cmdline[l = strlen(var_version)] == 0)) { hprintf(c->pipe, "version 0x%04X\n", VERSION); } else if ((strstr(cmdline, var_codepage) == cmdline) && (cmdline[l = strlen(var_codepage)] == 0)) { hprintf(c->pipe, "codepage %d\n", GetOEMCP()); } else { hprintf(c->pipe, "error Unknown argument (%s)\n", c->cmd); goto finish; } res = 1; finish: return res; }
void CCO2_View::Get_CO2_Temperature_unit(CString &strTemp) { UINT uint_temp=GetOEMCP();//get system is for chinese or english if(uint_temp!=936 && uint_temp!=950) { if(product_register_value[MODBUS_DEGC_OR_F]==0) //121 { strTemp.Format(_T("%cC"),176); } else { strTemp.Format(_T("%cF"),176); } } else { //Chinese. if(product_register_value[MODBUS_DEGC_OR_F]==0)//121 { strTemp=_T("℃"); } else { strTemp=_T("℉"); } } }
VOID WINAPI EngGetCurrentCodePage( OUT PUSHORT OemCodePage, OUT PUSHORT AnsiCodePage) { *OemCodePage = GetOEMCP(); *AnsiCodePage = GetACP(); }
// Find the codepage number for a charset name. static uint cs_codepage(string name) { uint cp = CP_ACP; char upname[strlen(name) + 1]; strtoupper(upname, name); uint iso; if (sscanf(upname, "ISO-8859-%u", &iso) == 1 || sscanf(upname, "ISO8859-%u", &iso) == 1 || sscanf(upname, "ISO8859%u", &iso) == 1) { if (iso && iso <= 16 && iso != 12) cp = 28590 + iso; } else if (sscanf(upname, "CP%u", &cp) == 1 || sscanf(upname, "WIN%u", &cp) == 1 || sscanf(upname, "%u", &cp) == 1) { // Got a codepage number. } else { // Search the charset table. for (uint i = 0; i < lengthof(cs_names); i++) { if (!strcasecmp(name, cs_names[i].name)) { cp = cs_names[i].cp; break; } } } return cp == CP_ACP ? GetACP() : cp == CP_OEMCP ? GetOEMCP() : valid_codepage(cp) ? cp : GetACP(); }
static res_language_enumeration check_code_page( void ) /*****************************************************/ { unsigned int codepage = 0; #if defined __OS2__ OS_UINT cp; OS_UINT bytesOutput; #elif defined __WINDOWS__ char lang[4]; #endif /*** Determine the system default code page ***/ #if defined __NT__ codepage = GetOEMCP(); #elif defined __OS2__ DosGetCp( 2, &cp, &bytesOutput ); codepage = cp; #elif defined __OSI__ codepage = 437; // Maybe we could try harder... #elif defined __DOS__ codepage = dos_get_code_page(); #elif defined __WINDOWS__ if( GetProfileString( "Intl", "sLanguage", "ENU", lang, 4 ) ) { if( !stricmp( lang, "JPN" ) ) codepage = 932; } #endif /*** Try to match the returned code page to known ones ***/ switch( codepage ) { case 932: return( RLE_JAPANESE ); default: return( RLE_ENGLISH ); } }
/* Print some "press enter" message, wait for that, exit. */ static void doExit(int code) { /* set console codepage to OEM in case the process changed it to something else */ SetConsoleOutputCP(GetOEMCP()); puts(sleepMsg); _getch(); exit(code); }
std::string get_local_console_charset() { #if defined(SYS_WINDOWS) if (get_windows_version() >= WINDOWS_VERSION_VISTA) return std::string("CP") + to_string(GetACP()); return std::string("CP") + to_string(GetOEMCP()); #else return get_local_charset(); #endif }
L00401540() { /* unknown */ void ebp; /* unknown */ void edi; L00401308(edx, eax, ecx, ebx); GetSystemDefaultLCID(); return(GetOEMCP()); }
L004011CC() { /* unknown */ void ebp; /* unknown */ void edi; L0040144C(ecx, ebx, esi, ebx); GetOEMCP(); return(GetACP()); }
L00401114() { /* unknown */ void ebp; /* unknown */ void edi; L0040155C(ecx, esi, esi); GetOEMCP(); return(GetActiveWindow()); }
L004010BC() { /* unknown */ void ebp; /* unknown */ void edi; L00401158(esi, ebx, ebx, ebx); GetOEMCP(); return(GetCurrentProcessId()); }
L004010D8() { /* unknown */ void ebp; (save)edi; L00401424(eax, eax, ecx, esi); (restore)edi; GetOEMCP(); return(IsDBCSLeadByte(0)); }
UINT mswin_charset() { CHARSETINFO cis; if (SYMHANDLING(H_IBM)) if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE)) return cis.ciCharset; else return OEM_CHARSET; else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE)) return cis.ciCharset; else return ANSI_CHARSET; }
UINT mswin_charset() { CHARSETINFO cis; if( iflags.IBMgraphics ) if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) ) return cis.ciCharset; else return OEM_CHARSET; else if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) ) return cis.ciCharset; else return ANSI_CHARSET; }
void console_appender::append_color_by_priority( const logging_event& event ) { //Prepare the color #if defined(WIN32) || defined(WIN64) static WORD attributes[] = { 0 ,defualt_attributes_//TRACE ,FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY//DEBUG ,FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY//INFO ,FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY//WARN ,FOREGROUND_RED | FOREGROUND_INTENSITY//ERROR ,FOREGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_BLUE //FATAL }; #else static const char* color_codes[] = { "" ,""//TRACE ,"\033[1;37m"//DEBUG ,"\033[1;36m"//INFO ,"\033[1;33m"//WARN ,"\033[1;31m"//ERROR ,"\033[1;35m"//FATAL }; #endif #if defined(WIN32) || defined(WIN64) SetConsoleTextAttribute(out_handle_, attributes[event.get_priority()/10000]); if ( utf8_ ) { wchar_t wbuf[LOGGING_MAX_MESSAGE_SIZE]; char buf[LOGGING_MAX_MESSAGE_SIZE*4]; int len = MultiByteToWideChar( CP_UTF8, 0, event.get_message().c_str(), event.get_message().length(),wbuf,sizeof(wbuf) ); len = WideCharToMultiByte( GetOEMCP(),0,wbuf,len,buf,sizeof(buf),NULL,NULL ); buf[len] = 0; const_cast<logging_event&>(event).get_message().assign( buf, len ); } #else (*stream_) << color_codes[event.get_priority()/10000]; #endif _get_layout().format(event,*stream_); #if defined(WIN32) || defined(WIN64) stream_->flush(); SetConsoleTextAttribute(out_handle_, defualt_attributes_); stream_->flush(); #else *stream_ << "\033[0m"; stream_->flush(); #endif }
int Init_enc_set_filesystem_encoding(void) { int idx; #if defined NO_LOCALE_CHARMAP # error NO_LOCALE_CHARMAP defined #elif defined _WIN32 || defined __CYGWIN__ char cp[SIZEOF_CP_NAME]; CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP()); idx = rb_enc_find_index(cp); if (idx < 0) idx = ENCINDEX_ASCII; #else idx = rb_enc_to_index(rb_default_external_encoding()); #endif return idx; }
static int enc_set_filesystem_encoding(void) { int idx; #if defined NO_LOCALE_CHARMAP idx = rb_enc_to_index(rb_default_external_encoding()); #elif defined _WIN32 || defined __CYGWIN__ char cp[sizeof(int) * 8 / 3 + 4]; snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP()); idx = rb_enc_find_index(cp); if (idx < 0) idx = rb_ascii8bit_encindex(); #else idx = rb_enc_to_index(rb_default_external_encoding()); #endif enc_alias_internal("filesystem", idx); return idx; }
/* * Get ANSI/system codepage. */ static UINT IDNA_GetCodePage (void) { #ifdef IDNA_DEBUG_ENABLED CPINFOEX CPinfo; UINT CP = 0; IDNA_DEBUG ("OEM codepage %u\n", GetOEMCP()); CP = GetACP(); if (GetCPInfoEx(CP, 0, &CPinfo)) { IDNA_DEBUG ("ACP-name " STR_FMT "\n", CPinfo.CodePageName); } return (CP); #else return GetACP(); #endif }
static WINBASEAPI BOOL WINAPI GetCPInfoExUW_EMULATE(UINT CodePage, DWORD dwFlags, LPCPINFOEXA lpCPInfoEx) { // Emulate GetCPInfoExUW() on platforms that don't have GetCPInfoExW(). // This can be done by using GetCPInfo(), then filling in the other fields. if (!lpCPInfoEx) { // Struct not specified. Don't bother converting anything. return GetCPInfo(CodePage, (LPCPINFO)lpCPInfoEx); } // Get the code page information. BOOL bRet = GetCPInfo(CodePage, (LPCPINFO)lpCPInfoEx); if (!bRet) return bRet; // Get the other fields for the CPINFOEX struct. switch (CodePage) { case CP_ACP: lpCPInfoEx->CodePage = GetACP(); break; case CP_OEMCP: lpCPInfoEx->CodePage = GetOEMCP(); break; default: lpCPInfoEx->CodePage = CodePage; break; } // Use a reasonable default for the Unicode default character. lpCPInfoEx->UnicodeDefaultChar = L'?'; // Clear the code page name for now. // TODO: Add a lookup table. lpCPInfoEx->CodePageName[0] = 0x00; return bRet; }
// Добавляем все необходимые таблицы символов void AddCodePages(DWORD codePages) { // Добавляем стандартные таблицы символов uintptr_t cp_auto = CP_DEFAULT; if ( 0 != (codePages & ::DefaultCP) ) { AddStandardCodePage(MSG(MDefaultCP), CP_DEFAULT, -1, true); cp_auto = CP_REDETECT; } AddStandardCodePage((codePages & ::SearchAll) ? MSG(MFindFileAllCodePages) : MSG(MEditOpenAutoDetect), cp_auto, -1, (codePages & (::SearchAll | ::Auto)) != 0); AddSeparator(MSG(MGetCodePageSystem)); AddStandardCodePage(L"OEM", GetOEMCP(), -1, (codePages & ::OEM) != 0); AddStandardCodePage(L"ANSI", GetACP(), -1, (codePages & ::ANSI) != 0); AddSeparator(MSG(MGetCodePageUnicode)); if (codePages & ::UTF7) AddStandardCodePage(L"UTF-7", CP_UTF7, -1, true); //?? не поддерживается, да и нужно ли? AddStandardCodePage(L"UTF-8", CP_UTF8, -1, (codePages & ::UTF8) != 0); AddStandardCodePage(L"UTF-16 (Little endian)", CP_UNICODE, -1, (codePages & ::UTF16LE) != 0); AddStandardCodePage(L"UTF-16 (Big endian)", CP_REVERSEBOM, -1, (codePages & ::UTF16BE) != 0); // Получаем таблицы символов установленные в системе allow_m2 = (codePages & ::AllowM2) != 0; EnumSystemCodePages((CODEPAGE_ENUMPROCW)EnumCodePagesProc, CP_INSTALLED); }
[[nodiscard]] HRESULT ConsoleServerInitialization(_In_ HANDLE Server, const ConsoleArguments* const args) { Globals& Globals = ServiceLocator::LocateGlobals(); try { Globals.pDeviceComm = new DeviceComm(Server); Globals.launchArgs = *args; Globals.uiOEMCP = GetOEMCP(); Globals.uiWindowsCP = GetACP(); Globals.pFontDefaultList = new RenderFontDefaults(); FontInfo::s_SetFontDefaultList(Globals.pFontDefaultList); } CATCH_RETURN(); // Removed allocation of scroll buffer here. return S_OK; }
static unsigned char * _clip_win_cp(int who) { int cp_num = 0; unsigned char * buf; switch (who) { case 1: cp_num = GetConsoleCP(); break; case 2: cp_num = GetACP(); break; case 3: cp_num = GetOEMCP(); break; case 4: cp_num = GetConsoleOutputCP(); break; } buf = malloc(10); snprintf(buf,10,"cp%d",cp_num); return buf; }
/**************************************************************************** * GetKBCodePage (USER32.@) */ UINT WINAPI GetKBCodePage(void) { return GetOEMCP(); }
bool GetFileFormat(File& file, UINT& nCodePage, bool* pSignatureFound, bool bUseHeuristics) { DWORD dwTemp=0; bool bSignatureFound = false; bool bDetect=false; DWORD Readed = 0; if (file.Read(&dwTemp, sizeof(dwTemp), Readed) && Readed > 1 ) // minimum signature size is 2 bytes { if (LOWORD(dwTemp) == SIGN_UNICODE) { nCodePage = CP_UNICODE; file.SetPointer(2, nullptr, FILE_BEGIN); bSignatureFound = true; } else if (LOWORD(dwTemp) == SIGN_REVERSEBOM) { nCodePage = CP_REVERSEBOM; file.SetPointer(2, nullptr, FILE_BEGIN); bSignatureFound = true; } else if ((dwTemp & 0x00FFFFFF) == SIGN_UTF8) { nCodePage = CP_UTF8; file.SetPointer(3, nullptr, FILE_BEGIN); bSignatureFound = true; } else { file.SetPointer(0, nullptr, FILE_BEGIN); } } if (bSignatureFound) { bDetect = true; } else if (bUseHeuristics) { file.SetPointer(0, nullptr, FILE_BEGIN); DWORD Size=0x8000; // BUGBUG. TODO: configurable LPVOID Buffer=xf_malloc(Size); DWORD ReadSize = 0; bool ReadResult = file.Read(Buffer, Size, ReadSize); file.SetPointer(0, nullptr, FILE_BEGIN); if (ReadResult && ReadSize) { int test= IS_TEXT_UNICODE_STATISTICS| IS_TEXT_UNICODE_REVERSE_STATISTICS| IS_TEXT_UNICODE_CONTROLS| IS_TEXT_UNICODE_REVERSE_CONTROLS| IS_TEXT_UNICODE_ILLEGAL_CHARS| IS_TEXT_UNICODE_ODD_LENGTH| IS_TEXT_UNICODE_NULL_BYTES; if (IsTextUnicode(Buffer, ReadSize, &test)) { if (!(test&IS_TEXT_UNICODE_ODD_LENGTH) && !(test&IS_TEXT_UNICODE_ILLEGAL_CHARS)) { if ((test&IS_TEXT_UNICODE_NULL_BYTES) || (test&IS_TEXT_UNICODE_CONTROLS) || (test&IS_TEXT_UNICODE_REVERSE_CONTROLS)) { if ((test&IS_TEXT_UNICODE_CONTROLS) || (test&IS_TEXT_UNICODE_STATISTICS)) { nCodePage=CP_UNICODE; bDetect=true; } else if ((test&IS_TEXT_UNICODE_REVERSE_CONTROLS) || (test&IS_TEXT_UNICODE_REVERSE_STATISTICS)) { nCodePage=CP_REVERSEBOM; bDetect=true; } } } } else if (IsTextUTF8(static_cast<LPBYTE>(Buffer), ReadSize)) { nCodePage=CP_UTF8; bDetect=true; } else { nsUniversalDetectorEx *ns = new nsUniversalDetectorEx(); ns->HandleData(static_cast<LPCSTR>(Buffer), ReadSize); ns->DataEnd(); int cp = ns->getCodePage(); if ( cp >= 0 ) { const wchar_t *deprecated = Opt.strNoAutoDetectCP.CPtr(); if ( 0 == wcscmp(deprecated, L"-1") ) { if ( Opt.CPMenuMode ) { if ( static_cast<UINT>(cp) != GetACP() && static_cast<UINT>(cp) != GetOEMCP() ) { int selectType = 0; wchar_t szcp[16]; _snwprintf(szcp, ARRAYSIZE(szcp), L"%d", cp); GeneralCfg->GetValue(FavoriteCodePagesKey, szcp, &selectType, 0); if (0 == (selectType & CPST_FAVORITE)) cp = -1; } } } else { while (*deprecated) { while (*deprecated && (*deprecated < L'0' || *deprecated > L'9')) ++deprecated; int dp = (int)wcstol(deprecated, (wchar_t **)&deprecated, 0); if (cp == dp) { cp = -1; break; } } } } if (cp != -1) { nCodePage = cp; bDetect = true; } delete ns; } } xf_free(Buffer); } if (pSignatureFound) { *pSignatureFound = bSignatureFound; } return bDetect; }