示例#1
0
Symbol Stream::readSymbol( )
{
    Byte b = 0;
    if(!checkIO(StreamRead))
    {
       fprintf(stdout, "error: Wrong Stream. It should be read only.\n");
        m_error = true;
    }
    else
    {
       if(m_mode == StreamFile && m_file)
        {
            int c = fgetc(m_file);
            if(c == EOF)
            {
                m_inEOF = true;
            }
            else
            {
                b = (Byte)(c);
            }
        }
        else // StreamMemory
        {
           b = m_memBuffer->readSymbol();
        }
    }
    return Symbol(b);
}
  IoStatus
  SwapSpace::swapOut(char* buffer)
  {
    IoStatus status = OK;

    if (!store_)
    {
      init();    // failure is fatal
    }
    else
    {
      status = checkIO();
    }

    if (status == OK)
    {
      swapOutBuffer_ = buffer;
      // Initiate overflow of buffer to temporary storage
      ioPending_ = WRITE;
      DWORD ignoredBlockNum = 0;
      status = mapStatus(store_->writeThru(swapOutBuffer_, swapBufferSize_,
                                           ignoredBlockNum));
      // status is OK if write was successfully initiated
    }

    return status;
  }
示例#3
0
    void check(const char code[], bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified) {
        // Clear the error buffer..
        errout.str("");

        Settings settings;
        settings.addEnabled("warning");
        settings.addEnabled("style");
        if (portability)
            settings.addEnabled("portability");
        settings.inconclusive = inconclusive;
        settings.platform(platform);

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");

        // Check..
        CheckIO checkIO(&tokenizer, &settings, this);
        checkIO.checkWrongPrintfScanfArguments();

        // Simplify token list..
        tokenizer.simplifyTokenList();
        checkIO.checkCoutCerrMisusage();
        checkIO.checkFileUsage();
        checkIO.invalidScanf();
    }
示例#4
0
uint32_t Stream::read( )
{
    uint32_t uint32 = 0;
    if(checkIO(StreamRead))
    {
        if(m_mode == StreamFile)
        {
            // Read the number of entries
            if(fread(&uint32, sizeof(uint32), 1, m_file) != 1)
            {
                m_error = true;
                assert(0);
                //return nullptr;
            }
            else
            {
                uint32 = ntohl(uint32);
            }
        }
        else // StreamMemory
        {
            uint32 = m_memBuffer->read();
        }
    }
    return uint32;
}
示例#5
0
bool Stream::write(const Byte* array, size_t size)
{
    bool bOk = true;
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            if(fwrite(array, 1, size, m_file) != size)
            {
                m_error = true;
                fprintf(stdout, "ERROR: cannot write to file\n");
                bOk = false;
            }
        }
        else // StreamMemory
        {
            bOk = m_memBuffer->write(array, size);
        }
    }
    else
    {
        m_error = true;
        fprintf(stdout, "ERROR\n");
    }
    return bOk;
}
示例#6
0
bool Stream::write(uint32_t uint32)
{
    bool bOk = true;
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            // Write the number of in network byte order.
            uint32 = htonl(uint32);
            if(fwrite(&uint32, sizeof(uint32_t), 1, m_file) != 1)
            {
                m_error = true;
                fprintf(stdout, "ERROR: cannot write to file\n");
                bOk = false;
            }
        }
        else // StreamMemory
        {
            bOk = m_memBuffer->write(uint32);
        }
    }
    else
    {
        m_error = true;
        bOk = false;
        fprintf(stdout, "ERROR: file is not set\n");
    }
    return bOk;
}
示例#7
0
Stream& Stream::operator<<(const std::string& msg)
{
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            fprintf(m_file, "%s", msg.c_str());
        }
        else // StreamMemory
        {
            m_memBuffer->write((Byte*)msg.c_str(), msg.size());
        }
    }
    return *this;
}
示例#8
0
Stream& Stream::operator<<(const char* msg)
{
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            fprintf(m_file, "%s", msg);
        }
        else // StreamMemory
        {
            size_t iNb = strlen(msg);
            m_memBuffer->write((Byte*)msg, iNb);
        }
    }
    return *this;
}
示例#9
0
void Stream::rewind( )
{
    if(checkIO(StreamRead))
    {
        if(m_mode == StreamFile)
        {
            ::rewind(m_file);
        }
        else // StreamMemory
        {
            m_memBuffer->rewind();
        }
        m_inEOF = false;
    }
    else
    {
        m_error = true;
    }
}
  IoStatus
  SwapSpace::rewind(void)
  {
    IoStatus status = OK;

    if ((numSwap_ > 0) || isIoPending())
    {
      status = checkIO();
      if (status == OK)
      {
        atEOF_ = false;
        if (!haveFirstBuffer())
        {
          swapRead_ = swapStart_;
          status = fetch();    // status == OK if read initiated
        }
      }
    }

    return status;
  }
示例#11
0
bool Stream::writeByte(const Byte b)
{
    bool bOk = true;
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            fputc(b, m_file);
        }
        else // StreamMemory
        {
            bOk = m_memBuffer->writeByte(b);
        }
    }
    else
    {
        m_error = true;
        bOk = false;
    }
    return bOk;
}
示例#12
0
Byte Stream::readByte( )
{
    if(!checkIO(StreamRead)) m_error = true;
    Byte b = 0;
    if(m_file)
    {
        if(m_mode == StreamFile)
        {
            int c = fgetc(m_file);
            if(c == EOF)
            {
                m_inEOF = true;
            }
            b = (Byte)c;
        }
        else // StreamMemory
        {
            b= m_memBuffer->readByte();
        }
    }
    return b;
}
示例#13
0
bool Stream::writeSymbol(const Symbol& s)
{
    bool bOk = true;
    if(checkIO(StreamWrite))
    {
        Byte b = (Byte)s.toInt();
        if(m_mode == StreamFile)
        {
            fputc(b, m_file);
        }
        else // StreamMemory
        {
            bOk = m_memBuffer->writeSymbol(s);
        }
    }
    else
    {
        m_error = true;
        bOk = false;
    }
    return bOk;
}
示例#14
0
void Stream::printf(const std::string& buffer, bool eof)
{
    if(checkIO(StreamWrite))
    {
        if(m_mode == StreamFile)
        {
            fprintf(m_file, "%s", buffer.c_str());
            if(eof)
            {
                fprintf(m_file, "\n");
            }
        }
        else // StreamMemory
        {
            m_memBuffer->write((Byte*)buffer.c_str(), buffer.size());
            if(eof)
            {
                const char* s = "\n";
                m_memBuffer->write((Byte*)s, 2);
            }
        }
    }
}
  IoStatus
  SwapSpace::fetchNextBuffer(void)
  {
    IoStatus status = (numSwap_ > 0) ? checkIO() : END_OF_DATA;
    if ((status == OK) && (swapStart_ != swapEnd_))
    {
      if (swapRead_ != swapEnd_)
      {
        swapRead_ += swapBufferSize_;
      }

      if (swapRead_ < swapEnd_)
      {
        status = fetch();    // status == OK if read initiated
      }
      else
      {
        atEOF_ = true;
        status = END_OF_DATA;
      }
    }

    return status;
  }
示例#16
0
bool Stream::read(unsigned char* buffer, const size_t size)
{
    bool bOk = true;
    if(checkIO(StreamRead))
    {
        if(m_mode == StreamFile)
        {
            if(fread(buffer, 1, size, m_file) != size)
            {
                m_error = true;
                bOk = false;
            }
        }
        else // StreamMemory
        {
            bOk = m_memBuffer->read(buffer, size);
        }
    }
    else
    {
        bOk = false;
    }
    return bOk;
}