From 5f0678097f5bb9f7fd29833e74ade9c479deff38 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 5 Aug 2016 10:24:39 -0300 Subject: [PATCH] eeshow/gui.c: get only list of file names from main, parse on its own --- eeshow/gui.c | 26 +++++++++++++++++++++++--- eeshow/gui.h | 8 ++++++-- eeshow/main.c | 14 +++++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/eeshow/gui.c b/eeshow/gui.c index c70ff0b..bcdff7f 100644 --- a/eeshow/gui.c +++ b/eeshow/gui.c @@ -599,7 +599,27 @@ static void get_git(struct gui_ctx *ctx, const char *sch_name) } -int gui(const struct sheet *sheets, const char *sch_name) +static struct sheet *parse_sheets(int n_args, char **args, bool recurse) +{ + struct lib lib; + struct sch_ctx sch_ctx; + struct file sch_file; + int i; + + sch_init(&sch_ctx, recurse); + file_open(&sch_file, args[n_args - 1], NULL); + + lib_init(&lib); + for (i = 0; i != n_args - 1; i++) + lib_parse(&lib, args[i], &sch_file); + sch_parse(&sch_ctx, &sch_file, &lib); + file_close(&sch_file); + + return sch_ctx.sheets; +} + + +int gui(unsigned n_args, char **args, bool recurse) { GtkWidget *window; struct gui_ctx ctx = { @@ -612,8 +632,8 @@ int gui(const struct sheet *sheets, const char *sch_name) .aois = NULL, }; - get_sheets(&ctx, sheets); - get_git(&ctx, sch_name); + get_sheets(&ctx, parse_sheets(n_args, args, recurse)); + get_git(&ctx, args[n_args - 1]); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); diff --git a/eeshow/gui.h b/eeshow/gui.h index 4c7c181..c5528d6 100644 --- a/eeshow/gui.h +++ b/eeshow/gui.h @@ -13,9 +13,13 @@ #ifndef GUI_H #define GUI_H -#include "sch.h" +#include +/* + * Note: this isn't (argc, argv) ! args stars right with the first file name + * and there is no NULL at the end. + */ -int gui(const struct sheet *sheets, const char *sch_name); +int gui(unsigned n_args, char **args, bool recurse); #endif /* !GUI_H */ diff --git a/eeshow/main.c b/eeshow/main.c index a8e4744..4187ae8 100644 --- a/eeshow/main.c +++ b/eeshow/main.c @@ -146,6 +146,17 @@ int main(int argc, char **argv) if (dashdash - optind < 1) usage(*argv); + if (!have_dashdash) { + unsigned n = argc - optind; + char **args; + + args = alloc_size(sizeof(char *) * n); + memcpy(args, argv + optind, sizeof(const char *) * n); + + optind = 0; /* reset getopt */ + return gui(n, args, recurse); + } + sch_init(&sch_ctx, recurse); file_open(&sch_file, argv[dashdash - 1], NULL); @@ -181,9 +192,6 @@ found: sch_parse(&sch_ctx, &sch_file, &lib); file_close(&sch_file); - if (!have_dashdash) - return gui(sch_ctx.sheets, argv[dashdash - 1]); - gfx_init(*ops, gfx_argc, gfx_argv); if (recurse) { const struct sheet *sheet;