Index: src/conf.c =================================================================== --- src/conf.c (revision 5901) +++ src/conf.c (revision 5902) @@ -125,8 +125,14 @@ } if (d->root == NULL) { - /* empty project file */ - lht_dom_uninit(d); + lht_node_t *prjroot, *confroot; + prjroot = lht_dom_node_alloc(LHT_HASH, "geda-project-v1"); + confroot = lht_dom_node_alloc(LHT_LIST, "pcb-rnd-conf-v1"); + lht_dom_hash_put(prjroot, confroot); + prjroot->doc = d; + confroot->doc = d; + d->root = prjroot; + conf_root[role] = d; return 0; } @@ -837,19 +843,30 @@ conf_rev++; } -static lht_node_t *conf_lht_get_first_(lht_node_t *cwd) +static lht_node_t *conf_lht_get_first_(lht_node_t *cwd, int create) { + lht_node_t *ov; /* normally the "overwrite" node */ + /* assume root is a li and add to the first hash */ cwd = conf_lht_get_confroot(cwd); if (cwd == NULL) return NULL; - cwd = cwd->data.list.first; - if ((cwd == NULL) || (cwd->type != LHT_HASH)) + ov = cwd->data.list.first; + if (ov == NULL) { + lht_node_t *new_ov; + if (!create) + return NULL; + new_ov = lht_dom_node_alloc(LHT_HASH, "overwrite"); + lht_dom_list_append(cwd, new_ov); + ov = new_ov; + } + else if (ov->type != LHT_HASH) return NULL; - return cwd; + + return ov; } -lht_node_t *conf_lht_get_first(conf_role_t target) +lht_node_t *conf_lht_get_first(conf_role_t target, int create) { assert(target != CFR_invalid); assert(target >= 0); @@ -856,13 +873,13 @@ assert(target < CFR_max_alloc); if (conf_root[target] == NULL) return NULL; - return conf_lht_get_first_(conf_root[target]->root); + return conf_lht_get_first_(conf_root[target]->root, create); } static lht_node_t *conf_lht_get_at_(conf_role_t target, const char *conf_path, const char *lht_path, int create) { - lht_node_t *n, *r; - n = conf_lht_get_first(target); + lht_node_t *n, *r = NULL; + n = conf_lht_get_first(target, create); if (n == NULL) return NULL; r = lht_tree_path_(n->doc, n, lht_path, 1, 0, NULL); @@ -1078,7 +1095,7 @@ return -1; } - cwd = conf_lht_get_first(target); + cwd = conf_lht_get_first(target, 0); if (cwd == NULL) { free(path); return -1; @@ -1498,7 +1515,7 @@ int conf_save_file(const char *project_fn, const char *pcb_fn, conf_role_t role, const char *fn) { int fail = 1; - lht_node_t *r = conf_lht_get_first(role); + lht_node_t *r = conf_lht_get_first(role, 0); const char *try; char *efn; Index: src/conf.h =================================================================== --- src/conf.h (revision 5901) +++ src/conf.h (revision 5902) @@ -318,8 +318,9 @@ #define conf_force_set_str(var, val) *((CFT_STRING *)(&var)) = val /* get the first config subtree node (it's a hash and its children - are "design", "rc", ...) */ -lht_node_t *conf_lht_get_first(conf_role_t target); + are "design", "rc", ...); if create is 1, and the subtree doesn't + exist, create an "overwrite". */ +lht_node_t *conf_lht_get_first(conf_role_t target, int create); /* loop helper */ conf_listitem_t *conf_list_first_str(conflist_t *list, const char **item_str, int *idx); Index: src_plugins/hid_gtk/gui-config.c =================================================================== --- src_plugins/hid_gtk/gui-config.c (revision 5901) +++ src_plugins/hid_gtk/gui-config.c (revision 5902) @@ -1075,7 +1075,7 @@ lht_node_t *m; lht_clean_list(config_library_lst); - m = conf_lht_get_first(CFR_DESIGN); + m = conf_lht_get_first(CFR_DESIGN, 0); cl->lst = lht_tree_path_(m->doc, m, "rc/library_search_paths", 1, 0, NULL); if (cl->lst == NULL) { Index: src_plugins/io_pcb/attribs.c =================================================================== --- src_plugins/io_pcb/attribs.c (revision 5901) +++ src_plugins/io_pcb/attribs.c (revision 5902) @@ -94,7 +94,7 @@ void io_pcb_attrib_c2a(pcb_board_t *pcb) { - lht_node_t *nmain = conf_lht_get_first(CFR_DESIGN); + lht_node_t *nmain = conf_lht_get_first(CFR_DESIGN, 0); c2a(pcb, nmain, ""); }