Esempio n. 1
0
/**
 * @brief Load the index from a file.
 * @param backwardIndexPath the path to the index file.
 * @return the operation code.
 */
u_int32_t ORBIndex::load(string backwardIndexPath)
{
    clear();
    readIndex(backwardIndexPath);

    return INDEX_LOADED;
}
Esempio n. 2
0
void Plugin::handleStatus(const std::string& name, const std::string& value)
{
    // Checking status of changed file that is tracked by git-bin
    File f(Plugin::GIT_CONFIG);
    if (!f.exists())
    {
        logger().error("Git bin has not been initialized");
        return;
    } 
    readIndex();
    for (auto it = _index.begin(); it != _index.end(); it++)
    {
        std::cout << (*it).filepath.c_str();
        std::string filepath(Plugin::GIT_CACHE_DIR);
        filepath.append("/wf/").append((*it).uuid);
        std::cout << (*it).md5.c_str() << std::endl;
        std::cout << getFileMd5(filepath) << std::endl;
        if ((*it).md5 != getFileMd5(filepath))
        {
            std::cout << " > Modified" << std::endl;
        } 
        else
        {
            std::cout << " > Not changed" << std::endl;
        }
    }
}
void SaveableFlannBasedMatcher::load()
{
  printf("Load called! Filename: %s\n", filename);
  // Read the descriptors
  std::vector<Mat> descsVec;
  std::string descriptorsFilename(filename);
  descriptorsFilename += "-descriptors.bin";
  readDescriptors(descsVec, descriptorsFilename.c_str());

  // Add the descriptors to the matcher
  printf("Adding the descriptors to the matcher...\n");
  add(descsVec);

  std::string treeFilename(filename);
  treeFilename += "-tree.xml.gz";
  cv::FileStorage store(treeFilename.c_str(), cv::FileStorage::READ);
  cv::FileNode node = store.root();
  printf("Reading the matcher tree data...\n");
  read(node);

  std::string indexFilename(filename);
  indexFilename += ".flannindex";
  printf("Reading the flann index...\n");
  readIndex(indexFilename.c_str());
  store.release();
}
Esempio n. 4
0
bool Plugin::isFileIndexed(const std::string filepath)
{
    readIndex();
    for (auto it = _index.begin(); it != _index.end(); it++)
    {
        if ((*it).filepath == filepath) return true;
    }
    return false;
}
bool KMFolderIndex::recreateIndex()
{
  QApplication::setOverrideCursor( QCursor( Qt::ArrowCursor ) );
  KMessageBox::error(0,
       i18n("The mail index for '%1' is corrupted and will be regenerated now, "
            "but some information, including status flags, will be lost.", label()));
  QApplication::restoreOverrideCursor();
  if ( createIndexFromContents() != 0 )
    return false;
  return readIndex();
}
Esempio n. 6
0
ORBIndex::ORBIndex()
{
    // Init the mutex.
    pthread_rwlock_init(&rwLock, NULL);

    // Initialize the nbOccurences table.
    for (unsigned i = 0; i < NB_VISUAL_WORDS; ++i)
        nbOccurences[i] = 0;

    readIndex(DEFAULT_INDEX_PATH);
}
Esempio n. 7
0
IndexEntry* Plugin::getIndexEntry(const std::string filepath)
{
    readIndex();
    for (auto it = _index.begin(); it != _index.end(); it++)
    {
        if ((*it).filepath == filepath)
        {
            return &(*it);
        }
    }
    return nullptr;
}
Esempio n. 8
0
bool NetDemo::startPlaying(const std::string &filename)
{
    this->filename = filename;

    if (isPlaying())
    {
        // restart playing
        cleanUp();
        return startPlaying(filename);
    }

    if (isRecording())
    {
        error("Cannot play a netdemo while recording.");
        return false;
    }

    if (!(demofp = fopen(filename.c_str(), "rb")))
    {
        error("Unable to open netdemo file.");
        return false;
    }

    if (!readHeader())
    {
        error("Unable to read netdemo header.");
        return false;
    }

    if (header.version != NETDEMOVER)
    {
        // Do nothing since there is only one version of netdemo files currently
    }

    // read the demo's index
    if (fseek(demofp, header.snapshot_index_offset, SEEK_SET) != 0)
    {
        error("Unable to find netdemo index.\n");
        return false;
    }

    if (!readIndex())
    {
        error("Unable to read netdemo index.\n");
        return false;
    }

    // get set up to read server cmds
    fseek(demofp, NetDemo::HEADER_SIZE, SEEK_SET);
    state = NetDemo::playing;
    return true;
}
bool CTimeServerThread::loadAMBE()
{
	wxString ambeFileName;
	wxString indxFileName;

	switch (m_language) {
		case LANG_ENGLISH_US_1:
		case LANG_ENGLISH_US_2:
			ambeFileName = wxT("TIME_en_US.ambe");
			indxFileName = wxT("TIME_en_US.indx");
			break;
		case LANG_DEUTSCH_1:
		case LANG_DEUTSCH_2:
			ambeFileName = wxT("TIME_de_DE.ambe");
			indxFileName = wxT("TIME_de_DE.indx");
			break;
		case LANG_FRANCAIS:
			ambeFileName = wxT("TIME_fr_FR.ambe");
			indxFileName = wxT("TIME_fr_FR.indx");
			break;
		case LANG_NEDERLANDS:
			ambeFileName = wxT("TIME_nl_NL.ambe");
			indxFileName = wxT("TIME_nl_NL.indx");
			break;
		case LANG_SVENSKA:
			ambeFileName = wxT("TIME_se_SE.ambe");
			indxFileName = wxT("TIME_se_SE.indx");
			break;
		default:
			ambeFileName = wxT("TIME_en_GB.ambe");
			indxFileName = wxT("TIME_en_GB.indx");
			break;
	}

	bool ret = readAMBE(ambeFileName);
	if (!ret) {
		delete[] m_ambe;
		m_ambe = NULL;
		return false;
	}

	ret = readIndex(indxFileName);
	if (!ret) {
		delete[] m_ambe;
		m_ambe = NULL;
		return false;
	}

	return true;
}
Esempio n. 10
0
int main(int argc, const char * argv[])
{
    int origIndex, destIndex, origX, origY, destX, destY;
    bool legalMove = false;
    short unsigned int victory = VC_NO_VICTORY;
    
    initialize();
    printBoard();
    
    
    while(!victory){
        
        while (!legalMove){
            origIndex = readIndex(ORIGINE);
            destIndex = readIndex(DESTINATION);
            transf_index2rel(origIndex, &origX, &origY);
            transf_index2rel(destIndex, &destX, &destY);
            if (isMoveLegal (origX, origY, destX, destY)){
                executeMove(origX, origY, destX, destY);
                printBoard();
                victory = checkForVictory();
                victoryMessage(victory);
                setColor();
            }
            
            else printf("Illegal move, let's try again!\n");
        }
       
       
    }
    
    printf("END\n");
    
        return 0;
        
    }
Esempio n. 11
0
bool unpackPackage(const wchar_t* packagePath, const wchar_t* targetDir) {
	writeLog(LOG_NORMAL, L"Unpacking package: %s", packagePath);
	writeLog(LOG_NORMAL, L"To Directory: %s", targetDir);
	if (!fsEnsureDirectoryExists(targetDir)) {
		writeLog(LOG_QUIET, L"ERROR: Target directory does not exist and cannot be created.", targetDir);
		return false;
	}
	NexasPackage* package = openPackage(packagePath);
	if (!package) return false;
	bool result = validateHeader(package)
			&& readIndex(package)
			&& extractFiles(package, targetDir);
	closePackage(package);
	writeLog(LOG_NORMAL, (result) ? L"Unpacking Successful." : L"ERROR: Unpacking Failed.");
	return result;
}
Esempio n. 12
0
	void ArchiveEditable::open(const _TCHAR *fn, const char *key, CryptState crypt_state)
	{
		File::open(fn, File::WRITE);
		setKey(key);
		if(iv_) index_iv_ = *iv_;
		if(readIndex()) {
			crypt_state_ = crypt_state;
			if(crypt_state_ == KEEP) {
				if(flags_ & FLAG_CRYPTED) crypt_state_ = CRYPT;
				else crypt_state_ = UNCRYPT;
			}
			setAlign(2);
			setUpList();
		}
		else close();
	}
Esempio n. 13
0
//-----------------------------------------------------------------------------
int KMFolder::open(void)
{
  int rc = 0;

  mOpenCount++;
  if (mOpenCount > 1) return 0;  // already open

  assert(name() != "");

  mFilesLocked = FALSE;
  mStream = fopen(location(), "r+"); // messages file
  if (!mStream) 
  {
    debug("Cannot open folder `%s': %s", (const char*)location(), 
	  strerror(errno));
    mOpenCount = 0;
    return errno;
  }

  if (!path().isEmpty())
  {
    if (isIndexOutdated()) // test if contents file has changed
    {
      QString str;
      mIndexStream = NULL;
      str.sprintf(i18n("Folder `%s' changed. Recreating index."), 
		  (const char*)name());
      emit statusMsg(str);
    }
    else mIndexStream = fopen(indexLocation(), "r+"); // index file

    if (!mIndexStream) rc = createIndexFromContents();
    else readIndex();
  }
  else
  {
    //debug("No path specified for folder `" + name() +
    //      "' -- Turning autoCreateIndex off");
    mAutoCreateIndex = FALSE;
    rc = createIndexFromContents();
  }

  if (!rc) lock();
  mQuiet = 0;

  return rc;
}
Esempio n. 14
0
QString QOrmAttributeInfo::store(QOrmObject *obj)
{
    if (!d->f_st)
    {
        QVariant v = read(obj);
        if (v.isNull())
        {
            if (isForeignKey() || isPrimaryKey())
                v = readIndex(obj);
        }
        else
        {
            //qDebug()<<QOrm::isOrmObject(v)<<v<<isForeignKey();
            if (isForeignKey() && QOrm::isOrmObject(v))
            //if (QOrm::isOrmObject(v))
            {
                QOrmObject *fk = v.value<QOrmObject*>();
                if (!fk) v = QVariant();
                else v = refAttribute().readIndex(fk);
            }
        }

        switch (v.type())
        {
            case QVariant::Date:
            case QVariant::DateTime:
            case QVariant::Time:
            case QVariant::String:
                return '\'' + v.toString() + '\'';
            case QVariant::Invalid:
            case QVariant::UserType:
                return "NULL";
            case QVariant::Int:
            case QVariant::Double:
            default:
                return v.toString();
        }
    }

    return (obj->*(d->f_st))();
}
Esempio n. 15
0
void Plugin::handleSync(const std::string& name, const std::string& value)
{
    AutoPtr<PropertyFileConfiguration> config = new PropertyFileConfiguration(Plugin::GIT_CONFIG);
    std::string targetUrl = config->getString("url", Plugin::GIT_CACHE_DIR);
    URI uri(targetUrl);
    FileTransfer* ft;
    if (uri.getScheme() == "ssh")
    {
        ft = new FileTransfer();
    } 
    else if (uri.getScheme() == "s3")
    {
        ft = new AWSFileTransfer();
    }
    ft->setTargetUrl(targetUrl);
    readIndex();
    for (auto it = _index.begin(); it != _index.end(); it++)
    {
        std::string filepath(Plugin::GIT_CACHE_DIR);
        filepath.append("/wf/");
        filepath.append((*it).uuid);
        File f(filepath);
        if (f.exists())
        {
            ft->uploadFile(filepath);
        } else {
            ft->downloadFile((*it).uuid);
            File f((*it).uuid);
            std::string newPath;
            newPath.append(Plugin::GIT_CACHE_DIR);
            newPath.append("/of/");
            f.copyTo(newPath);
            newPath.append((*it).uuid);
            newPath.clear();
            newPath.append(Plugin::GIT_CACHE_DIR);
            newPath.append("/wf/");
            f.moveTo(newPath);
        }
    }
}
Esempio n. 16
0
	void ArchiveEditable::commit()
	{
		assert(File::good());
		bool need_update = false;
		int old_file_size = length();
		int index_size = calcIndexLen();

		if(index_size != index_size_) need_update = true;
		else {
			for(ListItr i = list_.begin(); i != list_.end(); ++i) {
				if(i->attr != EntryAttr::ALREADY) {
					need_update = true;
					break;
				}
			}
		}

		if(need_update) {
			int cur_file_size = commitEntrys(index_size);
			assert(File::good());
			commitIndex(index_size);
			assert(File::good());
			// ファイルサイズ変更
			if(old_file_size > cur_file_size) truncate(cur_file_size); // 縮んだ場合は縮める。大きくなった場合は特に操作はいらない
			assert(File::good());
			File::flush();
			assert(File::good());
			index_.clear();
			list_.clear();
			if(readIndex()) setUpList();
			else close();
		}
		else {
			list_.clear();
		}
	}
Esempio n. 17
0
uint8_t psHeader::open(const char *name)
{
    char *idxName=(char *)malloc(strlen(name)+6);
    bool r=false;
    FP_TYPE appendType=FP_DONT_APPEND;
    uint32_t append;
    char *type;
    uint64_t startDts;
    uint32_t version=0;

    sprintf(idxName,"%s.idx2",name);
    indexFile index;
    if(!index.open(idxName))
    {
        printf("[psDemux] Cannot open index file %s\n",idxName);
        free(idxName);
        return false;
    }
    if(!index.readSection("System"))
    {
        printf("[psDemux] Cannot read system section\n");
        goto abt;
    }

    version=index.getAsUint32("Version");
    if(version!=ADM_INDEX_FILE_VERSION)
    {
        GUI_Error_HIG(QT_TRANSLATE_NOOP("psdemuxer","Error"), QT_TRANSLATE_NOOP("psdemuxer","This file's index has been created with an older version of avidemux.\nPlease delete the idx2 file and reopen."));
        goto abt;
    }
    type=index.getAsString("Type");
    if(!type || type[0]!='P')
    {
        printf("[psDemux] Incorrect or not found type\n");
        goto abt;
    }
    append=index.getAsUint32("Append");
    printf("[psDemux] Append=%" PRIu32"\n",append);
    if(append) appendType=FP_APPEND;
    if(!parser.open(name,&appendType))
    {
        printf("[psDemux] Cannot open root file %s\n",name);
        goto abt;
    }
    if(!readVideo(&index)) 
    {
        printf("[psDemux] Cannot read Video section of %s\n",idxName);
        goto abt;
    }
    if(!readAudio(&index,name)) 
    {
        printf("[psDemux] Cannot read Audio section of %s => No audio\n",idxName);
    }
    if(!readIndex(&index))
    {
        printf("[psDemux] Cannot read index for file %s\n",idxName);
        goto abt;
    }
    if(readScrReset(&index))
    {
        ADM_info("Adjusting timestamps\n");
        // Update PTS/DTS of video taking SCR Resets into account
        int nbPoints=listOfScrGap.size();
        int index=0;
        uint64_t pivot=listOfScrGap[0].position;
        uint64_t timeOffset=0;
        uint32_t nbImage=ListOfFrames.size();
        for(int i=0;i<nbImage;i++)
        {
            dmxFrame *frame=ListOfFrames[i];
            if(frame->startAt>pivot) // next gap
            {
                    timeOffset=listOfScrGap[index].timeOffset;
                    index++;
                    if(index>=nbPoints) pivot=0xfffffffffffffffLL;
                        else pivot=listOfScrGap[index].position;
            }
            if(frame->dts!=ADM_NO_PTS) frame->dts+=timeOffset;
            if(frame->pts!=ADM_NO_PTS) frame->pts+=timeOffset;
        }
        ADM_info("Adjusted %d scr reset out of %d\n",(int)index,(int)nbPoints);
        ADM_info("Updating audio with list of SCR\n");
        for(int i=0;i<listOfAudioTracks.size();i++)
                  listOfAudioTracks[i]->access->setScrGapList(&listOfScrGap) ;
    }
    updatePtsDts();
    _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size();
    printf("[psDemux] Found %d video frames\n",_videostream.dwLength);
    if(_videostream.dwLength)_isvideopresent=1;
//***********
    
    psPacket=new psPacketLinear(0xE0);
    if(psPacket->open(name,appendType)==false) 
    {
        printf("psDemux] Cannot psPacket open the file\n");
        goto abt;
    }
    r=true;
    for(int i=0;i<listOfAudioTracks.size();i++)
    {
        ADM_psTrackDescriptor *desc=listOfAudioTracks[i];
        ADM_audioStream *audioStream=ADM_audioCreateStream(&desc->header,desc->access);
        if(!audioStream)
        {
            
        }else       
        {
                desc->stream=audioStream;
        }
    }
abt:
    index.close();
    free(idxName);
    printf("[psDemuxer] Loaded %d\n",r);
    return r;
}
Esempio n. 18
0
uint8_t psHeader::open(const char *name)
{
    char idxName[strlen(name)+4];
    bool r=false;
    FP_TYPE appendType=FP_DONT_APPEND;
    uint32_t append;
    char *type;

    sprintf(idxName,"%s.idx",name);
    indexFile index;
    if(!index.open(idxName))
    {
        printf("[psDemux] Cannot open index file %s\n",idxName);
        return false;
    }
    if(!index.readSection("System"))
    {
        printf("[psDemux] Cannot read system section\n");
        goto abt;
    }
    type=index.getAsString("Type");
    if(!type || type[0]!='P')
    {
        printf("[psDemux] Incorrect or not found type\n");
        goto abt;
    }
    append=index.getAsUint32("Append");

    if(append) appendType=FP_APPEND;
    if(!parser.open(name,&appendType))
    {
        printf("[psDemux] Cannot open root file\n",name);
        goto abt;
    }
    if(!readVideo(&index)) 
    {
        printf("[psDemux] Cannot read Video section of %s\n",idxName);
        goto abt;
    }
    if(!readAudio(&index,name)) 
    {
        printf("[psDemux] Cannot read Audio section of %s\n",idxName);
        goto abt;
    }
    if(!readIndex(&index))
    {
        printf("[psDemux] Cannot read index for file %s\n",idxName);
        goto abt;
    }
    updatePtsDts();
    _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size();
    printf("[psDemux] Found %d video frames\n",_videostream.dwLength);
    if(_videostream.dwLength)_isvideopresent=1;
//***********
    
    psPacket=new psPacketLinear(0xE0);
    if(psPacket->open(name,append)==false) 
    {
        printf("psDemux] Cannot psPacket open the file\n");
        goto abt;
    }
    r=true;
abt:
    index.close();
    printf("[psDemuxer] Loaded %d\n",r);
    return r;
}
Esempio n. 19
0
void printNext(std::ostream& os, Instr::Pointer code, int& step,
			   bool prstep)
{
  if (prstep){
    os << std::dec;
    os << step << ": ";
  }
  int oldStep = step;
  switch (code[step++]){
  case Instr::MKDENO:{
    int di = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "MKDENO d" << di << " -> r" << ri;
    break;}
  case Instr::CALLNATIVE:{
    int ni = readIndex(code,step);
    int pi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "CALLNATIVE n" << ni << " r" << pi << " -> r" << ri;
    break;}
  case Instr::TESTNATIVE:{
    int ni = readIndex(code,step);
    int pi = readIndex(code,step);
    os << "TESTNATIVE p" << ni << " r" << pi;
    break;}
  case Instr::LOADGLOBAL:{
    int ci = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "LOADGLOBAL g" << ci << " -> r" << ri;
    break;}
  case Instr::WAITLOADGLOBAL:{
    int ci = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "WAITLOADGLOBAL g" << ci << " -> r" << ri;
    break;}
  case Instr::LOADPARAM:{
    int vi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "LOADPARAM p" << vi << " -> r" << ri;
    break;}
  case Instr::WAITLOADPARAM:{
    int vi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "WAITLOADPARAM p" << vi << " -> r" << ri;
    break;}
  case Instr::WAITGLOBAL:{
    int vi = readIndex(code,step);
    os << "WAITGLOBAL g" << vi;
    break;}
  case Instr::WAIT:{
    int vi = readIndex(code,step);
    os << "WAIT v" << vi;
    break;}
  case Instr::LOAD:{
    int vi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "LOAD v" << vi << " -> r" << ri;
    break;}
  case Instr::WAITLOAD:{
    int vi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "WAITLOAD v" << vi << " -> r" << ri;
    break;}
  case Instr::MOVE:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "MOVE r" << ri1 << " -> r" << ri2;
    break;}
  case Instr::STORE:{
    int ri = readIndex(code,step);
    int vi = readIndex(code,step);
    os << "STORE r" << ri << " -> v" << vi;
    break;}
  case Instr::STOREGLOBAL:{
    int ri = readIndex(code,step);
    int gi = readIndex(code,step);
    os << "STOREGLOBAL r" << ri << " -> g" << gi;
    break;}
  case Instr::UNIFY:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "UNIFY r" << ri1 << ", r" << ri2;
    break;}
  case Instr::MEMBER:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "MEMBER r" << ri1 << ", r" << ri2;
    break;}
  case Instr::UNIQMEMBER:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "UNIQMEMBER r" << ri1 << ", r" << ri2;
    break;}
  case Instr::SUBSET:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "SUBSET r" << ri1 << ", r" << ri2;
    break;}
  case Instr::MKTERM:{
    int ci = readIndex(code,step);
    int pi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "MKTERM c" << ci << ", r" << pi 
       << " -> r" << ri;
    break;}
  case Instr::MKSINGLE:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "MKSINGLE r" << ri1 << " -> r" << ri2;
    break;}
  case Instr::HOM:{
    int hi = readIndex(code,step);
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    os << "HOM h" << hi << " r" << ri1 << " -> r" << ri2;
    break;}
  case Instr::MKEMPTY:{
    int ri = readIndex(code,step);
    os << "MKEMPTY -> r" << ri;
    break;}
  case Instr::MKUNIV:{
    int ri = readIndex(code,step);
    os << "MKUNIV -> r" << ri;
    break;}
  case Instr::ISECT:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    int ri3 = readIndex(code,step);
    os << "ISECT r" << ri1 << ", r " << ri2 
       << " -> r" << ri3;
    break;}
  case Instr::UNION:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    int ri3 = readIndex(code,step);
    os << "UNION r" << ri1 << ", r " << ri2 
       << " -> r" << ri3;
    break;}
  case Instr::APPLY:{
    int ri1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    int ri3 = readIndex(code,step);
    os << "APPLY r" << ri1 << ", r" << ri2 <<
      " -> r" << ri3;
    break;}
  case Instr::APPLYGLOBAL:{
    int gi1 = readIndex(code,step);
    int ri2 = readIndex(code,step);
    int ri3 = readIndex(code,step);
    os << "APPLYGLOBAL g" << gi1 << ", r" << ri2 <<
      " -> r" << ri3;
    break;}
  case Instr::IF:{
    int ri = readIndex(code,step);
    int ti = readIndex(code,step);
    os << "IF r" << ri << ", " << (step+ti);
    break;}
  case Instr::IFNOT:{
    int ri = readIndex(code,step);
    int ti = readIndex(code,step);
    os << "IFNOT r" << ri << ", " << (step+ti);
    break;}
  case Instr::GOTO:{
    int ti = readIndex(code,step);
    os << "GOTO " << (step+ti);
    break;}
  case Instr::MKINTEN:{
    int ii = readIndex(code,step);
    int pi = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "MKINTEN s" << ii <<
      ", r" << pi << " -> r" << ri;
    break;}
  case Instr::MKOUTERINTEN:{
    int ii = readIndex(code,step);
    int ri = readIndex(code,step);
    os << "MKOUTERINTEN s" << ii << " -> r" << ri;
    break;}
  case Instr::FAILURE:{
    os << "FAILURE";
    break;}
  case Instr::SUCCESS:{
    os << "SUCCESS";
    break;}
  case Instr::DEPTHFIRST:{
    os << "DEPTHFIRST";
    break;}
  default:
    os << "??? " << (int)code[oldStep];
  }
}
Esempio n. 20
0
std::vector<IndexEntry>* Plugin::getIndex()
{
    readIndex();
    return &_index;
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
// INPUT VARIABLES
	char* program;
	char* target_dir;
	char* output_file_name;
	char* input_file_name;
	char* rewritten_file_name;	

// determines which mode the program is running in
	int indexer_test_flag;

// overall data structure
	INVERTED_INDEX* index;

// these variables handle the scandir results and pulling information from files
	int numfiles = 0;
	struct dirent **files;	
	char* file_name;
	char* file_contents;

// this variable is used for parsing the HTML
	int file_pos;

// variables used for WordNode (word == key) and DocumentNode (doc_id)
	char* word;
	int doc_id;

	indexer_test_flag = 0; // default is basic funcitonality

	program = argv[0];

// if incorrect number of arguments
	if(argc != 3 && argc != 5)
	{
		fprintf(stderr, "%s: The indexer requires either 2 (a target directory and output file name) or 4 (a target directory, output file name, input file name, and a rewritten file name\n", program);

		return 1;
	}

	target_dir = argv[1];
	output_file_name = argv[2];

// if 5 arguments --> TESTING MODE
	if(argc == 5)
	{
		indexer_test_flag = 1;
		input_file_name = argv[3];
		rewritten_file_name = argv[4];
	}

// if the target directory doesn't exist
	if(!directoryExists(target_dir))
	{
		fprintf(stderr, "%s: Invalid target directory %s\n", program, target_dir);
		return 1;
	}
	
	numfiles = getFileList(target_dir, &files);

	chdir(target_dir);

// if there are no files in the target directory
	if(numfiles <= 0)
	{
		fprintf(stderr, "%s: Error with target directory %s'n", program, target_dir);
		return 1;
	}

	index = initializeDict();

// this for loop goes through each file in "files", pulls each word out of the HTML, and updates the index data structure
	for(int i=0; i < numfiles; i++)
	{
		file_name = files[i]->d_name;

// if it's a regular file (to avoid . and .. files)
		if(regularFile(file_name))
		{
			file_contents = NULL;	
			file_contents = readFile(file_name);
			file_pos = 0;
			doc_id = atoi(file_name);

// just in case a 404 wasn't caught by the crawler
			if(file_contents != NULL)
			{
				word = NULL;
				word = malloc(500*sizeof(char));
				MALLOC_CHECK(word);
				BZERO(word, 500*sizeof(char));

// GetNextWord returns the index in file_contents where it stopped parsing, while assigning a new word to the "word"
				while((file_pos = parseHTML(file_contents, word, file_pos)) != -1)
				{
					updateIndex(word, doc_id, index);

					free(word);
					//word = NULL;
					word = malloc(500*sizeof(char));
					MALLOC_CHECK(word);
					BZERO(word, 500*sizeof(char));
				}

				free(word);
			}

			free(file_contents);
		}

		free(files[i]);
	}

	free(files);

// outputs to a file
	saveFile(index, output_file_name);
	cleanIndex(index);

// if it's in testing mode
	if(indexer_test_flag)
	{
		INVERTED_INDEX* newindex;
		newindex = readIndex(input_file_name);
		saveFile(newindex, rewritten_file_name);
		cleanIndex(newindex);
	}
}
Esempio n. 22
0
int
main(int argc, char *argv[]) {
    int in;
    struct stat sb;
    uint8 *buf;
    index_header *h;
    struct options opts;
    char outnbuf[512];

    parse_arguments(argc, argv, &opts);

    in = open(opts.infile, O_RDONLY);
    if (in == -1) {
        fprintf(stderr, "Error: Could not open file %s: %s\n", opts.infile,
                strerror(errno));
        return EXIT_FAILURE;
    }

    if (fstat(in, &sb) == -1) {
        perror("stat() failed");
        return EXIT_FAILURE;
    }

    buf = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, in, 0);
    if (buf == MAP_FAILED) {
        perror("mmap() failed");
        return EXIT_FAILURE;
    }
    close(in);

    if (opts.sound && !opts.outfile) {
        char *pdot = strrchr(opts.infile, '.');
        opts.outfile = outnbuf;
        strcpy(outnbuf, opts.infile);
        if (pdot)
            outnbuf[pdot - opts.infile] = 0;

    }

    h = readIndex(buf);
    if (opts.print)
        printIndex(h, buf, stdout);

    if (opts.list) {
        listEntries(h, buf, stdout);
    }

    if (opts.sound && opts.outfile) {
        writeSoundEntries(h, buf, opts.outfile);

    } else if (opts.outfile) {
        FILE *out;
        out = fopen(opts.outfile, "wb+");
        if (out == NULL) {
            fprintf(stderr, "Could not open output file '%s': %s\n",
                    opts.outfile, strerror(errno));
            exit(EXIT_FAILURE);
        }
        writeEntries(h, buf, out);
        fclose(out);
    }

    // freeIndex(h);
    munmap(buf, sb.st_size);
    return EXIT_SUCCESS;
}
Esempio n. 23
0
uint8_t tsHeader::open(const char *name)
{
    char *idxName=(char *)malloc(strlen(name)+6);
    bool r=false;
    FP_TYPE appendType=FP_DONT_APPEND;
    uint32_t append;
    char *type;
    uint64_t startDts;
    uint32_t version=0;

    sprintf(idxName,"%s.idx2",name);
    indexFile index;
    if(!index.open(idxName))
    {
        printf("[tsDemux] Cannot open index file %s\n",idxName);
        free(idxName);
        return false;
    }
    if(!index.readSection("System"))
    {
        printf("[tsDemux] Cannot read system section\n");
        goto abt;
    }
    type=index.getAsString("Type");
    if(!type || type[0]!='T')
    {
        printf("[tsDemux] Incorrect or not found type\n");
        goto abt;
    }

    version=index.getAsUint32("Version");
    if(version!=ADM_INDEX_FILE_VERSION)
    {
        GUI_Error_HIG("Error","This file's index has been created with an older version of avidemux.\nPlease delete the idx2 file and reopen.");
        goto abt;
    }
    append=index.getAsUint32("Append");
    printf("[tsDemux] Append=%"PRIu32"\n",append);
    if(append) appendType=FP_APPEND;
    if(!parser.open(name,&appendType))
    {
        printf("[tsDemux] Cannot open root file (%s)\n",name);
        goto abt;
    }
    if(!readVideo(&index)) 
    {
        printf("[tsDemux] Cannot read Video section of %s\n",idxName);
        goto abt;
    }

    if(!readAudio(&index,name)) 
    {
        printf("[tsDemux] Cannot read Audio section of %s => No audio\n",idxName);
    }

    if(!readIndex(&index))
    {
        printf("[tsDemux] Cannot read index for file %s\n",idxName);
        goto abt;
    }
    updateIdr();
    updatePtsDts();
    _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size();
    printf("[tsDemux] Found %d video frames\n",_videostream.dwLength);
    if(_videostream.dwLength)_isvideopresent=1;
//***********
    
    tsPacket=new tsPacketLinear(videoPid);
    if(tsPacket->open(name,appendType)==false) 
    {
        printf("tsDemux] Cannot tsPacket open the file\n");
        goto abt;
    }
    r=true;
    for(int i=0;i<listOfAudioTracks.size();i++)
    {
        ADM_tsTrackDescriptor *desc=listOfAudioTracks[i];
        ADM_audioStream *audioStream=ADM_audioCreateStream(&desc->header,desc->access);
        if(!audioStream)
        {
            
        }else       
        {
                desc->stream=audioStream;
                audioStream->setLanguage(desc->language);
        }
    }
abt:
    free(idxName);
    index.close();
    printf("[tsDemuxer] Loaded %d\n",r);
    return r;
}
Esempio n. 24
0
void CDExtraGatewayAudioUnit::setLanguage(TEXT_LANG language)
{
	m_language = language;

	wxString ambeFileName;
	wxString indxFileName;

	switch (language) {
		case TL_DEUTSCH:
			ambeFileName = wxT("de_DE.ambe");
			indxFileName = wxT("de_DE.indx");
			break;
		case TL_DANSK:
			ambeFileName = wxT("dk_DK.ambe");
			indxFileName = wxT("dk_DK.indx");
			break;
		case TL_ITALIANO:
			ambeFileName = wxT("it_IT.ambe");
			indxFileName = wxT("it_IT.indx");
			break;
		case TL_FRANCAIS:
			ambeFileName = wxT("fr_FR.ambe");
			indxFileName = wxT("fr_FR.indx");
			break;
		case TL_ESPANOL:
			ambeFileName = wxT("es_ES.ambe");
			indxFileName = wxT("es_ES.indx");
			break;
		case TL_SVENSKA:
			ambeFileName = wxT("se_SE.ambe");
			indxFileName = wxT("se_SE.indx");
			break;
		case TL_POLSKI:
			ambeFileName = wxT("pl_PL.ambe");
			indxFileName = wxT("pl_PL.indx");
			break;
		case TL_ENGLISH_US:
			ambeFileName = wxT("en_US.ambe");
			indxFileName = wxT("en_US.indx");
			break;
		case TL_NORSK:
			ambeFileName = wxT("no_NO.ambe");
			indxFileName = wxT("no_NO.indx");
			break;
//		case TL_NEDERLANDS_NL:
//			ambeFileName = wxT("nl_NL.ambe");
//			indxFileName = wxT("nl_NL.indx");
//			break;
//		case TL_NEDERLANDS_BE:
//			ambeFileName = wxT("nl_BE.ambe");
//			indxFileName = wxT("nl_BE.indx");
//			break;
		default:
			ambeFileName = wxT("en_GB.ambe");
			indxFileName = wxT("en_GB.indx");
			break;
	}

	bool ret = readAMBE(ambeFileName);
	if (!ret) {
		delete[] m_ambe;
		m_ambe = NULL;
		return;
	}

	ret = readIndex(indxFileName);
	if (!ret) {
		delete[] m_ambe;
		m_ambe = NULL;
	}
}
//
// here are the private guts
//
rampInfo* cRamp::do_ramp( ramp_fileoffset_t arg , eWhatToRead	what )
{
   
   switch( what ) {
   case RAMP_RUNINFO:
   case RAMP_HEADER:
   case RAMP_PEAKS:
   case RAMP_INSTRUMENT:
      break; // OK
   default:
	  std::cerr << "unknown read type!\n";
      return NULL;
      break;
   }	
   
   rampInfo* returnPtr=NULL;
   
   if ((RAMP_RUNINFO != what) && (RAMP_INSTRUMENT != what) && !m_scanOffsets) {
      int iLastScan = 0; 
     // we need the index to get anything besides the header
      ramp_fileoffset_t indexOffset = getIndexOffset(m_handle);
      m_scanOffsets = readIndex(m_handle, indexOffset, &iLastScan);
      if (iLastScan >= m_runInfo->m_data.scanCount) {
		 if (!m_declaredScansOnly) {
           m_runInfo->m_data.scanCount = iLastScan;
		 } else { // get rid of all the fake entries created
			 for (int n=1;n<=iLastScan;n++) { // ramp is 1 based
				 if (m_scanOffsets[n]==-1) {
					// find a run of fakes
				    int m;
					for (m=n+1;(m<=iLastScan)&&(m_scanOffsets[m]==-1);m++);
					if (m<=iLastScan) {
						memmove(m_scanOffsets+n,m_scanOffsets+m,
						  sizeof(ramp_fileoffset_t)*((iLastScan-m)+1));
					}
					iLastScan-=(m-n);
				 }
			 }
		 }
      }
      // HENRY - store last scan explicitly.
      m_lastScan = iLastScan;
      // END HENRY
   }

   
   // HENRY -- arg is out of bounds. instead of creating havoc in RAMP, let's just kill it here.
   if (RAMP_RUNINFO != what && (RAMP_INSTRUMENT != what) && (arg > m_runInfo->m_data.scanCount || arg < 1)) {
     return (NULL);
   }
     
   if (m_scanOffsets || (RAMP_RUNINFO == what) || (RAMP_INSTRUMENT == what)) {
      ramp_fileoffset_t scanOffset=-1;
      if (RAMP_RUNINFO == what || RAMP_INSTRUMENT == what) {
         scanOffset = 0; // read from head of file
      } else {
         scanOffset = m_scanOffsets[arg]; // ramp is one-based
      }
      
      if (scanOffset >= 0) {
         
         // -----------------------------------------------------------------------
         // And now we can parse the info we were looking for
         // -----------------------------------------------------------------------
         
         
         // Ok now we have to copy everything in our structure
         switch( what )
         {
         case RAMP_RUNINFO:
            returnPtr = new rampRunInfo( m_handle );
            break;
         case RAMP_HEADER:
            returnPtr = new rampScanInfo( m_handle, scanOffset, (int)arg );
            if (returnPtr) {
#ifdef HAVE_PWIZ_MZML_LIB
			   if (!m_handle->mzML) // rampadapter already set this for us
#endif
              ((rampScanInfo *)returnPtr)->m_data.filePosition = scanOffset; // for future reference
            
              // HENRY -- error checking here
              if (((rampScanInfo*)returnPtr)->m_data.acquisitionNum < 0) {
                // something failed in RAMP, possibly because it's a missing scan
                delete ((rampScanInfo*)returnPtr);
                returnPtr = NULL;
              }
            }
            break;           
         case RAMP_PEAKS:
            returnPtr = new rampPeakList( m_handle, scanOffset);
            
            // HENRY -- error checking here
            if (returnPtr && ((rampPeakList*)returnPtr)->getPeakCount() <= 0) {
              // something failed in RAMP, possibly because it's a missing scan
              delete ((rampPeakList*)returnPtr);
              returnPtr = NULL;
            }
            break;
            
         // HENRY -- add the instrument info reading functionality (present in RAMP, but not provided in cRAMP before)
         case RAMP_INSTRUMENT:
            returnPtr = new rampInstrumentInfo(m_handle);
            if (((rampInstrumentInfo*)returnPtr)->m_instrumentStructPtr == NULL) {
              delete ((rampInstrumentInfo*)returnPtr);
              returnPtr = NULL;
            }
            break;
         }
         
      }
   }
   
   
   
   return returnPtr;
}