static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb, bool no_checks) { char real_path[PATH_MAX_LENGTH]; config_file_t *sub_conf = NULL; struct config_include_list *head = conf->includes; struct config_include_list *node = (struct config_include_list*) malloc(sizeof(*node)); if (node) { node->next = NULL; /* Add include list */ node->path = strdup(path); if (head) { while (head->next) head = head->next; head->next = node; } else conf->includes = node; } real_path[0] = '\0'; #ifdef _WIN32 if (!string_is_empty(conf->path)) fill_pathname_resolve_relative(real_path, conf->path, path, sizeof(real_path)); #else #ifndef __CELLOS_LV2__ if (*path == '~') { const char *home = getenv("HOME"); strlcpy(real_path, home ? home : "", sizeof(real_path)); strlcat(real_path, path + 1, sizeof(real_path)); } else #endif if (!string_is_empty(conf->path)) fill_pathname_resolve_relative(real_path, conf->path, path, sizeof(real_path)); #endif sub_conf = (config_file_t*) config_file_new_internal(real_path, conf->include_depth + 1, cb, no_checks); if (!sub_conf) return; /* Pilfer internal list. */ add_child_list(conf, sub_conf); config_file_free(sub_conf); }
static void add_sub_conf(config_file_t *conf, char *line) { char real_path[PATH_MAX_LENGTH]; config_file_t *sub_conf = NULL; char *path = extract_value(line, false); if (!path) return; add_include_list(conf, path); real_path[0] = '\0'; #ifdef _WIN32 fill_pathname_resolve_relative(real_path, conf->path, path, sizeof(real_path)); #else #ifndef __CELLOS_LV2__ if (*path == '~') { const char *home = getenv("HOME"); strlcpy(real_path, home ? home : "", sizeof(real_path)); strlcat(real_path, path + 1, sizeof(real_path)); } else #endif fill_pathname_resolve_relative(real_path, conf->path, path, sizeof(real_path)); #endif sub_conf = (config_file_t*) config_file_new_internal(real_path, conf->include_depth + 1); if (!sub_conf) { free(path); return; } /* Pilfer internal list. */ add_child_list(conf, sub_conf); config_file_free(sub_conf); free(path); }
config_file_t *config_file_new(const char *path) { return config_file_new_internal(path, 0, NULL); }
config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb) { return config_file_new_internal(path, 0, cb); }
config_file_t *config_file_read(const char *path) { return config_file_new_internal(path, 0, NULL, true); }
static void add_sub_conf(config_file_t *conf, char *line) { char *path = extract_value(line, false); if (!path) return; add_include_list(conf, path); char real_path[PATH_MAX]; #ifdef _WIN32 // Accomodate POSIX systems on Win32. bool is_full_path = *path == '/'; if (is_full_path) strlcpy(real_path, path, sizeof(real_path)); else { // Workaround GetFullPathName not existing on XDK. // : is not a valid element in a path name. (NTFS streams?) if (strchr(path, ':') == NULL) { strlcpy(real_path, conf->path, sizeof(real_path)); char *split = strrchr(real_path, '/'); if (!split) split = strrchr(real_path, '\\'); split[1] = '\0'; strlcat(real_path, path, sizeof(real_path)); } else strlcpy(real_path, path, sizeof(real_path)); } #else if (*path == '/') strlcpy(real_path, path, sizeof(real_path)); #ifndef __CELLOS_LV2__ else if (*path == '~') { const char *home = getenv("HOME"); strlcpy(real_path, home ? home : "/", sizeof(real_path)); strlcat(real_path, path + 1, sizeof(real_path)); } #endif else { strlcpy(real_path, conf->path, sizeof(real_path)); char *split = strrchr(real_path, '/'); if (split) { split[1] = '\0'; strlcat(real_path, path, sizeof(real_path)); } else strlcpy(real_path, path, sizeof(real_path)); } #endif config_file_t *sub_conf = config_file_new_internal(real_path, conf->include_depth + 1); if (!sub_conf) { free(path); return; } // Pilfer internal list. :D add_child_list(conf, sub_conf); config_file_free(sub_conf); free(path); }