void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time)
{
	if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
	{
		StatusIconData sid = { sizeof(sid) };
		sid.szModule = MODULENAME;
		sid.dwId = 1;
		sid.flags = MBF_TCHAR;

		switch (type)
		{
		case ICON_HIDDEN:
			{
				sid.flags |= MBF_HIDDEN;
				break;
			}
		case ICON_READ:
			{
				sid.hIcon = IcoLib_GetIcon("read_icon");
				CMString tooltip;
				if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME)
				{
					TCHAR ttime[64];
					_locale_t locale = _create_locale(LC_ALL, "");
					_tcsftime_l(ttime, _countof(ttime), _T("%X %x"), localtime(&time), locale);
					_free_locale(locale);
					tooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime);
				}
				else
				{
					tooltip = TranslateT("Last message read (unknown time)");
				}
				sid.tszTooltip = tooltip.Detach();
				break;
			}
		case ICON_UNREAD:
			{
				sid.hIcon = IcoLib_GetIcon("unread_icon");
				sid.tszTooltip = TranslateT("Last message is not read");
				break;
			}
		case ICON_FAILED:
			{
				sid.hIcon = IcoLib_GetIcon("fail_icon");
				sid.tszTooltip = TranslateT("Last message was not sent.");
				break;
			}
		case ICON_NOSENT:
			{
				sid.hIcon = IcoLib_GetIcon("nosent_icon");
				sid.tszTooltip = TranslateT("Sending...");
				break;
			}
		default:
			return;
		}

		Srmm_ModifyIcon(hContact, &sid);
	}
}
Example #2
0
// find sorted position after the last separator
int FindSortedPos(HMENU hMenu, const char* text)
{
	int pos = -1, nbItems = GetMenuItemCount(hMenu);
#ifdef _WIN32
	wchar_t widetext[4096], widebuf[4096];
	MultiByteToWideChar(CP_UTF8, 0, text, -1, widetext, 4096);
	_locale_t locale = _create_locale(LC_ALL, "");
#else
	char buf[4096] = "";
#endif
	MENUITEMINFO mi = {sizeof(MENUITEMINFO),};
	mi.fMask = MIIM_TYPE;

	for (int i=nbItems-1; i>=0 ; i--)
	{
		GetMenuItemInfo(hMenu, i, true, &mi);
		if (mi.fType == MFT_SEPARATOR)
			break;
#ifdef _WIN32
		GetMenuStringW(hMenu, i, widebuf, 4096, MF_BYPOSITION);
		if (_wcsnicoll_l(widetext, widebuf, 4096, locale) < 0) // setLocale() can break things (atof and comma as a decimal mark) so use temporary locale object
			pos = i;
#else
		GetMenuString(hMenu, i, buf, sizeof(buf), MF_BYPOSITION);
		if (strcasecmp(text, buf) < 0) // not as good as on Win OS, e.g. French "Sélectionner" vs "Supprimer"
			pos = i;
#endif
	}
#ifdef _WIN32
	_free_locale(locale);
#endif
	return pos<0 ? nbItems : pos;
}
Example #3
0
wstring s2ws(const string &s,const char *locale /*= ""*/)
{
	assert(locale);

    wstring result;

    _locale_t loc = _create_locale(LC_CTYPE,locale);  //使用指定的locale。
	//如果_create_locale返回空,返回空字符串。
    if(!loc)
    {
        return result;
    }

	const size_t len = s.size()+1;
	wchar_t *dest = new wchar_t[len];
	size_t numOfCharConverted = 0;
    errno_t err = _mbstowcs_s_l(&numOfCharConverted,dest,len,s.c_str(),_TRUNCATE,loc);
    _free_locale(loc);
    if(err == 0)
    {
        result = dest;
    }
    else if(err == STRUNCATE)
    {
		assert(!"dest buffer should be adequate");
        result = dest;
    }
    else
    {
		//转换失败。
    }
    delete []dest;
    return result;
}
Example #4
0
string ws2s(const wstring &ws,const char *locale /*= ""*/)
{
    string result;
    _locale_t loc = _create_locale(LC_CTYPE,locale);
    if(!loc)
    {
        return result;
    }
    const size_t len = ws.size()*4+1;
    char *dest = new char[len];
    size_t numOfCharConverted = 0;

    errno_t err = _wcstombs_s_l(&numOfCharConverted,dest,len,ws.c_str(),_TRUNCATE,loc);
    _free_locale(loc);
    if(err == 0)
    {
        result = dest;
    }
    else if(err == STRUNCATE)
    {
        OutputDebugStringA("UniCore ws2s 目标缓冲区不足,字符串被截断。");
        result = dest;
    }
    else
    {
        OutputDebugStringA("UniCore ws2s 转换Unicode字符串到MBCS字符串时失败。");
    }
    delete []dest;
    return result;
}
Example #5
0
/*
 * On Windows, use CP<code page number> instead of the nl_langinfo() result
 *
 * Visual Studio 2012 expanded the set of valid LC_CTYPE values, so have its
 * locale machinery determine the code page.  See comments at IsoLocaleName().
 * For other compilers, follow the locale's predictable format.
 *
 * Visual Studio 2015 should still be able to do the same, but the declaration
 * of lc_codepage is missing in _locale_t, causing this code compilation to
 * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
 * exception and post-VS2015 versions should be able to handle properly the
 * codepage number using _create_locale(). So, instead of the same logic as
 * VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short
 * locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly
 * process falls back to the pre-VS-2010 manual parsing done with
 * using <Language>_<Country>.<CodePage> as a base.
 *
 * Returns a malloc()'d string for the caller to free.
 */
static char *
win32_langinfo(const char *ctype)
{
	char	   *r = NULL;

#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
	_locale_t	loct = NULL;

	loct = _create_locale(LC_CTYPE, ctype);
	if (loct != NULL)
	{
		r = malloc(16);			/* excess */
		if (r != NULL)
			sprintf(r, "CP%u", loct->locinfo->lc_codepage);
		_free_locale(loct);
	}
#else
	char	   *codepage;

#if (_MSC_VER >= 1900)
	uint32		cp;
	WCHAR		wctype[LOCALE_NAME_MAX_LENGTH];

	memset(wctype, 0, sizeof(wctype));
	MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, LOCALE_NAME_MAX_LENGTH);

	if (GetLocaleInfoEx(wctype,
						LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
						(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
	{
		r = malloc(16);			/* excess */
		if (r != NULL)
			sprintf(r, "CP%u", cp);
	}
	else
#endif
	{
		/*
		 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
		 * example, English_United States.1252.
		 */
		codepage = strrchr(ctype, '.');
		if (codepage != NULL)
		{
			int			ln;

			codepage++;
			ln = strlen(codepage);
			r = malloc(ln + 3);
			if (r != NULL)
				sprintf(r, "CP%s", codepage);
		}

	}
#endif

	return r;
}
Example #6
0
ScCLocale::~ScCLocale()
{
#if defined(Q_WS_WIN)
	_free_locale(cLocale);
#else
  #if not defined(Q_OS_SOLARIS) and not defined(Q_OS_OPENBSD) and not defined (Q_OS_FREEBSD)
	freelocale(cLocale);
  #endif
#endif
}
Example #7
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
+   D e s t r o y C L o c a l e                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  DestroyCLocale() releases the resources allocated for a locale object
%  returned by a call to the AcquireCLocale() method.
%
%  The format of the DestroyCLocale method is:
%
%      void DestroyCLocale(void)
%
*/
static void DestroyCLocale(void)
{
#if defined(MAGICKCORE_HAVE_NEWLOCALE)
  if (c_locale != (locale_t) NULL)
    freelocale(c_locale);
#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
  if (c_locale != (locale_t) NULL)
    _free_locale(c_locale);
#endif
  c_locale=(locale_t) NULL;
}
Example #8
0
std::wstring UIniConfig::formatKey( std::wstring &key, va_list ap )
{
    //该函数返回格式化后的字符串长度,不包括0结束符。
    _locale_t loc = _create_locale(LC_ALL,"");
    const int len = _vscwprintf_p_l(key.c_str(),loc,ap)+1;
    wchar_t *buffer = new wchar_t[len];

    _vswprintf_p_l(buffer,len,key.c_str(),loc,ap);
    _free_locale(loc);

    wstring result = buffer;

    delete[] buffer;
    return result;
}
Example #9
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//endPlugin
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void endPlugin(HINSTANCE hMainInstance)
{
	if (plugin_load) plugin_shutdown(true);
	if(locale){
		_free_locale(locale);
		locale = NULL;
	}
	if(com_initialized){
		_Module.Term();
		::CoUninitialize(); 
		com_initialized = false;
	}

#ifdef _DEBUG
	//Memory leak tracking - not used in production version
	_CrtDumpMemoryLeaks();
#endif
}
Example #10
0
STDMETHODIMP CKhParser::Terminate( long* hRes )
{
    saveResults();
    if (pIXMLHTTPRequest != NULL)
        pIXMLHTTPRequest.Release();
    repl.clear();
    if (locinfo != 0) {
        _free_locale(locinfo);
        locinfo = 0;
    }
    homonyms.clear();
    currHom = -1;
    cache.clear();
    sentences.clear();
    empty.clear();
    safeArraySize = 0;
    request = L"/suddenly/?parse=";

    return S_OK;
}
Example #11
0
/*
 *	Convert Windows locale name to the ISO formatted one
 *	if possible.
 *
 *	This function returns NULL if conversion is impossible,
 *	otherwise returns the pointer to a static area which
 *	contains the iso formatted locale name.
 */
static
char *
IsoLocaleName(const char *winlocname)
{
#if (_MSC_VER >= 1400)			/* VC8.0 or later */
	static char iso_lc_messages[32];
	_locale_t	loct = NULL;

	if (pg_strcasecmp("c", winlocname) == 0 ||
		pg_strcasecmp("posix", winlocname) == 0)
	{
		strcpy(iso_lc_messages, "C");
		return iso_lc_messages;
	}

	loct = _create_locale(LC_CTYPE, winlocname);
	if (loct != NULL)
	{
		char		isolang[32],
					isocrty[32];
		LCID		lcid;

		lcid = loct->locinfo->lc_handle[LC_CTYPE];
		if (lcid == 0)
			lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
		_free_locale(loct);

		if (!GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, isolang, sizeof(isolang)))
			return NULL;
		if (!GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, isocrty, sizeof(isocrty)))
			return NULL;
		snprintf(iso_lc_messages, sizeof(iso_lc_messages) - 1, "%s_%s", isolang, isocrty);
		return iso_lc_messages;
	}
	return NULL;
#else
	return NULL;				/* Not supported on this version of msvc/mingw */
#endif   /* _MSC_VER >= 1400 */
}
Example #12
0
/*
 * On Windows, use CP<code page number> instead of the nl_langinfo() result
 *
 * Visual Studio 2012 expanded the set of valid LC_CTYPE values, so have its
 * locale machinery determine the code page.  See comments at IsoLocaleName().
 * For other compilers, follow the locale's predictable format.
 *
 * Returns a malloc()'d string for the caller to free.
 */
static char *
win32_langinfo(const char *ctype)
{
	char	   *r = NULL;

#if (_MSC_VER >= 1700)
	_locale_t	loct = NULL;

	loct = _create_locale(LC_CTYPE, ctype);
	if (loct != NULL)
	{
		r = malloc(16);			/* excess */
		if (r != NULL)
			sprintf(r, "CP%u", loct->locinfo->lc_codepage);
		_free_locale(loct);
	}
#else
	char	   *codepage;

	/*
	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
	 * example, English_United States.1252.
	 */
	codepage = strrchr(ctype, '.');
	if (codepage != NULL)
	{
		int			ln;

		codepage++;
		ln = strlen(codepage);
		r = malloc(ln + 3);
		if (r != NULL)
			sprintf(r, "CP%s", codepage);
	}
#endif

	return r;
}
Example #13
0
void LCD_UpdateThread(void* Control)
{
	CMPC_Lcd* ctrl = static_cast<CMPC_Lcd*>(Control);
	wchar_t str[40];
	__time64_t ltime;
	__time64_t otime = 0;
	struct tm thetime;
	_locale_t locale = _create_locale(LC_TIME, "");

	while (ctrl->Thread_Loop) {
		EnterCriticalSection(&ctrl->cs);
		if (_time64(&ltime) != otime) { // Retrieve the time
			otime = ltime;
			_localtime64_s(&thetime, &ltime);

			// Format the current time structure into a string
			// using %#x is the long date representation,
			// appropriate to the current locale
			if (_wcsftime_l(str, _countof(str), _T("%#x"), (const struct tm*)&thetime, locale) &&
			(ltime > ctrl->nThread_tTimeout || ltime < otime)) { // message displayed, no update until timeout
				ctrl->m_MonoPage.m_Text[0].SetText(str);
				ctrl->m_ColorPage.m_Text[0].SetText(str);
			}

			if (_wcsftime_l(str, _countof(str), _T("%X"), (const struct tm*)&thetime, locale)) {
				ctrl->m_MonoPage.m_Text[1].SetText(str);
				ctrl->m_ColorPage.m_Text[1].SetText(str);
			}
		}
		ctrl->m_Connection.Update();
		LeaveCriticalSection(&ctrl->cs);
		Sleep(LCD_UPD_TIMER);
	}

	_free_locale(locale);
	_endthread();
}
Example #14
0
void ModelicaStrings_scanReal(_In_z_ const char* string, int startIndex,
                              int unsignedNumber, _Out_ int* nextIndex,
                              _Out_ double* number) {
    /*
    Grammar of real number:

    real ::= [sign] unsigned [fraction] [exponent]
    sign ::= '+' | '-'
    unsigned ::= digit [unsigned]
    fraction ::= '.' [unsigned]
    exponent ::= ('e' | 'E') [sign] unsigned
    digit ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
    */

    int len = 0;
    /* Temporary variable for the length of a matched unsigned number. */

    int total_length = 0;
    /* Total number of characters recognized as part of a decimal number. */

    int token_start = ModelicaStrings_skipWhiteSpace(string, startIndex);
    /* Index of first char of token, after ws. */

    int exp_len = 0;
    /* Total number of characters recognized as part of the non-numeric parts
     * of exponent (the 'e' and the sign). */

    /* Scan sign of decimal number */

    if (string[token_start-1] == '+' || string[token_start-1] == '-') {
        total_length = 1;
        if (unsignedNumber == 1) {
            goto Modelica_ERROR;
        }
    }

    /* Scan integer part of mantissa. */

    len = MatchUnsignedInteger(string, token_start + total_length);
    total_length += len;

    /* Scan decimal part of mantissa. */

    if (string[token_start + total_length-1] == '.') {
        total_length += 1;
        len = MatchUnsignedInteger(string, token_start + total_length);
        if (len > 0) {
            total_length += len;
        }
    }

    /* Scan exponent part of mantissa. */

    if (string[token_start + total_length-1] == 'e' || string[token_start + total_length-1] == 'E') {
        /* total_length += 1; */
        exp_len = 1;

        if (string[token_start + total_length] == '+' || string[token_start + total_length] == '-') {
            exp_len += 1;
        }
        len = MatchUnsignedInteger(string, token_start + total_length + exp_len);
        if (len == 0) {
            goto Modelica_ERROR;
        }
        total_length += exp_len + len;
    }

    /* Convert accumulated characters into a number. */

    if (total_length > 0 && total_length < MAX_TOKEN_SIZE) {
#if defined(NO_LOCALE)
        const char* const dec = ".";
#elif defined(_MSC_VER) && _MSC_VER >= 1400
        _locale_t loc = _create_locale(LC_NUMERIC, "C");
#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3)
        locale_t loc = newlocale(LC_NUMERIC, "C", NULL);
#else
        char* dec = localeconv()->decimal_point;
#endif
        char buf[MAX_TOKEN_SIZE+1];
        /* Buffer for copying the part recognized as the number for passing to strtod(). */
        char* endptr;
        /* For error checking of strtod(). */
        double x;
        /* For receiving the result. */

        strncpy(buf, string+token_start-1, (size_t)total_length);
        buf[total_length] = '\0';
#if !defined(NO_LOCALE) && (defined(_MSC_VER) && _MSC_VER >= 1400)
        x = _strtod_l(buf, &endptr, loc);
        _free_locale(loc);
#elif !defined(NO_LOCALE) && (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3))
        x = strtod_l(buf, &endptr, loc);
        freelocale(loc);
#else
        if (*dec == '.') {
            x = strtod(buf, &endptr);
        }
        else if (NULL == strchr(buf, '.')) {
            x = strtod(buf, &endptr);
        }
        else {
            char* p = strchr(buf, '.');
            *p = *dec;
            x = strtod(buf, &endptr);
        }
#endif
        if (*endptr == 0) {
            *number = x;
            *nextIndex = token_start + total_length;
            return;
        }
    }

    /* Token missing or cannot be converted to result type. */

Modelica_ERROR:
    *nextIndex = startIndex;
    *number = 0;
    return;
}
Example #15
0
/**
 * Composes a string with a format string (like printf) in the buffer pointed
 * by buf (taking buf_size as the maximum buffer capacity to fill).
 * If the resulting string would be longer than n - 1 characters, the remaining
 * characters are discarded and not stored, but counted for the value returned
 * by the function.
 * A terminating NUL character is automatically appended after the content
 * written.
 * Internally, the function retrieves arguments from the list identified by
 * args as if va_arg was used on it, and thus the state of args is likely to
 * be altered by the call.
 * In any case, arg should have been initialized by va_start at some point
 * before the call, and it is expected to be released by va_end at some point
 * after the call.
 *
 * This version ignores the current locale and uses the locale "C" for Linux,
 * FreeBSD, OSX and Android.
 *
 * @param buf Pointer to a buffer where the resulting C string is stored.
 * @param buf_size Maximum number of bytes to be used in the buffer. The
 *        generated string has a length of at most buf_size - 1, leaving space
 *        for the additional terminating NUL character.
 * @param format C string that contains a format string (see printf).
 * @param args A value identifying a variable arguments list initialized with
 *        va_start.
 *
 * @return On success, the number of characters that would have been written if
 *         buf_size had been sufficiently large, not counting the terminating
 *         NUL character. On failure, a negative number is returned.
 *         Notice that only when this returned value is non-negative and less
 *         than buf_size, the string has been completely written.
 *
 * @since 0.6.0
 */
SR_API int sr_vsnprintf_ascii(char *buf, size_t buf_size,
	const char *format, va_list args)
{
#if defined(_WIN32)
	int ret;

#if 0
	/*
	 * TODO: This part compiles with mingw-w64 but doesn't run with Win7.
	 *       Doesn't start because of "Procedure entry point _create_locale
	 *       not found in msvcrt.dll".
	 *       mingw-w64 should link to msvcr100.dll not msvcrt.dll!.
	 * See: https://msdn.microsoft.com/en-us/en-en/library/1kt27hek.aspx
	 */
	_locale_t locale;

	locale = _create_locale(LC_NUMERIC, "C");
	ret = _vsnprintf_l(buf, buf_size, format, locale, args);
	_free_locale(locale);
#endif

	/* vsprintf uses the current locale, may cause issues for floats. */
	ret = vsnprintf(buf, buf_size, format, args);

	return ret;
#elif defined(__APPLE__)
	/*
	 * See:
	 * https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/printf_l.3.html
	 * https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/xlocale.3.html
	 */
	int ret;
	locale_t locale;

	locale = newlocale(LC_NUMERIC_MASK, "C", NULL);
	ret = vsnprintf_l(buf, buf_size, locale, format, args);
	freelocale(locale);

	return ret;
#elif defined(__FreeBSD__) && __FreeBSD_version >= 901000
	/*
	 * See:
	 * https://www.freebsd.org/cgi/man.cgi?query=printf_l&apropos=0&sektion=3&manpath=FreeBSD+9.1-RELEASE
	 * https://www.freebsd.org/cgi/man.cgi?query=xlocale&apropos=0&sektion=3&manpath=FreeBSD+9.1-RELEASE
	 */
	int ret;
	locale_t locale;

	locale = newlocale(LC_NUMERIC_MASK, "C", NULL);
	ret = vsnprintf_l(buf, buf_size, locale, format, args);
	freelocale(locale);

	return ret;
#elif defined(__ANDROID__)
	/*
	 * The Bionic libc only has two locales ("C" aka "POSIX" and "C.UTF-8"
	 * aka "en_US.UTF-8"). The decimal point is hard coded as ".".
	 * See: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/locale.cpp
	 */
	int ret;

	ret = vsnprintf(buf, buf_size, format, args);

	return ret;
#elif defined(__linux__)
	int ret;
	locale_t old_locale, temp_locale;

	/* Switch to C locale for proper float/double conversion. */
	temp_locale = newlocale(LC_NUMERIC, "C", NULL);
	old_locale = uselocale(temp_locale);

	ret = vsnprintf(buf, buf_size, format, args);

	/* Switch back to original locale. */
	uselocale(old_locale);
	freelocale(temp_locale);

	return ret;
#elif defined(__unix__) || defined(__unix)
	/*
	 * This is a fallback for all other BSDs, *nix and FreeBSD <= 9.0, by
	 * using the current locale for snprintf(). This may not work correctly
	 * for floats!
	 */
	int ret;

	ret = vsnprintf(buf, buf_size, format, args);

	return ret;
#else
	/* No implementation for unknown systems! */
	return -1;
#endif
}
Example #16
0
int wmain(int argc, const wchar_t* argv[])
{
    try
    {
        if (argc < 2)
        {
            DisplayAboutMessage(NULL);
            DisplayResource(NULL, IDR_TEXT);
            return 1;
        }

        _locale_t l = _create_locale(LC_ALL, "C");

        FileInfo fileInfo(argv[1]);
        std::vector<wchar_t> chars;
        if (fileInfo.exists)
            chars = fileInfo.load(l);

        HWND hWnd = GetConsoleWindow();
        HICON hIcon = (HICON) SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
        SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON)));

        const Screen screenOrig;
        AutoRestoreBufferInfo arbi(screenOrig.hOut);
        AutoRestoreMode armIn(screenOrig.hIn, ENABLE_EXTENDED_FLAGS | ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT, 0xFFFF);
        AutoRestoreMode armOut(screenOrig.hOut, 0, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);

        Screen screen(screenOrig);
        screen.hOut = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CONSOLE_TEXTMODE_BUFFER, nullptr);

        HKEY hKey = NULL;
        RegOpenKey(HKEY_CURRENT_USER, L"SOFTWARE\\RadSoft\\ConEdit", &hKey);

        CONSOLE_SCREEN_BUFFER_INFOEX csbi = arbi.get();
        csbi.dwSize = GetSize(screen.csbi.srWindow);
        EditScheme scheme(hKey, csbi);

        csbi.wAttributes = 0;
        scheme.get(EditScheme::DEFAULT).apply(csbi.wAttributes);
        SetConsoleScreenBufferInfoEx(screen.hOut, &csbi);

        AutoRestoreActiveScreenBuffer arasb(screenOrig.hOut, screen.hOut);

        ModeConEdit mce(hKey, fileInfo, GetSize(screen.csbi.srWindow), chars, l);

        RegCloseKey(hKey);
        hKey = NULL;

        DoMode(mce, screen, scheme);

        SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIcon);

        _free_locale(l);

        return 0;
    }
    catch (const std::exception& e)
    {
        printf(e.what());
        printf("\n");
        return 1;
    }
}
Example #17
0
void CommClose(PComVar cv)
{
	if ( ! cv->Open ) {
		return;
	}
	cv->Open = FALSE;

	/* disable event message posting & flush buffer */
	cv->RRQ = FALSE;
	cv->Ready = FALSE;
	cv->InPtr = 0;
	cv->InBuffCount = 0;
	cv->OutPtr = 0;
	cv->OutBuffCount = 0;
	cv->LineModeBuffCount = 0;
	cv->FlushLen = 0;
	cv->Flush = FALSE;

	/* close port & release resources */
	switch (cv->PortType) {
		case IdTCPIP:
			if (HAsync!=0) {
				PWSACancelAsyncRequest(HAsync);
			}
			HAsync = 0;
#ifndef NO_INET6
			Pfreeaddrinfo(cv->res0);
#endif /* NO_INET6 */
			if ( cv->s!=INVALID_SOCKET ) {
				Pclosesocket(cv->s);
			}
			cv->s = INVALID_SOCKET;
			TTXCloseTCP(); /* TTPLUG */
			FreeWinsock();
			break;
		case IdSerial:
			if ( cv->ComID != INVALID_HANDLE_VALUE ) {
				CloseHandle(ReadEnd);
				CloseHandle(wol.hEvent);
				CloseHandle(rol.hEvent);
				PurgeComm(cv->ComID, PURGE_TXABORT | PURGE_RXABORT |
				                     PURGE_TXCLEAR | PURGE_RXCLEAR);
				EscapeCommFunction(cv->ComID,CLRDTR);
				SetCommMask(cv->ComID,0);
				PCloseFile(cv->ComID);
				ClearCOMFlag(cv->ComPort);
			}
			TTXCloseFile(); /* TTPLUG */
			break;
		case IdFile:
			if (cv->ComID != INVALID_HANDLE_VALUE) {
				PCloseFile(cv->ComID);
			}
			TTXCloseFile(); /* TTPLUG */
			break;

		case IdNamedPipe:
			if ( cv->ComID != INVALID_HANDLE_VALUE ) {
				CloseHandle(ReadEnd);
				CloseHandle(wol.hEvent);
				CloseHandle(rol.hEvent);
				PCloseFile(cv->ComID);
			}
			TTXCloseFile(); /* TTPLUG */
			break;
	}
	cv->ComID = INVALID_HANDLE_VALUE;
	cv->PortType = 0;

	_free_locale(cv->locale);
}
Example #18
0
char *nl_langinfo(nl_item item)
{
    char *l, *p;
    _locale_t lt; 
  
    //if (item != DEF_CODESET)
    //    return NULL;
    //p = local_charset();
    p = setlocale(LC_ALL, "");
    //p = setlocale(LC_ALL, NULL);
    if (p) {
        printf("setlocal: %s\n", p);
    }

    lt = _get_current_locale();
    if (lt) {
        int loci = (int)lt->locinfo;
        //const char *ccp = get_name_from_clid(loci);
        //const char *ccp2 = get_name_from_clid(item);
        //SPRTF("Got locinfo %d (0x%08X) %s\n", loci, loci, (ccp2 ? ccp2 : "no value"));
        _free_locale(lt);
    }
    if (((l = getenv("LC_ALL"))   && *l) ||
        ((l = getenv("LC_CTYPE")) && *l) ||
        ((l = getenv("LANG"))     && *l)) 
    {
        /* check standardized locales */
        if (!strcmp(l, "C") || !strcmp(l, "POSIX"))
            return C_CODESET;

        /* check for encoding name fragment */
        if (strstr(l, "UTF") || strstr(l, "utf"))
            return "UTF-8";

        if ((p = strstr(l, "8859-"))) 
        {
            memcpy(buf, "ISO-8859-\0\0", 12);
            p += 5;
            if (digit(*p)) 
            {
                buf[9] = *p++;
                if (digit(*p)) 
                    buf[10] = *p++;
                return buf;
            }
        }

        if (strstr(l, "KOI8-R")) 
            return "KOI8-R";

        if (strstr(l, "KOI8-U"))
            return "KOI8-U";

        if (strstr(l, "620")) 
            return "TIS-620";

        if (strstr(l, "2312")) 
            return "GB2312";

        if (strstr(l, "HKSCS")) 
            return "Big5HKSCS";   /* no MIME charset */

        if (strstr(l, "Big5") || strstr(l, "BIG5"))
            return "Big5";

        if (strstr(l, "GBK"))
            return "GBK";           /* no MIME charset */

        if (strstr(l, "18030"))
            return "GB18030";     /* no MIME charset */

        if (strstr(l, "Shift_JIS") || strstr(l, "SJIS"))
            return "Shift_JIS";

        /* check for conclusive modifier */
        if (strstr(l, "euro")) 
            return "ISO-8859-15";

        /* check for language (and perhaps country) codes */
        if (strstr(l, "zh_TW")) 
            return "Big5";

        if (strstr(l, "zh_HK"))
            return "Big5HKSCS";   /* no MIME charset */

        if (strstr(l, "zh"))
            return "GB2312";

        if (strstr(l, "ja"))
            return "EUC-JP";

        if (strstr(l, "ko"))
            return "EUC-KR";

        if (strstr(l, "ru"))
            return "KOI8-R";

        if (strstr(l, "uk"))
            return "KOI8-U";

        if (strstr(l, "pl") || strstr(l, "hr") ||
	        strstr(l, "hu") || strstr(l, "cs") ||
            strstr(l, "sk") || strstr(l, "sl"))
            return "ISO-8859-2";

        if (strstr(l, "eo") || strstr(l, "mt"))
            return "ISO-8859-3";

        if (strstr(l, "el"))
            return "ISO-8859-7";

        if (strstr(l, "he"))
            return "ISO-8859-8";

        if (strstr(l, "tr"))
            return "ISO-8859-9";

        if (strstr(l, "th"))
            return "TIS-620";      /* or ISO-8859-11 */

        if (strstr(l, "lt"))
            return "ISO-8859-13";

        if (strstr(l, "cy"))
            return "ISO-8859-14";

        if (strstr(l, "ro"))
            return "ISO-8859-2";   /* or ISO-8859-16 */

        if (strstr(l, "am") || strstr(l, "vi"))
            return "UTF-8";

        /* Send me further rules if you like, but don't forget that we are
         * *only* interested in locale naming conventions on platforms
         * that do not already provide an nl_langinfo(CODESET) implementation. */
        //return "ISO-8859-1"; /* should perhaps be "UTF-8" instead */
        //return "UTF-8"; /* have set default return as "UTF-8"!!! */
    }
    return C_CODESET;
}
Example #19
0
void ModelicaStrings_scanInteger(_In_z_ const char* string,
                                 int startIndex, int unsignedNumber,
                                 _Out_ int* nextIndex, _Out_ int* integerNumber) {
    int sign = 0;
    /* Number of characters used for sign. */

    int token_start = ModelicaStrings_skipWhiteSpace(string, startIndex);
    /* Index of first char of token, after ws. */

    if (string[token_start-1] == '+' || string[token_start-1] == '-') {
        sign = 1;
    }

    if (unsignedNumber==0 || (unsignedNumber==1 && sign==0)) {
        int number_length = MatchUnsignedInteger(string, token_start + sign);
        /* Number of characters in unsigned number. */

        if (number_length > 0 && sign + number_length < MAX_TOKEN_SIZE) {
            /* check if the scanned string is no Real number */
            int next = token_start + sign + number_length - 1;
            if ( string[next] == '\0' ||
                (string[next] != '.'  && string[next] != 'e'
                                      && string[next] != 'E') ) {
#if defined(NO_LOCALE)
#elif defined(_MSC_VER) && _MSC_VER >= 1400
                _locale_t loc = _create_locale(LC_NUMERIC, "C");
#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3)
                locale_t loc = newlocale(LC_NUMERIC, "C", NULL);
#endif
                char buf[MAX_TOKEN_SIZE+1];
                /* Buffer for copying the part recognized as the number for passing to strtol(). */
                char* endptr;
                /* For error checking of strtol(). */
                int x;
                /* For receiving the result. */

                strncpy(buf, string+token_start-1, (size_t)(sign + number_length));
                buf[sign + number_length] = '\0';
#if !defined(NO_LOCALE) && (defined(_MSC_VER) && _MSC_VER >= 1400)
                x = (int)_strtol_l(buf, &endptr, 10, loc);
                _free_locale(loc);
#elif !defined(NO_LOCALE) && (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3))
                x = (int)strtol_l(buf, &endptr, 10, loc);
                freelocale(loc);
#else
                x = (int)strtol(buf, &endptr, 10);
#endif
                if (*endptr == 0) {
                    *integerNumber = x;
                    *nextIndex = token_start + sign + number_length;
                    return;
                }
            }
        }
    }

    /* Token missing or cannot be converted to result type. */
    *nextIndex     = startIndex;
    *integerNumber = 0;
    return;
}
Example #20
0
void wxXLocale::Free()
{
    if ( m_locale )
        _free_locale(m_locale);
}
Example #21
0
void hpdf_doc::add_text(et_datachunk &dc)
{
	et_type datatype = dc.type;
	wstring &out_string = dc.w_string;

	char *line = new char[4096];
	memset(line, 0, 4096);
	_locale_t loceng;
	size_t size = 0;

	loceng = _create_locale(LC_ALL, "en-US");

	int len = out_string.length(); // count of space
	int n_TX = (et_cp.TX > 0) ? et_cp.TX : et_cp.T,
		n_TY = (et_cp.TY > 0) ? et_cp.TY : et_cp.T;

	HPDF_REAL f_xpos = dc.rect.left, f_ypos = dc.rect.bottom;
	HPDF_REAL f_advance = 0.0;
	HPDF_REAL f_width = MMTEXT2PTX(et_cp.W * n_TX / 2);
	HPDF_REAL f_gap = MMTEXT2PTX(et_cp.X/2);
	HPDF_REAL f_space = MMTEXT2PTY((et_cp.Z * n_TY) + et_cp.L);

	HPDF_Page_BeginText(h_current_page);

	select_datatype_font(datatype);

	f_space = HPDF_Page_GetCurrentFontSize(h_current_page);

	if (f_space > f_linespace)
		f_linespace = f_space;


	switch (datatype) {
	case ET_LATAN:
		
		/*
		size = _wcstombs_l(line, out_string.c_str(), 4096, loceng);
		if (size == 0) goto END_PROC;

		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		f_advance = HPDF_Page_TextWidth(h_current_page, line); 
		*/
		if (et_cp.CorE == 'C') f_width = f_width * 2;
		text_out_eng(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space, loceng);
		break;
	case ET_SPACE:
		f_advance += ((f_width + f_gap) * len);
		break;

	case ET_CJK:
	case ET_CJKFORM:
	case ET_BOXDRAW:

		if (et_cp.VorH == 'H' || datatype != ET_CJK)
			horizontal(f_xpos, f_ypos);
		else
			vertical(f_xpos, f_ypos);

		if (datatype == ET_BOXDRAW) resize_font_boxdraw();
		/*
		size = wchar_to_utf8(out_string.c_str(), out_string.length(), line, 4096, NULL);
		if (size == 0) goto END_PROC;
		
		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		//if (datatype == ET_BOXDRAW)
		//	f_advance += (len * ((f_width + f_gap) * 2));
		//else
			f_advance += HPDF_Page_TextWidth(h_current_page, line); //(len * ((f_width + f_gap) * 2));
			*/
		text_out_cjk(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space);

		break;
	}
	HPDF_Page_EndText(h_current_page);
	
	if (et_cp.U > 0)
	{
		HPDF_Page_SetLineWidth(h_current_page, 0.5);
		HPDF_Page_MoveTo(h_current_page, f_xpos, f_ypos - f_linespace);
		HPDF_Page_LineTo(h_current_page, f_xpos, f_ypos);
		HPDF_Page_Stroke(h_current_page);
	}
	
	f_xpos += f_advance;

	delete [] line; // free buffer

	_free_locale(loceng);
}
Example #22
0
/*
 * Convert a Windows setlocale() argument to a Unix-style one.
 *
 * Regardless of platform, we install message catalogs under a Unix-style
 * LL[_CC][.ENCODING][@VARIANT] naming convention.	Only LC_MESSAGES settings
 * following that style will elicit localized interface strings.
 *
 * Before Visual Studio 2012 (msvcr110.dll), Windows setlocale() accepted "C"
 * (but not "c") and strings of the form <Language>[_<Country>][.<CodePage>],
 * case-insensitive.  setlocale() returns the fully-qualified form; for
 * example, setlocale("thaI") returns "Thai_Thailand.874".	Internally,
 * setlocale() and _create_locale() select a "locale identifier"[1] and store
 * it in an undocumented _locale_t field.  From that LCID, we can retrieve the
 * ISO 639 language and the ISO 3166 country.  Character encoding does not
 * matter, because the server and client encodings govern that.
 *
 * Windows Vista introduced the "locale name" concept[2], closely following
 * RFC 4646.  Locale identifiers are now deprecated.  Starting with Visual
 * Studio 2012, setlocale() accepts locale names in addition to the strings it
 * accepted historically.  It does not standardize them; setlocale("Th-tH")
 * returns "Th-tH".  setlocale(category, "") still returns a traditional
 * string.	Furthermore, msvcr110.dll changed the undocumented _locale_t
 * content to carry locale names instead of locale identifiers.
 *
 * MinGW headers declare _create_locale(), but msvcrt.dll lacks that symbol.
 * IsoLocaleName() always fails in a MinGW-built postgres.exe, so only
 * Unix-style values of the lc_messages GUC can elicit localized messages.	In
 * particular, every lc_messages setting that initdb can select automatically
 * will yield only C-locale messages.  XXX This could be fixed by running the
 * fully-qualified locale name through a lookup table.
 *
 * This function returns a pointer to a static buffer bearing the converted
 * name or NULL if conversion fails.
 *
 * [1] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373763.aspx
 * [2] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373814.aspx
 */
static char *
IsoLocaleName(const char *winlocname)
{
#if (_MSC_VER >= 1400)			/* VC8.0 or later */
	static char iso_lc_messages[32];
	_locale_t	loct = NULL;

	if (pg_strcasecmp("c", winlocname) == 0 ||
		pg_strcasecmp("posix", winlocname) == 0)
	{
		strcpy(iso_lc_messages, "C");
		return iso_lc_messages;
	}

	loct = _create_locale(LC_CTYPE, winlocname);
	if (loct != NULL)
	{
#if (_MSC_VER >= 1700)			/* Visual Studio 2012 or later */
		size_t		rc;
		char	   *hyphen;

		/* Locale names use only ASCII, any conversion locale suffices. */
		rc = wchar2char(iso_lc_messages, loct->locinfo->locale_name[LC_CTYPE],
						sizeof(iso_lc_messages), NULL);
		_free_locale(loct);
		if (rc == -1 || rc == sizeof(iso_lc_messages))
			return NULL;

		/*
		 * Since the message catalogs sit on a case-insensitive filesystem, we
		 * need not standardize letter case here.  So long as we do not ship
		 * message catalogs for which it would matter, we also need not
		 * translate the script/variant portion, e.g. uz-Cyrl-UZ to
		 * uz_UZ@cyrillic.	Simply replace the hyphen with an underscore.
		 *
		 * Note that the locale name can be less-specific than the value we
		 * would derive under earlier Visual Studio releases.  For example,
		 * French_France.1252 yields just "fr".  This does not affect any of
		 * the country-specific message catalogs available as of this writing
		 * (pt_BR, zh_CN, zh_TW).
		 */
		hyphen = strchr(iso_lc_messages, '-');
		if (hyphen)
			*hyphen = '_';
#else
		char		isolang[32],
					isocrty[32];
		LCID		lcid;

		lcid = loct->locinfo->lc_handle[LC_CTYPE];
		if (lcid == 0)
			lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
		_free_locale(loct);

		if (!GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, isolang, sizeof(isolang)))
			return NULL;
		if (!GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, isocrty, sizeof(isocrty)))
			return NULL;
		snprintf(iso_lc_messages, sizeof(iso_lc_messages) - 1, "%s_%s", isolang, isocrty);
#endif
		return iso_lc_messages;
	}
	return NULL;
#else
	return NULL;				/* Not supported on this version of msvc/mingw */
#endif   /* _MSC_VER >= 1400 */
}
Example #23
0
 ~string_to_double()
 {
     _free_locale(locale_);
 }