Пример #1
0
bool CServer::Startup()
{
	// Register our RPCs before set the NetServer´s rpc handler
	CEvents* pEvents = new CEvents();

	// Create all the managers
	m_pPlayerManager = new CPlayerManager();
	m_pVehicleManager = new CVehicleManager();
	m_pActorManager = new CActorManager();
	m_pObjectManager = new CObjectManager();
	m_pFireManager = new CFireManager();
	m_pPickupManager = new CPickupManager();
	m_p3DLabelManager = new C3DLabelManager();
	m_pBlipManager = new CBlipManager();
	m_pCheckpointManager = new CCheckpointManager();

	// Open the settings file
	if(!CSettings::Open(SharedUtility::GetAbsolutePath("settings.xml"), true, false))
	{
		CLogFile::Print("Failed to open settings.xml..");
#ifdef _WIN32
		Sleep(3000);
#else
		sleep(3);
#endif
		return false;
	}

#ifdef _WIN32
		 // Color stuff
        CONSOLE_SCREEN_BUFFER_INFO csbiScreen;
        WORD wOldColAttr;       // For input process.

        GetConsoleScreenBufferInfo((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), &csbiScreen);
        wOldColAttr = csbiScreen.wAttributes;

        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), wOldColAttr | FOREGROUND_INTENSITY);

        // Print message to console.
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

#endif
	CLogFile::Print("");
	CLogFile::Print("====================================================================");

#ifdef _WIN32
	SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), wOldColAttr | FOREGROUND_INTENSITY);
#endif


	CLogFile::Print(" " VERSION_IDENTIFIER " " OS_STRING " Server");
	CLogFile::Print(" Copyright (C) 2013 GTA-Network Team");
	CLogFile::Printf(" Port: %d", CVAR_GET_INTEGER("port"));
	CLogFile::Printf(" HTTP Port: %d", CVAR_GET_INTEGER("httpport"));
	CLogFile::Printf(" Query Port: %d", (CVAR_GET_INTEGER("queryport")));

	if(CVAR_GET_STRING("hostaddress").IsNotEmpty())
		CLogFile::Printf(" Host Address: %s", CVAR_GET_STRING("hostaddress").Get());

	if(CVAR_GET_STRING("httpserver").IsNotEmpty())
		CLogFile::Printf(" HTTP Server: %s", CVAR_GET_STRING("httpserver").Get());

	CLogFile::Printf(" Max Players: %d", CVAR_GET_INTEGER("maxplayers"));

#ifdef _WIN32
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        CLogFile::Print("====================================================================");
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), wOldColAttr | FOREGROUND_INTENSITY);
#else
        CLogFile::Print("====================================================================");
#endif
	
	// Load modules
	// Note: modules not implemented yet coming soon
	auto modules = CVAR_GET_LIST("module");
	if(modules.size() > 0)
	{
		CLogFile::Print("");
		CLogFile::Print("========================== Loading Modules =========================");

		for(auto strModule : modules)
		{
			CLogFile::Printf("Loading module %s.", strModule.Get());
			if(!strModule.ToLower().EndsWith(".so") && !strModule.ToLower().EndsWith(".dll"))
			{
				// If no extension specified in module name string, load SO for linux and DLL for Win
#ifdef _WIN32
				strModule.Append(".dll");
#else
				strModule.Append(".so");
#endif		
			}
			//CModule * pModule = g_pModuleManager->LoadModule(strModule);

			//if(!pModule)
				CLogFile::Printf("Warning: Failed to load module %s.", strModule.Get());
		}

		CLogFile::Print("");
	}
	m_pResourceManager = new CResourceManager("resources");

	// Loading resources
#ifdef _WIN32
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
        CLogFile::Print("");
        CLogFile::Print("============ Loading Resources ===========");
		CLogFile::Print("");
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), wOldColAttr | FOREGROUND_INTENSITY);
#else
        CLogFile::Print("");
        CLogFile::Print("============ Loading Resources ===========");
		CLogFile::Print("");
#endif


	auto resources = CVAR_GET_LIST("resource");

	int iResourcesLoaded = 0;
	int iFailedResources = 0;

	for(auto strResource : resources)
	{
		if(!strResource.IsEmpty())
		{
			CLogFile::Printf("Loading resource (%s)", strResource.C_String());
			if(CResource* pResource = m_pResourceManager->Load(SharedUtility::GetAbsolutePath(m_pResourceManager->GetResourceDirectory()),strResource))
			{
				m_pResourceManager->StartResource(pResource);
				iResourcesLoaded++;
			} else {
				CLogFile::Printf("Warning: Failed to load resource %s.", strResource.Get());
				iFailedResources++;
			}
		}
	}

	CLogFile::Printf("Successfully loaded %d resources (%d failed).", iResourcesLoaded, iFailedResources);

#ifdef _WIN32
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        CLogFile::Print("");
        CLogFile::Print("====================================================================");
        CLogFile::Print("");
        SetConsoleTextAttribute((HANDLE)GetStdHandle(STD_OUTPUT_HANDLE), wOldColAttr | FOREGROUND_INTENSITY);
#else
        CLogFile::Print("");
        CLogFile::Print("====================================================================");
        CLogFile::Print("");
#endif

	m_pNetworkModule->Startup();

	return true;
}
bool rahmen_puls_test(_WORD Cardauswahl,  string &ErrorMessage, bool ScreenOut, int loop)
{
	_WORD ErrorCounter = 0;
	_WORD counter	  = 0;
	_DWORD ErrorStatus = 0;
	_WORD SendeDaten	  = 0;
	_WORD ReadDaten	   =0; 
	_BYTE EventValue   = 0;
	_BYTE CntrlRegValue= 0; 
	
	bool EVFifoNotEmpty = true;
	bool testOK = true;

	COORD coordScreen;
	COORD StatusCoord;

	StatusCoord.X = 4;
	StatusCoord.Y = 24;

	PCI_PCIcardReset(Cardauswahl, ErrorStatus);

	if(ScreenOut)
	{
		ClearScreen();
		
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLUE | FOREGROUND_WHITE);   
		cout<<"Kleiner Event Filter Test auf Karten Nr.: "<<Cardauswahl<<endl<<endl;
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);

		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);   
		cout<<"Bitte das SWPZ-Adapterkabel SE->TIF zwischen den Mil-Bus und"<<endl;
		cout<<"der zwei poligen Lemo-Buchse verbinden."<<endl<<endl;
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);


		cout<<"Press Enter to go on...."<<endl;
		getchar();
		getchar();

		ClearScreen();

		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLUE | FOREGROUND_WHITE);   
		cout<<"Puls Test mit Karten Nr. "<<Cardauswahl<<endl<<endl;
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);

		// Text Ausgabe
		// -------------

		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);
		cout <<"Clear Event- Filter and test it      :"<<endl;
		cout <<"Clear Event- FiFo   and test it      :"<<endl;
		cout <<"Set Event 1 EventOff,Puls1/2 On      :"<<endl;
		cout <<"Set Event 2 EventOff,Puls1/2 Off     :"<<endl;
		cout <<"Switch Event Filter on               :"<<endl;
		cout <<"Set Rahmen Puls 1 On                 :"<<endl;
		cout <<"Set Rahmen Puls 2 On                 :"<<endl;
		cout <<"Event FiFo empty                     :"<<endl;
		cout <<""<<endl;
	}


	// Events settings löschen
	//--------------------------
	
	PCI_EvFilterClear(Cardauswahl, ErrorStatus);

	// Testen ob settings gelöscht
	//-----------------------------	
	counter		= 0;
	EventValue  = 0;
	ErrorStatus = 0;
	
	while((ErrorStatus & EventNrError) != EventNrError) 
	{
		PCI_EvFilterRead(Cardauswahl, counter, EventValue, ErrorStatus);

		if(EventValue != 0)
			ErrorCounter++;
			
		counter++;
	}

	coordScreen.X = 38;
	coordScreen.Y = 2;
	SetConsoleCursorPosition(hConsoleOut, coordScreen);

	if((counter-1) < 4096)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" ERROR ! insufficient events cleared ! "<<endl;
			testOK = false;	
		}
		else
		{
			ErrorMessage = " ERROR ! insufficient events cleared ! ";
			return false;
		}
	}
	else if((counter-1) > 4096)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" ERROR ! events cleared overflow! "<<endl;
			testOK = false;	
		}
		else
		{
			ErrorMessage = " ERROR ! events cleared overflow ! ";
			return false;
		}
	}
	else if(ErrorCounter == 0)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}
	else
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);
			cout<<" FAILURE ! Some settings not cleared :"<<ErrorCounter<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = "  FAILURE ! Some settings not cleared ! ";
			return false;
		}
	}

	//---------------------------
	// FiFo löschen
	//---------------------------

	PCI_EvFiFioClear(Cardauswahl, ErrorStatus);

	// FiFo prüfen
	//--------------------
	EVFifoNotEmpty = true;
	ReadDaten   = 0;
	ErrorStatus = 0;

	PCI_EvFiFoRead (Cardauswahl, ReadDaten, EVFifoNotEmpty, ErrorStatus);

	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 3;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if(EVFifoNotEmpty == true)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" ERROR ! EV-FiFo not empty !"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " ERROR ! EV-FiFo not empty ! ";
			return false;
		}
	}
	else 
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}

	// Event eins setzen
	PCI_EvFilterSet(Cardauswahl, 1, Puls1_On, ErrorStatus);
	PCI_EvFilterSet(Cardauswahl, 1, Puls2_On, ErrorStatus);
	PCI_EvFilterSet(Cardauswahl, 1, EventOff, ErrorStatus);

	// Value von event eins einlesen
	EventValue = 0;
	PCI_EvFilterRead(Cardauswahl,1, EventValue, ErrorStatus);

	// Value von event eins pruefen
	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 4;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if(EventValue != (EvFilter_Start_Puls1 | EvFilter_Start_Puls2))
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" Failure"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " Failure ! ";
			return false;
		}
	}
	else 
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}

	// Event zwei setzen
	PCI_EvFilterSet(Cardauswahl, 2, EventOff, ErrorStatus);
	PCI_EvFilterSet(Cardauswahl, 2, Puls1_Off, ErrorStatus);
	PCI_EvFilterSet(Cardauswahl, 2, Puls2_Off, ErrorStatus);

	// Value von event zwei einlesen
	EventValue = 0;
	PCI_EvFilterRead(Cardauswahl,2, EventValue, ErrorStatus);

	// Value von event zwei pruefen
	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 5;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if(EventValue != (EvFilter_Stop_Puls1 | EvFilter_Stop_Puls2))
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" Failure"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " Failure ! ";
			return false;
		}
	}
	else 
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}


	// Filter einschalten
	//--------------------

	PCI_CntrlRegSet(Cardauswahl, Cntrl_EvFilter_On, ErrorStatus);

	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 6;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if(PCI_StatusTest(Cardauswahl, EvFilter_On, ErrorStatus))
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}
	else
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" Failure !"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " Failure ! ";
			return false;
		}
	}

	// Puls oder Rahmen Puls
	PCI_CntrlRegSet(Cardauswahl, Cntrl_Puls1_Rahmen_On, ErrorStatus);

	// Control Register auslesen
	PCI_CntrlRegRead(Cardauswahl, CntrlRegValue, ErrorStatus );
	
	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 7;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if((CntrlRegValue & Ctrl_Puls1_Rahmen_On) != Ctrl_Puls1_Rahmen_On)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" Failure !"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " Failure ! ";
			return false;
		}
	}
	else
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}

	// Puls oder Rahmen Puls
	PCI_CntrlRegSet(Cardauswahl, Cntrl_Puls2_Rahmen_On, ErrorStatus);

	// Control Register auslesen
	PCI_CntrlRegRead(Cardauswahl, CntrlRegValue, ErrorStatus );
	
	if(ScreenOut)
	{
		coordScreen.X = 38;
		coordScreen.Y = 8;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
	}

	if((CntrlRegValue & Ctrl_Puls2_Rahmen_On) != Ctrl_Puls2_Rahmen_On)
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
			cout<<" Failure !"<<endl;
			testOK = false;
		}
		else
		{
			ErrorMessage = " Failure ! ";
			return false;
		}
	}
	else
	{
		if(ScreenOut)
		{
			SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
			cout<<" OK "<<endl;
		}
	}

	coordScreen.X = 0;
	coordScreen.Y = 13;
	SetConsoleCursorPosition(hConsoleOut, coordScreen);
	
	if(testOK == true)
	{
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
		cout<<"\n\n...Press Enter to START Rahmen Pulse 1 & 2 ...";
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);
		getchar();
	
		SendeDaten = 1;
		PCI_MilBusWrite(Cardauswahl, SendeDaten,ErrorStatus);

		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
		cout<<"\n\n...Press Enter to STOP Rahmen Pulse 1 & 2 ...";
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);
		getchar();

		SendeDaten = 2;
		PCI_MilBusWrite(Cardauswahl, SendeDaten,ErrorStatus);

		if(ScreenOut)
		{
			coordScreen.X = 38;
			coordScreen.Y = 9;
			SetConsoleCursorPosition(hConsoleOut, coordScreen);
		}

		if (PCI_StatusTest(Cardauswahl, Evt_Fifo_Not_Empty, ErrorStatus))
		{
			if(ScreenOut)
			{
				SetConsoleTextAttribute(hConsoleOut, BACKGROUND_RED | FOREGROUND_WHITE);  
				cout<<" Error ! Event FiFo is not empty !"<<endl;
			}
			else
			{
				ErrorMessage = " Error ! Event FiFo is not empty ! ";
				return false;
			}
		}
		else
		{
			if(ScreenOut)
			{
				SetConsoleTextAttribute(hConsoleOut, BACKGROUND_GREEN | FOREGROUND_WHITE);  
				cout<<" OK "<<endl;
			}
		}
	}

	if(ScreenOut)
	{
		SetConsoleTextAttribute(hConsoleOut, BACKGROUND_BLACK | FOREGROUND_WHITE);
		coordScreen.X = 0;
		coordScreen.Y = 20;
		SetConsoleCursorPosition(hConsoleOut, coordScreen);
		cout<< "..press ENTER to go back..."<<endl;
		getchar();
	}
	return true;
}
Пример #3
0
static void DoPrintStr(const char *cp, HWND edit, HANDLE StdOut)
{
	if (edit == NULL && StdOut == NULL)
		return;

	char buf[256];
	wchar_t wbuf[countof(buf)];
	int bpos = 0;
	CHARRANGE selection;
	CHARRANGE endselection;
	LONG lines_before = 0, lines_after;
	CHARFORMAT format;

	if (edit != NULL)
	{
		// Store the current selection and set it to the end so we can append text.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&selection);
		endselection.cpMax = endselection.cpMin = GetWindowTextLength(edit);
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&endselection);

		// GetWindowTextLength and EM_EXSETSEL can disagree on where the end of
		// the text is. Find out what EM_EXSETSEL thought it was and use that later.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&endselection);

		// Remember how many lines there were before we added text.
		lines_before = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
	}

	while (*cp != 0)
	{
		// 28 is the escape code for a color change.
		if ((*cp == 28 && bpos != 0) || bpos == 255)
		{
			buf[bpos] = 0;
			if (edit != NULL)
			{
				ToEditControl(edit, buf, wbuf, bpos);
			}
			if (StdOut != NULL)
			{
				DWORD bytes_written;
				WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
			}
			bpos = 0;
		}
		if (*cp != 28)
		{
			buf[bpos++] = *cp++;
		}
		else
		{
			const BYTE *color_id = (const BYTE *)cp + 1;
			EColorRange range = V_ParseFontColor(color_id, CR_UNTRANSLATED, CR_YELLOW);
			cp = (const char *)color_id;

			if (range != CR_UNDEFINED)
			{
				// Change the color of future text added to the control.
				PalEntry color = V_LogColorFromColorRange(range);
				if (StdOut != NULL && FancyStdOut)
				{
					// Unfortunately, we are pretty limited here: There are only
					// eight basic colors, and each comes in a dark and a bright
					// variety.
					float h, s, v, r, g, b;
					WORD attrib = 0;

					RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v);
					if (s != 0)
					{ // color
						HSVtoRGB(&r, &g, &b, h, 1, 1);
						if (r == 1)  attrib  = FOREGROUND_RED;
						if (g == 1)  attrib |= FOREGROUND_GREEN;
						if (b == 1)  attrib |= FOREGROUND_BLUE;
						if (v > 0.6) attrib |= FOREGROUND_INTENSITY;
					}
					else
					{ // gray
						     if (v < 0.33) attrib = FOREGROUND_INTENSITY;
						else if (v < 0.90) attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
						else			   attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
					}
					SetConsoleTextAttribute(StdOut, attrib);
				}
				if (edit != NULL)
				{
					// GDI uses BGR colors, but color is RGB, so swap the R and the B.
					swapvalues(color.r, color.b);
					// Change the color.
					format.cbSize = sizeof(format);
					format.dwMask = CFM_COLOR;
					format.dwEffects = 0;
					format.crTextColor = color;
					SendMessage(edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
				}
			}
		}
	}
	if (bpos != 0)
	{
		buf[bpos] = 0;
		if (edit != NULL)
		{
			ToEditControl(edit, buf, wbuf, bpos);
		}
		if (StdOut != NULL)
		{
			DWORD bytes_written;
			WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
		}
	}

	if (edit != NULL)
	{
		// If the old selection was at the end of the text, keep it at the end and
		// scroll. Don't scroll if the selection is anywhere else.
		if (selection.cpMin == endselection.cpMin && selection.cpMax == endselection.cpMax)
		{
			selection.cpMax = selection.cpMin = GetWindowTextLength (edit);
			lines_after = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
			if (lines_after > lines_before)
			{
				SendMessage(edit, EM_LINESCROLL, 0, lines_after - lines_before);
			}
		}
		// Restore the previous selection.
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&selection);
		// Give the edit control a chance to redraw itself.
		I_GetEvent();
	}
	if (StdOut != NULL && FancyStdOut)
	{ // Set text back to gray, in case it was changed.
		SetConsoleTextAttribute(StdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	}
}
Пример #4
0
int	VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
{
	/////////////////////////////////////////////////////////////////
	/* XXX Two streams are being used. Disabled to avoid inconsistency [flaviojs]
	static COORD saveposition = {0,0};
	*/

	/////////////////////////////////////////////////////////////////
	DWORD written;
	char *p, *q;
	NEWBUF(tempbuf); // temporary buffer

	if(!fmt || !*fmt)
		return 0;

	// Print everything to the buffer
	BUFVPRINTF(tempbuf,fmt,argptr);

	if( !is_console(handle) && stdout_with_ansisequence )
	{
		WriteFile(handle, BUFVAL(tempbuf), BUFLEN(tempbuf), &written, 0);
		return 0;
	}

	// start with processing
	p = BUFVAL(tempbuf);
	while ((q = strchr(p, 0x1b)) != NULL)
	{	// find the escape character
		if( 0==WriteConsole(handle, p, (DWORD)(q-p), &written, 0) ) // write up to the escape
			WriteFile(handle, p, (DWORD)(q-p), &written, 0);

		if( q[1]!='[' )
		{	// write the escape char (whatever purpose it has) 
			if(0==WriteConsole(handle, q, 1, &written, 0) )
				WriteFile(handle,q, 1, &written, 0);
			p=q+1;	//and start searching again
		}
		else
		{	// from here, we will skip the '\033['
			// we break at the first unprocessible position
			// assuming regular text is starting there
			uint8 numbers[16], numpoint=0;
			CONSOLE_SCREEN_BUFFER_INFO info;

			// initialize
			GetConsoleScreenBufferInfo(handle, &info);
			memset(numbers,0,sizeof(numbers));

			// skip escape and bracket
			q=q+2;
			for(;;)
			{
				if( ISDIGIT(*q) ) 
				{	// add number to number array, only accept 2digits, shift out the rest
					// so // \033[123456789m will become \033[89m
					numbers[numpoint] = (numbers[numpoint]<<4) | (*q-'0');
					++q;
					// and next character
					continue;
				}
				else if( *q == ';' )
				{	// delimiter
					if(numpoint<sizeof(numbers)/sizeof(*numbers))
					{	// go to next array position
						numpoint++;
					}
					else
					{	// array is full, so we 'forget' the first value
						memmove(numbers,numbers+1,sizeof(numbers)/sizeof(*numbers)-1);
						numbers[sizeof(numbers)/sizeof(*numbers)-1]=0;
					}
					++q;
					// and next number
					continue;
				}
				else if( *q == 'm' )
				{	// \033[#;...;#m - Set Graphics Rendition (SGR)
					uint8 i;
					for(i=0; i<= numpoint; ++i)
					{
						if( 0x00 == (0xF0 & numbers[i]) )
						{	// upper nibble 0
							if( 0 == numbers[i] )
							{	// reset
								info.wAttributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
							}
							else if( 1==numbers[i] )
							{	// set foreground intensity
								info.wAttributes |= FOREGROUND_INTENSITY;
							}
							else if( 5==numbers[i] )
							{	// set background intensity
								info.wAttributes |= BACKGROUND_INTENSITY;
							}
							else if( 7==numbers[i] )
							{	// reverse colors (just xor them)
								info.wAttributes ^= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
													BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
							}
							//case '2': // not existing
							//case '3':	// blinking (not implemented)
							//case '4':	// unterline (not implemented)
							//case '6': // not existing
							//case '8': // concealed (not implemented)
							//case '9': // not existing
						}
						else if( 0x20 == (0xF0 & numbers[i]) )
						{	// off

							if( 1==numbers[i] )
							{	// set foreground intensity off
								info.wAttributes &= ~FOREGROUND_INTENSITY;
							}
							else if( 5==numbers[i] )
							{	// set background intensity off
								info.wAttributes &= ~BACKGROUND_INTENSITY;
							}
							else if( 7==numbers[i] )
							{	// reverse colors (just xor them)
								info.wAttributes ^= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
													BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
							}
						}
						else if( 0x30 == (0xF0 & numbers[i]) )
						{	// foreground
							uint8 num = numbers[i]&0x0F;
							if(num==9) info.wAttributes |= FOREGROUND_INTENSITY;
							if(num>7) num=7;	// set white for 37, 38 and 39
							info.wAttributes &= ~(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
							if( (num & 0x01)>0 ) // lowest bit set = red
								info.wAttributes |= FOREGROUND_RED;
							if( (num & 0x02)>0 ) // second bit set = green
								info.wAttributes |= FOREGROUND_GREEN;
							if( (num & 0x04)>0 ) // third bit set = blue
								info.wAttributes |= FOREGROUND_BLUE;
						}
						else if( 0x40 == (0xF0 & numbers[i]) )
						{	// background
							uint8 num = numbers[i]&0x0F;
							if(num==9) info.wAttributes |= BACKGROUND_INTENSITY;
							if(num>7) num=7;	// set white for 47, 48 and 49
							info.wAttributes &= ~(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);
							if( (num & 0x01)>0 ) // lowest bit set = red
								info.wAttributes |= BACKGROUND_RED;
							if( (num & 0x02)>0 ) // second bit set = green
								info.wAttributes |= BACKGROUND_GREEN;
							if( (num & 0x04)>0 ) // third bit set = blue
								info.wAttributes |= BACKGROUND_BLUE;
						}
					}
					// set the attributes
					SetConsoleTextAttribute(handle, info.wAttributes);
				}
				else if( *q=='J' )
				{	// \033[#J - Erase Display (ED)
					//    \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged.
					//    \033[1J - Clears the screen from start to cursor. The cursor position is unchanged.
					//    \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1).
					uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F);
					int cnt;
					DWORD tmp;
					COORD origin = {0,0};
					if(num==1)
					{	// chars from start up to and including cursor
						cnt = info.dwSize.X * info.dwCursorPosition.Y + info.dwCursorPosition.X + 1;
					}
					else if(num==2)
					{	// Number of chars on screen.
						cnt = info.dwSize.X * info.dwSize.Y;
						SetConsoleCursorPosition(handle, origin); 
					}
					else// 0 and default
					{	// number of chars from cursor to end
						origin = info.dwCursorPosition;
						cnt = info.dwSize.X * (info.dwSize.Y - info.dwCursorPosition.Y) - info.dwCursorPosition.X; 
					}
					FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp);
					FillConsoleOutputCharacter(handle, ' ',              cnt, origin, &tmp);
				}
				else if( *q=='K' )
				{	// \033[K  : clear line from actual position to end of the line
					//    \033[0K - Clears all characters from the cursor position to the end of the line.
					//    \033[1K - Clears all characters from start of line to the cursor position.
					//    \033[2K - Clears all characters of the whole line.

					uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F);
					COORD origin = {0,info.dwCursorPosition.Y}; //warning C4204
					SHORT cnt;
					DWORD tmp;
					if(num==1)
					{
						cnt = info.dwCursorPosition.X + 1;
					}
					else if(num==2)
					{
						cnt = info.dwSize.X;
					}
					else// 0 and default
					{
						origin = info.dwCursorPosition;
						cnt = info.dwSize.X - info.dwCursorPosition.X; // how many spaces until line is full
					}
					FillConsoleOutputAttribute(handle, info.wAttributes, cnt, origin, &tmp);
					FillConsoleOutputCharacter(handle, ' ',              cnt, origin, &tmp);
				}
				else if( *q == 'H' || *q == 'f' )
void textColor(int color){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO consoleInfo; 
    SetConsoleTextAttribute(hConsole, color);
}
Пример #6
0
void txtColor(int color){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
Пример #7
0
void SetColor(int color)//设置颜色
 {
     SetConsoleTextAttribute(hConsole, color);
//是API设置字体颜色和背景色的函数 格式:SetConsoleTextAttribute(句柄,颜色);
 }
Пример #8
0
int _tmain(int argc, _TCHAR* argv[])
{
	if(argc != 4) {
		usage();
		exit(1);
	}

	int x = atoi(argv[1]);
	int y = atoi(argv[2]);
	int z = atoi(argv[3]);
	if (x > 50 || x < 1) {
		usage();
		exit(1);
	}

	if (y > 50 || y < 1) {
		usage();
		exit(1);
	}

	if (z > 50 || z < 1) {
		usage();
		exit(1);
	}

	printf("Input: X=%d Y=%d Z=%d\n", x, y, z);
	
	int result[5][2] = {0};
	result[0][0] = x+1;
	result[1][0] = x+y;
	result[2][0] = y+z;
	result[3][0] = z+1;
	result[4][0] = x+y+z;

	for (int i=0; i<5; i++) {
		for(int j=0; j<sizeof(A)/sizeof(int); j++) {
			if (A[j] == result[i][0]) {
				result[i][1] = FOREGROUND_GREEN;
			} 
		}
		if (result[i][1] != 0 ) {
			continue;
		}

		for(int j=0; j<sizeof(B)/sizeof(int); j++) {
			if (B[j] == result[i][0]) {
				result[i][1] = FOREGROUND_BLUE;
			}
		}
		if (result[i][1] != 0 ) {
			continue;
		}

		for(int j=0; j<sizeof(C)/sizeof(int); j++) {
			if (C[j] == result[i][0]) {
				result[i][1] = FOREGROUND_RED;
			}
		}

		if (result[i][1] != 0 ) {
			continue;
		}

		result[i][1] = FOREGROUND_INTENSITY;
	}

	//output 
	HANDLE consolehwnd; 
	consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE); 
	//
	printf("Result:");
	for(int i=0; i<5; i++) {
		SetConsoleTextAttribute(consolehwnd,result[i][1]);
		printf("%d ", result[i][0]);
	}
	printf("\n");
	SetConsoleTextAttribute(consolehwnd,FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED);

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}
Пример #9
0
//--------------------------------------------------------------
// Purpose  : Setting colour of the console text
// Input    : WORD (2 bytes data type)
// Output   : Nil
//--------------------------------------------------------------
void colour(WORD wAttrib)
{    
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute( hStdout, wAttrib );        
}
Пример #10
0
void set_output_color(WORD c) {
    if (!get_console_handle())
        return;
    SetConsoleTextAttribute(console_handle, c);
}
Пример #11
0
void Log::SetColor(bool stdout_stream, Color color)
{
    #if PLATFORM == PLATFORM_WINDOWS

    static WORD WinColorFG[Color_count] =
    {
        0,                                                  // BLACK
        FOREGROUND_RED,                                     // RED
        FOREGROUND_GREEN,                                   // GREEN
        FOREGROUND_RED | FOREGROUND_GREEN,                  // BROWN
        FOREGROUND_BLUE,                                    // BLUE
        FOREGROUND_RED |                    FOREGROUND_BLUE,// MAGENTA
        FOREGROUND_GREEN | FOREGROUND_BLUE,                 // CYAN
        FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE
                                                            // YELLOW
        FOREGROUND_RED | FOREGROUND_GREEN |                   FOREGROUND_INTENSITY,
                                                            // RED_BOLD
        FOREGROUND_RED |                                      FOREGROUND_INTENSITY,
                                                            // GREEN_BOLD
        FOREGROUND_GREEN |                   FOREGROUND_INTENSITY,
        FOREGROUND_BLUE | FOREGROUND_INTENSITY,             // BLUE_BOLD
                                                            // MAGENTA_BOLD
        FOREGROUND_RED |                    FOREGROUND_BLUE | FOREGROUND_INTENSITY,
                                                            // CYAN_BOLD
        FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
                                                            // WHITE_BOLD
        FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
    };

    HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
    SetConsoleTextAttribute(hConsole, WinColorFG[color]);
    #else

    enum ANSITextAttr
    {
        TA_NORMAL=0,
        TA_BOLD=1,
        TA_BLINK=5,
        TA_REVERSE=7
    };

    enum ANSIFgTextAttr
    {
        FG_BLACK=30, FG_RED,  FG_GREEN, FG_BROWN, FG_BLUE,
        FG_MAGENTA,  FG_CYAN, FG_WHITE, FG_YELLOW
    };

    enum ANSIBgTextAttr
    {
        BG_BLACK=40, BG_RED,  BG_GREEN, BG_BROWN, BG_BLUE,
        BG_MAGENTA,  BG_CYAN, BG_WHITE
    };

    static uint8 UnixColorFG[Color_count] =
    {
        FG_BLACK,                                           // BLACK
        FG_RED,                                             // RED
        FG_GREEN,                                           // GREEN
        FG_BROWN,                                           // BROWN
        FG_BLUE,                                            // BLUE
        FG_MAGENTA,                                         // MAGENTA
        FG_CYAN,                                            // CYAN
        FG_WHITE,                                           // WHITE
        FG_YELLOW,                                          // YELLOW
        FG_RED,                                             // LRED
        FG_GREEN,                                           // LGREEN
        FG_BLUE,                                            // LBLUE
        FG_MAGENTA,                                         // LMAGENTA
        FG_CYAN,                                            // LCYAN
        FG_WHITE                                            // LWHITE
    };

    fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm",UnixColorFG[color],(color>=YELLOW&&color<Color_count ?";1":""));
    #endif
}
Пример #12
0
int main(int argc, char ** argv)
{
	
	DWORD devIndex = 0; 
	char Buffer[255];
	ftdi_pins.pins = 0xF1;
	ftdi_pins.clk = HIGH;
	DWORD p = 0;
	byte e1 = 0xff;
	byte e2 = 0;

	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, 7);
	if (argc < 2) {
		printf("Please specify the hex file\n");
		return 1;
	}

	
	FT_STATUS ftStatus = FT_ListDevices((PVOID)devIndex, Buffer, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER);
	if (ftStatus == FT_OK) {

		int bytes = load_file(argv[1]);

		ftStatus = FT_OpenEx(Buffer, FT_OPEN_BY_SERIAL_NUMBER, &ftdi_chip);
		FT_SetBitMode(ftdi_chip, PIN_TX | PIN_RX | PIN_CTS, 1); // BIT BANG MODE
		FT_SetBaudRate(ftdi_chip, BAUD_RATE);						 

		setPin(RST_8051, LOW);
		setPin(MOSI_8051, LOW);
		setPin(CLK_8051, LOW);
		setPin(RST_8051, HIGH);
		
		Sleep(500);
		printf("%x\n", progEnable());		
		Sleep(1100);

		eraseChip();

		for (int i = from_addr; i < to_addr + 1; i++) {
			printf("%02X", readProgmem(0, i));
		}
		printf("\n");


		for (int i = from_addr; i < to_addr + 1; i++) {
			printf("%02X", memory[i]);
		}
		printf("\n");
		
		// write memory
		for (int i = from_addr; i < to_addr+1; i++) {
			writeProgmem(0, i, memory[i]);
			printf("%02X", readProgmem(0, i));
		}
		printf("\n");
		

		Sleep(1000);
		setPin(RST_8051, LOW);
		Sleep(500);

		FT_Close(ftdi_chip);

		getchar();
	}
	else {
		printf("Can't open FTDI chip\n");
		return 1;
	}

	return 0;
}
Пример #13
0
void set_console_color(int color, bool bright)
{
  if (!is_stdout_a_tty())
    return;

  switch(color)
  {
  case console_color_default:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE| (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;37m";
      else
        std::cout << "\033[0m";
#endif
    }
    break;
  case console_color_white:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;37m";
      else
        std::cout << "\033[0;37m";
#endif
    }
    break;
  case console_color_red:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;31m";
      else
        std::cout << "\033[0;31m";
#endif
    }
    break;
  case console_color_green:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;32m";
      else
        std::cout << "\033[0;32m";
#endif
    }
    break;

  case console_color_blue:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_INTENSITY);//(bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;34m";
      else
        std::cout << "\033[0;34m";
#endif
    }
    break;

  case console_color_cyan:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;36m";
      else
        std::cout << "\033[0;36m";
#endif
    }
    break;

  case console_color_magenta:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;35m";
      else
        std::cout << "\033[0;35m";
#endif
    }
    break;

  case console_color_yellow:
    {
#ifdef WIN32
      HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
#else
      if(bright)
        std::cout << "\033[1;33m";
      else
        std::cout << "\033[0;33m";
#endif
    }
    break;

  }
}
Пример #14
0
	void Logger::Log(LogLevel level, const tstring& pMessage, const tstring& tag)
	{
#if LOGGER_MIN_LEVEL > 0
		
		tstring levelName;
		switch(level)
		{
		case LogLevel::Info :
			levelName = _T("INFO");
			break;
		case LogLevel::Warning:
			levelName = _T("WARNING");
			break;
		case LogLevel::Error:
			levelName = _T("ERROR");
			break;
		case LogLevel::Debug:
			levelName = _T("DEBUG");
			break;
		}

	#ifdef DESKTOP
		tstringstream messageBuffer;
		messageBuffer << _T("[") << tag << _T("] ") << _T("[") << levelName <<  _T("] ") << pMessage << std::endl;
		tstring combinedMessage = messageBuffer.str();
		
		if(m_UseConsole)
		{
			switch(level)
			{
			case LogLevel::Info :
				#if LOGGER_MIN_LEVEL < 2
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
				#endif
				break;
			case LogLevel::Warning :
				#if LOGGER_MIN_LEVEL < 3
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
				#endif
				break;
			case LogLevel::Error :
				#if LOGGER_MIN_LEVEL < 4
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED);
				#endif
				break;
			case LogLevel::Debug :
				#if LOGGER_MIN_LEVEL < 5
				#ifdef DEBUG
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				#endif
				#endif
				break;
			}
			tprintf(combinedMessage.c_str());
		}
		else
		{
			OutputDebugString(combinedMessage.c_str());
		}
		#ifndef NO_LOG_FILE
		LogMessage(combinedMessage);
		#endif
	#else
		switch(level)
		{
		case LogLevel::Info:
			#if LOGGER_MIN_LEVEL < 2
			__android_log_print(ANDROID_LOG_INFO, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Warning:
			#if LOGGER_MIN_LEVEL < 3
			__android_log_print(ANDROID_LOG_WARN, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Error:
			#if LOGGER_MIN_LEVEL < 4
			__android_log_print(ANDROID_LOG_ERROR, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Debug:
			#if LOGGER_MIN_LEVEL < 5
			#ifdef DEBUG
			__android_log_print(ANDROID_LOG_DEBUG, tag.c_str(), pMessage.c_str());
			#endif
			#endif
			break;
		}
		#ifndef NO_LOG_FILE
		tstringstream messageBuffer;
		messageBuffer << _T("[") << tag << _T("] ") << _T("[") << levelName <<  _T("] ") << pMessage << std::endl;
		LogMessage(messageBuffer.str());
		#endif
	#endif
#endif
	}
Пример #15
0
void SetColor(unsigned char Fore, unsigned char Back)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),(Fore & 15)+(Back & 15)*16);
}
Пример #16
0
void Console::SetColor(unsigned short attr)
{
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon, attr);
}
Пример #17
0
int waeprintf (const char *fmt, ...)
{
	int result = 0;
	int strSize, param;
	char *strBuff, *s;
	va_list args;
	HANDLE hStdOut;
	CONSOLE_SCREEN_BUFFER_INFO csbi;

	hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	if (hStdOut == INVALID_HANDLE_VALUE
	 || !GetConsoleScreenBufferInfo(hStdOut, &csbi))
	{
		/* Attempt fallback, fixes MSYS. */
		va_start (args, fmt);
		result = vprintf (fmt, args);
		va_end (args);
		fflush (stdout);
		return result;
	}

	/* Find out how much memory to allocate. */
	va_start(args, fmt);
	strSize = vsnprintf(NULL, 0, fmt, args);
	va_end(args);

	if (!(strBuff = malloc(strSize + 1)))
		return -1;

	va_start(args, fmt);
	result = vsnprintf(strBuff, strSize + 1, fmt, args);
	va_end(args);

	for (s = strBuff; *s;)
	{
		char *p, code, changed;

		if (*s != '\x1b')
		{
			putchar(*s++);
			continue;
		}
		if (*++s != '[')
		{
			putchar(*s++);
			continue;
		}
		p = ++s;
		while (*s && (*s < 64 || *s > 126))
			s++;
		if (!*s)
			break;

		/* We only care for colors so far. */
		if ((code = *s++) != 'm')
			continue;
		for (param = changed = 0; p < s; p++)
		{
			if (*p >= '0' && *p <= '9')
				param = param * 10 + *p - '0';
			else
			{
				changed |= waeprocess(&csbi, code, param);
				param = 0;
			}
		}
		if (changed)
			SetConsoleTextAttribute(hStdOut, csbi.wAttributes);
	}

	free(strBuff);
	return result;
}
Пример #18
0
void InitConsole() {
	console	 = GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleScreenBufferInfo(console,&cinfo);
	SetConsoleTextAttribute(console, 0xF0);
}
Пример #19
0
/*
 * デフォルトカラー設定メソッド。
 * @return なし
 */
void ScreenControl::setDefaultColor(void)
{
    SetConsoleTextAttribute(mHandle, mInitColor);
    return;
}
Пример #20
0
        void out(exlib::string& s)
        {
            exlib::wstring ws = utf8to16String(s);
            exlib::wchar *ptr = &ws[0];
            exlib::wchar *pend = ptr + ws.length();
            exlib::wchar *ptr2;
            DWORD dwWrite;

            while (ptr2 = (exlib::wchar *) qstrchr(ptr, L'\x1b'))
            {
                if (ptr2[1] == '[')
                {
                    WriteConsoleW(m_handle, ptr, (DWORD)(ptr2 - ptr), &dwWrite, NULL);

                    ptr2 += 2;

                    while (true)
                    {
                        if (ptr2[0] == 'm')
                        {
                            m_Now = m_wAttr;
                            m_wLight = m_wAttr & FOREGROUND_INTENSITY;
                            SetConsoleTextAttribute(m_handle, m_Now);
                            ptr2 ++;
                            break;
                        }

                        if (qisdigit(ptr2[0]))
                        {
                            if (ptr2[1] == 'm')
                            {
                                if (ptr2[0] == '0')
                                {
                                    m_Now = m_wAttr;
                                    m_wLight = m_wAttr & FOREGROUND_INTENSITY;
                                    SetConsoleTextAttribute(m_handle, m_Now);
                                }
                                ptr2 += 2;
                                break;
                            }

                            WORD mask, val;
                            WORD light = m_wLight;

                            if (ptr2[1] == ';')
                            {
                                if (ptr2[0] == '0')
                                    m_wLight = light = 0;
                                else if (ptr2[0] == '1')
                                    m_wLight = light = FOREGROUND_INTENSITY;
                                ptr2 += 2;
                            }

                            if (ptr2[0] == '3')
                            {
                                mask = 0xf0;
                                ptr2 ++;
                            }
                            else if (ptr2[0] == '4')
                            {
                                mask = 0x0f;
                                ptr2 ++;
                            }
                            else if (ptr2[0] == '9')
                            {
                                mask = 0xf0;
                                light |= FOREGROUND_INTENSITY;
                                ptr2 ++;
                            }
                            else if (ptr2[0] == '1' && ptr2[1] == '0')
                            {
                                mask = 0x0f;
                                light |= FOREGROUND_INTENSITY << 4;
                                ptr2 += 2;
                            }
                            else
                                break;

                            if (!qisdigit(ptr2[0]))
                                break;

                            val = ptr2[0] - '0';

                            if (val != 8)
                            {
                                if (val == 9)
                                {
                                    val = (m_wAttr & 0x0f) | (m_Now & 0xf0);

                                    m_Now = val | light;
                                    SetConsoleTextAttribute(m_handle, m_Now);
                                }
                                else
                                {
                                    val = (val & 2) | ((val & 1) ? 4 : 0)
                                          | ((val & 4) ? 1 : 0);

                                    if (mask == 0x0f)
                                        val <<= 4;

                                    m_Now = (m_Now & mask) | val | light;
                                    SetConsoleTextAttribute(m_handle, m_Now);
                                }
                            }

                            ptr2 ++;
                            if (ptr2[0] == 'm')
                            {
                                ptr2 ++;
                                break;
                            }
                        }
                    }
                }
                ptr = ptr2;
            }

            WriteConsoleW(m_handle, ptr, (DWORD)(pend - ptr), &dwWrite, NULL);
        }
Пример #21
0
void setcolor(int fcolor, int bcolor)
{
	SetConsoleTextAttribute(
		GetStdHandle(STD_OUTPUT_HANDLE),
		(WORD)((bcolor << 4) | fcolor ));
}
Пример #22
0
void set_color(int color_num, int bgcolor) {		// only accept color_num 0 or 1	
	int color_arr[COLOR_SIZE] ={DARK_GREEN,GREEN};  // using only two color
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (bgcolor << 4) | color_arr[color_num]);
}
Пример #23
0
//------------------------------------------------------------------------------
static void display_matches(char** matches, int match_count, int longest)
{
    int i;
    char** new_matches;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    WORD text_attrib;
    HANDLE std_out_handle;
    wchar_t buffer[512];
    int show_matches = 2;
    int match_colour;

    // Process matches and recalculate the longest match length.
    new_matches = match_display_filter(matches, match_count);

    longest = 0;
    for (i = 0; i < (match_count + 1); ++i)
    {
        int len = (int)strlen(new_matches[i]);
        longest = (len > longest) ? len : longest;
    }

    std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(std_out_handle, &csbi);

    // Get the console's current colour settings
    match_colour = get_clink_setting_int("match_colour");
    if (match_colour == -1)
    {
        // Pick a suitable foreground colour, check fg isn't the same as bg, and set.
        text_attrib = csbi.wAttributes;
        text_attrib ^= 0x08;

        if ((text_attrib & 0xf0) == (text_attrib & 0x0f))
        {
            text_attrib ^= FOREGROUND_INTENSITY;
        }
    }
    else
    {
        text_attrib = csbi.wAttributes & 0xf0;
        text_attrib |= (match_colour & 0x0f);
    }

    SetConsoleTextAttribute(std_out_handle, text_attrib);

    // If there's lots of matches, check with the user before displaying them
    // This matches readline's behaviour, which will get skipped (annoyingly)
    if ((rl_completion_query_items > 0) &&
        (match_count >= rl_completion_query_items))
    {
        DWORD written;

        _snwprintf(
            buffer,
            sizeof_array(buffer),
            L"\nDisplay all %d possibilities? (y or n)",
            match_count
        );
        WriteConsoleW(std_out_handle, buffer, wcslen(buffer), &written, NULL);

        while (show_matches > 1)
        {
            int c = rl_read_key();
            switch (c)
            {
            case 'y':
            case 'Y':
            case ' ':
                show_matches = 1;
                break;

            case 'n':
            case 'N':
            case 0x7f:
                show_matches = 0;
                break;
            }
        }
    }

    // Get readline to display the matches.
    if (show_matches > 0)
    {
        // Turn of '/' suffix for directories. RL assumes '/', which isn't the
        // case, plus clink uses colours instead.
        int j = _rl_complete_mark_directories;
        _rl_complete_mark_directories = 0;

        rl_display_match_list(new_matches, match_count, longest);

        _rl_complete_mark_directories = j;
    }
    else
    {
        rl_crlf();
    }

    // Reset console colour back to normal.
    SetConsoleTextAttribute(std_out_handle, csbi.wAttributes);
    rl_forced_update_display();
    rl_display_fixed = 1;

    // Tidy up.
    for (i = 0; i < match_count; ++i)
    {
        free(new_matches[i]);
    }
    free(new_matches);
}
Пример #24
0
void DA::Log::ResetTextColor()
{
	// Set the color to white.
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
}
Пример #25
0
void drawMainMenu(int pos)
{

	CONSOLE_CURSOR_INFO cursor;
	cursor.bVisible = false;
	cursor.dwSize = 1;
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor);
   int current=pos; // store the value of the currently highlighted selection

   gotoxy(25,4); // position on screen
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
   cprintf("        BU MicroSight        "); // name of menu item
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

   if (current == 1)
   {

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
    // turn text color to black
      // turn the text background color grey

     gotoxy(25,7); // position on screen
     cprintf("-> Alter System Variables    "); // name of menu item

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    // textcolor(7);  // turn the text colour back to normal
    // textbackground(0);  // turn the text BG to black
   }
   else
   {
     gotoxy(25, 7);
     cprintf("   Alter System Variables    ");
   }

   if(current == 2)
   {
     //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
    // textbackground(7);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);

     gotoxy(25, 9);
     cprintf("-> Edit Trial Details        ");

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
     //textcolor(7);
     //textbackground(0);

   }
   else
   {
     gotoxy(25, 9);
     cprintf("   Edit Trial Details        ");
   }

   if(current == 3)
   {

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
  
     gotoxy(25, 11);
     cprintf("   Set Segmentation Method   ");

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
		
   }
   else
   {

     gotoxy(25, 11);
     cprintf("   Set Segmentation Method   ");

   }

   if (current == 4)
   {
      
	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);

     gotoxy(25, 13);
     cprintf("   Begin Trial Now           ");

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

   }
   else
   {

     gotoxy(25, 13);
     cprintf("   Begin Trial Now           ");

   }


   if(current == 5)
   {
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);

     gotoxy(25, 19);
     cprintf("   Exit                      ");

      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

   }
   else
   {

     gotoxy(25, 19);
     cprintf("   Exit                      ");

   }

}
Пример #26
0
int main(){
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hStdOut, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY | FOREGROUND_GREEN);
	int i, j;
	for (i = 0; i < 80; i++)
		printf("*");
	for (i = 0; i < N + 2; i++){
		printf("*");
		for (j = 1; j < 79; j++)
			printf(" ");
		printf("*");
	}
	for (i = 0; i < 80; i++)
		printf("*");
	SetConsoleTextAttribute(hStdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY | FOREGROUND_BLUE);


	gotoxy(0, N + 4);


	int a, b;
	printf("Enter interval:\na = ");
	scanf("%d", &a);
	printf("b = ");
	scanf("%d", &b);
	while (a>b){
		printf("Error!\nEnter :\na = ");
		scanf("%d", &a);
		printf("b = ");
		scanf("%d", &b);
	}

	int mas[N][N];
	srand(time(NULL));
	initialize_array(mas, a, b);

	print(mas);
	clean();

	//--------------------------------------------------

	char * str = (char*)malloc(10 * sizeof(char));
	char *p = (char*)malloc(10 * sizeof(char));
	getchar();
	gets(str);
	
	strcpy(p, str);
	int len = strlen(p);
	for (i = 0; i < len; i++)
		if (p[i] == ' ') p[i] = '\0';

	while (strcmp(str, "end")){


		if (!strcmp(str, "help")){
			clean();
			help();
		}
		else if (!strcmp(str, "res")){
			reset(mas);
			print(mas);
			clean();
		}
		else if (!strcmp(str, "initar")) {
			printf("Enter interval:\na = ");
			scanf("%d", &a);
			printf("b = ");
			scanf("%d", &b);
			while (a > b){
				printf("Error!\nEnter :\na = ");
				scanf("%d", &a);
				printf("b = ");
				scanf("%d", &b);
			}
			initialize_array(mas, a, b);
			print(mas);
			clean();
		}
		else if (!strcmp(p, "ch")){
			change(mas, p);
			print(mas);
			clean();
		}
		else if (!strcmp(str, "rev")){
			rev_min_max(mas);
			
			clean();
		}
		else if (!strcmp(str, "rot180")){
			rotateCW180(mas);
			print(mas);
			clean();
		}
		else if (!strcmp(str, "meanv")){
			printf("%g\n",mean_value(mas));
		}
		else if (!strcmp(str, "rfl")){
			rotate_first_last(mas);
			clean();
		}
		else if (!strcmp(str, "rll")){
			rotate_last_last(mas);
			clean();
		}
		else if (!strcmp(p, "sumj")){
			p += strlen(p) + 1;
			int t = atoi(p) - 1;
			if (t > 0 && t <= N){
				sum_elements(mas, t);
			}
			else {
				SetConsoleTextAttribute(hStdOut, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY | BACKGROUND_BLUE | FOREGROUND_RED);
				printf("Is not a valid number!\n");
				SetConsoleTextAttribute(hStdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY | FOREGROUND_BLUE);
			}
		}
		else {
			clean();
			SetConsoleTextAttribute(hStdOut, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY | BACKGROUND_BLUE | FOREGROUND_RED);
			printf("Please, enter help!\n");
			SetConsoleTextAttribute(hStdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY | FOREGROUND_BLUE);
		}

		gets(str);
		strcpy(p, str);
		int len = strlen(p);
		for (i = 0; i < len; i++)
			if (p[i] == ' ') p[i] = '\0';		
	}
}
Пример #27
0
DWORD WINAPI waiting_for(LPVOID p)
{            
      int ret,first = 1;
      int i=0;
      unsigned char c;
      int flag;
      unsigned short crc;
      int u;
      
      struct Frame *f;
      
      f = (struct Frame*) p;
   
      f->length =0; 
      f->type = 0; 
      
      if(side == 0)//LADO IZQUIERDO (EMISOR)
      {
          while(1)
          {                    
              flag = 0;
              
              while(flag ==0)
              {
                 if(first == 1)//es el primer caracter, por tanto esperamos hasta que exista uno en el buffer que poder leer
                  {
                    f_esperar_leer(INFINITE);
                    clearFrame(f);//aprovechamos para limpiar la trama
                    i=0;    
                  }
                  else
                  {
                    f_esperar_leer(800);//este ya no es el primer caracter
                  }
                  
                  ret=f_leer(&c);                
                  first= 0;
                  		
                  switch (ret)
                  {               
                     case 0://sin problemas al leer                   
                        fI->body[i] = c;
                        fI->length++;
            				i++;          				 
                     break;
           				
            			case -1://sobreescritura
            				if(mode == 1){fprintf(stderr,"Error de sobrescritura al leer\n");}		
           				break;
           				
            			case -2://no queda nada que leer
                                          
            			   //evaluamos la trama
                        fI->type = evaluateFrame(fI);  
                                 
            			   if(mode == 1)
                        { 
               			   printf("\n-------------------------------RECEIVED------------------------------------\n");                                                                        			   
               			   if(fI->type != -1)
               			   {
                           	SetConsoleTextAttribute(hstdoutI, FOREGROUND_GREEN); //Letra verde para trama correcta
                           }
                           else
                           {
                              SetConsoleTextAttribute(hstdoutI, FOREGROUND_RED); //Letra roja para trama incorrecta
                           }
               			   for(u=0;u<fI->length;u++)
                           {
                              printData(fI->body[u]);
                              printf(" ");
                           }
                           
                           printf("\n");
                           SetConsoleTextAttribute(hstdoutI, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); //Letra blanca
                        }
                        
            			   //indicamos que hay una trama lista
                        ReleaseSemaphore(side_I_data_ready,1,NULL);
                        
                        //reiniciamos los valores de control
                        first=1;
                        flag = 1;
           				break;
           				
            			case -3:
                        fprintf(stderr,"\nComunication off\n");
                        conexionOK = 0;
                        ExitThread(1);
           				break;
           			} 
               } 
          } 
       }
       else//LADO DERECHO (RECEPTOR)
       { 
          while(1)
          {       
            flag = 0;
             
              while(flag ==0)
              {
                  if(first == 1)//es el primer caracter, por tanto esperamos hasta que exista uno en el buffer que poder leer
                  {
                     f_esperar_leer(INFINITE);
                     clearFrame(f);//aprovechamos para limpiar la trama
                     i=0;   
                  }
                  else
                  {
                      f_esperar_leer(800);//no es el primera caracter
                  }
                  
                  ret=f_leer(&c);                
                  first = 0;
                
                  switch (ret)
                  {
                	    case 0://sin problemas al leer
                           fD->body[i] = c;
                           fD->length++;
                				i++;
                		break;
               				
                		case -1://sobreescritura
                			if(mode == 1){fprintf(stderr,"Read overrrun error\n");}		
               		break;
               				
                		case -2://no queda nada que leer
                        
                        //evaluamos la trama
                        fD->type = evaluateFrame(fD);
                        
                        if(mode == 1)
                        {
                           printf("\n-------------------------------RECEIVED------------------------------------\n");
                                                 			                   			                 			    
                   			if(fD->type != -1)
               			   {                         
                           	SetConsoleTextAttribute(hstdoutD, FOREGROUND_GREEN); //Letra verde para trama correcta         
                           }
                           else
                           {
                              SetConsoleTextAttribute(hstdoutD, FOREGROUND_RED); //Letra roja para trama incorrecta
       
                           }
                   			for(u=0;u<fD->length;u++)
                           {
                              printData(fD->body[u]);
                              printf(" ");
                           }                                            
                           printf("\n");
                           SetConsoleTextAttribute(hstdoutD, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); //Letra blanca
                        }
                        else
                        {
                           //para que cuando no este en modo debug muestre los datos que recibe
                           if(fD->type == dataFrame)
                           {
                              catchData(fD);
                              printf("\nReceived: %s",fD->data);
                           }
                           
                        }
                        
                        //indicamos que hay una trama lista
                			ReleaseSemaphore(side_D_data_ready,1,NULL);
                			
                			//reiniciamos los valores de control
                			first=1;
                		   flag = 1;                                     
               		 break;
               				
                		case -3://la comunicacion se ha cortado
                			fprintf(stderr,"\nComunication offn\n");
                			conexionOK = 0;
                			fD->type = -5;
                			ExitThread(1);
               		break;
               	} 
               }  
            } 
      }       
}
Пример #28
0
static int run_tests(struct TestData aTest[], unsigned test_count, unsigned max_conc_thread, char const *pubkey, char const *keysub, char const *origin)
{
    unsigned next_test = 0;
    unsigned failed_count = 0;
    unsigned passed_count = 0;
    unsigned indete_count = 0;
    HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo; 
    WORD wOldColorAttrs = FOREGROUND_INTENSITY;

    PUBNUB_ASSERT_OPT(max_conc_thread <= TEST_MAX_HANDLES);
    PUBNUB_ASSERT_OPT(hstdout != INVALID_HANDLE_VALUE);

    g_pubkey = pubkey;
    g_keysub = keysub;
    g_origin = origin;

    printf("Starting Run of %d tests\n", test_count);
    if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) {
        wOldColorAttrs = csbiInfo.wAttributes; 
    }

    while (next_test < test_count) {
        unsigned i;
        unsigned in_this_pass = max_conc_thread;
        HANDLE aHa[TEST_MAX_HANDLES];

        if (next_test + in_this_pass > test_count) {
            in_this_pass = test_count - next_test;
        }
        for (i = next_test; i < next_test+in_this_pass; ++i) {
            printf("Creating a thread for test %d\n", i);
            aHa[i - next_test] = aTest[i].pth = (HANDLE)_beginthreadex(NULL, 0, aTest[i].pf, &aTest[i].result, 0, NULL);
        }
        /* This is the simplest way to do it - wait for all threads to finish.
          With a little tweak, we could wait for the first that finishes and
          launch the next test (thread) "in its place". That's a TODO for
          next version.
         */
        if (WAIT_OBJECT_0 != WaitForMultipleObjects(in_this_pass, aHa, TRUE, INFINITE)) {
            SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
            printf("\n ! WaitForMultipleObjects failed abandonding tests!\n\n");
            SetConsoleTextAttribute(hstdout, wOldColorAttrs);
            return -1;
        }
        for (i = next_test; i < next_test+in_this_pass; ++i) {
            switch (aTest[i].result) {
	    case trFail:
                SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
		printf("\n!!!!!!! The %d. test ('%s') failed!\n\n", i + 1, aTest[i].name);
                ++failed_count;
                SetConsoleTextAttribute(hstdout, wOldColorAttrs);
		break;
	    case trPass:
                ++passed_count;
		break;
            case trIndeterminate:
                ++indete_count;
                SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
		printf(" Indeterminate %d. test ('%s') of %d\t", i+1, aTest[i].name, test_count);
                SetConsoleTextAttribute(hstdout, wOldColorAttrs);
                /* Should restart the test... */
		//printf("\x1b[33m ReStarting %d. test of %ld\x1b[m\t", i + 1, test_count);
                break;
            }
        }
        next_test = i;
    }
    
    puts("Test run over.");
    if (passed_count == test_count) {
        SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
        printf(" All %d tests passed.\n", test_count);
        SetConsoleTextAttribute(hstdout, wOldColorAttrs);
        return 0;
    }
    else {
        SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
        printf("%d tests passed, ", passed_count);
        SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
        printf("%d tests failed, ", failed_count);
        SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        printf("%d tests indeterminate\n", indete_count);
        SetConsoleTextAttribute(hstdout, wOldColorAttrs);
        return failed_count + indete_count;
    }
}
Пример #29
0
static void RestoreConsoleTextColor( WORD color )
{
	SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color | g_BackgroundFlags );
	g_LastColor = color;
}
Пример #30
0
    std::ostream & operator<<(std::ostream &out, const Color &c) {

#ifdef WINDOWS_OS
        switch (c) {
            case DEFAULT:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors.defaultColor);
                break;

            case BLACK:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0);
                break;
            case BLUE:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
                break;
            case RED:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
                break;
            case CYAN:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
                break;
            case GREEN:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
                break;
            case MAGENTA:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
                break;
            case WHITE:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
                break;
            case GRAY:
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
                break;
            case BOLD:
                WORD colors = DefaultColors::GetCurrentColor();
                colors |= FOREGROUND_INTENSITY;
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
                break;
    
        }

#else

        switch (c) {
            case DEFAULT:
                out << "\033[0m" ;
                break;

            case BLACK:
                out << "\033[0;30m";
                break;
            case BLUE:
                out << "\033[0;34m";
                break;
            case RED:
                out << "\033[0;31m";
                break;
            case CYAN:
                out << "\033[0;36m";
                break;
            case GREEN:
                out << "\033[0;32m";
                break;
            case MAGENTA:
                out << "\033[0;35m";
                break;
            case WHITE:
                out << "\033[0;37m";
                break;
            case GRAY:
                out << "\033[0;37m";
                break;
            case BOLD:
                out << "\033[1m";
                break;
        }
#endif

        return out;
    }