Beispiel #1
0
 void LineReader::OnData(const char * d, ssize_t l)
 {
   if(l <= 0) return;
   std::size_t idx = 0;
   while(l-- > 0) {
     char c = d[idx++];
     if(c == '\n') {
       OnLine(d, idx-1);
       d += idx;
     } else if (c == '\r' && d[idx] == '\n') {
       OnLine(d, idx-1);
       d += idx + 1;
     }
   }
 }
EditorString::EditorString(UBSocket* sock, std::string& target) :
Editor(sock),
m_state(M_FIRST),
m_target(target)
{
	OnLine(Global::Get()->EmptyString);
}
void StdinLine::OnRead()
{
	char buf[m_bufsize];
	int n = read(GetSocket(), buf, m_bufsize - 1); //recv(0, buf, 1000, 0);
	if (n == -1)
	{
		Handler().LogError(this, "OnRead", errno, strerror(errno), LOG_LEVEL_FATAL);
		SetCloseAndDelete();
		return;
	}
	for (size_t i = 0; i < (size_t)n; i++)
	{
		switch (buf[i])
		{
		case 13: // ignore
			break;
		case 10:
			OnLine(m_line);
			m_line = "";
			break;
		default:
			m_line += buf[i];
		}
	}
}
Beispiel #4
0
bool HTTPSocket::ProcessReceivedData(char *errbuf)
{
	if (errbuf)
		errbuf[0] = 0;
	if (!recvbuf)
		return true;

	char *buff=(char *)recvbuf;
	unsigned long bufflen=recvbuf_used;

	while(1) {
		if (m_header) {
			char *ptr=(char *)memchr(buff,'\n',bufflen);
			if (!ptr)
				break;
			int length=(ptr-buff)+1;
			std::string line;
			line.append(buff,length-2);
			OnLine(line);

			buff+=length;
			bufflen-=length;
		} else {
			OnData(buff,bufflen);
			buff+=bufflen;
			bufflen=0;
			break;
		}
	}

	if (bufflen) {
		memmove(recvbuf,buff,bufflen);
		recvbuf_used=bufflen;
	} else {
		safe_delete_array(recvbuf);
	}
}
Beispiel #5
0
//----------------------------------------------------------------------------------------------
// Public : Parse
//----------------------------------------------------------------------------------------------
void CObjMesh::Parse( const char* pBuffer )
{
	m_nLine = 0;
	m_pCurPos = strtok_s( (char*)pBuffer, "\r\n", (char**)&m_pNextLine );
	while( m_pCurPos ) 
	{
		m_nLine++;
		OnLine();
		m_pCurPos = strtok_s( NULL, "\r\n", (char**)&m_pNextLine );
	} 

	// Now we have a list of faces as well as vertex/tex/normals
	{
		/*
		// Create an index buffer, and get rid of duplicates.  This works, but it's REALLY slow!
		int nCurIndex = 0;
		for (int i = 0; i < (int)m_pFaces.size(); i++)
		{
		int nIndex = nCurIndex;

		// Search previous "faces" to see if one exists that matches the current one
		for (int nPrev = 0; nPrev <= i; nPrev++)
		{
		if (m_pFaces[i] == m_pFaces[nPrev])
		{
		nIndex = nPrev;
		break;
		}
		}
		m_pIndices.push_back(nIndex);

		if (nIndex == nCurIndex)
		nCurIndex++;
		}
		*/

		// Create an index buffer the stupid way.
		//int nCurIndex = 0;
		//for (int i = 0; i < (int)m_pFaces.size(); i++)
		//{
		//	int nIndex = nCurIndex++;
		//	m_pIndices.push_back(nIndex);
		//}

		if(m_pNormals.empty())
		{
			m_pNormals.resize(m_pVertexCoordinates.size());

			for(unsigned int i = 0; i < m_pNormals.size(); ++i)
			{
				m_pNormals[i].Set(0,0,0);
			}

			for(unsigned int i = 0; i < m_pFaces.size(); i += 3)
			{
				int indexA = m_pFaces[i].m_nVertexCoordIdx;
				int indexB = m_pFaces[i + 1].m_nVertexCoordIdx;
				int indexC = m_pFaces[i + 2].m_nVertexCoordIdx;
				Vector3 a = m_pVertexCoordinates[indexA];
				Vector3 b = m_pVertexCoordinates[indexB];
				Vector3 c = m_pVertexCoordinates[indexC];
				
				Vector3 u,v,normal;
				u = b - a;
				v = c - a;
				
				normal = Vector3::Cross(u,v);
				normal.Normalize();

				m_pNormals[indexA] += normal;
				m_pNormals[indexB] += normal;
				m_pNormals[indexC] += normal;

				m_pFaces[i].m_nNormalIdx = indexA;
				m_pFaces[i + 1].m_nNormalIdx = indexB;
				m_pFaces[i + 2].m_nNormalIdx = indexC;
			}

			for(unsigned int i = 0; i < m_pNormals.size(); ++i)
			{
				m_pNormals[i].Normalize();
			}
		}

		std::map<SFace, int, SCompareFace> pMap;

		// Temporary copy
		vector<Vector3> pVertexCoordinates = m_pVertexCoordinates;
		vector<Vector2> pTexCoordinates = m_pTexCoordinates;
		vector<Vector3> pNormals = m_pNormals;

		// Clear the existing arrays.  We're re-creating them.
		m_pVertexCoordinates.clear(); m_pTexCoordinates.clear(); m_pNormals.clear();

		unsigned int nIndexCounter = 0;
		for (int i = 0; i < (int)m_pFaces.size(); i++)
		{
			std::map<SFace, int, SCompareFace>::iterator oIter = pMap.find(m_pFaces[i]);

			// If found
			if ( oIter != pMap.end() )
			{
				// Add a previously-added index to the index buffer
				m_pIndices.push_back(oIter->second);
			}
			else
			{
				// Add to index buffer
				m_pIndices.push_back(nIndexCounter);

				// Add it to map
				pMap[m_pFaces[i]] = nIndexCounter;

				int nVertexCoordIdx = m_pFaces[i].m_nVertexCoordIdx;
				m_pVertexCoordinates.push_back( pVertexCoordinates[nVertexCoordIdx] );

				int nTexCoordIdx = m_pFaces[i].m_nTexCoordIdx;
				if (nTexCoordIdx >= 0)
					m_pTexCoordinates.push_back( pTexCoordinates[nTexCoordIdx] );

				int nNormalIdx = m_pFaces[i].m_nNormalIdx;
				if (nNormalIdx >= 0)
					m_pNormals.push_back( pNormals[nNormalIdx] );

				nIndexCounter++;
			}
		}
	}
}
void EditorString::OnLine(const std::string& line)
{	
	if(!line.compare("~"))
	{
		m_sock->Send("Allright, done!\n");
		m_state = M_DONE;
	}
	
	if(line[0] == '.')
	{
		ParseDot(line);
		return;
	}

	switch(m_state)
	{
	default:
	{
		Global::Get()->bug("EditorString::OnLine(), default m_state!\n");
		m_sock->Send("BUG! Disconnecting you now...\n");
		m_sock->SetCloseAndDelete();
		return;
	} /* default */

	case M_FIRST:
	{
		m_state = M_WAITING_FOR_INPUT;
		m_sock->Send("Welcome to the string editor.\n");
		// fallthrough
	} /* case M_FIRST: */

	case M_WAITING_FOR_INPUT:
	{
		if(line.size() == 0)
		{
			m_sock->Send("Please choose an editing mode.\n");
			m_sock->Send("If you need help please type '.h'.\n");
			return;
		}
		
		char mode;
		
		if(line[0] == '.')
			mode = line[1];
		else
			mode = line[0];
		
		E_STATE choice = ParseMode(mode);
		
		if(choice == M_FIRST)
			m_state = M_WAITING_FOR_INPUT;
		else
			m_state = choice;
		
		OnLine(Global::Get()->EmptyString);
		return;
	} /* case M_WAITING_FOR_INPUT: */

	case M_APPEND:
	{
		if(line.size() == 0)
		{
			m_sock->Sendf("If you want to append a newline type '.n' on an empty line.\n");
			return;
		}

		m_strings.push_back(line);
		return;
	} /* case M_APPEND: */
	
	case M_REPLACE:
	{
		if(line.size() == 0)
		{
			m_sock->Send("Not yet implemented - Alturin 30-12-2007.\n");
			return;
		}
		
		return;
	}
	case M_VIEW:
	{
		if(line.size() != 0)
		{
			m_sock->Send("At the moment all you can do here is hit enter to show the entire string.\n");
			return;
		}
		
		m_sock->Send(String::Get()->unlines(m_strings, " "));
		return;
	}


	case M_DONE:
	{
		m_sock->PopEditor();
		return;
	} /* case M_DONE: */
	
	} /* switch(state) */

}
Beispiel #7
0
TBParser::STATUS TBParser::Read(TBParserStream *stream, TBParserTarget *target)
{
	TBTempBuffer line, work;
	if (!line.Reserve(1024) || !work.Reserve(1024))
		return STATUS_OUT_OF_MEMORY;

	current_indent = 0;
	current_line_nr = 1;
	pending_multiline = false;
	multi_line_sub_level = 0;

	while (int read_len = stream->GetMoreData((char *)work.GetData(), work.GetCapacity()))
	{
		char *buf = work.GetData();

		// Skip BOM (BYTE ORDER MARK) character, often in the beginning of UTF-8 documents.
		if (current_line_nr == 1 && read_len > 3 &&
			(uint8)buf[0] == 239 &&
			(uint8)buf[1] == 187 &&
			(uint8)buf[2] == 191)
		{
			read_len -= 3;
			buf += 3;
		}

		int line_pos = 0;
		while (true)
		{
			// Find line end
			int line_start = line_pos;
			while (line_pos < read_len && buf[line_pos] != '\n')
				line_pos++;

			if (line_pos < read_len)
			{
				// We have a line
				// Skip preceding \r (if we have one)
				int line_len = line_pos - line_start;
				if (!line.Append(buf + line_start, line_len))
					return STATUS_OUT_OF_MEMORY;

				// Strip away trailing '\r' if the line has it
				char *linebuf = line.GetData();
				int linebuf_len = line.GetAppendPos();
				if (linebuf_len > 0 && linebuf[linebuf_len - 1] == '\r')
					linebuf[linebuf_len - 1] = 0;

				// Terminate the line string
				if (!line.Append("", 1))
					return STATUS_OUT_OF_MEMORY;

				// Handle line
				OnLine(line.GetData(), target);
				current_line_nr++;

				line.ResetAppendPos();
				line_pos++; // Skip this \n
				// Find next line
				continue;
			}
			// No more lines here so push the rest and break for more data
			if (!line.Append(buf + line_start, read_len - line_start))
				return STATUS_OUT_OF_MEMORY;
			break;
		}
	}
	if (line.GetAppendPos())
	{
		if (!line.Append("", 1))
			return STATUS_OUT_OF_MEMORY;
		OnLine(line.GetData(), target);
		current_line_nr++;
	}
	return STATUS_OK;
}
Beispiel #8
0
void ModuleSpanningTree::OnDelELine(userrec* source, const std::string &hostmask)
{
	OnLine(source,hostmask,false,'E',0,"");
}
Beispiel #9
0
void ModuleSpanningTree::OnDelQLine(userrec* source, const std::string &nickmask)
{
	OnLine(source,nickmask,false,'Q',0,"");
}
Beispiel #10
0
void ModuleSpanningTree::OnDelZLine(userrec* source, const std::string &ipmask)
{
	OnLine(source,ipmask,false,'Z',0,"");
}
Beispiel #11
0
void ModuleSpanningTree::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask)
{
	OnLine(source,hostmask,true,'E',duration,reason);
}
Beispiel #12
0
void ModuleSpanningTree::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask)
{
	OnLine(source,nickmask,true,'Q',duration,reason);
}