Index: trunk/src_plugins/vendordrill/vendor.c =================================================================== --- trunk/src_plugins/vendordrill/vendor.c (revision 34066) +++ trunk/src_plugins/vendordrill/vendor.c (revision 34067) @@ -193,67 +193,33 @@ return 0; } - -static const char pcb_acts_LoadVendorFrom[] = "LoadVendorFrom(filename, [yes|no])"; -static const char pcb_acth_LoadVendorFrom[] = "Loads the specified vendor lihata file. If second argument is \"yes\" or \"pure\", load in pure mode without side effects: do not reset or apply, only incrementally load."; -/* DOC: loadvendorfrom.html */ -fgw_error_t pcb_act_LoadVendorFrom(fgw_arg_t *res, int argc, fgw_arg_t *argv) +const char *lht_get_htext(lht_node_t *h, const char *name) { - const char *fname = NULL, *spure = NULL; - static char *default_file = NULL; - const char *sval; - int pure = 0, warn_drc = 0; - lht_doc_t *doc; - lht_node_t *drlres; - rnd_bool free_fname = rnd_false; - long num_skips; + lht_node_t *n = lht_dom_hash_get(h, name); - cached_drill = -1; + if ((n == NULL) || (n->type != LHT_TEXT)) + return NULL; - RND_ACT_MAY_CONVARG(1, FGW_STR, LoadVendorFrom, fname = argv[1].val.str); - RND_ACT_MAY_CONVARG(2, FGW_STR, LoadVendorFrom, spure = argv[2].val.str); + return n->data.text.value; +} - if (!fname || !*fname) { - fname = rnd_gui->fileselect(rnd_gui, "Load Vendor Resource File...", - "Picks a vendor resource file to load.\n" - "This file can contain drc settings for a\n" - "particular vendor as well as a list of\n" - "predefined drills which are allowed.", default_file, ".res", - NULL, "vendor", RND_HID_FSD_READ, NULL); - if (fname == NULL) { - RND_ACT_IRES(1); - return 0; - } +static int vendor_load_root(const char *fname, lht_node_t *root, rnd_bool pure) +{ + long num_skips; + lht_node_t *drc, *drlres; + const char *sval; + int warn_drc = 0; - free_fname = rnd_true; - - free(default_file); - default_file = NULL; - - if (fname && *fname) - default_file = rnd_strdup(fname); + if (root->type != LHT_HASH) { + rnd_hid_cfg_error(root, "vendor drill root node must be a hash\n"); + return -1; } - if (spure != NULL) { - if (strcmp(spure, "pure") == 0) - pure = 1; - else - pure = rnd_istrue(spure); - } - if (!pure) vendor_free_all(); - /* load the resource file */ - doc = rnd_hid_cfg_load_lht(&PCB->hidlib, fname); - if (doc == NULL) { - rnd_message(RND_MSG_ERROR, "Could not load vendor resource file \"%s\"\n", fname); - RND_ACT_IRES(1); - return 0; - } - /* figure out the units, if specified */ - sval = rnd_hid_cfg_text_value(doc, "/units"); + sval = lht_get_htext(root, "units"); if (sval == NULL) { if (!pure) sf = RND_MIL_TO_COORD(1); @@ -274,7 +240,8 @@ if (!pure) rounding_method = ROUND_UP; /* default to ROUND_UP */ - sval = rnd_hid_cfg_text_value(doc, "/round"); + + sval = lht_get_htext(root, "round"); if (sval != NULL) { if (RND_NSTRCMP(sval, "up") == 0) { rounding_method = ROUND_UP; @@ -291,10 +258,10 @@ } } - num_skips = process_skips(lht_tree_path(doc, "/", "/skips", 1, NULL)); + num_skips = process_skips(lht_dom_hash_get(root, "skips")); /* extract the drillmap resource */ - drlres = lht_tree_path(doc, "/", "/drillmap", 1, NULL); + drlres = lht_dom_hash_get(root, "drillmap"); if (drlres != NULL) { if (drlres->type == LHT_LIST) { lht_node_t *n; @@ -311,43 +278,46 @@ else rnd_message(RND_MSG_ERROR, "No drillmap resource found\n"); - sval = rnd_hid_cfg_text_value(doc, "/drc/copper_space"); - if (sval != NULL) { - load_meta_coord("design/bloat", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_INFO, "Set DRC minimum copper spacing to %ml mils\n", conf_core.design.bloat); - warn_drc = 1; - } + drc = lht_dom_hash_get(root, "drc"); + if ((drc != NULL) && (drc->type == LHT_HASH)) { + sval = lht_get_htext(drc, "copper_space"); + if (sval != NULL) { + load_meta_coord("design/bloat", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_INFO, "Set DRC minimum copper spacing to %ml mils\n", conf_core.design.bloat); + warn_drc = 1; + } - sval = rnd_hid_cfg_text_value(doc, "/drc/copper_overlap"); - if (sval != NULL) { - load_meta_coord("design/shrink", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_ERROR, "drc/copper_overlap is not supported anymore, please use the new DRC instead\n"); - } + sval = lht_get_htext(drc, "copper_overlap"); + if (sval != NULL) { + load_meta_coord("design/shrink", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_ERROR, "drc/copper_overlap is not supported anymore, please use the new DRC instead\n"); + } - sval = rnd_hid_cfg_text_value(doc, "/drc/copper_width"); - if (sval != NULL) { - load_meta_coord("design/min_wid", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_INFO, "Set DRC minimum copper spacing to %ml mils\n", conf_core.design.min_wid); - warn_drc = 1; - } + sval = lht_get_htext(drc, "copper_width"); + if (sval != NULL) { + load_meta_coord("design/min_wid", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_INFO, "Set DRC minimum copper spacing to %ml mils\n", conf_core.design.min_wid); + warn_drc = 1; + } - sval = rnd_hid_cfg_text_value(doc, "/drc/silk_width"); - if (sval != NULL) { - load_meta_coord("design/min_slk", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_INFO, "Set DRC minimum silk width to %ml mils\n", conf_core.design.min_slk); - warn_drc = 1; - } + sval = lht_get_htext(drc, "silk_width"); + if (sval != NULL) { + load_meta_coord("design/min_slk", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_INFO, "Set DRC minimum silk width to %ml mils\n", conf_core.design.min_slk); + warn_drc = 1; + } - sval = rnd_hid_cfg_text_value(doc, "/drc/min_drill"); - if (sval != NULL) { - load_meta_coord("design/min_drill", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_ERROR, "drc/min_drill is not supported anymore, please use the new DRC instead\n"); - } + sval = lht_get_htext(drc, "min_drill"); + if (sval != NULL) { + load_meta_coord("design/min_drill", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_ERROR, "drc/min_drill is not supported anymore, please use the new DRC instead\n"); + } - sval = rnd_hid_cfg_text_value(doc, "/drc/min_ring"); - if (sval != NULL) { - load_meta_coord("design/min_ring", floor(sf * atof(sval) + 0.5)); - rnd_message(RND_MSG_ERROR, "drc/min_ring is not supported anymore, please use the new DRC instead\n"); + sval = lht_get_htext(drc, "min_ring"); + if (sval != NULL) { + load_meta_coord("design/min_ring", floor(sf * atof(sval) + 0.5)); + rnd_message(RND_MSG_ERROR, "drc/min_ring is not supported anymore, please use the new DRC instead\n"); + } } rnd_message(RND_MSG_INFO, "Loaded %d vendor drills from %s\n", n_vendor_drills, fname); @@ -361,10 +331,68 @@ if (!pure) apply_vendor_map(); + return 0; +} + +static const char pcb_acts_LoadVendorFrom[] = "LoadVendorFrom(filename, [yes|no])"; +static const char pcb_acth_LoadVendorFrom[] = "Loads the specified vendor lihata file. If second argument is \"yes\" or \"pure\", load in pure mode without side effects: do not reset or apply, only incrementally load."; +/* DOC: loadvendorfrom.html */ +fgw_error_t pcb_act_LoadVendorFrom(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *fname = NULL, *spure = NULL; + static char *default_file = NULL; + int pure = 0; + lht_doc_t *doc; + rnd_bool free_fname = rnd_false; + int r; + + cached_drill = -1; + + RND_ACT_MAY_CONVARG(1, FGW_STR, LoadVendorFrom, fname = argv[1].val.str); + RND_ACT_MAY_CONVARG(2, FGW_STR, LoadVendorFrom, spure = argv[2].val.str); + + if (!fname || !*fname) { + fname = rnd_gui->fileselect(rnd_gui, "Load Vendor Resource File...", + "Picks a vendor resource file to load.\n" + "This file can contain drc settings for a\n" + "particular vendor as well as a list of\n" + "predefined drills which are allowed.", default_file, ".res", + NULL, "vendor", RND_HID_FSD_READ, NULL); + if (fname == NULL) { + RND_ACT_IRES(1); + return 0; + } + + free_fname = rnd_true; + + free(default_file); + default_file = NULL; + + if (fname && *fname) + default_file = rnd_strdup(fname); + } + + if (spure != NULL) { + if (strcmp(spure, "pure") == 0) + pure = 1; + else + pure = rnd_istrue(spure); + } + + /* load the resource file */ + doc = rnd_hid_cfg_load_lht(&PCB->hidlib, fname); + if (doc == NULL) { + rnd_message(RND_MSG_ERROR, "Could not load vendor resource file \"%s\"\n", fname); + RND_ACT_IRES(1); + return 0; + } + + r = vendor_load_root(fname, doc->root, pure); + if (free_fname) free((char*)fname); lht_dom_uninit(doc); - RND_ACT_IRES(0); + RND_ACT_IRES(r); return 0; }