Exemplo n.º 1
0
// Draw feature with respect to the world frame
void COpenGlDisplay::drawCurrentFeatures(CSLAM* SLAM)
{
	if (0 == SLAM->m_nMatches)
	{
		return;
	}

	Point3f location, sigma;
	Quaternion axis;
	char text[10];

	PointsMap* map_p = SLAM->map; 
	while (NULL != map_p)
	{
		if (true == map_p->isMatching)
		{
			glPushMatrix();

			location.x = (float)map_p->xyz.x;
			location.y = (float)map_p->xyz.y;

			if (TRUE == SLAM->isCompensate)
			{
				location.z = (float)(map_p->xyz.z + SLAM->m_deep)/2.0;
			} 
			else
			{
				location.z = (float)map_p->xyz.z;
			}

			glTranslatef(location.x,location.y,location.z);      // Move Left 1.5 Units And Into The Screen 6.0 
			glColor3f( 1.0f, 0.0f, 0.0f );
			_itoa_s(map_p->ID, text, 10);
			drawText(text, 0.3);
			
			sigma.x = (float)map_p->sigma.x;
			sigma.y = (float)map_p->sigma.y;
			sigma.z = (float)map_p->sigma.z;

			axis = map_p->axis;
			float angle = 2*atan2(sqrt(axis.x*axis.x+axis.y*axis.y+axis.z*axis.z), axis.r);
			angle = angle*180/3.141593f;

			//glTranslatef(location.x,location.y,location.z);
			glRotated(angle, -axis.x, -axis.y, -axis.z); 
			glScaled(min(4.0f,sigma.x),min(4.0f,sigma.y),min(4.0f,sigma.z));
			glEnable(GL_LIGHTING);

			if (true == map_p->isLoop)
			{
				glColor3f( 0.0f, 1.0f, 0.0f );
			} 
			else
			{
				glColor3f( 1.0f, 0.0f, 0.0f );
			}

			glutWireSphere(3.0f, 10,10);
			glPopMatrix();
		}
		map_p = map_p->next;
	}
}
Exemplo n.º 2
0
// OutputProgress
//------------------------------------------------------------------------------
/*static*/ void FLog::OutputProgress( float time, 
									  float percentage,
									  uint32_t numJobs, 
									  uint32_t numJobsActive, 
									  uint32_t numJobsDist, 
									  uint32_t numJobsDistActive )
{
    PROFILE_FUNCTION

	ASSERT( s_ShowProgress );

	// format progress % (we know it never goes above 99.9%)
	uint32_t intPerc = (uint32_t)( percentage * 10.0f ); // 0 to 999
	uint32_t hundreds = ( intPerc / 100 ); intPerc -= ( hundreds * 100 );
	uint32_t tens = ( intPerc / 10 ); intPerc -= ( tens * 10 );
	uint32_t ones = intPerc;
	m_ProgressText = g_OutputString;
	m_ProgressText[ 1 ] = ( hundreds > 0 ) ? ( '0' + (char)hundreds ) : ' ';
	m_ProgressText[ 2 ] = '0' + (char)tens;
	m_ProgressText[ 4 ] = '0' + (char)ones;

	// 20 column output (100/20 = 5% per char)
	uint32_t numStarsDone = (uint32_t)( percentage * 20.0f / 100.0f ); // 20 columns
	for ( uint32_t i=0; i<20; ++i ) 
	{
		m_ProgressText[ 9 + i ] = ( i < numStarsDone ) ? '*' : '-';
	}

	// time " [%um] %02us"
	uint32_t timeTakenMinutes = uint32_t( time / 60.0f );
	uint32_t timeTakenSeconds = (uint32_t)time - ( timeTakenMinutes * 60 );
	if ( timeTakenMinutes > 0 )
	{
		char buffer[ 8 ];
		_itoa_s( timeTakenMinutes, buffer, 8, 10 );
		m_ProgressText += buffer;
		m_ProgressText.Append( "m ", 2 );
	}
	char buffer[ 8 ];
	_itoa_s( timeTakenSeconds, buffer, 8, 10 );
	if ( timeTakenSeconds < 10 ) { m_ProgressText += '0'; }
	m_ProgressText += buffer;
	m_ProgressText += 's';

	// active/available jobs " (%u/%u)"
	m_ProgressText.Append( " (", 2 );
	_itoa_s( numJobsActive, buffer, 8, 10 );
	m_ProgressText += buffer;
	m_ProgressText += '/';
	_itoa_s( numJobsActive + numJobs, buffer, 8, 10 );
	m_ProgressText += buffer;
	m_ProgressText += ')';

	// distributed status "+(%u/%u)"
	if ( FBuild::Get().GetOptions().m_AllowDistributed )
	{
		m_ProgressText.Append( "+(", 2 );
		_itoa_s( numJobsDistActive, buffer, 8, 10 );
		m_ProgressText += buffer;
		m_ProgressText += '/';
		_itoa_s( numJobsDistActive + numJobsDist, buffer, 8, 10 );
		m_ProgressText += buffer;
		m_ProgressText += ')';
	}

	m_ProgressText.Append( "    \b\b\b", 7 ); // extra whitespace when string shortens

	// if build aborting, override all output
	if ( FBuild::Get().GetStopBuild() )
	{
		m_ProgressText.Format( "\rBUILD ABORTED - STOPPING (%u) ", numJobsActive );
		m_ProgressText += "                                  \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
	}

	// animation
	static int animIndex = 0;
	static char anim[] = { '\\', '|', '/', '-', '\\', '|', '/', '-' };
	m_ProgressText += anim[ ( animIndex++ ) % 8 ]; 

	// finally print it
	fwrite( m_ProgressText.Get(), 1, m_ProgressText.GetLength(), stdout );
}
Exemplo n.º 3
0
BOOLEAN	LoadFormFile(LPSTR lpFileName){
	UINT	i;
	TCHAR	stri[3];
	TCHAR	strtmp[MAX_STRING];
	TCHAR	strLeft[5], strTop[5], strRight[5], strBottom[5];
	RECT	crtWnd;
	HWND	hChildDlg;
	HWND	hGroup;
	UINT	numZone, tmpZone;

	// Initialize zone
	tmpZone = g_numZone;
	if (tmpZone != -1)
		for (i=0 ; i<=tmpZone ; i++)
			SendMessage(g_hDlgZone[i], WM_COMMAND, MAKELPARAM(IDC_BUTTON_CLOSE, 0), 0);

	numZone = GetPrivateProfileInt(TEXT("numZone"), TEXT("numZone"), 0, lpFileName);
	for (i=0 ; i<=numZone ; i++)
	{
		_itoa_s(i, (char *)stri, 3, 5);

		hChildDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_ZONE), g_hDlgBoard, dlgZoneProc);
		hGroup = FindWindowEx(hChildDlg, GetDlgItem(hChildDlg, IDC_BUTTON_CLOSE), TEXT("#32770"), TEXT(""));

		// Subject
		GetPrivateProfileString(stri, TEXT("subject"), 0, strtmp, MAX_STRING, lpFileName);
		SetDlgItemText(hGroup, IDC_EDIT_SUBJECT, strtmp);

		// Rectangle
		// GetPrivateProfileInt's return is (-) so use GetPrivateProfileString
		GetPrivateProfileString(stri, TEXT("left"), 0, strLeft, 5, lpFileName);
		GetPrivateProfileString(stri, TEXT("right"), 0, strRight, 5, lpFileName);
		GetPrivateProfileString(stri, TEXT("top"), 0, strTop, 5, lpFileName);
		GetPrivateProfileString(stri, TEXT("bottom"), 0, strBottom, 5, lpFileName);

		SetRect(&crtWnd, atoi((const char*)strLeft), atoi((const char*)strTop), atoi((const char*)strRight), atoi((const char*)strBottom));

		SetDlgItemInt(hGroup, IDC_EDIT_X, crtWnd.left, TRUE);
		SetDlgItemInt(hGroup, IDC_EDIT_Y, crtWnd.top, TRUE);
		SetDlgItemInt(hGroup, IDC_EDIT_WIDTH, crtWnd.right - crtWnd.left, TRUE);
		SetDlgItemInt(hGroup, IDC_EDIT_HEIGHT, crtWnd.bottom - crtWnd.top, TRUE);

		MoveWindow(GetParent(hGroup), crtWnd.left, crtWnd.top, crtWnd.right - crtWnd.left, crtWnd.bottom - crtWnd.top, TRUE);

		// Class name
		GetPrivateProfileString(stri, TEXT("class name"), 0, strtmp, MAX_STRING, lpFileName);
		SetDlgItemText(hGroup, IDC_EDIT_CLASSNAME, strtmp);

		// Path
		GetPrivateProfileString(stri, TEXT("path"), 0, strtmp, MAX_STRING, lpFileName);
		SetDlgItemText(hGroup, IDC_ZONEGROUP_EDIT_PATH, strtmp);

		// Auto run
		SendDlgItemMessage(hGroup, IDC_CHECK_AUTORUN, BM_SETCHECK, GetPrivateProfileInt(stri, TEXT("auto run"), 0, lpFileName), 0);

		// Auto resize
		SendDlgItemMessage(hGroup, IDC_CHECK_AUTORESIZE, BM_SETCHECK, GetPrivateProfileInt(stri, TEXT("auto resize"), 0, lpFileName), 0);
	}

	wsprintf(g_formPath, TEXT("%s"), lpFileName);
	return TRUE;
}
Exemplo n.º 4
0
void SW_ParaDrop::LoadFromINI(
	SWTypeExt::ExtData *pData, SuperWeaponTypeClass *pSW, CCINIClass *pINI)
{
	const char * section = pSW->ID;

	if(!pINI->GetSection(section)) {
		return;
	}

	INI_EX exINI(pINI);

	char base[0x40];

	auto CreateParaDropBase = [](char* pID, char* pBuffer) {
		// put a string like "Paradrop.Americans" into the buffer
		if(pBuffer) {
			AresCRT::strCopy(pBuffer, "ParaDrop", 9);
			if(pID && strlen(pID)) {
				AresCRT::strCopy(&pBuffer[8], ".", 2);
				AresCRT::strCopy(&pBuffer[9], pID, 0x18);
			}
		}
	};

	auto ParseParaDrop = [&](char* pID, int Plane) -> ParadropPlane* {
		ParadropPlane* pPlane = NULL;

		// create the plane part of this request. this will be
		// an empty string for the first plane for this is the default.
		char plane[0x10] = "";
		if(Plane) {
			AresCRT::strCopy(plane, ".Plane", 0x10);
			_itoa_s(Plane + 1, &plane[6], 10, 10);
		}
		
		// construct the full tag name base
		char base[0x40], key[0x40];
		_snprintf_s(base, 0x3F, "%s%s", pID, plane);

		// parse the plane contents
		_snprintf_s(key, 0x3F, "%s.Aircraft", base);
		if(pINI->ReadString(section, key, "", Ares::readBuffer, Ares::readLength)) {
			if(AircraftTypeClass* pTAircraft = AircraftTypeClass::Find(Ares::readBuffer)) {
				pPlane = new ParadropPlane();
				pPlane->pAircraft = pTAircraft;
			} else {
				Debug::INIParseFailed(section, key, Ares::readBuffer);
			}
		}

		// a list of UnitTypes and InfantryTypes
		_snprintf_s(key, 0x3F, "%s.Types", base);
		if(pINI->ReadString(section, key, "", Ares::readBuffer, Ares::readLength)) {
			// create new plane if there is none yet
			if(!pPlane) {
				pPlane = new ParadropPlane();
			}

			// parse the types
			pPlane->pTypes.Clear();

			char* context = nullptr;
			for(char* p = strtok_s(Ares::readBuffer, Ares::readDelims, &context); p && *p; p = strtok_s(nullptr, Ares::readDelims, &context)) {
				TechnoTypeClass* pTT = UnitTypeClass::Find(p);

				if(!pTT) {
					pTT = InfantryTypeClass::Find(p);
				}

				if(pTT) {
					pPlane->pTypes.AddItem(pTT);
				} else {
					Debug::INIParseFailed(section, key, p);
				}
			}
		}

		// don't parse nums if there are no types
		if(!pPlane || !pPlane->pTypes.Count) {
			return pPlane;
		}

		// the number how many times each item is created
		_snprintf_s(key, 0x3F, "%s.Num", base);
		if(pINI->ReadString(section, key, "", Ares::readBuffer, Ares::readLength)) {
			pPlane->pNum.Clear();

			char* context = nullptr;
			for(char* p = strtok_s(Ares::readBuffer, Ares::readDelims, &context); p && *p; p = strtok_s(nullptr, Ares::readDelims, &context)) {
				pPlane->pNum.AddItem(atoi(p));
			}
		}

		return pPlane;
	};

	auto GetParadropPlane = [&](char *pID, int defCount, DynamicVectorClass<ParadropPlane*>* ret) {
		// get the number of planes for this house or side
		char key[0x40];
		_snprintf_s(key, 0x3F, "%s.Count", pID);
		int count = pINI->ReadInteger(section, key, defCount);

		// parse every plane
		ret->SetCapacity(count, NULL);
		for(int i=0; i<count; ++i) {
			if(i>=ret->Count) {
				ret->AddItem(NULL);
			}
			
			ParadropPlane* pPlane = ParseParaDrop(base, i);
			if(pPlane) {
				pData->ParaDropPlanes.AddItem(pPlane);
				ret->Items[i] = pPlane;
			}
		}
	};

	// now load the paradrops
	// 0: default
	// 1 to n: n sides
	// n+1 to n+m+1: m countries

	// default
	CreateParaDropBase(NULL, base);
	GetParadropPlane(base, 1, &pData->ParaDrop[NULL]);

	// put all sides into the hash table
	for(int i=0; i<SideClass::Array->Count; ++i) {
		SideClass *pSide = SideClass::Array->GetItem(i);
		CreateParaDropBase(pSide->ID, base);
		GetParadropPlane(base, pData->ParaDrop[NULL].Count, &pData->ParaDrop[pSide]);
	}

	// put all countries into the hash table
	for(int i=0; i<HouseTypeClass::Array->Count; ++i) {
		HouseTypeClass *pTHouse = HouseTypeClass::Array->GetItem(i);
		CreateParaDropBase(pTHouse->ID, base);
		GetParadropPlane(base, pData->ParaDrop[SideClass::Array->GetItem(pTHouse->SideIndex)].Count, &pData->ParaDrop[pTHouse]);
	}
}
Exemplo n.º 5
0
	/* Raise an Eiffel exception in case an error occurred */
void eif_net_check (int retcode) {
	/* Check the return code of connect(), recv(), send(), ... */

#ifdef EIF_WINDOWS
	char buf[80]="Net error #";
	int errcode;
	if ((retcode == SOCKET_ERROR) || (retcode == INVALID_SOCKET)) {
		errcode = WSAGetLastError();
		errno = errcode;
		switch (errcode) {
			case WSANOTINITIALISED:
				eraise("WSANOTINITIALISED: A successful WSAStartup must occur before using this function.", EN_PROG);
				break;
			case WSAENETDOWN:
				eraise("WSAENETDOWN: The network subsystem has failed.", EN_PROG);
				break;
			case WSAEADDRINUSE:
				eraise("WSAEADDRINUSE: The specified address is already in use. (See the SO_REUSEADDR socket option under setsockopt).", EN_PROG);
				break;
			case WSAEFAULT:
				eraise("WSAEFAULT: The name or the namelen parameter is not a valid part of the user address space, the namelen parameter is too small, the name parameter contains incorrect address format for the associated address family, or the first two bytes of the memory block specified by name does not match the address family associated with the socket descriptor s.", EN_PROG);
				break;
			case WSAEINPROGRESS:
				eraise("WSAEINPROGRESS: A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.", EN_PROG);
				break;
			case WSAEINVAL:
				eraise("WSAEINVAL: The socket is already bound to an address.", EN_PROG);
				break;
			case WSAENOBUFS:
				eraise("WSAENOBUFS: Not enough buffers available, too many connections.", EN_PROG);
				break;
			case WSAENOTSOCK:
				eraise("WSAENOTSOCK: The descriptor is not a socket.", EN_PROG);
				break;
			case WSAEAFNOSUPPORT:
				eraise ("WSAEAFNOSUPPORT: The specified address family is not supported.", EN_PROG);
				break;
			case WSAEMFILE:
				eraise ("WSAEMFILE: No more socket descriptors are available.", EN_PROG);
				break;
			case WSAEPROTONOSUPPORT:
				eraise ("WSAEPROTONOSUPPORT: The specified protocol is not supported.", EN_PROG);
				break;
			case WSAEPROTOTYPE:
				eraise ("WSAEPROTOTYPE: The specified protocol is the wrong type for this socket.", EN_PROG);
				break;
			case WSAESOCKTNOSUPPORT:
				eraise ("WSAESOCKTNOSUPPORT: The specified socket type is not supported in this address family.", EN_PROG);
				break;
			case WSAECONNRESET:
				eraise ("WSAECONNRESET: Connection reset by peer.", EN_PROG);
				break;
			case WSAECONNREFUSED:
				eraise ("WSAECONNREFUSED: Connection refused.", EN_PROG);
				break;
			case WSAENOTCONN:
				eraise ("WSAENOTCONN: Socket is not connected.", EN_PROG);
				break;
			default:
				if ((errcode != EWOULDBLOCK) && (errcode != EINPROGRESS)) {
#if (_MSC_VER >= 1400)
					_itoa_s(errcode,&buf[11], 50, 10);
#else
					itoa(errcode,&buf[11],10);
#endif
					eraise(buf, EN_ISE_IO);
				} else {
					errno = 0;
				}
		}
	} else {
		errno = 0;
	}
#else
		/* Get the last error here, and signal it like above...*/
	if (retcode < 0) {
		if ((errno != EWOULDBLOCK) && (errno != EINPROGRESS)) {
			eraise(NULL, EN_IO);
		} else {
			errno = 0;
		}
	} else {
		errno = 0;
	}
#endif
}
void LoadDaisy3Smil2Handle::endElement  (const XMLCh *const uri, 
										 const XMLCh *const localname, 
										 const XMLCh *const qName)
{
	char* message4 = XMLString::transcode(localname);
	
	//Check the variable which its value are true;
	//		TRUE  means don't pass its function for store data from file to our variable.
	//		FALSE means complete, don't do anything more!

	  //////////////////
	 // Checking par //
	//////////////////
	if  (!strcmp(message4,"par") || !strcmp(message4,"Par") || !strcmp(message4,"PAR")) 
	{		
		if ( ((intCountAudio == 1) && (boolNewAudio = true))
		   ||((intCountText  == 1) && (boolNewText  = true))	 
		   ||((intCountImg   == 1) && (boolNewImg   = true)))
		{
			//push back seq information
			vecDaisy3Smil2BodySeqId.push_back			(strDaisy3Smil2BodySeqTempId);
			vecDaisy3Smil2BodySeqClass.push_back		(strDaisy3Smil2BodySeqTempClass);	
			vecDaisy3Smil2BodySeqCustomTest.push_back	(strDaisy3Smil2BodySeqTempCustomTest);
			vecDaisy3Smil2BodySeqDur.push_back			(strDaisy3Smil2BodySeqTempDur);
			vecDaisy3Smil2BodySeqXmlLang.push_back		(strDaisy3Smil2BodySeqTempXmlLang);
			vecDaisy3Smil2BodySeqEnd.push_back			(strDaisy3Smil2BodySeqTempEnd);
			vecDaisy3Smil2BodySeqFill.push_back			(strDaisy3Smil2BodySeqTempFill);
			_itoa_s(intDaisy3Smil2BodySeqTempLevel, a, 10);		//convert int to string
			vecDaisy3Smil2BodySeqLevel.push_back		(a);	//store that string to vector
			//push back par information
			vecDaisy3Smil2BodyParId.push_back			(strDaisy3Smil2BodyParTempId);
			vecDaisy3Smil2BodyParClass.push_back		(strDaisy3Smil2BodyParTempClass);
			vecDaisy3Smil2BodyParCustomTest.push_back	(strDaisy3Smil2BodyParTempCustomTest);
			vecDaisy3Smil2BodyParXmlLang.push_back		(strDaisy3Smil2BodyParTempXmlLang);
			_itoa_s(intDaisy3Smil2BodyParTempLevel, a, 10);		//convert int to string
			vecDaisy3Smil2BodyParLevel.push_back		(a);	//store that string to vector

			//push back Anchor <a> information
			vecDaisy3Smil2BodyAnchorId.push_back		(strDaisy3Smil2BodyAnchorTempId);
			vecDaisy3Smil2BodyAnchorClass.push_back		(strDaisy3Smil2BodyAnchorTempClass);
			vecDaisy3Smil2BodyAnchorTitle.push_back		(strDaisy3Smil2BodyAnchorTempTitle);
			vecDaisy3Smil2BodyAnchorXmlLang.push_back	(strDaisy3Smil2BodyAnchorTempXmlLang);
			vecDaisy3Smil2BodyAnchorHref.push_back		(strDaisy3Smil2BodyAnchorTempHref);
			vecDaisy3Smil2BodyAnchorExternal.push_back	(strDaisy3Smil2BodyAnchorTempExternal);
			//push back image information
			vecDaisy3Smil2BodyImgId.push_back			(strDaisy3Smil2BodyImgTempId);
			vecDaisy3Smil2BodyImgRegion.push_back		(strDaisy3Smil2BodyImgTempRegion);
			vecDaisy3Smil2BodyImgSrc.push_back			(strDaisy3Smil2BodyImgTempSrc);
			vecDaisy3Smil2BodyImgType.push_back			(strDaisy3Smil2BodyImgTempType);
			vecDaisy3Smil2BodyImgXmlLang.push_back		(strDaisy3Smil2BodyImgTempXmlLang);
			//push back text infomation
			vecDaisy3Smil2BodyTextId.push_back			(strDaisy3Smil2BodyTextTempId);
			vecDaisy3Smil2BodyTextSrcFile.push_back		(strDaisy3Smil2BodyTextTempSrc.substr(0,strDaisy3Smil2BodyTextTempSrc.find("#")));		//Seperte File and ID
			vecDaisy3Smil2BodyTextSrcId.push_back		(strDaisy3Smil2BodyTextTempSrc.substr(strDaisy3Smil2BodyTextTempSrc.find("#")+1));		//Seperte File and ID	
			vecDaisy3Smil2BodyTextType.push_back		(strDaisy3Smil2BodyTextTempType);
			vecDaisy3Smil2BodyTextRegion.push_back		(strDaisy3Smil2BodyTextTempRegion);
			vecDaisy3Smil2BodyTextXmlLang.push_back		(strDaisy3Smil2BodyTextTempXmlLang);
			vecDaisy3Smil2BodyTextContent.push_back		("WaItInG");
			//push back audio infomation
			vecDaisy3Smil2BodyAudioId.push_back			(strDaisy3Smil2BodyAudioTempId);
			vecDaisy3Smil2BodyAudioSrc.push_back		(strDaisy3Smil2BodyAudioTempSrc);
			vecDaisy3Smil2BodyAudioType.push_back		(strDaisy3Smil2BodyAudioTempType);
			vecDaisy3Smil2BodyAudioClipBegin.push_back	(strDaisy3Smil2BodyAudioTempClipBegin);
			vecDaisy3Smil2BodyAudioClipEnd.push_back	(strDaisy3Smil2BodyAudioTempClipEnd);
			vecDaisy3Smil2BodyAudioRegion.push_back		(strDaisy3Smil2BodyAudioTempRegion);
			vecDaisy3Smil2BodyAudioXmlLang.push_back	(strDaisy3Smil2BodyAudioTempXmlLang);

			//setup variable
			if (intCountImg   == 1)
				intCountImg   =  0;
			if (intCountText  == 1)
				intCountText  =  0;
			if (intCountAudio == 1)
				intCountAudio =  0;
		}

		//setup variable for find level of par in this SMIL.
		intDaisy3Smil2BodyParTempLevel--;
		return;
	}

	  ////////////////////////
	 // Checking seq and a //
	////////////////////////
	if  ( !strcmp(message4,"seq") 
		||!strcmp(message4,"Seq") 
		||!strcmp(message4,"SEQ")
		||!strcmp(message4,"a")
		||!strcmp(message4,"A"))
	{
		//setup variable
		if (intCountImg   > 0)
			intCountImg--;
		if (intCountText  > 0)
			intCountText--;
		if (intCountAudio > 0)
			intCountAudio--;

		//only seq
		if  (!strcmp(message4,"seq") || !strcmp(message4,"Seq") || !strcmp(message4,"SEQ")) 
		{
			//setup variable for find level od seq in this SMIL.
			intDaisy3Smil2BodySeqTempLevel--;
		}
		return;
	}
}
Exemplo n.º 7
0
BOOL CALLBACK SessionDialog::SessDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                                         LPARAM lParam)
{
  // This is a static method, so we don't know which instantiation we're
  // dealing with, but we can get a pseudo-this from the parameter to
  // WM_INITDIALOG, which we thereafter store with the window and retrieve
  // as follows:
  SessionDialog *_this =
    (SessionDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);

  int i;
  char tmphost[256];
  char buffer[256];
  HWND hListMode = GetDlgItem(hwnd, IDC_LIST_MODE);
  HWND hcombo = GetDlgItem(hwnd, IDC_HOSTNAME_EDIT);

  switch (uMsg) {
    case WM_INITDIALOG:
    {
      SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
      SessionDialog *_this = (SessionDialog *) lParam;
      CenterWindow(hwnd);
      _this->m_cc->m_hSess = hwnd;

      // Load connection history into the combo box
      const int maxEntries = pApp->m_options.m_historyLimit;
      int listIndex = 0;
      for (i = 0; i < maxEntries; i++) {
        char keyName[256];
        _itoa_s(i, keyName, _countof(keyName), 10);
        char buf[256];
        int dwbuflen = 255;
        if (RegQueryValueEx(_this->m_hRegKey, keyName, NULL, NULL, (LPBYTE)buf,
                            (LPDWORD)&dwbuflen) == ERROR_SUCCESS) {
          buf[255] = '\0';
          if (buf[0] != 0)
            SendMessage(hcombo, CB_INSERTSTRING, (WPARAM)listIndex++,
                        (LPARAM)buf);
        }
      }
      if (_this->m_pOpt->m_display[0] == '\0') {
        SendMessage(hcombo, CB_SETCURSEL, 0, 0);
        LRESULT r = SendMessage(hcombo, CB_GETLBTEXTLEN, 0, 0);
        if (r > 1 && r <= 256) {
          r = SendMessage(hcombo, CB_GETLBTEXT, 0, (LPARAM)buffer);
          if (r > 1)
            _this->m_pOpt->LoadOpt(buffer, KEY_VNCVIEWER_HISTORY);
        }
      } else {
        SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
      }

      UpdateConnectButton(hwnd);
      SetFocus(hcombo);
      return TRUE;
    }
    case WM_HELP:
      help.Popup(lParam);
      return 0;
    case WM_ACTIVATE:
    case WM_ACTIVATEAPP:
      if ((pApp->m_options.m_listening) ||
          (FindWindow("VNCviewer Daemon", 0) != NULL))
        EnableWindow(hListMode, FALSE);
      if ((!pApp->m_options.m_listening) &&
          (FindWindow("VNCviewer Daemon", 0) == NULL))
        EnableWindow(hListMode, TRUE);
      return 0;
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        case IDC_HOSTNAME_EDIT:
          switch (HIWORD(wParam)) {
            case CBN_SELENDOK:
            {
              int a = (int)SendMessage(hcombo, CB_GETCURSEL, 0, 0L);
              SendMessage(hcombo, CB_GETLBTEXT, a, (LPARAM)(int FAR*)buffer);
              _this->m_pOpt->LoadOpt(buffer, KEY_VNCVIEWER_HISTORY);
              EnableConnectButton(hwnd, TRUE);
              SetFocus(hcombo);
            }
            break;
            case CBN_EDITCHANGE:
              UpdateConnectButton(hwnd);
              break;
          }
          return TRUE;
        case IDC_LOAD:
        {
          char buf[80];
          buf[0] = '\0';
          if (_this->m_cc->LoadConnection(buf, true) != -1) {
            FormatDisplay(_this->m_cc->m_port, _this->m_pOpt->m_display,
                          _countof(_this->m_pOpt->m_display),
                          _this->m_cc->m_host);
            SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
          }
          UpdateConnectButton(hwnd);
          SetFocus(hcombo);
          return TRUE;
        }
        case IDC_LIST_MODE:
          pApp->m_options.LoadOpt(".listen", KEY_VNCVIEWER_HISTORY);
          pApp->m_options.m_listening = true;
          pApp->ListenMode();
          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, FALSE);
          return TRUE;
        case IDC_OK:
          char display[256];
          GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, display, 256);
          if (strlen(display) == 0)
            return TRUE;
          if (!ParseDisplay(display, _countof(display), tmphost,
                            _countof(tmphost), &_this->m_cc->m_port)) {
            MessageBox(NULL,
                "Invalid VNC server specified.\n\r"
                "Server should be of the form host:display.",
                "Connection setup", MB_OK | MB_ICONEXCLAMATION);
            return TRUE;
          } else {
            STRCPY(_this->m_cc->m_host, tmphost);
            STRCPY(_this->m_pOpt->m_display, display);
          }

          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, TRUE);
          return TRUE;
        case IDCANCEL:
          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, FALSE);
          return TRUE;
        case IDC_OPTIONBUTTON:
        {
          if (_this->m_pOpt->RaiseDialog())
            return TRUE;  // Options dialog already shown
          HWND hOptionButton = GetDlgItem(hwnd, IDC_OPTIONBUTTON);
          _this->m_pOpt->DoDialog();
          GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT,
                         _this->m_pOpt->m_display, 256);
          SendMessage(hcombo, CB_RESETCONTENT, 0, 0);
          int dwbuflen = 255;
          char valname[256];
          char buf[256];
          int maxEntries = pApp->m_options.m_historyLimit;
          for (i = 0; i < maxEntries; i++) {
            _itoa_s(i, valname, _countof(valname), 10);
            dwbuflen = 255;
            if (RegQueryValueEx(_this->m_hRegKey, (LPTSTR)valname, NULL, NULL,
                (LPBYTE)buf, (LPDWORD)&dwbuflen) != ERROR_SUCCESS)
              break;
            SendMessage(hcombo, CB_INSERTSTRING, (WPARAM)i,
                        (LPARAM)(int FAR*)buf);
          }
          SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
          SetFocus(hOptionButton);
          return TRUE;
        }
      }
    case WM_DESTROY:
      EndDialog(hwnd, FALSE);
      return TRUE;
  }
  return 0;
}
Exemplo n.º 8
0
void DrawInt(int i,int w, int h){
	_itoa_s (i,buffer,10);
	DrawString(buffer, w, h );
}
Exemplo n.º 9
0
int thxscan(FILE *fp, label_ent *label_tab, char file_name[10])
{
	char *o_ptr;
	char out_str[255];
	//char fname[256];
	char out_num[8];
	size_t i, IIPlen, ret_code;
	char upstream_name[255];	
	char upstream_port_name[255];
	int upstream_elem_no;
	char procname[255];	


	proc_ent *proc_curr;
	//	proc_ent *proc_new;
	//	proc_ent *proc_find;
	cnxt_ent *cnxt_tab;
	cnxt_ent *cnxt_curr;
	cnxt_ent *cnxt_new;
	cnxt_ent *cnxt_hold;

//	label_ent *label_new;

	//int label_ct;
	bool eq_arrow;
	IIP *IIP_ptr;

	char buffer[100];

	while (true) {
		if (NULL == fgets(buffer, 100, fp))
			goto finish;
		if (0 == strcmp(buffer, "INPORT") || 0 == strcmp(buffer, "OUTPORT"))
			continue;

		ret_code = 0;

		curr_char = getc(fp);
		proc_tab = 0;
		cnxt_tab = 0;
		label_curr = label_tab;

		strcpy_s(label_curr->label, " ");
		strcpy_s(label_curr->file, file_name);
		label_curr->ent_type = 'L';

		IIPlen = -1;
		out_num[0] = '\0';
		cnxt_hold = 0;

		scan_blanks(fp);

	netloop:
		TCO(X0, '\'');
		goto Xs;       // quote found - scan off rest of IIP
	X0:
		if (scan_sym(fp, out_str) != 0) {  // this could be a network label or a process name...
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}

		TCO(X2, ':');
		strcpy_s(label_curr->label, out_str);  // it was a label		  
		printf("Scanning Network: %s\n", out_str);
		scan_blanks(fp);

	bigloop:

		cnxt_hold = 0;
		IIPlen = -1;
		TCO(X1, '\'');
	Xs:
		o_ptr = out_str;
		goto get_rest_of_IIP;

	X1:
		if (scan_sym(fp, out_str) != 0) {  // this must be a process name...
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}
	X2:
		strcpy_s(procname, out_str);
		printf("Procname: %s\n", procname);
		if (cnxt_hold != 0) {
			strcpy_s(cnxt_hold->downstream_name, procname);
			cnxt_hold = 0;
		}

		proc_curr = find_or_build_proc(procname);

		if (4 == scan_blanks(fp))
			goto bigloop;

		goto X3;

	get_rest_of_IIP:
		TCO(tbsl, EOF);
		printf("EOF encountered within quoted string\n");
		ret_code = 4;
		goto exit;
	tbsl:
		TCO(tbq, '\\');
		CC;
		goto get_rest_of_IIP;
	tbq:
		TCO(copy, '\'');
		goto NQ2;
	copy:
		CC;
		goto get_rest_of_IIP;
	NQ2:
		*o_ptr = '\0';
		IIPlen = static_cast<int>(o_ptr - out_str);
		IIP_ptr = (IIP *)malloc(IIPlen + 1);
		memcpy(IIP_ptr->datapart, out_str, IIPlen);
		IIP_ptr->datapart[IIPlen] = '\0';
		printf("IIP: %s\n", IIP_ptr->datapart);
		scan_blanks(fp);
		//IIPlen = -1;
		goto tArrow;


		// scan off process name with optional component name

	X3:
		TCO(NB1, '(');
		scan_blanks(fp);
		TCO(rest_of_comp, ')');
		goto NN2;
	rest_of_comp:

		TCO(NQ6, '"');           // this says that comp name may be surrounded by double quotes (not included in comp_name)
	NQ6:
		o_ptr = comp_name;      // if no data between brackets, comp_name will not be modified...

	TB1:
		TCO(NQ7, '"');
		scan_blanks(fp);

	NQ7:
		TCO(NB2, ')');
		goto NN2;
	NB2:
		CC;
		goto TB1;

	NN2:
		*o_ptr = '\0';

		if (strlen(comp_name) > 0) {
			strcpy_s(proc_curr->comp_name, comp_name);
			printf("Comp name: %s\n", comp_name);
		}

	NB1:
		// comp scanned off, if any
		strcpy_s(upstream_name, procname);	    // in case this proc is the upstream of another arrow

		if (4 == scan_blanks(fp))
			goto bigloop;

		TCO(NQ1, '?');
		proc_curr->trace = 1;
		if (4 == scan_blanks(fp))
			goto bigloop;
	NQ1:

		TCO(tsc, EOF);
		eof_found = TRUE;
		goto nxtnet;

	tsc:
		TCO(tcom, ';');
		scan_blanks(fp);
	nxtnet:
		// this is a fudge because multiple nets are not currently supported 
		IIPlen = -1;

		TCO(nextnet, EOF);
		goto exit;

	tcom:

		IIPlen = -1;
		TCO(not_com, ',');

		scan_blanks(fp);
		goto bigloop;

	not_com:

		o_ptr = out_str;
		TC(outport, '*');     /* automatic port */
		*o_ptr = '\0';

		goto GUy;

	outport:
		if (scan_sym(fp, out_str) != 0) {
			printf("Name error\n");
			ret_code = 4;
			goto exit;
		}
	GUy:
		scan_blanks(fp);

		strcpy_s(upstream_port_name, out_str);
		printf("Upstream port: %s\n", out_str);
		upstream_elem_no = 0;
		TCO(tArrow, '[');
		o_ptr = out_num;
	GNx:
		TN(NNx);
		goto GNx;
	NNx:
		TCO(elemerr, ']');
		*o_ptr = '\0';
		upstream_elem_no = atoi(out_num);

	tArrow:
		scan_blanks(fp);
		eq_arrow = FALSE;
		TCO(tEq, '-');
		goto tGr;
	tEq:
		TCO(nArrow, '=');
		eq_arrow = TRUE;
	tGr:
		TCO(nArrow, '>');
		printf("Arrow\n");
		cnxt_new = (cnxt_ent *)malloc(sizeof(cnxt_ent));
		cnxt_new->succ = 0;
		cnxt_new->dropOldest = false;
		if (cnxt_tab == 0) {
			cnxt_tab = cnxt_new;
			label_curr->cnxt_ptr = cnxt_tab;
			cnxt_curr = cnxt_tab;
		}
		else {
			cnxt_curr->succ = cnxt_new;
			cnxt_curr = cnxt_new;
		}

		cnxt_hold = cnxt_new;
		if (IIPlen != -1) {
			strcpy_s(cnxt_hold->upstream_name, "!");
			cnxt_hold->upstream_port_name[0] = '\0';
			cnxt_hold->gen.IIPptr = IIP_ptr;
		}
		else {
			strcpy_s(cnxt_hold->upstream_name, upstream_name);
			strcpy_s(cnxt_hold->upstream_port_name, upstream_port_name);

			cnxt_hold->upstream_elem_no = upstream_elem_no;
		}
		cnxt_hold->capacity = -1;
		scan_blanks(fp);
		TCO(ncap, '(');
		o_ptr = out_num;
	GNz:
		TN(NNz);
		goto GNz;
	NNz:
		TCO(caperr, ')');
		*o_ptr = '\0';
		cnxt_hold->capacity = atoi(out_num);
		scan_blanks(fp);
		goto ncap;
	caperr:
		printf("Capacity error\n");
		ret_code = 4;
		goto exit;
	ncap:
		cnxt_hold->downstream_elem_no = 0;

		/* Scan off downstream port name */
		o_ptr = out_str;
		TC(Y2a, '*');       /* automatic port */
		*o_ptr = '\0';
		strcpy_s(cnxt_hold->downstream_port_name, out_str);  /* ext. conn */
		goto is_outport;
	Y2a:
		if (scan_sym(fp, out_str) != 0) {
			printf("Downstream port name error for %s %s\n",
				cnxt_hold->upstream_name,
				cnxt_hold->upstream_port_name);
			ret_code = 4;
			goto exit;
		}
		strcpy_s(cnxt_hold->downstream_port_name, out_str);

	is_outport:

		printf("Downstream port: %s\n", cnxt_hold->downstream_port_name);

		scan_blanks(fp);
		TCO(X1, '[');
		o_ptr = out_num;
	GNy:
		TN(NNy);
		goto GNy;
	NNy:
		TCO(elemerr, ']');
		*o_ptr = '\0';
		cnxt_hold->downstream_elem_no = atoi(out_num);
		//cnxt_hold = 0;
		scan_blanks(fp);
		goto X1;

	nextnet:
		scan_blanks(fp);

		if (eof_found) {
			label_curr->succ = 0;   // temporary fix as we are only generating one network for now
			goto exit;
		}

		goto netloop;


	elemerr:
		printf("Port element error\n");
		ret_code = 4;
		goto exit;

	nArrow:
		printf("No arrow found\n");
		ret_code = 4;
	exit:
		printf("\nSummary:\n");
		proc_curr = proc_tab;
		while (proc_curr != 0) {
			printf(" Process: %s (%s)\n", proc_curr->proc_name,
				proc_curr->comp_name);
			proc_curr = proc_curr->succ;
		}

		cnxt_hold = cnxt_tab;
		while (cnxt_hold != 0) {
			char up[200];
			char down[200];
			char elem[20];
			if (cnxt_hold->upstream_name[0] != '!') {
				strcpy_s(up, cnxt_hold->upstream_port_name);
				if (up[0] != '*') {
					strcat_s(up, "[");
					_itoa_s(cnxt_hold->upstream_elem_no, elem, 10);
					strcat_s(up, elem);
					strcat_s(up, "]");
				}
				strcpy_s(down, cnxt_hold->downstream_port_name);
				if (down[0] != '*') {
					strcat_s(down, "[");
					_itoa_s(cnxt_hold->downstream_elem_no, elem, 10);
					strcat_s(down, elem);
					strcat_s(down, "]");
				}
				printf(" Connection: %s %s -> %s %s\n",
					cnxt_hold->upstream_name,
					up,
					down,
					cnxt_hold->downstream_name);
			}
			else {
				strcpy_s(down, cnxt_hold->downstream_port_name);
				if (down[0] != '*') {
					strcat_s(down, "[");
					_itoa_s(cnxt_hold->downstream_elem_no, elem, 10);
					strcat_s(down, elem);
					strcat_s(down, "]");
				}
				printf(" IIP: -> %s %s\n",
					down,
					cnxt_hold->downstream_name);
				IIP_ptr = cnxt_hold->gen.IIPptr;
				printf("    \'");
				auto j = strlen(IIP_ptr->datapart);
				for (i = 0; i < j; i++)
					printf("%c", IIP_ptr->datapart[i]);
				printf("\'\n");
			}
			cnxt_hold = cnxt_hold->succ;
		}
	 
	}
	finish:
	if (fclose(fp) != 0) {
		printf("Close error\n");
		if (ret_code == 0)
			ret_code = 2;
	}
	if (ret_code > 0) {
		// printf("Scan error\n");
		return(ret_code);
	}
	
	// printf("Scan finished\n");
	return (ret_code);
}
Exemplo n.º 10
0
// **************************************************************************
//
//	ErrorString()
//
// Description:
//		Converts an HRESULT to a displayable string.
//
// Parameters:
//		hRes (in) - HRESULT to be converted.
//
// Returns:
//		ptr to displayable string.
//
// Globals accessed:
//		None.
//
// Globals modified:
//		None.
//
//===========================================================================
LPCTSTR CConsumer::ErrorString(HRESULT hRes)
{
    TCHAR szBuffer2[19];
	static TCHAR szBuffer[24];
	LPCTSTR psz;

    switch(hRes) 
    {
    case WBEM_NO_ERROR:
		psz = _T("WBEM_NO_ERROR");
		break;
    case WBEM_S_FALSE:
		psz = _T("WBEM_S_FALSE");
		break;
    case WBEM_S_NO_MORE_DATA:
		psz = _T("WBEM_S_NO_MORE_DATA");
		break;
	case WBEM_E_FAILED:
		psz = _T("WBEM_E_FAILED");
		break;
	case WBEM_E_NOT_FOUND:
		psz = _T("WBEM_E_NOT_FOUND");
		break;
	case WBEM_E_ACCESS_DENIED:
		psz = _T("WBEM_E_ACCESS_DENIED");
		break;
	case WBEM_E_PROVIDER_FAILURE:
		psz = _T("WBEM_E_PROVIDER_FAILURE");
		break;
	case WBEM_E_TYPE_MISMATCH:
		psz = _T("WBEM_E_TYPE_MISMATCH");
		break;
	case WBEM_E_OUT_OF_MEMORY:
		psz = _T("WBEM_E_OUT_OF_MEMORY");
		break;
	case WBEM_E_INVALID_CONTEXT:
		psz = _T("WBEM_E_INVALID_CONTEXT");
		break;
	case WBEM_E_INVALID_PARAMETER:
		psz = _T("WBEM_E_INVALID_PARAMETER");
		break;
	case WBEM_E_NOT_AVAILABLE:
		psz = _T("WBEM_E_NOT_AVAILABLE");
		break;
	case WBEM_E_CRITICAL_ERROR:
		psz = _T("WBEM_E_CRITICAL_ERROR");
		break;
	case WBEM_E_INVALID_STREAM:
		psz = _T("WBEM_E_INVALID_STREAM");
		break;
	case WBEM_E_NOT_SUPPORTED:
		psz = _T("WBEM_E_NOT_SUPPORTED");
		break;
	case WBEM_E_INVALID_SUPERCLASS:
		psz = _T("WBEM_E_INVALID_SUPERCLASS");
		break;
	case WBEM_E_INVALID_NAMESPACE:
		psz = _T("WBEM_E_INVALID_NAMESPACE");
		break;
	case WBEM_E_INVALID_OBJECT:
		psz = _T("WBEM_E_INVALID_OBJECT");
		break;
	case WBEM_E_INVALID_CLASS:
		psz = _T("WBEM_E_INVALID_CLASS");
		break;
	case WBEM_E_PROVIDER_NOT_FOUND:
		psz = _T("WBEM_E_PROVIDER_NOT_FOUND");
		break;
	case WBEM_E_INVALID_PROVIDER_REGISTRATION:
		psz = _T("WBEM_E_INVALID_PROVIDER_REGISTRATION");
		break;
	case WBEM_E_PROVIDER_LOAD_FAILURE:
		psz = _T("WBEM_E_PROVIDER_LOAD_FAILURE");
		break;
	case WBEM_E_INITIALIZATION_FAILURE:
		psz = _T("WBEM_E_INITIALIZATION_FAILURE");
		break;
	case WBEM_E_TRANSPORT_FAILURE:
		psz = _T("WBEM_E_TRANSPORT_FAILURE");
		break;
	case WBEM_E_INVALID_OPERATION:
		psz = _T("WBEM_E_INVALID_OPERATION");
		break;
	case WBEM_E_INVALID_QUERY:
		psz = _T("WBEM_E_INVALID_QUERY");
		break;
	case WBEM_E_INVALID_QUERY_TYPE:
		psz = _T("WBEM_E_INVALID_QUERY_TYPE");
		break;
	case WBEM_E_ALREADY_EXISTS:
		psz = _T("WBEM_E_ALREADY_EXISTS");
		break;
    case WBEM_S_ALREADY_EXISTS:
        psz = _T("WBEM_S_ALREADY_EXISTS");
        break;
    case WBEM_S_RESET_TO_DEFAULT:
        psz = _T("WBEM_S_RESET_TO_DEFAULT");
        break;
    case WBEM_S_DIFFERENT:
        psz = _T("WBEM_S_DIFFERENT");
        break;
    case WBEM_E_OVERRIDE_NOT_ALLOWED:
        psz = _T("WBEM_E_OVERRIDE_NOT_ALLOWED");
        break;
    case WBEM_E_PROPAGATED_QUALIFIER:
        psz = _T("WBEM_E_PROPAGATED_QUALIFIER");
        break;
    case WBEM_E_PROPAGATED_PROPERTY:
        psz = _T("WBEM_E_PROPAGATED_PROPERTY");
        break;
    case WBEM_E_UNEXPECTED:
        psz = _T("WBEM_E_UNEXPECTED");
        break;
    case WBEM_E_ILLEGAL_OPERATION:
        psz = _T("WBEM_E_ILLEGAL_OPERATION");
        break;
    case WBEM_E_CANNOT_BE_KEY:
        psz = _T("WBEM_E_CANNOT_BE_KEY");
        break;
    case WBEM_E_INCOMPLETE_CLASS:
        psz = _T("WBEM_E_INCOMPLETE_CLASS");
        break;
    case WBEM_E_INVALID_SYNTAX:
        psz = _T("WBEM_E_INVALID_SYNTAX");
        break;
    case WBEM_E_NONDECORATED_OBJECT:
        psz = _T("WBEM_E_NONDECORATED_OBJECT");
        break;
    case WBEM_E_READ_ONLY:
        psz = _T("WBEM_E_READ_ONLY");
        break;
    case WBEM_E_PROVIDER_NOT_CAPABLE:
        psz = _T("WBEM_E_PROVIDER_NOT_CAPABLE");
        break;
    case WBEM_E_CLASS_HAS_CHILDREN:
        psz = _T("WBEM_E_CLASS_HAS_CHILDREN");
        break;
    case WBEM_E_CLASS_HAS_INSTANCES:
        psz = _T("WBEM_E_CLASS_HAS_INSTANCES");
        break;
    case WBEM_E_QUERY_NOT_IMPLEMENTED:
        psz = _T("WBEM_E_QUERY_NOT_IMPLEMENTED");
        break;
    case WBEM_E_ILLEGAL_NULL:
        psz = _T("WBEM_E_ILLEGAL_NULL");
        break;
    case WBEM_E_INVALID_QUALIFIER_TYPE:
        psz = _T("WBEM_E_INVALID_QUALIFIER_TYPE");
        break;
    case WBEM_E_INVALID_PROPERTY_TYPE:
        psz = _T("WBEM_E_INVALID_PROPERTY_TYPE");
        break;
    case WBEM_E_VALUE_OUT_OF_RANGE:
        psz = _T("WBEM_E_VALUE_OUT_OF_RANGE");
        break;
    case WBEM_E_CANNOT_BE_SINGLETON:
        psz = _T("WBEM_E_CANNOT_BE_SINGLETON");
        break;
	default:
        _itoa_s(hRes, szBuffer2, 16);
	  StringCbCopy(szBuffer, sizeof(szBuffer),_T("0x"));
      StringCbCat(szBuffer, sizeof(szBuffer), szBuffer2);
	  psz = szBuffer;
	}
	return psz;
}
Exemplo n.º 11
0
void MorphTargets::LoadAnimations(void)
{
    double time = glfwGetTime();

    static const char *folder = "Resources/Animations/";
    char currentIndex[256] = "";

    std::vector<OBJModel> idle;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "IdleAnimation/idle");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath,".obj");

        idle.push_back(OBJModel(filePath, false));
    }

    animations.push_back(idle);

    std::vector<OBJModel> move;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "RunAnimation/run");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        move.push_back(OBJModel(filePath, false));
    }

    animations.push_back(move);

    std::vector<OBJModel> punch;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "PunchAnimation/punch");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        punch.push_back(OBJModel(filePath, false));
    }

    animations.push_back(punch);

    std::vector<OBJModel> block;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "BlockAnimation/block");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        block.push_back(OBJModel(filePath, false));
    }

    animations.push_back(block);

    std::vector<OBJModel> stagger;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "StaggerAnimation/stagger");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        stagger.push_back(OBJModel(filePath, false));
    }

    animations.push_back(stagger);

    std::vector<OBJModel> groundKick;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "GroundKickAnimation/groundkick");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        groundKick.push_back(OBJModel(filePath, false));
    }

    animations.push_back(groundKick);

    std::vector<OBJModel> airKick;
    for (unsigned int i = 1; i <= 10; ++i)
    {
        char filePath[256] = "";

        //Load the file
        strcat_s(filePath, folder);
        strcat_s(filePath, "DiveKickAnimation/divekick");
        _itoa_s(i, currentIndex, 10);
        strcat_s(filePath, currentIndex);
        strcat_s(filePath, ".obj");

        airKick.push_back(OBJModel(filePath, false));
    }

    animations.push_back(airKick);
}
Exemplo n.º 12
0
string intToStr(int value)
{
	char buffer[32];
	_itoa_s(value, buffer, sizeof(buffer), 10);
	return buffer;
}
Exemplo n.º 13
0
int ScreenShot()
{
  if (n > 1000)
    return 1;

  // we will store the image data here
  unsigned char *pixels;
  // the thingy we use to write files
  FILE * shot;
  // we get the width/height of the screen into this array
  int screenStats[4] = {0, 0, width, height};

  // get the width/height of the window
  //glGetIntegerv(GL_VIEWPORT, screenStats);

  // generate an array large enough to hold the pixel data 
  // (width*height*bytesPerPixel)
  pixels = new unsigned char[screenStats[2]*screenStats[3]*3];
  // read in the pixel data, TGA's pixels are BGR aligned
  glReadPixels(0, 0, screenStats[2], screenStats[3], 0x80E0, //GL_BGR=0x80E0
      GL_UNSIGNED_BYTE, pixels);

  // open the file for writing. If unsucessful, return 1
  char path[] = "screenshots/frame000.tga";

  _itoa_s(n, path+(n < 10? 19 : n < 100? 18 : 17), 4, 10);
  path[20] = '.';
  path[21] = 't';
  path[22] = 'g';
  if((fopen_s(&shot, path, "wb")) != 0) return 1;
  n++;

  // this is the tga header it must be in the beginning of 
  // every (uncompressed) .tga
  unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
  // the header that is used to get the dimensions of the .tga
  // header[1]*256+header[0] - width
  // header[3]*256+header[2] - height
  // header[4] - bits per pixel
  // header[5] - ?
  unsigned char header[6]={((int)(screenStats[2]%256)),
    ((int)(screenStats[2]/256)),
    ((int)(screenStats[3]%256)),
    ((int)(screenStats[3]/256)),24,0};

  // write out the TGA header
  fwrite(TGAheader, sizeof(unsigned char), 12, shot);
  // write out the header
  fwrite(header, sizeof(unsigned char), 6, shot);
  // write the pixels
  fwrite(pixels, sizeof(unsigned char), 
      screenStats[2]*screenStats[3]*3, shot);

  // close the file
  fclose(shot);
  // ROT the memory
  delete [] pixels;

  // return success
  return 0;
}
Exemplo n.º 14
0
long tcp_connect(bmdnet_handler_ptr handler,char*host,long port)
{
	long status;
#ifndef _WIN32
	char aux[256];
	struct sockaddr_in serv_addr;
	struct hostent hostinfo_buf;
	struct hostent *hostinfo=&hostinfo_buf;
	long one = 1;
	int si_temp; /* to musi byc int - nie zmieniac !!!! */
#else
	struct addrinfo *result = NULL, hints;
	char * portstr=NULL;
#endif
	if (host == NULL || port == 0 || port > 65535)
	{
		return(-1);
	}

	handler->s = (long)socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
	if (handler->s <= 0)
		return -1;

#ifndef WIN32
	if (setsockopt(handler->s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)))
	{
		return ERR(ERR_net, "Cannot set SO_REUSEADDR flag on socket", "LK");
	}
	memset(&serv_addr, 0, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = htons((short)port);

	if( gethostbyname_r(host, &hostinfo_buf, aux, sizeof(aux), &hostinfo, &si_temp) != 0 )
	{
		PRINT_ERROR("gethostbyname_r failed.\n");
		return(-1);
	}
	if (hostinfo==NULL) {
		PRINT_ERROR("Hostname not found.\n");
		return(-1);
	}
	serv_addr.sin_addr=*(struct in_addr *)hostinfo->h_addr;
	status = connect(handler->s, (const struct sockaddr *)&serv_addr,sizeof(serv_addr));
	if (status)
	{
		PRINT_ERROR("Cannot connect to host.\n");
		return(-1);
	}
#else
	ZeroMemory( &hints, sizeof(hints) );
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;
	portstr = calloc(6,sizeof(char));
	_itoa_s(port, portstr, 6,10);
	status = getaddrinfo(host, portstr, &hints, &result);
	if( status == WSAHOST_NOT_FOUND )
	{
		BMD_FOK(BMD_ERR_NET_RESOLV);
	}
	else
		if( status != 0 )
		{
			BMD_FOK(BMD_ERR_OP_FAILED);
		}
	if (result == NULL)
	{
		BMD_FOK(BMD_ERR_OP_FAILED);
	}
	status = connect(handler->s, result->ai_addr,(long)result->ai_addrlen);
	if (status)
	{
		PRINT_ERROR("Cannot connect to host.\n");
		return(-1);
	}
#endif

	return BMD_OK;
};
Exemplo n.º 15
0
/************************************************************************\
通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。
输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。
补充说明:
1、操作数为正整数,不需要考虑计算结果溢出的情况。
2、若输入算式格式错误,输出结果为“0”。
【输入】 pInputStr:  输入字符串
lInputLen:  输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例
输入:“4 + 7”  输出:“11”
输入:“4 - 7”  输出:“-3”
输入:“9 ++ 7”  输出:“0” 注:格式错误
\************************************************************************/
void CharIntegerOperation(const char *pInputStr, long lInputLen, char *pOutputStr)
{
	int i, am(0);
	for (i = 0; i<lInputLen; i++)
	{
		switch (pInputStr[i])
		{
		case '+': am = 1;
			break;
		case '-': am = 2;
			break;
		}
		if (am != 0) break;
	}
	if (pInputStr[i - 1] != ' ' && pInputStr[i + 1] != ' ')
	{
		pOutputStr[0] = '0';
		pOutputStr[1] = '\0';
		return;
	}
	int mid(i), a1(0), a2, b1, b2(lInputLen - 1);
	for (i = 0; i <= mid; i++)
	{
		if (pInputStr[i] == ' '){
			a2 = i - 1;
			break;
		}
	}
	for (i = mid + 1; i<lInputLen; i++)
	{
		if (pInputStr[i] != ' '){
			b1 = i;
			break;
		}
	}

	int n1(0), n2(0);
	for (i = a1; i <= a2; i++)
	{
		if (pInputStr[i] >= '0' && pInputStr[i] <= '9')
			n1 = n1 * 10 + pInputStr[i] - '0';
		else{
			pOutputStr[0] = '0';
			pOutputStr[1] = '\0';
			return;
		}
	}
	for (i = b1; i <= b2; i++)
	{
		if (pInputStr[i] >= '0' && pInputStr[i] <= '9')
			n2 = n2 * 10 + pInputStr[i] - '0';
		else{
			pOutputStr[0] = '0';
			pOutputStr[1] = '\0';
			return;
		}
	}

	int res(0);
	switch (am)
	{
	case 1: res = n1 + n2;
		break;
	case 2: res = n1 - n2;
		break;
	}
	char buffer[20];
	_itoa_s(res, buffer, 10);
	strcpy_s(pOutputStr,10, buffer);
}
Exemplo n.º 16
0
bool XMLProcessor::process_node(bool hasReferTable, xml_node* currentNode, string referTableName, string referColumn, string referPrimaryKey)
{
	vector<xml_node> childnodesVecs;
	vector<pair<string, string>> columnNameandValues;
	string trueTableName;
	string originalTrueTableName = DBStringProcessor::getOriginalTrueTableName(currentNode->name());
	string hashTableValue = returnHashString(*currentNode);
	string mainKeyValue = "-1";
	for (xml_node_iterator it = currentNode->begin(); it != currentNode->end(); ++it)
	{
		if (it->first_child().name() == "")
		{
			string column_name = DBStringProcessor::getOriginalTrueTableName(it->name());
			cout << "name: " << it->name() << endl;
			string column_value = it->child_value();
			columnNameandValues.push_back(make_pair(column_name, column_value));
		}
		else
		{
			cout << it->name() << endl;
			childnodesVecs.push_back(*it);
		}
	}
	vector<string> columnVec;
	if (columnNameandValues.size() > 0)
	{
		for (vector<pair<string, string>>::iterator it = columnNameandValues.begin(); it != columnNameandValues.end(); it++)
		{
			columnVec.push_back(it->first);
		}
	}
	if (nodeToDBName[hashTableValue] == "")//if there is no corresponding table in database
	{
		if (currentNode->name() != "")//make sure it is not the root node
		{
			countSameNode[originalTrueTableName]++;//true name of table plus 1
			char str[10];
			_itoa_s(countSameNode[originalTrueTableName], str, 10);
			cout << originalTrueTableName + "_" + string(str) << endl;
			trueTableName = DBStringProcessor::getLowerCaseString(originalTrueTableName + "_" + string(str));
			nodeToDBName[hashTableValue] = trueTableName;
			dbConnect.insertTableOfHashNametoTrueName(hashTableValue, originalTrueTableName, string(str));
			cout << "Table " + trueTableName << " has not been created in database" << endl;
			if (hasReferTable)
			{
				dbConnect.createTable(hasReferTable, trueTableName, columnVec, referTableName, DBStringProcessor::getMainKeyString(referTableName));
			}
			else
			{
				dbConnect.createTable(hasReferTable, trueTableName, columnVec);
			}
		}
		else
		{
			cout << "Processing the root node!" << endl;
		}
	}
	else
	{
		cout << "Table " + trueTableName + " has already been created in database" << endl;
	}
	trueTableName = nodeToDBName[hashTableValue];
	if (currentNode->name() != "")
	{
		if (hasReferTable)
		{
			string referColumn = DBStringProcessor::getMainKeyString(referTableName);
			dbConnect.insertIntoTableandReturnMainKey(hasReferTable, trueTableName, columnNameandValues, mainKeyValue, referTableName, referColumn, referPrimaryKey);
		}
		else
		{
			dbConnect.insertIntoTableandReturnMainKey(hasReferTable, trueTableName, columnNameandValues, mainKeyValue);
		}
	}
	for (int index = 0; index < childnodesVecs.size(); index++)
	{
		string childTableName = DBStringProcessor::getOriginalTrueTableName(childnodesVecs[index].name());
		if (currentNode->name() != "")
			process_node(true, &childnodesVecs[index], trueTableName, DBStringProcessor::getMainKeyString(trueTableName), mainKeyValue);
		else
			process_node(false, &childnodesVecs[index]);
	}
	return true;
}
Exemplo n.º 17
0
/*******************************************************************************
  Function Name  : CFormatMsgEthernet
  Input(s)       : -
  Output         : -
  Functionality  : Format Ethernet data bytes
  Member of      : CFormatMsgEthernet
  Author(s)      : Ashwin R Uchil
  Date Created   : 5.6.2014
  Modifications  : 
*******************************************************************************/
void CFormatMsgEthernet::vFormatEthernetDataMsg(STETHERNETDATA* pMsgEthernet,
                           SFORMATTEDDATA_ETHERNET* CurrDataEthernet,
                           BYTE bExprnFlag_Log)
{
    if (RX_FLAG == pMsgEthernet->m_ucDataType)
    {
        CurrDataEthernet->m_eDirection = DIR_RX;
        CurrDataEthernet->m_acMsgDir[0] = _T('R');
    }
    else if (TX_FLAG == pMsgEthernet->m_ucDataType)
    {
        CurrDataEthernet->m_eDirection = DIR_TX;
        CurrDataEthernet->m_acMsgDir[0] = _T('T');
    }
    CurrDataEthernet->m_acMsgDir[1] = _T('x');

    //TYPE_CHANNEL CurrChannel = pMsgEthernet->m_uDataInfo.m_sCANMsg.m_ucChannel;  // Assuming default CAN msg
    //if (pMsgCAN->m_uDataInfo.m_sCANMsg.m_bCANFD) // Incase of CANFD msg
    //{
    //    CurrChannel = pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucChannel;
    //}

    //if ((CurrChannel >= CHANNEL_CAN_MIN) && (CurrChannel <= CHANNEL_CAN_MAX ))
	//{
	//    sprintf_s(CurrDataCAN->m_acChannel, "%d", CurrChannel);
	//}

	char chSrcMAC[12], chDestMAC[12];
	_itoa_s(pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unDataLen, CurrDataEthernet->m_acDataLen, 10);

	memcpy(chSrcMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucSourceMAC, 12);
	sprintf(CurrDataEthernet->m_SourceMAC, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c\0",
		chSrcMAC[0],chSrcMAC[1],chSrcMAC[2],chSrcMAC[3],chSrcMAC[4],chSrcMAC[5],chSrcMAC[6],chSrcMAC[7],chSrcMAC[8],chSrcMAC[9],chSrcMAC[10],chSrcMAC[11]);

	memcpy(chDestMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestMac, 12);
	sprintf(CurrDataEthernet->m_DestMAC, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c\0",
		chDestMAC[0],chDestMAC[1],chDestMAC[2],chDestMAC[3],chDestMAC[4],chDestMAC[5],chDestMAC[6],chDestMAC[7],chDestMAC[8],chDestMAC[9],chDestMAC[10],chDestMAC[11]);
	
	//strcpy(CurrDataEthernet->m_DestMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestMac);
	memcpy(CurrDataEthernet->m_SourceIP, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucSourceIP, 15);
	memcpy(CurrDataEthernet->m_DestIP,  (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestIP, 15);
	
	memcpy(CurrDataEthernet->m_acMsgDesc, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucName, 100);

	//strcpy_s(CurrDataEthernet->m_acMsgDesc, LENGTH_STR_DESCRIPTION_CAN, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucName);
	CurrDataEthernet->m_u64TimeStamp = pMsgEthernet->m_lTickCount.QuadPart;
	CurrDataEthernet->m_dwMsgID = pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unMsgID;
	CurrDataEthernet->m_nDataLength = pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unDataLen;

	memcpy(CurrDataEthernet->m_abData, pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucData,
		CurrDataEthernet->m_nDataLength);


	/*PROCESS ERROR MSGS: If Error Message type. Change the data and type fields. */
	//if(ERR_FLAG == pMsgCAN->m_ucDataType)
	//{
	//    USHORT usErrCode = usProcessCurrErrorEntry(pMsgCAN->m_uDataInfo.m_sErrInfo);

    //    if( usErrCode != ERROR_UNKNOWN )
    //    {
    //        // Format error message
    //        char* ptrStrErrName = NULL;
    //        ptrStrErrName = vFormatCurrErrorEntry(usErrCode);

    //        if(ptrStrErrName)
    //        {
    //            strcpy_s(CurrDataCAN->m_acDataDec, LENGTH_STR_DATA_CAN, ptrStrErrName);
    //            strcpy_s(CurrDataCAN->m_acDataHex, LENGTH_STR_DATA_CAN, ptrStrErrName);
    //        }
    //    }

    //    CurrDataCAN->m_dwMsgID = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID;
    //    sprintf_s(CurrDataCAN->m_acMsgIDDec, FORMAT_STR_ID_DEC, CurrDataCAN->m_dwMsgID);
    //    strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_CAN, "ERR");
    //}

    /* PROCESS ERROR MSGS ENDS */
    vFormatTime(bExprnFlag_Log, CurrDataEthernet);
    vFormatDataAndId(bExprnFlag_Log, CurrDataEthernet);
}
Exemplo n.º 18
0
void fillDialog(HWND hwnd, JABIA_Character * ptr) {
	char buf[100];
	JABIA_Character character;
	if(ptr != NULL) {
		memcpy(&character, (void *)ptr, sizeof(JABIA_Character));		

		// address of character
		_itoa_s((uint32_t)ptr, buf, 100, 16);
		SetDlgItemText(hwnd, IDC_ADDRESS, buf);	

		_itoa_s(character.level, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_LEV, buf);

		_itoa_s(character.experience, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_EX, buf);

		_itoa_s(character.training_points, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_TP, buf);

		_itoa_s(character.inventory.weapon_in_hand, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_WPN_EQ, buf);

		_itoa_s(character.inventory.weapon_in_hand_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_WPN_EQ_DUR, buf);

		_itoa_s(character.inventory.helmet_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_HELM_EQ, buf);

		_itoa_s(character.inventory.helmet_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_HELM_EQ_DUR, buf);

		_itoa_s(character.inventory.eyewear_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_EYE_EQ, buf);

		_itoa_s(character.inventory.eyewear_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_EYE_EQ_DUR, buf);

		_itoa_s(character.inventory.special_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SPC_EQ, buf);

		_itoa_s(character.inventory.special_equiped_charges, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SPC_EQ_LEFT, buf);

		_itoa_s(character.inventory.shirt_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SHRT_EQ, buf);

		_itoa_s(character.inventory.shirt_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SHRT_EQ_DUR, buf);

		_itoa_s(character.inventory.vest_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_VEST_EQ, buf);

		_itoa_s(character.inventory.vest_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_VEST_DUR, buf);

		_itoa_s(character.inventory.shoes_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SHOES_EQ, buf);

		_itoa_s(character.inventory.shoes_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_SHOES_DUR, buf);

		_itoa_s(character.inventory.pants_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_PANTS_EQ, buf);

		_itoa_s(character.inventory.pants_equiped_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_PANTS_DUR, buf);

		_itoa_s(character.inventory.ammo_equiped, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_AMMO_EQ, buf);

		_itoa_s(character.inventory.ammo_equiped_count, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_AMMO_EQ_CNT, buf);

		_itoa_s(character.inventory.ammo_equiped_count, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_AMMO_EQ_CNT, buf);

		_itoa_s(character.inventory.weapon_attachment_removable, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_WPN_MOD, buf);

		// health and stamina 	
		sprintf_s(buf, "%.1f", character.health, 4);
		//OutputDebugString(buf);
		SetDlgItemText(hwnd, IDC_HLTH, buf);

		sprintf_s(buf, "%.1f", character.stamina, 4);
		SetDlgItemText(hwnd, IDC_STAMINA, buf);

		// name
		memset(buf, 0x00, 16);
		memcpy(buf, character.merc_name, character.name_length);
		SetDlgItemText(hwnd, IDC_MERC_NAME, buf);

		_itoa_s(character.faction, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_MERC_FAC, buf);

		_itoa_s(character.medical_condition, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_MED_COND, buf);

		// inventory
		_itoa_s(character.inventory.weapons[last_weaponslot_selected_index].weapon, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_WPN_INV, buf);

		_itoa_s(character.inventory.weapons[last_weaponslot_selected_index].weapon_durability, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_WPN_INV_DUR, buf);

		_itoa_s(character.inventory.weapons[last_weaponslot_selected_index].ammo_count, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_AMMO_INV_CNT, buf);

		_itoa_s(character.inventory.inventory_items[last_inventory_selected_index].item_id, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_INV_ITEM_ID, buf);

		// attributes
		_itoa_s(character.agility, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_AG, buf);

		_itoa_s(character.dexterity, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_DEX, buf);

		_itoa_s(character.strength, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_STR, buf);

		_itoa_s(character.intelligence, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_INT, buf);

		_itoa_s(character.perception, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_PER, buf);

		// skills

		_itoa_s(character.medical, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_MED, buf);

		_itoa_s(character.explosives, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_EXPL, buf);

		_itoa_s(character.marksmanship, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_MARK, buf);

		_itoa_s(character.stealth, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_STEALTH, buf);

		_itoa_s(character.mechanical, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_MECH, buf);

		_itoa_s(character.bleed_rate, buf, 100, 10);
		SetDlgItemText(hwnd, IDC_BLEED_RATE, buf);
	}	
}
Exemplo n.º 19
0
int main(int argc, char* argv[]) {
	srand (time(NULL));
	//------------Init SDL---------------------------
	//-----------------------------------------------
	SDL_Window* win;
	SDL_Renderer* ren;
	
	if(!Init(&win, &ren)) {
		if(ren) {
			SDL_DestroyRenderer(ren);
		}
		if(win) {
			SDL_DestroyWindow(win);
		}
		return -1;
	}


	//------------    Init Resources    --------------
	//-------------------------------------------------
	ResourceManager res(ren);
	Texture bull = res.getTexture("bull.bmp");
	Texture cow = res.getTexture("cow.bmp");
	Texture hint;
	TTF_Font* font72 = TTF_OpenFont("asta.ttf", 72);
	TTF_Font* font28 = TTF_OpenFont("asta.ttf", 28);

	CLEANUP_AND_EXIT(res.HasFailed() || !font72 || !font28);

	Texture digit_textures[10];
	for(int i = 0; i < 10; ++i) {
		char digit_buffer[2];
		_itoa_s(i, digit_buffer, 10);
		Texture d = RenderText(ren, digit_buffer, font72);
		CLEANUP_AND_EXIT(!d.ptr);

		digit_textures[i] = d;
		//this will release the texture at the end of program
		res.addTexture(digit_buffer, d);
	}

	//Initialize the description text
	{
		char* desc_text = "Use arrows to change the numbers and \"C\" to check your answer.";
		hint = RenderText(ren, desc_text, font28);
		CLEANUP_AND_EXIT(!hint.ptr);
		res.addTexture("InfoText", hint);
	}

	TTF_CloseFont(font72);
	TTF_CloseFont(font28);

	//------------Main Loop-------------------------
	//----------------------------------------------
	bool done = false;
	SDL_Event e;
	int base = (int)pow(10, secret_number_digits-1);

	char secret_number[secret_number_digits];
	char guess_number[secret_number_digits];

	//Fill in the numbers from above
	GenerateSecretNumber(secret_number);
	for(int i = 0; i < secret_number_digits; ++i) {
		guess_number[i] = i+1;
	}

	int bull_count = secret_number_digits;
	int cow_count = secret_number_digits;
	int selected = 0;
	while( !done ) {
		//Poll events
		while(SDL_PollEvent(&e)) {
			if(e.type == SDL_QUIT) 
				done = true;
			if(e.type == SDL_KEYDOWN) {
				switch( e.key.keysym.sym ) {
				case SDLK_UP:
					guess_number[selected] = std::min(guess_number[selected] + 1, 9); break;
				case SDLK_DOWN:
					guess_number[selected] = std::max(guess_number[selected] - 1, 0); break;
				case SDLK_LEFT:
					selected = std::max(selected - 1, 0); break;
				case SDLK_RIGHT:
					selected = std::min(selected + 1, secret_number_digits-1); break;
				case SDLK_c:
					UpdateBullsAndCows(guess_number, secret_number, &bull_count, &cow_count);
				}
			}
		}
		

		//--------------RENDERING-------------
		SDL_Rect rect;
		SDL_SetRenderDrawColor( ren, 0xFF, 0xFF, 0xFF, 0xFF );
		SDL_RenderClear(ren);

		//Render the images(bulls + cows)
		RenderImageRow(ren, bull.ptr, bull_count, IMG_SIZE, GLOBAL_X_OFFSET, 200);
		RenderImageRow(ren, cow.ptr, cow_count, IMG_SIZE, GLOBAL_X_OFFSET, 300);


		int digit_position_offset = GLOBAL_X_OFFSET + secret_number_digits * (IMG_SIZE + IMG_SPACING_PIXELS);

		//Render the red background behind the selected digit
		rect.x = digit_position_offset + DIGIT_SPACING_PIXELS * selected;
		rect.y = 250;
		rect.w = digit_textures[guess_number[selected]].width;
		rect.h = digit_textures[guess_number[selected]].height;
		SDL_SetRenderDrawColor( ren, 0xFF, 0x00, 0x00, 0xFF );
		SDL_RenderFillRect( ren, &rect );

		//Render the digits
		for(int i = 0; i < secret_number_digits; ++i) {
			int digit = guess_number[i];
			rect.x = digit_position_offset + DIGIT_SPACING_PIXELS * i;
			rect.y = 250;
			rect.w = digit_textures[digit].width;
			rect.h = digit_textures[digit].height;
			SDL_RenderCopy(ren, digit_textures[digit].ptr, 0, &rect);
		}

		//Draw description text
		rect.x = 40;
		rect.y = 400;
		rect.w = hint.width;
		rect.h = hint.height;
		SDL_RenderCopy(ren, hint.ptr, 0, &rect);
		SDL_RenderPresent(ren);
	}


	CLEANUP_AND_EXIT(true);
	return 0;
}
void  User_Interface::run()
{
	switch (this->status){

	case OUTPUT_DATA:
		{
			int max = this->calcMtrl->size();
			for (unsigned int i = 0; i < max; i++)
			{
				this->calcMtrl->pop_back();
			}
			this->redraw_window();
			this->type_build_box->set_top_index(0);
			this->num_floors_edit->set_text("");
			this->length_edit->set_text("");
			this->width_edit->set_text("");
			this->mat_fund_box->set_top_index(0);
			this->mat_wall_box->set_top_index(0);
			this->mat_roof_box->set_top_index(0);
			//this->mat_panel_box->set_top_index(0);

			this->enable_all(true);
			this->OK_button->set_text("Расчет");

			this->OK_button->show(SW_SHOW);
			this->show(SW_SHOW);
			this->status = INPUT_DATA;
			break;
		}

		case INPUT_DATA:
		{
			if (!this->materials->empty()){
				int type_build = this->type_build_box->get_top_index();

				int num_floors = _ttoi(this->num_floors_edit->get_text());
				double length = _ttof(this->length_edit->get_text());
				double width = _ttof(this->width_edit->get_text());

				int mat_fund = this->mat_fund_box->get_id_top_material();
				
				int mat_wall = this->mat_wall_box->get_id_top_material();
				
				int mat_roof = this->mat_roof_box->get_id_top_material();
				
				//int mat_panel = this->mat_panel_box->get_id_top_material();

				bool podval = this->checkbox->isChecked();

				Building* building = nullptr;
				switch (type_build)
				{
				case 0:
					building = new Home((double)width, (double)length, num_floors);
					break;
				case 1:
					building = new Office((double)width, (double)length, num_floors);
					break;
				case 2:
					building = new Storage((double)width, (double)length, num_floors);
					break;
				case 3:
					building = new Garage((double)width, (double)length, num_floors);
					break;
				default:
					break;
				}


				if (building){

					building->createFoundation(mat_fund, podval);
					building->createWall(type_build, mat_wall);
					building->createRoof(mat_roof, type_build);
					building->calculate();
					building->addMaterials(this->materials, this->calcMtrl);

					this->enable_all(false);
					this->OK_button->set_text("Новый");
					this->OK_button->show(SW_SHOW);
					this->status = OUTPUT_DATA;

					int X = 10, Y = 320;
					this->textout("Материал", 10, Y);
					this->textout("Количество", 230, Y);
					this->textout("Цена/шт", 330, Y);
					this->textout("Сумма грн", 400, Y);
					this->line(5,Y-5, 475, Y-5);
					this->line(5, Y + 20, 475, Y + 20);
					this->line(5, Y - 5, 5, Y + 20);
					this->line(225, Y - 5, 225, Y + 20);
					this->line(325, Y - 5, 325, Y + 20);
					this->line(395, Y - 5, 395, Y + 20);
					this->line(475, Y - 5, 475, Y + 20);
					Y += 25;
					double itogo = 0;
					char * buf = 0;
					int decimal;
					int sign;
					int err;
					if (!this->calcMtrl->empty()){
						for (unsigned int i = 0; i < this->calcMtrl->size(); i++)
						{
							if (this->calcMtrl->at(i)->count != 0)
							{
								char name[25];
								strncpy_s(name,25, this->calcMtrl->at(i)->type.c_str(), 24);
								this->textout((TCHAR*)name, 10, Y);


								buf = (char*)malloc(_CVTBUFSIZE);
								err = _fcvt_s(buf, _CVTBUFSIZE, this->calcMtrl->at(i)->count, 0, &decimal, &sign);
								this->textout((TCHAR*)buf, 230, Y);
								_itoa_s(this->calcMtrl->at(i)->price, buf, _CVTBUFSIZE, 10);
								this->textout((TCHAR*)buf, 330, Y);
								double summa = this->calcMtrl->at(i)->count * this->calcMtrl->at(i)->price;
								err = _fcvt_s(buf, _CVTBUFSIZE, summa, 0, &decimal, &sign);
								this->textout((TCHAR*)buf, 400, Y);
								itogo += summa;
								this->line(5, Y + 20, 475, Y + 20);
								this->line(5, Y - 5, 5, Y + 20);
								this->line(225, Y - 5, 225, Y + 20);
								this->line(325, Y - 5, 325, Y + 20);
								this->line(395, Y - 5, 395, Y + 20);
								this->line(475, Y - 5, 475, Y + 20);
								Y += 25;
							}
						}

						this->textout("Итого:", 350, Y);
						err = _fcvt_s(buf, _CVTBUFSIZE, itogo, 0, &decimal, &sign);
						this->textout((TCHAR*)buf, 400, Y);
						this->line(345, Y + 20, 475, Y + 20);
						this->line(345, Y - 5, 345, Y + 20);
						this->line(395, Y - 5, 395, Y + 20);
						this->line(475, Y - 5, 475, Y + 20);
					}
				}
			}
			else{
				this->textout("Нет данных о строительных материалах", 10, 320);
				this->status = OUTPUT_DATA;
			}
			break;
		}

		

	}
}
Exemplo n.º 21
0
    bool ExportSettingsManager::MarshalAllSettings( CHAR* strDestBuffer, DWORD dwBufferSize, bool bNewLines, ExportSettingsEntry* pRoot )
    {
        bool bResult = true;
        if( !pRoot )
        {
            size_t dwRootCount = GetRootCategoryCount();
            for( size_t i = 0; i < dwRootCount; ++i )
            {
                bResult &= MarshalAllSettings( strDestBuffer, dwBufferSize, bNewLines, GetRootCategory( i ) );
            }
            return bResult;
        }

        if( pRoot->m_Type == ExportSettingsEntry::CT_CATEGORY && pRoot->m_pFirstChild )
        {
            bResult &= MarshalAllSettings( strDestBuffer, dwBufferSize, bNewLines, pRoot->m_pFirstChild );
        }
        else
        {
            size_t dwCurrentLen = strlen( strDestBuffer );
            CHAR* strCurrentSpot = strDestBuffer + dwCurrentLen;
            const CHAR* strSettingName = pRoot->m_CommandLineOptionName.SafeString();
            size_t dwNameLen = strlen( strSettingName );
            if( dwCurrentLen + dwNameLen + 1 > dwBufferSize )
                return false;
            strcat_s( strDestBuffer, dwBufferSize, strSettingName );
            strcat_s( strDestBuffer, dwBufferSize, "=" );
            dwCurrentLen += ( dwNameLen + 1 );

            switch( pRoot->m_CurrentValue.m_Type )
            {
            case ExportVariant::VT_STRING:
                {
                    const CHAR* strValue = pRoot->GetValueString();
                    size_t dwValueLen = strlen( strValue );
                    if( dwCurrentLen + dwValueLen + 1 > dwBufferSize )
                    {
                        *strCurrentSpot = '\0';
                        return false;
                    }
                    strcat_s( strDestBuffer, dwBufferSize, strValue );
                    break;
                }
            case ExportVariant::VT_INT:
            case ExportVariant::VT_BOOL:
                {
                    INT iValue = 0;
                    if( pRoot->m_CurrentValue.m_Type == ExportVariant::VT_BOOL )
                        iValue = pRoot->GetValueBool();
                    else
                        iValue = pRoot->GetValueInt();
                    CHAR strValue[32] = {0};
                    _itoa_s( iValue, strValue, 10 );
                    size_t dwValueLen = strlen( strValue );
                    if( dwCurrentLen + dwValueLen + 1 > dwBufferSize )
                    {
                        *strCurrentSpot = '\0';
                        return false;
                    }
                    strcat_s( strDestBuffer, dwBufferSize, strValue );
                    break;
                }
            case ExportVariant::VT_FLOAT:
                {
                    float fValue = pRoot->GetValueFloat();
                    CHAR strValue[32];
                    sprintf_s( strValue, "%0.5f", fValue );
                    size_t dwValueLen = strlen( strValue );
                    if( dwCurrentLen + dwValueLen + 1 > dwBufferSize )
                    {
                        *strCurrentSpot = '\0';
                        return false;
                    }
                    strcat_s( strDestBuffer, dwBufferSize, strValue );
                    break;
                }
            }
            if( bNewLines )
            {
                strcat_s( strDestBuffer, dwBufferSize, ";\n" );
            }
            else
            {
                strcat_s( strDestBuffer, dwBufferSize, ";" );
            }
        }

        if( pRoot->m_pSibling )
        {
            bResult &= MarshalAllSettings( strDestBuffer, dwBufferSize, bNewLines, pRoot->m_pSibling );
        }

        return bResult;
    }
Exemplo n.º 22
0
void __cdecl SilAssert (
		const char * expr,
		const char * filename,
		unsigned lineno
		)
{
	/*
	 * Build the assertion message, then display it.
	 */
	int nCode = IDIGNORE;
	char * pch;
	char assertbuf[ASSERTBUFSZ];
	char progname[MAX_PATH + 1];

	/*
		* Line 1: box intro line
		*/
	strcpy_s( assertbuf, ASSERTBUFSZ, BOXINTRO );
	strcat_s( assertbuf, ASSERTBUFSZ, dblnewline );

#if WIN32
	// TODO-Linux: Find filename of managed executable
	/*
		* Line 2: program line
		*/
	strcat_s( assertbuf, ASSERTBUFSZ, PROGINTRO );

	progname[MAX_PATH] = '\0';
	if ( !GetModuleFileName( NULL, progname, MAX_PATH ))
		strcpy_s( progname, ASSERTBUFSZ, "<program name unknown>");

	pch = (char *)progname;

	/* sizeof(PROGINTRO) includes the NULL terminator */
	if ( sizeof(PROGINTRO) + strlen(progname) + NEWLINESZ > MAXLINELEN )
	{
		int cch = (sizeof(PROGINTRO) + strlen(progname) + NEWLINESZ) - MAXLINELEN;
		pch += cch;
		strncpy_s( pch, sizeof(progname) - cch, dotdotdot, DOTDOTDOTSZ );
	}

	strcat_s( assertbuf, ASSERTBUFSZ, pch );
	strcat_s( assertbuf, ASSERTBUFSZ, newline );
#endif

	/*
		* Line 3: file line
		*/
	strcat_s( assertbuf, ASSERTBUFSZ, FILEINTRO );

	/* sizeof(FILEINTRO) includes the NULL terminator */
	if ( sizeof(FILEINTRO) + strlen(filename) + NEWLINESZ > MAXLINELEN )
	{
		size_t p, len, ffn;

		pch = (char *) filename;
		ffn = MAXLINELEN - sizeof(FILEINTRO) - NEWLINESZ;

		for ( len = strlen(filename), p = 1;
				pch[len - p] != '\\' && pch[len - p] != '/' && p < len;
				p++ );

		/* keeping pathname almost 2/3rd of full filename and rest
			* is filename
			*/
		if ( (ffn - ffn/3) < (len - p) && ffn/3 > p )
		{
			/* too long. using first part of path and the
				filename string */
			strncat_s( assertbuf, ASSERTBUFSZ, pch, ffn - DOTDOTDOTSZ - p );
			strcat_s( assertbuf, ASSERTBUFSZ, dotdotdot );
			strcat_s( assertbuf, ASSERTBUFSZ, pch + len - p );
		}
		else if ( ffn - ffn/3 > len - p )
		{
			/* pathname is smaller. keeping full pathname and putting
				* dotdotdot in the middle of filename
				*/
			p = p/2;
			strncat_s( assertbuf, ASSERTBUFSZ, pch, ffn - DOTDOTDOTSZ - p );
			strcat_s( assertbuf, ASSERTBUFSZ, dotdotdot );
			strcat_s( assertbuf, ASSERTBUFSZ, pch + len - p );
		}
		else
		{
			/* both are long. using first part of path. using first and
				* last part of filename.
				*/
			strncat_s( assertbuf, ASSERTBUFSZ, pch, ffn - ffn/3 - DOTDOTDOTSZ );
			strcat_s( assertbuf, ASSERTBUFSZ, dotdotdot );
			strncat_s( assertbuf, ASSERTBUFSZ, pch + len - p, ffn/6 - 1 );
			strcat_s( assertbuf, ASSERTBUFSZ, dotdotdot );
			strcat_s( assertbuf, ASSERTBUFSZ, pch + len - (ffn/3 - ffn/6 - 2) );
		}

	}
	else
		/* plenty of room on the line, just append the filename */
		strcat_s( assertbuf, ASSERTBUFSZ, filename );

	strcat_s( assertbuf, ASSERTBUFSZ, newline );

	/*
		* Line 4: line line
		*/
	strcat_s( assertbuf, ASSERTBUFSZ, LINEINTRO );
	_itoa_s( lineno, assertbuf + strlen(assertbuf), sizeof(assertbuf) - strlen(assertbuf), 10 );
	strcat_s( assertbuf, ASSERTBUFSZ, dblnewline );

	/*
		* Line 5: message line
		*/
	strcat_s( assertbuf, ASSERTBUFSZ, EXPRINTRO );

	/* sizeof(HELPINTRO) includes the NULL terminator */

	if (    strlen(assertbuf) +
			strlen(expr) +
			2*DBLNEWLINESZ +
			sizeof(INFOINTRO)-1 +
			sizeof(HELPINTRO) > ASSERTBUFSZ )
	{
		strncat_s( assertbuf, ASSERTBUFSZ,
			expr,
			ASSERTBUFSZ -
			(strlen(assertbuf) +
			DOTDOTDOTSZ +
			2*DBLNEWLINESZ +
			sizeof(INFOINTRO)-1 +
			sizeof(HELPINTRO)) );
		strcat_s( assertbuf, ASSERTBUFSZ, dotdotdot );
	}
	else
		strcat_s( assertbuf, ASSERTBUFSZ, expr );

	strcat_s( assertbuf, ASSERTBUFSZ, dblnewline );

	/*
		* Line 6, 7: info line
		*/

	strcat_s(assertbuf, ASSERTBUFSZ, INFOINTRO);
	strcat_s( assertbuf, ASSERTBUFSZ, dblnewline );

	/*
		* Line 8: help line
		*/
	strcat_s(assertbuf, ASSERTBUFSZ, HELPINTRO);

	// SIL addition: log the message using OutputDebugString

	if (g_ReportHook)
		g_ReportHook(_CRT_ASSERT, assertbuf);
	else
		OutputDebugString(assertbuf);

	// NOTE: this method is intented to be used by unmanaged apps only;
	// managed apps should use DebugProcs.AssertProc in DebugProcs.cs

	/*
	 * Write out via MessageBox
	 */
	if (g_fShowMessageBox)
	{
		nCode = MessageBoxA(NULL, assertbuf,
			"SIL Program Failure warning (Assert failed)",
			MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SETFOREGROUND|MB_TASKMODAL);

		/* Abort: abort the program */
		if (nCode == IDABORT)
		{
			/* raise abort signal */
			raise(SIGABRT);

			/* We usually won't get here, but it's possible that
				SIGABRT was ignored.  So exit the program anyway. */

			_exit(3);
		}

		/* Retry: call the debugger */
		if (nCode == IDRETRY)
		{
#if WIN32
			_DbgBreak();
#else
			raise(SIGTRAP);
#endif
			/* return to user code */
			return;
		}

		if (nCode != IDIGNORE)
			abort();
	}
	else // !g_fShowMessageBox
	{
		// if we don't show a message box we should at least abort (and output the assertion
		// text if we haven't done that already). Note that we don't call _exit(3) as above
		// so that we can trap the signal and ignore it in unit tests
		if (g_ReportHook)
			OutputDebugString(assertbuf);
		raise(SIGABRT);
	}

	/* Ignore: continue execution */
	return;
}