#include <eh_utils.h>
Go to the source code of this file.
Functions | |
CLASS (Eh_key_file) | |
GQuark | eh_key_file_error_quark (void) |
void | destroy_hash_table_list (gpointer key, gpointer value, gpointer user_data) |
Destroy each symbol table in a list. | |
void | dup_key (gpointer key, gpointer value, gpointer user_data) |
Duplicate a key of a GHashTable and add it to a list. | |
gchar ** | eh_key_file_list_to_array (GList *l, gpointer key) |
Construct an array of value-strings from a list of symbol tables. | |
Eh_symbol_table | eh_key_file_add_group (Eh_key_file f, const gchar *group_name, gboolean replace) |
void | add_record_value (gpointer key, gpointer value, gpointer user_data) |
Add a key-value pair to a key-file group. | |
Eh_key_file | eh_key_file_new () |
Eh_key_file | eh_key_file_destroy (Eh_key_file f) |
gboolean | eh_key_file_has_group (Eh_key_file f, const gchar *group_name) |
gboolean | eh_key_file_has_key (Eh_key_file f, const gchar *group_name, const gchar *key) |
gchar ** | eh_key_file_get_groups (Eh_key_file f) |
gint | eh_key_file_group_size (Eh_key_file f, const gchar *group_name) |
gint | eh_key_file_size (Eh_key_file f) |
gchar ** | eh_key_file_get_keys (Eh_key_file f, const gchar *group_name) |
gchar ** | eh_key_file_get_all_values (Eh_key_file f, const gchar *group_name, const gchar *key) |
gchar * | eh_key_file_get_value (Eh_key_file f, const gchar *group_name, const gchar *key) |
gchar * | eh_key_file_get_str_value (Eh_key_file f, const gchar *group_name, const gchar *key) |
gchar ** | eh_key_file_get_str_values (Eh_key_file f, const gchar *group_name, const gchar *key) |
gboolean | eh_key_file_get_bool_value (Eh_key_file f, const gchar *group_name, const gchar *key) |
gboolean * | eh_key_file_get_bool_values (Eh_key_file f, const gchar *group_name, const gchar *key) |
double | eh_key_file_get_dbl_value (Eh_key_file f, const gchar *group_name, const gchar *key) |
double * | eh_key_file_get_dbl_array (Eh_key_file f, const gchar *group_name, const gchar *key, gint *len) |
double * | eh_key_file_get_dbl_values (Eh_key_file f, const gchar *group_name, const gchar *key) |
gint | eh_key_file_get_int_value (Eh_key_file f, const gchar *group_name, const gchar *key) |
void | eh_key_file_set_value (Eh_key_file f, const gchar *group_name, const gchar *key, const gchar *value) |
void | eh_key_file_reset_value (Eh_key_file f, const gchar *group_name, const gchar *key, const gchar *value) |
Eh_symbol_table | eh_key_file_get_symbol_table (Eh_key_file f, const gchar *group_name) |
Eh_symbol_table * | eh_key_file_get_symbol_tables (Eh_key_file f, const gchar *group_name) |
void | print_keys (gpointer key, gpointer value, gpointer user_data) |
Print the name of a key. | |
Eh_key_file | eh_key_file_scan (const char *file, GError **error) |
gint | eh_key_file_scan_from_template (const gchar *file, const gchar *group_name, Eh_key_file_entry t[], GError **error) |
gssize | eh_key_file_fprint_template (FILE *fp, const gchar *group_name, Eh_key_file_entry entry[]) |
Eh_symbol_table | eh_key_file_scan_for (const gchar *file, const gchar *name, Eh_symbol_table tab, GError **error) |
Eh_symbol_table | eh_key_file_pop_group (Eh_key_file f) |
void add_record_value | ( | gpointer | key, | |
gpointer | value, | |||
gpointer | user_data | |||
) |
Add a key-value pair to a key-file group.
A helper function to add a key-value pair to a Eh_key_file
key | The key-string to add | |
value | The value-string to add | |
user_data | Location of a the key-file and group name. |
Definition at line 140 of file eh_key_file.c.
References eh_key_file_set_value().
Referenced by eh_key_file_scan().
CLASS | ( | Eh_key_file | ) |
Definition at line 3 of file eh_key_file.c.
void destroy_hash_table_list | ( | gpointer | key, | |
gpointer | value, | |||
gpointer | user_data | |||
) |
Destroy each symbol table in a list.
A helper function that destroys each Eh_symbol_table in a GList, as well as the GList itself. In this case, it is used to destroy a group of an Eh_key_file.
key | The key parameter of a GHashTable. In this case, it is the name of group. | |
value | The value parameter of a GHashTable. In this case, it is a pointer to a GList* of Eh_symbol_table's. | |
user_data | Unused. |
Definition at line 26 of file eh_key_file.c.
References eh_symbol_table_destroy().
Referenced by eh_key_file_destroy().
void dup_key | ( | gpointer | key, | |
gpointer | value, | |||
gpointer | user_data | |||
) |
Duplicate a key of a GHashTable and add it to a list.
A helper function to duplicate each key of a GHashTable and add it to a list of all the keys. The keys in the list are delimited by '
'.
key | A pointer to GHashTable key | |
value | A pointer to GHashTable value | |
user_data | Location of the string containing the list of keys |
Definition at line 44 of file eh_key_file.c.
References eh_free.
Referenced by eh_key_file_get_groups(), and eh_key_file_get_keys().
Eh_symbol_table eh_key_file_add_group | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
gboolean | replace | |||
) |
Add a group to a Eh_key_file
Add the group group_name
to an Eh_key_file. If replace
is TRUE, and the group_name
is already present in the key-file, the symbol table of the present group is returned. Otherwise, a new symbol table is created.
f | An Eh_key_file | |
group_name | The name of the group to add (or append) | |
replace | If TRUE, and the given group already exists, it is replaced. Otherwise, a new instance of the group is created. |
Definition at line 96 of file eh_key_file.c.
References eh_require, and eh_symbol_table_new().
Referenced by eh_key_file_reset_value(), and eh_key_file_set_value().
Eh_key_file eh_key_file_destroy | ( | Eh_key_file | f | ) |
Destroy an Eh_key_file
Free all of the resources used by an Eh_key_file.
Definition at line 173 of file eh_key_file.c.
References destroy_hash_table_list(), and eh_free.
Referenced by eh_key_file_scan(), eh_key_file_scan_for(), eh_key_file_scan_from_template(), sed_cube_new_from_file(), sed_epoch_queue_new(), sed_hydro_scan_n_records(), and sed_sediment_scan().
GQuark eh_key_file_error_quark | ( | void | ) |
Definition at line 10 of file eh_key_file.c.
gssize eh_key_file_fprint_template | ( | FILE * | fp, | |
const gchar * | group_name, | |||
Eh_key_file_entry | entry[] | |||
) |
Definition at line 853 of file eh_key_file.c.
References EH_ARG_DARRAY, EH_ARG_DBL, EH_ARG_FILENAME, EH_ARG_INT, eh_free, and Eh_key_file_entry::label.
gchar** eh_key_file_get_all_values | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Get all of the values associated with a key from a key-file group
Note that copies of the value-strings are made, so it is ok to free them when they are no longer needed.
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 330 of file eh_key_file.c.
References eh_key_file_list_to_array().
Referenced by eh_key_file_get_bool_values(), eh_key_file_get_dbl_values(), eh_key_file_get_str_values(), and sed_process_scan().
gboolean eh_key_file_get_bool_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Find a key in a key-file and convert its value to a gboolean
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 415 of file eh_key_file.c.
References eh_free, eh_key_file_get_value(), and eh_str_to_boolean().
gboolean* eh_key_file_get_bool_values | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Find all values of a key in a key-file and convert them to gboolean
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 437 of file eh_key_file.c.
References eh_key_file_get_all_values(), eh_key_file_group_size(), eh_new, and eh_str_to_boolean().
Referenced by sed_process_scan().
double* eh_key_file_get_dbl_array | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key, | |||
gint * | len | |||
) |
Find a key in a key-file and convert its value to a double array
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group | |
len | Location to store the array length |
Definition at line 487 of file eh_key_file.c.
References eh_free, eh_key_file_get_value(), eh_new, and eh_require.
Referenced by eh_key_file_scan_from_template().
double eh_key_file_get_dbl_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Find a key in a key-file and convert its value to a double
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 462 of file eh_key_file.c.
References eh_free, eh_key_file_get_value(), and eh_nan().
Referenced by eh_key_file_scan_from_template(), and sed_cube_new_from_file().
double* eh_key_file_get_dbl_values | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Find all values of a key in a key-file and convert them to double
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 530 of file eh_key_file.c.
References eh_key_file_get_all_values(), eh_key_file_group_size(), and eh_new.
gchar** eh_key_file_get_groups | ( | Eh_key_file | f | ) |
Get the names of all the groups in an Eh_key_file
f | An Eh_key_file |
Definition at line 234 of file eh_key_file.c.
gint eh_key_file_get_int_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
gchar** eh_key_file_get_keys | ( | Eh_key_file | f, | |
const gchar * | group_name | |||
) |
Get all of the keys present in a given group
Note that copies of the key-strings are made, so it is ok to free them when they are no longer needed.
f | An Eh_key_file | |
group_name | The name of a key-file group |
Definition at line 295 of file eh_key_file.c.
References dup_key(), eh_free, and eh_symbol_table_foreach().
gchar* eh_key_file_get_str_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Get a string value from a key-file
Note that a copy of the value-string is made, so it is ok to free it when it is no longer needed. If there is more than one occurance of the group in the key-file, the value is obtained from the first occurance of the group.
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 385 of file eh_key_file.c.
References eh_key_file_get_value().
gchar** eh_key_file_get_str_values | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Get an array of strings from a key-file
Note that copies of the value-strings are made, so it is ok to free them when they are no longer needed.
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 402 of file eh_key_file.c.
References eh_key_file_get_all_values().
Referenced by sed_process_scan().
Eh_symbol_table eh_key_file_get_symbol_table | ( | Eh_key_file | f, | |
const gchar * | group_name | |||
) |
Construct a Eh_symbol_table of key-value pairs for a given group
A new symbol table is created that contains all of the key-value pairs of the given group. If the key-file contains more than one occurance of the group, only the first occurance is used.
f | An Eh_key_file | |
group_name | The name of a key-file group |
Definition at line 644 of file eh_key_file.c.
References eh_symbol_table_dup().
Referenced by eh_key_file_scan_for().
Eh_symbol_table* eh_key_file_get_symbol_tables | ( | Eh_key_file | f, | |
const gchar * | group_name | |||
) |
Construct Eh_symbol_table's of key-value pairs for all occurances of a group
A new symbol table of key-value pairs is created for each occurance of the group and placed into a NULL-terminated array. Each symbol table can be safely destroyed using eh_symbol_table_destroy.
f | An Eh_key_file | |
group_name | The name of a key-file group |
Definition at line 664 of file eh_key_file.c.
References eh_key_file_group_size(), and eh_symbol_table_dup().
Referenced by sed_epoch_queue_new(), and sed_process_scan().
gchar* eh_key_file_get_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Get the value associated with the first occurance of key in a key-file group
Note that a copy of the value-string is made, so it is ok to free it when it is no longer needed. If there is more than one occurance of the group in the key-file, the value is obtained from the first occurance of the group.
f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of a key within the group |
Definition at line 357 of file eh_key_file.c.
References eh_symbol_table_lookup().
Referenced by eh_key_file_get_bool_value(), eh_key_file_get_dbl_array(), eh_key_file_get_dbl_value(), eh_key_file_get_int_value(), eh_key_file_get_str_value(), eh_key_file_scan_from_template(), and sed_cube_new_from_file().
gint eh_key_file_group_size | ( | Eh_key_file | f, | |
const gchar * | group_name | |||
) |
The number of instances of a group in an Eh_key_file
f | An Eh_key_file | |
group_name | The name of a key-file group |
Definition at line 259 of file eh_key_file.c.
Referenced by eh_key_file_get_bool_values(), eh_key_file_get_dbl_values(), eh_key_file_get_symbol_tables(), and sed_process_scan().
gboolean eh_key_file_has_group | ( | Eh_key_file | f, | |
const gchar * | group_name | |||
) |
Query if a key-file has the given group.
f | An Eh_key_file | |
group_name | The name of the group in question |
Definition at line 198 of file eh_key_file.c.
Referenced by eh_key_file_scan_for(), eh_key_file_set_value(), and sed_process_scan().
gboolean eh_key_file_has_key | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key | |||
) |
Query if a key-file group has the given key.
f | An Eh_key_file | |
group_name | The name of the group in question | |
key | The name of the key |
Definition at line 214 of file eh_key_file.c.
References eh_symbol_table_lookup().
Referenced by eh_key_file_scan_from_template(), and eh_key_file_set_value().
gchar** eh_key_file_list_to_array | ( | GList * | l, | |
gpointer | key | |||
) |
Construct an array of value-strings from a list of symbol tables.
From a GList of Eh_symbol_tables, get the corresponding value for the given key-string and put it in an array of strings.
l | The GList of Eh_symbol_tables's | |
key | The key-string specifying the value to get |
Definition at line 69 of file eh_key_file.c.
References eh_symbol_table_lookup().
Referenced by eh_key_file_get_all_values().
Eh_key_file eh_key_file_new | ( | void | ) |
Create a new Eh_key_file
Definition at line 152 of file eh_key_file.c.
References eh_free_mem(), and NEW_OBJECT.
Referenced by eh_key_file_scan().
Eh_symbol_table eh_key_file_pop_group | ( | Eh_key_file | f | ) |
Pop the next group of a key-file
Construct a symbol table of key-value pairs from the next group in a key-file. The group is removed from the Eh_key_file. The groups are ordered in the same way as they are in the original file that was scanned.
f | An Eh_key_file |
Definition at line 972 of file eh_key_file.c.
References eh_free, and eh_require.
Referenced by sed_hydro_scan_n_records(), and sed_sediment_scan().
void eh_key_file_reset_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key, | |||
const gchar * | value | |||
) |
Reset a value in a key-file
This is similar to eh_key_file_set_value, only if the key is already present in the given group, it's value is set to the new value. If the group is not present, then a new group is created.
key
and value
strings are duplicated, so it is fine to free them after use.f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of the key whose value to set | |
value | A string containing the new value |
Definition at line 618 of file eh_key_file.c.
References eh_key_file_add_group(), eh_require, and eh_symbol_table_insert().
Eh_key_file eh_key_file_scan | ( | const char * | file, | |
GError ** | error | |||
) |
Scan a key-file
Scan an entire key-file and construct a new Eh_key_file containing the file information.
file | The name of the file to scan | |
error | A GError |
Definition at line 708 of file eh_key_file.c.
References add_record_value(), eh_close_scanner(), eh_free, eh_key_file_destroy(), eh_key_file_new(), eh_open_scanner(), eh_return_val_if_fail, eh_scan_next_record(), eh_symbol_table_destroy(), eh_symbol_table_foreach(), and eh_symbol_table_new().
Referenced by eh_key_file_scan_for(), eh_key_file_scan_from_template(), sed_cube_new_from_file(), sed_epoch_queue_new(), sed_hydro_scan_n_records(), sed_process_queue_init(), and sed_sediment_scan().
Eh_symbol_table eh_key_file_scan_for | ( | const gchar * | file, | |
const gchar * | name, | |||
Eh_symbol_table | tab, | |||
GError ** | error | |||
) |
Scan a file for a particular key-file group
Scan a key-file for a particular group and place the key-value pairs found in this group into a Eh_symbol_table. If the input symbol table, tab
is NULL, a new symbol table is constructed. Only the first occurance of the group is scanned.
file | The name of the file to scan | |
name | The name of the group to scan | |
tab | A symbol table to place the key-value pairs into. If NULL, a new table will be created. | |
error | A GError |
Definition at line 920 of file eh_key_file.c.
References eh_key_file_destroy(), eh_key_file_get_symbol_table(), eh_key_file_has_group(), eh_key_file_scan(), eh_return_val_if_fail, eh_symbol_table_copy(), and eh_symbol_table_destroy().
Referenced by eh_get_opt_defaults(), and set_default_values().
gint eh_key_file_scan_from_template | ( | const gchar * | file, | |
const gchar * | group_name, | |||
Eh_key_file_entry | t[], | |||
GError ** | error | |||
) |
Definition at line 762 of file eh_key_file.c.
References Eh_key_file_entry::arg_data_len, EH_ARG_DARRAY, EH_ARG_DBL, EH_ARG_FILENAME, EH_ARG_INT, eh_free, eh_key_file_destroy(), EH_KEY_FILE_ERROR, EH_KEY_FILE_ERROR_ARRAY_LEN_MISMATCH, EH_KEY_FILE_ERROR_MISSING_ENTRY, eh_key_file_get_dbl_array(), eh_key_file_get_dbl_value(), eh_key_file_get_value(), eh_key_file_has_key(), eh_key_file_scan(), eh_new, eh_require, eh_return_val_if_fail, eh_strv_append(), and Eh_key_file_entry::label.
Referenced by inflow_scan_parameter_file(), plume_scan_parameter_file(), and sakura_scan_parameter_file().
void eh_key_file_set_value | ( | Eh_key_file | f, | |
const gchar * | group_name, | |||
const gchar * | key, | |||
const gchar * | value | |||
) |
Set a value in a key-file.
Set the value of a key within a group of a key-file. If the group, group_name
does not already exist, then a new group is created and the key-value pair added. If the specified key is already present within the group, a new occurance of the group is created and the key-value pair added to it.
key
and value
strings are duplicated, so it is fine to free them after use.f | An Eh_key_file | |
group_name | The name of a key-file group | |
key | The name of the key whose value to set | |
value | A string containing the new value |
Definition at line 578 of file eh_key_file.c.
References eh_key_file_add_group(), eh_key_file_has_group(), eh_key_file_has_key(), eh_require, and eh_symbol_table_insert().
Referenced by add_record_value().
gint eh_key_file_size | ( | Eh_key_file | f | ) |
The number of groups in an Eh_key_file
The total number of groups including repeated occurances of a group.
f | An Eh_key_file |
Definition at line 275 of file eh_key_file.c.
Referenced by sed_hydro_scan_n_records().
void print_keys | ( | gpointer | key, | |
gpointer | value, | |||
gpointer | user_data | |||
) |
Print the name of a key.
key | A key-string to print | |
value | Not used | |
user_data | Not used |
Definition at line 692 of file eh_key_file.c.