예제 #1
0
int main( int argc, char const * const argv[] )
{
    processDir( "./" );
    for( int arg = 1 ; arg < argc ; arg++ )
        processDir( argv[arg] );
    return 0 ;
}
예제 #2
0
void AssetBrowser::findResources()
{
	for (auto& resources : m_resources)
	{
		resources.clear();
	}

	const char* base_path = m_editor.getEngine().getDiskFileDevice()->getBasePath();
	processDir(base_path, Lumix::stringLength(base_path));
	auto* patch_device = m_editor.getEngine().getPatchFileDevice();
	if (patch_device) processDir(patch_device->getBasePath(), Lumix::stringLength(patch_device->getBasePath()));
}
예제 #3
0
void AssetBrowser::findResources()
{
	for (auto& resources : m_resources)
	{
		resources.clear();
	}

	const char* base_path = m_editor.getEngine().getDiskFileDevice()->getBasePath(0);
	processDir(base_path, Lumix::stringLength(base_path));
	base_path = m_editor.getEngine().getDiskFileDevice()->getBasePath(1);
	if (base_path[0] != 0) processDir(base_path, Lumix::stringLength(base_path));
}
예제 #4
0
파일: main.cpp 프로젝트: vbifial/cvproj
int main(int argc, char *argv[])
{
    int time = getTimeMill();
    QCoreApplication a(argc, argv);
    
    QString dirPath = (argc > 1) ? a.arguments()[1] : 
            a.applicationDirPath();
    QString patternPath = (argc > 2) ? a.arguments()[2] :
            QString("input.jpg");
    QImage pattern(patternPath);
    if (pattern.isNull()) {
        pattern = QImage("input.jpg");
    }
    if (pattern.isNull())
        cout << "No pattern image." << endl;
    else {
        gpattern = GImage(pattern);
        GPyramid pyr(gpattern, 1.6f, 0.5f, 3);
        poivec p = getDOGDetection(pyr);
        p = calculateOrientations(pyr, p);
        pdescs = getDescriptors(pyr, p);
        processDir(dirPath);
    }
    
    time = getTimeMill() - time;
    cout << "Completed in " << time << "ms." << endl;
    return 0;
//    return a.exec();
}
예제 #5
0
void MainWindow::on_openDirButton_clicked()
{
    m_imageFiles.clear();
    m_imageTargetPath.clear();

    QString dir_path = QFileDialog::getExistingDirectory(this, "Selecteer een directory met liederen", QDir::homePath());

    if (dir_path.isEmpty())
    {
        QMessageBox::critical( this, "Selecteer een directory met liederen!", "Selecteer een directory met liederen!");
        return;
    }

    QDir dir (dir_path);
    if (!dir.exists())
    {
        QMessageBox::critical( this, "Directory bestaat niet!", "Directory bestaat niet!");
        return;
    }


    m_sourcePath = dir.absolutePath();
    m_targetPath = m_sourcePath + "_converted" + "/";

    processDir (dir.absolutePath(), "./", m_imageFiles, m_imageTargetPath);

    ui->imagesFoundLabel->setText("Liederen gevonden: " + QString::number(m_imageFiles.count()));

    ui->songSlider->setMaximum(m_imageFiles.count());
    ui->songSlider->setEnabled( m_imageFiles.count() );

    if (m_imageFiles.count())
        loadImage(m_imageFiles.first());
}
 // add functions with the tests here and use e.g. CPPUNIT_ASSERT to do the
 // test
 void testSetGetString()
 {
 QString dir(SRCDIR);
     QDir d(dir+"/share/libmathml/testsuite");
 printf("%s\n", (const char*)d.absolutePath().toUtf8());
     processDir(d);
     CPPUNIT_ASSERT(VALGRIND_COUNT_ERRORS == 0);
 }
예제 #7
0
int main(int argc, char* argv[]){
    //simple parameter number verification
    if(argc != 2){
        printHelp();
        exit(-1);
    }

    //process images from a given directory
    processDir(argv[1]);

}
예제 #8
0
void TarListingThread::processDir( const KTarDirectory *tardir, const TQString & root )
{
	TQStringList list = tardir->entries();
	
	TQStringList::const_iterator itEnd = list.constEnd();

	for ( TQStringList::const_iterator it = list.constBegin(); it != itEnd; ++it )
	{
		const KTarEntry* tarEntry = tardir->entry((*it));
		if (!tarEntry)
			continue;

		TQStringList col_list;
		TQString name;
		if (root.isEmpty() || root.isNull())
			name = tarEntry->name();
		else
			name = root + tarEntry->name();
		if ( !tarEntry->isFile() )
			name += '/';
		col_list.append( name );
		TQString perms = makeAccessString(tarEntry->permissions());
		if (!tarEntry->isFile())
			perms = "d" + perms;
		else if (!tarEntry->symlink().isEmpty())
			perms = "l" + perms;
		else
			perms = "-" + perms;
		col_list.append(perms);
		col_list.append( tarEntry->user() );
		col_list.append( tarEntry->group() );
		TQString strSize = "0";
		if (tarEntry->isFile())
		{
			strSize.sprintf("%d", ((KTarFile *)tarEntry)->size());
		}
		col_list.append(strSize);
		TQString timestamp = tarEntry->datetime().toString(Qt::ISODate);
		col_list.append(timestamp);
		col_list.append(tarEntry->symlink());
		
		ListingEvent *ev = new ListingEvent( col_list );
		tqApp->postEvent( m_parent, ev );

		// if it's a directory, process it.
		// remember that name is root + / + the name of the directory
		if ( tarEntry->isDirectory() )
		{
			processDir( static_cast<const KTarDirectory *>( tarEntry ), name );
		}
	}
}
예제 #9
0
파일: utils.cpp 프로젝트: Daniel1892/tora
	void processDir(const char * directory)
	{
		int fd;
		
		fd = open( directory, O_RDONLY);
		//if ( fd == -1)
		//{
		//	fprintf( stderr, _strerror(NULL) );
		//	exit(-1);
		//}
		processDir(directory, fd);
		if ( fd != -1)
			close(fd);
	}
예제 #10
0
/* Main - create the threads and start the processing */
int main(int argc, char *argv[]) {

    /* Check for argument count */
    if (argc != 2) {
        std::cerr << "Invalid number of arguments." << std::endl;
        return -1;
    }

    /* Read the path to the data */
    std::string path(argv[1]);

    /* Read the list of directories to process */
    std::string image_list_filename = path + "image_list.dat";
    std::vector<std::string> input_images;
    FILE *file = fopen(image_list_filename.c_str(), "r");
    if (!file) {
        std::cerr << "Could not open 'image_list.dat' inside '" << path << "'." << std::endl;
        return -1;
    }
    char line[128];
    while (fgets(line, sizeof(line), file) != NULL) {
        line[strlen(line)-1] = 0;
        std::string temp_str(line);
        input_images.push_back(temp_str);
    }
    fclose(file);

    /* Create and prepare the file for metrics */
    std::string metrics_file = path + "computed_metrics.csv";
    std::ofstream data_stream;
    data_stream.open(metrics_file, std::ios::out);
    if (!data_stream.is_open()) {
        std::cerr << "Could not create the metrics file." << std::endl;
        return -1;
    }
    data_stream << std::endl;
    data_stream.close();

    /* Process each image */
    for (unsigned int index = 0; index < input_images.size(); index++) {
        std::cout << "Processing " << input_images[index] << std::endl;
        if (!processDir(path, input_images[index], metrics_file)) {
            std::cout << "ERROR !!!" << std::endl;
            return -1;
        }
    }

    return 0;
}
예제 #11
0
void TarListingThread::run()
{
	if (!m_archive->open( IO_ReadOnly ))
	{
		ListingEvent *ev = new ListingEvent( QStringList(), ListingEvent::Error );
		qApp->postEvent( m_parent, ev );
		return;
	}
	
	processDir( m_archive->directory(), QString() );
	
	// Send an empty QStringList in an Event to signal the listing end.
	ListingEvent *ev = new ListingEvent( QStringList(), ListingEvent::ListingFinished );
	qApp->postEvent( m_parent, ev );
}
예제 #12
0
파일: main.cpp 프로젝트: vbifial/cvproj
void processDir(QString &path) {
    cout << "dir " << path.toStdString() << endl;
    QDir dir(path);
    auto list = dir.entryList(QDir::Files);
    for (int i = 0; i < list.size(); i++) {
        QString filePath = path + "/" + list[i];
        processFile(filePath);
    }
    list = dir.entryList(QDir::Dirs);
    for (int i = 0; i < list.size(); i++) {
        if (list[i] == s1 || list[i] == s2)
            continue;
        QString np = path + "/" + list[i];
        processDir(np);
    }
}
예제 #13
0
int CAccessHandle::processDir(std::string absDirName)
{
	CAccessConfig::getInstance()->g_logger->log_trace("[%s][%d]process dir %s!", __FILE__, __LINE__, absDirName.c_str());

	if(!checkWhiteBlackDir(absDirName))
	{		
		return ERROR_DATADIR_NONEED_PROC;
	}

	DIR * dirFP = NULL;
	struct dirent * direntp = NULL;
	struct stat buf;
	char sFilePath[256];
	if ((dirFP = opendir(absDirName.c_str())) == NULL)
	{
		CAccessConfig::getInstance()->g_logger->log_error("[%s][%d]open dir (%s) failed!", __FILE__, __LINE__, absDirName.c_str());
		return ERROR_DATADIR_OPEN_FAILED;
	}
	while ((direntp = readdir(dirFP)) != NULL)
	{
		if(direntp->d_name[0] != '.')
		{
			memset(sFilePath, 0, sizeof(sFilePath));
			snprintf(sFilePath, sizeof(sFilePath) - 1, "%s/%s", absDirName.c_str(), direntp->d_name);
			std::string absfile = sFilePath;
			stat(sFilePath, &buf);
			if(S_ISDIR(buf.st_mode))
			{
				//DEBUG_LOG
				processDir(absfile);
                	}
                	if(S_ISREG(buf.st_mode))
			{
				//DEBUG_LOG				
				processFile(absfile);
               	}	
		}
	}
	closedir(dirFP);
	
	return ERROR_SUCCESS;
}
예제 #14
0
 bool processDir(QDir &dir) {
     QFileInfoList list = dir.entryInfoList();
     for (int i = 0; i < list.size(); ++i) {
         QFileInfo fi = list.at(i);
         if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") {
             QDir d(fi.absoluteFilePath());
             if (processDir(d)) {
                 return true;
             }
         } else if (fi.fileName().endsWith(".mml")) {
             QString path = fi.absoluteFilePath();
             testFile(path);
             checkErrors(path);
             if (VALGRIND_COUNT_ERRORS != 0 || leaked != 0) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #15
0
/*
  Given a directory name, verify if it is valid and then process all the
  PNG images inside it and any other subdirectory. BMP images are saved in
  a BMP directory
  Input: dirname - directory name to be processed.
*/
void processDir(char* dirname){
    //open directory
    DIR *dir;
    struct dirent *file;
    dir = opendir(dirname);
    if(dir != NULL){
        //process each file inside dir
        while((file = readdir(dir))){
            //verify if the file is a PNG image
            if(verifyFile(file->d_name)){
                char message[MESSAGELENGTH] = "------------\nCriando copia BMP da imagem: ";
                strcat(message,file->d_name);
                strcat(message,"\n");
                logger(message);
                convert2BMP(file->d_name, dirname);
            }
            else if((!strcmp(file->d_name, ".")) || (!strcmp(file->d_name, ".."))){
                //do nothing
            }
            else{
                //it may be a directory or an file with different file type, try to open it
                //attach current path
                char currentFile[FILENAMELENGTH] = ".\\";
                strcat(currentFile,dirname);
                strcat(currentFile,"\\");
                strcat(currentFile,file->d_name);
                processDir(currentFile);
            }
        }
        (void)closedir(dir);
    }
    else{
        //log error
        char message[MESSAGELENGTH] = "***Arquivo invalido: ";
        strcat(message,dirname);
        strcat(message,"\n");
        logger(message);
    }
}
예제 #16
0
void MainWindow::processDir( QString path, QString relativePath, QStringList& imageFiles, QStringList& imageFilesTargetPath )
{
    QDir dir (path);

    QFileInfoList file_list = dir.entryInfoList(QStringList() << "*.png" << "*.bmp" << "*.jpg" << "*.gif");

    for (int i=0; i<file_list.size(); i++)
    {
        QFileInfo file_info = file_list.at(i);

        if (!file_info.exists())
            continue;

        if (!file_info.isFile())
            continue;

        imageFiles.push_back( file_info.absoluteFilePath() );

        imageFilesTargetPath.push_back( relativePath );
    }

    QFileInfoList dir_list = dir.entryInfoList( QStringList(), QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);

    for (int i=0; i<dir_list.size(); i++)
    {
        QFileInfo dir_info = dir_list.at(i);

        if (!dir_info.exists())
            continue;

        if (!dir_info.isDir())
            continue;

        processDir (dir_info.absoluteFilePath(), relativePath + "/" + dir_info.fileName(), imageFiles, imageFilesTargetPath);
    }
}
예제 #17
0
void AssetBrowser::processDir(const char* dir, int base_length)
{
	auto* iter = PlatformInterface::createFileIterator(dir, m_editor.getAllocator());
	PlatformInterface::FileInfo info;
	while (getNextFile(iter, &info))
	{
		if (info.filename[0] == '.') continue;

		if (info.is_directory)
		{
			char child_path[Lumix::MAX_PATH_LENGTH];
			Lumix::copyString(child_path, dir);
			Lumix::catString(child_path, "/");
			Lumix::catString(child_path, info.filename);
			processDir(child_path, base_length);
		}
		else
		{
			addResource(dir + base_length, info.filename);
		}
	}

	destroyFileIterator(iter);
}
예제 #18
0
void LinkBackupThread::run()
{
  if (!::getCopyLinkUtil().setHashType(m_backupSet.getHashMethod()))
  {
    ERROR_MSG(QString(tr("Failed to setup hash generator.")), 0);
    return;
  }
  ::getCopyLinkUtil().resetStats();

  setOldEntries(nullptr);
  setCurrentEntries(new DBFileEntries());

  m_cancelRequested = false;
  m_previousDirRoot = newestBackDirectory(m_backupSet.getToPath());
  if (m_previousDirRoot.length() > 0) {
    INFO_MSG(QString(tr("Found previous backup in %1")).arg(m_previousDirRoot), 1);

    QString previousDBFileEntries = findHashFileCaseInsensitive(m_previousDirRoot, m_backupSet.getHashMethod());
    if (previousDBFileEntries.isEmpty())
    {
        WARN_MSG(QString(tr("Although a previous backup was found in %1, file entries were not found for hash method %2.")).arg(m_previousDirRoot, m_backupSet.getHashMethod()), 1);
    }
    else
    {
        setOldEntries(DBFileEntries::read(previousDBFileEntries));
        INFO_MSG(QString(tr("Found %1 entries in previous backup.")).arg(numOldEntries()), 1);
    }
  } else {
    WARN_MSG(QString(tr("No previous backup found.")), 1);
  }
  if (m_oldEntries == nullptr)
  {
    m_oldEntries = new DBFileEntries();
  }
  m_toDirRoot = createBackDirectory(m_backupSet.getToPath());

  QDir topFromDir(m_backupSet.getFromPath());

  // Name of the directory that is backed up without the path.
  QString topFromDirName = topFromDir.dirName();
  if (!topFromDir.exists() || topFromDirName.length() == 0) {
    WARN_MSG(QString(tr("Diretcory does not exist, or no directory name in %1, aborting backup.")).arg(m_backupSet.getFromPath()), 1);
    return;
  }

  QString canonicalPath = topFromDir.canonicalPath();
  m_fromDirWithoutTopDirName = canonicalPath.left(canonicalPath.length() - topFromDirName.length());

  QDir toDirLocation(m_toDirRoot);
  toDirLocation.mkdir(topFromDirName);
  toDirLocation.cd(topFromDirName);

  DEBUG_MSG(QString(tr("toDirRoot:%1 topFromDirName:%2 m_fromDir:%3")).arg(m_toDirRoot, topFromDirName, canonicalPath), 1);
  INFO_MSG(QString(tr("toDirRoot:%1 topFromDirName:%2 m_fromDir:%3")).arg(m_toDirRoot, topFromDirName, canonicalPath), 0);

  processDir(topFromDir, toDirLocation);
  TRACE_MSG(QString("Ready to write final hash summary %1").arg(m_toDirRoot + "/" + m_backupSet.getHashMethod() + ".txt"), 1);
  m_currentEntries->write(m_toDirRoot + "/" + m_backupSet.getHashMethod() + ".txt");

  INFO_MSG(QString(tr("Backup finished.")), 0);
  INFO_MSG(::getCopyLinkUtil().getStats(), 0);
}
예제 #19
0
void LinkBackupThread::processDir(QDir& currentFromDir, QDir& currentToDir)
{
  long numErrors = getLogger().errorCount();
  if (numErrors > 1000)
  {
    QString errorMessage = QString("%1 errors found, quit?");
    QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Test", errorMessage, QMessageBox::Yes|QMessageBox::No);
      if (reply == QMessageBox::Yes) {
        requestCancel();
      } else {
        getLogger().clearErrorCount();
      }
  }

  TRACE_MSG(QString("Processing directory %1").arg(currentFromDir.canonicalPath()), 1);
  // Process directories, then process files.
  QList<QFileInfo> list = currentFromDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::Hidden | QDir::Readable);
  QFileInfo info;
  foreach (info, list) {
    if (isCancelRequested()) {
      return;
    }
    TRACE_MSG(QString("Found Dir to processes %1").arg(info.canonicalFilePath()), 2);
    if (passes(info))
    {
      DEBUG_MSG(QString("Dir Passes: %1").arg(info.canonicalFilePath()), 2);
      if (!currentToDir.mkdir(info.fileName())) {
        ERROR_MSG(QString("Failed to create directory %1/%2").arg(currentToDir.canonicalPath(), info.fileName()), 1);
      } else if (!currentToDir.cd(info.fileName())) {
        ERROR_MSG(QString("Failed to cd to directory %1/%2").arg(currentToDir.canonicalPath(), info.fileName()), 1);
      } else if (!currentFromDir.cd(info.fileName())) {
        ERROR_MSG(QString("Failed to cd to directory %1/%2").arg(currentFromDir.canonicalPath(), info.fileName()), 1);
        if (!currentToDir.cdUp()) {
          ERROR_MSG("Failed to cd up a directory for the to directory", 1);
          requestCancel();
          return;
        }
      } else {
        processDir(currentFromDir, currentToDir);
        if (!currentToDir.cdUp()) {
          ERROR_MSG("Failed to cd up a directory for the to directory", 1);
          requestCancel();
          return;
        }
        if (!currentFromDir.cdUp()) {
          ERROR_MSG("Failed to cd up a directory for the from directory", 1);
          requestCancel();
          return;
        }
      }
    }
    else
    {
      DEBUG_MSG(QString("Skipping Dir: %1").arg(info.canonicalFilePath()), 2);
    }
  }
  // Now handle files
  list = currentFromDir.entryInfoList(QDir::Files | QDir::NoSymLinks | QDir::Hidden | QDir::Readable);
  foreach (info, list) {
    if (isCancelRequested()) {
      return;
    }
    QString fullPathFileToRead = info.canonicalFilePath();
    //TRACE_MSG(QString("Found File to test %1").arg(fullPathFileToRead), 2);
    if (passes(info))
    {
      //TRACE_MSG(QString("File passes %1").arg(fullPathFileToRead), 2);
      QFile fileToRead(fullPathFileToRead);
      // Just in case someone deleted the file.
      if (fileToRead.exists())
      {
        DBFileEntry* currentEntry = new DBFileEntry(info, m_fromDirWithoutTopDirName);
        const DBFileEntry* linkEntry = m_oldEntries->findEntry(m_backupSet.getCriteria(), currentEntry, m_fromDirWithoutTopDirName);

        QString pathToLinkFile = m_previousDirRoot;

        // If not in the old backup, search the current backup.
        if (linkEntry == nullptr)
        {
          linkEntry = m_currentEntries->findEntry(m_backupSet.getCriteria(), currentEntry, m_fromDirWithoutTopDirName);
          pathToLinkFile = m_toDirRoot;
        }

        if (linkEntry == nullptr)
        {
          bool failedToCopy = false;
          QString fullFileNameToWrite = m_toDirRoot + "/" + currentEntry->getPath();
          bool needHash = (currentEntry->getHash().length() == 0);
          if (needHash)
          {
            failedToCopy = !::getCopyLinkUtil().copyFileGenerateHash(fullPathFileToRead, fullFileNameToWrite);
            if (!failedToCopy)
            {
              currentEntry->setHash(getCopyLinkUtil().getLastHash());
            }
          }
          else if (!getCopyLinkUtil().copyFile(fullPathFileToRead, fullFileNameToWrite))
          {
            failedToCopy = true;
          }

          if (failedToCopy)
          {
            ERROR_MSG(QString(tr("EC %1")).arg(currentEntry->getPath()), 1);
          }
          else
          {
            INFO_MSG(QString(tr("C  %1")).arg(currentEntry->getPath()), 1);
            currentEntry->setLinkTypeCopy();
            m_currentEntries->addEntry(currentEntry);
            currentEntry = nullptr;
          }
        }
        else
        {
          if (getCopyLinkUtil().linkFile(pathToLinkFile + "/" + linkEntry->getPath(), m_toDirRoot + "/" + currentEntry->getPath()))
          {
            currentEntry->setLinkTypeLink();
            currentEntry->setHash(linkEntry->getHash());
            m_currentEntries->addEntry(currentEntry);
            INFO_MSG(QString(tr("L %1")).arg(currentEntry->getPath()), 1);
            currentEntry = nullptr;
          }
          else
          {
            ERROR_MSG(QString(tr("EL %1")).arg(currentEntry->getPath()), 1);
            ERROR_MSG(QString(tr("(%1)(%2)(%3)")).arg(pathToLinkFile, linkEntry->getPath(), m_toDirRoot), 1);
          }
        }
        if (currentEntry != nullptr)
        {
          delete currentEntry;
          currentEntry= nullptr;
        }
      }
    }
  }
  TRACE_MSG(QString("Finished with directory %1").arg(currentFromDir.canonicalPath()), 1);
}
예제 #20
0
파일: dt.c 프로젝트: rondilley/difftree
int main(int argc, char *argv[]) {
  PRIVATE int pid = 0;
  PRIVATE int c = 0, i = 0, fds = 0, status = 0;
  int digit_optind = 0;
  PRIVATE struct passwd *pwd_ent;
  PRIVATE struct group *grp_ent;
  PRIVATE char **ptr;
  char *tmp_ptr = NULL;
  char *pid_file = NULL;
  char *user = NULL;
  char *group = NULL;
#ifdef LINUX
  struct rlimit rlim;

  getrlimit( RLIMIT_CORE, &rlim );
#ifdef DEBUG
  rlim.rlim_cur = rlim.rlim_max;
  printf( "DEBUG - RLIMIT_CORE: %ld\n", rlim.rlim_cur );
#else
  rlim.rlim_cur = 0; 
#endif
  setrlimit( RLIMIT_CORE, &rlim );
#endif

  /* setup config */
  config = ( Config_t * )XMALLOC( sizeof( Config_t ) );
  XMEMSET( config, 0, sizeof( Config_t ) );

  /* get real uid and gid, we may want to drop privs */
  config->gid = getgid();
  config->uid = getuid();

  while (1) {
    int this_option_optind = optind ? optind : 1;
#ifdef HAVE_GETOPT_LONG
    int option_index = 0;
    static struct option long_options[] = {
      {"atime", no_argument, 0, 'a' },
      {"debug", required_argument, 0, 'd' },
      {"exdir", required_argument, 0, 'e' },
      {"exfile", required_argument, 0, 'E' },
      {"help", no_argument, 0, 'h' },
      {"md5", no_argument, 0, 'm' },
      {"preserve", no_argument, 0, 'p' },
      {"quick", no_argument, 0, 'q' },
      {"sha256", no_argument, 0, 's' },
      {"version", no_argument, 0, 'v' },
      {"write", required_argument, 0, 'w' },
      {0, no_argument, 0, 0}
    };
    c = getopt_long(argc, argv, "ad:e:E:hmpqsvw:", long_options, &option_index);
#else
    c = getopt( argc, argv, "ad:e:E:hmpqsvw:" );
#endif

    if (c EQ -1)
      break;

    switch (c) {
      case 'a':
      /* enable atime change reporting */
      config->show_atime = TRUE;
      
    case 'p':
      if ( config->uid != 0 ) {
        fprintf( stderr, "ERR - Insufficient priviledges to preserve ATIME, aborting\n" );
        print_help();
        return( EXIT_FAILURE );
      }
      config->preserve_atime = TRUE;
      
      break;
        
      
    case 'd':
      /* show debig info */
      config->debug = atoi( optarg );
      config->mode = MODE_INTERACTIVE;
      break;

    case 'e':
      /* exclude a specific directory from the diff */
      if ( ( config->exclusions = (char **)XMALLOC( sizeof( char * ) * 2 ) ) EQ NULL ) {
        fprintf( stderr, "ERR - Unable to allocate memory for exclusion list\n" );
        return( EXIT_FAILURE );
      }
      if ( ( config->exclusions[0] = XMALLOC( MAXPATHLEN + 1 ) ) EQ NULL ) {
        fprintf( stderr, "ERR - Unable to allocate memory for exclusion list\n" );
        XFREE( config->exclusions );
        return( EXIT_FAILURE );
      }
      if ( optarg[0] != '/' ) {
        config->exclusions[0][0] = '/';
        XSTRNCPY( config->exclusions[0]+1, optarg, MAXPATHLEN - 1 );
      } else
        XSTRNCPY( config->exclusions[0], optarg, MAXPATHLEN );
      config->exclusions[1] = 0;
      break;
        
    case 'E':
      /* exclude a list of directories in the specific file */
      //if ( loadExclusions( optarg ) != TRUE )
      //  return( EXIT_FAILURE );
      //break;
      fprintf( stderr, "ERR - Feature not currently supported\n" );
      print_help();
      return( EXIT_SUCCESS );
      
    case 'h':
      /* show help info */
      print_help();
      return( EXIT_SUCCESS );

    case 'm':
      /* md5 hash files */
      config->hash = TRUE;
      config->md5_hash = TRUE;
      config->digest_size = 16;
      config->sha256_hash = FALSE;
      break;

    case 'q':
      /* do quick checks only */
      config->quick = TRUE;
      break;
      
    case 's':
      /* sha256 hash files */
      config->hash = TRUE;
      config->sha256_hash = TRUE;
      config->digest_size = 32;
      config->md5_hash = FALSE;
      break;

    case 'v':
      /* show the version */
      print_version();
      return( EXIT_SUCCESS );


    case 'w':
      /* define the dir to store logs in */
      if ( ( config->outfile = ( char * )XMALLOC( MAXPATHLEN + 1 ) ) EQ NULL ) {
        /* XXX problem */
      }
      XMEMSET( config->outfile, 0, MAXPATHLEN + 1 );
      XSTRNCPY( config->outfile, optarg, MAXPATHLEN );
      break;
      
    default:
      fprintf( stderr, "Unknown option code [0%o]\n", c);
    }
  }

  /* turn off quick mode if hash mode is enabled */
  if ( config->hash )
    config->quick = FALSE;

  /* check dirs and files for danger */

  if ( time( &config->current_time ) EQ -1 ) {
    fprintf( stderr, "ERR - Unable to get current time\n" );
    
    /* cleanup buffers */
    cleanup();
    return EXIT_FAILURE;
  }

  /* initialize program wide config options */
  config->hostname = (char *)XMALLOC( MAXHOSTNAMELEN+1 );

  /* get processor hostname */
  if ( gethostname( config->hostname, MAXHOSTNAMELEN ) != 0 ) {
    fprintf( stderr, "Unable to get hostname\n" );
    strncpy( config->hostname, "unknown", MAXHOSTNAMELEN );
  }

  /* setup gracefull shutdown */
  signal( SIGINT, sigint_handler );
  signal( SIGTERM, sigterm_handler );
  signal( SIGFPE, sigfpe_handler );
  signal( SIGILL, sigill_handler );
  signal( SIGSEGV, sigsegv_handler );
#ifndef MINGW
  signal( SIGHUP, sighup_handler );
  signal( SIGBUS, sigbus_handler );
#endif  

  /****
   *
   * lets get this party started
   *
   ****/

  show_info();
  if ( ( baseDir = (char *)XMALLOC( PATH_MAX ) ) EQ NULL ) {
    fprintf( stderr, "ERR - Unable to allocate memory for baseDir string\n" );
    cleanup();
    return( EXIT_FAILURE );
  }
  if ( ( compDir = (char *)XMALLOC( PATH_MAX ) ) EQ NULL ) {
    fprintf( stderr, "ERR - Unable to allocate memory for compDir string\n" );
    cleanup();
    return( EXIT_FAILURE );
  }

  compDirHash = initHash( 52 );

  while (optind < argc ) {
    if ( ( compDirLen = strlen( argv[optind] ) ) >= PATH_MAX ) {
      fprintf( stderr, "ERR - Argument too long\n" );
      if ( baseDirHash != NULL )
	freeHash( baseDirHash );
      freeHash( compDirHash );
      cleanup();
      return( EXIT_FAILURE );
    } else {
      strncpy( compDir, argv[optind++], PATH_MAX-1 );
      /* process directory tree */
      if ( processDir( compDir ) EQ FAILED ) {
	if ( baseDirHash != NULL  )
	  freeHash( baseDirHash );
        freeHash( compDirHash );
	cleanup();
	return( EXIT_FAILURE );
      }

      if ( baseDirHash != NULL ) {
	/* compare the old tree to the new tree to find missing files */
	if ( traverseHash( baseDirHash, findMissingFiles ) != TRUE ) {
	  freeHash( baseDirHash );
	  freeHash( compDirHash );
	  cleanup();
	  return( EXIT_FAILURE );
	}
      }

      /* Prep for next dir to compare */
      if ( baseDirHash != NULL )
	freeHash( baseDirHash );
      baseDirHash = compDirHash;
      compDirHash = initHash( getHashSize( baseDirHash ) );
      baseDirLen = compDirLen;
      strncpy( baseDir, compDir, compDirLen );
    }
  }

  if ( baseDirHash != NULL )
    freeHash( baseDirHash );
  if ( compDirHash != NULL )
    freeHash( compDirHash );

  /****
   *
   * we are done
   *
   ****/

  cleanup();

  return( EXIT_SUCCESS );
}
예제 #21
0
파일: utils.cpp 프로젝트: Daniel1892/tora
	void processDir(const char * directory, int fd)
	{
		struct stat sb;
		char buf[2048];
		struct dirent   * dirfil;

		if ( fd != -1)
			fstat( fd, &sb);
		if( isDirectory(directory, sb))
		{
#if defined __linux || defined __CYGWIN__
			DIR *Hdir = fdopendir(fd);
#else
			DIR *Hdir = opendir(directory);
#endif
			do
			{
				int fds;
				struct stat sbs;
				// We successfully opened a directory, we iterate all
				// subdirectories and find all files within all directories
				//
				dirfil	= readdir(Hdir);

				if	( dirfil != NULL	// Out of entries in this directory
					  && dirfil->d_name[0] != '.' // Current or prior directory, or hidden file
					)
				{
					int buflen;

					// We found a new entry in this directory, we need to know
					// if it is a sub directory of course.
					//
					buflen = sprintf( (char *)buf, "%s%c%s", directory, DIRDELIM, dirfil->d_name);
					fds = open( buf, O_RDONLY);
					fstat( fds, &sbs);
					
					if (buf, isDirectory(buf, sbs))
					{
						// This was a directory too, close the reference here, and call
						// ourselves recursively, to process this subdirectory
						//
						processDir(buf, fds);
						printf(" %s\n", buf);
					}
					else
					{
						printf("  - %s\n", dirfil->d_name); fflush(stdout);
						//printf(" S"); fflush(stdout);
						parseFile(buf, fds);
						// putc('E', stdout); fflush(stdout);
						
					}
					close(fds);
				}				
			} while (dirfil != NULL);
			closedir(Hdir);
		} else {
			printf("  - %s\n", directory); fflush(stdout);			
			parseFile(directory, fd);
		}
	}
예제 #22
0
/* Main - create the threads and start the processing */
int main(int argc, char *argv[]) {

    /* Check for argument count */
    if (argc != 2) {
        std::cerr << "Invalid number of arguments." << std::endl;
        return -1;
    }

    /* Read the path to the data */
    std::string path(argv[1]);

    /* Read the list of directories to process */
    std::string image_list_filename = path + "image_list.dat";
    std::vector<std::string> input_images;
    FILE *file = fopen(image_list_filename.c_str(), "r");
    if (!file) {
        std::cerr << "Could not open 'image_list.dat' inside '" << path << "'." << std::endl;
        return -1;
    }
    char line[128];
    while (fgets(line, sizeof(line), file) != NULL) {
        line[strlen(line)-1] = 0;
        std::string temp_str(line);
        if (temp_str.find("dapi") == std::string::npos) continue;
        input_images.push_back(temp_str);
    }
    fclose(file);

    /* Create the scatterplot Control and SZ file */
    // Create the plots directory
    std::string plots_directory = path + PLOTS_DIR_NAME;
    struct stat st = {0};
    if (stat(plots_directory.c_str(), &st) == -1) {
        mkdir(plots_directory.c_str(), 0700);
    }

    std::ofstream scatterplot_stream;

    // Control
    std::string scatter_control_file = plots_directory + SCATTERPLOT_CONTROL;
    scatterplot_stream.open(scatter_control_file, std::ios::out);
    if (!scatterplot_stream.is_open()) {
        std::cerr << "Could not create the scatter plot Control file." << std::endl;
        return -1;
    }
    scatterplot_stream.close();

    // SZ
    std::string scatter_sz_file = plots_directory + SCATTERPLOT_SZ;
    scatterplot_stream.open(scatter_sz_file, std::ios::out);
    if (!scatterplot_stream.is_open()) {
        std::cerr << "Could not create the scatter plot SZ file." << std::endl;
        return -1;
    }
    scatterplot_stream.close();

    /* Create and prepare the file for metrics */
    std::string metrics_file_name = path.substr(path.find_first_of("/")+1);
    std::size_t found = metrics_file_name.find_first_of("/");
    assert(found != std::string::npos);
    metrics_file_name[found] = '_';
    found = metrics_file_name.find_first_of(" ");
    while (found != std::string::npos) {
        metrics_file_name[found] = '_';
        found = metrics_file_name.find_first_of(" ", found+1);
    }
    std::string metrics_file = path + "metrics_" + metrics_file_name + ".csv";
    std::ofstream data_stream;
    data_stream.open(metrics_file, std::ios::out);
    if (!data_stream.is_open()) {
        std::cerr << "Could not create the metrics file." << std::endl;
        return -1;
    }

    data_stream << "Merged Image,";
    data_stream << "DAPI-GFP Cell Count,";
    data_stream << "DAPI-GFP Soma Diameter (mean),";
    data_stream << "DAPI-GFP Soma Diameter (std. dev.),";
    data_stream << "DAPI-GFP Soma Aspect Ratio (mean),";
    data_stream << "DAPI-GFP Soma Aspect Ratio (std. dev.),";
    data_stream << "DAPI-GFP Soma Error Ratio (mean),";
    data_stream << "DAPI-GFP Soma Error Ratio (std. dev.),";
    data_stream << "DAPI-RFP Cell Count,";
    data_stream << "DAPI-RFP Soma Diameter (mean),";
    data_stream << "DAPI-RFP Soma Diameter (std. dev.),";
    data_stream << "DAPI-RFP Soma Aspect Ratio (mean),";
    data_stream << "DAPI-RFP Soma Aspect Ratio (std. dev.),";
    data_stream << "DAPI-RFP Soma Error Ratio (mean),";
    data_stream << "DAPI-RFP Soma Error Ratio (std. dev.),";

    // GFP (low, medium and high) bins
    data_stream << "GFP_Low_Contour_Count,";
    for (unsigned int i = 0; i < NUM_AREA_BINS-1; i++) {
        data_stream << i*BIN_AREA << " <= GFP_Low_Contour_Area < " << (i+1)*BIN_AREA << ",";
    }
    data_stream << "GFP_Low_Contour_Area >= " << (NUM_AREA_BINS-1)*BIN_AREA << ",";

    data_stream << "GFP_Medium_Contour_Count,";
    for (unsigned int i = 0; i < NUM_AREA_BINS-1; i++) {
        data_stream << i*BIN_AREA << " <= GFP_Medium_Contour_Area < " << (i+1)*BIN_AREA << ",";
    }
    data_stream << "GFP_Medium_Contour_Area >= " << (NUM_AREA_BINS-1)*BIN_AREA << ",";

    data_stream << "GFP_High_Contour_Count,";
    for (unsigned int i = 0; i < NUM_AREA_BINS-1; i++) {
        data_stream << i*BIN_AREA << " <= GFP_High_Contour_Area < " << (i+1)*BIN_AREA << ",";
    }
    data_stream << "GFP_High_Contour_Area >= " << (NUM_AREA_BINS-1)*BIN_AREA << ",";


    data_stream << std::endl;
    data_stream.close();

    /* Process each image */
    for (unsigned int index = 0; index < input_images.size(); index++) {
        std::cout << "Processing " << input_images[index] << std::endl;
        if (!processDir(path, input_images[index], metrics_file)) {
            std::cout << "ERROR !!!" << std::endl;
            return -1;
        }
    }

    /* Generate the scatter plot */
    std::cout << "Calculating the scatter plot statistics." << std::endl;
    scatterPlotStat(plots_directory);

    return 0;
}
예제 #23
0
파일: main.cpp 프로젝트: guptask/ngn2_cchmc
/* Main - create the threads and start the processing */
int main(int argc, char *argv[]) {

    /* Check for argument count */
    if (argc != 2) {
        std::cerr << "Invalid number of arguments." << std::endl;
        return -1;
    }

    /* Read the path to the data */
    std::string path(argv[1]);

    /* Read the list of directories to process */
    std::string image_list_filename = path + "image_list.dat";
    std::vector<std::string> input_images;
    FILE *file = fopen(image_list_filename.c_str(), "r");
    if (!file) {
        std::cerr << "Could not open 'image_list.dat' inside '" << path << "'." << std::endl;
        return -1;
    }
    char line[128];
    while (fgets(line, sizeof(line), file) != NULL) {
        line[strlen(line)-1] = 0;
        std::string temp_str(line);
        input_images.push_back(temp_str);
    }
    fclose(file);

    /* Create and prepare the file for metrics */
    std::string metrics_file = path + "computed_metrics.csv";
    std::ofstream data_stream;
    data_stream.open(metrics_file, std::ios::out);
    if (!data_stream.is_open()) {
        std::cerr << "Could not create the metrics file." << std::endl;
        return -1;
    }
    data_stream << "CZI Image,";
    data_stream << "Z-index start,";
    data_stream << "Z-index end,";

    data_stream << "Total Cell Count,";

    data_stream << "Neural Cell Count,";
    data_stream << "Neural Nuclei Diameter (mean),";
    data_stream << "Neural Nuclei Diameter (std. dev.),";
    data_stream << "Neural Nuclei Aspect Ratio (mean),";
    data_stream << "Neural Nuclei Aspect Ratio (std. dev.),";
    data_stream << "Neural Nuclei Error Ratio (mean),";
    data_stream << "Neural Nuclei Error Ratio (std. dev.),";

    data_stream << "Neural Soma Diameter (mean),";
    data_stream << "Neural Soma Diameter (std. dev.),";
    data_stream << "Neural Soma Aspect Ratio (mean),";
    data_stream << "Neural Soma Aspect Ratio (std. dev.),";
    data_stream << "Neural Soma Error Ratio (mean),";
    data_stream << "Neural Soma Error Ratio (std. dev.),";

    data_stream << "Astrocyte Count,";
    data_stream << "Astrocyte Diameter (mean),";
    data_stream << "Astrocyte Diameter (std. dev.),";
    data_stream << "Astrocyte Aspect Ratio (mean),";
    data_stream << "Astrocyte Aspect Ratio (std. dev.),";
    data_stream << "Astrocyte Error Ratio (mean),";
    data_stream << "Astrocyte Error Ratio (std. dev.),";

    // Synapse bins
    data_stream << "Synapse Contour Count,";
    for (unsigned int i = 0; i < NUM_AREA_BINS-1; i++) {
        data_stream << i*BIN_AREA << " <= Synapse Contour Area < " << (i+1)*BIN_AREA << ",";
    }
    data_stream << "Synapse Contour Area >= " << (NUM_AREA_BINS-1)*BIN_AREA << ",";

    data_stream << std::endl;
    data_stream.close();

    /* Process each image */
    for (unsigned int index = 0; index < input_images.size(); index++) {
        std::cout << "Processing " << input_images[index] << std::endl;
        if (!processDir(path, input_images[index], metrics_file)) {
            std::cout << "ERROR !!!" << std::endl;
            return -1;
        }
    }

    return 0;
}