Index: brave.c =================================================================== --- brave.c (revision 12708) +++ brave.c (revision 12709) @@ -25,19 +25,75 @@ #include "config.h" +#include + #include "brave.h" +#include "compat_misc.h" +#include "error.h" #include "hid_dad.h" -static struct { +pcb_brave_t pcb_brave = 0; + +typedef struct { pcb_brave_t bit; - const char *shrt, *lng; -} desc[] = { - {PCB_BRAVE_PSTK_VIA, "use padstack for vias", - "placing new vias will place padstacks instsad of old via objects" }, - {0, NULL, NULL} + const char *name, *shrt, *lng; + int widget; +} desc_t; + +static desc_t desc[] = { + {PCB_BRAVE_PSTK_VIA, "pstk_via", "use padstack for vias", + "placing new vias will place padstacks instsad of old via objects", 0 }, + {0, NULL, NULL, NULL} }; +static desc_t *find_by_name(const char *name) +{ + desc_t *d; + for(d = desc; d->name != NULL; d++) + if (pcb_strcasecmp(name, d->name) == 0) + return d; + return NULL; +} +static void set_conf(pcb_brave_t br) +{ + gds_t tmp; + desc_t *d; + + gds_init(&tmp); + + for(d = desc; d->name != NULL; d++) { + if (br & d->bit) { + gds_append_str(&tmp, d->name); + gds_append(&tmp, ','); + } + } + + /* truncate last comma */ + gds_truncate(&tmp, gds_len(&tmp)-1); + +#warning TODO: set the conf + + gds_uninit(&tmp); +} + +static void brave_set(pcb_brave_t bit, int on) +{ + int state = pcb_brave & bit; + pcb_brave_t nb; + + if (state == on) + return; + + if (on) + nb = pcb_brave | bit; + else + nb = pcb_brave & ~bit; + + set_conf(nb); +} + + static const char pcb_acts_Brave[] = "Brave()\n" "Brave(setting, on|off)\n"; @@ -44,6 +100,25 @@ static const char pcb_acth_Brave[] = "Changes brave settings."; static int pcb_act_Brave(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) { + desc_t *d; + if (argc == 0) { + + } + + /* look up */ + if (argc > 0) { + d = find_by_name(argv[0]); + if (d == NULL) { + pcb_message(PCB_MSG_ERROR, "Unknown brave setting: %s\n", argv[0]); + return -1; + } + } + + if (argc > 1) + brave_set(d->bit, (pcb_strcasecmp(argv[1], "on") == 0)); + + pcb_message(PCB_MSG_INFO, "Brave setting: %s in %s\n", argv[0], (pcb_brave & d->bit) ? "on" : "off"); + return 0; }