Exemple #1
0
void FLEXplorer::WriteDefaultOptions()
{
#ifdef WIN32
    BRegistry reg(BRegistry::currentUser, FLEXPLOREREG);
    reg.SetValue(FLEXPLORERBOOTSECTORFILE, FlexFileContainer::bootSectorFile);
    reg.SetValue(FLEXPLORERTEXTFLAG, FlexCopyManager::autoTextConversion ?
                  1 : 0);
#endif
#ifdef UNIX
    std::string rcFileName;
    BEnvironment env;

    if (!env.GetValue("HOME", rcFileName))
    {
        rcFileName = ".";
    }

    rcFileName += PATHSEPARATORSTRING FLEXPLORERRC;
    BRcFile rcFile(rcFileName.c_str());
    rcFile.Initialize(); // truncate file
    rcFile.SetValue(FLEXPLORERBOOTSECTORFILE,
                    FlexFileContainer::bootSectorFile.c_str());
    rcFile.SetValue(FLEXPLORERTEXTFLAG,
                    FlexCopyManager::autoTextConversion ? 1 : 0);
#endif
}
int
ConfigStateGetRunCount(ConfigStateEnum &code)
{
    int nStartups = 1;
    std::string rcFile(GetUserVisItDirectory());
    rcFile += "state";
    rcFile += VISIT_VERSION;
    rcFile += ".txt";

    FILE *f = 0;
    if((f = fopen(rcFile.c_str(), "r")) != 0)
    {
        if(fscanf(f, "%d", &nStartups) == 1)
        { 
            if(nStartups < 0)
                nStartups = 1;
        }
        fclose(f);
        code = CONFIGSTATE_SUCCESS;
    }
    else
        code = CONFIGSTATE_IOERROR;

    return nStartups;
}
void
ConfigStateIncrementRunCount(ConfigStateEnum &code)
{
    std::string rcFile(GetUserVisItDirectory());
    rcFile += "state";
    rcFile += VISIT_VERSION;
    rcFile += ".txt";

    // Does the file exist?
    bool firstTime = false;
    VisItStat_t s;
    if(VisItStat(rcFile.c_str(), &s) == -1)
        firstTime = true;

    ConfigStateEnum code2;
    int nStartups = firstTime ? 0 : ConfigStateGetRunCount(code2);
    if(!firstTime && code2 == CONFIGSTATE_IOERROR)
        nStartups = 0;
    FILE *f = 0;
    if((f = fopen(rcFile.c_str(), "w")) != 0)
    {
        fprintf(f, "%d\n", nStartups + 1);
        fclose(f);
        code = firstTime ? CONFIGSTATE_FIRSTTIME : CONFIGSTATE_SUCCESS;
    }
    else
        code = CONFIGSTATE_IOERROR;
}
Exemple #4
0
QString DesktopPrivate::themeName()
{
    /**
     * We try to parse the gtkrc file first
     * primarily to avoid resolving Gtk functions if
     * the KDE 3 "Qt" style is currently in use
     *
     */

	QString themeName;
    QString rcPaths = QString::fromLocal8Bit(getenv("GTK2_RC_FILES"));

    if (!rcPaths.isEmpty())
    {
        QStringList paths = rcPaths.split(QString::fromLatin1(":"));

        foreach (const QString &rcPath, paths)
        {
            if (!rcPath.isEmpty())
            {
                QFile rcFile(rcPath);

                if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text))
                {
                    QTextStream in(&rcFile);

                    while(!in.atEnd())
                    {
                        QString line = in.readLine();

                        if (line.contains(QString::fromLatin1("gtk-theme-name")))
                        {
                            line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1);
                            line.remove(QLatin1Char('\"'));
                            line = line.trimmed();
                            themeName = line;
                            break;
                        }
                    }
                }
            }

            if (!themeName.isEmpty())
                break;
        }
    }
Exemple #5
0
void FLEXplorer::ReadDefaultOptions()
{
    int int_result;
    std::string string_result;
#ifdef WIN32
    BRegistry reg(BRegistry::localMachine, FLEXPLOREREG);

    if (!reg.GetValue(FLEXPLORERBOOTSECTORFILE, string_result) &&
        !string_result.empty())
    {
        FlexFileContainer::bootSectorFile = string_result;
    }

    if (!reg.GetValue(FLEXPLORERTEXTFLAG, int_result))
    {
        FlexCopyManager::autoTextConversion = (int_result != 0);
    }
#endif
#ifdef UNIX
    std::string rcFileName;
    BEnvironment env;

    if (!env.GetValue("HOME", rcFileName))
    {
        rcFileName = ".";
    }

    rcFileName += PATHSEPARATORSTRING FLEXPLORERRC;
    BRcFile rcFile(rcFileName.c_str());

    if (!rcFile.GetValue(FLEXPLORERBOOTSECTORFILE, string_result) &&
        !string_result.empty())
    {
        FlexFileContainer::bootSectorFile = string_result;
    }

    if (!rcFile.GetValue(FLEXPLORERTEXTFLAG, int_result))
    {
        FlexCopyManager::autoTextConversion = (int_result != 0);
    }
#endif
}
Exemple #6
0
void Win32MakefileGenerator::processRcFileVar()
{
    if (Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
        return;

    if (((!project->values("VERSION").isEmpty())
        && project->values("RC_FILE").isEmpty()
        && project->values("RES_FILE").isEmpty()
        && !project->isActiveConfig("no_generated_target_info")
        && (project->isActiveConfig("shared") || !project->values("QMAKE_APP_FLAG").isEmpty()))
        || !project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty()){

        QByteArray rcString;
        QTextStream ts(&rcString, QFile::WriteOnly);

        QStringList vers = project->values("VERSION").first().split(".");
        for (int i = vers.size(); i < 4; i++)
            vers += "0";
        QString versionString = vers.join(".");

        QString companyName;
        if (!project->values("QMAKE_TARGET_COMPANY").isEmpty())
            companyName = project->values("QMAKE_TARGET_COMPANY").join(" ");

        QString description;
        if (!project->values("QMAKE_TARGET_DESCRIPTION").isEmpty())
            description = project->values("QMAKE_TARGET_DESCRIPTION").join(" ");

        QString copyright;
        if (!project->values("QMAKE_TARGET_COPYRIGHT").isEmpty())
            copyright = project->values("QMAKE_TARGET_COPYRIGHT").join(" ");

        QString productName;
        if (!project->values("QMAKE_TARGET_PRODUCT").isEmpty())
            productName = project->values("QMAKE_TARGET_PRODUCT").join(" ");
        else
            productName = project->values("TARGET").first();

        QString originalName = project->values("TARGET").first() + project->values("TARGET_EXT").first();
        int rcLang = project->intValue("RC_LANG", 1033);            // default: English(USA)
        int rcCodePage = project->intValue("RC_CODEPAGE", 1200);    // default: Unicode

        ts << "# if defined(UNDER_CE)" << endl;
        ts << "#  include <winbase.h>" << endl;
        ts << "# else" << endl;
        ts << "#  include <winver.h>" << endl;
        ts << "# endif" << endl;
        ts << endl;
        ts << "VS_VERSION_INFO VERSIONINFO" << endl;
        ts << "\tFILEVERSION " << QString(versionString).replace(".", ",") << endl;
        ts << "\tPRODUCTVERSION " << QString(versionString).replace(".", ",") << endl;
        ts << "\tFILEFLAGSMASK 0x3fL" << endl;
        ts << "#ifdef _DEBUG" << endl;
        ts << "\tFILEFLAGS VS_FF_DEBUG" << endl;
        ts << "#else" << endl;
        ts << "\tFILEFLAGS 0x0L" << endl;
        ts << "#endif" << endl;
        ts << "\tFILEOS VOS__WINDOWS32" << endl;
        if (project->isActiveConfig("shared"))
            ts << "\tFILETYPE VFT_DLL" << endl;
        else
            ts << "\tFILETYPE VFT_APP" << endl;
        ts << "\tFILESUBTYPE 0x0L" << endl;
        ts << "\tBEGIN" << endl;
        ts << "\t\tBLOCK \"StringFileInfo\"" << endl;
        ts << "\t\tBEGIN" << endl;
        ts << "\t\t\tBLOCK \""
           << QString("%1%2").arg(rcLang, 4, 16, QLatin1Char('0')).arg(rcCodePage, 4, 16, QLatin1Char('0'))
           << "\"" << endl;
        ts << "\t\t\tBEGIN" << endl;
        ts << "\t\t\t\tVALUE \"CompanyName\", \"" << companyName << "\\0\"" << endl;
        ts << "\t\t\t\tVALUE \"FileDescription\", \"" <<  description << "\\0\"" << endl;
        ts << "\t\t\t\tVALUE \"FileVersion\", \"" << versionString << "\\0\"" << endl;
        ts << "\t\t\t\tVALUE \"LegalCopyright\", \"" << copyright << "\\0\"" << endl;
        ts << "\t\t\t\tVALUE \"OriginalFilename\", \"" << originalName << "\\0\"" << endl;
        ts << "\t\t\t\tVALUE \"ProductName\", \"" << productName << "\\0\"" << endl;
        ts << "\t\t\tEND" << endl;
        ts << "\t\tEND" << endl;
        ts << "\t\tBLOCK \"VarFileInfo\"" << endl;
        ts << "\t\tBEGIN" << endl;
        ts << "\t\t\tVALUE \"Translation\", "
           << QString("0x%1").arg(rcLang, 4, 16, QLatin1Char('0'))
           << ", " << QString("%1").arg(rcCodePage, 4) << endl;
        ts << "\t\tEND" << endl;
        ts << "\tEND" << endl;
        ts << "/* End of Version info */" << endl;
        ts << endl;

        ts.flush();


        QString rcFilename = project->values("OUT_PWD").first()
                           + "/"
                           + project->values("TARGET").first()
                           + "_resource"
                           + ".rc";
        QFile rcFile(QDir::cleanPath(rcFilename));

        bool writeRcFile = true;
        if (rcFile.exists() && rcFile.open(QFile::ReadOnly)) {
            writeRcFile = rcFile.readAll() != rcString;
            rcFile.close();
        }
        if (writeRcFile) {
	    bool ok;
	    ok = rcFile.open(QFile::WriteOnly);
	    if (!ok) {
		// The file can't be opened... try creating the containing
		// directory first (needed for clean shadow builds)
		QDir().mkpath(QFileInfo(rcFile).path());
		ok = rcFile.open(QFile::WriteOnly);
	    }
	    if (!ok) {
		::fprintf(stderr, "Cannot open for writing: %s", rcFile.fileName().toLatin1().constData());
		::exit(1);
	    }
	    rcFile.write(rcString);
	    rcFile.close();
        }
        if (project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty())
            project->values("RC_FILE").insert(0, rcFile.fileName());
    }
    if (!project->values("RC_FILE").isEmpty()) {
        if (!project->values("RES_FILE").isEmpty()) {
            fprintf(stderr, "Both rc and res file specified.\n");
            fprintf(stderr, "Please specify one of them, not both.");
            exit(1);
        }
        QString resFile = project->values("RC_FILE").first();

        // if this is a shadow build then use the absolute path of the rc file
        if (Option::output_dir != qmake_getpwd()) {
            QFileInfo fi(resFile);
            project->values("RC_FILE").first() = fi.absoluteFilePath();
        }

        resFile.replace(".rc", Option::res_ext);
        project->values("RES_FILE").prepend(fileInfo(resFile).fileName());
        if (!project->values("OBJECTS_DIR").isEmpty()) {
            QString resDestDir;
            if (project->isActiveConfig("staticlib"))
                resDestDir = fileInfo(project->first("DESTDIR")).absoluteFilePath();
            else
                resDestDir = project->first("OBJECTS_DIR");
            resDestDir.append(Option::dir_sep);
            project->values("RES_FILE").first().prepend(resDestDir);
        }
        project->values("RES_FILE").first() = Option::fixPathToTargetOS(project->values("RES_FILE").first(), false, false);
	project->values("POST_TARGETDEPS") += project->values("RES_FILE");
        project->values("CLEAN_FILES") += project->values("RES_FILE");
    }
}
Exemple #7
0
void Win32MakefileGenerator::processRcFileVar()
{
    if (Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
        return;

    if (((!project->values("VERSION").isEmpty() || !project->values("RC_ICONS").isEmpty())
            && project->values("RC_FILE").isEmpty()
            && project->values("RES_FILE").isEmpty()
            && !project->isActiveConfig("no_generated_target_info")
            && (project->isActiveConfig("shared") || !project->values("QMAKE_APP_FLAG").isEmpty()))
            || !project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty()) {

        QByteArray rcString;
        QTextStream ts(&rcString, QFile::WriteOnly);

        QStringList vers = project->first("VERSION").toQString().split(".", QString::SkipEmptyParts);
        for (int i = vers.size(); i < 4; i++)
            vers += "0";
        QString versionString = vers.join('.');

        QStringList rcIcons;
        foreach (const ProString &icon, project->values("RC_ICONS"))
            rcIcons.append(fileFixify(icon.toQString(), FileFixifyAbsolute));

        QString companyName;
        if (!project->values("QMAKE_TARGET_COMPANY").isEmpty())
            companyName = project->values("QMAKE_TARGET_COMPANY").join(' ');

        QString description;
        if (!project->values("QMAKE_TARGET_DESCRIPTION").isEmpty())
            description = project->values("QMAKE_TARGET_DESCRIPTION").join(' ');

        QString copyright;
        if (!project->values("QMAKE_TARGET_COPYRIGHT").isEmpty())
            copyright = project->values("QMAKE_TARGET_COPYRIGHT").join(' ');

        QString productName;
        if (!project->values("QMAKE_TARGET_PRODUCT").isEmpty())
            productName = project->values("QMAKE_TARGET_PRODUCT").join(' ');
        else
            productName = project->first("TARGET").toQString();

        QString originalName = project->values("TARGET").first() + project->values("TARGET_EXT").first();
        int rcLang = project->intValue("RC_LANG", 1033);            // default: English(USA)
        int rcCodePage = project->intValue("RC_CODEPAGE", 1200);    // default: Unicode

        ts << "# if defined(UNDER_CE)\n";
        ts << "#  include <winbase.h>\n";
        ts << "# else\n";
        ts << "#  include <winver.h>\n";
        ts << "# endif\n";
        ts << endl;
        if (!rcIcons.isEmpty()) {
            for (int i = 0; i < rcIcons.size(); ++i)
                ts << QString("IDI_ICON%1\tICON\tDISCARDABLE\t%2").arg(i + 1).arg(cQuoted(rcIcons[i])) << endl;
            ts << endl;
        }
        ts << "VS_VERSION_INFO VERSIONINFO\n";
        ts << "\tFILEVERSION " << QString(versionString).replace(".", ",") << endl;
        ts << "\tPRODUCTVERSION " << QString(versionString).replace(".", ",") << endl;
        ts << "\tFILEFLAGSMASK 0x3fL\n";
        ts << "#ifdef _DEBUG\n";
        ts << "\tFILEFLAGS VS_FF_DEBUG\n";
        ts << "#else\n";
        ts << "\tFILEFLAGS 0x0L\n";
        ts << "#endif\n";
        ts << "\tFILEOS VOS__WINDOWS32\n";
        if (project->isActiveConfig("shared"))
            ts << "\tFILETYPE VFT_DLL\n";
        else
            ts << "\tFILETYPE VFT_APP\n";
        ts << "\tFILESUBTYPE 0x0L\n";
        ts << "\tBEGIN\n";
        ts << "\t\tBLOCK \"StringFileInfo\"\n";
        ts << "\t\tBEGIN\n";
        ts << "\t\t\tBLOCK \""
           << QString("%1%2").arg(rcLang, 4, 16, QLatin1Char('0')).arg(rcCodePage, 4, 16, QLatin1Char('0'))
           << "\"\n";
        ts << "\t\t\tBEGIN\n";
        ts << "\t\t\t\tVALUE \"CompanyName\", \"" << companyName << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"FileDescription\", \"" <<  description << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"FileVersion\", \"" << versionString << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"LegalCopyright\", \"" << copyright << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"OriginalFilename\", \"" << originalName << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"ProductName\", \"" << productName << "\\0\"\n";
        ts << "\t\t\t\tVALUE \"ProductVersion\", \"" << versionString << "\\0\"\n";
        ts << "\t\t\tEND\n";
        ts << "\t\tEND\n";
        ts << "\t\tBLOCK \"VarFileInfo\"\n";
        ts << "\t\tBEGIN\n";
        ts << "\t\t\tVALUE \"Translation\", "
           << QString("0x%1").arg(rcLang, 4, 16, QLatin1Char('0'))
           << ", " << QString("%1").arg(rcCodePage, 4) << endl;
        ts << "\t\tEND\n";
        ts << "\tEND\n";
        ts << "/* End of Version info */\n";
        ts << endl;

        ts.flush();


        QString rcFilename = project->values("OUT_PWD").first()
                             + "/"
                             + project->values("TARGET").first()
                             + "_resource"
                             + ".rc";
        QFile rcFile(QDir::cleanPath(rcFilename));

        bool writeRcFile = true;
        if (rcFile.exists() && rcFile.open(QFile::ReadOnly)) {
            writeRcFile = rcFile.readAll() != rcString;
            rcFile.close();
        }
        if (writeRcFile) {
            bool ok;
            ok = rcFile.open(QFile::WriteOnly);
            if (!ok) {
                // The file can't be opened... try creating the containing
                // directory first (needed for clean shadow builds)
                QDir().mkpath(QFileInfo(rcFile).path());
                ok = rcFile.open(QFile::WriteOnly);
            }
            if (!ok) {
                ::fprintf(stderr, "Cannot open for writing: %s", rcFile.fileName().toLatin1().constData());
                ::exit(1);
            }
            rcFile.write(rcString);
            rcFile.close();
        }
        if (project->values("QMAKE_WRITE_DEFAULT_RC").isEmpty())
            project->values("RC_FILE").insert(0, rcFile.fileName());
    }
Exemple #8
0
static int
set_param(char *name, char *value)
{
    struct param_ptr *p;
    double ppc;

    if (value == NULL)
	return 0;
    p = search_param(name);
    if (p == NULL)
	return 0;
    switch (p->type) {
    case P_INT:
	if (atoi(value) >= 0)
	    *(int *)p->varptr = (p->inputtype == PI_ONOFF)
		? str_to_bool(value, *(int *)p->varptr) : atoi(value);
	break;
    case P_NZINT:
	if (atoi(value) > 0)
	    *(int *)p->varptr = atoi(value);
	break;
    case P_SHORT:
	*(short *)p->varptr = (p->inputtype == PI_ONOFF)
	    ? str_to_bool(value, *(short *)p->varptr) : atoi(value);
	break;
    case P_CHARINT:
	*(char *)p->varptr = (p->inputtype == PI_ONOFF)
	    ? str_to_bool(value, *(char *)p->varptr) : atoi(value);
	break;
    case P_CHAR:
	*(char *)p->varptr = value[0];
	break;
    case P_STRING:
	*(char **)p->varptr = value;
	break;
#if defined(USE_SSL) && defined(USE_SSL_VERIFY)
    case P_SSLPATH:
	if (value != NULL && value[0] != '\0')
	    *(char **)p->varptr = rcFile(value);
	else
	    *(char **)p->varptr = NULL;
	ssl_path_modified = 1;
	break;
#endif
#ifdef USE_COLOR
    case P_COLOR:
	*(int *)p->varptr = str_to_color(value);
	break;
#endif
#ifdef USE_M17N
    case P_CODE:
	*(wc_ces *) p->varptr =
	    wc_guess_charset_short(value, *(wc_ces *) p->varptr);
	break;
#endif
    case P_PIXELS:
	ppc = atof(value);
	if (ppc >= MINIMUM_PIXEL_PER_CHAR && ppc <= MAXIMUM_PIXEL_PER_CHAR * 2)
	    *(double *)p->varptr = ppc;
	break;
    case P_SCALE:
	ppc = atof(value);
	if (ppc >= 10 && ppc <= 1000)
	    *(double *)p->varptr = ppc;
	break;
    }
    return 1;
}
Exemple #9
0
void
init_rc(void)
{
    int i;
    struct stat st;
    FILE *f;

    if (rc_dir != NULL)
	goto open_rc;

    rc_dir = expandPath(RC_DIR);
    i = strlen(rc_dir);
    if (i > 1 && rc_dir[i - 1] == '/')
	rc_dir[i - 1] = '\0';

#ifdef USE_M17N
    display_charset_str = wc_get_ces_list();
    document_charset_str = display_charset_str;
    system_charset_str = display_charset_str;
#endif

    if (stat(rc_dir, &st) < 0) {
	if (errno == ENOENT) {	/* no directory */
	    if (do_mkdir(rc_dir, 0700) < 0) {
		fprintf(stderr, "Can't create config directory (%s)!", rc_dir);
		goto rc_dir_err;
	    }
	    else {
		stat(rc_dir, &st);
	    }
	}
	else {
	    fprintf(stderr, "Can't open config directory (%s)!", rc_dir);
	    goto rc_dir_err;
	}
    }
    if (!S_ISDIR(st.st_mode)) {
	/* not a directory */
	fprintf(stderr, "%s is not a directory!", rc_dir);
	goto rc_dir_err;
    }
    if (!(st.st_mode & S_IWUSR)) {
	fprintf(stderr, "%s is not writable!", rc_dir);
	goto rc_dir_err;
    }
    no_rc_dir = FALSE;
    tmp_dir = rc_dir;

    if (config_file == NULL)
	config_file = rcFile(CONFIG_FILE);

    create_option_search_table();

  open_rc:
    /* open config file */
    if ((f = fopen(etcFile(W3MCONFIG), "rt")) != NULL) {
	interpret_rc(f);
	fclose(f);
    }
    if ((f = fopen(confFile(CONFIG_FILE), "rt")) != NULL) {
	interpret_rc(f);
	fclose(f);
    }
    if ((f = fopen(config_file, "rt")) != NULL) {
	interpret_rc(f);
	fclose(f);
    }
    return;

  rc_dir_err:
    no_rc_dir = TRUE;
    if (((tmp_dir = getenv("TMPDIR")) == NULL || *tmp_dir == '\0') &&
	((tmp_dir = getenv("TMP")) == NULL || *tmp_dir == '\0') &&
	((tmp_dir = getenv("TEMP")) == NULL || *tmp_dir == '\0'))
	tmp_dir = "/tmp";
}
Exemple #10
0
///////////////////////////////////////////////////////////////////////
// check for, and load resources
///////////////////////////////////////////////////////////////////////
int PuffRC::loadResources(char *modelArg, const char *type) {
  RCType rcType;
  int lineNumber = 0;
  
  // open rcfile, we already know it exists from PuffRC::init()
  std::ifstream rcFile(fileName, std::ios::in);
  
  // set type of resource we are looking for
  if (strncmp(type, "model=", 6) == 0) rcType = PUFFRC_MODEL;
  if (strncmp(type, "dem=", 5) == 0) rcType = PUFFRC_DEM;
  
  // begin parsing 
  char *line = new char[1024];	// buffer to hold each line from file 
  std::string text;  // string copy of the buffer; easier to parse
  std::string param, value, tmpMask;
  
  while (rcFile.getline(line, 1024, '\n') != NULL) {
    //  read the next line if it is a continuation of the previous
    while (line[strlen(line)-1] == '\\') {
      // create another buffer
      char *nextLine = new char[1024];
      // read the line in
      rcFile.getline(nextLine, 1024, '\n');
      // replace the '\' with a space
      line[strlen(line)-1] = ' ';
      // add a return to mark the end of the line
      line[strlen(line)] = '\0';
      // concantenate without overwriting the buffer
      strncat(line,nextLine,1024-strlen(line));
      }
    lineNumber++;
    text = line;
    // skip if not "model=..."
    param=type;
    param.append(modelArg);
    // append a space so two models do not have similar name (i.e avn
    // and avn-anl).
    param.append(" "); 
    if (text.find(param) == std::string::npos) continue;
    // tokenize the line
    std::vector<std::string> valuePairs;
    Tokenize(text, valuePairs, " ");
    // iterate through the vector of param/value pairs
    std::vector<std::string>::const_iterator p;
    for(p=valuePairs.begin(); p!=valuePairs.end(); ++p) {
      param = (*p).substr(0,(*p).find_first_of("="));
      value = (*p).substr((*p).find_first_of("=")+1,(*p).length());
      switch(rcType) {
        case PUFFRC_MODEL:
        // pseudo-switch on param
        if(param == "model") 
	{ 
	  modelName=value; 
	} else if(param == "path") { 
	  dataPath=value; 
		envReplace(&dataPath);
	} else if(param == "mask") {
	  tmpMask=value; 
	} else if(param == "record") { 
	  if (value == "yes" || value == "true" ||
	      value == "Yes" || value == "True" ||
	      value == "YES" || value == "TRUE" )  
	  { 
	    fourDdata = true;
	  } else if (value == "no" || value == "false" ||
	             value == "No" || value == "False" ||
		     value == "NO" || value == "FALSE") { 
            fourDdata = false;
	  } else {
	    std::cerr << "unknown parameter/value pair: " << param <<"="<<value
	    << "\n Value should be \"yes\" or \"no\"" << std::endl;
	  }
	} else if(param == "var") {
          if (value.find("T") != std::string::npos) Tmask=tmpMask;
          if (value.find("u") != std::string::npos) umask=tmpMask;
          if (value.find("U") != std::string::npos) umask=tmpMask;
          if (value.find("v") != std::string::npos) vmask=tmpMask;
          if (value.find("V") != std::string::npos) vmask=tmpMask;
          if (value.find("z") != std::string::npos) zmask=tmpMask;
          if (value.find("Z") != std::string::npos) zmask=tmpMask;
	} else if(param == "varTname") {
	  varTname = value;
        } else if(param == "varUname") {
	  varUname = value;
	} else if(param == "varVname") {
	  varVname = value;
	} else if(param == "varZname") {
	  varZname = value;
	} else {
	  std::cerr << "ERROR: bad resource file specification\n"
	  << "unknown parameter value: " << param << " on line "
	  << lineNumber << std::endl;
	  return 1;
	  }  
	break;
	case PUFFRC_DEM:
	// pseudo-switch on param
	if(param == "dem") 
	{
	  demName=value;
	} else if(param == "path") {
	  demPath=value;
		envReplace(&demPath);
	} else {
	  std::cerr << "ERROR: bad resource file specification\n"
	  << "unknown parameter value: " << param << " on line "
	  << lineNumber << std::endl;
	  return 1;
	  }  
	break;
	default:
	break;
        }
      }

    } // end while reading file
    
  rcFile.close();
  
  delete[] line;

  // append '/' to path if necessary
  if (dataPath[dataPath.length()-1] != '/') dataPath.append("/");  
  if (modelName.length() == 0) {
    std::cerr << "ERROR: could not find resource information for model " << 
             modelArg << " in file \"" << fileName << "\"" << std::endl;
    return 1;
    }
    
  return 0;
}
Exemple #11
0
void FlexOptionManager::GetOptions(
    struct sGuiOptions *pGuiOptions,
    struct sOptions *pOptions)
{
    int int_result;
    std::string string_result;

#ifdef _WIN32
    BRegistry reg(BRegistry::currentUser, FLEXEMUREG);

    reg.GetValue(FLEXDISKDIR, pOptions->disk_dir);
    reg.GetValue(FLEXDISK0, pOptions->drive[0]);
    reg.GetValue(FLEXDISK1, pOptions->drive[1]);
    reg.GetValue(FLEXDISK2, pOptions->drive[2]);
    reg.GetValue(FLEXDISK3, pOptions->drive[3]);
    reg.GetValue(FLEXMDCRDRIVE0, pOptions->mdcrDrives[0]);
    reg.GetValue(FLEXMDCRDRIVE1, pOptions->mdcrDrives[1]);
    reg.GetValue(FLEXMONITOR, pOptions->hex_file);
    reg.GetValue(FLEXCOLOR, pGuiOptions->color);

    if (!reg.GetValue(FLEXDOCDIR, pGuiOptions->doc_dir))
        if (!reg.GetValue(FLEXNCOLORS, int_result))
        {
            if (int_result == 2 || int_result == 8 || int_result == 64)
            {
                pGuiOptions->nColors = int_result;
            }
        }

    if (!reg.GetValue(FLEXSCREENWIDTH, int_result))
    {
        if (int_result < 1)
        {
            int_result = 1;
        }

        if (int_result > MAX_PIXELSIZEX)
        {
            int_result = MAX_PIXELSIZEX;
        }

        pGuiOptions->pixelSizeX = int_result;
    }

    if (!reg.GetValue(FLEXSCREENHEIGHT, int_result))
    {
        if (int_result < 1)
        {
            int_result = 1;
        }

        if (int_result > MAX_PIXELSIZEY)
        {
            int_result = MAX_PIXELSIZEY;
        }

        pGuiOptions->pixelSizeY = int_result;
    }

    if (!reg.GetValue(FLEXINVERSE, int_result))
    {
        pGuiOptions->isInverse = (int_result != 0);
    }

    if (!reg.GetValue(FLEXRAMEXTENSION, int_result))
    {
        pOptions->isRamExtension = (int_result != 0);
    }

    if (!reg.GetValue(FLEXHIMEM, int_result))
    {
        pOptions->isHiMem = (int_result != 0);
    }

    if (!reg.GetValue(FLEXFLEXIBLEMMU, int_result))
    {
        pOptions->isFlexibleMmu = (int_result != 0);
    }

    if (!reg.GetValue(FLEXEUROCOM2V5, int_result))
    {
        pOptions->isEurocom2V5 = (int_result != 0);
    }

    if (!reg.GetValue(FLEXUNDOCUMENTED, int_result))
    {
        pOptions->use_undocumented = (int_result != 0);
    }

    if (!reg.GetValue(FLEXRTC, int_result))
    {
        pOptions->useRtc = (int_result != 0);
    }

    if (!reg.GetValue(FLEXRTC, int_result))
    {
        pOptions->useRtc = (int_result != 0);
    }

    if (!reg.GetValue(FLEXFREQUENCY, string_result))
    {
        try
        {
            pOptions->frequency = (stof(string_result));
        }
        catch(std::exception &)
        {
            // Intentionally ignore value if not convertible to float.
        }
    }
#endif
#ifdef UNIX
    std::string rcFileName;
    BEnvironment env;

    if (!env.GetValue("HOME", rcFileName))
    {
        rcFileName = ".";
    }

    rcFileName += PATHSEPARATORSTRING FLEXEMURC;
    BRcFile rcFile(rcFileName.c_str());
    rcFile.GetValue(FLEXDISKDIR, pOptions->disk_dir);
    rcFile.GetValue(FLEXDISK0, pOptions->drive[0]);
    rcFile.GetValue(FLEXDISK1, pOptions->drive[1]);
    rcFile.GetValue(FLEXDISK2, pOptions->drive[2]);
    rcFile.GetValue(FLEXDISK3, pOptions->drive[3]);
    rcFile.GetValue(FLEXMDCRDRIVE0, pOptions->mdcrDrives[0]);
    rcFile.GetValue(FLEXMDCRDRIVE1, pOptions->mdcrDrives[1]);
    rcFile.GetValue(FLEXMONITOR, pOptions->hex_file);
    rcFile.GetValue(FLEXCOLOR, pGuiOptions->color);
    rcFile.GetValue(FLEXDOCDIR, pGuiOptions->doc_dir);

    if (!rcFile.GetValue(FLEXNCOLORS, int_result))
    {
        if (int_result == 2 || int_result == 8 || int_result == 64)
        {
            pGuiOptions->nColors = int_result;
        }
    }

    if (!rcFile.GetValue(FLEXSCREENWIDTH, int_result))
    {
        if (int_result < 1)
        {
            int_result = 1;
        }

        if (int_result > MAX_PIXELSIZEX)
        {
            int_result = MAX_PIXELSIZEX;
        }

        pGuiOptions->pixelSizeX = int_result;
    }

    if (!rcFile.GetValue(FLEXSCREENHEIGHT, int_result))
    {
        if (int_result < 1)
        {
            int_result = 1;
        }

        if (int_result > MAX_PIXELSIZEY)
        {
            int_result = MAX_PIXELSIZEY;
        }

        pGuiOptions->pixelSizeY = int_result;
    }

    if (!rcFile.GetValue(FLEXINVERSE, int_result))
    {
        pGuiOptions->isInverse = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXRAMEXTENSION, int_result))
    {
        pOptions->isRamExtension = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXHIMEM, int_result))
    {
        pOptions->isHiMem = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXFLEXIBLEMMU, int_result))
    {
        pOptions->isFlexibleMmu = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXEUROCOM2V5, int_result))
    {
        pOptions->isEurocom2V5 = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXUNDOCUMENTED, int_result))
    {
        pOptions->use_undocumented = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXRTC, int_result))
    {
        pOptions->useRtc = (int_result != 0);
    }

    if (!rcFile.GetValue(FLEXFREQUENCY, string_result))
    {
        try
        {
            pOptions->frequency = (stof(string_result));
        }
        catch(std::exception &)
        {
            // Intentionally ignore value if not convertible to float.
        }
    }
#endif
} // GetOptions
Exemple #12
0
void FlexOptionManager::WriteOptions(
    struct sGuiOptions *pGuiOptions,
    struct sOptions *pOptions,
    bool  ifNotExists /* = false */
)
{
#ifdef _WIN32
    std::string   v;

    BRegistry reg(BRegistry::currentUser, FLEXEMUREG);

    if (ifNotExists && reg.GetValue(FLEXVERSION, v) == ERROR_SUCCESS)
    {
        return;
    }

    reg.SetValue(FLEXINVERSE, pGuiOptions->isInverse ? 1 : 0);
    reg.SetValue(FLEXRAMEXTENSION, pOptions->isRamExtension ? 1 : 0);
    reg.SetValue(FLEXHIMEM, pOptions->isHiMem ? 1 : 0);
    reg.SetValue(FLEXFLEXIBLEMMU, pOptions->isFlexibleMmu ? 1 : 0);
    reg.SetValue(FLEXEUROCOM2V5, pOptions->isEurocom2V5 ? 1 : 0);
    reg.SetValue(FLEXUNDOCUMENTED, pOptions->use_undocumented ? 1 : 0);
    reg.SetValue(FLEXRTC, pOptions->useRtc ? 1 : 0);
    reg.SetValue(FLEXCOLOR, pGuiOptions->color.c_str());
    reg.SetValue(FLEXNCOLORS, pGuiOptions->nColors);
    reg.SetValue(FLEXDOCDIR, pGuiOptions->doc_dir.c_str());
    reg.SetValue(FLEXSCREENWIDTH, pGuiOptions->pixelSizeX);
    reg.SetValue(FLEXSCREENHEIGHT, pGuiOptions->pixelSizeY);
    reg.SetValue(FLEXMONITOR, pOptions->hex_file.c_str());
    reg.SetValue(FLEXDISKDIR, pOptions->disk_dir.c_str());
    reg.SetValue(FLEXDISK0, pOptions->drive[0].c_str());
    reg.SetValue(FLEXDISK1, pOptions->drive[1].c_str());
    reg.SetValue(FLEXDISK2, pOptions->drive[2].c_str());
    reg.SetValue(FLEXDISK3, pOptions->drive[3].c_str());
    reg.SetValue(FLEXMDCRDRIVE0, pOptions->mdcrDrives[0].c_str());
    reg.SetValue(FLEXMDCRDRIVE1, pOptions->mdcrDrives[1].c_str());
    reg.SetValue(FLEXFREQUENCY, std::to_string(pOptions->frequency));
    reg.SetValue(FLEXVERSION, VERSION);
#endif
#ifdef UNIX
    std::string rcFileName;
    BEnvironment env;

    if (!env.GetValue("HOME", rcFileName))
    {
        rcFileName = ".";
    }

    rcFileName += PATHSEPARATORSTRING FLEXEMURC;

    if (ifNotExists && access(rcFileName.c_str(), F_OK) == 0)
    {
        return;
    }

    BRcFile rcFile(rcFileName.c_str());
    rcFile.Initialize(); // truncate file
    rcFile.SetValue(FLEXINVERSE, pGuiOptions->isInverse ? 1 : 0);
    rcFile.SetValue(FLEXCOLOR, pGuiOptions->color.c_str());
    rcFile.SetValue(FLEXNCOLORS, pGuiOptions->nColors);
    rcFile.SetValue(FLEXDOCDIR, pGuiOptions->doc_dir.c_str());
    rcFile.SetValue(FLEXSCREENWIDTH, pGuiOptions->pixelSizeX);
    rcFile.SetValue(FLEXSCREENHEIGHT, pGuiOptions->pixelSizeY);
    rcFile.SetValue(FLEXMONITOR, pOptions->hex_file.c_str());
    rcFile.SetValue(FLEXDISKDIR, pOptions->disk_dir.c_str());
    rcFile.SetValue(FLEXDISK0, pOptions->drive[0].c_str());
    rcFile.SetValue(FLEXDISK1, pOptions->drive[1].c_str());
    rcFile.SetValue(FLEXDISK2, pOptions->drive[2].c_str());
    rcFile.SetValue(FLEXDISK3, pOptions->drive[3].c_str());
    rcFile.SetValue(FLEXMDCRDRIVE0, pOptions->mdcrDrives[0].c_str());
    rcFile.SetValue(FLEXMDCRDRIVE1, pOptions->mdcrDrives[1].c_str());
    rcFile.SetValue(FLEXRAMEXTENSION, pOptions->isRamExtension ? 1 : 0);
    rcFile.SetValue(FLEXHIMEM, pOptions->isHiMem ? 1 : 0);
    rcFile.SetValue(FLEXFLEXIBLEMMU, pOptions->isFlexibleMmu ? 1 : 0);
    rcFile.SetValue(FLEXEUROCOM2V5, pOptions->isEurocom2V5 ? 1 : 0);
    rcFile.SetValue(FLEXUNDOCUMENTED, pOptions->use_undocumented ? 1 : 0);
    rcFile.SetValue(FLEXRTC, pOptions->useRtc ? 1 : 0);
    rcFile.SetValue(FLEXFREQUENCY, std::to_string(pOptions->frequency).c_str());
#endif
} /* WriteOptions */