예제 #1
0
void SourceEditor::checkTimeStamp()
{
    if ( formWindow() )
	formWindow()->formFile()->checkTimeStamp();
    else if ( sourceFile() )
	sourceFile()->checkTimeStamp();
}
예제 #2
0
bool SourceEditor::saveAs()
{
    if ( formWindow() )
	return formWindow()->formFile()->saveAs();
    else if ( sourceFile() )
	return sourceFile()->saveAs();
    return FALSE;
}
예제 #3
0
void SourceEditor::save()
{
    if ( !obj )
	return;
    if ( formWindow() )
	formWindow()->formFile()->syncCode();
    else if ( sourceFile() )
	sourceFile()->setText( iFace->text() );
}
예제 #4
0
bool Dictionary::InsertWordsIntoDict(const string& filename)
{
    // Purpose: insert the words found in the file specified into the dictionary

    fstream sourceFile(filename.c_str(), ios::in);
    if (!sourceFile)
    {
        cerr << "Error: file \"" << filename << "\" does not exist, and thus file-insertion could not be performed." << endl;
        return failure;
    }

    string currentWord;

    while (sourceFile >> currentWord)
    {
        if (totalWordsInDict >= maxWordsInDict) // If we're over the limit, don't keep calling the add a word function, it's a waste of time.
        {
            cerr << "Error: max words in dictionary (" << maxWordsInDict << ") has been reached. Complete insertion failed." << endl;
            return failure; // As usual boolean values fail to suffice in certain contexs. We may have inserted SOME, so it's not a true absolute failure.
        }
        this->AddAWord(currentWord); // Add the word, this handles incrementation for us.
    }
    sourceFile.close();
    return success;
}
예제 #5
0
파일: file.cpp 프로젝트: cvalka4/cupt
	string perform(const shared_ptr< const Config >& /* config */, const download::Uri& uri,
			const string& targetPath, const std::function< void (const vector< string >&) >& callback)
	{
		auto sourcePath = uri.getOpaque();
		auto protocol = uri.getProtocol();

		// preparing source
		string openError;
		File sourceFile(sourcePath, "r", openError);
		if (!openError.empty())
		{
			return format2("unable to open the file '%s' for reading: %s", sourcePath, openError);
		}

		if (protocol == "copy")
		{
			return copyFile(sourcePath, sourceFile, targetPath, callback); // full copying
		}
		else if (protocol == "file")
		{
			// symlinking
			unlink(targetPath.c_str()); // yep, no error handling;
			if (symlink(sourcePath.c_str(), targetPath.c_str()) == -1)
			{
				return format2e("unable to create symbolic link '%s' -> '%s'", targetPath, sourcePath);
			}
			return string();
		}
		else
		{
			fatal2i("a wrong scheme '%s' for the 'file' download method", protocol);
			return string(); // unreachable
		}
	}
예제 #6
0
int source  (char const *comm)  /* 002 */
{
    Tstr filename = makeScript(comm, TRUE); // 003
    int rtn = sourceFile  ((char const*)filename, (char const*)Tenv::appGet("SIRE"), "-env");
    unlink((char const*)filename);
    return(rtn);
}
예제 #7
0
int main(int argc, char *argv[])
{
    if( argc == 2 && strcmp(argv[1], "--help") == 0 )
    {
        QCoreApplication a(argc, argv);
        // this doesn't work
        printf("Command line usage:\n\nReplacementWorkspace my-replacements.xml input.txt output.txt\n");
        return a.exec();
    }
    else if( argc == 4 ) {
        // this does nothing and it hangs
        QCoreApplication a(argc, argv);

        QString transformationFile( argv[1] );
        QString sourceFile( argv[2] );
        QString destFile( argv[3] );

        ReplacementEngine re;
        re.readFromFile(transformationFile);
        re.processFile(sourceFile, destFile);

        return a.exec();
    }
    else
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
}
예제 #8
0
static bool copyIfNotPresent
    ( const QString &sourcePath
    , const QString &destinationPath
    )
{
    QFile sourceFile(sourcePath);
    QFile destinationFile(destinationPath);

    if (destinationFile.exists()) return true;

    if (sourceFile.open(QIODevice::ReadOnly | QIODevice::Text) == false) {
        fprintf(stderr, "Failed to read template.\n");
        return false;
    }

    QFileInfo destinationInfo(destinationFile);
    QDir(destinationInfo.absolutePath()).mkpath(".");

    if (destinationFile.open(QIODevice::WriteOnly | QIODevice::Text) == false) {
        fprintf(stderr, "Failed to open user configuration file for writing.\n");
        return false;
    }

    QTextStream in(&sourceFile);
    QTextStream out(&destinationFile);
    out << in.readAll();

    return true;
}
예제 #9
0
Core::GeneratedFiles ClassWizard::generateFiles(const QWizard *w,
                                                QString *errorMessage) const
{
    Q_UNUSED(errorMessage);

    const ClassWizardDialog *wizard = qobject_cast<const ClassWizardDialog *>(w);
    const ClassWizardParameters params = wizard->parameters();

    const QString fileName = Core::BaseFileWizard::buildFileName(
                params.path, params.fileName, QLatin1String(Constants::C_PY_EXTENSION));
    Core::GeneratedFile sourceFile(fileName);

    SourceGenerator generator;
    generator.setPythonQtBinding(SourceGenerator::PySide);
    Kit *kit = kitForWizard(wizard);
    if (kit) {
        QtSupport::BaseQtVersion *baseVersion = QtSupport::QtKitInformation::qtVersion(kit);
        if (baseVersion && baseVersion->qtVersion().majorVersion == 5)
            generator.setPythonQtVersion(SourceGenerator::Qt5);
        else
            generator.setPythonQtVersion(SourceGenerator::Qt4);
    }

    QString sourceContent = generator.generateClass(
                params.className, params.baseClass, params.classType
                );

    sourceFile.setContents(sourceContent);
    sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
    return Core::GeneratedFiles() << sourceFile;
}
예제 #10
0
void PHPOutlineTree::BuildTree(const wxFileName& filename)
{
    m_filename = filename;
    PHPSourceFile sourceFile(filename, NULL);
    sourceFile.SetParseFunctionBody(false);
    sourceFile.Parse();
    wxWindowUpdateLocker locker(this);
    DeleteAllItems();

    wxTreeItemId root = AddRoot(wxT("Root"));

    wxImageList* images = new wxImageList(clGetScaledSize(16), clGetScaledSize(16), true);
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/globals")));            // 0
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_private")));   // 1
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_protected"))); // 2
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/function_public")));    // 3
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_private")));     // 4
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_protected")));   // 5
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/member_public")));      // 6
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/namespace")));          // 7
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/class")));              // 8
    images->Add(m_manager->GetStdIcons()->LoadBitmap(wxT("cc/16/enumerator")));         // 9
    AssignImageList(images);

    // Build the tree view
    BuildTree(root, sourceFile.Namespace());

    if(HasChildren(GetRootItem())) {
        ExpandAll();
    }
}
예제 #11
0
    virtual void read(const string& filename, const string& head, MSData& result, int runIndex = 0) const
    {
        if (runIndex != 0)
            throw ReaderFail("[Reader_BTDX::read] multiple runs not supported");

        shared_ptr<istream> is(new pwiz::util::random_access_compressed_ifstream(filename.c_str()));
        if (!is.get() || !*is)
            throw runtime_error(("[Reader_BTDX::read] Unable to open file " + filename));

        result.fileDescription.fileContent.set(MS_MSn_spectrum);
        result.fileDescription.fileContent.set(MS_centroid_spectrum);
        SourceFilePtr sourceFile(new SourceFile);
        sourceFile->id = "BTDX1";
        bfs::path p(filename);
        sourceFile->name = p.leaf();
        string location = bfs::complete(p.branch_path()).string();
        if (location.empty()) location = ".";
        sourceFile->location = string("file:///") + location;
        result.fileDescription.sourceFilePtrs.push_back(sourceFile);

        result.id = result.run.id = bfs::basename(filename);
        result.run.spectrumListPtr = SpectrumListPtr(SpectrumList_BTDX::create(is, result));
        result.run.chromatogramListPtr = ChromatogramListPtr(new ChromatogramListSimple);
        return;
    }
예제 #12
0
//================================================================================
//convertPathL
//================================================================================
void convertPathL(TDesC& aPath, TDesC& aPathName, RFs& aFs, TDesC& aTargetFile)
	{
	aFs.MkDirAll(aPathName);

	CDir* entryList = NULL;
	TInt error = aFs.GetDir(aPath,KEntryAttMatchMask,ESortByName,entryList);
	User::LeaveIfError(error);

	TInt numberOfFiles = entryList->Count();
	for (TInt i=0; i<numberOfFiles; i++)
		{
		//get the source file
		HBufC* temp=HBufC::NewLC(((*entryList)[i].iName).Length());
		TPtr sourceFileName(temp->Des());
		sourceFileName.Copy((*entryList)[i].iName);

		HBufC* temp2=HBufC::NewLC(((*entryList)[i].iName).Length()+aPathName.Length());
		TPtr sourceFile(temp2->Des());
		sourceFile = aPathName;
		sourceFile.Append(sourceFileName);
		//do the conversion
		synchronousL(sourceFile, aTargetFile);
		//output result
		_LIT(KString,"%S");
		test.Printf(KString,&(sourceFileName));
		test.Printf(_L("\n"));
		CleanupStack::PopAndDestroy(2);//temp, temp2
		}

	delete entryList;
	test.Printf(_L("\n%d files converted\n"),numberOfFiles);
	}
예제 #13
0
static void copyTemplateFile(const QString &fileName, const QString &targetDirectory,
        const Profile &profile, const QtEnvironment &qtEnv, QStringList *allFiles,
        const QtModuleInfo *module = 0)
{
    if (!QDir::root().mkpath(targetDirectory)) {
        throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: "
                                         "Cannot create directory '%2'.")
                        .arg(profile.name(), targetDirectory));
    }
    QFile sourceFile(QLatin1String(":/templates/") + fileName);
    if (!sourceFile.open(QIODevice::ReadOnly)) {
        throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: "
                "Cannot open '%1' (%2).").arg(sourceFile.fileName(), sourceFile.errorString()));
    }
    QByteArray newContent = sourceFile.readAll();
    if (module)
        replaceSpecialValues(&newContent, profile, *module, qtEnv);
    sourceFile.close();
    const QString targetPath = targetDirectory + QLatin1Char('/') + fileName;
    allFiles->append(QFileInfo(targetPath).absoluteFilePath());
    QFile targetFile(targetPath);
    if (targetFile.open(QIODevice::ReadOnly)) {
        if (newContent == targetFile.readAll()) // No need to overwrite anything in this case.
            return;
        targetFile.close();
    }
    if (!targetFile.open(QIODevice::WriteOnly)) {
        throw ErrorInfo(Internal::Tr::tr("Setting up Qt profile '%1' failed: "
                "Cannot open '%1' (%2).").arg(targetFile.fileName(), targetFile.errorString()));
    }
    targetFile.resize(0);
    targetFile.write(newContent);
}
예제 #14
0
	bool getFileText( const std::string& filePath, std::string& outText )
	{

		// Open the file
		//
		std::ifstream sourceFile( filePath.c_str() );


		if(sourceFile.good() )
		{

			// Read the full contents of the file into a string. (may throw.)
			//
			sourceFile.seekg( 0, std::ios::end );
			outText.reserve( static_cast< size_t > ( sourceFile.tellg() ));
			sourceFile.seekg( 0, std::ios::beg );

			outText.assign(( std::istreambuf_iterator<char>(sourceFile )),
				std::istreambuf_iterator<char>() );

			sourceFile.close();
			return true;
		}
		return false;
	}
예제 #15
0
SourceEditor::~SourceEditor()
{
    saveBreakPoints();
    editor = 0;
    if ( formWindow() ) {
	formWindow()->formFile()->setCodeEdited( FALSE );
	formWindow()->formFile()->setEditor( 0 );
    } else if ( sourceFile() ) {
	sourceFile()->setEditor( 0 );
	if ( MainWindow::self->objectHierarchy()->sourceEditor() == this )
	    MainWindow::self->objectHierarchy()->setFormWindow( 0, 0 );
    }
    iFace->release();
    lIface->release();
    MainWindow::self->editorClosed( this );
}
예제 #16
0
static bool copyResourceFile(const QString &sourceFileName, const QString &targetFileName,
                             QString *errorMessage)
{

    QFile sourceFile(sourceFileName);
    if (!sourceFile.exists()) {
        *errorMessage = QDir::toNativeSeparators(sourceFileName) + QLatin1String(" does not exist.");
        return false;
    }
    if (!sourceFile.copy(targetFileName)) {
        *errorMessage = QLatin1String("Cannot copy ")
            + QDir::toNativeSeparators(sourceFileName) + QLatin1String(" to ")
            + QDir::toNativeSeparators(targetFileName) + QLatin1String(": ")
            + sourceFile.errorString();
        return false;
    }
    // QFile::copy() sets the permissions of the source file which are read-only for
    // resource files. Set write permission to enable deletion of the temporary directory.
    QFile targetFile(targetFileName);
    if (!targetFile.setPermissions(targetFile.permissions() | QFileDevice::WriteUser)) {
        *errorMessage = QLatin1String("Cannot set write permission on ")
            + QDir::toNativeSeparators(targetFileName) + QLatin1String(": ")
            + targetFile.errorString();
        return false;
    }
    return true;
}
예제 #17
0
GLuint OpenGLRenderer::LoadFragShader(const std::string& vertexFile)
{
	//Open file
	GLuint shaderID = 0;
	std::string shaderString;
	std::ifstream sourceFile(vertexFile.c_str());

	//Source file loaded
	if (sourceFile)
	{
		//Get shader source
		shaderString.assign((std::istreambuf_iterator< char >(sourceFile)), std::istreambuf_iterator< char >());
		//Create shader ID
		shaderID = glCreateShader(GL_FRAGMENT_SHADER);

		//Set shader source
		const GLchar* shaderSource = shaderString.c_str();
		glShaderSource(shaderID, 1, (const GLchar**)&shaderSource, NULL);

		//Compile shader source
		glCompileShader(shaderID);

		//Check shader for errors
		GLint shaderCompiled = GL_FALSE;
		glGetShaderiv(shaderID, GL_COMPILE_STATUS, &shaderCompiled);
		if (shaderCompiled != GL_TRUE)
		{
			printf("Unable to compile shader %d!\n\nSource:\n%s\n", shaderID, shaderSource);
			glDeleteShader(shaderID);
			shaderID = 0;
		}
	}
	return shaderID;
}
예제 #18
0
bool UpdateClient::copyFile(const QString &srcDir, const QString &destDir, const QString &srcFileName, const QString &destFileName)
{
    QFileInfo sourceFile(QDir::cleanPath(srcDir + QDir::separator() + srcFileName));
    QFileInfo destFile(QDir::cleanPath(destDir + QDir::separator() + destFileName));

    //if source file doesn't exists
    if (!QFile::exists(sourceFile.filePath()))
    {
        return false;
    }

    // check if dest directory not exists
    if (!QDir(QDir::cleanPath(destFile.absolutePath())).exists())
    {
        // try to create dest dir
        if (!QDir(QDir::rootPath()).mkpath(destFile.absolutePath()))
            return false;
    }

    // if dest file exists
    if (QFile::exists(destFile.filePath()))
    {
        // remove it (analog rewrite functionality)
        QFile::remove(destFile.filePath());
    }

    return QFile::copy(sourceFile.filePath(), destFile.filePath());
}
예제 #19
0
void PHPCodeCompletion::GetMembers(IEditor* editor, PHPEntityBase::List_t& members, wxString& scope)
{
    members.clear();
    scope.clear();
    if(!editor) {
        return;
    }

    // Parse until the current position to get the current scope name
    {
        wxString text = editor->GetTextRange(0, editor->GetCurrentPosition());
        PHPSourceFile sourceFile(text);
        sourceFile.SetParseFunctionBody(true);
        sourceFile.SetFilename(editor->GetFileName());
        sourceFile.Parse();

        const PHPEntityClass* scopeAtPoint = sourceFile.Class()->Cast<PHPEntityClass>();
        if(!scopeAtPoint) {
            return;
        }
        scope = scopeAtPoint->GetFullName();
    }

    // Second parse: parse the entire buffer so we are not limited by the caret position
    wxString text = editor->GetTextRange(0, editor->GetLength());
    PHPSourceFile sourceFile(text);
    sourceFile.SetParseFunctionBody(true);
    sourceFile.SetFilename(editor->GetFileName());
    sourceFile.Parse();

    // Locate the scope
    PHPEntityBase::Ptr_t parentClass = sourceFile.Namespace()->FindChild(scope);
    if(!parentClass) return;

    // filter out
    const PHPEntityBase::List_t& children = parentClass->GetChildren();
    PHPEntityBase::List_t::const_iterator iter = children.begin();

    for(; iter != children.end(); ++iter) {
        PHPEntityBase::Ptr_t child = *iter;
        if(child->Is(kEntityTypeVariable) && child->Cast<PHPEntityVariable>()->IsMember() &&
            !child->Cast<PHPEntityVariable>()->IsConst() && !child->Cast<PHPEntityVariable>()->IsStatic()) {
            // a member of a class
            members.push_back(child);
        }
    }
}
예제 #20
0
bool CWizZiwReader::encryptDataToTempFile(const QString& sourceFileName, \
                                          const QString& destFileName, \
                                          const QString& strZiwCipher)
{
    QFile sourceFile(sourceFileName);
    if (!sourceFile.open(QIODevice::ReadOnly)) {
        TOLOG("Can't open source file while encrypt to temp file");
        return false;
    }

    // encrypt data
    QByteArray inBytes(sourceFile.readAll());
    QByteArray outBytes;
    if (!WizAESEncryptToString((const unsigned char *)(strZiwCipher.toUtf8().constData()), inBytes, outBytes)) {
        return false;
    }

    // encrypt ziw cipher
    QByteArray encryptedZiwCipher;
    if (!encryptZiwCipher(strZiwCipher.toUtf8(), encryptedZiwCipher)) {
        return false;
    }

    // compose file
    // FIXME: hard coded here.
    WIZZIWHEADER header;
    memset(&header, 0, sizeof(header));
    header.szSign[0] = 'Z';
    header.szSign[1] = 'I';
    header.szSign[2] = 'W';
    header.szSign[3] = 'R';
    header.nVersion = 1;
    header.nKeyLength = WIZZIWFILE_KEY_LENGTH;
    memcpy(header.szEncryptedKey, encryptedZiwCipher.constData(), sizeof(header.szEncryptedKey));

    QFile destFile(destFileName);
    if (!destFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
        TOLOG("Can't open dest file while encrypt to temp file");
        return false;
    }

    QDataStream out(&destFile);
    if (sizeof(header) != out.writeRawData((const char *)&header, sizeof(header))) {
        TOLOG("Write data failed while encrypt to temp file");
        destFile.remove();
        return false;
    }

    if (outBytes.length() != out.writeRawData(outBytes.constData(), outBytes.length())) {
        TOLOG("Write data failed while encrypt to temp file");
        destFile.remove();
        return false;
    }

    destFile.close();
    sourceFile.close();

    return true;
}
예제 #21
0
QString generateCode(const QString &fileName, int indentation, bool closeEnum)
{
    QFile sourceFile(fileName);

    if (!sourceFile.open(QIODevice::ReadWrite)) {
        return QString();
    }

    QTextStream input(&sourceFile);

    QString result;
    QString indentationStr(indentation, QChar(' '));

    int currentLine = 0;
    while (!input.atEnd()) {
        QString line = input.readLine();
        ++currentLine;

        if (line.simplified().isEmpty() || (line.startsWith(QLatin1String("---")) && line.endsWith(QLatin1String("---")))) {
            continue;
        }

        int hashIndex = line.indexOf(QChar('#'));
        if ((hashIndex < 1) || (hashIndex + 1 > line.length())) {
            printf("Bad string: %s (%s:%d)\n", line.toLocal8Bit().constData(), fileName.toLocal8Bit().constData(), currentLine);
            return QString();
        }

        QString name = line.left(hashIndex);

        name[0] = name.at(0).toUpper();

        int separatorIndex = 0;
        while ((separatorIndex = indexOfSeparator(name, separatorIndex)) > 0) {
            if ((name.length() < separatorIndex + 1) || (!name.at(separatorIndex + 1).isLetter())) {
                printf("Bad name: %s (%s:%d)\n", name.toLocal8Bit().constData(), fileName.toLocal8Bit().constData(), currentLine);
                return QString();
            }
            name[separatorIndex + 1] = name.at(separatorIndex + 1).toUpper();
            name.remove(separatorIndex, 1);
        }

        QString value = line.mid(hashIndex + 1, hashMaxLength);
        int endOfValue = value.indexOf(QChar(' '));
        if (endOfValue > 0) {
            value.truncate(endOfValue);
        }

        result.append(indentationStr);

        if (!closeEnum || !input.atEnd()) {
            result.append(QString("%1 = 0x%2,\n").arg(name).arg(value));
        } else {
            result.append(QString("%1 = 0x%2\n").arg(name).arg(value));
        }
    }

    return result;
}
예제 #22
0
void QgsHtmlAnnotation::writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const
{
  QDomElement formAnnotationElem = doc.createElement( QStringLiteral( "HtmlAnnotationItem" ) );
  formAnnotationElem.setAttribute( QStringLiteral( "htmlfile" ), sourceFile() );

  _writeXml( formAnnotationElem, doc, context );
  elem.appendChild( formAnnotationElem );
}
예제 #23
0
Parser::Parser(string fileName)
{
    ifstream sourceFile(fileName);

    source.assign(std::istreambuf_iterator<char>(sourceFile),
                  std::istreambuf_iterator<char>()
                 ); //get source
}
예제 #24
0
void CustomDirManager::import(QStringList &files, bool local)
{
    QString targetDir = (local ? dirCustom : dirEpisode);
    targetDir = (!targetDir.endsWith("/") ? targetDir.append('/') : targetDir);
    foreach (QString targetFile, files) {
        QFile sourceFile(targetFile);
        sourceFile.copy(targetDir + targetFile.section("/", -1));
    }
예제 #25
0
void process_file(std::string const & filename)
{
	static std::map<std::string, bool> filenameLoaded;

	if (filename.empty())
		return;

	if (filenameLoaded[filename])
		return;

	filenameLoaded[filename] = true;

	std::ifstream sourceFile(filename.c_str());

	if (!sourceFile)
	{
		for (size_t index = 0; index < option_include.size(); ++index)
		{
			sourceFile.close();
			sourceFile.clear();
			sourceFile.open((option_include[index] + filename).c_str());

			if (sourceFile)
				break;
		}

		if (!sourceFile)
		{
			std::cerr << "file not found:" << filename << '\n';
			return;
		}
	}

	std::string idstring;
	std::getline(sourceFile, idstring);
	sourceFile.seekg(0);

	if (idstring == "//DDL")
	{
		SourceStream ss(sourceFile);

		process_stream<SourceTokenDDL>(ss, filename);
	}
	else if (idstring == "//DHLX")
	{
		SourceStream ss(sourceFile, SourceStream::ST_DHLX);

		process_stream<SourceTokenDHLX>(ss, filename);
	}
	else
	{
		SourceStream ss(sourceFile);

		process_stream<SourceTokenDDL>(ss, filename);
	}

	sourceFile.close();
}
예제 #26
0
static int cp(const char *sourceFileName, const char *targetFileName)
{
    QFile sourceFile(QString::fromLocal8Bit(sourceFileName));
    if (!sourceFile.copy(QString::fromLocal8Bit(targetFileName))) {
        qWarning().nospace() << sourceFile.errorString();
        return -1;
    }
    return 0;
}
예제 #27
0
void appendSourceFile(const string& filename, MSData& msd)
{
    SourceFilePtr sourceFile(new SourceFile);
    bfs::path p(filename);
    sourceFile->id = sourceFile->name = p.leaf();
    string location = bfs::complete(p.branch_path()).string();
    if (location.empty()) location = ".";
    sourceFile->location = string("file://") + location;
    msd.fileDescription.sourceFilePtrs.push_back(sourceFile);
}
예제 #28
0
PHPSetterGetterEntry::Vec_t PHPRefactoring::GetGetters(IEditor* editor) const
{
    PHPSetterGetterEntry::Vec_t getters, candidates;
    if(!editor) {
        return getters;
    }

    // Parse until the current position
    wxString text = editor->GetTextRange(0, editor->GetCurrentPosition());
    PHPSourceFile sourceFile(text);
    sourceFile.SetParseFunctionBody(true);
    sourceFile.SetFilename(editor->GetFileName());
    sourceFile.Parse();

    const PHPEntityClass* scopeAtPoint = sourceFile.Class()->Cast<PHPEntityClass>();
    if(!scopeAtPoint) {
        return getters;
    }

    // filter out
    const PHPEntityBase::List_t& children = scopeAtPoint->GetChildren();
    PHPEntityBase::List_t::const_iterator iter = children.begin();

    PHPEntityBase::List_t members, functions;
    for(; iter != children.end(); ++iter) {
        PHPEntityBase::Ptr_t child = *iter;
        if(child->Is(kEntityTypeFunction)) {
            functions.push_back(child);
        } else if(child->Is(kEntityTypeVariable) && child->Cast<PHPEntityVariable>()->IsMember() &&
                  !child->Cast<PHPEntityVariable>()->IsConst() && !child->Cast<PHPEntityVariable>()->IsStatic()) {
            // a member of a class
            members.push_back(child);
        }
    }

    if(members.empty()) {
        return getters;
    }

    // Prepare list of candidates
    PHPEntityBase::List_t::iterator membersIter = members.begin();
    for(; membersIter != members.end(); ++membersIter) {
        PHPSetterGetterEntry candidate(*membersIter);

        // make sure we don't add setters that already exist
        if(FindByName(functions, candidate.GetGetter(kSG_NameOnly))) {
            continue;
        }
        candidates.push_back(candidate);
    }

    getters.swap(candidates);
    return getters;
}
예제 #29
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();
}
예제 #30
0
파일: util.cpp 프로젝트: Remscar/cpgf
bool shouldTargetFileBeUpdated(const std::string & sourceFileName, const std::string & targetFileName)
{
	Poco::File targetFile(targetFileName);

	if(! targetFile.exists()) {
		return true;
	}

	Poco::File sourceFile(sourceFileName);
	
	return sourceFile.getLastModified() >= targetFile.getLastModified();
}