Пример #1
0
void
Esp8266WiFiPhy::ConfigureSoftAP(SoftAccessPoint sap, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWSAP_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + StringEscape(sap.m_ssid);
	ATCommand += "," + StringEscape(sap.m_password);
	ATCommand += "," + IntegerToString(sap.m_channel);
	ATCommand += "," + IntegerToString(sap.m_encryption);
	ATCommand += "," + IntegerToString(sap.m_maxconnections);
	ATCommand += "," + IntegerToString(sap.m_ssidbroadcast);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWSAP_xxx\r\n");
		return;
	}
	// assign to internal variable
	m_softAP = sap;
	testprintf("Ended!\r\n");
}
Пример #2
0
inline void Vector<ElemType>::checkRange(int index, const char *verb) {
	if (index < 0 || index >= size()) {
		Error("Attempt to " + string(verb) + " index "
		      + IntegerToString(index) + " in a vector of size "
		      + IntegerToString(size()) + ".");
	}
}
Пример #3
0
void
WinProperties::saveProperty(const std::string& nspace, const std::string& key, const std::string& value)
{
	std::string completeKey = root;
	completeKey.append(nspace);

	HKEY hRegKey;
	LONG OpenRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, completeKey.c_str(), 0, KEY_SET_VALUE, &hRegKey);

	if (OpenRet != ERROR_SUCCESS)
	{
		std::string ErrorMessage("WinProperties:saveProperty: Unknown root or namespace. Win32ErrorCode: ");
		ErrorMessage = ErrorMessage + IntegerToString(OpenRet);
		throw GeneralGameException(ErrorMessage);
	}

	LONG SetRet = RegSetValueEx(hRegKey, key.c_str(), 0, REG_SZ, (CONST BYTE*)value.c_str(), (DWORD)(value.size() + 1) * sizeof(wchar_t));

	RegCloseKey(hRegKey);

	if (SetRet != ERROR_SUCCESS)
	{
		std::string ErrorMessage("WinProperties:saveProperty: Cannot write value. Win32ErrorCode: ");
		ErrorMessage = ErrorMessage + IntegerToString(SetRet);
		throw GeneralGameException(ErrorMessage);
	}
}
//
// 주어진 마우스 위치 그룹으로 마우스 에뮬레이팅을 한다.
//
void EmulMouse::MouseEmulating()
{
	while (isThreadExit == false)
		for (unsigned int idx = 0; idx < vec_MouseXY.size(); ++idx)
		{
			long mouseX = 0, mouseY = 0;
			mouseX = vec_MouseXY[idx].x;
			mouseY = vec_MouseXY[idx].y;

			if (isThreadExit == true) return;
			LeftMouseClick(mouseX, mouseY);

			string buffer;
			char* strX;
			char* strY;

			IntegerToString(mouseX, &strX);
			IntegerToString(mouseY, &strY);

			buffer += "x :";
			buffer += strX;
			buffer += " ";
			buffer += "y :";
			buffer += strY;
			buffer += "\r\n";

			threadLogBuffer.push_back(buffer);
			
			if (isThreadExit == true) return;
			Sleep(mouseClickTime);
		}

	isEmulStart = false;
}
//--------------------------------------------------------------
//IntegerToStringTest
TEST(IntegerToStringTest, PositiveNos) { 

	Integer a = 123;
	Integer b("0xA");
    EXPECT_EQ ("18.", IntegerToString(18));
	EXPECT_EQ ("10.", IntegerToString(b));
	EXPECT_EQ ("123.", IntegerToString(a));
}
Пример #6
0
string RationalExpression::toString() {
	string stringRep = IntegerToString(numerator);
	if (denominator > 1) {
		stringRep += '/';
		stringRep += IntegerToString(denominator);
	}
	return stringRep;
}
TEST(IntegerToStringTest, NegativeNos) { 

	Integer a = -123;
	//NOTE: -ve numbers in hexadecimal format is not supported.	
	Integer b("0x-A");
    EXPECT_EQ("-18.", IntegerToString(-18));
//	EXPECT_EQ("-10.", IntegerToString(b));
	EXPECT_EQ("-123.", IntegerToString(a));
}
Пример #8
0
void DrawStartingBoard(string choice)
{
	int i;
	string letter[10]={"A","B","C","D","E","F","G","H","I","J"};
	if( StringEqual(choice,"y") ) { PlayNamedSound("Fanfare"); }
	for (i=0;i<=NUM_COLS;i++)
	{
		if (i!=NUM_COLS)
		{
			MovePen((i+1.3)*LG,GetWindowHeight()-LG);
			DrawTextString(IntegerToString(i));
		}
		MovePen((i+1)*LG,GetWindowHeight()-1.3*LG);
		DrawLine(0,(-NUM_ROWS)*LG);
	}
	for (i=0;i<=NUM_ROWS;i++)
	{
		if (i!=NUM_ROWS)
		{
			MovePen(LG/4,GetWindowHeight()-(11.1-i)*LG);
			DrawTextString(letter[9-i]);
		}
		MovePen(LG,GetWindowHeight()-(11.3-i)*LG);
		DrawLine((NUM_COLS)*LG,0);
	}
}
Пример #9
0
//Warm-up A: Print in binary
string Warmup::RecPrintInBinary(int num) {
	if (num == 0) return "0";
	else if (num == 1) return "1";
	else {
		return RecPrintInBinary(num / 2) + IntegerToString(num % 2);
	}	
}
Пример #10
0
void
Esp8266WiFiPhy::ListStationAP(StationAccessPoint sap){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWLAP";
	if (!sap.m_ssid.empty()){
		ATCommand += "=" + StringEscape(sap.m_ssid);
		if (!sap.m_bssidmac.empty()){
			ATCommand += "," + StringEscape(sap.m_bssidmac);
			if (sap.m_channel != -1){
				ATCommand += "," + IntegerToString(sap.m_channel); // not to be escaped, since number!
			}
		}
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWLAP\r\n");
		return;
	}
	dbgprintf("+CWLAP:(<ECN>,<SSID>,<RSSI>,<MAC>,<CH>,<FREQ OFFSET>,<FREQ CALIB>)\r\n");
	testprintf("Ended!\r\n");
}
Пример #11
0
void
Esp8266WiFiPhy::SetWiFiMode(uint8_t mode, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWMODE_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + IntegerToString((int)mode);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWMODE_xxx=\r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Пример #12
0
FILE * GetFile(void)
{
	int num;
	string fname;
	num=RandomInteger(1,5);
	fname=Concat("ShipData",IntegerToString(num));
	return fopen(fname,"r");
}
Пример #13
0
/* 
 * Function: EraseOldScore
 * ------------------------
 * I used to do this with SetEraseMode, but that left cruft behind, so instead
 * paint an opaque white box over the old score
 */
static void EraseOldScore(playerT playerNum, int value)
{   
    SetFont(SCORE_FONT);
    SetPointSize(SCORE_FONT_SIZE);
    string str = IntegerToString(value);
    FillBox(gState.scoreBox[playerNum].x + gState.scoreBox[playerNum].w - TextStringWidth(str), 
	    gState.scoreBox[playerNum].y + GetFontDescent(),
	    TextStringWidth(str), GetFontAscent(), 1.0, "blue");
}
void EmulMouse::SetPosTextWnd(HWND _hWnd, long _x, long _y)
{
	string buffer;
	char* strX;
	char* strY;

	IntegerToString(_x, &strX);
	IntegerToString(_y, &strY);

	buffer += "x :";
	buffer += strX;
	buffer += " ";
	buffer += "y :";
	buffer += strY;

	wstring wstrBuffer = s2ws(buffer);
	LPCWSTR result = wstrBuffer.c_str();

	SetWindowText(_hWnd, result);
}
Пример #15
0
/* 
 * Function: DrawOneScore
 * ----------------------
 * Draws the specified score for the player according to player enum.
 */
static void DrawOneScore(playerT playerNum, int value)
{   
    SetFont(SCORE_FONT);
    SetPointSize(SCORE_FONT_SIZE);
    SetPenColor("Label Color");
    string str = IntegerToString(value);
    MovePen(gState.scoreBox[playerNum].x + gState.scoreBox[playerNum].w - TextStringWidth(str), 
	    gState.scoreBox[playerNum].y + GetFontDescent() + 0.03); // the 0.03 hack added Sept-2011
    // Using SetEraseMode() to delete old score interfered with the line underneath
    DrawTextString(str);
}
Пример #16
0
/*Generates string from vector*/
string GenerateString(vector<Integer> v)
{
	string output;
	Integer temp;

	for(vector<Integer>::iterator itr = v.begin(); itr != v.end(); itr++)
	{
		temp = *itr;
		output = output + IntegerToString(temp);
	}
	return output;
}
Пример #17
0
/*Function to compute input string for hash function*/
string ComputeHashString(vector<Integer> generators, vector<Integer> public_keys,
                         vector<Integer> T)
{
	string output;
	unsigned int i = 0;
	for( vector<Integer>::iterator itr = generators.begin();
	    itr != generators.end(); itr++, i++)
	{
		//g1, y1, g2, y2, ........ gn, yn
		output += IntegerToString(*itr) + IntegerToString(public_keys[i]);
	}

	//append t1, t2, ........ tn

	for(vector<Integer>::iterator itr = T.begin(); itr != T.end(); itr++)
	{
		output = output + IntegerToString(*itr);
	}

	return output;
}
Пример #18
0
void DrawScore(int MissilesLeft,int ShipsLeft,int hit,int total)
{
	MovePen(16.5*LG,GetWindowHeight());
	StartFilledRegion(1);
	SetPenColor("White");
	DrawLine(0,-10*LG);
	DrawLine(7*LG,0);
	DrawLine(0,10*LG);
	DrawLine(-7*LG,0);
	EndFilledRegion();
	SetPenColor("Black");
	MovePen(17*LG,GetWindowHeight()-4*LG);
	DrawTextString("Missiles left: ");
	DrawTextString(IntegerToString(MissilesLeft));
	MovePen(17*LG,GetWindowHeight()-5.5*LG);
	DrawTextString("Ships to sink: ");
	DrawTextString(IntegerToString(ShipsLeft));
	MovePen(17*LG,GetWindowHeight()-7*LG);
	DrawTextString("Hit rate: ");
	DrawTextString(IntegerToString(percent(hit,total)));
	DrawTextString("%");
}
Пример #19
0
void createGrowthFile(ordGrowthT algorithm){
	int i, stop;
	stop = (algorithm->arrSize/50);
	FILE *outfile;
	string file;
	file = Concat(algorithm->algorithm, ".txt");
	outfile = fopen(file, "w");
	fprintf(outfile, "%s\n", algorithm->algorithm);
	//spara de vanliga mönstren
	//5
	fprintf(outfile, "\ncommon 5pattern textlen\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->textLen[i]));
	}
	fprintf(outfile,"\ncommon 5pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->five->nComps[i]));
	}

	fprintf(outfile, "\ncommon 10pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->ten->nComps[i]));
	}
	
	fprintf(outfile, "\ncommon 20pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->twenty->nComps[i]));
	}

	//spara de ovanliga mönstren

	//5
	
	fprintf(outfile, "\nUNncommon 5pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->lowfive->nComps[i]));
	}
	//10

	fprintf(outfile, "\nUNcommon 10pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->lowten->nComps[i]));
	}
	//20
	
	fprintf(outfile, "\nUNcommon 20pattern ncomps\n");
	for (i = 0; i < stop; i++){
		fprintf(outfile, "%s	", IntegerToString(algorithm->lowtwenty->nComps[i]));
	}

	fclose(outfile);
	printf("File created");
}
Пример #20
0
bool Encoding::decompress(ibstream &inStream, obstream &outStream){
	int mapSize = inStream.get();
	char kill = inStream.get(); //get rid of pipe

	map<string, int> dmap; //remove this after testing
	for (int i = 0; i < mapSize; i++){
		int code;
		string key;
		code = inStream.get();
		int val = inStream.get();
		while (val != '|'){
			key += val;
			val = inStream.get();
		}
		dmap[key] = code;
	}

		int input;
		string code;

	while (true){
			code += IntegerToString(inStream.readbit());
			if (dmap.count(code) > 0){
				input = dmap[code];
				//cout << input << endl;
				outStream.put(input);
				code.clear();
				if (inStream.peek() == _EOF_)
				break;
			}
	}


	cout << " made it out of the loop";
		outStream.close();


	return true;
}
Пример #21
0
bool HttpClient::Request(HttpRequest::MethodType method,
                         const std::string& url,
                         const std::string& data,
                         const HttpClient::Options& options,
                         HttpResponse *response,
                         ErrorCode *error)
{
    ErrorCode error_placeholder;
    if (error == NULL) {
        error = &error_placeholder;
    }

    HttpRequest request;
    request.SetMethod(method);
    request.SetBody(data);
    request.SetHeader("Content-Length", IntegerToString(data.size()));

    DownloadTask task(this);
    bool ret = task.ProcessRequest(url, options, &request, response);

    *error = task.GetLastError();
    return ret && *error == SUCCESS;
}
Пример #22
0
 String ConvertToString(const IntType& val)
 {
   return IntegerToString(val);
 }
Пример #23
0
string ConvertCoordinates(cityT city) {
    string coords;
    coords = IntegerToString(city.coordinates.x) + ":" + IntegerToString(city.coordinates.y);
    return coords;
}
Пример #24
0
std::string
WinProperties::loadProperty(const std::string& nspace, const std::string &key) const
{
		// erst Session Keys prüfen
	std::string newKey = nspace + "/" + key;
	
	std::map<std::string, std::string> ::const_iterator iter = propMap.find(newKey);

	if (propMap.end() != iter)
		return iter->second;

		// in Session nicht vorhanden -> aus Registry laden
	std::string completeKey = root;
	completeKey.append(nspace);

	HKEY hRegKey;
	LONG OpenRet = RegOpenKeyEx(HKEY_CURRENT_USER, completeKey.c_str(), 0, KEY_QUERY_VALUE, &hRegKey);

	if (OpenRet != ERROR_SUCCESS)
	{
		std::string ErrorMessage("WinProperties:loadProperty: Unknown root or namespace (\"");
		ErrorMessage = ErrorMessage + completeKey;
		ErrorMessage = ErrorMessage +  "\"). Win32ErrorCode: ";
		
		ErrorMessage = ErrorMessage + IntegerToString(OpenRet);
		throw GeneralGameException(ErrorMessage);
	}

		// Zunächst nur die Länge des String herausfinden
	DWORD KeyLen;
	LONG QueryRet = RegQueryValueEx(hRegKey, key.c_str(), NULL, NULL, NULL, &KeyLen);

	if (QueryRet != ERROR_SUCCESS)
	{
		std::string ErrorMessage("WinProperties::loadProperty: Failed to open key '");
		
		ErrorMessage = ErrorMessage + key + "'. Win32ErrorCode: "  + IntegerToString(QueryRet);
		RegCloseKey(hRegKey);
		throw GeneralGameException(ErrorMessage);
	}

	KeyLen += sizeof(TCHAR);	// für ein Nullzeichen

	TCHAR* buffer = new TCHAR[KeyLen / sizeof(TCHAR)];

	if (!buffer)
	{
		RegCloseKey(hRegKey);
		throw GeneralGameException("WinProperties::loadProperty: Not enough memory to get value.");
	}

	QueryRet = RegQueryValueEx(hRegKey, key.c_str(), NULL, NULL, (LPBYTE)buffer, &KeyLen);

	RegCloseKey(hRegKey);

	if (QueryRet != ERROR_SUCCESS)
	{
		std::string ErrorMessage("WinProperties::loadProperty: Failed to get value. Win32ErrorCode: ");
		ErrorMessage = ErrorMessage + IntegerToString(QueryRet);
		throw GeneralGameException(ErrorMessage);
	}

	std::string value(buffer);
	delete [] buffer;

	return value;
}
Пример #25
0
void DrawDetonatedLandMine(location landMine, int value) {
	DrawCenteredCircle(kLandMineRadius, landMine.x, landMine.y, kNoMinePresentColor);
	DrawCenteredCircle(kLandMineReach - kLandMineRadius, landMine.x, landMine.y, kAlreadyDetonatedMineColor, false);
	DrawCenteredText(IntegerToString(value), landMine.x, landMine.y, "Gray");
}
Пример #26
0
EventLogger_Status_TypeDef EventLogger_LogEvent(EventLogger_Handle_TypeDef *plog, uint Facility,
												uint Severity, uint Node_id, char* Function_id,
												...){

	//if(plog->LogStatus == LOG_BUFFER_FULL) return LOG_BUFFER_FULL;
	EventLogger_Log_TypeDef		TempLog;
	TempLog.LogString[0] = '\0';
	char String[20];
	String[0] = '\0';
	char Time[20];
	Time[0] = '\0';
	int Next = -1;

	switch(Facility){
		case APPLICATION:
			strcat(TempLog.LogString,"Application");
			break;
		case NETWORK:
			strcat(TempLog.LogString,"Network");
			break;
		case DATALINK:
			strcat(TempLog.LogString,"Datalink");
			break;
		case SECURITY:
			strcat(TempLog.LogString,"Security");
			break;
		case MAINTENCE:
			strcat(TempLog.LogString,"Maintence");
			break;
		default:
			strcat(TempLog.LogString,"Unknown");
			break;
	}

	strcat(TempLog.LogString, ",");

	switch(Severity){
		case ALERT:
			strcat(TempLog.LogString, "alert");
			break;
		case CRITICAL:
			strcat(TempLog.LogString, "crit");
			break;
		case ERROR:
			strcat(TempLog.LogString, "err");
			break;
		case WARNING:
			strcat(TempLog.LogString, "warning");
			break;
		case NOTICE:
			strcat(TempLog.LogString, "notice");
			break;
		case INFORMATIONAL:
			strcat(TempLog.LogString, "info");
			break;
		case DEBUGGING:
			strcat(TempLog.LogString, "debug");
			break;
		default:
			strcat(TempLog.LogString, "unknown");
			break;
	}

	strcat(TempLog.LogString, ",");
	strcat(TempLog.LogString, IntegerToString(Node_id, String));
	strcat(TempLog.LogString, "@");
	strcat(TempLog.LogString, Function_id);

	va_list Description_Params;
	va_start (Description_Params, Function_id);

	Next = va_arg(Description_Params, int);
	if(Next == LOG_END){
		strcat(TempLog.LogString, ";\n");
	}
	else{
		strcat(TempLog.LogString, ",");
	do{
		switch(Next){
			case LOG_INT:
				strcat(TempLog.LogString, " ");
				strcpy(String, va_arg(Description_Params, char*));
				strcat(TempLog.LogString, String);
				strcat(TempLog.LogString, "=");
				IntegerToString(va_arg(Description_Params, int), String);
				strcat(TempLog.LogString, String);
				break;
			case LOG_STRING:
				strcat(TempLog.LogString, " ");
				strcpy(String, va_arg(Description_Params, char*));
				strcat(TempLog.LogString, String);
				strcat(TempLog.LogString, "=");
				strcpy(String, va_arg(Description_Params, char*));
				strcat(TempLog.LogString, String);
				break;
			case LOG_END:
				break;
			default:
				Next = LOG_END;
				break;
		}
		Next = va_arg(Description_Params, int);
	} while ( Next != LOG_END);

	strcat(TempLog.LogString, ";\n");
	}


#if (LOG_USE_OS == 1)
	osMutexWait(Log_Mutex, osWaitForever);
	strcat(Time,IntegerToString(_sys_time.year,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.month,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.day,String));
	strcat(Time, ",");
	strcat(Time,IntegerToString(_sys_time.hour,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.minutes,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.seconds,String));
	strcat(Time, ",");
#if	(LOG_USE_BUFFERING == 1)
	int i = 0;
	while(LogIndex_List[i] != 0) {
		i++;
		if(i == LOG_MAX_BUFF){
			osMutexRelease(Log_Mutex);
			plog->LogStatus = LOG_BUFFER_FULL;
			return plog->LogStatus;
		}
	}
	LogIndex_List[i] = 1;
	strcpy(Log_List[i].LogString, Time);
	strcat(Log_List[i].LogString, TempLog.LogString);
	osMessagePut ( plog->os_event, i, 0);
#else	//ELSE BUFFERING
	strcpy(plog->pLogData->LogString, Time);
	strcat(plog->pLogData->LogString, TempLog.LogString);
	plog->Interface->WriteLog(plog);
#endif	//END BUFFERING
	osMutexRelease(Log_Mutex);
#else	// ELSE OS
	strcat(Time,IntegerToString(_sys_time.year,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.month,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.day,String));
	strcat(Time, ",");
	strcat(Time,IntegerToString(_sys_time.hour,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.minutes,String));
	strcat(Time, ":");
	strcat(Time,IntegerToString(_sys_time.seconds,String));
	strcat(Time, ",");
	strcpy(plog->pLogData->LogString, Time);
	strcat(plog->pLogData->LogString, TempLog.LogString);
	plog->Interface->WriteLog(plog);
#endif	// END OS
	va_end(Description_Params);
	return LOG_OK;
}
Пример #27
0
bool CCodeBlocksWorkspace::GenerateMakefile
 (const CString& FileName, CCodeBlocksBuildConfig& Config)
{
 // generate individual makefiles for projects
 CString cwd = GetCurrentDir();
 CString workspace_path = ExtractFilePath(FileName);
 if (!workspace_path.IsEmpty())
 {
  ChangeDir(workspace_path);
 }
 //
 m_TargetNames.Clear(); m_MakefileNames.Clear(); m_TargetDeps.Clear();
 for (size_t i = 0; i < m_Units.size(); i++)
 {
  CString project_name = m_Units[i]->m_FileName;
  //CString makefile_path = JoinPaths(workspace_path,ExtractFilePath(project_name));
  CString makefile_path = ExtractFilePath(project_name);
  //CString makefile_pathname = JoinPaths(workspace_path,project_name+".mak");
  CString makefile_pathname = project_name+".mak";
  CString target_name = ChangeFileExt(project_name,"");
  CString makefile_name = ExtractFileName(makefile_pathname);
  target_name = CCodeBlocksProject::DecorateTargetName(target_name,Config.TargetNameCase());
  CString target_deps;
  for (int j = 0; j < m_Units[i]->m_Depends.GetCount(); j++)
  {
   CString dep_name = ChangeFileExt(m_Units[i]->m_Depends[j],"");
   if (j>0) target_deps += " ";
   target_deps += CCodeBlocksProject::DecorateTargetName(dep_name,Config.TargetNameCase());
  }
  m_TargetDeps.Insert(target_deps);
  m_TargetNames.Insert(target_name);
  m_MakefilePaths.Insert(makefile_path);
  m_MakefileNames.Insert(makefile_name);
  makefile_pathname = MakeNativePath(makefile_pathname);
  //std::cout<<"cwd "<<cwd.GetCString()<<std::endl;
  //std::cout<<"gen_makefile "<<makefile_pathname.GetCString()<<std::endl;
  m_Units[i]->m_Project.GenerateMakefile(makefile_pathname,Config);
 }
 // generate workspace makefile
 int active_platforms = 0;
 for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++)
 {
  if (Config.Platforms().Platform(pi)->Active()) active_platforms++;
 }
 bool single_platform = (1==active_platforms);
 for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++)
 {
  CPlatform *pl = Config.Platforms().Platform(pi);
  if (!pl->Active()) continue;
  CString makefile_path = ExtractFilePath(FileName);
  CString makefile_name = ExtractFileName(FileName);
  CString platform_suffix;
  if (!single_platform) platform_suffix = "."+LowerCase(pl->Name());
  makefile_name += platform_suffix;
  ChangeDir(makefile_path);
  // begin makefile
  m_Makefile.Clear();
  int section = 0;
  // head comment
  const int header_width = 80;
  m_Makefile.Header().Insert(FillStr("#",'-',"#",header_width));
#ifdef REVISION_NUMBER
  {
   CString rn = IntegerToString(REVISION_NUMBER);
   CString line = FillStr("# This makefile was generated by 'cbp2make' tool rev."+rn,' ',"#",header_width);
   m_Makefile.Header().Insert(line);
  }
#else
  CString line = FillStr("# This makefile was generated by 'cbp2make' tool rev.",' ',"#",header_width)
#endif
  m_Makefile.Header().Insert(FillStr("#",'-',"#",header_width));
  m_Makefile.Header().Insert("");
  section++;
  // macros
  CString line = pl->EvalWorkDir();
  m_Makefile.AddMacro("WRKDIR",line,section);
  m_Makefile.AddMacro("MAKE",pl->Tool_Make(),section);
  section++;
  // targets
  CMakefileRule& rule_all = m_Makefile.AddRule("all",section);
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   rule_all.Dependencies().Insert(m_TargetNames[i]);
  }
  section++;
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   CString makefile_path = m_MakefilePaths[i];
   CMakefileRule& rule_target = m_Makefile.AddRule(m_TargetNames[i],section);
   rule_target.Dependencies().Insert(m_TargetDeps[i]);
   line = "$(MAKE)";
   if (!makefile_path.IsEmpty())
   {
    line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode());
   }
   line += " all -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode());
   rule_target.Commands().Insert(line);
  }
  section++;
  //
  CMakefileRule& rule_clean = m_Makefile.AddRule("clean",section);
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   rule_clean.Dependencies().Insert("clean_"+m_TargetNames[i]);
  }
  section++;
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   CString makefile_path = m_MakefilePaths[i];
   CMakefileRule& rule_clean_target = m_Makefile.AddRule("clean_"+m_TargetNames[i],section);
   line = "$(MAKE)";
   if (!makefile_path.IsEmpty())
   {
    line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode());
   }
   line += " clean -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode());
   rule_clean_target.Commands().Insert(line);
  }
  // save makefile
  CStringList& text = m_Makefile.Update();
  text.SaveToFile(makefile_name);
  m_Makefile.Clear();
  ChangeDir(cwd);
 }
 return true;
}
Пример #28
0
void CStringVariable::SetInteger(const int Value)
{
 m_Value = IntegerToString(Value);
}
Пример #29
0
void CCodeBlocksWorkspace::GenerateMakefileText(const CString& FileName,
 CCodeBlocksBuildConfig& Config)
{
 // generate individual makefiles for projects
 //std::cout<<"Workspace: "<<FileName.GetCString()<<std::endl;
 CString cwd = GetCurrentDir();
 CString workspace_path = ExtractFilePath(FileName);
 if (!workspace_path.IsEmpty())
 {
  ChangeDir(workspace_path);
 }
 //std::cout<<"Workspace path: "<<workspace_path.GetCString()<<std::endl;
 m_TargetNames.Clear(); m_MakefileNames.Clear();
 for (size_t i = 0; i < m_Units.size(); i++)
 {
  CString project_name = m_Units[i]->m_FileName;
  CString makefile_path = JoinPaths(workspace_path,ExtractFilePath(project_name));
  CString makefile_pathname = JoinPaths(workspace_path,project_name+".mak");
  CString target_name = LowerCase(ChangeFileExt(project_name,""));
  CString makefile_name = ExtractFileName(makefile_pathname);
  //std::cout<<"Project name: "<<project_name.GetCString()<<std::endl;
  //std::cout<<"Makefile path: "<<makefile_path.GetCString()<<std::endl;
  //std::cout<<"Makefile pathname: "<<makefile_pathname.GetCString()<<std::endl;
  target_name = CCodeBlocksProject::DecorateTargetName(target_name);
  //std::cout<<"Target name: "<<target_name.GetCString()<<std::endl;
  //std::cout<<"Makefile name: "<<makefile_name.GetCString()<<std::endl;
  m_TargetNames.Insert(target_name);
  m_MakefilePaths.Insert(makefile_path);
  m_MakefileNames.Insert(makefile_name);
  makefile_pathname = MakeNativePath(makefile_pathname);
  //std::cout<<"Native makefile pathname: "<<makefile_pathname.GetCString()<<std::endl;
  m_Units[i]->m_Project.GenerateMakefile(makefile_pathname,Config);
 }
 //CString cwd = GetCurrentDir();
 // generate workspace makefile
 int active_platforms = 0;
 for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++)
 {
  if (Config.Platforms().Platform(pi)->Active()) active_platforms++;
 }
 bool single_platform = (1==active_platforms);
 for (size_t pi = 0, pn = Config.Platforms().GetCount(); pi < pn; pi++)
 {
  CPlatform *pl = Config.Platforms().Platform(pi);
  if (!pl->Active()) continue;
  CString makefile_path = ExtractFilePath(FileName);
  CString makefile_name = ExtractFileName(FileName);
  CString platform_suffix;
  if (!single_platform) platform_suffix = "."+LowerCase(pl->Name());
  makefile_name += platform_suffix;
  //ChangeDir(makefile_path);
  //
  m_MakefileText.Clear();
  // head comment
  m_MakefileText.Insert("#------------------------------------------------------------------------------#");
#ifdef REVISION_NUMBER
  {
   CString s = "# This makefile was generated by 'cbp2make' tool rev.                          #";
   CString n = IntegerToString(REVISION_NUMBER);
   int o = FindStr(s,"rev.") + 4;
   for (int i = 0; i < n.GetLength(); i++) s.SetChar(i+o,n[i]);
   m_MakefileText.Insert(s);
  }
#else
  m_MakefileText.Insert("# This makefile was generated by 'cbp2make' tool                               #");
#endif
  m_MakefileText.Insert("#------------------------------------------------------------------------------#");
  m_MakefileText.Insert("");
  // macros
  CString line = "WRKDIR = "+pl->EvalWorkDir();
  m_MakefileText.Insert(line);
  line = "MAKE = "+pl->Tool_Make();
  m_MakefileText.Insert(line);
  m_MakefileText.Insert("");
  // targets
  line = "all:";
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   line.Append(" ").Append(m_TargetNames[i]);
  }
  m_MakefileText.Insert(line); m_MakefileText.Insert("");
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   CString makefile_path = m_MakefilePaths[i];
   line = m_TargetNames[i]+":";
   m_MakefileText.Insert(line);
   line = "\t$(MAKE)";
   if (!makefile_path.IsEmpty())
   {
    line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode());
   }
   line += " all -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode());
   m_MakefileText.Insert(line);
   m_MakefileText.Insert("");
  }
  //
  line = "clean:";
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   line.Append(" clean_").Append(m_TargetNames[i]);
  }
  m_MakefileText.Insert(line); m_MakefileText.Insert("");
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   CString makefile_path = m_MakefilePaths[i];
   line = "clean_"+m_TargetNames[i]+":";
   m_MakefileText.Insert(line);
   line = "\t$(MAKE)";
   if (!makefile_path.IsEmpty())
   {
    line += " -C "+pl->ProtectPath(pl->Pd(makefile_path),Config.QuotePathMode());
   }
   line += " clean -f "+pl->ProtectPath(pl->Pd(m_MakefileNames[i])+platform_suffix,Config.QuotePathMode());
   m_MakefileText.Insert(line);
   m_MakefileText.Insert("");
  }
  //
  line = ".PHONY:";
  for (int i = 0; i < m_TargetNames.GetCount(); i++)
  {
   line.Append(" ").Append(m_TargetNames[i]);
   line.Append(" clean_").Append(m_TargetNames[i]);
  }
  m_MakefileText.Insert(line); m_MakefileText.Insert("");
  m_MakefileText.SaveToFile(makefile_name);
  m_MakefileText.Clear();
  ChangeDir(cwd);
 }
}
Пример #30
0
void PlayGame(coord history[],ship_p cell[][NUM_COLS],class_p clas,ship_p ship,int ship_num,string choice)
{
	int num,hit=0,total=0,sum,length,q,sink=0,sink_this_time;
	string message;
	coord location;
	ship_p boat;
	DrawScore(100,ship_num,0,1);
	for (num=0;num<=99;num++)
	{
		do
		{
			location=GetLocationChosenByUser();
			if ( IsInHistory(location,history) )
			{;}
			else 
			{
				history[num].col=location.col;
				history[num].row=location.row;
				break;
			}
		}
		while(TRUE);
		
		total++;
		sink_this_time=0;
		if ( cell[location.row][location.col]==NULL )
		{			
			MarkMiss(location);
			DrawPrintfMessage("Miss!");
			if ( StringEqual("y",choice) ) { PlayNamedSound("Missile"); }
		}
		else
		{
			hit++;
			boat=cell[location.row][location.col];
			cell[location.row][location.col]=NULL;
			sum=0;
			length=clas[boat->clas].length;
			if( StringEqual(choice,"y") ) { PlayNamedSound( clas[boat->clas].sound ); }
			for (q=0;q<=length-1;q++)
			{
				if (cell[ (boat->contain)[q].row ][ (boat->contain)[q].col ]==NULL)
				{
					sum++;
				}
			}
			if (sum==length)
			{
				sink_this_time=1;
				sink++;
				clas[boat->clas].num--;
				MarkLineAsSunk( boat->contain,length,"White" );
				MarkLineAsSunk( boat->contain,length,clas[boat->clas].color );
				message="You sank the ";
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message," ");
				message=Concat(message,boat->name);
				message=Concat(message," ! ");
				message=Concat(message,"There are ");
				message=Concat( message , IntegerToString(clas[boat->clas].num) );
				message=Concat(message," ");
				message=Concat(message,clas[boat->clas].name);
				message=Concat(message,"s left.");
				DrawPrintfMessage(message);
				if( StringEqual(choice,"y") ) { PlayNamedSound("You Sank My Battleship"); }
			}
			if (sink_this_time==0)
			{
				MarkHit(location,clas[boat->clas].color,0.85);
				DrawPrintfMessage("Direct hit!");
			}
		}
		DrawScore(99-num,ship_num-sink,hit,total);
		if (sink==ship_num)
		{
			break;
		}
	}
	if (sink==ship_num ) { DrawPrintfMessage("You win!"); }
	else { DrawPrintfMessage("I win!"); }
	if( StringEqual(choice,"y") )
	{
		if (sink==ship_num ) { PlayNamedSound("Song of Joy"); }
		else { PlayNamedSound("That's Pathetic"); }
	}
}