Beispiel #1
0
void Teleinfo::ParseData(const unsigned char *pData, int Len)
{
	int ii = 0;
	while (ii<Len)
	{
		const unsigned char c = pData[ii];

		if ((c == 0x0d) || (c == 0x00) || (c == 0x02) || (c == 0x03))
		{
			ii++;
			continue;
		}

		m_buffer[m_bufferpos] = c;
		if (c == 0x0a || m_bufferpos == sizeof(m_buffer) - 1)
		{
			// discard newline, close string, parse line and clear it.
			if (m_bufferpos > 0)
				m_buffer[m_bufferpos] = 0;

			//We check the line only if the checksum is ok
			if (isCheckSumOk())
				MatchLine();

			m_bufferpos = 0;
		}
		else
		{
			m_bufferpos++;
		}
		ii++;
	}
}
Beispiel #2
0
void P1MeterBase::ParseData(const unsigned char *pData, int Len)
{
	int ii=0;
	while (ii<Len)
	{
		const unsigned char c = pData[ii];
		if(c == 0x0d)
		{
			ii++;
			continue;
		}

		m_buffer[m_bufferpos] = c;
		if(c == 0x0a || m_bufferpos == sizeof(m_buffer) - 1)
		{
			// discard newline, close string, parse line and clear it.
			m_linecount++;
			if (m_bufferpos > 0) {
				m_buffer[m_bufferpos] = 0;
				MatchLine();
			}
			m_bufferpos = 0;
		}
		else
		{
			m_bufferpos++;
		}
		ii++;
	}
}
Beispiel #3
0
void CTeleinfoSerial::ParseData(const char *pData, int Len)
{
	int ii = 0;
	while (ii<Len)
	{
		const char c = pData[ii];

		if ((c == 0x0d) || (c == 0x00) || (c == 0x02) || (c == 0x03))
		{
			ii++;
			continue;
		}

		m_buffer[m_bufferpos] = c;
		if (c == 0x0a || m_bufferpos == sizeof(m_buffer) - 1)
		{
			// discard newline, close string, parse line and clear it.
			if (m_bufferpos > 0)
				m_buffer[m_bufferpos] = 0;

			//We process the line only if the checksum is ok and user did not request to bypass CRC verification
			if ((m_bDisableCRC) || isCheckSumOk(teleinfo.CRCmode1))
				MatchLine();

			m_bufferpos = 0;
		}
		else
		{
			m_bufferpos++;
		}
		ii++;
	}
}
Beispiel #4
0
bool wxExTextFile::Parse()
{
  if (m_Tool.GetId() == ID_TOOL_REPORT_REPLACE &&
      m_FileName.GetStat().IsReadOnly())
  {
    return false;
  }

  if (m_Tool.IsFindType())
  {
    if (wxExFindReplaceData::Get()->GetFindString().empty())
    {
      wxFAIL;
      return false;
    }

    m_FindString = wxExFindReplaceData::Get()->GetFindString();

    if (!wxExFindReplaceData::Get()->MatchCase())
    {
      std::transform(
        m_FindString.begin(), 
        m_FindString.end(), 
        m_FindString.begin(), 
        toupper);
    }
  }

  for (size_t i = 0; i < GetLineCount(); i++)
  {
    wxString& line = GetLine(i);

    if (m_Tool.IsFindType())
    {
      if (MatchLine(line))
      {
        Report(i);
      }
    }
    else
    {
      GoToLine(i);
      
      if (!ParseLine(line))
      {
        return false;
      }
    }
  }

  return true;
}
TextFileSearcher::eFileSearcherReturn TextFileSearcher::FindInFile(const wxString& filePath, wxArrayString &foundLines)
{
	eFileSearcherReturn success=idStringNotFound;
	wxString line;

	// Tests file existence
	if ( !wxFileName::FileExists(filePath) )
	{
		// We skip missing files without alerting user.
		// If a file has disappeared, it is not our problem.
		// cbMessageBox( filePath + _T(" does not exist."), _T("Error"), wxICON_ERROR);
		return idFileNotFound;
	}

	// File open
	if ( !m_TextFile.Open(filePath, wxConvFile) )
	{
		return idFileOpenError;
	}

	// Tests all file lines
	for ( size_t i = 0; i < m_TextFile.GetLineCount(); ++i )
	{
		line = m_TextFile.GetLine(i);
		if ( MatchLine(line) )
		{
			success=idStringFound;
			// An interesting line is found. We clean and add it to the provided array
			line.Replace(_T("\t"), _T(" "));
			line.Replace(_T("\r"), _T(" "));
			line.Replace(_T("\n"), _T(" "));
			line.Trim(false);
			line.Trim(true);

			foundLines.Add(wxString::Format(wxT("%d"), i + 1));
			foundLines.Add(line);
		}
	}

	// File close
	m_TextFile.Close();

	return success;
}
Beispiel #6
0
void MochadTCP::ParseData(const unsigned char *pData, int Len)
{
	int ii=0;
	while (ii<Len)
	{
		const unsigned char c = pData[ii];
		if(c == 0x0d)
		{
			ii++;
			continue;
		}

		m_mochadbuffer[m_bufferpos] = c;
		if(c == 0x0a || m_bufferpos == sizeof(m_mochadbuffer) - 1)
		{
			// discard newline, close string, parse line and clear it.
			if(m_bufferpos > 0) m_mochadbuffer[m_bufferpos] = 0;
			m_linecount++;
			if (strlen((const char *)m_mochadbuffer) > 14) {
				int i = 0;
				while (m_mochadbuffer[i+15] != 0) {
					m_mochadbuffer[i] = m_mochadbuffer[i+15];
					i++;
				}
				m_mochadbuffer[i] = 0;
//				_log.Log(LOG_STATUS, "Mochad: recv '%s'", m_mochadbuffer);
				MatchLine();
			}
			m_bufferpos = 0;
		}
		else
		{
			m_bufferpos++;
		}
		ii++;
	}
}