示例#1
0
gboolean
get_verbose ()
{
	gboolean verbose;
	gchar *file;
    config_t config;

    file = g_strconcat (g_getenv ("HOME"),
                               "/.config/gjackctl/gjackctl.conf",
                               NULL);

	config_init (&config);
	config_read_file (&config, file);
	
	if (config_lookup_bool (&config, "gjackctl.server.verbose", &verbose) == CONFIG_FALSE)
    {
        config_setting_t *group;
        config_setting_t *setting;
        
        g_print ("Verbose config option not available\n");
        g_print ("Creating config setting now...\n");

        group = config_lookup (&config, "gjackctl.server");

        setting = config_setting_add (group, "verbose", CONFIG_TYPE_BOOL);
        config_setting_set_bool (setting, FALSE);
        config_write_file (&config, file);       
    }

	if (verbose == FALSE)
	{
		config_destroy (&config);

		return FALSE;
	}
	else
    {
        config_destroy (&config);	

        return TRUE;
   	}
}
示例#2
0
/**
 * Opens a file for writing cluto format
 * @param fn File name
 * @return number of regular files
 */
int output_cluto_open(char *fn)
{
    assert(fn);
    cfg_int bits;

    f = fopen(fn, "w");
    if (!f) {
        error("Could not open output file '%s'.", fn);
        return FALSE;
    }

    config_lookup_bool(&cfg, "output.skip_null", &skip_null);
    config_lookup_int(&cfg, "features.hash_bits", &bits);
    cols = 1 << bits;

    /* Write dummy header. We fix it later */
    fprintf(f, "%12ld %12ld %12ld\n", rows, cols, entries);

    return TRUE;
}
ModBusReader::ModBusReader(config_t cfg)
{
	if(!config_lookup_bool(&cfg, "main.debug", &this->debug)) {
		this->debug = false;
	}
	
	if(!config_lookup_string(&cfg, "reader.port", &this->_address)) {
		throw "Reader port is not defined";
	}
	if(!config_lookup_int(&cfg, "reader.baud_rate", &this->baud)) {
		baud = 115200;
	}
	if(!config_lookup_int(&cfg, "reader.slave_id", &this->slave_id)) {
		throw "Reader slave_id is not defined";
	}

	if(!config_lookup_int(&cfg, "reader.register_number", &this->register_number)) {
		throw "Reader register_number is not defined";
	}
}
示例#4
0
文件: fvec.c 项目: MLDroid/sally
/*
 * Internal: Allocates and extracts a feature vector from a string
 * without postprocessing but blended n-grams
 * @param x String of bytes (with space delimiters)
 * @param l Length of sequence
 * @return feature vector
 */
fvec_t *fvec_extract_intern(char *x, int l)
{
    int blend;
    cfg_int i, n;

    /* Get config */
    config_lookup_bool(&cfg, "features.ngram_blend", &blend);
    config_lookup_int(&cfg, "features.ngram_len", &n);

    /* Extract n-grams */
    fvec_t *fv = fvec_extract_intern2(x, l, n);

    /* Blended n-grams */
    for (i = 1; blend && i < n; i++) {
        fvec_t *fx = fvec_extract_intern2(x, l, i);
        fvec_add(fv, fx);
        fvec_destroy(fx);
    }

    return fv;
}
示例#5
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_weapons()
{
        config_setting_t *cfg;
        int i, j;
        char sname[100];
        const char *value;

        cfg = config_lookup(cf, "weapon");
        i = config_setting_length(cfg);
        printf("Parsing weapon file... We have %d weapons", i);
        for(j=0;j<i;j++) {
                obj_t *o;
                int x;

                o = (obj_t *) gtmalloc(sizeof(obj_t));

                sprintf(sname, "weapon.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(o->basename, value);

                sprintf(sname, "weapon.[%d].type", j);
                config_lookup_string(cf, sname, &value);
                if(!strcmp(value, "sword")) {
                        o->flags |= OF_SWORD;
                        o->skill  = SKILL_SWORD;
                } else if(!strcmp(value, "axe")) {
                        o->flags |= OF_AXE;
                        o->skill  = SKILL_AXE;
                } else if(!strcmp(value, "knife")) {
                        o->flags |= OF_KNIFE;
                        o->skill  = SKILL_KNIFE;
                } else if(!strcmp(value, "stick")) {
                        o->flags |= OF_STICK;
                        o->skill  = SKILL_STICK;
                } else if(!strcmp(value, "mace")) {
                        o->flags |= OF_MACE;
                        o->skill  = SKILL_MACE;
                } if(!strcmp(value, "hammer")) {
                        o->flags |= OF_HAMMER;
                        o->skill  = SKILL_MACE;
                }

                o->type   = OT_WEAPON;

                sprintf(sname, "weapon.[%d].dice", j);
                config_lookup_int(cf, sname, &x);
                o->dice = x;
                sprintf(sname, "weapon.[%d].sides", j);
                config_lookup_int(cf, sname, &x);
                o->sides = x;

                sprintf(sname, "weapon.[%d].unique", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_UNIQUE);

                sprintf(sname, "weapon.[%d].rarity", j);
                config_lookup_string(cf, sname, &value);
                o->rarity = parse_rarity(o, sname);

                x = 0;
                sprintf(sname, "weapon.[%d].mod", j);
                config_lookup_int(cf, sname, &x);
                o->attackmod = o->damagemod = x;

                o->id = objid; objid++;
                o->color = COLOR_WHITE;
                o->stackable = false;

                o->head = objdefs->head;
                objdefs->next = o;
                o->next = NULL;
                objdefs = o;

                game->objdefs++;
                printf(".");
        }

        printf(" OK\n");

        return 0;
}
示例#6
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_armor()
{
        config_setting_t *cfg;
        int i, j, y;
        char sname[100];
        const char *value;
        //double f;

        cfg = config_lookup(cf, "armor");
        i = config_setting_length(cfg);
        printf("Parsing armor file... We have %d armors", i);
        for(j=0;j<i;j++) {
                obj_t *o;
                int x;

                o = (obj_t *) gtmalloc(sizeof(obj_t));

                sprintf(sname, "armor.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(o->basename, value);

                sprintf(sname, "armor.[%d].truename", j);
                if(config_lookup_string(cf, sname, &value) == CONFIG_TRUE)
                        strcpy(o->truename, value);

                sprintf(sname, "armor.[%d].type", j);
                config_lookup_string(cf, sname, &value);
                if(!strcmp(value, "bodyarmor"))
                        o->flags |= OF_BODYARMOR;
                if(!strcmp(value, "headarmor"))
                        o->flags |= OF_HEADGEAR;
                if(!strcmp(value, "shield"))
                        o->flags |= OF_SHIELD;
                if(!strcmp(value, "gloves"))
                        o->flags |= OF_GLOVES;
                if(!strcmp(value, "footarmor"))
                        o->flags |= OF_FOOTWEAR;

                o->type   = OT_ARMOR;
                sprintf(sname, "armor.[%d].ac", j);
                config_lookup_int(cf, sname, &x);
                o->ac = x;

                sprintf(sname, "armor.[%d].rarity", j);
                o->rarity = parse_rarity(o, sname);

                sprintf(sname, "armor.[%d].unique", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_UNIQUE);

                x = 0;
                sprintf(sname, "armor.[%d].obvious", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_OBVIOUS);

                o->color = COLOR_WHITE;
                for(y = 0; y < 10; y++) {
                        sprintf(sname, "armor.[%d].effect.[%d].brand", j, y);
                        if(config_lookup_string(cf, sname, &value) == CONFIG_TRUE) {
                                if(!strcmp(value, "stat")) {
                                        sprintf(sname, "armor.[%d].effect.[%d].stat", j, y);
                                        config_lookup_string(cf, sname, &value);
                                        sprintf(sname, "armor.[%d].effect.[%d].gain", j, y);
                                        config_lookup_int(cf, sname, &x);

                                        if(!strcmp(value, "strength")) 
                                                add_effect_with_duration_and_intgain(o, OE_STRENGTH, -1, x);
                                        if(!strcmp(value, "physique"))
                                                add_effect_with_duration_and_intgain(o, OE_PHYSIQUE, -1, x);
                                        if(!strcmp(value, "intelligence"))
                                                add_effect_with_duration_and_intgain(o, OE_INTELLIGENCE, -1, x);
                                        if(!strcmp(value, "wisdom"))
                                                add_effect_with_duration_and_intgain(o, OE_WISDOM, -1, x);
                                        if(!strcmp(value, "dexterity"))
                                                add_effect_with_duration_and_intgain(o, OE_DEXTERITY, -1, x);
                                        if(!strcmp(value, "charisma"))
                                                add_effect_with_duration_and_intgain(o, OE_CHARISMA, -1, x);

                                        o->color = COLOR_MAGENTA;
                                }

                                if(!strcmp(value, "speed")) {
                                        sprintf(sname, "armor.[%d].effect.[%d].gain", j, y);
                                        config_lookup_int(cf, sname, &x);
                                        add_effect_with_duration_and_intgain(o, OE_SPEED, -1, x);
                                }
                        }
                }

                o->stackable = false;
                o->id = objid; objid++;

                o->head = objdefs->head;
                objdefs->next = o;
                o->next = NULL;
                objdefs = o;

                printf(".");
        }

        printf(" OK\n");
        objdefs->head->dice = i;
        game->objdefs = i;

        return 0;
}
示例#7
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_monsters()
{
        config_setting_t *cfg_monsters;
        int i, j, boolval, tmp, id;
        char sname[100];
        const char *value;
        char string[50];

        cfg_monsters = config_lookup(cf, "monsters");
        i = config_setting_length(cfg_monsters);
        game->monsterdefs = i;
        printf("Parsing monster file... We have %d monsters", i);

        /* 
         * main monster parsing loop 
         * goes through each possible setting, looks it up in the cfg file
         * and adds it to a monster structure which is then placed in the
         * linked list monsterdefs.
         */
        
        for(j=0;j<i;j++) {
                monster_t *m;

                m = (monster_t *) gtmalloc(sizeof(monster_t));
                id = j+1;

                sprintf(sname, "monsters.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(m->name, value);

                sprintf(sname, "monsters.[%d].str", j);
                config_lookup_int(cf, sname, &(m->attr.str));
                sprintf(sname, "monsters.[%d].phy", j);
                config_lookup_int(cf, sname, &(m->attr.phy));
                sprintf(sname, "monsters.[%d].intl", j);
                config_lookup_int(cf, sname, &(m->attr.intl));
                sprintf(sname, "monsters.[%d].wis", j);
                config_lookup_int(cf, sname, &(m->attr.wis));
                sprintf(sname, "monsters.[%d].dex", j);
                config_lookup_int(cf, sname, &(m->attr.dex));
                sprintf(sname, "monsters.[%d].cha", j);
                config_lookup_int(cf, sname, &(m->attr.cha));

                sprintf(sname, "monsters.[%d].appearance", j);
                config_lookup_string(cf, sname, &value);
                m->c = (char) *value;

                sprintf(sname, "monsters.[%d].level", j);
                config_lookup_int(cf, sname, &(m->level));

                sprintf(sname, "monsters.[%d].hp", j);
                config_lookup_int(cf, sname, &(m->hp));
                m->maxhp = m->hp;

                sprintf(sname, "monsters.[%d].speed", j);
                config_lookup_int(cf, sname, &(m->speed));

                sprintf(sname, "monsters.[%d].havegold", j);
                if(config_lookup_bool(cf, sname, &boolval))
                        if(boolval)
                                setbit(m->flags, MF_CANHAVEGOLD);

                sprintf(sname, "monsters.[%d].useweapon", j);
                if(config_lookup_bool(cf, sname, &boolval))
                        if(boolval)
                                setbit(m->flags, MF_CANUSEWEAPON);

                sprintf(sname, "monsters.[%d].usearmor", j);
                if(config_lookup_bool(cf, sname, &boolval))
                        if(boolval)
                                setbit(m->flags, MF_CANUSEARMOR);

                sprintf(sname, "monsters.[%d].aitype", j);
                config_lookup_int(cf, sname, &tmp);
                m->ai = aitable[tmp];
                m->mid = tmp;   // for monsterdefs, mid holds aitableindex
                m->id = id;

                m->viewradius = 12; // temporary solution?!

                // Let's give the monster a weapon!
                if(hasbit(m->flags, MF_CANUSEWEAPON)) {
                        int x;
                        obj_t *o;

                        sprintf(sname, "monsters.[%d].weapon", j);
                        config_lookup_string(cf, sname, &value);
                        strcpy(string, value);

                        x = get_objdef_by_name(string);

                        m->inventory = init_inventory();
                        o = spawn_object(x, 0);
                        m->inventory->object[0] = o;
                        m->weapon = o;
                }

                if(hasbit(m->flags, MF_CANHAVEGOLD)) {
                        if(!m->inventory)
                                m->inventory = init_inventory();

                        m->inventory->gold += ri(0, 15*m->level);
                        }

                
//if(m->weapon)
//fprintf(stderr, "DEBUG: %s:%d - %s has the weapon called a %s\n", __FILE__, __LINE__, m->name, m->weapon->basename);
                        

                /*
                 * the following was written in one go, it's beautiful and seems totally bugfree!!
                 */
                m->head = monsterdefs->head;
                monsterdefs->next = m;
                m->next = NULL;
                m->prev = monsterdefs;
                monsterdefs = m;

                printf("."); // "progress bar"
        }
        
        printf(" OK\n");

        monsterdefs->head->x = i; // store number of monsters in x of head.
        return 0;
}
示例#8
0
int parse_opts(pam_url_opts *opts, int argc, const char *argv[], int mode)
{
#if defined(DEBUG)
	pam_url_debug = true;
#else
	pam_url_debug = false;
#endif
	opts->configfile = NULL;
	opts->use_first_pass = false;
	opts->prepend_first_pass = false;
	opts->first_pass = NULL;

	if(argc > 0 && argv != NULL)
	{
	int next_arg;
		for(next_arg = 0; next_arg < argc; next_arg++)
		{
			if(strcmp(argv[next_arg], "debug") == 0)
			{
				pam_url_debug = true;
				continue;
			}

			if(strncmp(argv[next_arg], "config=", 7) == 0)
			{
				// Skip the first 7 chars ('config=').
				opts->configfile = strdup(argv[next_arg] + 7);
				continue;
			}

			if(strcmp(argv[next_arg], "use_first_pass") == 0)
			{
				opts->use_first_pass = true;
				continue;
			}

			if(strcmp(argv[next_arg], "prepend_first_pass") == 0)
			{
				opts->prepend_first_pass = true;
				continue;
			}
		}
	}

	if(opts->configfile == NULL)
		opts->configfile = strdup("/etc/pam_url.conf");

	switch(mode)
	{
		case PAM_SM_ACCOUNT:
			opts->mode = "PAM_SM_ACCOUNT";
			break;
		case PAM_SM_SESSION:
			opts->mode = "PAM_SM_SESSION";
			break;
		case PAM_SM_PASSWORD:
			opts->mode = "PAM_SM_PASSWORD";
			break;
		case PAM_SM_AUTH:
		default:
			opts->mode = "PAM_SM_AUTH";
			break;
	}

	config_init(&config);
	config_read_file(&config, opts->configfile);

	// General Settings
	if(config_lookup_string(&config, "pam_url.settings.url", &opts->url) == CONFIG_FALSE)
		opts->url = DEF_URL;

	if(config_lookup_string(&config, "pam_url.settings.returncode", &opts->ret_code) == CONFIG_FALSE)
		opts->ret_code = DEF_RETURNCODE;

	if(config_lookup_string(&config, "pam_url.settings.userfield", &opts->user_field) == CONFIG_FALSE)
		opts->user_field = DEF_USER;

	if(config_lookup_string(&config, "pam_url.settings.passwdfield", &opts->passwd_field) == CONFIG_FALSE)
		opts->passwd_field = DEF_PASSWD;

	if(config_lookup_string(&config, "pam_url.settings.extradata", &opts->extra_field) == CONFIG_FALSE)
		opts->extra_field = DEF_EXTRA;


	// SSL Options
	if(config_lookup_string(&config, "pam_url.ssl.use_client_cert", &opts->use_client_cert) == CONFIG_FALSE)
		opts->use_client_cert = false;

	if(config_lookup_string(&config, "pam_url.ssl.client_cert", &opts->ssl_cert) == CONFIG_FALSE)
		opts->ssl_cert = DEF_SSLCERT;

	if(config_lookup_string(&config, "pam_url.ssl.client_key", &opts->ssl_key) == CONFIG_FALSE)
		opts->ssl_key = DEF_SSLKEY;
	if(config_lookup_string(&config, "pam_url.ssl.ca_cert", &opts->ca_cert) == CONFIG_FALSE)
		opts->ca_cert = DEF_CA_CERT;

	if(config_lookup_bool(&config, "pam_url.ssl.verify_host", (int *)&opts->ssl_verify_host) == CONFIG_FALSE)
		opts->ssl_verify_host = true;

	if(config_lookup_bool(&config, "pam_url.ssl.verify_peer", (int *)&opts->ssl_verify_peer) == CONFIG_FALSE)
		opts->ssl_verify_peer = true;

	return PAM_SUCCESS;
}
示例#9
0
int main(int argc, char *argv[]) {
    config_t cfg;
    config_setting_t *setting;
    const char *base = NULL, *str1, *str2;
    int count, n, boolean_value;
    double ker;
    char *config_file_name = "test.cfg";

    /* Inizializzazione */
    config_init(&cfg);

    if (!config_read_file(&cfg, config_file_name)) {
        fprintf(stderr, "%d - %s\n",
                config_error_line(&cfg),
                config_error_text(&cfg));

        config_destroy(&cfg);

        return(EXIT_FAILURE);
    }

    /* Si verifica l'esistenza di un un valore booleano */
    if (config_lookup_bool(&cfg, "prova", &boolean_value))
            printf("valore booleano: %s\n", boolean_value ? "Yes" : "No");
    else
        printf("boolean_value is not defined\n");

    /* Ricezione di una stringa */
    if (config_lookup_string(&cfg, "filename", &str1))
        printf("   Tipo di file: %s\n", str1);
    else
        printf("No filename setting config file\n");

    setting = config_lookup(&cfg, "rete");

    if (setting != NULL) {
        /* Legge  stringa */
        if (config_setting_lookup_string(setting, "host", &str2))
            printf("           Host: %s\n", str2);
        else
            printf("No host\n");

        if (config_setting_lookup_string(setting, "arch", &str2))
            printf("   Architettura: %s\n", str2);
        else
            printf("No arch\n");
        
        if (config_setting_lookup_float(setting, "kernel", &ker))
            printf(" Kernel version: %f\n", ker);
        else
            printf("No kernel\n");
    }

    setting = config_lookup(&cfg, "negozio.libri");
    if (setting != NULL) {
        /* Legge  stringa */
        if (config_setting_lookup_string(setting, "titolo", &str2))
            printf("         Titolo: %s\n", str2);
        else
            printf("No titolo\n");
    }

    // Quando si lavora con liste o con array si utilizza l'indicizzazione */
    setting = config_lookup(&cfg, "negozio.pizzeria.pizze_da_asporto.[1]");
    if (setting != NULL) {
        /* Legge  stringa */
        if (config_setting_lookup_string(setting, "nome", &str2))
            printf("          Pizza: %s\n", str2);
        else
            printf("No nome\n");
    }


    return(EXIT_SUCCESS);
}
示例#10
0
文件: main.c 项目: analani/tg
void parse_config (void) {
  //config_filename = make_full_path (config_filename);
  
  config_t conf;
  config_init (&conf);
  if (config_read_file (&conf, config_filename) != CONFIG_TRUE) {
    fprintf (stderr, "Can not read config '%s': error '%s' on the line %d\n", config_filename, config_error_text (&conf), config_error_line (&conf));
    exit (2);
  }

  if (!prefix) {
    config_lookup_string (&conf, "default_profile", (void *)&prefix);
  }

  static char buf[1000];
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  
  int test_mode = 0;
  strcpy (buf + l, "test");
  config_lookup_bool (&conf, buf, &test_mode);
  if (test_mode) {
    tgl_set_test_mode ();
  }
  
  strcpy (buf + l, "log_level");
  long long t = log_level;
  config_lookup_int (&conf, buf, (void *)&t);
  log_level = t;
  
  if (!msg_num_mode) {
    strcpy (buf + l, "msg_num");
    config_lookup_bool (&conf, buf, &msg_num_mode);
  }

  parse_config_val (&conf, &config_directory, "config_directory", CONFIG_DIRECTORY, 0);
  config_directory = make_full_path (config_directory);

  parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory);
  parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory);
  
  if (!lua_file) {
    parse_config_val (&conf, &lua_file, "lua_script", 0, config_directory);
  }
  
  strcpy (buf + l, "binlog_enabled");
  config_lookup_bool (&conf, buf, &binlog_enabled);
  
  int pfs_enabled = 0;
  strcpy (buf + l, "pfs_enabled");
  config_lookup_bool (&conf, buf, &pfs_enabled);
  if (pfs_enabled) {
    tgl_enable_pfs ();
  }

  if (binlog_enabled) {
    parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
    tgl_set_binlog_mode (1);
    tgl_set_binlog_path (binlog_file_name);
  } else {
    tgl_set_binlog_mode (0);
    parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory);
    parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory);
    //tgl_set_auth_file_path (auth_file_name);
  }
  tgl_set_download_directory (downloads_directory);
  
  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }
  if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", downloads_directory);
    }
  }
  config_destroy (&conf);
}
示例#11
0
void init(CodecConfiguration *configuration) {
    // Need to initialize loggers.
    // Then need to pre-allocate pinned memory and Cuda Global Memory.
    gpuTunerCategory = log4c_category_get("performance_tuning_gpu_logger");
    cpuTunerCategory = log4c_category_get("performance_tuning_cpu_logger");
    log4c_init();

    currentMode = PRODUCTION;
    config_t propConfig;
    config_init(&propConfig);
    if (!config_read_file(&propConfig, configuration->propertyFilePath)) {
        fprintf(stderr, "%s:%d - %s\n",
                config_error_file(&propConfig), config_error_line(&propConfig), config_error_text(&propConfig));
        config_destroy(&propConfig);
        return;
    }

    config_lookup_bool(&propConfig, "isUseGpu", &useGpu);
    config_lookup_bool(&propConfig, "isUseDynamicParallelism", &useDynamicParallelism);
    config_lookup_int(&propConfig, "max_packet_size", &maxPacketSize);
    config_lookup_int(&propConfig, "max_batch_size", &maxBatchSize);
    config_lookup_int(&propConfig, "tuner_loop_count", &tunerLoopCount);
    config_lookup_int(&propConfig, "number_of_cpu_cores", &nCpuCores);
    config_lookup_int(&propConfig, "cuda_stream_count", &cudaStreamCount);
    config_lookup_bool(&propConfig, "print_accuracy_log", &printAccuracyLog);

    currentCudaContextSize = (uint32_t) maxBatchSize;
    cudaPduContext = allocatePinnedPduContext(maxBatchSize);
    initCudaParameters((uint32_t) maxBatchSize, ((uint64_t) maxPacketSize * (uint64_t) maxBatchSize));

    int isTunerMode = 0;
    config_lookup_bool(&propConfig, "isTunerMode", &isTunerMode);
    currentMode = isTunerMode ? TUNER : PRODUCTION;
    printf("Is Use GPU %d | Max Packet Size %d | Max Batch Size %d | Tuner Mode %d | Accuracy Log %d\n",
           useGpu, maxPacketSize, maxBatchSize, currentMode, printAccuracyLog);
    fflush(stdout);
    switch (currentMode) {
        case TUNER: {
            configureTuner(&propConfig);
            break;
        }
        default: {
            int x, y, z;
            config_setting_t *block = config_lookup(&propConfig, "production.block");
            config_setting_t *grid = config_lookup(&propConfig, "production.grid");

            config_setting_lookup_int(block, "x", &x);
            config_setting_lookup_int(block, "y", &y);
            config_setting_lookup_int(block, "z", &z);

            blockDimProdction.x = (uint32_t) x;
            blockDimProdction.y = (uint32_t) y;
            blockDimProdction.z = (uint32_t) z;

            config_setting_lookup_int(grid, "x", &x);
            config_setting_lookup_int(grid, "y", &y);
            config_setting_lookup_int(grid, "z", &z);

            gridDimProduction.x = (uint32_t) x;
            gridDimProduction.y = (uint32_t) y;
            gridDimProduction.z = (uint32_t) z;

            config_lookup_int(&propConfig, "production.cpu_decode_threshold", &cpuDecodeThreshold);
        }
    }
}
示例#12
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_potions()
{
        config_setting_t *cfg;
        int i, j, material, d, s, durd, durs, durm, effect, negative;
        char sname[100];
        const char *value;

        cfg = config_lookup(cf, "potion");
        i = config_setting_length(cfg);
        printf("Parsing potions file... We have %d potions", i);
        material = 1;
        for(j = 0; j < i; j++) {
                obj_t *o;
                int x;
                int y;

                o = (obj_t *) gtmalloc(sizeof(obj_t));

                sprintf(sname, "potion.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(o->basename, value);

                for(y = 0; y < 10; y++) {
                        sprintf(sname, "potion.[%d].effect.[%d].brand", j, y);
                        config_lookup_string(cf, sname, &value);

                        if(!strcmp(value, "healing")) {
                                x = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].sides", j, y);
                                config_lookup_int(cf, sname, &x);
                                s = x;

                                x = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].dice", j, y);
                                config_lookup_int(cf, sname, &x);
                                d = x;

                                if(d && s) {
                                        o->dice = d;
                                        o->sides = s;
                                        add_effect(o, OE_HEAL_NOW);
                                }
                        }

                        sprintf(sname, "potion.[%d].effect.[%d].type", j, y);
                        config_lookup_string(cf, sname, &value);

                        if(!strcmp(value, "permanent")) {
                                sprintf(sname, "potion.[%d].effect.[%d].brand", j, y);
                                config_lookup_string(cf, sname, &value);
                                if(!strcmp(value, "stat")) {
                                        sprintf(sname, "potion.[%d].effect.[%d].stat", j, y);
                                        config_lookup_string(cf, sname, &value);

                                        if(!strcmp(value, "strength")) 
                                                add_effect_with_duration(o, OE_STRENGTH, -1);
                                        if(!strcmp(value, "physique"))
                                                add_effect_with_duration(o, OE_PHYSIQUE, -1);
                                        if(!strcmp(value, "intelligence"))
                                                add_effect_with_duration(o, OE_INTELLIGENCE, -1);
                                        if(!strcmp(value, "wisdom"))
                                                add_effect_with_duration(o, OE_WISDOM, -1);
                                        if(!strcmp(value, "dexterity"))
                                                add_effect_with_duration(o, OE_DEXTERITY, -1);
                                        if(!strcmp(value, "charisma"))
                                                add_effect_with_duration(o, OE_CHARISMA, -1);
                                } else if(!strcmp(value, "water"))
                                        add_effect(o, OE_WATER);
                        } else if(!strcmp(value, "temporary")) {
                                sprintf(sname, "potion.[%d].effect.[%d].brand", j, y);
                                config_lookup_string(cf, sname, &value);

                                if(!strcmp(value, "invisibility"))
                                        effect = OE_INVISIBILITY;

                                if(!strcmp(value, "stat")) {
                                        sprintf(sname, "potion.[%d].effect.[%d].stat", j, y);
                                        config_lookup_string(cf, sname, &value);
                                        if(!strcmp(value, "strength"))
                                                effect = OE_STRENGTH;
                                        if(!strcmp(value, "dexterity"))
                                                effect = OE_DEXTERITY;
                                        if(!strcmp(value, "wisdom"))
                                                effect = OE_WISDOM;
                                        if(!strcmp(value, "physique"))
                                                effect = OE_PHYSIQUE;
                                        if(!strcmp(value, "intelligence"))
                                                effect = OE_INTELLIGENCE;
                                        if(!strcmp(value, "charisma"))
                                                effect = OE_CHARISMA;
                                }

                                sprintf(sname, "potion.[%d].effect.[%d].negative", j, y);
                                if(config_lookup_bool(cf, sname, &negative) != CONFIG_TRUE)
                                        negative = false;

                                durd = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].dur_d", j, y);
                                config_lookup_int(cf, sname, &durd);
                                durs = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].dur_s", j, y);
                                config_lookup_int(cf, sname, &durs);
                                durm = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].dur_m", j, y);
                                config_lookup_int(cf, sname, &durm);

                                x = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].dice", j, y);
                                config_lookup_int(cf, sname, &x);
                                d = x;

                                x = 0;
                                sprintf(sname, "potion.[%d].effect.[%d].sides", j, y);
                                config_lookup_int(cf, sname, &x);
                                s = x;

                                if(negative)
                                        add_negative_effect_with_duration_dice_sides(o, effect, durd, durs, durm, d, s);
                                else
                                        add_effect_with_duration_dice_sides(o, effect, durd, durs, durm, d, s);
                        }
                }

                sprintf(sname, "potion.[%d].unique", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_UNIQUE);

                x = 0;
                sprintf(sname, "potion.[%d].obvious", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_OBVIOUS);

                clearbit(o->flags, OF_IDENTIFIED);
                x = 0;
                sprintf(sname, "potion.[%d].autoid", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_IDENTIFIED);

                sprintf(sname, "potion.[%d].rarity", j);
                config_lookup_string(cf, sname, &value);
                o->rarity = parse_rarity(o, sname);

                o->stackable = true;

                o->type = OT_POTION;
                o->id = objid; objid++;


                sprintf(sname, "potion.[%d].color", j);
                if(config_lookup_string(cf, sname, &value) == CONFIG_TRUE) {
                        if(!strcmp(value, "amber"))
                                o->material = POT_AMBER;
                        else if(!strcmp(value, "brown"))
                                o->material = POT_BROWN;
                        else if(!strcmp(value, "dark red"))
                                o->material = POT_DARKRED;
                        else if(!strcmp(value, "white"))
                                o->material = POT_CLEAR;
                        else if(!strcmp(value, "yellow"))
                                o->material = POT_YELLOW;
                } else {
                        o->material = mats_potions[material];
                        material++;
                        if(material > POTS) {
                                material = ri(1, POTS);
                                fprintf(stderr, "DEBUG: whoa! we ran out of material! going random!");
                        }
                }

                switch(o->material) {
                        case POT_RED:       o->color = COLOR_RED; break;
                        case POT_GREEN:     o->color = COLOR_GREEN; break;
                        case POT_SPARKLING: o->color = COLOR_WHITE; break;
                        case POT_BLUE:      o->color = COLOR_BLUE; break;
                        case POT_CLEAR:     o->color = COLOR_WHITE; break;
                        case POT_YELLOW:    o->color = COLOR_YELLOW; break;
                        case POT_PINK:      o->color = COLOR_MAGENTA; break; // TODO: CHANGE TO PINK
                        case POT_AMBER:     o->color = COLOR_AMBER; break;
                        case POT_GOLD:      o->color = COLOR_GOLD; break;
                        case POT_ORANGE:    o->color = COLOR_ORANGE; break; 
                        case POT_LIMEGREEN: o->color = COLOR_LIMEGREEN; break;
                        case POT_CYAN:      o->color = COLOR_CYAN; break;
                        case POT_SKYBLUE:   o->color = COLOR_SKYBLUE; break;
                        case POT_VIOLET:    o->color = COLOR_VIOLET; break;
                        case POT_CRIMSON:   o->color = COLOR_CRIMSON; break;
                        case POT_AZURE:     o->color = COLOR_AZURE; break;
                        case POT_DARKRED:   o->color = COLOR_DARKRED; break;
                        case POT_SEAGREEN:  o->color = COLOR_SEAGREEN; break;
                        case POT_PURPLE:    o->color = COLOR_PURPLE; break;
                        case POT_MAGENTA:   o->color = COLOR_MAGENTA; break;
                        case POT_FIZZY:     o->color = COLOR_FIZZY; break;
                        case POT_BROWN:     o->color = COLOR_BROWN; break;
                        default:            o->color = COLOR_WHITE; break;
                };

                o->head = objdefs->head;
                objdefs->next = o;
                o->next = NULL;
                objdefs = o;

                game->objdefs++;
                printf(".");
        }

printf(" OK\n");

return 0;
}
示例#13
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_amulet()
{
        config_setting_t *cfg;
        int i, j, material;
        char sname[100];
        const char *value;

        cfg = config_lookup(cf, "amulet");
        i = config_setting_length(cfg);
        printf("Parsing jewelry file... We have %d amulets", i);
        material = 1;
        for(j=0;j<i;j++) {
                obj_t *o;
                int x;

                o = (obj_t *) gtmalloc(sizeof(obj_t));

                sprintf(sname, "amulet.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(o->basename, value);
                
                sprintf(sname, "amulet.[%d].brand", j);
                config_lookup_string(cf, sname, &value);
                if(!strcmp(value, "protection")) {                     // This means this amulet is some sort of protection
                        sprintf(sname, "amulet.[%d].type", j);
                        config_lookup_string(cf, sname, &value);

                        if(!strcmp(value, "life")) 
                                add_effect(o, OE_PROTECTION_LIFE);
                        if(!strcmp(value, "fire"))
                                add_effect(o, OE_PROTECTION_FIRE);
                }

                sprintf(sname, "amulet.[%d].unique", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_UNIQUE);
                
                sprintf(sname, "amulet.[%d].obvious", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_OBVIOUS);

                sprintf(sname, "amulet.[%d].rarity", j);
                o->rarity = parse_rarity(o, sname);

                x = 0;
                /*sprintf(sname, "amulet.[%d].mod", j);
                config_lookup_int(cf, sname, &x);
                o->attackmod = o->damagemod = x;*/

                o->type = OT_AMULET;
                o->id = objid; objid++;
                o->color = COLOR_WHITE;
                o->stackable = false;

                o->material = mats_amulets[material];
                material++;
                if(material > MATERIALS)
                        die("whoa! we ran out of material!");

                o->head = objdefs->head;
                objdefs->next = o;
                o->next = NULL;
                objdefs = o;

                game->objdefs++;
                printf(".");
        }

        printf(" OK\n");

        return 0;
}
示例#14
0
MainDialog::MainDialog(QString userConfigFile) {
  ui = new Ui::MainDialog;
  ui->setupUi(this);

  if(userConfigFile.isEmpty()) {
    userConfigFile_ = qgetenv("XDG_CONFIG_HOME");
    if(userConfigFile_.isEmpty()) {
      userConfigFile_ = QDir::homePath();
      userConfigFile_ += "/.config";
    }
    // QDir configDir = QDir(userConfigFile);
    // if(!configDir.exists())
    userConfigFile_ += "/compton.conf";
  }
  else
    userConfigFile_ = userConfigFile;

  config_init(&config_);
  if(config_read_file(&config_, userConfigFile_.toLocal8Bit().constData()) == CONFIG_FALSE) {
    // loading user config file failed
    // try our default example
    qDebug() << "load fail, try " << COMPTON_CONF_DATA_DIR << "/compton.conf.example";
    config_read_file(&config_, COMPTON_CONF_DATA_DIR "/compton.conf.example");
  }

  // set up signal handlers and initial values of the controls
  connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onDialogButtonClicked(QAbstractButton*)));
  connect(ui->aboutButton, SIGNAL(clicked(bool)), SLOT(onAboutButtonClicked()));
  connect(ui->shadow_color, SIGNAL(clicked(bool)), SLOT(onColorButtonClicked()));
  double color;
  shadowColor_.setRedF(config_lookup_float(&config_, "shadow-red", &color) == CONFIG_TRUE ?  color : 0.0);
  shadowColor_.setGreenF(config_lookup_float(&config_, "shadow-green", &color) == CONFIG_TRUE ? color : 0.0);
  shadowColor_.setBlueF(config_lookup_float(&config_, "shadow-blue", &color) == CONFIG_TRUE ? color : 0.0);
  updateShadowColorButton();

  // objectNames are kept the same as config file key names.
  Q_FOREACH(QWidget* child, findChildren<QWidget*>()) {
    if(!child->isWidgetType() || child->objectName().isEmpty())
      continue;
    // objectName uses _ while config file keys uses - as separator.
    QByteArray keyName = child->objectName().replace('_', '-').toLatin1(); // generate config key from objectName.
    if(child->inherits("QCheckBox")) {
      int val = -1;
      if(config_lookup_bool(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QCheckBox*>(child)->setChecked((bool)val);
      connect(child, SIGNAL(toggled(bool)), SLOT(onButtonToggled(bool)));
    }
    else if(child->inherits("QDoubleSpinBox")) {
      double val;
      if(config_lookup_float(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QDoubleSpinBox*>(child)->setValue(val);
      connect(child, SIGNAL(valueChanged(double)), SLOT(onSpinValueChanged(double)));
    }
    else if(child->inherits("QSpinBox")) {
      int val;
      if(config_lookup_int(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QSpinBox*>(child)->setValue(val);
      connect(child, SIGNAL(valueChanged(int)), SLOT(onSpinValueChanged(int)));
    }
  }
}
示例#15
0
文件: fvec.c 项目: MLDroid/sally
/**
 * Extract byte n-grams from a string. The features (n-grams) are 
 * represented by hash values.
 * @param fv Feature vector
 * @param x Byte sequence 
 * @param l Length of sequence
 * @param nlen N-gram length
 * @param pos Positional n-grams 
 * @param shift Shift value
 */
static void extract_ngrams(fvec_t *fv, char *x, int l, int nlen, int pos,
                           int shift)
{
    assert(fv && x);

    unsigned int i = 0, ci = 0;
    int sort, flen, sign;
    cfg_int bits;
    char *fstr, *t = x;
    fentry_t *cache = NULL;

    /* Get configuration */
    config_lookup_bool(&cfg, "features.ngram_sort", &sort);
    config_lookup_int(&cfg, "features.hash_bits", &bits);
    config_lookup_bool(&cfg, "features.vect_sign", &sign);

    /* Set bits of hash mask */
    feat_t hash_mask = ((long long unsigned) 2 << (bits - 1)) - 1;

    if (fhash_enabled())
        cache = calloc(l, sizeof(fentry_t));

    for (i = 1; t < x + l; i++) {
        /* Check for sequence end */
        if (t + nlen > x + l)
            break;

        /* Copy feature string and add slack */
        flen = nlen;
        fstr = malloc(flen + sizeof(unsigned long));
        memcpy(fstr, t, nlen);

        /* Sorted n-grams code */
        if (sort)
            qsort(fstr, flen, 1, chrcmp);

        /* Positional n-grams code */
        if (pos) {
            int32_t p = ci + shift;
            memcpy(fstr + flen, &p, sizeof(int32_t));
            flen += sizeof(int32_t);
        }

        feat_t h = hash_str(fstr, flen);
        fv->dim[fv->len] = h & hash_mask;
        fv->val[fv->len] = 1;

        /* Signed embedding */
        if (sign)
            fv->val[fv->len] *= (signed) h > 0 ? -1 : 1;

        /* Cache feature */
        if (fhash_enabled())
            cache_put(&cache[ci], fv, fstr, flen);

        t++;
        fv->len++;
        ci++;
        free(fstr);
    }
    fv->total += fv->len;

    if (!fhash_enabled())
        return;

    /* Flush cache */
    cache_flush(cache, ci);
    free(cache);
}
示例#16
0
文件: fvec.c 项目: MLDroid/sally
/**
 * Extracts word n-grams from a string. The features are represented 
 * by hash values.
 * @param fv Feature vector
 * @param x Byte sequence 
 * @param l Length of sequence
 * @parma nlen N-gram len
 * @param pos Positional n-grams
 * @param shift Shift value
 */
static void extract_wgrams(fvec_t *fv, char *x, int l, int nlen, int pos,
                           int shift)
{
    assert(fv && x && l > 0);
    int sort, sign, flen;
    cfg_int bits;
    unsigned int i, j = l, ci = 0;
    unsigned int dlm = 0;
    unsigned int fstart, fnext = 0, fnum = 0;
    char *t = malloc(l + 1), *fstr;
    fentry_t *cache = NULL;

    /* Get configuration */
    config_lookup_bool(&cfg, "features.ngram_sort", &sort);
    config_lookup_int(&cfg, "features.hash_bits", &bits);
    config_lookup_bool(&cfg, "features.vect_sign", &sign);

    /* Set bits of hash mask */
    feat_t hash_mask = ((long long unsigned) 2 << (bits - 1)) - 1;

    if (fhash_enabled())
        cache = calloc(l, sizeof(fentry_t));

    /* Find first delimiter symbol */
    for (dlm = 0; !delim[(unsigned char) dlm] && dlm < 256; dlm++);

    /* Remove redundant delimiters */
    for (i = 0, j = 0; i < l; i++) {
        if (delim[(unsigned char) x[i]]) {
            if (j == 0 || delim[(unsigned char) t[j - 1]])
                continue;
            t[j++] = (char) dlm;
        } else {
            t[j++] = x[i];
        }
    }

    /* No characters remaining */
    if (j == 0)
        goto clean;

    /* Add trailing delimiter */
    if (t[j - 1] != dlm)
        t[j++] = (char) dlm;

    /* Extract n-grams */
    for (fstart = i = 0; i < j; i++) {
        /* Count delimiters and remember start position */
        if (t[i] == dlm && ++fnum == 1)
            fnext = i;

        /* Store n-gram */
        if (fnum == nlen && i - fstart > 0) {
            /* Copy feature string and add slack */
            flen = i - fstart;
            fstr = malloc(flen + sizeof(unsigned long));
            memcpy(fstr, t + fstart, flen);

            /* Sorted n-grams code */
            if (sort)
                fstr = sort_words(fstr, flen, dlm);

            /* Positional n-grams code */
            if (pos) {
                int32_t p = ci + shift;
                memcpy(fstr + flen, &p, sizeof(int32_t));
                flen += sizeof(int32_t);
            }

            feat_t h = hash_str(fstr, flen);
            fv->dim[fv->len] = h & hash_mask;
            fv->val[fv->len] = 1;

            /* Signed embedding */
            if (sign)
                fv->val[fv->len] *= (signed) h > 0 ? -1 : 1;

            /* Cache feature and key */
            if (fhash_enabled())
                cache_put(&cache[ci], fv, fstr, flen);

            fstart = fnext + 1, i = fnext, fnum = 0;
            fv->len++;
            ci++;
            free(fstr);
        }
    }

    /* Save extracted n-grams */
    fv->total += fv->len;

  clean:
    if (fhash_enabled()) {
        cache_flush(cache, ci);
        free(cache);
    }
    free(t);
}
示例#17
0
void
parse_config (void)
{
  const char *home;
  FILE *fp;
  config_t conf;

  config_init (&conf);

  /* Try $HOME first. */
  home = getenv ("HOME");
  if (home != NULL) {
    CLEANUP_FREE char *path = NULL;

    if (asprintf (&path, "%s/%s", home, home_filename) == -1) {
      perror ("asprintf");
      exit (EXIT_FAILURE);
    }

    fp = fopen (path, "r");
    if (fp != NULL) {
      /*
      if (verbose)
        fprintf (stderr, "%s: reading configuration from %s\n",
                 program_name, path);
      */

      if (config_read (&conf, fp) == CONFIG_FALSE) {
        fprintf (stderr,
                 _("%s: %s: line %d: error parsing configuration file: %s\n"),
                 program_name, path, config_error_line (&conf),
                 config_error_text (&conf));
        exit (EXIT_FAILURE);
      }

      if (fclose (fp) == -1) {
        perror (path);
        exit (EXIT_FAILURE);
      }

      /* Notes:
       *
       * (1) It's not obvious from the documentation, that config_read
       * completely resets the 'conf' structure.  This means we cannot
       * call config_read twice on the two possible configuration
       * files, but instead have to copy out settings into our
       * variables between calls.
       *
       * (2) If the next call fails then 'read_only' variable is not
       * updated.  Failure could happen just because the setting is
       * missing from the configuration file, so we ignore it here.
       */
      config_lookup_bool (&conf, "read_only", &read_only);
    }
  }

  fp = fopen (etc_filename, "r");
  if (fp != NULL) {
    /*
    if (verbose)
      fprintf (stderr, "%s: reading configuration from %s\n",
               program_name, etc_filename);
    */

    if (config_read (&conf, fp) == CONFIG_FALSE) {
      fprintf (stderr,
               _("%s: %s: line %d: error parsing configuration file: %s\n"),
               program_name, etc_filename, config_error_line (&conf),
               config_error_text (&conf));
      exit (EXIT_FAILURE);
    }

    if (fclose (fp) == -1) {
      perror (etc_filename);
      exit (EXIT_FAILURE);
    }

    config_lookup_bool (&conf, "read_only", &read_only);
  }

  config_destroy (&conf);
}
static int ct_parseopts(int argc, char * const *argv)
{
    struct option long_opts[] = {
        {"abort-on-error",  no_argument,       &ct_opt.o_abort_on_error, 1},
        {"abort_on_error",  no_argument,       &ct_opt.o_abort_on_error, 1},
        {"archive",         required_argument, NULL,                  'A'},
        {"config",          required_argument, NULL,                  'c'},
        {"daemon",          no_argument,       &ct_opt.o_daemonize,      1},
        {"event-fifo",      required_argument, NULL,                  'f'},
        {"event_fifo",      required_argument, NULL,                  'f'},
        {"dry-run",         no_argument,       &ct_opt.o_dry_run,        1},
        {"help",            no_argument,       NULL,                  'h'},
        {"quiet",           no_argument,       NULL,                  'q'},
        {"rebind",          no_argument,       NULL,                  'r'},
        {"update-interval", required_argument, NULL,                  'u'},
        {"update_interval", required_argument, NULL,                  'u'},
        {"verbose",         no_argument,       NULL,                  'v'},
        {0, 0, 0, 0}
    };
    int c, rc;
    config_t cfg;
    const char *config_str;

    optind = 0;
    while ((c = getopt_long(argc, argv, "A:b:c:f:hp:qu:v",
                            long_opts, NULL)) != -1) {
        switch (c) {
        case 'A':
            if ((ct_opt.o_archive_cnt >= LL_HSM_MAX_ARCHIVE) ||
                    (atoi(optarg) >= LL_HSM_MAX_ARCHIVE)) {
                rc = -E2BIG;
                CT_ERROR(rc, "archive number must be less"
                         "than %zu", LL_HSM_MAX_ARCHIVE);
                return rc;
            }
            ct_opt.o_archive_id[ct_opt.o_archive_cnt] = atoi(optarg);
            ct_opt.o_archive_cnt++;
            break;
        case 'b': /* -b and -c have both a number with unit as arg */
        case 'c':
            ct_opt.o_config = optarg;
            break;
        case 'f':
            ct_opt.o_event_fifo = optarg;
            break;
        case 'h':
            usage(argv[0], 0);
        case 'q':
            ct_opt.o_verbose--;
            break;
        case 'u':
            ct_opt.o_report_int = atoi(optarg);
            if (ct_opt.o_report_int < 0) {
                rc = -EINVAL;
                CT_ERROR(rc, "bad value for -%c '%s'", c, optarg);
                return rc;
            }
            break;
        case 'v':
            ++ct_opt.o_verbose;
            break;
        case 0:
            break;
        default:
            return -EINVAL;
        }
    }

    if (argc != optind + 1) {
        rc = -EINVAL;
        CT_ERROR(rc, "no mount point specified");
        return rc;
    }

    ct_opt.o_mnt = argv[optind];
    ct_opt.o_mnt_fd = -1;

    CT_TRACE("mount_point=%s", ct_opt.o_mnt);

    config_init(&cfg);
    if (! config_read_file(&cfg, ct_opt.o_config)) {
        CT_ERROR(-EINVAL, "error while reading config file\r\n%s:%d - %s",
                 config_error_file(&cfg),
                 config_error_line(&cfg),
                 config_error_text(&cfg));
        return -EINVAL;
    }

    if (config_lookup_string(&cfg, "access_key", &config_str)) {
        strncpy(access_key, config_str, sizeof(access_key));
    }
    else {
        CT_ERROR(-EINVAL, "could not find access_key");
        return -EINVAL;
    }

    if (config_lookup_string(&cfg, "secret_key", &config_str)) {
        strncpy(secret_key, config_str, sizeof(secret_key));
    }
    else {
        CT_ERROR(-EINVAL, "could not find secret_key");
        return -EINVAL;
    }

    if (config_lookup_string(&cfg, "host", &config_str)) {
        strncpy(host, config_str, sizeof(host));
    }
    else {
        CT_ERROR(-EINVAL, "could not find host");
        return -EINVAL;
    }

    if (config_lookup_string(&cfg, "bucket_prefix", &config_str)) {
        strncpy(bucket_prefix, config_str, sizeof(host));
    }
    else {
        CT_ERROR(-EINVAL, "could not find bucket_prefix");
        return -EINVAL;
    }

    if (config_lookup_int(&cfg, "chunk_size", &chunk_size)) {
        if (chunk_size < 0) {
            CT_ERROR(-EINVAL, "chunk_size cannot be negative");
            return -EINVAL;
        }
    }
    else {
        CT_ERROR(-EINVAL, "could not find chunk_size");
        return -EINVAL;
    }

    if (config_lookup_int(&cfg, "bucket_count", &bucket_count)) {
        if (bucket_count < 0) {
            CT_ERROR(-EINVAL, "bucket_count cannot be negative");
            return -EINVAL;
        }
    }
    else {
        CT_ERROR(-EINVAL, "could not find bucket_count");
        return -EINVAL;
    }

    int ssl_enabled;
    if (config_lookup_bool(&cfg, "ssl", &ssl_enabled)){
        if(ssl_enabled){
            bucketContext.protocol = S3ProtocolHTTPS;
        }
        else{
            bucketContext.protocol = S3ProtocolHTTP;
        }
    }
    else{
        CT_ERROR(-EINVAL, "could not find ssl");
        return -EINVAL;
    }

    return 0;
}
示例#19
0
文件: datafiles.c 项目: abstrakct/gt2
int parse_bracelet()
{
        config_setting_t *cfg;
        int i, j, material;
        char sname[100];
        const char *value;

        cfg = config_lookup(cf, "bracelet");
        i = config_setting_length(cfg);
        printf("Parsing jewelry file... We have %d bracelets", i);
        material = 1;
        for(j = 0; j < i; j++) {
                obj_t *o;
                int x;
                int y;

                o = (obj_t *) gtmalloc(sizeof(obj_t));

                sprintf(sname, "bracelet.[%d].name", j);
                config_lookup_string(cf, sname, &value);
                strcpy(o->basename, value);
                
                for(y = 0; y < 10; y++) {
                        sprintf(sname, "bracelet.[%d].effect.[%d].brand", j, y);
                        config_lookup_string(cf, sname, &value);
                        if(!strcmp(value, "stat")) {                     // This means this bracelet modifies a stat
                                sprintf(sname, "bracelet.[%d].effect.[%d].stat", j, y);
                                config_lookup_string(cf, sname, &value);

                                if(!strcmp(value, "strength")) 
                                        add_effect(o, OE_STRENGTH);
                                if(!strcmp(value, "physique"))
                                        add_effect(o, OE_PHYSIQUE);
                                if(!strcmp(value, "intelligence"))
                                        add_effect(o, OE_INTELLIGENCE);
                                if(!strcmp(value, "wisdom"))
                                        add_effect(o, OE_WISDOM);
                                if(!strcmp(value, "dexterity"))
                                        add_effect(o, OE_DEXTERITY);
                                if(!strcmp(value, "charisma"))
                                        add_effect(o, OE_CHARISMA);
                        }
                }

                sprintf(sname, "bracelet.[%d].unique", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_UNIQUE);

                x = 0;
                sprintf(sname, "bracelet.[%d].obvious", j);
                config_lookup_bool(cf, sname, &x);
                if(x)
                        setbit(o->flags, OF_OBVIOUS);

                sprintf(sname, "bracelet.[%d].rarity", j);
                config_lookup_string(cf, sname, &value);
                o->rarity = parse_rarity(o, sname);

                x = 0;
                sprintf(sname, "bracelet.[%d].mod", j);
                config_lookup_int(cf, sname, &x);
                o->attackmod = o->damagemod = x;

                o->type = OT_BRACELET;
                o->id = objid; objid++;
                o->color = COLOR_WHITE;
                clearbit(o->flags, OF_IDENTIFIED);
                o->stackable = false;

                o->material = mats_bracelets[material];
                material++;
                if(material > MATERIALS)
                        die("whoa! we ran out of material!");

                o->head = objdefs->head;
                objdefs->next = o;
                o->next = NULL;
                objdefs = o;

                game->objdefs++;
                printf(".");
        }

        printf(" OK\n");

        return 0;
}
示例#20
0
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
                       int *enable_ipv6,
                       int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports,
                       int *tcp_relay_port_count, int *enable_motd, char **motd)
{
    config_t cfg;

    const char *NAME_PORT                 = "port";
    const char *NAME_PID_FILE_PATH        = "pid_file_path";
    const char *NAME_KEYS_FILE_PATH       = "keys_file_path";
    const char *NAME_ENABLE_IPV6          = "enable_ipv6";
    const char *NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback";
    const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
    const char *NAME_ENABLE_TCP_RELAY     = "enable_tcp_relay";
    const char *NAME_ENABLE_MOTD          = "enable_motd";
    const char *NAME_MOTD                 = "motd";

    config_init(&cfg);

    // Read the file. If there is an error, report it and exit.
    if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
        syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return 0;
    }

    // Get port
    if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT);
        syslog(LOG_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT);
        *port = DEFAULT_PORT;
    }

    // Get PID file location
    const char *tmp_pid_file;

    if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH);
        tmp_pid_file = DEFAULT_PID_FILE_PATH;
    }

    *pid_file_path = malloc(strlen(tmp_pid_file) + 1);
    strcpy(*pid_file_path, tmp_pid_file);

    // Get keys file location
    const char *tmp_keys_file;

    if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH);
        tmp_keys_file = DEFAULT_KEYS_FILE_PATH;
    }

    *keys_file_path = malloc(strlen(tmp_keys_file) + 1);
    strcpy(*keys_file_path, tmp_keys_file);

    // Get IPv6 option
    if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false");
        *enable_ipv6 = DEFAULT_ENABLE_IPV6;
    }

    // Get IPv4 fallback option
    if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK,
               DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false");
        *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK;
    }

    // Get LAN discovery option
    if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY,
               DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false");
        *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY;
    }

    // Get TCP relay option
    if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY,
               DEFAULT_ENABLE_TCP_RELAY ? "true" : "false");
        *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY;
    }

    if (*enable_tcp_relay) {
        parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count);
    } else {
        *tcp_relay_port_count = 0;
    }

    // Get MOTD option
    if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD,
               DEFAULT_ENABLE_MOTD ? "true" : "false");
        *enable_motd = DEFAULT_ENABLE_MOTD;
    }

    if (*enable_motd) {
        // Get MOTD
        const char *tmp_motd;

        if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) {
            syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD);
            syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD);
            tmp_motd = DEFAULT_MOTD;
        }

        size_t tmp_motd_length = strlen(tmp_motd) + 1;
        size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
        *motd = malloc(motd_length);
        strncpy(*motd, tmp_motd, motd_length);
        (*motd)[motd_length - 1] = '\0';
    }

    config_destroy(&cfg);

    syslog(LOG_DEBUG, "Successfully read:\n");
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE_PATH,        *pid_file_path);
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH,       *keys_file_path);
    syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT,                 *port);
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6,          *enable_ipv6          ? "true" : "false");
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");

    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY,     *enable_tcp_relay     ? "true" : "false");

    // show info about tcp ports only if tcp relay is enabled
    if (*enable_tcp_relay) {
        if (*tcp_relay_port_count == 0) {
            syslog(LOG_DEBUG, "No TCP ports could be read.\n");
        } else {
            syslog(LOG_DEBUG, "Read %d TCP ports:\n", *tcp_relay_port_count);
            int i;

            for (i = 0; i < *tcp_relay_port_count; i ++) {
                syslog(LOG_DEBUG, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]);
            }
        }
    }

    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_MOTD,          *enable_motd          ? "true" : "false");

    if (*enable_motd) {
        syslog(LOG_DEBUG, "'%s': %s\n", NAME_MOTD, *motd);
    }

    return 1;
}
int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6,
                       int *enable_lan_discovery)
{
    config_t cfg;

    const char *NAME_PORT                 = "port";
    const char *NAME_PID_FILE_PATH        = "pid_file_path";
    const char *NAME_KEYS_FILE_PATH       = "keys_file_path";
    const char *NAME_ENABLE_IPV6          = "enable_ipv6";
    const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";

    config_init(&cfg);

    // Read the file. If there is an error, report it and exit.
    if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
        syslog(LOG_ERR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return 0;
    }

    // Get port
    if (config_lookup_int(&cfg, NAME_PORT, port) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PORT);
        syslog(LOG_WARNING, "Using default '%s': %d\n", NAME_PORT, DEFAULT_PORT);
        *port = DEFAULT_PORT;
    }

    // Get PID file location
    const char *tmp_pid_file;

    if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_PID_FILE_PATH, DEFAULT_PID_FILE_PATH);
        tmp_pid_file = DEFAULT_PID_FILE_PATH;
    }

    *pid_file_path = malloc(strlen(tmp_pid_file) + 1);
    strcpy(*pid_file_path, tmp_pid_file);

    // Get keys file location
    const char *tmp_keys_file;

    if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_KEYS_FILE_PATH, DEFAULT_KEYS_FILE_PATH);
        tmp_keys_file = DEFAULT_KEYS_FILE_PATH;
    }

    *keys_file_path = malloc(strlen(tmp_keys_file) + 1);
    strcpy(*keys_file_path, tmp_keys_file);

    // Get IPv6 option
    if (config_lookup_bool(&cfg, NAME_ENABLE_IPV6, enable_ipv6) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV6);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV6, DEFAULT_ENABLE_IPV6 ? "true" : "false");
        *enable_ipv6 = DEFAULT_ENABLE_IPV6;
    }

    // Get LAN discovery option
    if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) {
        syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY);
        syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_LAN_DISCOVERY,
               DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false");
        *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY;
    }

    config_destroy(&cfg);

    syslog(LOG_DEBUG, "Successfully read:\n");
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_PID_FILE_PATH,        *pid_file_path);
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH,       *keys_file_path);
    syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT,                 *port);
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6,          *enable_ipv6          ? "true" : "false");
    syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");

    return 1;
}
示例#22
0
void sub_shc_handle_input(unsigned int button)
{
    switch (button)
    {
    case GP2X_BUTTON_B:
        {
            sfx_play(SFXBACK);
            if(shc_showpopup)
            {
            	POPUP_empty();
            	xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS);
				shc_showpopup = 0;
            }
            else
            {
            	shc_init_stage = 10;
            	shc_timer = 0;
           	}
            break;
        }
    case GP2X_BUTTON_LEFT:
        {
        	if(shc_showpopup)
        		break;

            sfx_play(SFXBACK);
            shc_init_stage = 10;
            shc_timer = 0;
            break;
        }
    case GP2X_BUTTON_UP:
        {
        	if(shc_showpopup)
        	{
        		if(POPUP_up())
        			sfx_play(SFXMOVE);

        		break;
        	}

            if (shc_selection > 0)
            {
                shc_movereq += 1;
                shc_selection--;
            }
            break;
        }
    case GP2X_BUTTON_DOWN:
        {
        	if(shc_showpopup)
        	{
				if(POPUP_down())
					sfx_play(SFXMOVE);

				break;
        	}

            if (shc_selection + 1 < shc_menucount)
            {
                shc_movereq -= 1;
                shc_selection++;
            }
            break;
        }
	case GP2X_BUTTON_Y:
        {
        	shc_node *curr = shc_root;
            unsigned int i = 0;

            for (i = 0; curr != NULL && i < shc_selection;
                 curr = curr->next, i++);

            if (!shc_init_stage && curr && !shc_showpopup)
            {
                struct stat statbuf;

                stat(curr->path, &statbuf);

                if (S_ISREG(statbuf.st_mode))
                {
                    xmb_activateFlag(XMB_NOBATT | XMB_FOCUS);

                    POPUP_setrevert(NULL, 0);

                    POPUP_add(NULL, "Delete Shortcut", sub_shc_popexec, 0);

                    POPUP_setselected(0);

		            shc_showpopup = 1;
                }
            }
            break;
        }
    case GP2X_BUTTON_X:
        {
            shc_node *curr = shc_root;
            unsigned int i = 0;

            if (shc_showpopup)
            {
                POPUP_execsel();
                sub_shc_destroy();         /* Empty list */
                sub_shc_init(shc_self);    /* Reload */
                xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS);
                POPUP_empty();
                shc_showpopup = 0;
                break;
            }

            for (i = 0; curr != NULL && i < shc_selection;
                 curr = curr->next, i++);

            if (curr)
            {
                char *dir_name = (char *) calloc(1, 1024);

                if (config_lookup_bool(&CONFIG, "outro"))
                    gfx_draw_outro(SDL_GetVideoSurface());

                gp2xmb_deinit();

                if (dir_name)
                {
                    strncpy(dir_name, curr->path, 1023);
                    chdir(dirname(dir_name));
                    free(dir_name);
                }

                gp2x_setclock(200);

                if (execl(curr->path, curr->path, NULL))
                {
                    gp2xmb_init();      /* start everything up again */
                    while (!xmb_getFlagState(XMB_LOADED))
                    {
                        bg_draw(SDL_GetVideoSurface());
                        progress_draw(SDL_GetVideoSurface(), 1);
                        SDL_Flip(SDL_GetVideoSurface());
                    }
                    msgbox(SDL_GetVideoSurface(),NULL, "System Error",
                           "Failed to execute program.", OK);
                    msgbox_retval();
                    return;
                }
            }

            break;
        }
    default:
        break;
    }
}