Пример #1
0
static BOOL CALLBACK sDumpWindow(HWND hwnd, LPARAM lParam) {
	String dump;
	dump << (IsWindowEnabled(hwnd) ? "ena" : "dis") << ' '
	     << (IsWindowVisible(hwnd) ? "vis" : "hid") << ' '
	     << Sprintf("owner=0x%x ", GetWindow(hwnd, GW_OWNER));
	Ctrl *ctrl = Ctrl::CtrlFromHWND(hwnd);
	if(ctrl) {
#ifdef _DEBUG
		dump << "Ctrl: " << UPP::Name(ctrl);
#endif
	}
	else if(!lParam)
		return TRUE;
	else
	{
#ifdef PLATFORM_WINCE
		wchar clsname[256], title[1024];
#else
		char clsname[256], title[1024];
#endif
		::GetClassName(hwnd, clsname, __countof(clsname));
		::GetWindowText(hwnd, title, __countof(title));
		dump << "HWND: " << Sprintf("0x%x", hwnd) << ", class = "
		     << clsname << ", title = " << title;
	}
	LLOG(dump);
	return TRUE;
}
Пример #2
0
unsigned GetVMPipeNameW(unsigned PID, wchar_t *pName, size_t MaxNameLength, bool TryReconstructingIfNotAvailable)
{
	if (!pName || !PID)
		return 0;
	pName[0] = 0;

	TCHAR tszMappingName[MAX_PATH];
	_sntprintf_s(tszMappingName, __countof(tszMappingName), _TRUNCATE, tszMappingNameFormat, PID);
	//HANDLE hMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READONLY, 0, sizeof(KdClientStatus), tszMappingName);
	HANDLE hMapping = OpenFileMapping(FILE_MAP_READ, FALSE, tszMappingName);
	bool bOldVersion = false;
	KdClientStatus *pStatus = (KdClientStatus *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, sizeof(KdClientStatus));
	if (!pStatus)
	{
		bOldVersion = true;
		pStatus = (KdClientStatus *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
	}
	BazisLib::DateTime startTime = BazisLib::DateTime::Now();
	if ((hMapping == INVALID_HANDLE_VALUE) || !pStatus)
	{
		if (hMapping != INVALID_HANDLE_VALUE)
			CloseHandle(hMapping);
		if (!TryReconstructingIfNotAvailable)
			return 0;
		
		TCHAR tszSession[MAX_PATH] = {0,};
		GetVMSessionNameW(PID, tszSession, __countof(tszSession));
		if (!tszSession[0])
			return 0;
		unsigned len = _snwprintf(pName, MaxNameLength, L"\\\\.\\pipe\\kd_%s", tszSession);
		for (int i = 0; pName[i]; i++)
			if (pName[i] == ' ')
				pName[i] = '_';
		return len;
	}
	unsigned len = (unsigned)wcslen(pStatus->PipeName);
	wcsncpy_s(pName, MaxNameLength, pStatus->PipeName, _TRUNCATE);

	if ((bOldVersion || (pStatus->HostSideDLLVersion != VIRTUALKD_VER_INT)) && !s_bUserWarnedAboutVersion)
	{
		unsigned oldVersion = 0, newVersion = VIRTUALKD_VER_INT;
		if (pStatus)
			oldVersion = pStatus->HostSideDLLVersion;

		oldVersion >>= 16;
		newVersion >>= 16;

		s_bUserWarnedAboutVersion = true;
		MessageBox(0, 
			BazisLib::String::sFormat(_T("One of the virtual machines has an old version of KDCLIENT.DLL/VBOXDD.DLL loaded (%d.%d.%d expected, %d.%d.%d found). Please install the latest file versions, as described on VirtualKD website, and restart your virtual machines."),
			(oldVersion >> 12) & 0x0F,
			(oldVersion >> 8) & 0x0F,
			(oldVersion >> 4) & 0x0F,
			(newVersion >> 12) & 0x0F,
			(newVersion >> 8) & 0x0F,
			(newVersion >> 4) & 0x0F).c_str(),
			_T("VirtualKD"),
			MB_ICONWARNING | MB_TASKMODAL);
	}
Пример #3
0
String GetLocaleInfoA(LCID lcid, LCTYPE lctype)
{
	if(IsWinNT()) {
		wchar cbuf[1000];
		UnicodeWin32().GetLocaleInfoW(lcid, lctype, cbuf, __countof(cbuf));
		return FromSystemCharsetW(cbuf);
	}
	else {
		char cbuf[1000];
		::GetLocaleInfoA(lcid, lctype, cbuf, __countof(cbuf));
		return FromSystemCharset(cbuf);
	}
}
Пример #4
0
void InitializeRpcDispatcher()
{
#ifndef KDVMWARE_USE_PROXY
	wchar_t wszPipeName[MAX_PATH] = {0,};
	if (!VBoxCmdLineToPipeNameW(wszPipeName, __countof(wszPipeName)))
		return;
	ASSERT(g_pReporter);
	wcsncpy(g_pReporter->GetStatusPointer()->PipeName, wszPipeName, __countof(g_pReporter->GetStatusPointer()->PipeName));
#else
	wcsncpy(g_pReporter->GetStatusPointer()->PipeName, L"\\\\.\\pipe\\kdvmware_proxypipe", __countof(g_pReporter->GetStatusPointer()->PipeName));
#endif
	s_pClient = new KdRpcDispatcher(new KdComDispatcher(wszPipeName));
	g_pReporter->GetStatusPointer()->PatchErrorPlus1 = 1;
}
Пример #5
0
WString GetLocaleInfoW(LCID lcid, LCTYPE lctype)
{
	union {
		wchar wbuf[1000];
		char abuf[1000];
	};
	Zero(wbuf);
	if(::GetLocaleInfoW(lcid, lctype, (WCHAR *)wbuf, __countof(wbuf)))
		return wbuf;
#ifdef PLATFORM_WINCE
	return Null;
#else
	::GetLocaleInfoA(lcid, lctype, abuf, __countof(abuf));
	return ToUnicode(abuf, CHARSET_DEFAULT);
#endif
}
Пример #6
0
void KdComDispatcher::KdpSendControlPacket(ULONG PacketType, ULONG NextPacketId)
{
	static char __unused[sizeof(KD_PACKET_HEADER) == 16];
	static unsigned LastSentID = 0;
	KD_PACKET_HEADER hdr;
	hdr.Signature = 'iiii';
	hdr.PacketType = (USHORT)PacketType;
	hdr.TotalDataLength = 0;
	if (NextPacketId)
		hdr.PacketID = LastSentID = NextPacketId;
	else
		hdr.PacketID = LastSentID;
	hdr.Checksum = 0;
	if (KdTraceEnabled && (g_pReporter->GetStatusPointer()->DebugLevel >= DebugLevelTraceKdCom))
	{
			TCHAR tsz[512];
			_sntprintf(tsz, __countof(tsz), _T("Sending control packet (type = %d, id = %08X)... "),
					hdr.PacketType,
					hdr.PacketID);
			g_pReporter->LogLineIfEnabled(tsz);
	}
	m_Pipe.Send(&hdr, sizeof(hdr));
	if (KdTraceEnabled && (g_pReporter->GetStatusPointer()->DebugLevel >= DebugLevelTraceKdCom))
	{
		g_pReporter->LogLineIfEnabled(_T("ok\r\n"));
	}
}
Пример #7
0
String RichPara::Format::ToString() const
{
	String out;
	if(!UPP::IsNull(label))
		out << "label <" << label << ">: ";
	out
	<< align << ", left " << lm << ", right " << rm
	<< ", indent " << indent << ", before " << before << ", after " << after
	<< ", tabsize " << tabsize << ", bullet " << bullet
	<< (newpage  ? ", newpage" : "")
	<< (keep     ? ", keep" : "")
	<< (keepnext ? ", keepnext" : "")
	<< (orphan   ? ", orphan" : "");
	int i;
	for(i = 0; i < tab.GetCount(); i++)
		out << (i ? "\n" : ", ")
		<< "tab[" << i << "] = " << tab[i].pos << ", align " << tab[i].align
		<< ", fill " << FormatIntHex(tab[i].fillchar, 2);
	out << "\n";
	out << "before_number " << before_number << ", after_number " << after_number
	<< (reset_number ? ", reset_number" : "");
	for(i = 0; i < __countof(number); i++)
		if(number[i] != RichPara::NUMBER_NONE)
			out << " num[" << i << "] = " << (int)number[i];
	out << "\n";
	return out;
}
Пример #8
0
void RTFParser::ReadCharSet()
{
	if(PassQ("ansi")) {}
	else if(PassQ("mac")) {}
	else if(PassQ("pc")) {}
	else if(PassQ("pca")) {}
	else if(PassQ("ansicpg")) {
		static const struct {
			int  ansicpg;
			byte charset;
		}
		charsets[] =
		{
			{ 1250, CHARSET_WIN1250 },
			{ 1251, CHARSET_WIN1251 },
			{ 1252, CHARSET_WIN1252 },
			{ 1253, CHARSET_WIN1253 },
			{ 1254, CHARSET_WIN1254 },
			{ 1255, CHARSET_WIN1255 },
			{ 1256, CHARSET_WIN1256 },
			{ 1257, CHARSET_WIN1257 },
		};
		for(int c = 0; c < __countof(charsets); c++)
			if(charsets[c].ansicpg == command_arg) {
				default_charset = state.charset = charsets[c].charset;
				break;
			}
	}
}
Пример #9
0
CAviFile:: CAviFile(const wchar_t* lpszFileName /* =_T("Output.avi") */, 
			DWORD dwCodec /* = mmioFOURCC('M','P','G','4') */,
			DWORD dwFrameRate /* = 1 */)
{

//	AVIFileInit();

	m_hHeap=NULL;
	m_hAviDC=NULL;
	m_lpBits=NULL;
	m_lSample=NULL;
	m_pAviFile=NULL;
	m_pAviStream=NULL;
	m_pAviCompressedStream=NULL;

	m_dwFCCHandler = dwCodec;
	m_dwFrameRate = dwFrameRate;

	_tcscpy_s(m_szFileName, lpszFileName);
	_tcscpy_s(m_szErrMsg, _T("Method Succeeded"));
	m_szErrMsg[__countof(m_szErrMsg)-1] = _T('\0');

	pAppendFrame[0]= &CAviFile::AppendDummy;			// VC8 requires & for Function Pointer; Remove it if your compiler complains;
	pAppendFrame[1]= &CAviFile::AppendFrameFirstTime;
	pAppendFrame[2]= &CAviFile::AppendFrameUsual;

	pAppendFrameBits[0]=&CAviFile::AppendDummy;
	pAppendFrameBits[1]=&CAviFile::AppendFrameFirstTime;
	pAppendFrameBits[2]=&CAviFile::AppendFrameUsual;

	m_nAppendFuncSelector=1;		//0=Dummy	1=FirstTime	2=Usual
}
Пример #10
0
int GetLeapSeconds(Date dt)
{
	static Tuple2<int, int> sLeapSeconds[] = {
		{ 1972,6 }, { 1972,12 }, { 1973,12 }, { 1974,12 }, { 1975,12 }, { 1976,12 }, { 1977,12 },
		{ 1978,12 }, { 1979,12 }, { 1981,6 }, { 1982,6 }, { 1983,6 }, { 1985,6 }, { 1987,12 },
		{ 1989,12 }, { 1990,12 }, { 1992,6 }, { 1993,6 }, { 1994,6 }, { 1995,12 }, { 1997,6 },
		{ 1998,12 }, { 2005,12 }, { 2008,12 }, { 2012,6 },
	};
	static byte ls[1200]; // 100 years of leap seconds per month
	ONCELOCK {
		for(int i = 0; i < __countof(sLeapSeconds); i++) {
			int l = (sLeapSeconds[i].a - 1970) * 12 + sLeapSeconds[i].b - 1;
			memset(ls + l, i + 1, __countof(ls) - l);
		}
	}
	return ls[minmax(12 * (dt.year - 1970) + dt.month - 1, 0, __countof(ls) - 1)];
}
Пример #11
0
double ipow10(int i)
{
	static const double pow_tbl[] =
	{
		1e00,
		1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09, 1e10,
		1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20,
		1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30,
		1e31, 1e32, 1e33, 1e34, 1e35, 1e36, 1e37, 1e38, 1e39, 1e40,
		1e41, 1e42, 1e43, 1e44, 1e45, 1e46, 1e47, 1e48, 1e49, 1e50,
	};
	if(i >= 0 && i < __countof(pow_tbl))
		return pow_tbl[i];
	else if(i < 0 && i > -__countof(pow_tbl))
		return 1 / pow_tbl[-i];
	return pow(10.0, (double)i);
}
Пример #12
0
void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
	//Register our JS functions
	CefRefPtr<CefV8Value> object = context->GetGlobal();
	for(int f = 0; f < __countof(func_names); f++){
		CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction(func_names[f], this);
		object->SetValue(func_names[f], func, V8_PROPERTY_ATTRIBUTE_NONE);
	}			
}
Пример #13
0
int ReadTemplateType(CParser& p)
{
	static const char *nm[] = { "id", "filename", "option", "select", "text" };
	for(int i = 0; i < __countof(nm); i++)
		if(p.Id(nm[i]))
			return i;
	p.ThrowError("Unknown type");
	return 0;
}
Пример #14
0
unsigned PrimeBound(unsigned n)
{
	static unsigned prime_tab[] = {
		17, 29, 61, 127, 257, 509, 1021, 2053, 4093, 8191, 16381,
		32771, 65537, 131071, 262147, 524287, 1048573, 2097143,
		4194301, 8388617, 16777213, 33554467, 67108859, 134217757,
		268435459, 536870909, 1073741827, 2147483647u, 4294967291u
	};
	return *FindUpperBoundIter(prime_tab, prime_tab + __countof(prime_tab), n);
}
Пример #15
0
/**
 * not thread safe
 * */
static int get_valid_entry(){
	AutoLock autoLock(assetMutex);

	for(int i=ENTRY_RESERVED; i<__countof(assetsEntrys); ++i){
		if(assetsEntrys[i].file == NULL){
			return i;
		}
	}
	return 0;
}
Пример #16
0
extern "C" __declspec(dllexport) bool DllRegisterServer()
{
	TCHAR tszThisDLL[MAX_PATH];
	GetModuleFileName(g_hThisDll, tszThisDLL, __countof(tszThisDLL));

	BazisLib::RegistryKey key(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\SysProgs\\VirtualKD\\VirtualBoxIntegration"));
	key[_T("KDClientDLLPath")] = tszThisDLL;
	
	return true;
}
Пример #17
0
String LanguageInfo::ToString() const
{
	String out;
	out << "LANGUAGE={" << LNGAsText(language) << "}\n"
		<< "ENGLISH_NAME={" << english_name << "}\n"
		"NATIVE_NAME={" << native_name << "}\n"
		"THOUSAND_SEPARATOR={" << thousand_separator << "}\n"
		"DECIMAL_POINT={" << decimal_point << "}\n"
		"MONTH_NAMES={\n";
	int i;
	for(i = 0; i < __countof(month_names); i++)
		out << "    {" << FromUnicode(month_names[i]) << "} / {" << FromUnicode(short_month_names[i]) << "}\n";
	out << "}\n"
		"DAY_NAMES={\n";
	for(i = 0; i < __countof(day_names); i++)
		out << "    {" << FromUnicode(day_names[i]) << "} / {" << FromUnicode(short_day_names[i]) << "}\n";
	out << "}\n";
	return out;
}
Пример #18
0
static void sDrawLineStroke(cairo_t *cr, int width)
{
	static double dash[] = { 18, 6 };
	static double dot[] = { 3, 3 };
	static double dashdot[] = { 9, 6, 3, 6 };
	static double dashdotdot[] = { 9, 3, 3, 3, 3, 3 };
	switch(width) {
	case PEN_NULL:       return;
	case PEN_DASH:       cairo_set_dash(cr, dash, __countof(dash), 0); break;
	case PEN_DOT:        cairo_set_dash(cr, dot, __countof(dot), 0); break;
	case PEN_DASHDOT:    cairo_set_dash(cr, dashdot, __countof(dashdot), 0); break;
	case PEN_DASHDOTDOT: cairo_set_dash(cr, dashdotdot, __countof(dashdotdot), 0); break;
	default:             break;
	}
	cairo_set_line_width(cr, width < 0 ? 1 : width);
	cairo_stroke(cr);
	if(width < 0)
		cairo_set_dash(cr, dot, 0, 0);
}
Пример #19
0
void RemoteSlaveProcess::Recv(int part, int timeout)
{
    if(terminated)
        return;
    if(!socket.IsOpen())
    {
        SVRLOG("-> broken pipe");
        terminated = true;
        return;
    }
//	LOG("RemoteSlaveProcess::Recv(" << part << ")");

    int starttick = GetTickCount();
    while( (IsNull(timeout) || int(GetTickCount())-starttick <= timeout) && (socket.Peek() || current_part <= part))
    {
        String data = socket.Read(0);
        SVRLOG("-> [" << current_part << "] = " << data.GetLength() << " bytes: <" << data << ">");
        if(data.IsVoid())
        {
            SVRLOG("-> broken pipe");
            terminated = true;
            return;
        }
        const char *p = data, *e = data.End();
        ASSERT(current_part >= 0 && current_part < __countof(output));
        for(const char *t; e > p && (t = (const char *)memchr(p, 0, e - p));)
        {
            output[current_part].Cat(p, int(t - p));
            p = t + 1;
            if(++current_part >= __countof(output))
            {
                SVRLOG("-> EOF");
                terminated = true;
                return;
            }
        }
        if(p < e)
            output[current_part].Cat(p, int(e - p));
    }
    SVRLOG("-> finished, current_part = " << current_part);
}
Пример #20
0
int smartTime(
        __xin unsigned long long size, 
        __xin int maxunit, 
        __xin int smart, 
        __xin size_t buflen, 
        __xout char* buf) {
    return smartSizeRadixDesc(size, 
            __countof(_alltimes), 
            _alltimes, 
            maxunit, 
            smart, buflen, buf);
}
Пример #21
0
int sGetAddrInfo(const char *host, const char *port, int family, addrinfo **result)
{
	if(!host || !*host)
		return EAI_NONAME;
	addrinfo hints;
	memset(&hints, 0, sizeof(addrinfo));
	const static int FamilyToAF[] = { AF_UNSPEC, AF_INET, AF_INET6 };
	hints.ai_family = FamilyToAF[(family > 0 && family < __countof(FamilyToAF)) ? family : 0];
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	return getaddrinfo(host, port, &hints, result);
}
Пример #22
0
const char *TcpSocketErrorDesc(int code)
{
	static Tuple2<int, const char *> err[] = {
		{ WSAEINTR,                 "Interrupted function call." },
		{ WSAEACCES,                "Permission denied." },
		{ WSAEFAULT,                "Bad address." },
		{ WSAEINVAL,                "Invalid argument." },
		{ WSAEMFILE,                "Too many open files." },
		{ WSAEWOULDBLOCK,           "Resource temporarily unavailable." },
		{ WSAEINPROGRESS,           "Operation now in progress." },
		{ WSAEALREADY,              "Operation already in progress." },
		{ WSAENOTSOCK,              "TcpSocket operation on nonsocket." },
		{ WSAEDESTADDRREQ,          "Destination address required." },
		{ WSAEMSGSIZE,              "Message too long." },
		{ WSAEPROTOTYPE,            "Protocol wrong type for socket." },
		{ WSAENOPROTOOPT,           "Bad protocol option." },
		{ WSAEPROTONOSUPPORT,       "Protocol not supported." },
		{ WSAESOCKTNOSUPPORT,       "TcpSocket type not supported." },
		{ WSAEOPNOTSUPP,            "Operation not supported." },
		{ WSAEPFNOSUPPORT,          "Protocol family not supported." },
		{ WSAEAFNOSUPPORT,          "Address family not supported by protocol family." },
		{ WSAEADDRINUSE,            "Address already in use." },
		{ WSAEADDRNOTAVAIL,         "Cannot assign requested address." },
		{ WSAENETDOWN,              "Network is down." },
		{ WSAENETUNREACH,           "Network is unreachable." },
		{ WSAENETRESET,             "Network dropped connection on reset." },
		{ WSAECONNABORTED,          "Software caused connection abort." },
		{ WSAECONNRESET,            "Connection reset by peer." },
		{ WSAENOBUFS,               "No buffer space available." },
		{ WSAEISCONN,               "TcpSocket is already connected." },
		{ WSAENOTCONN,              "TcpSocket is not connected." },
		{ WSAESHUTDOWN,             "Cannot send after socket shutdown." },
		{ WSAETIMEDOUT,             "Connection timed out." },
		{ WSAECONNREFUSED,          "Connection refused." },
		{ WSAEHOSTDOWN,             "Host is down." },
		{ WSAEHOSTUNREACH,          "No route to host." },
		{ WSAEPROCLIM,              "Too many processes." },
		{ WSASYSNOTREADY,           "Network subsystem is unavailable." },
		{ WSAVERNOTSUPPORTED,       "Winsock.dll version out of range." },
		{ WSANOTINITIALISED,        "Successful WSAStartup not yet performed." },
		{ WSAEDISCON,               "Graceful shutdown in progress." },
		{ WSATYPE_NOT_FOUND,        "Class type not found." },
		{ WSAHOST_NOT_FOUND,        "Host not found." },
		{ WSATRY_AGAIN,             "Nonauthoritative host not found." },
		{ WSANO_RECOVERY,           "This is a nonrecoverable error." },
		{ WSANO_DATA,               "Valid name, no data record of requested type." },
		{ WSASYSCALLFAILURE,        "System call failure." },
	};
	const Tuple2<int, const char *> *x = FindTuple(err, __countof(err), code);
	return x ? x->b : "Unknown error code.";
}
Пример #23
0
void RunServiceDispatcher(String service_name_)
{
	ASSERT(service_name_.GetLength() < __countof(service_name));
	strcpy(service_name, service_name);
	static SERVICE_TABLE_ENTRY servicetable[] = {
		{ service_name, &ServiceInit },
		{ NULL, NULL }
	};

	RLOG(ThreadId() << "starting service control dispatcher");
	StartServiceCtrlDispatcher(servicetable);
	RLOG(ThreadId() << "exiting main thread");
	return;
}
Пример #24
0
unsigned GetNextVMSessionPIDEx( HANDLE hList, VMType *pVMType )
{
	TCHAR *tszNames[] = {_T("VirtualBox.exe"), _T("vmware-vmx.exe"), _T("vmware-vmx-debug.exe"), _T("vmware-vmx-stats.exe")};
	unsigned PID = 0;
	unsigned idxMatch = 0;
	for (;;)
	{
		PID = FindProcessByNames(hList, tszNames, __countof(tszNames), false, &idxMatch);
		if ((PID == -1) || !PID)
			return 0;
		if (idxMatch)
			break;
		//Skip VirtualBox processes not running any VMs
		wchar_t sessionName[MAX_PATH];
		if (GetVMSessionNameW(PID, sessionName, __countof(sessionName)))
			break;
	}
	if (pVMType)
	{
		if (!PID)
			*pVMType = kVMUnknown;
		{
			BazisLib::WOW64APIProvider wow;
#ifdef _WIN64
			bool Is64 = !wow.IsWow64Process(PID);
#else
			bool Is64 = wow.IsWow64Process() && !wow.IsWow64Process(PID);
#endif
			if (idxMatch)
				*pVMType = Is64 ? kVMWare64 : kVMWare32;
			else
				*pVMType = Is64 ? kVBox64 : kVBox32;
		}
	}
	return PID;
}
Пример #25
0
int smartTimeDiff(
        __xin unsigned long long lfs, 
        __xin unsigned long long rfs, 
        __xin int maxunit, 
        __xin int smart, 
        __xin size_t buflen, 
        __xout char* buf) {

    return smartRadixDiffDesc(lfs, rfs, 
            __countof(_alltimes), 
            _alltimes, 
            maxunit, 
            smart, 
            _alltimessuffixs_en,
            buflen, 
            buf);

}
Пример #26
0
bool Replace(Font fnt, int chr, Font& rfnt)
{
	static Vector<int> rface;
	static Vector<dword> l, h;
	ONCELOCK {
		for(int i = 0; i < __countof(sFontReplacements) && rface.GetCount() < 20; i++) {
			int q = Font::FindFaceNameIndex(sFontReplacements[i].name);
			if(q > 0) {
				rface.Add(q);
				l.Add(sFontReplacements[i].l);
				h.Add(sFontReplacements[i].h);
			}
		}
	}

	Font f = fnt;
//	dword tl = chr < 4096 ? 0x80000000 >> (chr >> 7) : 0;
//	dword th = 0x80000000 >> ((dword)chr >> 11);
	for(int i = 0; i < rface.GetCount(); i++) {
		if(/*((l[i] & tl) || (h[i] & th)) && */IsNormal(f.Face(rface[i]), chr)) {
			int a = fnt.GetAscent();
			int d = fnt.GetDescent();
			if(f.GetAscent() > a || f.GetDescent() > d) {
				static sFontMetricsReplacement cache[256];
				int q = CombineHash(fnt, f) & 255;
				if(cache[q].src != fnt || cache[q].dst != f) {
					cache[q].src = fnt;
					cache[q].dst = f;
					while((f.GetAscent() > a || f.GetDescent() > d) && f.GetHeight() > 1) {
						f.Height(max(1, min(f.GetHeight() - 1, f.GetHeight() * 9 / 10)));
					}
					cache[q].mdst = f;
				}
				else
					f = cache[q].mdst;
			}
			rfnt = f;
			return true;
		}
	}
	return false;
}
Пример #27
0
const wchar *isstmt(const wchar *p) {
	static const char *stmt[] = {
		"if", "else", "while", "do", "for"
	};
	for(const char **q = stmt; q < stmt + __countof(stmt); q++) {
		const char *k = *q;
		const wchar *s = p;
		for(;;) {
			if(*k== '\0') {
				if(!iscidl(*s)) return s;
				break;
			}
			if(*s != *k)
				break;
			s++;
			k++;
		}
	}
	return NULL;
}
Пример #28
0
	void Load(const char *dir)
	{
		Index<String> exist;
		FindFile ff(AppendFileName(dir, "*.tpp"));
		while(ff) {
			if(ff.IsFolder()) {
				String s = GetFileTitle(ff.GetName());
				group.Add(s, AttrText(TppName(s)).SetFont(StdFont().Bold()));
				exist.Add(s);
			}
			ff.Next();
		}
		static const char *h[4] = { "src.tpp", "srcdoc.tpp", "srcimp.tpp", "app.tpp" };
		for(int i = 0; i < __countof(h); i++) {
			String s = GetFileTitle(h[i]);
			if(exist.Find(s) < 0)
				group.Add(s, TppName(s) + " (new)");
		}
		group.Add(Null, "<other new>");
		group.GoBegin();
	}
Пример #29
0
bool LocalSlaveProcess::DecodeExitCode(int status)
{
    if(WIFEXITED(status)) {
        exit_code = (byte)WEXITSTATUS(status);
        return true;
    }
    else if(WIFSIGNALED(status) || WIFSTOPPED(status)) {
        static const struct {
            const char *name;
            int         code;
        }
        signal_map[] = {
#define SIGDEF(s) { #s, s },
            SIGDEF(SIGHUP) SIGDEF(SIGINT) SIGDEF(SIGQUIT) SIGDEF(SIGILL) SIGDEF(SIGABRT)
            SIGDEF(SIGFPE) SIGDEF(SIGKILL) SIGDEF(SIGSEGV) SIGDEF(SIGPIPE) SIGDEF(SIGALRM)
            SIGDEF(SIGPIPE) SIGDEF(SIGTERM) SIGDEF(SIGUSR1) SIGDEF(SIGUSR2) SIGDEF(SIGTRAP)
            SIGDEF(SIGURG) SIGDEF(SIGVTALRM) SIGDEF(SIGXCPU) SIGDEF(SIGXFSZ) SIGDEF(SIGIOT)
            SIGDEF(SIGIO) SIGDEF(SIGWINCH)
#ifndef PLATFORM_BSD
//SIGDEF(SIGCLD) SIGDEF(SIGPWR)
#endif
//SIGDEF(SIGSTKFLT) SIGDEF(SIGUNUSED) // not in Solaris, make conditional if needed
#undef SIGDEF
        };

        int sig = (WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status));
        exit_code = (WIFSIGNALED(status) ? 1000 : 2000) + sig;
        exit_string << "\nProcess " << (WIFSIGNALED(status) ? "terminated" : "stopped") << " on signal " << sig;
        for(int i = 0; i < __countof(signal_map); i++)
            if(signal_map[i].code == sig)
            {
                exit_string << " (" << signal_map[i].name << ")";
                break;
            }
        exit_string << "\n";
        return true;
    }
    return false;
}
Пример #30
0
void LanguageInfo::Set(int lang_)
{
	language = lang_;
	dword q = sGetLanguageDetails(language, &english_name, &native_name);	
	if(!q)
		return;

	getindexletter = DefaultGetIndexLetter;
	compare = DefaultLanguageCompare;
	if(language == LNG_('C','S','C','Z')) {
		getindexletter = CSCZGetIndexLetter;
		compare = CSCZLanguageCompare;
	}
#ifdef PLATFORM_WIN32
	LCID lcid = q;
	thousand_separator = GetLocaleInfoA(lcid, LOCALE_STHOUSAND);
	decimal_point = GetLocaleInfoA(lcid, LOCALE_SDECIMAL);
	static const LCTYPE months[] =
	{
		LOCALE_SMONTHNAME1,  LOCALE_SMONTHNAME2,  LOCALE_SMONTHNAME3,
		LOCALE_SMONTHNAME4,  LOCALE_SMONTHNAME5,  LOCALE_SMONTHNAME6,
		LOCALE_SMONTHNAME7,  LOCALE_SMONTHNAME8,  LOCALE_SMONTHNAME9,
		LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12,
	};
	static const LCTYPE smonths[] =
	{
		LOCALE_SABBREVMONTHNAME1,  LOCALE_SABBREVMONTHNAME2,  LOCALE_SABBREVMONTHNAME3,
		LOCALE_SABBREVMONTHNAME4,  LOCALE_SABBREVMONTHNAME5,  LOCALE_SABBREVMONTHNAME6,
		LOCALE_SABBREVMONTHNAME7,  LOCALE_SABBREVMONTHNAME8,  LOCALE_SABBREVMONTHNAME9,
		LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12,
	};
	ASSERT(__countof(months) == __countof(month_names));
	int i;
	for(i = 0; i < __countof(months); i++)
	{
		month_names[i] = GetLocaleInfoW(lcid, months[i]);
		short_month_names[i] = GetLocaleInfoW(lcid, smonths[i]);
	}
	static const LCTYPE days[] =
	{
		LOCALE_SDAYNAME1, LOCALE_SDAYNAME2, LOCALE_SDAYNAME3, LOCALE_SDAYNAME4,
		LOCALE_SDAYNAME5, LOCALE_SDAYNAME6, LOCALE_SDAYNAME7,
	};
	static const LCTYPE sdays[] =
	{
		LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2, LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4,
		LOCALE_SABBREVDAYNAME5, LOCALE_SABBREVDAYNAME6, LOCALE_SABBREVDAYNAME7,
	};
	ASSERT(__countof(days) == __countof(day_names));
	for(i = 0; i < __countof(days); i++)
	{
		day_names[i] = GetLocaleInfoW(lcid, days[i]);
		short_day_names[i] = GetLocaleInfoW(lcid, sdays[i]);
	}
#endif

#ifdef PLATFORM_POSIX
	String langtext = LNGAsText(language);
	char ltext[6];
	ltext[0] = ToLower(langtext[0]);
	ltext[1] = ToLower(langtext[1]);
	ltext[2] = '_';
	ltext[3] = ToUpper(langtext[3]);
	ltext[4] = ToUpper(langtext[4]);
	ltext[5] = 0;
	String oldloc = setlocale(LC_ALL, NULL);
	if(setlocale(LC_ALL, ltext))
	{
		const struct lconv *lc = localeconv();
		decimal_point = lc->decimal_point;
		thousand_separator = lc->thousands_sep;
		static const int months[] =
		{
			MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12,
		};
		static const int smonths[] =
		{
			ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12,
		};
		ASSERT(__countof(months) == __countof(month_names) && __countof(smonths) == __countof(month_names));
		int i;
		for(i = 0; i < __countof(months); i++)
		{
			month_names[i] = nl_langinfo(months[i]);
			short_month_names[i] = nl_langinfo(smonths[i]);
		}
		static const int days[] =
		{ // Linux locale starts with Sunday
			DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, DAY_1,
		};
		static const int sdays[] =
		{
			ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABDAY_1,
		};
		ASSERT(__countof(days) == __countof(day_names) && __countof(sdays) == __countof(day_names));
		for(i = 0; i < __countof(days); i++)
		{
			day_names[i] = nl_langinfo(days[i]);
			short_day_names[i] = nl_langinfo(sdays[i]);
		}

		setlocale(LC_ALL, oldloc);
	}
#endif
	for(int i = 0; i < 12; i++) {
		month[i] = month_names[i].ToString();
		smonth[i] = short_month_names[i].ToString();
	}
	for(int i = 0; i < 7; i++) {
		day[i] = day_names[i].ToString();
		sday[i] = short_day_names[i].ToString();
	}
}