FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
FOSSology library to read config file. More...
#include <fossconfig.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
Go to the source code of this file.
Macros | |
#define | BUFFER_SIZE 4096 |
Maximum buffer length. | |
#define | yynext() (c = next()) != EOF |
#define | throw_error(error, domain, code, ...) |
Functions | |
static gint | str_comp (gconstpointer a, gconstpointer b, gpointer user_data) |
static gboolean | collect_keys (char *key, gpointer *value, char **data) |
static gboolean | fo_config_sub (const GMatchInfo *match, GString *ret, gpointer data) |
static int | fo_config_key (GTree *group, gchar *key, gchar *val, gboolean list, gchar *fname, guint line, GError **error) |
Inserts a new Key/Value pair into the mapping of keys to values. More... | |
static gboolean | fo_config_eval (const GMatchInfo *match, GTree **g_current, fo_conf *dest, gchar *yyfile, guint yyline, GError **error) |
Decides what to do with any one line of an input file. More... | |
fo_conf * | fo_config_load (char *rawname, GError **error) |
Load the configuration information from the provided file. More... | |
char * | fo_config_get (fo_conf *conf, const char *group, const char *key, GError **error) |
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned. More... | |
char * | fo_config_get_list (fo_conf *conf, char *group, char *key, int idx, GError **error) |
int | fo_config_is_list (fo_conf *conf, char *group, char *key, GError **error) |
Checks if a particular value is a list or just a normal value. More... | |
int | fo_config_list_length (fo_conf *conf, char *group, char *key, GError **error) |
Gets the length of the list associated with a particular list key. More... | |
void | fo_config_free (fo_conf *conf) |
Frees the memory associated with the internal configuration data structures. More... | |
void | fo_config_join (fo_conf *dst, fo_conf *src, GError **error) |
Takes all groups and key from a fo_conf and adds them to another. More... | |
char ** | fo_config_group_set (fo_conf *conf, int *length) |
Gets the set of group names. More... | |
char ** | fo_config_key_set (fo_conf *conf, char *group, int *length) |
Gets the set of key names for a particular group. More... | |
int | fo_config_has_group (fo_conf *conf, char *group) |
Checks if the currently parsed configuration file has a specific group. More... | |
int | fo_config_has_key (fo_conf *conf, char *group, char *key) |
Checks if the a specific group in the currently parsed configuration file has a specific key. More... | |
char * | trim (char *ptext) |
Trimming whitespace. More... | |
Variables | |
static const gchar * | fo_conf_pattern |
static const gchar * | fo_conf_variable = "\\$(\\w+)" |
GRegex * | fo_conf_parse |
Regex for parsing. | |
GRegex * | fo_conf_replace |
Regex for replace. | |
FOSSology library to read config file.
This library provides various methods to handle the FOSSology configuration file.
Definition in file fossconfig.c.
#define throw_error | ( | error, | |
domain, | |||
code, | |||
... | |||
) |
Create a GError and return
Definition at line 104 of file fossconfig.c.
|
static |
Function that collects all of the keys for a GTree into a single array of strings. This is used to grab the sets of keys for the fo_config_key_set and fo_config_group_set functions printf("%s\n", (*error)->message);
key | the key for this particular key/value pair |
value | the value for this particular key/value pair |
data | not used |
Definition at line 85 of file fossconfig.c.
|
static |
Decides what to do with any one line of an input file.
Based upon what part of the regex matches, this chooses what to do with the line from the input file.
portion/result:
group: create a new GTree* for the new group and move on
key: call fo_config_key with the key/value pair and list set to FALSE
klist: call fo_config_key with the key/value pair and list set to TRUE
match | The regex match that was found |
g_current | The current group that is being read from the file |
dest | The fo_conf struct that all this is being placed in |
yyfile | The name of the file that is being parsed |
yyline | The line of the file that is being parsed |
error | GError struct used to pass errors out |
Definition at line 202 of file fossconfig.c.
void fo_config_free | ( | fo_conf * | conf | ) |
Frees the memory associated with the internal configuration data structures.
conf | The fo_conf struct to free |
Definition at line 506 of file fossconfig.c.
char* fo_config_get | ( | fo_conf * | conf, |
const char * | group, | ||
const char * | key, | ||
GError ** | error | ||
) |
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.
conf | fo_conf object to load from |
group | C string that is the name of the group |
key | C string that is the name of the key for the key/value pair |
Definition at line 336 of file fossconfig.c.
char* fo_config_get_list | ( | fo_conf * | conf, |
char * | group, | ||
char * | key, | ||
int | idx, | ||
GError ** | error | ||
) |
Keys can be associated with multiple values. If this is the case for a particular key, use this function instead of fo_config_get(). This also takes the index of the element in the list. Index work identically to standard c-array indices. It is important to note event though keys will appear as "key[]" in the config file this function just takes "key" as the key
conf | fo_conf object to load from |
group | C string that is the name of the group |
key | C string that is the name of the key for the key/value pair |
idx | The index of the value in the value list |
error | object that allows errors to propagate up the stack |
Definition at line 382 of file fossconfig.c.
char** fo_config_group_set | ( | fo_conf * | conf, |
int * | length | ||
) |
Gets the set of group names.
This function returns an array of strings that the user can iterate to get all group names. The user does not own the return of this function and should not free any of the memory associated with it.
conf | fo_conf object to load from |
length | Pointer allowing the number of groups to be returned |
Definition at line 572 of file fossconfig.c.
int fo_config_has_group | ( | fo_conf * | conf, |
char * | group | ||
) |
Checks if the currently parsed configuration file has a specific group.
conf | fo_conf object to load from |
group | The name of the group to check for |
Definition at line 651 of file fossconfig.c.
int fo_config_has_key | ( | fo_conf * | conf, |
char * | group, | ||
char * | key | ||
) |
Checks if the a specific group in the currently parsed configuration file has a specific key.
group | The group to check for the key |
key | The key to check for |
Definition at line 668 of file fossconfig.c.
int fo_config_is_list | ( | fo_conf * | conf, |
char * | group, | ||
char * | key, | ||
GError ** | error | ||
) |
Checks if a particular value is a list or just a normal value.
conf | fo_conf object to load from |
group | C string name of the group |
key | C string name of the key |
Definition at line 439 of file fossconfig.c.
Takes all groups and key from a fo_conf and adds them to another.
This will iterate across the groups of a configuration and add each to another configuration. This joins the two configurations, making it possible to see multiple configuration files as a single configuration.
dst | The destination for all the information in src |
src | The information that will be duplicated into dst |
error | A location to returns errors from |
Definition at line 531 of file fossconfig.c.
|
static |
Inserts a new Key/Value pair into the mapping of keys to values.
Since the values need to be strings, if the key that is being is inserted is a list then this uses a system of "[value1][value2]...[valueN]"
to store the value. This is done under the assumption that lists are not going to be extremely long.
group | The Group that this key belongs to |
key | The key that the value is associated with |
val | The value that the key maps to |
list | If the key/value pair is a list |
fname | The name of the file that this key was found in |
line | The line number in the file that this key was found on |
error | GError struct that is used to pass errors out of this function |
Definition at line 147 of file fossconfig.c.
char** fo_config_key_set | ( | fo_conf * | conf, |
char * | group, | ||
int * | length | ||
) |
Gets the set of key names for a particular group.
This returns an array of strings that the user can iterate to get all of the key's for a particular group. This is useful if the keys are not known for a particular group. The array returned by this is owned by the config library and should not be freed by the caller.
conf | fo_conf object to load from |
group | C string name of the group |
length | Pointer allowing the number of keys to be returned |
Definition at line 614 of file fossconfig.c.
int fo_config_list_length | ( | fo_conf * | conf, |
char * | group, | ||
char * | key, | ||
GError ** | error | ||
) |
Gets the length of the list associated with a particular list key.
group | C string name of the group |
key | C string name of the key |
Definition at line 475 of file fossconfig.c.
fo_conf* fo_config_load | ( | char * | rawname, |
GError ** | error | ||
) |
Load the configuration information from the provided file.
If the user has not done a fo_config_free since the last fo_config_load, this will make sure to call that first. In other words, it is assumed that if this is called the configuration file has changed and the user would like to use the new copy.
rawname | The name of the configuration file |
error | Object that allows errors to propagate up the stack |
Definition at line 275 of file fossconfig.c.
|
static |
A glib regex replace callback function. This will get called from the fo_config_key when it call g_regex_replace_evel().
match | The regex match that was found in the text i.e. '$HI' |
ret | A GString that is the return location for this function |
data | User data passed into the function, currently unused. |
Definition at line 117 of file fossconfig.c.
|
static |
A wrapper function for the strcmp function that allows it to mascarade as a GCompareDataFunc
a | C string to be compared |
b | C string to be compare |
user_data | not used |
Definition at line 69 of file fossconfig.c.
char* trim | ( | char * | ptext | ) |
Trimming whitespace.
Will trim the lead/trail space
ptext | The string to trim |
Definition at line 690 of file fossconfig.c.
|
static |
Complicated regular expression for parsing the different elements of the ini file format.
The parts:
Please refer to the glib regular expression syntax for more information about how the different parts of the regex work.
Definition at line 44 of file fossconfig.c.
|
static |
Regular expression that is used to match variables in the configuration file. This simply matches a '$' followed by a set of alphabetic characters.
Definition at line 55 of file fossconfig.c.