Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int module_prev_state, channel_prev_state;
- int module_count = 0;
- int channel_count = 0;
- static int handler(void* user, const char* section, const char* name,
- const char* value)
- {
- settings* pconfig = (settings*)user;
- #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
- if (strcmp(section, "module") == 0) {
- if (MATCH("module", "name")) {
- pconfig->module[module_count].name = strdup(value); ///< Filling module name
- module_prev_state = module_count;
- ++module_count;
- } else if (MATCH("module", "imitationType")) {
- pconfig->module[module_prev_state].imitation_type = strdup(value); ///< Filling imitation type
- } else if (MATCH("module", "tract")) {
- pconfig->module[module_prev_state].tract = atoi(value); ///< Filling physical address
- } else if (MATCH("module", "channel")) {
- pconfig->module[module_prev_state].channel = atoi(value); ///< Filling channel number
- } else {
- module_prev_state = module_count;
- return 0; /* unknown section/name, error */
- }
- }
- if (strcmp(section, "channel") == 0) {
- if (MATCH("channel", "number")) {
- pconfig->channel[channel_count].channel_number = atoi(value); ///< Filling channel number
- channel_prev_state = channel_count;
- ++channel_count; /// Counting channels by names
- } else if (MATCH("channel", "working")) {
- pconfig->channel[channel_prev_state].isWorking = atoi(value); ///< Filling working state
- } else if (MATCH("channel", "frequency")) {
- pconfig->channel[channel_prev_state].frequency = atoi(value); ///< Filling channel frequency
- } else if (MATCH("channel", "moduleCount")) {
- pconfig->channel[channel_prev_state].moduleCount = atoi(value); ///< Filling module amount
- } else {
- channel_prev_state = channel_count;
- return 0; /* unknown section/name, error */
- }
- }
- /// Reallocating memory for next iterations
- pconfig = (settings *) realloc(pconfig, (module_count + channel_count) * sizeof(channel_config));
- pconfig->module = (module_config *) realloc(pconfig->module, module_count * sizeof(module_config));
- pconfig->channel = (channel_config *) realloc(pconfig->channel, channel_count * sizeof(channel_config));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement