#include "config-load.h" #include "config-ini.h" #include "types.h" #include #include #include #include static const char * simple_basename(const char *path) { const char *slash = strrchr(path, '/'); return slash ? (slash+1) : path; } static const char * extname(const char *filename) { const char *dot = strrchr(filename, '.'); return dot ? (dot+1) : NULL; } static interface_config_t * read_interface_config(const char *path) { ini_file_t *file = read_ini_file(path); ini_section_t *section; ini_field_t *field; list_for_each_entry(section, &file->sections, node) { printf("%s\n", section->name); list_for_each_entry(field, §ion->fields, node) printf("%s.%s=%s\n", section->name, field->key, field->value); } free_ini_file(file); return NULL; } bool read_config_file(const char *path) { const char *filename = simple_basename(path); const char *ext = extname(filename); if (!ext) { errno = EINVAL; return false; } char *name = strndup(filename, (ext - filename) - 1); if (strcmp(ext, "interface") == 0) { interface_config_t *iface = read_interface_config(path); free(iface); } free(name); return true; }