summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-22 20:47:06 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-22 20:49:29 -0300
commit8dfb6b2c9f722d70b30e5794fe20ce9450dd05d4 (patch)
tree757749cdbd459d5460f893f6cf6116790845cb3b /gui
parentc9a05d88435e5cc47492b4b62f8312ad8011fd2c (diff)
downloadeeshow-8dfb6b2c9f722d70b30e5794fe20ce9450dd05d4.tar.gz
eeshow-8dfb6b2c9f722d70b30e5794fe20ce9450dd05d4.tar.bz2
eeshow-8dfb6b2c9f722d70b30e5794fe20ce9450dd05d4.zip
eeshow/: change file name handling from positional to be extension-driven
This also enables versioning for page layouts. We no longer need the option -P.
Diffstat (limited to 'gui')
-rw-r--r--gui/common.h6
-rw-r--r--gui/gui.c46
-rw-r--r--gui/gui.h9
-rw-r--r--gui/render.c4
4 files changed, 36 insertions, 29 deletions
diff --git a/gui/common.h b/gui/common.h
index c67ef76..32a9a19 100644
--- a/gui/common.h
+++ b/gui/common.h
@@ -52,9 +52,11 @@ struct gui_hist {
struct gui_sheet *sheets; /* NULL if failed */
unsigned age; /* 0-based; uncommitted or HEAD = 0 */
+ struct pl_ctx *pl; /* NULL if none or failed */
+
/* caching support */
void **oids; /* file object IDs */
- int libs_open;
+ unsigned libs_open;
struct sch_ctx sch_ctx;
struct lib lib; /* combined library */
bool identical; /* identical with previous entry */
@@ -68,8 +70,6 @@ struct gui_ctx {
float scale; /* pixels = eeschema * scale */
int x, y; /* center, in eeschema coordinates */
- struct pl_ctx *pl; // @@@
-
struct gui_hist *hist; /* revision history; NULL if none */
struct hist *vcs_hist; /* underlying VCS data; NULL if none */
diff --git a/gui/gui.c b/gui/gui.c
index 98b98b7..f41e90a 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -30,6 +30,7 @@
#include "misc/util.h"
#include "misc/diag.h"
#include "file/git-hist.h"
+#include "kicad/ext.h"
#include "kicad/pl.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
@@ -212,12 +213,13 @@ static struct gui_sheet *get_sheets(struct gui_ctx *ctx, struct gui_hist *hist,
*/
static const struct sheet *parse_files(struct gui_hist *hist,
- int n_args, char **args, bool recurse, struct gui_hist *prev)
+ const struct file_names *fn, bool recurse, struct gui_hist *prev)
{
char *rev = NULL;
struct file sch_file;
- struct file lib_files[n_args - 1];
- int libs_open, i;
+ struct file lib_files[fn->n_libs];
+ struct file pl_file;
+ unsigned libs_open, i;
bool libs_cached = 0;
bool ok;
@@ -225,7 +227,7 @@ static const struct sheet *parse_files(struct gui_hist *hist,
rev = vcs_git_get_rev(hist->vcs_hist);
sch_init(&hist->sch_ctx, recurse);
- ok = file_open_revision(&sch_file, rev, args[n_args - 1], NULL);
+ ok = file_open_revision(&sch_file, rev, fn->sch, NULL);
if (rev)
free(rev);
@@ -235,11 +237,22 @@ static const struct sheet *parse_files(struct gui_hist *hist,
}
lib_init(&hist->lib);
- for (libs_open = 0; libs_open != n_args - 1; libs_open++)
- if (!file_open(lib_files + libs_open, args[libs_open],
+ for (libs_open = 0; libs_open != fn->n_libs; libs_open++)
+ if (!file_open(lib_files + libs_open, fn->libs[libs_open],
&sch_file))
goto fail;
+ if (fn->pl) {
+ if (!file_open(&pl_file, fn->pl, &sch_file))
+ goto fail;
+ hist->pl = pl_parse(&pl_file);
+ file_close(&pl_file);
+ /*
+ * We treat failing to parse the page layout as a "minor"
+ * failure and don't reject the revision just because of it.
+ */
+ }
+
if (hist->vcs_hist) {
hist->oids = alloc_type_n(void *, libs_open);
hist->libs_open = libs_open;
@@ -293,8 +306,7 @@ fail:
struct add_hist_ctx {
struct gui_ctx *ctx;
- int n_args;
- char **args;
+ const struct file_names *fn;
bool recurse;
unsigned limit;
};
@@ -324,7 +336,8 @@ static void add_hist(void *user, struct hist *h)
hist->vcs_hist = h;
hist->libs_open = 0;
hist->identical = 0;
- sch = parse_files(hist, ahc->n_args, ahc->args, ahc->recurse, prev);
+ hist->pl = NULL;
+ sch = parse_files(hist, ahc->fn, ahc->recurse, prev);
hist->sheets = sch ? get_sheets(ctx, hist, sch) : NULL;
hist->age = age;
@@ -336,13 +349,12 @@ static void add_hist(void *user, struct hist *h)
}
-static void get_revisions(struct gui_ctx *ctx,
- int n_args, char **args, bool recurse, int limit)
+static void get_revisions(struct gui_ctx *ctx, const struct file_names *fn,
+ bool recurse, int limit)
{
struct add_hist_ctx add_hist_ctx = {
.ctx = ctx,
- .n_args = n_args,
- .args = args,
+ .fn = fn,
.recurse = recurse,
.limit = limit ? limit < 0 ? -limit : limit : -1,
};
@@ -383,14 +395,12 @@ static void get_history(struct gui_ctx *ctx, const char *sch_name, int limit)
/* ----- Initialization ---------------------------------------------------- */
-int gui(unsigned n_args, char **args, bool recurse, int limit,
- struct pl_ctx *pl)
+int gui(const struct file_names *fn, bool recurse, int limit)
{
GtkWidget *window;
char *title;
struct gui_ctx ctx = {
.scale = 1 / 16.0,
- .pl = pl, // @@@
.hist = NULL,
.vcs_hist = NULL,
.showing_history= 0,
@@ -422,11 +432,11 @@ int gui(unsigned n_args, char **args, bool recurse, int limit,
gtk_widget_show_all(window);
- get_history(&ctx, args[n_args - 1], limit);
+ get_history(&ctx, fn->sch, limit);
if (ctx.hist_size)
setup_progress_bar(&ctx, window);
- get_revisions(&ctx, n_args, args, recurse, limit);
+ get_revisions(&ctx, fn, recurse, limit);
for (ctx.new_hist = ctx.hist; ctx.new_hist && !ctx.new_hist->sheets;
ctx.new_hist = ctx.new_hist->next);
if (!ctx.new_hist)
diff --git a/gui/gui.h b/gui/gui.h
index f0307cb..bd80284 100644
--- a/gui/gui.h
+++ b/gui/gui.h
@@ -15,12 +15,9 @@
#include <stdbool.h>
-/*
- * Note: this isn't (argc, argv) ! args stars right with the first file name
- * and there is no NULL at the end.
- */
+#include "kicad/ext.h"
+
-int gui(unsigned n_args, char **args, bool recurse, int limit,
- struct pl_ctx *pl);
+int gui(const struct file_names *fn, bool recurse, int limit);
#endif /* !GUI_GUI_H */
diff --git a/gui/render.c b/gui/render.c
index 465128d..ec4db2e 100644
--- a/gui/render.c
+++ b/gui/render.c
@@ -231,8 +231,8 @@ void render_sheet(struct gui_sheet *sheet)
char *argv[] = { "gui", NULL };
gfx_init(&cro_canvas_ops, 1, argv);
- if (sheet->ctx && sheet->ctx->pl) /* @@@ no pl_render for delta */
- pl_render(sheet->ctx->pl, sheet->hist->sch_ctx.sheets,
+ if (sheet->hist && sheet->hist->pl) /* @@@ no pl_render for delta */
+ pl_render(sheet->hist->pl, sheet->hist->sch_ctx.sheets,
sheet->sch);
sch_render(sheet->sch);
cro_canvas_end(gfx_ctx,