Example #1
0
/*
 * processFileList - process a possible file list
 */
static void processFileList( const char *ptr )
{
    DIR                 *dirp;
    struct dirent       *dirent;
    const char          *tmp;
    bool                has_wild = false;
    char                buff1[_MAX_PATH2];
    char                buff2[_MAX_PATH2];
    char                *drive;
    char                *dir;
    char                *fname;
    char                *ext;
    char                path[_MAX_PATH];

    tmp = ptr;
    while( *tmp != '\0' ) {
        if( *tmp == '*' || *tmp == '?' ) {
            has_wild = true;
            break;
        }
        tmp++;
    }

    if( !has_wild ) {
        processFile( ptr );
        return;
    }

    _splitpath2( ptr, buff1, &drive, &dir, &fname, &ext );
    dirp = opendir( ptr );
    if( dirp == NULL ) {
        return;
    }
    while( (dirent = readdir( dirp )) != NULL ) {

#ifdef __UNIX__
        {
            struct stat buf;
            stat( dirent->d_name, &buf );
            if ( S_ISDIR( buf.st_mode ) )
                continue;
        }
#else
        if( dirent->d_attr & (_A_SUBDIR | _A_VOLID) ) {
            continue;
        }
#endif

        _splitpath2( dirent->d_name, buff2, NULL, NULL, &fname, &ext );
        _makepath( path, drive, dir, fname, ext );
        strlwr( path );
        processFile( path );
    }
    closedir( dirp );

} /* processFileList */
Example #2
0
int
main(int argc, char *argv[])
{
	int i;
	int opt;

	while(1) {
		opt = getopt_long(argc, argv, "DvVTBtPs", long_options, NULL);
		if(opt == -1)
			break;
		switch(opt) {
		case 'v':
			verbose = 1;
			break;
		case 's':
			rsgt_read_showVerified = 1;
			break;
		case 'V':
			fprintf(stderr, "rsgtutil " VERSION "\n");
			exit(0);
		case 'D':
			mode = MD_DUMP;
			break;
		case 'B':
			mode = MD_SHOW_SIGBLK_PARAMS;
			break;
		case 'P':
			rsgt_read_puburl = optarg;
			break;
		case 'T':
			mode = MD_DETECT_FILE_TYPE;
			break;
		case 't':
			mode = MD_VERIFY;
			break;
		case 'e':
			mode = MD_EXTEND;
			break;
		case '?':
			break;
		default:fprintf(stderr, "getopt_long() returns unknown value %d\n", opt);
			return 1;
		}
	}

	if(optind == argc)
		processFile("-");
	else {
		for(i = optind ; i < argc ; ++i)
			processFile(argv[i]);
	}

	return 0;
}
Example #3
0
void TableGenerator::findComposeFile()
{
    bool found = false;
    // check if XCOMPOSEFILE points to a Compose file
    if (qEnvironmentVariableIsSet("XCOMPOSEFILE")) {
        QString composeFile(qgetenv("XCOMPOSEFILE"));
        if (composeFile.endsWith(QLatin1String("Compose")))
            found = processFile(composeFile);
        else
            qWarning("Qt Warning: XCOMPOSEFILE doesn't point to a valid Compose file");
#ifdef DEBUG_GENERATOR
        if (found)
            qDebug() << "Using Compose file from: " << composeFile;
#endif
    }
    // check if user’s home directory has a file named .XCompose
    if (!found && cleanState()) {
        QString composeFile = qgetenv("HOME") + QStringLiteral("/.XCompose");
        if (QFile(composeFile).exists())
            found = processFile(composeFile);
#ifdef DEBUG_GENERATOR
        if (found)
            qDebug() << "Using Compose file from: " << composeFile;
#endif
    }
    // check for the system provided compose files
    if (!found && cleanState()) {
        QString table = composeTableForLocale();
        if (cleanState()) {
            if (table.isEmpty())
                // no table mappings for the system's locale in the compose.dir
                m_state = UnsupportedLocale;
            else
                found = processFile(systemComposeDir() + QLatin1Char('/') + table);
#ifdef DEBUG_GENERATOR
            if (found)
                qDebug() << "Using Compose file from: " <<
                            systemComposeDir() + QLatin1Char('/') + table;
#endif
        }
    }

    if (found && m_composeTable.isEmpty())
        m_state = EmptyTable;

    if (!found)
        m_state = MissingComposeFile;
}
Example #4
0
int main(int argc, char** argv) {
   checkOptions(options, argc, argv);
   HumdrumStream streamer(options);
   HumdrumFile infile;

   if (summaryQ) {
      Summary.setSize(1000);
      Summary.setAll(0);
   }

   while (streamer.read(infile)) {
      if (!streamer.eof()) {
         // if there are multiple segments, store a segement marker
         // for each segment.  Do not store if only a single segment,
         // unless --segement option is given.
         SEGMENTS = 1;
      }
      processFile(infile, infile.getFileName());
   }

   if (summaryQ) {
      printSummary(Summary);
   }
  
   return 0;
}
Example #5
0
void MakePageLib::traversDirectoryWithRecursion(const std::string &path)
{
    DIR *dir = opendir(path.c_str());
    if(dir == NULL)
    {
        LOG_FATAL << "open dir error:" << path;  
    }
    chdir(path.c_str()); //更改工作目录

    struct dirent *pd;
    while((pd = readdir(dir)) != NULL)
    {
        if(pd->d_name[0] == '.') // . ..
            continue;

        //int lstat(const char *path, struct stat *buf);
        struct stat buf;
        if(lstat(pd->d_name, &buf) == -1)
        {
            LOG_ERROR << "lstat file :" << pd->d_name << " error";
            continue;
        }

        if(S_ISDIR(buf.st_mode))
            traversDirectoryWithRecursion(pd->d_name);
        else if(S_ISREG(buf.st_mode))
            processFile(pd->d_name);

    }

    closedir(dir);
    chdir(".."); //退出到上一层
}
Example #6
0
void MagicFolderCache::startElement(XML_CSTR name, const XMLAttributes& atts)
{
	if( IN_STATE( PS_FOLDER ) )
	{
		if( MATCH("MagicFolder") )
		{
			_depth++;
			
			// Push this folder path onto the path stack...
			_pathStack = newStringStackItem(_pathStack, atts.getValue(_T("name")));
			
			// Store a folder object which will hold configuration etc.
			_current = new Folder(_pathStack->val.c_str(), _T(""));
			_map->insert(MagicFolderCache::FolderMap::value_type(_pathStack->val, _current));
		}
		else if( MATCH("File") )
		{
			STATE(PS_FILE);
			processFile(atts);
		}
		else
		{
			processUserData(name, atts);
		}
	}
	else if( IN_STATE( PS_FILE ) || IN_STATE( PS_USERDATA ) )
	{
		processUserData(name, atts);
	}
}
/**
	Parses the file with the given name and adds it to the database.
	@param path: path to the file to process
	@param name: name of the file to process
	@param parseBody: boolean value stating whether the body must be parsed or not
*/
void DatasetGenerator::parseFile(const string &filePath, const string &fileName, bool parseBody)
{
	aParseBody=parseBody;
	DB.connect();
	processFile(filePath, fileName);
	DB.close();
}
Example #8
0
static void processChunk(Regex* re, SearchOutput* output, unsigned int chunkIndex, const char* data, size_t fileCount, Regex* includeRe, Regex* excludeRe)
{
	const DataChunkFileHeader* files = reinterpret_cast<const DataChunkFileHeader*>(data);

	OrderedOutput::Chunk* chunk = output->output.begin(chunkIndex);

	if (!output->isLimitReached())
	{
		HighlightBuffer hlbuf;

		for (size_t i = 0; i < fileCount; ++i)
		{
			const DataChunkFileHeader& f = files[i];

			if (includeRe && !includeRe->search(data + f.nameOffset, f.nameLength))
				continue;

			if (excludeRe && excludeRe->search(data + f.nameOffset, f.nameLength))
				continue;
			
			processFile(re, output, chunk, hlbuf, data + f.nameOffset, f.nameLength, data + f.dataOffset, f.dataSize, f.startLine);
		}
	}

	output->output.end(chunk);
}
bool CMailViewTpl::SaveToFile( LPCSTR fileName )
{
  FarFile f;
  if ( !f.CreateForWrite( fileName ) )
    return false;

  class CWriteSink : public IWriteSink
  {
  private:
    FarFile * f;
  public:
    CWriteSink( FarFile * ff ) : f( ff )
    {
    }
    virtual ~CWriteSink()
    {
    }
    virtual void write( LPCSTR str, int len )
    {
      f->Write( str, len );
    }
  };

  CWriteSink ws( &f );
  processFile( m_fileName, &ws );

  f.Close();

  return true;
}
Example #10
0
void processFileArgument(char* name) {
    if (!table.lookup(name)) {
        fprintf(stderr, "File %s is not present in baseline.\n", name);
        return;
    }

    File localfile(name);
    if (localfile.exists()) {
        processFile(name);
    } else {
        if (forced_revision()) {
            File tempfile("forced_mergefile.tmp");
            File rcsfile(dirs.baseline, dirs.subdir->path, "RCS",
                         localfile.path);
            char line[LINE_LENGTH];
            char* version = forced_revision_number ? forced_revision_number :
                            rcsfile.getRevisionFromDate(forced_revision_date);
            sprintf(line, "co -q -p%s %s,v > %s",
                    version, rcsfile.path, tempfile.path);
            if (execute(line)) {
                tempfile.un_link();
                exit(-1);
            }
            localfile.become(tempfile, save);
            tempfile.un_link();
        } else {
            File basefile(dirs.baseline, dirs.subdir->path, localfile.path);
            localfile.become(basefile, save);
        }
    }
}
Example #11
0
unsigned int CppCheck::check(const std::string &path, const std::string &content)
{
    _fileContent = content;
	const unsigned int retval = processFile(path,true); // 
    _fileContent.clear();
    return retval;
}
Example #12
0
bool StorageDistributedDirectoryMonitor::findFiles()
{
	std::map<UInt64, std::string> files;

	Poco::DirectoryIterator end;
	for (Poco::DirectoryIterator it{path}; it != end; ++it)
	{
		const auto & file_path_str = it->path();
		Poco::Path file_path{file_path_str};

		if (!it->isDirectory() && startsWith(file_path.getExtension().data(), "bin"))
			files[parse<UInt64>(file_path.getBaseName())] = file_path_str;
	}

	if (files.empty())
		return false;

	for (const auto & file : files)
	{
		if (quit)
			return true;

		processFile(file.second);
	}

	return true;
}
void CollectionScanner::scanDirectory(QDir directory) {

    QStack<QDir> stack;
    stack.push(directory);
    while(!stack.empty()) {

        const QDir dir = stack.pop();
        const QFileInfoList flist = dir.entryInfoList(
                    QDir::NoDotAndDotDot |
                    QDir::Dirs | QDir::Files | QDir::Readable
                    );

        QFileInfo fileInfo;
        Q_FOREACH(fileInfo, flist) {
            if(fileInfo.isFile() ) {
                processFile(fileInfo);
            } else if (fileInfo.isDir()) {
                QString subDirPath = fileInfo.absoluteFilePath();
#ifdef APP_MAC
                if (directoryBlacklist.contains(subDirPath)) {
                    qDebug() << "Skipping directory" << subDirPath;
                    continue;
                }
#endif
                QDir subDir(subDirPath);
                stack.push(subDir);
            }
        }
    }

}
Example #14
0
AREXPORT void ArDataLogger::addString(
	const char *name, ArTypes::UByte2 maxLength,
	ArFunctor2<char *, ArTypes::UByte2> *functor)
{
  ArTypes::UByte2 len;

  myMutex.lock();
  if (maxLength < strlen(name))
    len = strlen(name);
  else
    len = maxLength;  
  if (myMaxMaxLength < len)
    myMaxMaxLength = len;

  myStrings.push_back(new ArStringInfoHolder(name, len, functor));
  bool *boolPtr;
  boolPtr = new bool;
  // if we've added to config we default to true
  if (myAddedToConfig)
    *boolPtr = true;
  else
    *boolPtr = false;
  myStringsEnabled.push_back(boolPtr);
  myStringsCount++;
  myMutex.unlock();
  if (myAddedToConfig)
    processFile(NULL, 0);
}
Example #15
0
/**
 *  \brief Process the contents of stdin.
 *  \result 0 if all OK.
 */
void showStdIn (void)
{
	/*------------------------------------------------------------------------*
     * First display a table with the file name and size.                     *
     *------------------------------------------------------------------------*/
	if (!displayColumnInit (1, ptrFileColumn, 0))
	{
		fprintf (stderr, "ERROR in: displayColumnInit\n");
		return;
	}
	if (!displayQuiet)
	{
		displayDrawLine (0);
		displayHeading (0);
		displayNewLine (0);
		displayInColumn (0, "stdin");
		displayNewLine (DISPLAY_INFO);
		displayAllLines ();
	}
	displayTidy ();

	if (!displayColumnInit (displayCols, ptrDumpColumn, displayFlags))
	{
		fprintf (stderr, "ERROR in: displayColumnInit\n");
		return;
	}

	if (!displayQuiet) displayDrawLine (0);
	if (!displayQuiet) displayHeading (0);

	processFile (stdin);
	++filesFound;
}
Example #16
0
void UploadOperation::startUpload()
{
    if (isTerminating()) {
        killOp();
        return ;
    } // terminate operation is needed

    // Current file info
    FileInfo *fileInfo = m_toCopy->getFileInfo();

    // Logging
    if (m_toCopy->getFirst()->getParent() == NULL) {
        StringStorage message;

        message.format(_T("Uploading '%s' %s"), m_pathToSourceFile.getString(),
                       fileInfo->isDirectory() ? _T("folder") : _T("file"));

        notifyInformation(message.getString());
    } // logging

    if (fileInfo->isDirectory()) {
        processFolder();
    } else {
        processFile();
    } // if not directory

    if (isTerminating()) {
        killOp();
        return ;
    } // terminate operation is needed
} // void
void* CDVToolReaderThread::Entry()
{
	// Wait here until we have the essentials to run
	while (!m_killed && (m_dongle == NULL || m_soundcard == NULL))
		Sleep(500UL);		// 1/2 sec

	if (m_killed)
		return NULL;

	m_dongle->Create();
	m_dongle->SetPriority(100U);
	m_dongle->Run();

	while (!m_killed) {
		if (m_reader != NULL)
			processFile();

		Sleep(500UL);		// 1/2 sec
	}

	m_soundcard->close();
	delete m_soundcard;

	m_dongle->kill();
	m_dongle->Wait();

	return NULL;
}
Example #18
0
int MainWindow::on_evalbutton_clicked()
{
    QString filex;

    if(ui->line->text() == "")
    {
        filex = QFileDialog::getOpenFileName(this, tr("Choose a file to open."), QString(), tr("RSBXL2 Files (*.rsbxl2)"));
        ui->line->setText(filex);
    }

    filex = ui->line->text();
    QMessageBox box;
    box.setText(tr("Error: File was not chosen."));
    box.setIcon(QMessageBox::Warning);
    int res = processFile(filex);

    if(res == -1)
    {
        box.exec();
    }
    else if(res == -2)
    {
        box.setText(tr("Error: Could not open file."));
        box.setIcon(QMessageBox::Critical);
        box.exec();
    }
    return 0;
}
Example #19
0
void DownloadOperation::startDownload()
{
  if (isTerminating()) {
    killOp();
    return ;
  } // if terminating

  FileInfo *fileInfo = m_toCopy->getFileInfo();

  // Logging
  if (m_toCopy->getFirst()->getParent() == NULL) {
    StringStorage message;

    message.format(_T("Downloading '%s' %s"), m_pathToTargetFile.getString(),
                   fileInfo->isDirectory() ? _T("folder") : _T("file"));

    notifyInformation(message.getString());
  } // logging

  if (fileInfo->isDirectory()) {
    processFolder();
  } else {
    processFile();
  } // if not directory

  if (isTerminating()) {
    killOp();
    return ;
  } // if terminating
}
void ProcessorThread::threadProc()
{
	while (!exit && !ctxt.error) {
		std::string fn = ctxt.queue.dequeue(dequeueTimeout);
		if (!fn.empty()) {
			busy = true;
			// TODO: Exception handling
			try {
				processFile(fn, ctxt);
			}
			catch (const Exceptions::Exception& ex) {
				ctxt.error = true;
				fprintf(stderr, "%s\n", ex.message.c_str());
			}
			catch (const std::exception& ex) {
				ctxt.error = true;
				fprintf(stderr, "Unexpected fatal error: %s\n", ex.what());
			}
			catch (...) {
				ctxt.error = true;
				fprintf(stderr, "Unexpected fatal error");
			}
			busy = false;
		}
	}
}
Example #21
0
int main(int argc, char *argv[])
{
   char *fn=NULL,*p=NULL,ch;
   FILE *in;
   
   if (argc!=2) {
      fprintf(stderr,"usage: %s filename\n",argv[0]);
      return 2;
   }
   
   fn=strdup(argv[1]);
   
   if ((p=strrchr(fn,'/'))) {
      ch=*(p+1);
      *(p+1)=0;
      path=strdup(fn);
      *(p+1)=ch;
   }
   else path="";
   
   in=fopen(fn,"r");
   
   if (in) processFile(strdup(fn),in,stdout);
   else {
      fprintf(stderr,"file %s not found\n",fn);
      err=1;
   }
   
   if (*path)  free(path);
   if (*fn) free(fn);
   return err;
}
Example #22
0
/*
 * This small program copies all of the source from files inside of the
 * src folder and puts them into one file that can then be loaded into
 * the html file to run SoBr.
 */
int main()
{
	extern FILE * output;
	extern FILE * files;

	char fileName[MAX_SIZE];

	system(FIND_COMMAND);
	files = fopen(FILES, "r");
	if(files == NULL)
		killAll("Error opening the list of files");
	output = fopen(OUTPUT_FILE, "w");
	if(output == NULL)
		killAll("Error creating the output file");
	// loop through all of the js files
	while(fgets(fileName, MAX_SIZE, files) != NULL)
	{
		// remove the '\n' from the fileName
		int i = strlen(fileName);
		fileName[i - 1] = '\0';

		processFile(fileName);
	}

	// close files
	fclose(files);
	fclose(output);

	printf("Done processing the files, output should now be in %s\n", OUTPUT_FILE);

	return 0;
}
int main(int argc, char * argv[])
{
	Args args;
	processArgs(argc, argv, args);
	processFile(args.inputFile);

	return 0;
}
Example #24
0
int
main(int argc, char *argv[])
{
	rsgtInit("rsyslog logsigner " VERSION);
	processFile("-");
	rsgtExit();
	return 0;
}
Example #25
0
int main(int argC,char* argV[])
{
	if(argC!=2)
		printf("Usage %s <score list file>");
	else
		processFile(argV[1]);
	return 0;
}
Example #26
0
//---------------------------------------------------------------------------
void MainWindow::on_actionImport_XmlGz_Prompt_triggered()
{
    QString FileName=QFileDialog::getOpenFileName(this, "Import from .qctools.xml.gz", "", "Statistic files (*.qctools.xml *.qctools.xml.gz *.xml.gz *.xml)", 0, QFileDialog::DontUseNativeDialog);
    if (FileName.size()==0)
        return;

    processFile(FileName);
}
Example #27
0
int main (int argc, char** argv) {
    
    if(argc != 2) {
        cout << "Usage: " << argv[0] << " INPUT_FILE" << endl;
    } else {
        string filename = argv[1];
        processFile(filename);
    }
    return 0;
}
Example #28
0
int main(int argc, char* argv[]) {
   HumdrumFileSet infiles;
   checkOptions(options, argc, argv);
   infiles.read(options);
   string filename;

   // for now only deal with a single segment:
   processFile(infiles[0]);
   return 0;
}
void FileSelector::setMainWindow(MainWindow * w) {
    mainWindow = w;

    QString q = "ImageExamples/main_image.bmp";
    QString q2 = "ImageExamples/TV244.jpg";

    addFile(q); addFile(q2);
    processFile(q);
    mainWindow->process_file(q);
}
Example #30
0
// Process a directory tree: for each jpg file, calculate the phash,
// and write the hash value and file string to the output file.
void processTree(const char *path, char *basepath, FILE *fp)
{
	std::list<std::string> folders;
	std::vector<std::string> files;

	char thispath[257];
	char apath[257];

	sprintf(thispath, "%s%s", basepath, path);
	struct dirent *dent;
	DIR *srcdir = opendir(thispath);
	if (srcdir == NULL)
		return;

	while ((dent = readdir(srcdir)) != NULL)
	{
		struct stat st;

		if (dent->d_name[0] == '.')
			continue;

		if (strlen(thispath) + strlen(dent->d_name) > 256)
		{
			printf("Path too long:%s", dent->d_name);
			continue;
		}

		sprintf(apath, "%s\\%s", thispath, dent->d_name);
		stat(apath, &st);

		if (st.st_mode & _S_IFDIR) // recurse into subdirectories
		{
			sprintf(apath, "%s\\%s", path, dent->d_name);
			folders.push_back(apath);
//			processTree(apath, basepath, fp);
		}
		else
		{
			files.push_back(apath);
//			processFile(apath, basepath, fp);
		}
	}
	closedir(srcdir);

	int max = files.size();
#pragma omp parallel for
	for (int dex = 0; dex < max; dex++)
	{
		processFile((char *)(files[dex].c_str()), basepath, fp);
	}
	for (std::list<std::string>::iterator it = folders.begin(); it != folders.end(); ++it)
	{
		processTree((*it).c_str(), basepath, fp);
	}
}