rename structures key & section to ConfigKey & ConfigSection to avoid
generation wrong links in Doxygen
This commit is contained in:
+50
-48
@@ -25,32 +25,34 @@
|
|||||||
#include "shared/report.h"
|
#include "shared/report.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct key {
|
/** configuration key */
|
||||||
char *name;
|
typedef struct _config_key {
|
||||||
char *value;
|
char *name; /**< name of the config key */
|
||||||
struct key *next_key;
|
char *value; /**< value of the config key */
|
||||||
} key;
|
struct _config_key *next_key; /**< pointer to next config key */
|
||||||
|
} ConfigKey;
|
||||||
|
|
||||||
typedef struct section {
|
/** configuration section */
|
||||||
char *name;
|
typedef struct _config_section {
|
||||||
key *first_key;
|
char *name; /**< name of the config section */
|
||||||
struct section *next_section;
|
ConfigKey *first_key; /**< config keys in the config section */
|
||||||
} section;
|
struct _config_section *next_section; /**< pointer to next config section */
|
||||||
|
} ConfigSection;
|
||||||
|
|
||||||
|
|
||||||
static section *first_section = NULL;
|
static ConfigSection *first_section = NULL;
|
||||||
/* Yes there is a static. It's C after all :)*/
|
/* Yes there is a static. It's C after all :)*/
|
||||||
|
|
||||||
|
|
||||||
static section *find_section(const char *sectionname);
|
static ConfigSection *find_section(const char *sectionname);
|
||||||
static section *add_section(const char *sectionname);
|
static ConfigSection *add_section(const char *sectionname);
|
||||||
static key *find_key(section *s, const char *keyname, int skip);
|
static ConfigKey *find_key(ConfigSection *s, const char *keyname, int skip);
|
||||||
static key *add_key(section *s, const char *keyname, const char *value);
|
static ConfigKey *add_key(ConfigSection *s, const char *keyname, const char *value);
|
||||||
static char get_next_char_f(FILE *f);
|
static char get_next_char_f(FILE *f);
|
||||||
#if defined(LCDPROC_CONFIG_READ_STRING)
|
#if defined(LCDPROC_CONFIG_READ_STRING)
|
||||||
static int process_config(section **current_section, char(*get_next_char)(), const char *source_descr, FILE *f);
|
static int process_config(ConfigSection **current_section, char(*get_next_char)(), const char *source_descr, FILE *f);
|
||||||
#else
|
#else
|
||||||
static int process_config(section **current_section, const char *source_descr, FILE *f);
|
static int process_config(ConfigSection **current_section, const char *source_descr, FILE *f);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ static int process_config(section **current_section, const char *source_descr, F
|
|||||||
int config_read_file(const char *filename)
|
int config_read_file(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
section *curr_section = NULL;
|
ConfigSection *curr_section = NULL;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
report(RPT_NOTICE, "Using Configuration File: %s", filename);
|
report(RPT_NOTICE, "Using Configuration File: %s", filename);
|
||||||
@@ -91,7 +93,7 @@ int config_read_string(const char *sectionname, const char *str)
|
|||||||
/* All the config parameters are placed in the given section in memory.*/
|
/* All the config parameters are placed in the given section in memory.*/
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
section *s;
|
ConfigSection *s;
|
||||||
|
|
||||||
/* We use a nested fuction to transfer the characters from buffer to parser*/
|
/* We use a nested fuction to transfer the characters from buffer to parser*/
|
||||||
char get_next_char() {
|
char get_next_char() {
|
||||||
@@ -145,7 +147,7 @@ int config_read_string(const char *sectionname, const char *str)
|
|||||||
const char *config_get_string(const char *sectionname, const char *keyname,
|
const char *config_get_string(const char *sectionname, const char *keyname,
|
||||||
int skip, const char *default_value)
|
int skip, const char *default_value)
|
||||||
{
|
{
|
||||||
key *k = find_key(find_section(sectionname), keyname, skip);
|
ConfigKey *k = find_key(find_section(sectionname), keyname, skip);
|
||||||
|
|
||||||
if (k == NULL)
|
if (k == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
@@ -182,7 +184,7 @@ const char *config_get_string(const char *sectionname, const char *keyname,
|
|||||||
short config_get_bool(const char *sectionname, const char *keyname,
|
short config_get_bool(const char *sectionname, const char *keyname,
|
||||||
int skip, short default_value)
|
int skip, short default_value)
|
||||||
{
|
{
|
||||||
key *k = find_key(find_section(sectionname), keyname, skip);
|
ConfigKey *k = find_key(find_section(sectionname), keyname, skip);
|
||||||
|
|
||||||
if (k == NULL)
|
if (k == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
@@ -221,7 +223,7 @@ short config_get_bool(const char *sectionname, const char *keyname,
|
|||||||
short config_get_tristate(const char *sectionname, const char *keyname,
|
short config_get_tristate(const char *sectionname, const char *keyname,
|
||||||
int skip, const char *name3rd, short default_value)
|
int skip, const char *name3rd, short default_value)
|
||||||
{
|
{
|
||||||
key *k = find_key(find_section(sectionname), keyname, skip);
|
ConfigKey *k = find_key(find_section(sectionname), keyname, skip);
|
||||||
|
|
||||||
if (k == NULL)
|
if (k == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
@@ -257,7 +259,7 @@ short config_get_tristate(const char *sectionname, const char *keyname,
|
|||||||
long int config_get_int(const char *sectionname, const char *keyname,
|
long int config_get_int(const char *sectionname, const char *keyname,
|
||||||
int skip, long int default_value)
|
int skip, long int default_value)
|
||||||
{
|
{
|
||||||
key *k = find_key(find_section(sectionname), keyname, skip);
|
ConfigKey *k = find_key(find_section(sectionname), keyname, skip);
|
||||||
|
|
||||||
if (k != NULL) {
|
if (k != NULL) {
|
||||||
char *end;
|
char *end;
|
||||||
@@ -284,7 +286,7 @@ long int config_get_int(const char *sectionname, const char *keyname,
|
|||||||
double config_get_float(const char *sectionname, const char *keyname,
|
double config_get_float(const char *sectionname, const char *keyname,
|
||||||
int skip, double default_value)
|
int skip, double default_value)
|
||||||
{
|
{
|
||||||
key *k = find_key(find_section(sectionname), keyname, skip);
|
ConfigKey *k = find_key(find_section(sectionname), keyname, skip);
|
||||||
|
|
||||||
if (k != NULL) {
|
if (k != NULL) {
|
||||||
char *end;
|
char *end;
|
||||||
@@ -317,11 +319,11 @@ int config_has_section(const char *sectionname)
|
|||||||
*/
|
*/
|
||||||
int config_has_key(const char *sectionname, const char *keyname)
|
int config_has_key(const char *sectionname, const char *keyname)
|
||||||
{
|
{
|
||||||
section *s = find_section(sectionname);
|
ConfigSection *s = find_section(sectionname);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
|
|
||||||
for (k = s->first_key; k != NULL; k = k->next_key) {
|
for (k = s->first_key; k != NULL; k = k->next_key) {
|
||||||
/* Did we find the right key ?*/
|
/* Did we find the right key ?*/
|
||||||
@@ -336,12 +338,12 @@ int config_has_key(const char *sectionname, const char *keyname)
|
|||||||
/** Clear configuration. */
|
/** Clear configuration. */
|
||||||
void config_clear(void)
|
void config_clear(void)
|
||||||
{
|
{
|
||||||
section *s;
|
ConfigSection *s;
|
||||||
section *next_s;
|
ConfigSection *next_s;
|
||||||
|
|
||||||
for (s = first_section; s != NULL; s = next_s) {
|
for (s = first_section; s != NULL; s = next_s) {
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
key *next_k;
|
ConfigKey *next_k;
|
||||||
|
|
||||||
for (k = s->first_key; k != NULL; k = next_k) {
|
for (k = s->first_key; k != NULL; k = next_k) {
|
||||||
/* Advance before we destroy the current key */
|
/* Advance before we destroy the current key */
|
||||||
@@ -365,9 +367,9 @@ void config_clear(void)
|
|||||||
|
|
||||||
/**** INTERNAL FUNCTIONS ****/
|
/**** INTERNAL FUNCTIONS ****/
|
||||||
|
|
||||||
static section *find_section(const char *sectionname)
|
static ConfigSection *find_section(const char *sectionname)
|
||||||
{
|
{
|
||||||
section *s;
|
ConfigSection *s;
|
||||||
|
|
||||||
for (s = first_section; s != NULL; s = s->next_section) {
|
for (s = first_section; s != NULL; s = s->next_section) {
|
||||||
if (strcasecmp(s->name, sectionname) == 0) {
|
if (strcasecmp(s->name, sectionname) == 0) {
|
||||||
@@ -378,15 +380,15 @@ static section *find_section(const char *sectionname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static section *add_section(const char *sectionname)
|
static ConfigSection *add_section(const char *sectionname)
|
||||||
{
|
{
|
||||||
section *s;
|
ConfigSection *s;
|
||||||
section **place = &first_section;
|
ConfigSection **place = &first_section;
|
||||||
|
|
||||||
for (s = first_section; s != NULL; s = s->next_section)
|
for (s = first_section; s != NULL; s = s->next_section)
|
||||||
place = &(s->next_section);
|
place = &(s->next_section);
|
||||||
|
|
||||||
*place = (section*) malloc(sizeof(section));
|
*place = (ConfigSection *) malloc(sizeof(ConfigSection));
|
||||||
if (*place != NULL) {
|
if (*place != NULL) {
|
||||||
(*place)->name = strdup(sectionname);
|
(*place)->name = strdup(sectionname);
|
||||||
(*place)->first_key = NULL;
|
(*place)->first_key = NULL;
|
||||||
@@ -397,11 +399,11 @@ static section *add_section(const char *sectionname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static key *find_key(section *s, const char *keyname, int skip)
|
static ConfigKey *find_key(ConfigSection *s, const char *keyname, int skip)
|
||||||
{
|
{
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
key *last_key = NULL;
|
ConfigKey *last_key = NULL;
|
||||||
|
|
||||||
/* Check for NULL section*/
|
/* Check for NULL section*/
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
@@ -425,16 +427,16 @@ static key *find_key(section *s, const char *keyname, int skip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static key *add_key(section *s, const char *keyname, const char *value)
|
static ConfigKey *add_key(ConfigSection *s, const char *keyname, const char *value)
|
||||||
{
|
{
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
key **place = &(s->first_key);
|
ConfigKey **place = &(s->first_key);
|
||||||
|
|
||||||
for (k = s->first_key; k != NULL; k = k->next_key)
|
for (k = s->first_key; k != NULL; k = k->next_key)
|
||||||
place = &(k->next_key);
|
place = &(k->next_key);
|
||||||
|
|
||||||
*place = (key *) malloc(sizeof(key));
|
*place = (ConfigKey *) malloc(sizeof(ConfigKey));
|
||||||
if (*place != NULL) {
|
if (*place != NULL) {
|
||||||
(*place)->name = strdup(keyname);
|
(*place)->name = strdup(keyname);
|
||||||
(*place)->value = strdup(value);
|
(*place)->value = strdup(value);
|
||||||
@@ -480,9 +482,9 @@ static char get_next_char_f(FILE *f)
|
|||||||
|
|
||||||
|
|
||||||
#if defined(LCDPROC_CONFIG_READ_STRING)
|
#if defined(LCDPROC_CONFIG_READ_STRING)
|
||||||
static int process_config(section **current_section, char(*get_next_char)(), const char *source_descr, FILE *f)
|
static int process_config(ConfigSection **current_section, char(*get_next_char)(), const char *source_descr, FILE *f)
|
||||||
#else
|
#else
|
||||||
static int process_config(section **current_section, const char *source_descr, FILE *f)
|
static int process_config(ConfigSection **current_section, const char *source_descr, FILE *f)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int state = ST_INITIAL;
|
int state = ST_INITIAL;
|
||||||
@@ -494,7 +496,7 @@ static int process_config(section **current_section, const char *source_descr, F
|
|||||||
char value[MAXVALUELENGTH+1];
|
char value[MAXVALUELENGTH+1];
|
||||||
int value_pos = 0;
|
int value_pos = 0;
|
||||||
int escape = 0;
|
int escape = 0;
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
int line_nr = 1;
|
int line_nr = 1;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@@ -807,10 +809,10 @@ static int process_config(section **current_section, const char *source_descr, F
|
|||||||
#if CONFIGFILE_DEBUGTEST
|
#if CONFIGFILE_DEBUGTEST
|
||||||
void config_dump(void)
|
void config_dump(void)
|
||||||
{
|
{
|
||||||
section *s;
|
ConfigSection *s;
|
||||||
|
|
||||||
for (s = first_section; s != NULL; s = s->next_section) {
|
for (s = first_section; s != NULL; s = s->next_section) {
|
||||||
key *k;
|
ConfigKey *k;
|
||||||
|
|
||||||
fprintf(stderr, "[%s]\n", s->name);
|
fprintf(stderr, "[%s]\n", s->name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user