Jump to content

Read a configuration file: Difference between revisions

(→‎C: Added example)
Line 614:
#include <confini.h>
 
#define boolrosetta_uint8_t unsigned char
 
#define FALSE 0
#define TRUE 1
 
#define CONFIGS_MEMBERSCONFIGS_TO_READ 5
#define INI_ARRAY_DELIMITER ','
 
Line 626:
char *fullname;
char *favouritefruit;
boolrosetta_uint8_t needspeeling;
boolrosetta_uint8_t seedsremoved;
char **otherfamily;
size_t otherfamily_len;
Line 671:
}
 
if (ini_string_match_ss!confs->fullname && ini_string_match_si("FULLNAME", this->data, this->format)) {
/* Remove all quotes, if any */
this->d_len = ini_string_parse(this->data, this->format);
 
if (ini_string_match_ss("FULLNAME", this->data, this->format)) {
 
this->v_len = ini_string_parse(this->value, this->format); /* Remove all quotes, if any */
Line 680 ⟶ 677:
confs->_configs_left_--;
 
} else if (ini_string_match_ss!confs->favouritefruit && ini_string_match_si("FAVOURITEFRUIT", this->data, this->format)) {
 
this->v_len = ini_string_parse(this->value, this->format); /* Remove all quotes, if any */
Line 686 ⟶ 683:
confs->_configs_left_--;
 
} else if (ini_string_match_ss(confs->needspeeling & 0x80) && ini_string_match_si("NEEDSPEELING", this->data, this->format)) {
 
confs->needspeeling = ini_get_bool(this->value, TRUE);
confs->_configs_left_--;
 
} else if (ini_string_match_ss(confs->seedsremoved & 0x80) && ini_string_match_si("SEEDSREMOVED", this->data, this->format)) {
 
confs->seedsremoved = ini_get_bool(this->value, TRUE);
confs->_configs_left_--;
 
} else if (ini_string_match_ss!confs->otherfamily && ini_string_match_si("OTHERFAMILY", this->data, this->format)) {
 
this->v_len = ini_array_collapse(this->value, INI_ARRAY_DELIMITER, this->format); /* Save memory (not strictly needed) */
Line 717 ⟶ 714:
.hash_marker = INI_IGNORE,
.multiline_nodes = INI_NO_MULTILINE,
.case_sensitive = TRUEFALSE,
.no_spaces_in_names = TRUE,
.no_single_quotes = FALSE,
Line 728 ⟶ 725:
};
 
*confs = (struct configs) { NULL, NULL, FALSE0x80, FALSE0x80, NULL, 0, CONFIGS_MEMBERSCONFIGS_TO_READ };
 
if (load_ini_path("rosetta.conf", config_format, NULL, configs_member_handler, confs) & CONFINI_ERROR) {
Line 747 ⟶ 744:
ini_global_set_implicit_value("YES", 0);
populate_configs(&confs);
confs.needspeeling &= 0x7F;
confs.seedsremoved &= 0x7F;
 
/* Print the configurations parsed */
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.