void PreprocessHandler::writeTargetFile(QString sourceFile, QString targetFile, QString currentDir) {

    QFileInfo sourceInfo(sourceFile);
    QDir::setCurrent(sourceInfo.absolutePath());

    std::string result;
    result.reserve(20 * 1024);  // 20K

    result += "# 1 \"builtins\"\n";
    result += "# 1 \"";
    result += toStdString(sourceFile);
    result += "\"\n";

    qDebug() << "Processing source" << sourceInfo.absolutePath() << sourceInfo.fileName();
    preprocess.file(toStdString(sourceInfo.fileName()),
                    rpp::pp_output_iterator<std::string> (result));

    QDir::setCurrent(currentDir);

    QFile f(targetFile);
    if (!f.open(QIODevice::Append | QIODevice::Text)) {
        std::fprintf(stderr, "Failed to write preprocessed file: %s\n", qPrintable(targetFile));
    }
    f.write(result.c_str(), result.length());
}
Beispiel #2
0
bool Project::index(const Path &sourceFile, const Path &cc, const List<String> &args)
{
    const Path compiler = resolveCompiler(cc.canonicalized());
    SourceInformation sourceInformation = sourceInfo(Location::insertFile(sourceFile));
    const bool js = args.isEmpty() && sourceFile.endsWith(".js");
    bool added = false;
    if (sourceInformation.isNull()) {
        sourceInformation.sourceFile = sourceFile;
    } else if (js) {
        debug() << sourceFile << " is not dirty. ignoring";
        return false;
    } else {
        List<SourceInformation::Build> &builds = sourceInformation.builds;
        const bool allowMultiple = Server::instance()->options().options & Server::AllowMultipleBuildsForSameCompiler;
        for (int j=0; j<builds.size(); ++j) {
            if (builds.at(j).compiler == compiler) {
                if (builds.at(j).args == args) {
                    debug() << sourceFile << " is not dirty. ignoring";
                    return false;
                } else if (!allowMultiple) {
                    builds[j].args = args;
                    added = true;
                    break;
                }
            }
        }
    }
    if (!added && !js)
        sourceInformation.builds.append(SourceInformation::Build(compiler, args));
    index(sourceInformation, IndexerJob::Makefile);
    return true;
}
Beispiel #3
0
void ZPunctaObjsModel::setupModelData(ZObjsItem *parent)
{
  QList<QVariant> data;

  m_punctaSourceToParent.clear();
  m_punctaSourceToCount.clear();
  m_punctaToRow.clear();
  m_punctaSourceParentToRow.clear();
  m_punctaSeparatedByFile.clear();
  int sourceParentRow = 0;
  int numDigit = numDigits(m_doc->punctaList()->size()+1);
  for (int i=0; i<m_doc->punctaList()->size(); i++) {
    data.clear();
    ZPunctum *p = m_doc->punctaList()->at(i);
    QFileInfo sourceInfo(p->source());
    if (m_punctaSourceToParent.find(p->source()) != m_punctaSourceToParent.end()) {
      ZObjsItem *sourceParent = m_punctaSourceToParent[p->source()];
      data << QString("puncta %1").arg(m_punctaSourceToCount[p->source()] + 1, numDigit, 10, QLatin1Char('0')) << p->score() << p->name() << p->comment() << p->x() << p->y() <<
              p->z() << p->sDevOfIntensity() << p->volSize() << p->mass() << p->radius() <<
              p->meanIntensity() << p->maxIntensity() << p->property1() << p->property2() <<
              p->property3() << p->color() << sourceInfo.fileName();
      m_punctaToRow[p] = m_punctaSourceToCount[p->source()];
      m_punctaSourceToCount[p->source()]++;
      ZObjsItem *punctum = new ZObjsItem(data, p, sourceParent);
      punctum->setCheckState(p->isVisible() ? Qt::Checked : Qt::Unchecked);
      punctum->setToolTip(QString("puncta from: %1").arg(p->source()));
      sourceParent->appendChild(punctum);
      m_punctaSeparatedByFile[m_punctaSourceParentToRow[sourceParent]].push_back(m_doc->punctaList()->at(i));
    } else {
      data << sourceInfo.fileName() << "score" << "name" << "comment" << "x" << "y" << "z" << "sDev" <<
              "volSize" << "mass" << "radius" << "meanIntensity" << "maxIntensity" <<
              "property1" << "property2" << "property3" << "color" << "source";
      m_punctaSeparatedByFile.push_back(std::vector<ZPunctum*>());
      ZObjsItem *sourceParent = new ZObjsItem(data, NULL, parent);
      sourceParent->setToolTip(QString("puncta source: %1").arg(p->source()));
      m_punctaSourceToParent[p->source()] = sourceParent;
      m_punctaSourceToCount[p->source()] = 0;
      parent->appendChild(sourceParent);
      m_punctaSourceParentToRow[sourceParent] = sourceParentRow++;

      data.clear();
      data << QString("puncta %1").arg(m_punctaSourceToCount[p->source()] + 1, numDigit, 10, QLatin1Char('0')) << p->score() << p->name() << p->comment() << p->x() << p->y() <<
              p->z() << p->sDevOfIntensity() << p->volSize() << p->mass() << p->radius() <<
              p->meanIntensity() << p->maxIntensity() << p->property1() << p->property2() <<
              p->property3() << p->color() << sourceInfo.fileName();
      m_punctaToRow[p] = m_punctaSourceToCount[p->source()];
      m_punctaSourceToCount[p->source()]++;
      ZObjsItem *punctum = new ZObjsItem(data, p, sourceParent);
      punctum->setCheckState(p->isVisible() ? Qt::Checked : Qt::Unchecked);
      punctum->setToolTip(QString("puncta from: %1").arg(p->source()));
      sourceParent->appendChild(punctum);
      m_punctaSeparatedByFile[m_punctaSourceParentToRow[sourceParent]].push_back(m_doc->punctaList()->at(i));
    }
  }
}
bool BaseClassWriter::needsGeneration(const QString &className)
{
    QFileInfo headerInfo(mTargetDir.absoluteFilePath(className + ".h"));
    QFileInfo sourceInfo(mTargetDir.absoluteFilePath(className + ".cpp"));
    bool noUpdateNeeded =
        headerInfo.exists() &&
        headerInfo.lastModified() > mParser.lastConfigUpdate();
    noUpdateNeeded &= sourceInfo.exists() &&
                      sourceInfo.lastModified() > mParser.lastConfigUpdate();
    return !noUpdateNeeded;
}
Beispiel #5
0
static bool preprocess(const QString &sourceFile, QByteArray *out)
{
    rpp::pp_environment env;
    rpp::pp preprocess(env);

    rpp::pp_null_output_iterator null_out;

    const char *ppconfig = ":/trolltech/generator/rpp/src/rpp/pp-qt-configuration";

    QFile configFile(ppconfig);
    if (!configFile.open(QFile::ReadOnly)) {
        fprintf(stderr, "Preprocessor configuration file not found '%s'\n", ppconfig);
        return false;
    }

    QByteArray ba = configFile.readAll();
    configFile.close();
    preprocess.operator() (ba.constData(), ba.constData() + ba.size(), null_out);

    QString qtdir = getenv ("QTDIR");
    if (qtdir.isEmpty()) {
        fprintf(stderr, "Generator requires QTDIR to be set\n");
        return false;
    }

    qtdir += "/include";

    QString currentDir = QDir::current().absolutePath();
    QFileInfo sourceInfo(sourceFile);
    QDir::setCurrent(sourceInfo.absolutePath());

    preprocess.push_include_path(".");
    preprocess.push_include_path(QDir::convertSeparators(qtdir).toStdString());
    preprocess.push_include_path(QDir::convertSeparators(qtdir + "/QtXml").toStdString());
    preprocess.push_include_path(QDir::convertSeparators(qtdir + "/QtNetwork").toStdString());
    preprocess.push_include_path(QDir::convertSeparators(qtdir + "/QtCore").toStdString());
    preprocess.push_include_path(QDir::convertSeparators(qtdir + "/QtGui").toStdString());
    preprocess.push_include_path(QDir::convertSeparators(qtdir + "/QtOpenGL").toStdString());

    std::string result;
    result.reserve (20 * 1024); // 20K

    result += "# 1 \"builtins\"\n";
    result += "# 1 \"";
    result += sourceFile.toStdString();
    result += "\"\n";

    preprocess.file (sourceInfo.fileName().toStdString(),
                     rpp::pp_output_iterator<std::string> (result));

    *out = QString::fromStdString(result).toUtf8();
    return true;
}
Beispiel #6
0
QString SyncProcess::updateEntry(const QString & path, const QDir & source, const QDir & destination)
{
  QFileInfo sourceInfo(path);
  QString relativePath = source.relativeFilePath(path);
  QString destinationPath = destination.absoluteFilePath(relativePath);
  QFileInfo destinationInfo(destinationPath);
  if (sourceInfo.isDir()) {
    if (!destinationInfo.exists()) {
      progress->addText(tr("Create directory %1\n").arg(destinationPath));
      if (!destination.mkdir(relativePath)) {
        return QObject::tr("Create '%1' failed").arg(destinationPath);
      }
    }
  }
  else {
    if (!destinationInfo.exists()) {
      // qDebug() << "Copy" << path << "to" << destinationPath;
      progress->addText(tr("Copy %1 to %2").arg(path).arg(destinationPath) + "\n");
      if (!QFile::copy(path, destinationPath)) {
        return QObject::tr("Copy '%1' to '%2' failed").arg(path).arg(destinationPath);
      }
    }
    else if (sourceInfo.lastModified() > destinationInfo.lastModified()) {
      // retrieve source contents
      QFile sourceFile(path);
      if (!sourceFile.open(QFile::ReadOnly)) {
        return QObject::tr("Open '%1' failed").arg(path);
      }
      QByteArray sourceContents = sourceFile.readAll();
      sourceFile.close();

      // retrieve destination contents
      QFile destinationFile(destinationPath);
      if (!destinationFile.open(QFile::ReadOnly)) {
        return QObject::tr("Open '%1' failed").arg(destinationPath);
      }
      QByteArray destinationContents = destinationFile.readAll();
      destinationFile.close();

      if (contentsDifferent(sourceContents, destinationContents)) {
        // copy contents
        if (!destinationFile.open(QFile::WriteOnly | QIODevice::Truncate)) {
          return QObject::tr("Write '%1' failed").arg(destinationPath);
        }
        progress->addText(tr("Write %1").arg(destinationPath) + "\n");
        // qDebug() << "Write" << destinationPath;
        destinationFile.write(sourceContents);
        destinationFile.close();
      }
    }
  }
  return QString();
}
Beispiel #7
0
bool Java::compile(const QString& filename, const QString& port)
{
	QFileInfo sourceInfo(filename);
	QStringList args;

	refreshSettings();

	m_outputFileName = sourceInfo.dir().absoluteFilePath(sourceInfo.baseName());
	QStringList files = QDir(m_outputFileName).entryList(QStringList() << "*.class");

	foreach(const QString& file, files) {
		QFile(m_outputFileName + "/" + file).remove();
	}
Beispiel #8
0
void OCamlSource::newBreakpoint ( )
{
    QFileInfo sourceInfo( curFile );
    QString module = sourceInfo.baseName();
    if (module.length() > 0)
    {
        module[0] = module[0].toUpper();
        QString command = QString("break @ %1 %2 %3")
            .arg(module)
            .arg( QString::number( _breakpoint_line ) )
            .arg( QString::number( _breakpoint_column ) )
            ;
        emit debugger( DebuggerCommand( command, DebuggerCommand::HIDE_DEBUGGER_OUTPUT ) );
    }
}
Beispiel #9
0
TEST(Tracking, NoTracking)
{
    std::array<char, 1024> mem;
    std::fill(std::begin(mem), std::end(mem), 5);

    // Test for noop
    mem::NoTracking tracker;
    mem::SourceInfo sourceInfo("test-file.h", 126);
    bool allFive;

    tracker.onAllocation(mem.data(), 1024, 4, sourceInfo);
    allFive = std::all_of(std::begin(mem), std::end(mem), [](char val){ return val == 5; });
    EXPECT_TRUE(allFive);

    tracker.onRelease(mem.data());
    allFive = std::all_of(std::begin(mem), std::end(mem), [](char val){ return val == 5; });
    EXPECT_TRUE(allFive);
}
Beispiel #10
0
bool Gcc::compile(QString filename)
{
	QFileInfo sourceInfo(filename);
	QStringList args;

	refreshSettings();

#ifdef Q_OS_WIN32
	m_outputFileName = sourceInfo.dir().absoluteFilePath(sourceInfo.baseName() + ".exe");
#else
	m_outputFileName = sourceInfo.dir().absoluteFilePath(sourceInfo.baseName());
#endif
	QString objectName = sourceInfo.dir().absoluteFilePath(sourceInfo.baseName() + ".o");

	QFileInfo outputInfo(m_outputFileName);
	if(sourceInfo.lastModified() < outputInfo.lastModified())
		return true;

	args = m_cflags;
	m_defaultPort.replace("\\", "\\\\");
	args << "-DDEFAULT_SERIAL_PORT=\"" + m_defaultPort + "\"";
	args << "-c" << filename << "-o" << objectName;
	m_gcc.start(m_gccPath, args);
	m_gcc.waitForFinished();
	processCompilerOutput();
	m_linkerMessages.clear();

	if(m_gcc.exitCode() != 0)
		return false;

	args.clear();
	args << "-o" << m_outputFileName << objectName;
	args << m_lflags;
	m_gcc.start(m_gccPath, args);
	m_gcc.waitForFinished();
	processLinkerOutput();

	QFile objectFile(objectName);
	objectFile.remove();

	if(m_gcc.exitCode() == 0)
		return true;
	return false;
}
Beispiel #11
0
/*
Функция подготавливает список файлов для копирования и подсчитивает их колличество. Содержимое
каталога строится в алфавитном порядке. (можно изменить с помощью переменной filesSort)
При работе функции возможно возбуждение исключения CopyExcepion. При обработки символической ссылки
в список копирования будет добавлен путь к файлу на который указывает эта ссылка
*/
int CopyJob::prepareCopy(int index, int level, const QString& sName, QString destDir, CopyInfoList& files)
{
  QFileInfo sourceInfo(sName);
  qint64 countFiles(0);
  
  CopyExcepion::throwIf(breakCurrentWork, UserTerminate, "User terminate");
  
  if ( !destDir.isEmpty() && !destDir.endsWith(QLatin1Char('/')) ) destDir += QLatin1Char('/');
  
  CopyExcepion::throwIf(!sourceInfo.exists(), SourceNotExists, sourceInfo.absoluteFilePath());
  
  if ( sourceInfo.isSymLink() )
    sourceInfo.setFile(sourceInfo.symLinkTarget());
  
  CopyInfo copyInfo;
  
  if ( sourceInfo.isFile() ){
    copyInfo.fill(sourceInfo.fileName(), sourceInfo.absoluteDir().absolutePath() + QLatin1Char('/'),
                  destDir, CopyInfo::FILE, sourceInfo.size(), index, level);
    files.append(copyInfo);
    countFiles++;
  }
  else 
    if ( sourceInfo.isDir() ){
      QDir sourceDir(sourceInfo.filePath());
          
      copyInfo.fill(sourceDir.dirName(), "", destDir, CopyInfo::DIR, 0, index, level);
      files.append(copyInfo);
      countFiles++;

      QFileInfoList filesInDir = sourceDir.entryInfoList(filesFilter, filesSort);
    
      for ( int i = 0; i < filesInDir.size(); i++ ){
        countFiles += prepareCopy(index, level + 1, filesInDir.at(i).absoluteFilePath(), 
                                  destDir + sourceDir.dirName(), files);
      }
    }
    else
      throw CopyExcepion(UnknownFileType, "Unknown file type");
    
  return countFiles;
}
    // Fetch sources whose deadline timers have arrived.
    //
    bool scanSources ()
    {
        bool interrupted = false;

        for (int i = 0; i < m_logic.getSources ().size (); ++i)
        {
            SourceInfo& sourceInfo (*m_logic.getSources ()[i]);

            Time const currentTime = Time::getCurrentTime ();

            if (currentTime <= sourceInfo.whenToFetch)
            {
                m_logic.fetchAndProcessSource (sourceInfo);
            }

            interrupted = m_thread.interruptionPoint ();

            if (interrupted)
                break;
        }

        return interrupted;
    }
Beispiel #13
0
	bool Mesh::Load(const char *file)
	{
		QString fileName(file);

		QFileInfo sourceInfo(fileName);
		QFile source(fileName);

		if (!source.open(QIODevice::ReadOnly))
			return false;

		Name = QString("avatar/") + sourceInfo.baseName();

		char version[25];
		version[24] = '\0';

		if (source.read(version, 24) != 24)
			return false;

		Version = QString(version);

		getvar(hasWeights);
		getvar(hasDetailTexCoords);

		getvar(position);
		getvar(rotationAngles);
		getvar(rotationOrder);
		getvar(Scale);
		getvar(numVertices);

		Vertices = (Vertex *)malloc(sizeof(Vertex) * numVertices);
		Weights = (float *)calloc(sizeof(float), numVertices);
		detailTexCoords = (Vector2 *)calloc(sizeof(Vector2), numVertices);

		int i;

		for (i = 0 ; i < numVertices ; i++)
			getvar(Vertices[i].baseCoords);

		for (i = 0 ; i < numVertices ; i++)
			getvar(Vertices[i].baseNormals);

		for (i = 0 ; i < numVertices ; i++)
			getvar(Vertices[i].baseBinormals);

		for (i = 0 ; i < numVertices ; i++)
			getvar(Vertices[i].texCoords);

		if (hasDetailTexCoords)
		{
			for (i = 0 ; i < numVertices ; i++)
				getvar(detailTexCoords[i]);
		}

		if (hasWeights)
		{
			for (i = 0 ; i < numVertices ; i++)
				getvar(Weights[i]);
		}

		getvar(numFaces);

		Faces = (Face *)malloc(sizeof(Face) * numFaces);

		for (i = 0 ; i < numFaces ; i++)
			getvar(Faces[i]);

		if (hasWeights)
		{
			char joint[64];

			getvar(numSkinJoints);
			for (i = 0 ; i < numSkinJoints ; i++)
			{
				getvar(joint);
				jointNames.append(QString(joint));
			}
		}

		numMorphs = 0;

		while (true)
		{
			char morphName[64];

			getvar(morphName);
			if (!strcmp(morphName, "End Morphs"))
				break;

			if (numMorphs == 0)
				Morphs = (Morph *)malloc(sizeof(Morph));
			else
				Morphs = (Morph *)realloc(Morphs, sizeof(Morph) * (numMorphs + 1));

			Morph *current = &Morphs[numMorphs];
			numMorphs++;

			memcpy(current->morphName, morphName, 64);
			getvar(current->numVertices);

			current->Vertices = (MorphVertex *)malloc(sizeof(MorphVertex) * current->numVertices);
			for (i = 0 ; i < current->numVertices ; i++)
				getvar(current->Vertices[i]);
		}

		getvar(numRemaps);

		if (numRemaps > 0)
		{
			Remaps = (Remap *)malloc(sizeof(Remap) * numRemaps);
			for (i = 0 ; i < numRemaps ; i++)
				getvar(Remaps[i]);
		}

		source.close();

		return true;
	}
bool KDUpdater::UFCompressor::compress()
{
    d->errorString.clear();
   
    // Perform some basic checks.
    QFileInfo sourceInfo(d->source);
    if( !sourceInfo.isReadable() ) {
        d->setError( tr( "\"%1\" is not readable").arg( d->source ) );
        return false;
    }

    QDir sourceDir( sourceInfo.absoluteFilePath() ); // = sourceInfo.dir();
    sourceDir.cdUp();
    QString sourcePath = sourceDir.absolutePath();

    // First create the ZIP header.
    KDUpdater::UFHeader header;
    header.magic = QLatin1String( KD_UPDATER_UF_HEADER_MAGIC );
    header.fileList << d->fileNameRelativeTo(sourceInfo.absoluteFilePath(), sourcePath);
    header.permList << static_cast<quint64>(sourceInfo.permissions());
    header.isDirList << sourceInfo.isDir();
    // qDebug("ToCompress: %s", qPrintable(header.FileList.first()));

    if(sourceInfo.isDir())
        d->updateUFHeader(sourcePath, QDir(d->source), header);

    // open the uf file for writing
    QFile ufFile( d->ufFileName );
    //this should actually use temp files for security, for now remove partial files if saving failed  
    FileRemover remover( &ufFile );
    
    if( !ufFile.open(QFile::WriteOnly) )
    {
        d->setError( tr( "Could not open \"%1\" for writing: %2").arg( d->ufFileName, ufFile.errorString() ) );
        return false;
    }
    
    QDataStream ufDS( &ufFile );
    ufDS.setVersion( QDataStream::Qt_4_2 );
    QCryptographicHash hash( QCryptographicHash::Md5 );

    // Insert the header into the UF file
    ufDS << header;
    header.addToHash(hash);

    // Now create ZIP entries and add them.
    for(int i=0; i<header.fileList.count(); i++)
    {
        if(header.isDirList[i])
            continue;

        KDUpdater::UFEntry ufEntry;
        ufEntry.fileName = header.fileList[i];

        QString completeFileName = QString::fromLatin1( "%1/%2" ).arg(sourcePath, ufEntry.fileName);
        QFile zeFile( completeFileName );
        if ( !zeFile.open( QFile::ReadOnly ) ) {
            d->setError( tr( "Could not open input file \"%1\" to compress: %2").arg( completeFileName, zeFile.errorString() ) );
            return false;
        }
        ufEntry.fileData = qCompress(zeFile.readAll());
        ufEntry.permissions = static_cast<quint64>(zeFile.permissions());

        //qDebug("Compressed %s as %s", qPrintable(completeFileName), qPrintable(ufEntry.fileName));

        ufDS << ufEntry;
        ufEntry.addToHash(hash);
    }

    // All done, append hash and close file
    ufDS << hash.result();
    ufFile.close();
    
    if ( ufFile.error() != QFile::NoError )
    {
        d->setError( tr( "Could not save compressed data to \"%1\": %2").arg( ufFile.fileName(), ufFile.errorString() ) );
        return false;
    }

    remover.finalizeAndRelease(); // do not remove the file

    return true;
}