Index: dlg.c =================================================================== --- dlg.c (revision 31280) +++ dlg.c (revision 31281) @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include "actions_pcb.h" #define PCB dont_use @@ -144,7 +142,7 @@ rnd_message(RND_MSG_ERROR, "Internal error: failed to create role root, rule is NOT saved\n"); return; } - MKDIR_RULES(nd); + MKDIR_RULES(nd, return); if ((nd->data.list.first == NULL) && (role != RND_CFR_USER)) { gdl_iterator_t it; rnd_conf_listitem_t *i; @@ -156,22 +154,20 @@ } rnd_message(RND_MSG_WARNING, "NOTE: Copying ALL drc rule to config role %s\n", ctx->rule, save_roles[ri]); } - MKDIR_ND(nd, nd, LHT_HASH, ctx->rule); + MKDIR_ND(nd, nd, LHT_HASH, ctx->rule, return); rnd_message(RND_MSG_INFO, "NOTE: Copying drc rule '%s' to config role %s\n", ctx->rule, save_roles[ri]); } - MKDIR_ND_SET_TEXT(nd, "type", ctx->dlg[ctx->wtype].val.str); - MKDIR_ND_SET_TEXT(nd, "desc", ctx->dlg[ctx->wdesc].val.str); - MKDIR_ND_SET_TEXT(nd, "title", ctx->dlg[ctx->wtitle].val.str); - MKDIR_ND_SET_TEXT(nd, "source", ctx->dlg[ctx->wsource].val.str); - MKDIR_ND_SET_TEXT(nd, "query", txt->hid_get_text(atxt, hid_ctx)); + MKDIR_ND_SET_TEXT(nd, "type", ctx->dlg[ctx->wtype].val.str, return); + MKDIR_ND_SET_TEXT(nd, "desc", ctx->dlg[ctx->wdesc].val.str, return); + MKDIR_ND_SET_TEXT(nd, "title", ctx->dlg[ctx->wtitle].val.str, return); + MKDIR_ND_SET_TEXT(nd, "source", ctx->dlg[ctx->wsource].val.str, return); + MKDIR_ND_SET_TEXT(nd, "query", txt->hid_get_text(atxt, hid_ctx), return); rnd_conf_update(NULL, -1); drc_rlist_pcb2dlg(); } -#undef MKDIR_ND - static int pcb_dlg_rule_edit(rnd_conf_role_t role, const char *rule) { rnd_hid_dad_buttons_t clbtn[] = {{"Close", 0}, {NULL, 0}}; Index: drc_query.c =================================================================== --- drc_query.c (revision 31280) +++ drc_query.c (revision 31281) @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include #include @@ -355,17 +357,17 @@ return nt->data.text.value; } -#define MKDIR_ND(outnode, parent, ntype, nname) \ +#define MKDIR_ND(outnode, parent, ntype, nname, errinstr) \ do { \ lht_node_t *nnew; \ lht_err_t err; \ - char *nname0 = nname; \ + char *nname0 = (char *)nname; \ if (parent->type == LHT_LIST) nname0 = rnd_concat(nname, ":0", NULL); \ nnew = lht_tree_path_(parent->doc, parent, nname0, 1, 1, &err); \ if (parent->type == LHT_LIST) free(nname0); \ if ((nnew != NULL) && (nnew->type != ntype)) { \ rnd_message(RND_MSG_ERROR, "Internal error: invalid existing node type for %s: %d, rule is NOT saved\n", nname, nnew->type); \ - return; \ + errinstr; \ } \ else if (nnew == NULL) { \ nnew = lht_dom_node_alloc(ntype, nname); \ @@ -374,29 +376,29 @@ case LHT_LIST: err = lht_dom_list_append(parent, nnew); break; \ default: \ rnd_message(RND_MSG_ERROR, "Internal error: invalid parent node type for %s: %d, rule is NOT saved\n", parent->name, parent->type); \ - return; \ + errinstr; \ } \ } \ outnode = nnew; \ } while(0) -#define MKDIR_ND_SET_TEXT(parent, nname, nval) \ +#define MKDIR_ND_SET_TEXT(parent, nname, nval, errinstr) \ do { \ lht_node_t *ntxt; \ - MKDIR_ND(ntxt, parent, LHT_TEXT, nname); \ + MKDIR_ND(ntxt, parent, LHT_TEXT, nname, errinstr); \ if (ntxt == NULL) { \ rnd_message(RND_MSG_ERROR, "Internal error: new text node for %s is NULL, rule is NOT saved\n", nname); \ - return; \ + errinstr; \ } \ free(ntxt->data.text.value); \ ntxt->data.text.value = rnd_strdup(nval == NULL ? "" : nval); \ } while(0) -#define MKDIR_RULES(nd) \ +#define MKDIR_RULES(nd, errinstr) \ do { \ - MKDIR_ND(nd, nd, LHT_HASH, "plugins"); \ - MKDIR_ND(nd, nd, LHT_HASH, "drc_query"); \ - MKDIR_ND(nd, nd, LHT_LIST, "rules"); \ + MKDIR_ND(nd, nd, LHT_HASH, "plugins", errinstr); \ + MKDIR_ND(nd, nd, LHT_HASH, "drc_query", errinstr); \ + MKDIR_ND(nd, nd, LHT_LIST, "rules", errinstr); \ } while(0) static int pcb_drc_query_rule_by_name(const char *name, rnd_conf_native_t **nat_out, lht_node_t **nd_out, int do_create) @@ -404,7 +406,7 @@ char *path = rnd_concat(DRC_CONF_PATH_RULES, name, NULL); rnd_conf_native_t *nat = rnd_conf_get_field(path); lht_node_t *nd = NULL; - int ret = -1; + int ret = -1, needs_update = 0; if (!do_create) { if (nat != NULL) { @@ -414,9 +416,12 @@ } else { if (nat == NULL) { /* allocate new node */ -TODO("allocate new rule here"); -/* MKDIR_RULES(nd) - MKDIR_ND(nd, nd, LHT_HASH, name);*/ + MKDIR_RULES(nd, goto skip); + MKDIR_ND(nd, nd, LHT_HASH, name, goto skip); + if (nd == NULL) /* failed to create */ + ret = -1; + else + needs_update = 1; } else { /* failed to allocate because it exists: return error, but also set the output */ ret = -1; @@ -423,6 +428,10 @@ } } + if (needs_update) + rnd_conf_update(path, -1); + + skip:; free(path); if (nat_out != NULL) @@ -431,6 +440,7 @@ *nd_out = nd; return ret; + } static int pcb_drc_query_clear(rnd_hidlib_t *hidlib, const char *src) @@ -445,7 +455,7 @@ if (pcb_drc_query_rule_by_name(rule, NULL, &nd, 1) != 0) return -1; /* do not re-create existing rule, force creating a new */ - + return -1; } static int pcb_drc_query_set(rnd_hidlib_t *hidlib, const char *rule, const char *key, const char *val)