Пример #1
0
wxFileOffset wxChmInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode)
{
    wxString mode_str = wxEmptyString;

    if ( !m_contentStream || m_contentStream->Eof() )
    {
        m_lasterror = wxSTREAM_EOF;
        return 0;
    }
    m_lasterror = wxSTREAM_NO_ERROR;

    wxFileOffset nextpos;

    switch ( mode )
    {
        case wxFromCurrent:
            nextpos = seek + m_pos;
            break;
        case wxFromStart:
            nextpos = seek;
            break;
        case wxFromEnd:
            nextpos = m_size - 1 + seek;
            break;
        default:
            nextpos = m_pos;
            break; /* just to fool compiler, never happens */
    }
    m_pos=nextpos;

    // Set current position on stream
    m_contentStream->SeekI(m_pos);
    return m_pos;
}
Пример #2
0
void Database::loadIpCounts(wxInputStream &file)
{
    double totallinecount = 0;
    wxTextInputStream str(file);

    str >> totallinecount;

    int c = 0;
    while(!file.Eof())
    {
        wxString line = str.ReadLine();
        if (line.IsEmpty())
            break;

        std::wistringstream stream(line.c_str().AsWChar());

        std::wstring memaddr;
        stream >> memaddr;

        double count;
        stream >> count;

        std::wstring srcfile;
        int linenum;

        ::readQuote(stream, srcfile);
        stream >> linenum;

        LineInfo& lineinfo = (fileinfo[srcfile])[linenum];
        lineinfo.count += count;
        lineinfo.percentage += 100.0f * ((float)count / (float)totallinecount);
    }
}
Пример #3
0
bool wxChmInputStream::Eof() const
{
    return (m_content==NULL ||
            m_contentStream==NULL ||
            m_contentStream->Eof() ||
            m_pos>m_size);
}
Пример #4
0
 wxString ReadStream(wxInputStream& stream)
 {
     wxTextInputStream txt(stream);
     wxString str, line;
     while (!stream.Eof())
         str += txt.ReadLine() + wxT('\n');
     return str;
 }
void ApprExpansionDatabase::doRead(wxInputStream& in) {
	wxTextInputStream tin(in);
	while (!in.Eof()) {
		String l = tin.ReadLine();
		if (l.size() < 3) continue;
		order.push_back(l.substr(0,2));
		expansions[l.substr(0,2)] = l.substr(3);
	}
}
Пример #6
0
void Database::loadStats(wxInputStream &file)
{
    wxTextInputStream str(file);

    stats.clear();

    int c = 0;
    while(!file.Eof())
    {
        wxString line = str.ReadLine();
        if (line.IsEmpty())
            break;

        stats.push_back(line.c_str().AsWChar());
    }
}
Пример #7
0
bool MainWindow::ReadOutput(wxInputStream& s)
{
    // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
    s.Reset();
    wxTextInputStream tis(s, " ", wxConvUTF8);

    while (true) {
        wxString line = tis.ReadLine();
        if ( !line.empty() ) {
            this->text->AppendText(line);
        }
        this->text->AppendText(wxTextFile::GetEOL());
        if (s.Eof()) {
            break;
        }
    }

    return true;
}
Пример #8
0
// read symbol table
void Database::loadSymbols(wxInputStream &file)
{
    wxTextInputStream str(file, wxT(" \t"), wxConvAuto(wxFONTENCODING_UTF8));
    int c = 0;
    while(!file.Eof())
    {
        wxString line = str.ReadLine();
        if (line.IsEmpty())
            break;

        std::wistringstream stream(line.c_str().AsWChar());
        Symbol *sym = new Symbol;

        stream >> sym->id;
        ::readQuote(stream, sym->module);
        ::readQuote(stream, sym->procname);
        ::readQuote(stream, sym->sourcefile);
        stream >> sym->sourceline;
        sym->isCollapseFunction = osFunctions.Contains(sym->procname.c_str());
        sym->isCollapseModule = osModules.Contains(sym->module.c_str());
        symbols[sym->id] = sym;
    }
}
Пример #9
0
static void SkipWhitespace(wxInputStream& input, unsigned int& lineNumber)
{

    char c;

    while (!input.Eof())
    {
        c = input.Peek();
        if (c == '\n')
        {
            ++lineNumber;
        }
        else if (c == '-')
        {
            input.GetC();
            char c2 = input.Peek();
            if (c2 == '-')
            {
                // Lua single line comment.
                while (!input.Eof() && input.GetC() != '\n')
                {
                }
                ++lineNumber;
                continue;
            }
        }
        else if (c == '/')
        {
            input.GetC();
            char c2 = input.Peek();
            if (c2 == '*')
            {
                // C++ block comment.
                input.GetC();
                while (!input.Eof())
                {
                    c = input.GetC();
                    if (c == '\n')
                    {
                        ++lineNumber;
                    }
                    if (c == '*' && input.Peek() == '/')
                    {
                        input.GetC();
                        break;
                    }
                }
                continue;
            }
            else if (c2 == '/')
            {
                // C++ single line comment.
                while (!input.Eof() && input.GetC() != '\n')
                {
                }
                ++lineNumber;
                continue;
            }
            else
            {
                input.Ungetch(c);
                break;
            }
        }
        if (!IsSpace(c))
        {
            break;
        }
        input.GetC();
    }

}
Пример #10
0
bool GetToken(wxInputStream& input, wxString& result, unsigned int& lineNumber)
{

    result.Empty();

    SkipWhitespace(input, lineNumber);

    // Reached the end of the file.
    if (input.Eof())
    {
        return false;
    }

    char c = input.GetC();

    if (c == '\"')
    {

        // Quoted string, search for the end quote.

        do
        {
            result += c;
            c = input.GetC();
        }
        while (input.IsOk() && c != '\"');

        result += c;
        return true;

    }

    char n = input.Peek();

    if (IsDigit(c) || (c == '.' && IsDigit(n)) || (c == '-' && IsDigit(n)))
    {

        bool hasDecimal = false;

        while (!IsSpace(c))
        {

            result.Append(c);

            if (input.Eof())
            {
                return true;
            }

            c = input.Peek();

            if (!IsDigit(c) && c != '.')
            {
                return true;
            }

            input.GetC();

            if (c == '\n')
            {
                ++lineNumber;
                return true;
            }

        }

    }
    else
    {

        if (IsSymbol(c))
        {
            result = c;
            return true;
        }

        while (!IsSpace(c) && !input.Eof())
        {

            result.Append(c);

            if (IsSymbol(input.Peek()))
            {
                break;
            }

            c = input.GetC();

            if (c == '\n')
            {
                ++lineNumber;
                return true;
            }

        }

    }

    return true;

}
Пример #11
0
 bool Eof() const
     { wxASSERT(m_pStream); return m_pStream->Eof(); }
/**
 * Calculates the checksums from the given stream.
 *
 * @param  in         Input stream from which the data will be extracted to
 *                    compute the checksum. The data are extracted until the end
 *                    of the stream is reached.
 * @param  checksums  Array of checksums to calculate.
 * @param  sumValues  The calculated values of the checksums from the input
 *                    stream. The array is erased first before adding results.
 *                    On success <CODE>ArrayChecksum.GetCount() == sumValues.GetCount()</CODE>,
 *                    on failure, <CODE>sumValues</CODE> should be empty.
 * @return <UL>
 *           <LI><CODE>Ok</CODE> if the checksum has been successfully calculated.</Li>
 *           <LI><CODE>ReadError</CODE> if a read error has occured.</LI>
 *           <LI><CODE>Canceled</CODE> if the user has canceled the calculation.</LI>
 *         </UL>
 */
ChecksumCalculator::State ChecksumCalculator::calculate(wxInputStream& in,
                                                 const ArrayChecksum& checksums,
                                                       wxArrayString& sumValues)
{
  // Check if the input stream is valid.
  if (!in.IsOk())
    return ReadError;
  
  // Check if at least a checksum instance is OK.
  bool aInstanceOK = false;
  size_t i = 0;
  size_t s = checksums.GetCount();
  while (!aInstanceOK && i < s)
    if (checksums[i] != NULL)
      aInstanceOK = true;
    else
      i++;
  if (!aInstanceOK)
    return ReadError;
  
  // Initializes the buffer.
  const size_t bufSize = getBufferSize();
  wxByte* buff = new wxByte[bufSize];

  // Calculating the checksum.
  ChecksumProgress* p = getChecksumProgress();
  bool canceled = false;
  size_t read;
  wxStreamError lastError = wxSTREAM_NO_ERROR;
  s = checksums.GetCount();
  for (i = 0; i < s; i++)
    if (checksums[i] != NULL)
      checksums[i]->reset();
  while (!canceled && !in.Eof() && lastError == wxSTREAM_NO_ERROR)
  {
    in.Read(buff, bufSize);
    read = in.LastRead();
    if (read > 0 && read <= bufSize)
    {
      for (i = 0; i < s; i++)
        if (checksums[i] != NULL)
          checksums[i]->update(buff, read);
      if (p != NULL)
        p->update(read, canceled);
    }
    lastError = in.GetLastError();
  }

  // Cleans-up the memory
  delete[] buff;
  
  if (canceled)
    return CanceledByUser;
  
  if (lastError != wxSTREAM_NO_ERROR && lastError != wxSTREAM_EOF)
    return ReadError;
    
  sumValues.Empty();
  for (i = 0; i < s; i++)
    if (checksums[i] != NULL)
      sumValues.Add(checksums[i]->getValue());
    else
      sumValues.Add(wxEmptyString);

  return Ok;
}
Пример #13
0
// read callstacks
void Database::loadProcList(wxInputStream &file,bool collapseKernelCalls)
{
    wxTextInputStream str(file);

    wxProgressDialog progressdlg("Sleepy", "Please wait while the profile database is scanned...",
                                 (int)file.GetSize(), theMainWin,
                                 wxPD_APP_MODAL|wxPD_AUTO_HIDE);

    class CallStackPtrComp
    {
        CallStack *p;
    public:
        CallStackPtrComp(CallStack *_p): p(_p) {}
        bool operator <(const CallStackPtrComp b) const {
            return p->stack < b.p->stack;
        }
        CallStack *Get() {
            return p;
        }
    };

    std::set<CallStackPtrComp> callstackSet;

    while(!file.Eof())
    {
        wxString line = str.ReadLine();
        if (line.IsEmpty())
            break;

        std::wistringstream stream(line.c_str().AsWChar());

        CallStack callstack;
        stream >> callstack.samplecount;

        while(true)
        {
            std::wstring id;
            stream >> id;
            if (id.empty())
                break;

            const Symbol *sym = symbols[id];

            if(collapseKernelCalls && sym->isCollapseFunction) {
                callstack.stack.clear();
            }

            callstack.stack.push_back(sym);
        }

        if(collapseKernelCalls) {
            if(callstack.stack.size() && callstack.stack[0]->isCollapseModule) {
                while(callstack.stack.size() >= 2) {
                    if(	!callstack.stack[1]->isCollapseModule )
                    {
                        break;
                    }
                    callstack.stack.erase(callstack.stack.begin());
                }
            }
        }

        std::set<CallStackPtrComp>::iterator iter = callstackSet.find(&callstack);
        if(iter != callstackSet.end()) {
            ((CallStackPtrComp)*iter).Get()->samplecount += callstack.samplecount;
            continue;
        }
        callstacks.push_back(callstack);
        callstackSet.insert(&callstacks[callstacks.size()-1]);

        wxFileOffset offset = file.TellI();
        if(offset != wxInvalidOffset)
            progressdlg.Update(offset);
    }
}