Esempio n. 1
0
struct tankdef
readTankFromDir(char* path) {
  DIR* dp;
  if( (dp=opendir(path))==NULL ) {
    perror(path);
    exit(1);
  }

  struct tankdef theTank;
  initTank(&theTank);
  struct dirent* files;
  while( (files=readdir(dp)) != NULL ) {
    if( isNotRealDir(files) ) {
      continue;
    }
    char file[1000];
    sprintf(file, "%s/%s", path, files->d_name);
    if( isSensor(files->d_name) ) {
      int sensorId = files->d_name[strlen("sensor")]-'0';
      theTank.sensors[sensorId] = parseSensor(file);
    } else if( strcmp(files->d_name, "name") == MATCH ) {
      loadFileContent( theTank.name, file, max_size(NAME) );
    } else if( strcmp(files->d_name, "author") == MATCH ) {
      loadFileContent( theTank.author, file, max_size(AUTHOR) );
    } else if( strcmp(files->d_name, "program") == MATCH ) {
      loadFileContent( theTank.program, file, max_size(PROGRAM) );
    } else if( strcmp(files->d_name, "color") == MATCH ) {
      loadFileContent( theTank.color, file, max_size(COLOR) );
    }
  }
  closedir(dp);
  return theTank;
}
Esempio n. 2
0
static JSBool
import_file(JSContext  *context,
            const std::string &name,
            const std::string &file,
            JSObject   *module_obj)
{
    jsval script_retval;

    JS::CompileOptions options(context);

	std::string script;
	
	IOError ret = loadFileContent(file, script);
	
    if (ret == IO_ERROR_IS_DIRECTORY || ret == IO_ERROR_NOT_DIRECTORY || ret == IO_ERROR_NOT_FOUND) {
		std::cout << "io error?!\n";
        return JS_FALSE;
    }

    if (!gjs_eval_with_scope(context, module_obj, script.c_str(), script.size(),
                             file.c_str(), NULL)) {
		std::cout << "gjs_eval_with_scope failed\n";
        return JS_FALSE;
	}

	return JS_TRUE;
}
Esempio n. 3
0
std::string File::string() const
{
    if (!m_valid)
        loadFileContent();

	return m_source;
}
//////////////////////////////////////////////////////////////////////////////
//
// FileConverter
//
//////////////////////////////////////////////////////////////////////////////
bool FileConverter::convertFile(Core::GeneratedFile &file, QString &errorMessage)
{
    ImportLog &log = convertedProjectContext().importLog();
    log.logInfo(tr("===== Converting file: %1").arg(file.path()));
    loadFileContent(file, errorMessage);
    if (!errorMessage.isEmpty())
        logError(errorMessage);
    return errorMessage.isEmpty();
}
bool FileConverter::loadFileContent(Core::GeneratedFile &file, QString &errorMessage)
{
    if (file.binaryContents().isEmpty()) {
        // virtual files have some content set already
        QString filePath = file.path();
        QByteArray ba = loadFileContent(filePath, errorMessage);
        file.setBinaryContents(ba);
    }
    return errorMessage.isEmpty();
}
Esempio n. 6
0
 CSVParser::CSVParser(const std::string &data, char sep, const DataType &type)
   : _type(type), _sep(sep), _initialized(false)
 {
     _file = data;
     
     if(loadFileContent())
     {
       parseHeader();
     }
 }
Esempio n. 7
0
 CSVParser::CSVParser(const std::string &data, const DataType &type)
   : _type(type), _initialized(false)
 {
     _file = data;
     
     if(loadFileContent() && detectSeperator())
     {
         parseHeader();
     }
 }
bool ProjectFileConverter::convertFile(Core::GeneratedFile &file, QString &errorMessage)
{
    if (!FileConverter::convertFile(file, errorMessage))
        return false;

    ImportLog &log = convertedProjectContext().importLog();
    QMap<QString, QString> origProjectVariables = scanForDefinedVariables(file);
    QString fileContent;

    QLatin1String path( ":/qnx/cascadesimport/resources/templates/project.pro");
    QByteArray ba = loadFileContent(path, errorMessage);
    if (!errorMessage.isEmpty())
        return false;
    fileContent = QString::fromUtf8(ba);

    QStringList headers;
    QStringList sources;
    QStringList resources;
    QStringList otherFiles;

    QSet<QString> entries;
    foreach (const QString &filePath, convertedProjectContext().collectedFiles()) {
        QString ext = filePath.section(QLatin1Char('.'), -1);
        if (ext.compare(QLatin1String("c"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("cc"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("cpp"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("h"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("hh"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("hpp"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0)
            resources << filePath;
        else if (ext.compare(QLatin1String("qml"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("js"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("ts"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("pro"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (filePath.compare(QLatin1String("bar-descriptor.xml"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (filePath.startsWith(QLatin1String("assets/"), Qt::CaseInsensitive))
            // include all the content of the assets directory
            otherFiles << filePath;
        else if (filePath.startsWith(QLatin1String("src/"), Qt::CaseInsensitive))
            // include all the content of the src directory
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("log"), Qt::CaseInsensitive) != 0)
                log.logWarning(tr("File '%1' not listed in '%2' file, should it be?")
                        .arg(filePath).arg(file.path()));
    }

    fileContent.replace(QLatin1String("%HEADERS%"), headers.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%SOURCES%"), sources.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%RESOURCES%"), resources.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%OTHER_FILES%"), otherFiles.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%PROJECT_NAME%"), convertedProjectContext().projectName());
    fileContent.replace(QLatin1String("%TARGET%"), origProjectVariables.value(QLatin1String("TARGET"),
                                      convertedProjectContext().projectName()));
    fileContent.replace(QLatin1String("%EXTRA_LIBS%"), origProjectVariables.value(QLatin1String("LIBS")));
    fileContent.replace(QLatin1String("%IMPORTER_VERSION%"),
                        QLatin1String(Qnx::Constants::QNX_BLACKBERRY_CASCADESIMPORTER_VERSION));
    fileContent.replace(QLatin1String("%DATE_TIME%"),
                                      QDateTime::currentDateTime().toString(Qt::ISODate));
    fileContent.replace(QLatin1String("%QT%"),
            updateVariable(origProjectVariables.value(QLatin1String("QT")),
                           QLatin1String("declarative script svg sql network xml xmlpatterns"),
                           QString()
    ));
    fileContent.replace(QLatin1String("%CONFIG%"),
            updateVariable(origProjectVariables.value(QLatin1String("CONFIG")),
                           QLatin1String("qt warn_on"),
                           QLatin1String("debug release debug_and_release cascades cascades10")
    ));
    fileContent.replace(QLatin1String("%MOBILITY%"), origProjectVariables.value(QLatin1String("MOBILITY")));
    file.setContents(fileContent);
    file.setAttributes(file.attributes() | Core::GeneratedFile::OpenProjectAttribute);
    return errorMessage.isEmpty();
}