void custom_kw_config_deserialize(custom_kw_config_type * config, stringlist_type * config_set) { pthread_rwlock_wrlock(& config->rw_lock); { custom_kw_config_reset__(config); for (int i = 0; i < stringlist_get_size(config_set); i++) { const char * items = stringlist_iget(config_set, i); char key[128]; int index; int is_double; int count = sscanf(items, "%s %d %d", key, &index, &is_double); if (count == 3) { hash_insert_int(config->custom_keys, key, index); hash_insert_int(config->custom_key_types, key, is_double); } else util_abort("%s: internal error - deserialize failed\n",__func__); } config->undefined = false; config->key_definition_file = util_alloc_string_copy("from storage"); //Todo: Handle this differently? } pthread_rwlock_unlock(& config->rw_lock); }
static bool custom_kw_config_setup__(custom_kw_config_type * config, const char * result_file) { FILE * stream = util_fopen__(result_file, "r"); if (stream != NULL) { bool read_ok = true; config->key_definition_file = util_alloc_string_copy(result_file); int counter = 0; char key[128]; char value[128]; int read_count; while ((read_count = fscanf(stream, "%s %s", key, value)) != EOF) { if (read_count == 1) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' is missing value in file: '%s'\n", __func__, config->name, key, result_file); read_ok = false; break; } if (custom_kw_config_has_key(config, key)) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' already defined!\n", __func__, config->name, key); } else { hash_insert_int(config->custom_keys, key, counter++); hash_insert_int(config->custom_key_types, key, util_sscanf_double(value, NULL)); } } fclose(stream); return read_ok; } return false; }
void ecl_config_add_fixed_length_schedule_kw(ecl_config_type * ecl_config, const char * kw, int length) { hash_insert_int(ecl_config->fixed_length_kw, kw, length); if (ecl_config->sched_file != NULL ) sched_file_add_fixed_length_kw(ecl_config->sched_file, kw, length); }
bool summary_key_set_fread(summary_key_set_type * set, const char * filename) { bool file_exists = false; pthread_rwlock_wrlock( &set->rw_lock ); { hash_clear(set->key_set); if (util_file_exists(filename)) { FILE * stream = util_fopen(filename, "r"); if (stream) { stringlist_type * key_set = stringlist_fread_alloc(stream); for (int i = 0; i < stringlist_get_size(key_set); i++) { hash_insert_int(set->key_set, stringlist_iget(key_set, i), 1); } stringlist_free(key_set); fclose( stream ); } else { util_abort("%s: failed to open: %s for reading \n",__func__ , filename ); } file_exists = true; } } pthread_rwlock_unlock( &set->rw_lock ); return file_exists; }
bool set_add_key(set_type * set, const char * key) { if (hash_has_key(set->key_hash , key)) return false; else { hash_insert_int(set->key_hash , key , 1); return true; } }
int hash_inc_counter(hash_type * hash , const char * counter_key) { if (hash_has_key( hash , counter_key)) { node_data_type * node_data = hash_get_node_data(hash , counter_key); return node_data_fetch_and_inc_int( node_data ); } else { hash_insert_int(hash , counter_key , 0); return 0; } }
custom_kw_config_type * custom_kw_config_alloc_with_definition(const char * key, const hash_type * definition) { custom_kw_config_type * custom_kw_config = custom_kw_config_alloc_empty(key, NULL, NULL); stringlist_type * keys = hash_alloc_stringlist((hash_type *) definition); for(int index = 0; index < stringlist_get_size(keys); index++) { const char * definition_key = stringlist_iget_copy(keys, index); int type_value = hash_get_int(definition, definition_key); if(type_value < 0 || type_value > 1) { fprintf(stderr ,"[%s] Warning: Value type not 0 or 1 for key: '%s', defaulting to string!\n", __func__, key); type_value = 0; } hash_insert_int(custom_kw_config->custom_keys, definition_key, index); hash_insert_int(custom_kw_config->custom_key_types, definition_key, type_value); } custom_kw_config->undefined = false; custom_kw_config->key_definition_file = util_alloc_string_copy("custom definition"); stringlist_free(keys); return custom_kw_config; }
static bool custom_kw_config_read_data__(const custom_kw_config_type * config, const char * result_file, stringlist_type * result) { FILE * stream = util_fopen__(result_file, "r"); if (stream != NULL) { bool read_ok = true; stringlist_clear(result); stringlist_iset_ref(result, hash_get_size(config->custom_keys) - 1, NULL); hash_type * read_keys = hash_alloc(); char key[128]; char value[128]; int read_count; while ((read_count = fscanf(stream, "%s %s", key, value)) != EOF) { if (read_count == 1) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' missing value in file: %s!\n", __func__, config->name, key, result_file); read_ok = false; break; } if (custom_kw_config_has_key(config, key)) { if (hash_has_key(read_keys, key)) { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' has appeared multiple times. Only the last occurrence will be used!\n", __func__, config->name, key); } hash_insert_int(read_keys, key, 1); int index = custom_kw_config_index_of_key(config, key); stringlist_iset_copy(result, index, value); } else { fprintf(stderr ,"[%s] Warning: Key: '%s:%s' not in the available set. Ignored!\n", __func__, config->name, key); } } fclose(stream); if (read_ok) { read_ok = hash_key_list_compare(read_keys, config->custom_keys); } return read_ok; } return false; }
bool summary_key_set_add_summary_key(summary_key_set_type * set, const char * summary_key) { bool writable_and_non_existent = true; pthread_rwlock_wrlock( &set->rw_lock); { if(hash_has_key(set->key_set, summary_key)) { writable_and_non_existent = false; } if(set->read_only) { writable_and_non_existent = false; } if(writable_and_non_existent) { hash_insert_int(set->key_set, summary_key, 1); } } pthread_rwlock_unlock( &set->rw_lock ); return writable_and_non_existent; }
void summary_key_matcher_add_summary_key(summary_key_matcher_type * matcher, const char * summary_key) { if(!hash_has_key(matcher->key_set, summary_key)) { hash_insert_int(matcher->key_set, summary_key, !util_string_has_wildcard(summary_key)); } }
void sched_file_add_fixed_length_kw( sched_file_type * sched_file , const char * kw , int length ) { hash_insert_int( sched_file->fixed_length_table, kw , length ); }