summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-02 20:05:44 -0300
committerWerner Almesberger <werner@almesberger.net>2016-09-02 20:05:44 -0300
commit85a2516303231f65fe9699f2e5165d3d3e1f9b9b (patch)
tree5d50fe58fe956db3c7dab441c2b1bbfb7fa4f7b3
parentc4f8f5e0225cca8e188ba81a56573124b6273dde (diff)
downloadeeshow-85a2516303231f65fe9699f2e5165d3d3e1f9b9b.tar.gz
eeshow-85a2516303231f65fe9699f2e5165d3d3e1f9b9b.tar.bz2
eeshow-85a2516303231f65fe9699f2e5165d3d3e1f9b9b.zip
main/eeplot.c: split off from main.c
-rw-r--r--Makefile42
-rw-r--r--main.c194
-rw-r--r--main/common.c2
-rw-r--r--main/eeplot.c256
4 files changed, 298 insertions, 196 deletions
diff --git a/Makefile b/Makefile
index 7546417..f94c77e 100644
--- a/Makefile
+++ b/Makefile
@@ -13,23 +13,37 @@
SHELL = /bin/bash
NAME = eeshow
+
+OBJS_KICAD = \
+ kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
+ kicad/lib-render.o kicad/dwg.o kicad/delta.o kicad/sexpr.o \
+ kicad/pl-parse.o kicad/pl-render.o kicad/ext.o kicad/pro.o
+OBJS_FILE = \
+ file/file.o file/git-util.o file/git-file.o file/git-hist.o
+OBJS_MISC = \
+ misc/diag.o misc/util.o
+
OBJS = main.o version.o \
main/common.o \
- kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
- kicad/lib-render.o kicad/dwg.o kicad/delta.o kicad/sexpr.o \
- kicad/pl-parse.o kicad/pl-render.o kicad/ext.o kicad/pro.o \
+ $(OBJS_KICAD) \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \
gui/help.o gui/icons.o gui/index.o gui/timer.o \
- file/file.o file/git-util.o file/git-file.o file/git-hist.o \
+ $(OBJS_FILE) \
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
gfx/text.o gfx/misc.o gfx/pdftoc.o \
- misc/diag.o misc/util.o
+ $(OBJS_MISC)
+EEPLOT_OBJS = main/eeplot.o main/common.o version.o \
+ $(OBJS_KICAD) \
+ $(OBJS_FILE) \
+ gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
+ gfx/text.o gfx/misc.o gfx/pdftoc.o \
+ $(OBJS_MISC)
EETEST_OBJS = main/eetest.o main/common.o version.o \
- kicad/sexpr.o \
- gui/fmt-pango.o \
- file/file.o file/git-util.o file/git-file.o file/git-hist.o \
- misc/diag.o misc/util.o
+ kicad/sexpr.o \
+ gui/fmt-pango.o \
+ $(OBJS_FILE) \
+ $(OBJS_MISC)
ICONS = delta diff
@@ -64,15 +78,19 @@ include Makefile.c-common
.PHONY: test neo900 sch test testref png pngref pdf diff view newref
.PHONY: leak
-all:: $(NAME) eetest
+all:: $(NAME) eeplot eetest
$(NAME): $(OBJS)
$(MAKE) -B version.o
$(CC) -o $(NAME) $(OBJS) $(LDLIBS)
+eeplot: $(EEPLOT_OBJS)
+ $(MAKE) -B version.o
+ $(CC) -o $@ $(EEPLOT_OBJS) $(LDLIBS)
+
eetest: $(EETEST_OBJS)
$(MAKE) -B version.o
- $(CC) -o eetest $(EETEST_OBJS) $(LDLIBS)
+ $(CC) -o $@ $(EETEST_OBJS) $(LDLIBS)
#----- Help texts -------------------------------------------------------------
@@ -176,4 +194,4 @@ leak: $(NAME)
#----- Cleanup ----------------------------------------------------------------
spotless::
- rm -f eetest
+ rm -f eeplot eetest
diff --git a/main.c b/main.c
index 01d054c..c59956b 100644
--- a/main.c
+++ b/main.c
@@ -15,44 +15,27 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
-#include <string.h>
#include <locale.h>
-#include <cairo/cairo.h>
+//#include <cairo/cairo.h>
#include <gtk/gtk.h>
#include "misc/util.h"
#include "misc/diag.h"
-#include "gfx/fig.h"
-#include "gfx/cro.h"
-#include "gfx/diff.h"
-#include "gfx/gfx.h"
#include "file/file.h"
#include "kicad/ext.h"
-#include "kicad/pl.h"
-#include "kicad/lib.h"
-#include "kicad/sch.h"
-#include "kicad/pro.h"
+#include "kicad/pl.h" // for suppress_page_layout
+#include "gfx/cro.h" // for disable_overline, use_pango
#include "gui/gui.h"
#include "version.h"
#include "main/common.h"
#include "main.h"
-static struct gfx_ops const *ops_list[] = {
- &fig_ops,
- &cro_png_ops,
- &cro_pdf_ops,
- &diff_ops,
-};
-
-
void usage(const char *name)
{
fprintf(stderr,
"usage: %s [gtk_flags] [-1] [-N n] kicad_file ...\n"
-" %s [-1] [-e] [-v ...] kicad_file ...\n"
-" %*s[-- driver_spec]\n"
" %s -V\n"
" %s gdb ...\n"
"\n"
@@ -61,7 +44,6 @@ void usage(const char *name)
" rev git revision\n"
"\n"
" -1 show only one sheet - do not recurse into sub-sheets\n"
-" -e show extra information (e.g., pin types)\n"
" -v increase verbosity of diagnostic output\n"
" -E shell_command ...\n"
" execute the specified shell command when the GUI is ready.\n"
@@ -69,80 +51,30 @@ void usage(const char *name)
" -N n limit history to n revisions (unlimited if omitted or 0)\n"
" -V print revision (version) number and exit\n"
" gdb run eeshow under gdb\n"
-"\n"
-"No driver spec: enter GUI\n"
-"\n"
-"FIG driver spec:\n"
-" fig [-t template.fig] [var=value ...]\n"
-"\n"
-" var=value substitute \"<var>\" with \"value\" in template\n"
-" -t template.fig merge this file with generated output\n"
-"\n"
-"Cairo PNG driver spec:\n"
-" png [-o output.png] [-s scale]\n"
-"\n"
-" -o output.png write PNG to specified file (default; standard output)\n"
-" -s scale scale by indicated factor (default: 1.0)\n"
-"\n"
-"Cairo PDF driver spec:\n"
-" pdf [-o output.pdf] [-s scale] [-T]\n"
-"\n"
-" see PNG for -o and -s\n"
-" -T do not add table of contents\n"
-"\n"
-"Diff driver spec:\n"
-" diff [-o output.pdf] [-s scale] [file.lib ...] file.sch\n"
-"\n"
-" see PNG\n"
- , name, name, (int) strlen(name) + 1, "", name, name);
+ , name, name, name);
exit(1);
}
int main(int argc, char **argv)
{
- struct lib lib;
- struct sch_ctx sch_ctx;
- struct file pro_file, sch_file;
- bool extra = 0;
bool one_sheet = 0;
const char **commands = NULL;
unsigned n_commands = 0;
- struct pl_ctx *pl = NULL;
int limit = 0;
char c;
- int dashdash;
- unsigned i;
- bool have_dashdash = 0;
struct file_names file_names;
- struct file_names *fn = &file_names;
- int gfx_argc;
- char **gfx_argv;
- const struct gfx_ops **ops = ops_list;
- struct gfx *gfx;
- int retval;
run_under_gdb(argc, argv);
- for (dashdash = 1; dashdash != argc; dashdash++)
- if (!strcmp(argv[dashdash], "--")) {
- have_dashdash = 1;
- break;
- }
+ gtk_init(&argc, &argv);
+ setlocale(LC_ALL, "C"); /* restore sanity */
- if (!have_dashdash) {
- gtk_init(&argc, &argv);
- setlocale(LC_ALL, "C"); /* restore sanity */
- }
-
- while ((c = getopt(dashdash, argv, "1evE:LN:OPV")) != EOF)
+ while ((c = getopt(argc, argv, "1vE:LN:OPV")) != EOF)
switch (c) {
case '1':
one_sheet = 1;
break;
- case 'e':
- extra = 1;
- break;
case 'v':
verbose++;
break;
@@ -170,117 +102,13 @@ int main(int argc, char **argv)
usage(*argv);
}
- if (dashdash - optind < 1)
+ if (argc - optind < 1)
usage(*argv);
- classify_files(&file_names, argv + optind, dashdash - optind);
+ classify_files(&file_names, argv + optind, argc - optind);
if (!file_names.pro && !file_names.sch)
fatal("project or top sheet name required");
- if (!have_dashdash) {
- optind = 0; /* reset getopt */
- return run_gui(&file_names, !one_sheet, limit,
- commands, n_commands);
- }
-
- if (dashdash == argc) {
- gfx_argc = 1;
- gfx_argv = alloc_type_n(char *, 2);
- gfx_argv[0] = (char *) (*ops)->name;
- gfx_argv[1] = NULL;
- } else {
- gfx_argc = argc - dashdash - 1;
- if (!gfx_argc)
- usage(*argv);
- gfx_argv = alloc_type_n(char *, gfx_argc + 1);
- memcpy(gfx_argv, argv + dashdash + 1,
- sizeof(const char *) * (gfx_argc + 1));
-
- for (ops = ops_list; ops != ARRAY_END(ops_list); ops++)
- if (!strcmp((*ops)->name, *gfx_argv))
- goto found;
- fatal("graphics backend \"%s\" not found\n", *gfx_argv);
-found:
- ;
- }
-
- if (file_names.pro) {
- if (!file_open(&pro_file, file_names.pro, NULL))
- return 1;
- fn = pro_parse_file(&pro_file, &file_names);
- }
-
- gfx = gfx_init(*ops);
- if (!gfx_args(gfx, gfx_argc, gfx_argv))
- return 1;
- if (!gfx_multi_sheet(gfx))
- one_sheet = 1;
-
- free(gfx_argv);
-
- sch_init(&sch_ctx, !one_sheet);
- if (!file_open(&sch_file, fn->sch, file_names.pro ? &pro_file : NULL))
- return 1;
-
- lib_init(&lib);
- for (i = 0; i != fn->n_libs; i++)
- if (!lib_parse(&lib, fn->libs[i],
- file_names.pro ? &pro_file : &sch_file))
- return 1;
-
- if (file_names.pro)
- file_close(&pro_file);
-
- if (fn->pl) {
- struct file file;
-
- if (!file_open(&file, fn->pl, &sch_file))
- return 1;
- pl = pl_parse(&file);
- file_close(&file);
- if (!pl)
- return 1;
- }
-
- if (fn != &file_names) {
- free_file_names(fn);
- free(fn);
- }
- free_file_names(&file_names);
-
- if (!sch_parse(&sch_ctx, &sch_file, &lib, NULL))
- return 1;
- file_close(&sch_file);
-
- if (one_sheet) {
- sch_render(sch_ctx.sheets, gfx);
- if (extra)
- sch_render_extra(sch_ctx.sheets, gfx);
- if (pl)
- pl_render(pl, gfx, sch_ctx.sheets, sch_ctx.sheets);
- } else {
- const struct sheet *sheet;
-
- for (sheet = sch_ctx.sheets; sheet; sheet = sheet->next) {
- gfx_sheet_name(gfx, sheet->title);
- sch_render(sheet, gfx);
- if (extra)
- sch_render_extra(sheet, gfx);
- if (pl)
- pl_render(pl, gfx, sch_ctx.sheets, sheet);
- if (sheet->next)
- gfx_new_sheet(gfx);
- }
- }
- retval = gfx_end(gfx);
-
- sch_free(&sch_ctx);
- lib_free(&lib);
- if (pl)
- pl_free(pl);
-
- file_cleanup();
- cairo_debug_reset_static_data();
-
- return retval;
+ optind = 0; /* reset getopt */
+ return run_gui(&file_names, !one_sheet, limit, commands, n_commands);
}
diff --git a/main/common.c b/main/common.c
index 50cee63..676f988 100644
--- a/main/common.c
+++ b/main/common.c
@@ -24,7 +24,7 @@ void run_under_gdb(int argc, char *const *argv)
{
char **args;
- if (argc < 1 || strcmp(argv[1], "gdb"))
+ if (argc < 2 || strcmp(argv[1], "gdb"))
return;
args = alloc_type_n(char *, argc + 2);
diff --git a/main/eeplot.c b/main/eeplot.c
new file mode 100644
index 0000000..578b25f
--- /dev/null
+++ b/main/eeplot.c
@@ -0,0 +1,256 @@
+/*
+ * main/eeplot.c - Plots eeschema schematics
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * 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.
+ */
+
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <cairo/cairo.h>
+
+#include "misc/util.h"
+#include "misc/diag.h"
+#include "gfx/fig.h"
+#include "gfx/cro.h"
+#include "gfx/diff.h"
+#include "gfx/gfx.h"
+#include "file/file.h"
+#include "kicad/ext.h"
+#include "kicad/pl.h"
+#include "kicad/lib.h"
+#include "kicad/sch.h"
+#include "kicad/pro.h"
+#include "version.h"
+#include "main/common.h"
+#include "main.h"
+
+
+static struct gfx_ops const *ops_list[] = {
+ &fig_ops,
+ &cro_png_ops,
+ &cro_pdf_ops,
+ &diff_ops,
+};
+
+
+void usage(const char *name)
+{
+ fprintf(stderr,
+"usage: %s [-1] [-e] [-v ...] kicad_file ...\n"
+" %*s-- driver_spec\n"
+" %s -V\n"
+" %s gdb ...\n"
+"\n"
+" kicad_file [rev:]file.ext\n"
+" ext .pro, .lib, .sch, or .kicad_wks\n"
+" rev git revision\n"
+"\n"
+" -1 show only one sheet - do not recurse into sub-sheets\n"
+" -e show extra information (e.g., pin types)\n"
+" -v increase verbosity of diagnostic output\n"
+" -E shell_command ...\n"
+" execute the specified shell command when the GUI is ready.\n"
+" Sets EESHOW_WINDOW_ID to the X11 window ID.\n"
+" -V print revision (version) number and exit\n"
+" gdb run eeshow under gdb\n"
+"\n"
+"FIG driver spec:\n"
+" fig [-t template.fig] [var=value ...]\n"
+"\n"
+" var=value substitute \"<var>\" with \"value\" in template\n"
+" -t template.fig merge this file with generated output\n"
+"\n"
+"Cairo PNG driver spec:\n"
+" png [-o output.png] [-s scale]\n"
+"\n"
+" -o output.png write PNG to specified file (default; standard output)\n"
+" -s scale scale by indicated factor (default: 1.0)\n"
+"\n"
+"Cairo PDF driver spec:\n"
+" pdf [-o output.pdf] [-s scale] [-T]\n"
+"\n"
+" see PNG for -o and -s\n"
+" -T do not add table of contents\n"
+"\n"
+"Diff driver spec:\n"
+" diff [-o output.pdf] [-s scale] [file.lib ...] file.sch\n"
+"\n"
+" see PNG\n"
+ , name, (int) strlen(name) + 1, "", name, name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ struct lib lib;
+ struct sch_ctx sch_ctx;
+ struct file pro_file, sch_file;
+ bool extra = 0;
+ bool one_sheet = 0;
+ struct pl_ctx *pl = NULL;
+ char c;
+ int dashdash;
+ unsigned i;
+ struct file_names file_names;
+ struct file_names *fn = &file_names;
+ int gfx_argc;
+ char **gfx_argv;
+ const struct gfx_ops **ops = ops_list;
+ struct gfx *gfx;
+ int retval;
+
+ run_under_gdb(argc, argv);
+
+ for (dashdash = 1; dashdash != argc; dashdash++)
+ if (!strcmp(argv[dashdash], "--"))
+ break;
+ if (dashdash == argc)
+ usage(*argv);
+
+ while ((c = getopt(dashdash, argv, "1evL:OPV")) != EOF)
+ switch (c) {
+ case '1':
+ one_sheet = 1;
+ break;
+ case 'e':
+ extra = 1;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'L':
+ suppress_page_layout = 1;
+ break;
+ case 'O':
+ disable_overline = 1;
+ break;
+ case 'P':
+ use_pango = 1;
+ break;
+ case 'V':
+ fprintf(stderr, "%s %sZ\n", version, build_date);
+ return 1;
+ default:
+ usage(*argv);
+ }
+
+ if (dashdash - optind < 1)
+ usage(*argv);
+
+ classify_files(&file_names, argv + optind, dashdash - optind);
+ if (!file_names.pro && !file_names.sch)
+ fatal("project or top sheet name required");
+
+ if (dashdash == argc) {
+ gfx_argc = 1;
+ gfx_argv = alloc_type_n(char *, 2);
+ gfx_argv[0] = (char *) (*ops)->name;
+ gfx_argv[1] = NULL;
+ } else {
+ gfx_argc = argc - dashdash - 1;
+ if (!gfx_argc)
+ usage(*argv);
+ gfx_argv = alloc_type_n(char *, gfx_argc + 1);
+ memcpy(gfx_argv, argv + dashdash + 1,
+ sizeof(const char *) * (gfx_argc + 1));
+
+ for (ops = ops_list; ops != ARRAY_END(ops_list); ops++)
+ if (!strcmp((*ops)->name, *gfx_argv))
+ goto found;
+ fatal("graphics backend \"%s\" not found\n", *gfx_argv);
+found:
+ ;
+ }
+
+ if (file_names.pro) {
+ if (!file_open(&pro_file, file_names.pro, NULL))
+ return 1;
+ fn = pro_parse_file(&pro_file, &file_names);
+ }
+
+ gfx = gfx_init(*ops);
+ if (!gfx_args(gfx, gfx_argc, gfx_argv))
+ return 1;
+ if (!gfx_multi_sheet(gfx))
+ one_sheet = 1;
+
+ free(gfx_argv);
+
+ sch_init(&sch_ctx, !one_sheet);
+ if (!file_open(&sch_file, fn->sch, file_names.pro ? &pro_file : NULL))
+ return 1;
+
+ lib_init(&lib);
+ for (i = 0; i != fn->n_libs; i++)
+ if (!lib_parse(&lib, fn->libs[i],
+ file_names.pro ? &pro_file : &sch_file))
+ return 1;
+
+ if (file_names.pro)
+ file_close(&pro_file);
+
+ if (fn->pl) {
+ struct file file;
+
+ if (!file_open(&file, fn->pl, &sch_file))
+ return 1;
+ pl = pl_parse(&file);
+ file_close(&file);
+ if (!pl)
+ return 1;
+ }
+
+ if (fn != &file_names) {
+ free_file_names(fn);
+ free(fn);
+ }
+ free_file_names(&file_names);
+
+ if (!sch_parse(&sch_ctx, &sch_file, &lib, NULL))
+ return 1;
+ file_close(&sch_file);
+
+ if (one_sheet) {
+ sch_render(sch_ctx.sheets, gfx);
+ if (extra)
+ sch_render_extra(sch_ctx.sheets, gfx);
+ if (pl)
+ pl_render(pl, gfx, sch_ctx.sheets, sch_ctx.sheets);
+ } else {
+ const struct sheet *sheet;
+
+ for (sheet = sch_ctx.sheets; sheet; sheet = sheet->next) {
+ gfx_sheet_name(gfx, sheet->title);
+ sch_render(sheet, gfx);
+ if (extra)
+ sch_render_extra(sheet, gfx);
+ if (pl)
+ pl_render(pl, gfx, sch_ctx.sheets, sheet);
+ if (sheet->next)
+ gfx_new_sheet(gfx);
+ }
+ }
+ retval = gfx_end(gfx);
+
+ sch_free(&sch_ctx);
+ lib_free(&lib);
+ if (pl)
+ pl_free(pl);
+
+ file_cleanup();
+ cairo_debug_reset_static_data();
+
+ return retval;
+}