Date:2016-08-23 01:47:06 (7 years 3 months ago)
Author:Werner Almesberger
Commit:1b250bd46737db7133fe9314be6baa3edab3d5c7
Message: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.
Files: eeshow/Makefile (1 diff)
eeshow/gui/common.h (2 diffs)
eeshow/gui/gui.c (9 diffs)
eeshow/gui/gui.h (1 diff)
eeshow/gui/render.c (1 diff)
eeshow/main.c (8 diffs)
eeshow/main.h (1 diff)

Change Details

eeshow/Makefile
131131            $(NEO900_HW)/neo900.sch
132132
133133pdf: $(NAME)
134        ./eeshow -r -P $(NEO900_HW)/neo900pageframe_A3.kicad_wks \
134        ./eeshow -r $(NEO900_HW)/neo900pageframe_A3.kicad_wks \
135135            neo900.lib kicad-libs/components/powered.lib \
136136            $(NEO900_HW)/neo900.sch -- pdf -o neo900.pdf
137137
eeshow/gui/common.h
5252    struct gui_sheet *sheets; /* NULL if failed */
5353    unsigned age; /* 0-based; uncommitted or HEAD = 0 */
5454
55    struct pl_ctx *pl; /* NULL if none or failed */
56
5557    /* caching support */
5658    void **oids; /* file object IDs */
57    int libs_open;
59    unsigned libs_open;
5860    struct sch_ctx sch_ctx;
5961    struct lib lib; /* combined library */
6062    bool identical; /* identical with previous entry */
...... 
6870    float scale; /* pixels = eeschema * scale */
6971    int x, y; /* center, in eeschema coordinates */
7072
71    struct pl_ctx *pl; // @@@
72
7373    struct gui_hist *hist; /* revision history; NULL if none */
7474    struct hist *vcs_hist; /* underlying VCS data; NULL if none */
7575
eeshow/gui/gui.c
3030#include "misc/util.h"
3131#include "misc/diag.h"
3232#include "file/git-hist.h"
33#include "kicad/ext.h"
3334#include "kicad/pl.h"
3435#include "kicad/lib.h"
3536#include "kicad/sch.h"
...... 
212213 */
213214
214215static const struct sheet *parse_files(struct gui_hist *hist,
215    int n_args, char **args, bool recurse, struct gui_hist *prev)
216    const struct file_names *fn, bool recurse, struct gui_hist *prev)
216217{
217218    char *rev = NULL;
218219    struct file sch_file;
219    struct file lib_files[n_args - 1];
220    int libs_open, i;
220    struct file lib_files[fn->n_libs];
221    struct file pl_file;
222    unsigned libs_open, i;
221223    bool libs_cached = 0;
222224    bool ok;
223225
...... 
225227        rev = vcs_git_get_rev(hist->vcs_hist);
226228
227229    sch_init(&hist->sch_ctx, recurse);
228    ok = file_open_revision(&sch_file, rev, args[n_args - 1], NULL);
230    ok = file_open_revision(&sch_file, rev, fn->sch, NULL);
229231
230232    if (rev)
231233        free(rev);
...... 
235237    }
236238
237239    lib_init(&hist->lib);
238    for (libs_open = 0; libs_open != n_args - 1; libs_open++)
239        if (!file_open(lib_files + libs_open, args[libs_open],
240    for (libs_open = 0; libs_open != fn->n_libs; libs_open++)
241        if (!file_open(lib_files + libs_open, fn->libs[libs_open],
240242            &sch_file))
241243            goto fail;
242244
245    if (fn->pl) {
246        if (!file_open(&pl_file, fn->pl, &sch_file))
247            goto fail;
248         hist->pl = pl_parse(&pl_file);
249        file_close(&pl_file);
250        /*
251         * We treat failing to parse the page layout as a "minor"
252         * failure and don't reject the revision just because of it.
253         */
254    }
255
243256    if (hist->vcs_hist) {
244257        hist->oids = alloc_type_n(void *, libs_open);
245258        hist->libs_open = libs_open;
...... 
293306
294307struct add_hist_ctx {
295308    struct gui_ctx *ctx;
296    int n_args;
297    char **args;
309    const struct file_names *fn;
298310    bool recurse;
299311    unsigned limit;
300312};
...... 
324336    hist->vcs_hist = h;
325337    hist->libs_open = 0;
326338    hist->identical = 0;
327    sch = parse_files(hist, ahc->n_args, ahc->args, ahc->recurse, prev);
339    hist->pl = NULL;
340    sch = parse_files(hist, ahc->fn, ahc->recurse, prev);
328341    hist->sheets = sch ? get_sheets(ctx, hist, sch) : NULL;
329342    hist->age = age;
330343
...... 
336349}
337350
338351
339static void get_revisions(struct gui_ctx *ctx,
340    int n_args, char **args, bool recurse, int limit)
352static void get_revisions(struct gui_ctx *ctx, const struct file_names *fn,
353    bool recurse, int limit)
341354{
342355    struct add_hist_ctx add_hist_ctx = {
343356        .ctx = ctx,
344        .n_args = n_args,
345        .args = args,
357        .fn = fn,
346358        .recurse = recurse,
347359        .limit = limit ? limit < 0 ? -limit : limit : -1,
348360    };
...... 
383395/* ----- Initialization ---------------------------------------------------- */
384396
385397
386int gui(unsigned n_args, char **args, bool recurse, int limit,
387    struct pl_ctx *pl)
398int gui(const struct file_names *fn, bool recurse, int limit)
388399{
389400    GtkWidget *window;
390401    char *title;
391402    struct gui_ctx ctx = {
392403        .scale = 1 / 16.0,
393        .pl = pl, // @@@
394404        .hist = NULL,
395405        .vcs_hist = NULL,
396406        .showing_history= 0,
...... 
422432
423433    gtk_widget_show_all(window);
424434
425    get_history(&ctx, args[n_args - 1], limit);
435    get_history(&ctx, fn->sch, limit);
426436    if (ctx.hist_size)
427437        setup_progress_bar(&ctx, window);
428438
429    get_revisions(&ctx, n_args, args, recurse, limit);
439    get_revisions(&ctx, fn, recurse, limit);
430440    for (ctx.new_hist = ctx.hist; ctx.new_hist && !ctx.new_hist->sheets;
431441        ctx.new_hist = ctx.new_hist->next);
432442    if (!ctx.new_hist)
eeshow/gui/gui.h
1515
1616#include <stdbool.h>
1717
18/*
19 * Note: this isn't (argc, argv) ! args stars right with the first file name
20 * and there is no NULL at the end.
21 */
18#include "kicad/ext.h"
19
2220
23int gui(unsigned n_args, char **args, bool recurse, int limit,
24    struct pl_ctx *pl);
21int gui(const struct file_names *fn, bool recurse, int limit);
2522
2623#endif /* !GUI_GUI_H */
eeshow/gui/render.c
231231    char *argv[] = { "gui", NULL };
232232
233233    gfx_init(&cro_canvas_ops, 1, argv);
234    if (sheet->ctx && sheet->ctx->pl) /* @@@ no pl_render for delta */
235        pl_render(sheet->ctx->pl, sheet->hist->sch_ctx.sheets,
234    if (sheet->hist && sheet->hist->pl) /* @@@ no pl_render for delta */
235        pl_render(sheet->hist->pl, sheet->hist->sch_ctx.sheets,
236236            sheet->sch);
237237    sch_render(sheet->sch);
238238    cro_canvas_end(gfx_ctx,
eeshow/main.c
11/*
2 * main.c - Convert Eeschema schematics to FIG
2 * main.c - Visualize and convert Eeschema schematics
33 *
44 * Written 2016 by Werner Almesberger
55 * Copyright 2016 by Werner Almesberger
...... 
2626#include "gfx/diff.h"
2727#include "gfx/gfx.h"
2828#include "file/file.h"
29#include "kicad/ext.h"
2930#include "kicad/sexpr.h"
3031#include "kicad/pl.h"
3132#include "kicad/lib.h"
...... 
6061        exit(1);
6162}
6263
63
64
6465void usage(const char *name)
6566{
6667    fprintf(stderr,
67"usage: %s [gtk_flags] [-r] [-N n] [[rev:]file.lib ...] [rev:]file.sch\n"
68" %s [-r] [-v ...] [[rev:]file.lib ...] [rev:]file.sch\n"
68"usage: %s [gtk_flags] [-r] [-N n] kicad_file ...\n"
69" %s [-r] [-v ...] kicad_file ...\n"
6970" %*s[-- driver_spec]\n"
7071" %s [-v ...] -C [rev:]file\n"
7172" %s [-v ...] -H path_into_repo\n"
...... 
7374" %s -V\n"
7475" %s gdb ...\n"
7576"\n"
76" rev git revision\n"
77" kicad_file [rev:]file.ext\n"
78" ext .lib, .sch, or .kicad_wks\n"
79" rev git revision\n"
80"\n"
7781" -r recurse into sub-sheets\n"
7882" -v increase verbosity of diagnostic output\n"
7983" -C 'cat' the file to standard output\n"
...... 
121125    const char *cat = NULL;
122126    const char *history = NULL;
123127    const char *fmt = NULL;
124    const char *page_layout = NULL;
125128    struct pl_ctx *pl = NULL;
126129    int limit = 0;
127130    char c;
128    int arg, dashdash;
131    int dashdash;
132    unsigned i;
129133    bool have_dashdash = 0;
134    struct file_names file_names;
130135    int gfx_argc;
131136    char **gfx_argv;
132137    const struct gfx_ops **ops = ops_list;
...... 
153158    if (!have_dashdash)
154159        gtk_init(&argc, &argv);
155160
156    while ((c = getopt(dashdash, argv, "P:rvC:F:H:N:SV")) != EOF)
161    while ((c = getopt(dashdash, argv, "rvC:F:H:N:SV")) != EOF)
157162        switch (c) {
158163        case 'r':
159164            recurse = 1;
...... 
173178        case 'N':
174179            limit = atoi(optarg);
175180            break;
176        case 'P':
177            page_layout = optarg;
178            break;
179181        case 'S':
180182            sexpr();
181183            return 0;
...... 
215217        return 0;
216218    }
217219
218    if (page_layout) {
219        struct file file;
220
221        if (!file_open(&file, page_layout, NULL))
222            return 1;
223        pl = pl_parse(&file);
224        file_close(&file);
225        if (!pl)
226            return 1;
227    }
228
229220    if (dashdash - optind < 1)
230221        usage(*argv);
231222
232    if (!have_dashdash) {
233        unsigned n = argc - optind;
234        char **args;
223    classify_files(&file_names, argv + optind, dashdash - optind);
224    if (!file_names.sch)
225        fatal("top sheet name required");
235226
236        args = alloc_type_n(char *, n);
237        memcpy(args, argv + optind, sizeof(const char *) * n);
238
227    if (!have_dashdash) {
239228        optind = 0; /* reset getopt */
240        return gui(n, args, recurse, limit, pl);
229        return gui(&file_names, recurse, limit);
241230    }
242231
243232    sch_init(&sch_ctx, recurse);
244    if (!file_open(&sch_file, argv[dashdash - 1], NULL))
233    if (!file_open(&sch_file, file_names.sch, NULL))
245234        return 1;
246235
247236    lib_init(&lib);
248    for (arg = optind; arg != dashdash - 1; arg++)
249        if (!lib_parse(&lib, argv[arg], &sch_file))
237    for (i = 0; i != file_names.n_libs; i++)
238        if (!lib_parse(&lib, file_names.libs[i], &sch_file))
239            return 1;
240
241    if (file_names.pl) {
242        struct file file;
243
244        if (!file_open(&file, file_names.pl, &sch_file))
245            return 1;
246        pl = pl_parse(&file);
247        file_close(&file);
248        if (!pl)
250249            return 1;
250    }
251251
252252    if (dashdash == argc) {
253253        gfx_argc = 1;
eeshow/main.h
11/*
2 * main.h - Convert Eeschema schematics to FIG
2 * main.h - Visualize and convert Eeschema schematics
33 *
44 * Written 2016 by Werner Almesberger
55 * Copyright 2016 by Werner Almesberger

Archive Download the corresponding diff file

Branches:
master



interactive