bool indri::index::DiskKeyfileVocabularyIterator::nextEntry(const char *skipTo) {

  assert(skipTo!=NULL);

  if (_justStartedIteration) {
    // position the iterator at the first
    // item that matches...
    _justStartedIteration=false;

    // get an iterator to the first term here
    indri::file::BulkTreeIterator *findIterator=_bulkTree.findFirst(skipTo);
    if (!findIterator) return false;

    // replace the current iterator with the new one
    if (_bulkIterator) delete _bulkIterator;
    _bulkIterator=findIterator;
    if (!_readData()) return false;

  } else {
    // get the next item...
    // assume all items w/ the same prefix are clumped together
    _bulkIterator->nextEntry();
    if (!_readData()) return false;
  }

  // make sure we're not at the end
  if (_bulkIterator->finished()) {
    return false;
  }

  // get the current entry
  indri::index::DiskTermData* thisEntry=currentEntry();
  if (!thisEntry) return false;

  // make sure we're still in the patten
  if (strstr(thisEntry->termData->term, skipTo)==thisEntry->termData->term) {
    return true;
  }

  // just to be certain - check the next entry...
  // read the next item...
  _bulkIterator->nextEntry();
  if (!_readData()) return false;
        
  // ensure we're not finished
  if (_bulkIterator->finished()) return false;

  // get the next entry...
  thisEntry=currentEntry();
  if (!thisEntry) return false;

  // check it.
  if (strstr(thisEntry->termData->term, skipTo)==thisEntry->termData->term) {
    return true;
  }

  // ok - I'm satisfied that we're done...
  return false;
}
void indri::index::DiskKeyfileVocabularyIterator::startIteration() {
  _acquire();

  _bulkIterator->startIteration();
  _readData();
  _justStartedIteration=true;
}
Beispiel #3
0
void AbstractCommand::setSocket(QTcpSocket* socket) 
{
    debugOutput(0, "AbstractCommand::setSocket()");
    Q_ASSERT(socket);
    m_socket = socket;
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(_readData()));
    reportSuccess();
}
Beispiel #4
0
bool IsoFilesystem::getFileData(file_handle_t iFile, unsigned char *pBuffer)
{
    if(iFile <= 0 || static_cast<size_t>(iFile) > m_iNumFiles)
    {
        _setError("Invalid file handle.");
        return false;
    }
    else
    {
        return _seekToSector(m_pFiles[iFile - 1].iSector) &&
               _readData(m_pFiles[iFile - 1].iSize, pBuffer);
    }
}
Beispiel #5
0
bool IsoFilesystem::initialise(FILE* fRawFile)
{
    m_fRawFile = fRawFile;
    _clear();

    // Until we know better, assume that sectors are 2048 bytes.
    m_iSectorSize = 2048;

    // The first 16 sectors are reserved for bootable media.
    // Volume descriptor records follow this, with one record per sector.
    for(uint32_t iSector = 16; _seekToSector(iSector); ++iSector)
    {
        unsigned char aBuffer[190];
        if(!_readData(sizeof(aBuffer), aBuffer))
            break;
        // CD001 is a standard identifier, \x01 is a version number
        if(memcmp(aBuffer + 1, "CD001\x01", 6) == 0)
        {
            if(aBuffer[0] == VDT_PRIVARY_VOLUME)
            {
                m_iSectorSize = ReadNativeInt<uint16_t>(aBuffer + 128);
                _findHospDirectory(aBuffer + 156, 34, 0);
                if(m_iNumFiles == 0)
                {
                    _setError("Could not find Theme Hospital data directory.");
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else if(aBuffer[0] == VDT_TERMINATOR)
                break;
        }
    }
    _setError("Could not find primary volume descriptor.");
    return false;
}
bool indri::index::DiskKeyfileVocabularyIterator::nextEntry() {
  _bulkIterator->nextEntry();
  _justStartedIteration=false;

  return _readData();
}
bool CScriptFunctionData::readDataFromStack_scriptFunctionCall(int stackHandle,const int* expectedArguments,int requiredArgumentCount,const char* functionName)
{	// use this when reading data returned from a Lua function call from a plugin
	bool retVal=_readData(stackHandle,expectedArguments,requiredArgumentCount,functionName,"return arguments.","Return argument ",_outData);
	simPopStackItem(stackHandle,0); // clears the stack
	return(retVal);
}
bool CScriptFunctionData::readDataFromStack(int stackHandle,const int* expectedArguments,int requiredArgumentCount,const char* functionName)
{  // use this when reading data from a script from inside of a custom script function call
	bool retVal=_readData(stackHandle,expectedArguments,requiredArgumentCount,functionName,"arguments.","Argument ",_inData);
	simPopStackItem(stackHandle,0); // clears the stack (which will serve as return value container from now)
	return(retVal);
}
Beispiel #9
0
void IsoFilesystem::_buildFileLookupTable(uint32_t iSector, int iDirEntsSize, const char* sPrefix)
{
    // Sanity check
    // Apart from at the root level, directory record arrays must take up whole
    // sectors, whose sizes are powers of two and at least 2048.
    // Path lengths shouldn't exceed 256 either (or at least not for the files
    // which we're interested in).
    size_t iLen = strlen(sPrefix);
    if((iLen != 0 && (iDirEntsSize & 0x7FF)) || (iLen > 256))
        return;

    unsigned char *pBuffer = new unsigned char[iDirEntsSize];
    if(!_seekToSector(iSector) || !_readData(iDirEntsSize, pBuffer))
    {
        delete[] pBuffer;
        return;
    }
    unsigned char *pDirEnt = pBuffer;
    for(; iDirEntsSize > 0; iDirEntsSize -= *pDirEnt, pDirEnt += *pDirEnt)
    {
        // There is zero padding so that no record spans multiple sectors.
        if(*pDirEnt == 0)
        {
            --iDirEntsSize, ++pDirEnt;
            continue;
        }

        uint32_t iDataSector = ReadNativeInt<uint32_t>(pDirEnt + 2);
        uint32_t iDataLength = ReadNativeInt<uint32_t>(pDirEnt + 10);
        uint8_t iFlags = pDirEnt[25];
        uint8_t iIdentLength = pDirEnt[32];
        _trimIdentifierVersion(pDirEnt + 33, iIdentLength);

        // Build new path
        char *sPath = new char[iLen + iIdentLength + 2];
        memcpy(sPath, sPrefix, iLen);
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#endif
        std::transform(pDirEnt + 33, pDirEnt + 33 + iIdentLength, sPath + iLen, _normalise);
#ifdef _MSC_VER
#pragma warning(default: 4996)
#endif
        sPath[iLen + iIdentLength] = 0;

        if(iFlags & DEF_DIRECTORY)
        {
            // None of the directories which we're interested in have length 1.
            // This also avoids the dummy "current" and "parent" directories.
            if(iIdentLength > 1)
            {
                sPath[iLen + iIdentLength] = m_cPathSeparator;
                sPath[iLen + iIdentLength + 1] = 0;
                _buildFileLookupTable(iDataSector, iDataLength, sPath);
            }
        }
        else
        {
            _file_t *pFile = _allocFileRecord();
            pFile->sPath = sPath;
            pFile->iSector = iDataSector;
            pFile->iSize = iDataLength;
            sPath = NULL;
        }
        delete[] sPath;
    }
    delete[] pBuffer;

    if(iLen == 0)
    {
        // The lookup table will be ordered by the underlying ordering of the
        // disk, which isn't quite the ordering we want.
        qsort(m_pFiles, m_iNumFiles, sizeof(_file_t), _fileNameComp);
    }
}
Beispiel #10
0
int IsoFilesystem::_findHospDirectory(const unsigned char *pDirEnt, int iDirEntsSize, int iLevel)
{
    // Sanity check
    // Apart from at the root level, directory record arrays must take up whole
    // sectors, whose sizes are powers of two and at least 2048.
    // The formal limit on directory depth is 8, so hitting 16 is insane.
    if((iLevel != 0 && (iDirEntsSize & 0x7FF)) || iLevel > 16)
        return 0;

    unsigned char *pBuffer = NULL;
    uint32_t iBufferSize = 0;
    for(; iDirEntsSize > 0; iDirEntsSize -= *pDirEnt, pDirEnt += *pDirEnt)
    {
        // There is zero padding so that no record spans multiple sectors.
        if(*pDirEnt == 0)
        {
            --iDirEntsSize, ++pDirEnt;
            continue;
        }

        uint32_t iDataSector = ReadNativeInt<uint32_t>(pDirEnt + 2);
        uint32_t iDataLength = ReadNativeInt<uint32_t>(pDirEnt + 10);
        uint8_t iFlags = pDirEnt[25];
        uint8_t iIdentLength = pDirEnt[32];
        _trimIdentifierVersion(pDirEnt + 33, iIdentLength);
        if(iFlags & DEF_DIRECTORY)
        {
            // The names "\x00" and "\x01" are used for the current directory
            // the parent directory respectively. We only want to visit these
            // when at the root level.
            if(iLevel == 0 || iIdentLength != 1 || pDirEnt[33] > 1)
            {
                if(iDataLength > iBufferSize)
                {
                    delete[] pBuffer;
                    iBufferSize = iDataLength;
                    pBuffer = new unsigned char[iBufferSize];
                }
                if(_seekToSector(iDataSector) && _readData(iDataLength, pBuffer))
                {
                    int iFoundLevel = _findHospDirectory(pBuffer, iDataLength, iLevel + 1);
                    if(iFoundLevel != 0)
                    {
                        if(iFoundLevel == 2)
                            _buildFileLookupTable(iDataSector, iDataLength, "");
                        delete[] pBuffer;
                        return iFoundLevel + 1;
                    }
                }
            }
        }
        else
        {
            // Look for VBLK-0.TAB to serve as indication that we've found the
            // Theme Hospital data.
            if(iIdentLength == 10)
            {
                const char sName[10] = {'V','B','L','K','-','0','.','T','A','B'};
                int i = 0;
                for(; i < 10; ++i)
                {
                    if(_normalise(pDirEnt[33 + i]) != sName[i])
                        break;
                }
                if(i == 10)
                {
                    return 1;
                }
            }
        }
    }
    delete[] pBuffer;

    return 0;
}