Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 29388) +++ trunk/scconfig/Rev.h (revision 29389) @@ -1 +1 @@ -static const int myrev = 29385; +static const int myrev = 29389; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 29388) +++ trunk/scconfig/Rev.tab (revision 29389) @@ -1,3 +1,4 @@ +29389 configure move generic actions from core to librnd 29385 configure remove build system special casing: generated lists for action registration 29375 configure librnd separation: stroke plugin API conversion from stub to event 29340 configure librnd separation: tool code Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 29388) +++ trunk/src/Makefile.in (revision 29389) @@ -71,6 +71,7 @@ $(LIBRND)/core/box.o $(LIBRND)/core/color.o $(LIBRND)/core/conf.o + $(LIBRND)/core/conf_act.o $(LIBRND)/core/conf_hid.o $(LIBRND)/core/compat_fs.o $(LIBRND)/core/compat_lrealpath.o @@ -580,7 +581,7 @@ # rndlib: corner case: some headers are not derived from the objects sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/hid_dlg.h } {} -sub /local/pcb/HDRS_HIDLIB {polygon1.h } {} +sub /local/pcb/HDRS_HIDLIB {$(LIBRND)/core/conf_act.h } {} append /local/pcb/HDRS_HIDLIB {$(LIBRND)/config.h $(LIBRND)/core/global_typedefs.h $(LIBRND)/core/globalconst.h $(LIBRND)/core/math_helper.h $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/hid_inlines.h $(LIBRND)/core/rotate.h $(LIBRND)/core/fptr_cast.h $(LIBRND)/core/safe_fs_dir.h $(LIBRND)/core/compat_inc.h $(LIBRND)/poly/rtree2_compat.h $(LIBRND)/core/color_cache.h } gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/dom_[^ ]*.h } {} gsub /local/pcb/HDRS_3RDLIB {../src_3rd/liblihata/tree_[^ ]*.h } {} Index: trunk/src/conf_act.c =================================================================== --- trunk/src/conf_act.c (revision 29388) +++ trunk/src/conf_act.c (revision 29389) @@ -34,203 +34,6 @@ #include #include -static const char pcb_acts_Conf[] = - "conf(set, path, value, [role], [policy]) - change a config setting to an absolute value\n" - "conf(delta, path, value, [role], [policy]) - change a config setting by a delta value (numerics-only)\n" - "conf(toggle, path, [role]) - invert boolean value of a flag; if no role given, overwrite the highest prio config\n" - "conf(reset, role) - reset the in-memory lihata of a role\n" - "conf(iseq, path, value) - returns whether the value of a conf item matches value (for menu checked's)\n" - ; -static const char pcb_acth_Conf[] = "Perform various operations on the configuration tree."; - -extern lht_doc_t *conf_root[]; -static inline int conf_iseq_pf(void *ctx, const char *fmt, ...) -{ - int res; - va_list ap; - va_start(ap, fmt); - res = pcb_safe_append_vprintf((gds_t *)ctx, 0, fmt, ap); - va_end(ap); - return res; -} - -static fgw_error_t pcb_act_Conf(fgw_arg_t *res, int argc, fgw_arg_t *argv) -{ - int op; - const char *a1, *a2, *a3, *a4; - - PCB_ACT_CONVARG(1, FGW_KEYWORD, Conf, op = fgw_keyword(&argv[1])); - PCB_ACT_MAY_CONVARG(2, FGW_STR, Conf, a1 = argv[2].val.str); - PCB_ACT_MAY_CONVARG(3, FGW_STR, Conf, a2 = argv[3].val.str); - PCB_ACT_MAY_CONVARG(4, FGW_STR, Conf, a3 = argv[4].val.str); - PCB_ACT_MAY_CONVARG(5, FGW_STR, Conf, a4 = argv[5].val.str); - - if ((op == F_Set) || (op == F_Delta)) { - const char *path, *val; - char valbuff[128]; - conf_policy_t pol = POL_OVERWRITE; - conf_role_t role = CFR_invalid; - int rs; - - if (argc < 4) { - pcb_message(PCB_MSG_ERROR, "conf(set) needs at least two arguments"); - return FGW_ERR_ARGC; - } - if (argc > 4) { - role = pcb_conf_role_parse(a3); - if (role == CFR_invalid) { - pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a3); - return FGW_ERR_ARG_CONV; - } - } - if (argc > 5) { - pol = pcb_conf_policy_parse(a4); - if (pol == POL_invalid) { - pcb_message(PCB_MSG_ERROR, "Invalid policy: '%s'", a4); - return FGW_ERR_ARG_CONV; - } - } - path = a1; - val = a2; - - if (op == F_Delta) { - double d; - char *end; - conf_native_t *n = pcb_conf_get_field(a1); - - if (n == 0) { - pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': no such path\n", argv[1]); - return FGW_ERR_ARG_CONV; - } - - switch(n->type) { - case CFN_REAL: - d = strtod(val, &end); - if (*end != '\0') { - pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': invalid delta value\n", a1); - return FGW_ERR_ARG_CONV; - } - d += *n->val.real; - sprintf(valbuff, "%f", d); - val = valbuff; - break; - case CFN_COORD: - case CFN_INTEGER: - default: - pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': not a numeric item\n", a1); - return FGW_ERR_ARG_CONV; - } - } - - if (role == CFR_invalid) { - conf_native_t *n = pcb_conf_get_field(a1); - if (n == NULL) { - pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s': no such path\n", a1); - return FGW_ERR_ARG_CONV; - } - rs = pcb_conf_set_native(n, 0, val); - pcb_conf_update(a1, 0); - } - else - rs = pcb_conf_set(role, path, -1, val, pol); - - if (rs != 0) { - pcb_message(PCB_MSG_ERROR, "conf(set) failed.\n"); - return FGW_ERR_UNKNOWN; - } - } - - else if (op == F_Iseq) { - const char *path, *val; - int rs; - gds_t nval; - conf_native_t *n; - - if (argc != 4) { - pcb_message(PCB_MSG_ERROR, "conf(iseq) needs two arguments"); - return FGW_ERR_ARGC; - } - path = a1; - val = a2; - - n = pcb_conf_get_field(a1); - if (n == NULL) { - if (pcbhl_conf.rc.verbose) - pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s' in iseq: no such path\n", path); - return FGW_ERR_ARG_CONV; - } - - gds_init(&nval); - pcb_conf_print_native_field(conf_iseq_pf, &nval, 0, &n->val, n->type, NULL, 0); - rs = !strcmp(nval.array, val); -/* printf("iseq: %s %s==%s %d\n", path, nval.array, val, rs);*/ - gds_uninit(&nval); - - PCB_ACT_IRES(rs); - return 0; - } - - else if (op == F_Toggle) { - conf_native_t *n = pcb_conf_get_field(a1); - const char *new_value; - conf_role_t role = CFR_invalid; - int res; - - if (n == NULL) { - pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s': no such path\n", a1); - return FGW_ERR_UNKNOWN; - } - if (n->type != CFN_BOOLEAN) { - pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': not a boolean\n", a1); - return FGW_ERR_UNKNOWN; - } - if (n->used != 1) { - pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': array size should be 1, not %d\n", a1, n->used); - return FGW_ERR_UNKNOWN; - } - if (argc > 3) { - role = pcb_conf_role_parse(a2); - if (role == CFR_invalid) { - pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a2); - return FGW_ERR_ARG_CONV; - } - } - if (n->val.boolean[0]) - new_value = "false"; - else - new_value = "true"; - if (role == CFR_invalid) - res = pcb_conf_set_native(n, 0, new_value); - else - res = pcb_conf_set(role, a1, -1, new_value, POL_OVERWRITE); - - if (res != 0) { - pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': failed to set new value\n", a1); - return FGW_ERR_UNKNOWN; - } - pcb_conf_update(a1, -1); - } - - else if (op == F_Reset) { - conf_role_t role; - role = pcb_conf_role_parse(a1); - if (role == CFR_invalid) { - pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a1); - return FGW_ERR_ARG_CONV; - } - pcb_conf_reset(role, ""); - pcb_conf_update(a1, -1); - } - - else { - pcb_message(PCB_MSG_ERROR, "Invalid conf command\n"); - return FGW_ERR_ARG_CONV; - } - - PCB_ACT_IRES(0); - return 0; -} - /*------------ get/chk (check flag actions for menus) ------------------*/ static const char pcb_acts_GetStyle[] = "GetStyle()" ; static const char pcb_acth_GetStyle[] = "Return integer index (>=0) of the currently active style or -1 if no style is selected (== custom style)"; @@ -328,7 +131,6 @@ } static pcb_action_t conf_action_list[] = { - {"conf", pcb_act_Conf, pcb_acth_Conf, pcb_acts_Conf}, {"GetStyle", pcb_act_GetStyle, pcb_acth_GetStyle, pcb_acts_GetStyle}, {"ChkMode", pcb_act_ChkMode, pcb_acth_ChkMode, pcb_acts_ChkMode}, {"ChkGridSize", pcb_act_ChkGridSize, pcb_acth_ChkGridSize, pcb_acts_ChkGridSize}, Index: trunk/src/librnd/core/conf_act.c =================================================================== --- trunk/src/librnd/core/conf_act.c (nonexistent) +++ trunk/src/librnd/core/conf_act.c (revision 29389) @@ -0,0 +1,245 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2016,2020 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" +#include "board.h" +#include +#include "conf_core.h" +#include +#include "funchash_core.h" +#include "route_style.h" +#include +#include + +static const char pcb_acts_Conf[] = + "conf(set, path, value, [role], [policy]) - change a config setting to an absolute value\n" + "conf(delta, path, value, [role], [policy]) - change a config setting by a delta value (numerics-only)\n" + "conf(toggle, path, [role]) - invert boolean value of a flag; if no role given, overwrite the highest prio config\n" + "conf(reset, role) - reset the in-memory lihata of a role\n" + "conf(iseq, path, value) - returns whether the value of a conf item matches value (for menu checked's)\n" + ; +static const char pcb_acth_Conf[] = "Perform various operations on the configuration tree."; + +extern lht_doc_t *conf_root[]; +static inline int conf_iseq_pf(void *ctx, const char *fmt, ...) +{ + int res; + va_list ap; + va_start(ap, fmt); + res = pcb_safe_append_vprintf((gds_t *)ctx, 0, fmt, ap); + va_end(ap); + return res; +} + +static fgw_error_t pcb_act_Conf(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + int op; + const char *a1, *a2, *a3, *a4; + + PCB_ACT_CONVARG(1, FGW_KEYWORD, Conf, op = fgw_keyword(&argv[1])); + PCB_ACT_MAY_CONVARG(2, FGW_STR, Conf, a1 = argv[2].val.str); + PCB_ACT_MAY_CONVARG(3, FGW_STR, Conf, a2 = argv[3].val.str); + PCB_ACT_MAY_CONVARG(4, FGW_STR, Conf, a3 = argv[4].val.str); + PCB_ACT_MAY_CONVARG(5, FGW_STR, Conf, a4 = argv[5].val.str); + + if ((op == F_Set) || (op == F_Delta)) { + const char *path, *val; + char valbuff[128]; + conf_policy_t pol = POL_OVERWRITE; + conf_role_t role = CFR_invalid; + int rs; + + if (argc < 4) { + pcb_message(PCB_MSG_ERROR, "conf(set) needs at least two arguments"); + return FGW_ERR_ARGC; + } + if (argc > 4) { + role = pcb_conf_role_parse(a3); + if (role == CFR_invalid) { + pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a3); + return FGW_ERR_ARG_CONV; + } + } + if (argc > 5) { + pol = pcb_conf_policy_parse(a4); + if (pol == POL_invalid) { + pcb_message(PCB_MSG_ERROR, "Invalid policy: '%s'", a4); + return FGW_ERR_ARG_CONV; + } + } + path = a1; + val = a2; + + if (op == F_Delta) { + double d; + char *end; + conf_native_t *n = pcb_conf_get_field(a1); + + if (n == 0) { + pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': no such path\n", argv[1]); + return FGW_ERR_ARG_CONV; + } + + switch(n->type) { + case CFN_REAL: + d = strtod(val, &end); + if (*end != '\0') { + pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': invalid delta value\n", a1); + return FGW_ERR_ARG_CONV; + } + d += *n->val.real; + sprintf(valbuff, "%f", d); + val = valbuff; + break; + case CFN_COORD: + case CFN_INTEGER: + default: + pcb_message(PCB_MSG_ERROR, "Can't delta-set '%s': not a numeric item\n", a1); + return FGW_ERR_ARG_CONV; + } + } + + if (role == CFR_invalid) { + conf_native_t *n = pcb_conf_get_field(a1); + if (n == NULL) { + pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s': no such path\n", a1); + return FGW_ERR_ARG_CONV; + } + rs = pcb_conf_set_native(n, 0, val); + pcb_conf_update(a1, 0); + } + else + rs = pcb_conf_set(role, path, -1, val, pol); + + if (rs != 0) { + pcb_message(PCB_MSG_ERROR, "conf(set) failed.\n"); + return FGW_ERR_UNKNOWN; + } + } + + else if (op == F_Iseq) { + const char *path, *val; + int rs; + gds_t nval; + conf_native_t *n; + + if (argc != 4) { + pcb_message(PCB_MSG_ERROR, "conf(iseq) needs two arguments"); + return FGW_ERR_ARGC; + } + path = a1; + val = a2; + + n = pcb_conf_get_field(a1); + if (n == NULL) { + if (pcbhl_conf.rc.verbose) + pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s' in iseq: no such path\n", path); + return FGW_ERR_ARG_CONV; + } + + gds_init(&nval); + pcb_conf_print_native_field(conf_iseq_pf, &nval, 0, &n->val, n->type, NULL, 0); + rs = !strcmp(nval.array, val); +/* printf("iseq: %s %s==%s %d\n", path, nval.array, val, rs);*/ + gds_uninit(&nval); + + PCB_ACT_IRES(rs); + return 0; + } + + else if (op == F_Toggle) { + conf_native_t *n = pcb_conf_get_field(a1); + const char *new_value; + conf_role_t role = CFR_invalid; + int res; + + if (n == NULL) { + pcb_message(PCB_MSG_ERROR, "Invalid conf field '%s': no such path\n", a1); + return FGW_ERR_UNKNOWN; + } + if (n->type != CFN_BOOLEAN) { + pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': not a boolean\n", a1); + return FGW_ERR_UNKNOWN; + } + if (n->used != 1) { + pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': array size should be 1, not %d\n", a1, n->used); + return FGW_ERR_UNKNOWN; + } + if (argc > 3) { + role = pcb_conf_role_parse(a2); + if (role == CFR_invalid) { + pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a2); + return FGW_ERR_ARG_CONV; + } + } + if (n->val.boolean[0]) + new_value = "false"; + else + new_value = "true"; + if (role == CFR_invalid) + res = pcb_conf_set_native(n, 0, new_value); + else + res = pcb_conf_set(role, a1, -1, new_value, POL_OVERWRITE); + + if (res != 0) { + pcb_message(PCB_MSG_ERROR, "Can not toggle '%s': failed to set new value\n", a1); + return FGW_ERR_UNKNOWN; + } + pcb_conf_update(a1, -1); + } + + else if (op == F_Reset) { + conf_role_t role; + role = pcb_conf_role_parse(a1); + if (role == CFR_invalid) { + pcb_message(PCB_MSG_ERROR, "Invalid role: '%s'", a1); + return FGW_ERR_ARG_CONV; + } + pcb_conf_reset(role, ""); + pcb_conf_update(a1, -1); + } + + else { + pcb_message(PCB_MSG_ERROR, "Invalid conf command\n"); + return FGW_ERR_ARG_CONV; + } + + PCB_ACT_IRES(0); + return 0; +} + + +static pcb_action_t rnd_conf_action_list[] = { + {"conf", pcb_act_Conf, pcb_acth_Conf, pcb_acts_Conf}, +}; + +void rnd_conf_act_init2(void) +{ + PCB_REGISTER_ACTIONS(rnd_conf_action_list, NULL); +} + + + Index: trunk/src/librnd/core/hid_init.c =================================================================== --- trunk/src/librnd/core/hid_init.c (revision 29388) +++ trunk/src/librnd/core/hid_init.c (revision 29389) @@ -320,8 +320,8 @@ extern void pcb_hidlib_error_init2(void); extern void pcb_hid_dlg_init2(void); extern void pcb_hid_nogui_init2(void); +extern void rnd_conf_act_init2(void); - void pcb_hidlib_init2(const pup_buildin_t *buildins, const pup_buildin_t *local_buildins) { pcb_actions_init(); @@ -367,6 +367,7 @@ pcb_hidlib_error_init2(); pcb_hid_dlg_init2(); pcb_hid_nogui_init2(); + rnd_conf_act_init2(); }