Index: trunk/src/sch-rnd/Makefile.dep =================================================================== --- trunk/src/sch-rnd/Makefile.dep (revision 1334) +++ trunk/src/sch-rnd/Makefile.dep (revision 1335) @@ -194,6 +194,11 @@ ../libcschem/cnc_arc.h ../plugins/std_tools/tool_rect.c \ ../plugins/std_tools/tool_wirenet.c ../plugins/std_tools/tool_line.c \ ../plugins/std_tools/tool_arrow.c ../plugins/std_tools/tool_remove.c +build_run.o: build_run.c ../libcschem/config.h \ + /usr/local/include/librnd/src_3rd/genvector/gds_char.h \ + /usr/local/include/librnd/src_3rd/genvector/genvector_impl.h \ + /usr/local/include/librnd/src_3rd/genvector/genvector_undef.h \ + conf_core.h build_run.h conf_core.o: conf_core.c conf_core.h conf_core_fields.h crosshair.o: crosshair.c conf_core.h crosshair.h ../libcschem/config.h draw.o: draw.c ../libcschem/concrete.h ../libcschem/common_types.h \ @@ -210,6 +215,8 @@ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/TODO.h ../libcschem/cnc_line.h ../libcschem/cnc_arc.h \ ../libcschem/cnc_pen.h conf_core.h draw.h +main_act.o: main_act.c ../libcschem/config.h crosshair.h conf_core.h \ + build_run.h operation.o: operation.c ../libcschem/config.h ../libcschem/operation.h \ ../libcschem/concrete.h ../libcschem/common_types.h ../libcschem/rtree.h \ /usr/local/include/librnd/src_3rd/genrtree/genrtree_api.h \ Index: trunk/src/sch-rnd/Makefile.in =================================================================== --- trunk/src/sch-rnd/Makefile.in (revision 1334) +++ trunk/src/sch-rnd/Makefile.in (revision 1335) @@ -14,6 +14,7 @@ select.o operation.o build_run.o + main_act.o @] Index: trunk/src/sch-rnd/build_run.c =================================================================== --- trunk/src/sch-rnd/build_run.c (revision 1334) +++ trunk/src/sch-rnd/build_run.c (revision 1335) @@ -39,17 +39,17 @@ extern void sch_rnd_main_uninit(void); -void sch_quit_app(void) +void csch_quit_app(void) { /* save data if necessary. It not needed, then don't trigger EmergencySave - * via our atexit() registering of sch_emergency_save(). We presumably wanted to + * via our atexit() registering of csch_emergency_save(). We presumably wanted to * exit here and thus it is not an emergency. */ TODO("implemnent this:"); #if 0 if (PCB->Changed && conf_core.editor.save_in_tmp) - sch_emergency_save(); + csch_emergency_save(); else - sch_disable_emergency_save(); + csch_disable_emergency_save(); #endif if (rnd_gui->do_exit == NULL) { @@ -61,10 +61,10 @@ } TODO("implement these in scconfig") -#define SCH_VERSION "" -#define SCH_REVISION "" +#define CSCH_VERSION "" +#define CSCH_REVISION "" -char *sch_get_info_program(void) +char *csch_get_info_program(void) { static gds_t info; static int first_time = 1; @@ -72,13 +72,13 @@ if (first_time) { first_time = 0; gds_init(&info); - gds_append_str(&info, "This is sch-rnd " SCH_VERSION " (" SCH_REVISION ")" "\nan interactive "); + gds_append_str(&info, "This is sch-rnd " CSCH_VERSION " (" CSCH_REVISION ")" "\nan interactive "); gds_append_str(&info, "schematics editor\nfrom the Ringdove EDA suite\ncompiled using librnd version " RND_VER_STR "\n"); } return info.array; } -char *sch_get_info_copyright(void) +char *csch_get_info_copyright(void) { static gds_t info; static int first_time = 1; @@ -94,7 +94,7 @@ return info.array; } -char *sch_get_info_websites(const char **url_out) +char *csch_get_info_websites(const char **url_out) { static gds_t info; static int first_time = 1; @@ -114,7 +114,7 @@ return info.array; } -char *sch_get_info_comments(void) +char *csch_get_info_comments(void) { static gds_t info; static int first_time = 1; @@ -124,9 +124,9 @@ first_time = 0; gds_init(&info); - tmp = sch_get_info_program(); + tmp = csch_get_info_program(); gds_append_str(&info, tmp); - tmp = sch_get_info_websites(NULL); + tmp = csch_get_info_websites(NULL); gds_append_str(&info, tmp); } return info.array; @@ -133,7 +133,7 @@ } -char *sch_get_info_compile_options(void) +char *csch_get_info_compile_options(void) { rnd_hid_t **hids; int i; @@ -194,7 +194,7 @@ return info.array; } -char *sch_get_info_license(void) +char *csch_get_info_license(void) { static gds_t info; static int first_time = 1; @@ -211,7 +211,7 @@ } /* Catches signals which abort the program. */ -void sch_catch_signal(int Signal) +void csch_catch_signal(int Signal) { const char *s; Index: trunk/src/sch-rnd/build_run.h =================================================================== --- trunk/src/sch-rnd/build_run.h (revision 1334) +++ trunk/src/sch-rnd/build_run.h (revision 1335) @@ -29,30 +29,30 @@ #ifndef PCB_BUILD_RUN_H #define PCB_BUILD_RUN_H -void sch_quit_app(void); +void csch_quit_app(void); /* Returns a string that has a bunch of information about this program. */ -char *sch_get_info_program(void); +char *csch_get_info_program(void); /* Returns a string that has a bunch of information about the copyrights. */ -char *sch_get_info_copyright(void); +char *csch_get_info_copyright(void); /* Returns a string about how the program is licensed. */ -char *sch_get_info_license(void); +char *csch_get_info_license(void); /* Returns a string that has a bunch of information about the websites. */ -char *sch_get_info_websites(const char **url_out); +char *csch_get_info_websites(const char **url_out); -/* Returns a string as the concatenation of sch_get_info_program() and sch_get_info_websites() */ -char *sch_get_info_comments(void); +/* Returns a string as the concatenation of csch_get_info_program() and csch_get_info_websites() */ +char *csch_get_info_comments(void); /* Returns a string that has a bunch of information about the options selected at compile time. */ -char *sch_get_info_compile_options(void); +char *csch_get_info_compile_options(void); /* Author's name: either from the config system (typically from the design) or as a last resort from the OS */ -const char *sch_author(void); +const char *csch_author(void); -void sch_catch_signal(int Signal); +void csch_catch_signal(int Signal); #endif Index: trunk/src/sch-rnd/main_act.c =================================================================== --- trunk/src/sch-rnd/main_act.c (nonexistent) +++ trunk/src/sch-rnd/main_act.c (revision 1335) @@ -0,0 +1,302 @@ +/* + * COPYRIGHT + * + * sch-rnd, interactive printed circuit board design + * (this file is copied from pcb-rnd, interactive printed circuit board design) + * Copyright (C) 1994,1995,1996 Thomas Nau + * Copyright (C) 1997, 1998, 1999, 2000, 2001 Harry Eaton + * Copyright (C) 2020,2022 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contact: + * Project page: http://repo.hu/projects/sch-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + * + * + * Old contact info: + * Harry Eaton, 6697 Buttonhole Ct, Columbia, MD 21044, USA + * haceaton@aplcomm.jhuapl.edu + * + */ + +#define Progname "sch-rnd" + +#include + +#include + +#include "crosshair.h" +#include +#include +#include "conf_core.h" +#include "build_run.h" +#include +#include + +/* print usage lines */ +static inline void u(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputc('\n', stderr); + va_end(ap); +} + +static const char csch_acts_PrintUsage[] = + "PrintUsage()\n" + "PrintUsage(plugin)"; + +static const char csch_acth_PrintUsage[] = "Print command line arguments of sch-rnd or a plugin loaded."; + +static int help0(void) +{ + rnd_hid_t **hl = rnd_hid_enumerate(); + int i; + + u("sch-rnd - Ringdove schematics program, http://repo.hu/projects/sch-rnd"); + u("For more information, please read the topic help pages:"); + u(" %s --help topic", Progname); + u("Topics are:"); + u(" invocation how to run sch-rnd"); + u(" main main/misc flags (affecting none or all plugins)"); + for (i = 0; hl[i]; i++) + if (hl[i]->usage != NULL) + u(" %-20s %s", hl[i]->name, hl[i]->description); + return 0; +} + +extern const char *sch_rnd_action_args[]; +extern const int PCB_ACTION_ARGS_WIDTH; +static int help_main(void) { + const char **cs; + for(cs = sch_rnd_action_args; cs[2] != NULL; cs += RND_ACTION_ARGS_WIDTH) { + fprintf(stderr, "%s [", Progname); + if (cs[0] != NULL) + fprintf(stderr, "-%s", cs[0]); + if ((cs[0] != NULL) && (cs[1] != NULL)) + fprintf(stderr, "|"); + if (cs[1] != NULL) + fprintf(stderr, "-%s", cs[1]); + fprintf(stderr, "] %s\n", cs[3]); + } + return 0; +} + +static int help_invoc(void) +{ + rnd_hid_t **hl = rnd_hid_enumerate(); + int i; + int n_printer = 0, n_gui = 0, n_exporter = 0; + + u("sch-rnd invocation:"); + u(""); + u("%s [main options] See --help main", Progname); + u(""); + u("%s [generics] [--gui GUI] [gui options] interactive GUI", Progname); + + u("Available GUI hid%s:", n_gui == 1 ? "" : "s"); + for (i = 0; hl[i]; i++) + if (hl[i]->gui) + fprintf(stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description); + + u("\n%s [generics] -p [printing options] \tto print", Progname); + u("Available printing hid%s:", n_printer == 1 ? "" : "s"); + for (i = 0; hl[i]; i++) + if (hl[i]->printer) + fprintf(stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description); + + u("\n%s [generics] -x hid [export options] \tto export", Progname); + u("Available export hid%s:", n_exporter == 1 ? "" : "s"); + for (i = 0; hl[i]; i++) + if (hl[i]->exporter) + fprintf(stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description); + + + u("\nGenerics:"); + u("-c conf/path=value set the value of a configuration item (in RND_CFR_CLI)"); + u("-C conffile load config file (as RND_CFR_CLI; after all -c's)"); + + return 0; +} + +fgw_error_t csch_act_PrintUsage(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *topic = NULL, *subt = NULL; + RND_ACT_MAY_CONVARG(1, FGW_STR, PrintUsage, topic = argv[1].val.str); + RND_ACT_IRES(0); + + u(""); + if (topic != NULL) { + rnd_hid_t **hl = rnd_hid_enumerate(); + int i; + + if (strcmp(topic, "invocation") == 0) return help_invoc(); + if (strcmp(topic, "main") == 0) return help_main(); + + for (i = 0; hl[i]; i++) { + if ((hl[i]->usage != NULL) && (strcmp(topic, hl[i]->name) == 0)) { + RND_ACT_MAY_CONVARG(2, FGW_STR, PrintUsage, subt = argv[2].val.str); + RND_ACT_IRES(hl[i]->usage(hl[i], subt)); + return 0; + } + } + fprintf(stderr, "No help available for %s\n", topic); + RND_ACT_IRES(-1); + return 0; + } + else + help0(); + return 0; +} + + +static const char csch_acts_PrintVersion[] = "PrintVersion()"; +static const char csch_acth_PrintVersion[] = "Print version."; +fgw_error_t csch_act_PrintVersion(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + printf("%s\n", csch_get_info_program()); + RND_ACT_IRES(0); + return 0; +} + +TODO("implement these in scconfig") +#define CSCH_VERSION "" +#define CSCH_REVISION "" + +static const char csch_acts_DumpVersion[] = "DumpVersion()"; +static const char csch_acth_DumpVersion[] = "Dump version in script readable format."; +fgw_error_t csch_act_DumpVersion(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + printf("%s\n", CSCH_VERSION); + printf("%s\n", CSCH_REVISION); + RND_ACT_IRES(0); + return 0; +} + +static const char csch_acts_PrintCopyright[] = "PrintCopyright()"; +static const char csch_acth_PrintCopyright[] = "Print copyright notice."; +fgw_error_t csch_act_PrintCopyright(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + printf("%s\n", csch_get_info_copyright()); + printf("%s\n", csch_get_info_license()); + + printf(" This program is free software; you can redistribute it and/or modify\n" + " it under the terms of the GNU General Public License as published by\n" + " the Free Software Foundation; either version 2 of the License, or\n" + " (at your option) any later version.\n\n"); + printf(" This program is distributed in the hope that it will be useful,\n" + " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + " GNU General Public License for more details.\n\n"); + printf(" You should have received a copy of the GNU General Public License\n" + " along with this program; if not, write to the Free Software\n" + " Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n"); + RND_ACT_IRES(0); + return 0; +} + +static const char csch_acts_PrintPaths[] = "PrintPaths()"; +static const char csch_acth_PrintPaths[] = "Print full paths and search paths."; +static void print_list(const rnd_conflist_t *cl) +{ + int n; + rnd_conf_listitem_t *ci; + const char *p; + + printf(" "); + rnd_conf_loop_list_str(cl, ci, p, n) { + printf("%c%s", (n == 0) ? '"' : ':', p); + } + printf("\"\n"); +} +fgw_error_t csch_act_PrintPaths(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + htsp_entry_t *e; + rnd_conf_fields_foreach(e) { + rnd_conf_native_t *n = e->value; + if ((strncmp(n->hash_path, "rc/path/", 8) == 0) && (n->type == RND_CFN_STRING) && (n->used == 1)) + printf("%-32s = %s\n", n->hash_path, n->val.string[0]); + } +TODO("print paths"); +#if 0 + printf("rc/default_font_file ="); print_list(&conf_core.rc.default_font_file); + printf("rc/library_search_paths ="); print_list(&conf_core.rc.library_search_paths); + printf("rc/library_shell = \"%s\"\n", conf_core.rc.library_shell); +#endif + RND_ACT_IRES(0); + return 0; +} + +/* Note: this can not be in librnd because of the app-specific setenvs */ +static const char csch_acts_System[] = "System(shell_cmd)"; +static const char csch_acth_System[] = "Run shell command"; +fgw_error_t csch_act_System(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + char tmp[128]; + const char *cmd; + + RND_ACT_CONVARG(1, FGW_STR, System, cmd = argv[1].val.str); + RND_ACT_IRES(0); + + rnd_setenv("PCB_RND_BOARD_FILE_NAME", RND_ACT_HIDLIB->filename == NULL ? "" : RND_ACT_HIDLIB->filename, 1); + rnd_snprintf(tmp, sizeof(tmp), "%mm", csch_crosshair_x); + rnd_setenv("PCB_RND_CROSSHAIR_X_MM", tmp, 1); + rnd_snprintf(tmp, sizeof(tmp), "%mm", csch_crosshair_y); + rnd_setenv("PCB_RND_CROSSHAIR_Y_MM", tmp, 1); + RND_ACT_IRES(rnd_system(RND_ACT_HIDLIB, cmd)); + return 0; +} + +static int csch_act_execute_file(rnd_hidlib_t *hidlib, const char *fn) +{ + int res; + + res = rnd_act_execute_file(hidlib, fn); + + csch_undo_inc_serial(); + rnd_gui->invalidate_all(rnd_gui); + + return res; +} + +static const char csch_acts_ExecActionFile[] = "ExecActionFile(filename)"; +static const char csch_acth_ExecActionFile[] = "Run actions from the given file."; +fgw_error_t csch_act_ExecActionFile(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *fname; + + RND_ACT_CONVARG(1, FGW_STR, ExecActionFile, fname = argv[1].val.str); + RND_ACT_IRES(csch_act_execute_file(RND_ACT_HIDLIB, fname)); + return 0; +} + +static rnd_action_t main_action_list[] = { + {"PrintUsage", csch_act_PrintUsage, csch_acth_PrintUsage, csch_acts_PrintUsage}, + {"PrintVersion", csch_act_PrintVersion, csch_acth_PrintVersion, csch_acts_PrintVersion}, + {"DumpVersion", csch_act_DumpVersion, csch_acth_DumpVersion, csch_acts_DumpVersion}, + {"PrintCopyright", csch_act_PrintCopyright, csch_acth_PrintCopyright, csch_acts_PrintCopyright}, + {"PrintPaths", csch_act_PrintPaths, csch_acth_PrintPaths, csch_acts_PrintPaths}, + {"System", csch_act_System, csch_acth_System, csch_acts_System}, + {"ExecCommand", csch_act_System, csch_acth_System, csch_acts_System}, + {"ExecActionFile", csch_act_ExecActionFile, csch_acth_ExecActionFile, csch_acts_ExecActionFile} +}; + +void csch_main_act_init2(void) +{ + RND_REGISTER_ACTIONS(main_action_list, NULL); +} Index: trunk/src/sch-rnd/sch-rnd.c =================================================================== --- trunk/src/sch-rnd/sch-rnd.c (revision 1334) +++ trunk/src/sch-rnd/sch-rnd.c (revision 1335) @@ -100,7 +100,7 @@ } /* action table number of columns for a single action */ -static const char *sch_rnd_action_args[] = { +const char *sch_rnd_action_args[] = { /*short, -long, action, help, hint-on-error */ NULL, "-show-actions", "PrintActions()", "Print all available actions (human readable) and exit", NULL, NULL, "-dump-actions", "DumpActions()", "Print all available actions (script readable) and exit", NULL, @@ -153,9 +153,14 @@ } +extern void csch_main_act_init2(void); +/*extern void rnd_main_act_init2(void);*/ + static void sch_rnd_main_init(void) { csch_init_actions(); + csch_main_act_init2(); +/* rnd_main_act_init2();*/ } void sch_rnd_main_uninit(void) @@ -204,24 +209,8 @@ rnd_main_args_init(&ga, argc, sch_rnd_action_args); rnd_hidlib_init1(conf_core_init); csch_event_init_app(); - for(n = 1; n < argc; n++) { - char *cmd = argv[n], *arg = argv[n+1]; - if (*cmd == '-') { - while(*cmd == '-') cmd++; - switch(*cmd) { - case 'd': - switch(cmd[1]) { - case 'a': dump_abs = 1; continue; - default: - fprintf(stderr, "Unknown argument '%s'\n", argv[n]); - exit(1); - } - break; - case 'f': fmt = arg; n++; continue; - } - } + for(n = 1; n < argc; n++) n += rnd_main_args_add(&ga, argv[n], argv[n+1]); - } rnd_hidlib_init2(pup_buildins, sch_rnd_buildins);