Index: trunk/src/actions_pcb.c =================================================================== --- trunk/src/actions_pcb.c (revision 29565) +++ trunk/src/actions_pcb.c (revision 29566) @@ -2,7 +2,7 @@ * COPYRIGHT * * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2019 Tibor 'Igor2' Palinkas + * Copyright (C) 2019,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 @@ -38,6 +38,8 @@ #include #include "layer.h" #include "layer_addr.h" +#include "undo.h" +#include "change.h" #include #include "conf_core.h" @@ -281,3 +283,21 @@ abort(); } } + +int pcb_act_execute_file(pcb_hidlib_t *hidlib, const char *fn) +{ + int res; + + defer_updates = 1; + defer_needs_update = 0; + + res = rnd_act_execute_file(hidlib, fn); + + defer_updates = 0; + if (defer_needs_update) { + pcb_undo_inc_serial(); + pcb_gui->invalidate_all(pcb_gui); + } + + return res; +} Index: trunk/src/actions_pcb.h =================================================================== --- trunk/src/actions_pcb.h (revision 29565) +++ trunk/src/actions_pcb.h (revision 29566) @@ -2,3 +2,8 @@ extern const char *PCB_PTR_DOMAIN_LAYERGRP; void pcb_actions_init_pcb_only(void); + +/* Read and execute an action script from a file, batching redraws; + return 0 if all actions returned 0 */ +int pcb_act_execute_file(pcb_hidlib_t *hidlib, const char *fn); + Index: trunk/src/main_act.c =================================================================== --- trunk/src/main_act.c (revision 29565) +++ trunk/src/main_act.c (revision 29566) @@ -40,11 +40,10 @@ #include #include "config.h" -#include "undo.h" -#include "change.h" #include "board.h" #include "data.h" #include "crosshair.h" +#include "actions_pcb.h" #include #include "layer.h" #include @@ -291,53 +290,10 @@ /* DOC: executefile.html */ fgw_error_t pcb_act_ExecuteFile(fgw_arg_t *res, int argc, fgw_arg_t *argv) { - FILE *fp; const char *fname; - char line[256]; - int n = 0; - char *sp; PCB_ACT_CONVARG(1, FGW_STR, ExecuteFile, fname = argv[1].val.str); - - if ((fp = pcb_fopen(PCB_ACT_HIDLIB, fname, "r")) == NULL) { - fprintf(stderr, "Could not open actions file \"%s\".\n", fname); - return 1; - } - - defer_updates = 1; - defer_needs_update = 0; - while (fgets(line, sizeof(line), fp) != NULL) { - n++; - sp = line; - - /* eat the trailing newline */ - while (*sp && *sp != '\r' && *sp != '\n') - sp++; - *sp = '\0'; - - /* eat leading spaces and tabs */ - sp = line; - while (*sp && (*sp == ' ' || *sp == '\t')) - sp++; - - /* - * if we have anything left and its not a comment line - * then execute it - */ - - if (*sp && *sp != '#') { - /*pcb_message("%s : line %-3d : \"%s\"\n", fname, n, sp); */ - pcb_parse_actions(PCB_ACT_HIDLIB, sp); - } - } - - defer_updates = 0; - if (defer_needs_update) { - pcb_undo_inc_serial(); - pcb_gui->invalidate_all(pcb_gui); - } - fclose(fp); - PCB_ACT_IRES(0); + PCB_ACT_IRES(pcb_act_execute_file(PCB_ACT_HIDLIB, fname)); return 0; }