Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 1757) +++ trunk/src/Makefile.in (revision 1758) @@ -16,6 +16,7 @@ change.o change_act.o conf.o + conf_act.o conf_core.o conf_hid.o clip.o @@ -133,7 +134,7 @@ # main: action registrations put /local/pcb/ACTION_REG_SRC { - action_act.c buffer.c change_act.c file_act.c find_act.c + action_act.c buffer.c change_act.c conf_act.c file_act.c find_act.c flags.c gui_act.c main.c misc.c move.c netlist.c object_act.c plugins.c polygon_act.c rats_act.c rats_patch.c remove_act.c select_act.c undo_act.c Index: trunk/src/conf_act.c =================================================================== --- trunk/src/conf_act.c (nonexistent) +++ trunk/src/conf_act.c (revision 1758) @@ -0,0 +1,144 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * + * This module, debug, was written and is Copyright (C) 2016 by Tibor Palinkas + * this module is also subject to the GNU GPL as described below + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "config.h" +#include "global.h" +#include "data.h" +#include "action_helper.h" +#include "conf.h" +#include "error.h" + +static const char conf_syntax[] = + "conf(set, path, value, [role], [policy]) - change a config setting\n" + "conf(toggle, path, [role]) - invert boolean value of a flag; if no role given, overwrite the highest prio config\n" + ; + +static const char conf_help[] = "Perform various operations on the configuration tree."; + +extern lht_doc_t *conf_root[]; +static int ActionConf(int argc, char **argv, Coord x, Coord y) +{ + char *cmd = argc > 0 ? argv[0] : 0; + + if (NSTRCMP(cmd, "set") == 0) { + char *path, *val; + conf_policy_t pol = POL_OVERWRITE; + conf_role_t role = CFR_invalid; + int res; + + if (argc < 3) { + Message("conf(set) needs at least two arguments"); + return 1; + } + if (argc > 3) { + role = conf_role_parse(argv[3]); + if (role == CFR_invalid) { + Message("Invalid role: '%s'", argv[3]); + return 1; + } + } + if (argc > 4) { + pol = conf_policy_parse(argv[4]); + if (pol == POL_invalid) { + Message("Invalid policy: '%s'", argv[4]); + return 1; + } + } + path = argv[1]; + val = argv[2]; + + + if (role == CFR_invalid) { + conf_native_t *n = conf_get_field(argv[1]); + if (n == NULL) { + Message("Invalid conf field '%s': no such path\n", argv[1]); + return 1; + } + res = conf_set_native(n, 0, val); + } + else + res = conf_set(role, path, -1, val, pol); + if (res != 0) { + Message("conf(set) failed.\n"); + return 1; + } + conf_update(); + } + + else if (NSTRCMP(cmd, "toggle") == 0) { + conf_native_t *n = conf_get_field(argv[1]); + char *new_value; + conf_role_t role = CFR_invalid; + int res; + + if (n == NULL) { + Message("Invalid conf field '%s': no such path\n", argv[1]); + return 1; + } + if (n->type != CFN_BOOLEAN) { + Message("Can not toggle '%s': not a boolean\n", argv[1]); + return 1; + } + if (n->used != 1) { + Message("Can not toggle '%s': array size should be 1, not %d\n", argv[1], n->used); + return 1; + } + if (argc > 2) { + role = conf_role_parse(argv[2]); + if (role == CFR_invalid) { + Message("Invalid role: '%s'", argv[2]); + return 1; + } + } + if (n->val.boolean[0]) + new_value = "false"; + else + new_value = "true"; + if (role == CFR_invalid) + res = conf_set_native(n, 0, new_value); + else + res = conf_set(role, argv[1], -1, new_value, POL_OVERWRITE); + + if (res != 0) { + Message("Can not toggle '%s': failed to set new value\n", argv[1]); + return 1; + } + conf_update(); + } + + else { + Message("Invalid conf command '%s'\n", argv[0]); + return 1; + } + return 0; +} + + +HID_Action conf_action_list[] = { + {"conf", 0, ActionConf, + conf_help, conf_syntax} +}; + +REGISTER_ACTIONS(conf_action_list, NULL) Index: trunk/src_plugins/debug/debug.c =================================================================== --- trunk/src_plugins/debug/debug.c (revision 1757) +++ trunk/src_plugins/debug/debug.c (revision 1758) @@ -33,20 +33,18 @@ #include "error.h" static const char conf_syntax[] = - "conf(dump, [verbose], [prefix]) - dump the current config tree to stdout\n" - "conf(dumplht, role, [prefix]) - dump in-memory lihata representation of a config tree\n" - "conf(set, path, value, [role], [policy]) - change a config setting\n" - "conf(toggle, path, [role]) - invert boolean value of a flag; if no role given, overwrite the highest prio config\n" + "dumpconf(native, [verbose], [prefix]) - dump the native (binary) config tree to stdout\n" + "dumpconf(lihata, role, [prefix]) - dump in-memory lihata representation of a config tree\n" ; static const char conf_help[] = "Perform various operations on the configuration tree."; extern lht_doc_t *conf_root[]; -static int ActionConf(int argc, char **argv, Coord x, Coord y) +static int ActionDumpConf(int argc, char **argv, Coord x, Coord y) { char *cmd = argc > 0 ? argv[0] : 0; - if (NSTRCMP(cmd, "dump") == 0) { + if (NSTRCMP(cmd, "native") == 0) { int verbose; const char *prefix = ""; if (argc > 1) @@ -56,7 +54,7 @@ conf_dump(stdout, prefix, verbose); } - else if (NSTRCMP(cmd, "dumplht") == 0) { + else if (NSTRCMP(cmd, "lihata") == 0) { conf_role_t role; const char *prefix = ""; if (argc <= 1) { @@ -171,7 +169,7 @@ HID_Action debug_action_list[] = { - {"conf", 0, ActionConf, + {"dumpconf", 0, ActionDumpConf, conf_help, conf_syntax} };