From 49a6ebd7972ef5225dd68225d980aa334774a84d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 2 Aug 2016 16:38:21 -0300 Subject: [PATCH] eeshow/: make libraries "related" to the [main] schematics sheet That way, we can use relative paths on the command line, ideally just ./eeshow foo.lib bar.lib com/plex/path/foo.sch --- eeshow/Makefile | 2 +- eeshow/diff.c | 8 ++++++-- eeshow/lib-parse.c | 4 ++-- eeshow/lib.h | 4 +++- eeshow/main.c | 11 ++++++++--- eeshow/sch-parse.c | 8 ++------ eeshow/sch.h | 3 ++- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/eeshow/Makefile b/eeshow/Makefile index 35601c3..97d93a8 100644 --- a/eeshow/Makefile +++ b/eeshow/Makefile @@ -78,7 +78,7 @@ neo900.pdf: $(NAME) sch2pdf neo900-template.fig $(NEO900_HW)/neo900.sch pdf: $(NAME) - ./eeshow -r $(NEO900_HW)/neo900.lib $(KICAD_LIBS)/powered.lib \ + ./eeshow -r neo900.lib kicad-libs/components/powered.lib \ $(NEO900_HW)/neo900.sch -- pdf -o neo900.pdf #----- Regression test based on Neo900 schematics ----------------------------- diff --git a/eeshow/diff.c b/eeshow/diff.c index a825c82..f6e1a23 100644 --- a/eeshow/diff.c +++ b/eeshow/diff.c @@ -20,6 +20,7 @@ #include "util.h" #include "main.h" #include "cro.h" +#include "file.h" #include "sch.h" #include "lib.h" #include "diff.h" @@ -111,6 +112,7 @@ static void *diff_init(int argc, char *const *argv) char c; int arg; struct sch_ctx new_sch; + struct file sch_file; struct lib new_lib; diff = alloc_type(struct diff); @@ -136,9 +138,11 @@ static void *diff_init(int argc, char *const *argv) if (argc - optind < 1) usage(*argv); + file_open(&sch_file, argv[argc - 1], NULL); for (arg = optind; arg != argc - 1; arg++) - lib_parse(&new_lib, argv[arg]); - sch_parse(&new_sch, argv[argc - 1], &new_lib); + lib_parse(&new_lib, argv[arg], &sch_file); + sch_parse(&new_sch, &sch_file, &new_lib); + file_close(&sch_file); optind = 0; gfx_init(&cro_img_ops, argc, argv); diff --git a/eeshow/lib-parse.c b/eeshow/lib-parse.c index 39c2a1f..df20f9c 100644 --- a/eeshow/lib-parse.c +++ b/eeshow/lib-parse.c @@ -252,12 +252,12 @@ static bool lib_parse_line(const struct file *file, } -void lib_parse(struct lib *lib, const char *name) +void lib_parse(struct lib *lib, const char *name, const struct file *related) { struct file file; lib->state = lib_skip; - file_open(&file, name, NULL); + file_open(&file, name, related); file_read(&file, lib_parse_line, lib); file_close(&file); } diff --git a/eeshow/lib.h b/eeshow/lib.h index 367caba..04121e5 100644 --- a/eeshow/lib.h +++ b/eeshow/lib.h @@ -16,6 +16,8 @@ #include +#include "file.h" + enum lib_state { lib_skip, /* before a definition */ @@ -117,7 +119,7 @@ const struct comp *lib_find(const struct lib *lib, const char *name); bool lib_field_visible(const struct comp *comp, int n); void lib_render(const struct comp *comp, unsigned unit, const int m[6]); -void lib_parse(struct lib *lib, const char *name); +void lib_parse(struct lib *lib, const char *name, const struct file *related); void lib_init(struct lib *lib); #endif /* !LIB_H */ diff --git a/eeshow/main.c b/eeshow/main.c index 8b947de..af323ba 100644 --- a/eeshow/main.c +++ b/eeshow/main.c @@ -81,6 +81,7 @@ int main(int argc, char *const *argv) { struct lib lib; struct sch_ctx sch_ctx; + struct file sch_file; bool recurse = 0; const char *cat = NULL; char c; @@ -122,9 +123,12 @@ int main(int argc, char *const *argv) if (dashdash - optind < 1) usage(*argv); + sch_init(&sch_ctx, recurse); + file_open(&sch_file, argv[dashdash - 1], NULL); + lib_init(&lib); for (arg = optind; arg != dashdash - 1; arg++) - lib_parse(&lib, argv[arg]); + lib_parse(&lib, argv[arg], &sch_file); if (dashdash == argc) { gfx_argc = 1; @@ -151,8 +155,9 @@ found: optind = 0; /* reset getopt */ - sch_init(&sch_ctx, recurse); - sch_parse(&sch_ctx, argv[dashdash - 1], &lib); + sch_parse(&sch_ctx, &sch_file, &lib); + file_close(&sch_file); + gfx_init(*ops, gfx_argc, gfx_argv); if (recurse) { const struct sheet *sheet; diff --git a/eeshow/sch-parse.c b/eeshow/sch-parse.c index eaa339b..98c82ab 100644 --- a/eeshow/sch-parse.c +++ b/eeshow/sch-parse.c @@ -516,14 +516,10 @@ static bool parse_line(const struct file *file, void *user, const char *line) } -void sch_parse(struct sch_ctx *ctx, const char *name, const struct lib *lib) +void sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib) { - struct file file; - ctx->lib = lib; - file_open(&file, name, NULL); - file_read(&file, parse_line, ctx); - file_close(&file); + file_read(file, parse_line, ctx); } diff --git a/eeshow/sch.h b/eeshow/sch.h index ea23ef3..91cf2d1 100644 --- a/eeshow/sch.h +++ b/eeshow/sch.h @@ -18,6 +18,7 @@ #include "dwg.h" #include "text.h" +#include "file.h" #include "lib.h" @@ -109,7 +110,7 @@ struct sch_ctx { void decode_alignment(struct text *txt, char hor, char vert); void sch_render(const struct sheet *sheet); -void sch_parse(struct sch_ctx *ctx, const char *name, const struct lib *lib); +void sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib); void sch_init(struct sch_ctx *ctx, bool recurse); #endif /* !SCH_H */