/* * Function to initialize global config struct */ static Config initConfig(CMap cmap) { char * val; int i = 0; Config c = mallocConfig(); FILE * file = fopen(DEFAULT_OPTIONS_FILENAME, "r"); if (file == NULL) { die("Default config file not found.", 2); } defCMap = getCMap(file); /* Load default config map from file */ for (i = 0; i < ARYLEN; ++i) { /* Load default values into config ary 1st */ config[i].value = getCValue(defCMap, config[i].keyword); } for (i = 0; i < ARYLEN; ++i) { val = getCValue(cmap, config[i].keyword); /* get user config value */ if (val != NULL) { if (!setConfigValue(c, i, val)) /* check & set configuration */ printErr("Invalid parameter value: ", "initConfig()", 1); /* ... or log an error */ } else if (!setConfigValue(c, i, config[i].value)) printErr("Error in default config file: ", "initConfig()", 1); } fclose(file); return c; }
void readConfigFile() { char line[128]; char *ptr, *savePtr; char *key, *value; FILE *cfgFile = fopen("/etc/udp2can.conf", "r"); if (cfgFile == NULL) { fprintf(stderr, "can't open config file: %d, %s\n", errno, strerror(errno)); exit(EXIT_FAILURE); } while ( fgets( line, sizeof line, cfgFile ) != NULL ) { ptr = line; while (isspace(*ptr) ) ptr++; if ((*ptr == '#') || (*ptr == 0)) continue; key = strtok_r(ptr, "\t ", &savePtr); if (key) { value = strtok_r(NULL, "\t\n ", &savePtr); if (value) { setConfigValue(key, value); } } } fclose(cfgFile); }
void Triggerconf::setConfigValue (string path, string value) { if (! checkItemCount (path, 3)) return; STRING_LIST items = tokenize (path); setConfigValue (items[0], items[1], items[2], value); }
void setConfigValue(const std::string &configKey, uint32 value) { std::stringstream stream; std::string val; stream << value; stream >> val; setConfigValue(configKey, val); return; }
void ZLStringOption::setValue(const std::string &value) { if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(myValue); } }
void ZLDoubleOption::setValue(double value) { if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(doubleToString(myValue)); } }
void ZLIntegerOption::setValue(long value) { if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(integerToString(myValue)); } }
void ZLColorOption::setValue(ZLColor value) { if (myIsSynchronized && (myIntValue == value.intValue())) { return; } myIntValue = value.intValue(); myIsSynchronized = true; if (myIntValue == myDefaultIntValue) { unsetConfigValue(); } else { setConfigValue(integerToString(myIntValue)); } }
void ZLBooleanOption::setValue(bool value) { if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(booleanToString(myValue)); } }
void ZLIntegerRangeOption::setValue(long value) { value = std::max(std::min(myMaxValue, value), myMinValue); if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(integerToString(myValue)); } }
int setConfigValueByName(char *name, char *value) { int param; for(param = 0; param < (sizeof(config_params)/sizeof(char*)); param++) { if(strstr(config_params[param],name)) { setConfigValue(param, value); return 0; } } return 1; }
void setConfigValue(const std::string &configKey, uint32 value) { setConfigValue(configKey, gcString("{0}", value).c_str()); return; }
static int loadConfig(char *conf) { FILE *config_file; char line[120]; char value[100]; char *lpos; int param; /* set everything to zero */ memset(&config, 0, sizeof(config)); /* default values */ config.database_port = MYSQL_PORT; config.mpd_port = MPD_PORT; strcpy(config.pid_file, PID_FILE); strcpy(config.logfile,LOG_FILE); config.led_shift_speed = 15000; config.serial_activated = 0; config.rkeys.music_on_hifi_on = 50; config.rkeys.everything_off = 58; config.rkeys.light_on = 66; config.rkeys.light_off[0] = 74; config.rkeys.mpd_play_pause = 51; config.rkeys.mpd_random = 59; config.rkeys.mpd_prev = 67; config.rkeys.mpd_next = 75; config.rkeys.hifi_on_off = 52; config.rkeys.brightlight = 60; config.rkeys.red = 53; config.rkeys.green = 61; config.rkeys.blue = 69; config.rkeys.light_off[1] = 77; config.rkeys.light_single_off[0] = 78; config.rkeys.light_single_off[1] = 79; config.rkeys.light_single_off[2] = 80; config.rkeys.red_single[0] = 54; config.rkeys.red_single[1] = 55; config.rkeys.red_single[2] = 56; config.rkeys.green_single[0] = 62; config.rkeys.green_single[1] = 63; config.rkeys.green_single[2] = 64; config.rkeys.blue_single[0] = 70; config.rkeys.blue_single[1] = 71; config.rkeys.blue_single[2] = 72; config.rkeys.ledmatrix_toggle = 57; config.rkeys.open_door = 65; config.rkeys.dockstar_on = 73; config.rkeys.dockstar_off = 81; config.security_time_to_active = 60; config.security_time_before_alarm = 60; config.remote_activated = 1; config_file = fopen(conf,"r"); if(!config_file) { return 0; } /* step through every line */ while(fgets(line, sizeof(line), config_file) != NULL) { /* skip comments and empty lines */ if(line[0] == '#' || line[0] == '\n') continue; for(param = 0; param < (sizeof(config_params)/sizeof(char*)); param++) { /* if param name not at the beginning of line */ if(strstr(line,config_params[param]) != line) continue; /* go beyond the = */ if(!(lpos = strstr(line, "="))) continue; /* go to the beginning of value * only whitespaces are skipped, no tabs */ do lpos++; while(*lpos == ' '); strcpy(value, lpos); /* throw away carriage return * might only work for *nix */ lpos = strchr(value,'\n'); *lpos = 0; setConfigValue(param, value); } } fclose(config_file); return 1; }
void ProgramOptions::setHomeQFDirectory(const QString &dir) { setConfigValue("quickfit/homedir", dir); }
void CFEManager::saveSettings(bool write) { configfile.clear(); satellite_map_t &satlist = CServiceManager::getInstance()->SatelliteList(); for(fe_map_iterator_t it = femap.begin(); it != femap.end(); it++) { CFrontend * fe = it->second; frontend_config_t & fe_config = fe->getConfig(); INFO("fe%d", fe->fenumber); setConfigValue(fe, "diseqcType", fe_config.diseqcType); setConfigValue(fe, "diseqcRepeats", fe_config.diseqcRepeats); setConfigValue(fe, "motorRotationSpeed", fe_config.motorRotationSpeed); setConfigValue(fe, "highVoltage", fe_config.highVoltage); setConfigValue(fe, "uni_scr", fe_config.uni_scr); setConfigValue(fe, "uni_qrg", fe_config.uni_qrg); setConfigValue(fe, "diseqc_order", fe_config.diseqc_order); setConfigValue(fe, "use_usals", fe_config.use_usals); setConfigValue(fe, "rotor_swap", fe_config.rotor_swap); setConfigValue(fe, "lastSatellitePosition", fe->getRotorSatellitePosition()); setConfigValue(fe, "mode", fe->getMode()); setConfigValue(fe, "master", fe->getMaster()); std::vector<int> satList; satellite_map_t satellites = fe->getSatellites(); for(sat_iterator_t sit = satellites.begin(); sit != satellites.end(); ++sit) { if (sit->second.configured) { sat_iterator_t tit = satlist.find(sit->first); if (tit != satlist.end()) sit->second.use_in_scan = tit->second.use_in_scan; satList.push_back(sit->first); setSatelliteConfig(fe, sit->second); } } char cfg_key[81]; sprintf(cfg_key, "fe%d_satellites", fe->fenumber); configfile.setInt32Vector(cfg_key, satList); } if (write && configfile.getModifiedFlag()) { config_exist = configfile.saveConfig(FECONFIGFILE); //configfile.setModifiedFlag(false); } }