summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-02 19:35:43 -0300
committerWerner Almesberger <werner@almesberger.net>2016-09-02 19:35:43 -0300
commitc4f8f5e0225cca8e188ba81a56573124b6273dde (patch)
treebe21547eb37078aee3904553a2cbd36dc82ef469
parent63c47828b196e6740d98cc150992ecc7aba0dc79 (diff)
downloadeeshow-c4f8f5e0225cca8e188ba81a56573124b6273dde.tar.gz
eeshow-c4f8f5e0225cca8e188ba81a56573124b6273dde.tar.bz2
eeshow-c4f8f5e0225cca8e188ba81a56573124b6273dde.zip
main/eetest.c: split off main.c
-rw-r--r--Makefile16
-rw-r--r--main.c70
-rw-r--r--main/eetest.c124
3 files changed, 141 insertions, 69 deletions
diff --git a/Makefile b/Makefile
index 645e280..7546417 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,11 @@ OBJS = main.o version.o \
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
+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
ICONS = delta diff
@@ -59,12 +64,16 @@ include Makefile.c-common
.PHONY: test neo900 sch test testref png pngref pdf diff view newref
.PHONY: leak
-all:: $(NAME)
+all:: $(NAME) eetest
$(NAME): $(OBJS)
$(MAKE) -B version.o
$(CC) -o $(NAME) $(OBJS) $(LDLIBS)
+eetest: $(EETEST_OBJS)
+ $(MAKE) -B version.o
+ $(CC) -o eetest $(EETEST_OBJS) $(LDLIBS)
+
#----- Help texts -------------------------------------------------------------
help.inc: $(HELP_TEXT) Makefile
@@ -163,3 +172,8 @@ leak: $(NAME)
diff $(NEO900_HW)/neo900.pro >/dev/null
# eeshow -N 1 $(NEO900_HW)/neo900.pro -- pdf >/dev/null
# eeshow -N 1 $(NEO900_HW)/neo900.pro -- png >/dev/null
+
+#----- Cleanup ----------------------------------------------------------------
+
+spotless::
+ rm -f eetest
diff --git a/main.c b/main.c
index 35ab15f..01d054c 100644
--- a/main.c
+++ b/main.c
@@ -29,13 +29,10 @@
#include "gfx/gfx.h"
#include "file/file.h"
#include "kicad/ext.h"
-#include "kicad/sexpr.h"
#include "kicad/pl.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
#include "kicad/pro.h"
-#include "gui/fmt-pango.h"
-#include "file/git-hist.h"
#include "gui/gui.h"
#include "version.h"
#include "main/common.h"
@@ -50,31 +47,12 @@ static struct gfx_ops const *ops_list[] = {
};
-static void sexpr(void)
-{
- struct sexpr_ctx *parser = sexpr_new();
- struct expr *expr;
- char *buf = NULL;
- size_t n = 0;
-
- while (getline(&buf, &n, stdin) > 0)
- sexpr_parse(parser, buf);
- if (sexpr_finish(parser, &expr))
- dump_expr(expr);
- else
- exit(1);
-}
-
-
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 ...] -C [rev:]file\n"
-" %s [-v ...] -H path_into_repo\n"
-" %s -S\n"
" %s -V\n"
" %s gdb ...\n"
"\n"
@@ -85,13 +63,10 @@ void usage(const char *name)
" -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"
-" -C 'cat' the file to standard 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"
-" -H show history of repository on standard output\n"
" -N n limit history to n revisions (unlimited if omitted or 0)\n"
-" -S parse S-expressions from stdin and dump to stdout\n"
" -V print revision (version) number and exit\n"
" gdb run eeshow under gdb\n"
"\n"
@@ -119,7 +94,7 @@ void usage(const char *name)
" 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);
+ , name, name, (int) strlen(name) + 1, "", name, name);
exit(1);
}
@@ -131,9 +106,6 @@ int main(int argc, char **argv)
struct file pro_file, sch_file;
bool extra = 0;
bool one_sheet = 0;
- const char *cat = NULL;
- const char *history = NULL;
- const char *fmt = NULL;
const char **commands = NULL;
unsigned n_commands = 0;
struct pl_ctx *pl = NULL;
@@ -163,7 +135,7 @@ int main(int argc, char **argv)
setlocale(LC_ALL, "C"); /* restore sanity */
}
- while ((c = getopt(dashdash, argv, "1evC:E:F:H:LN:OPSV")) != EOF)
+ while ((c = getopt(dashdash, argv, "1evE:LN:OPV")) != EOF)
switch (c) {
case '1':
one_sheet = 1;
@@ -174,20 +146,11 @@ int main(int argc, char **argv)
case 'v':
verbose++;
break;
- case 'C':
- cat = optarg;
- break;
case 'E':
commands = realloc_type_n(commands, const char *,
n_commands + 1);
commands[n_commands++] = optarg;
break;
- case 'F':
- fmt = optarg;
- break;
- case 'H':
- history = optarg;
- break;
case 'L':
suppress_page_layout = 1;
break;
@@ -200,9 +163,6 @@ int main(int argc, char **argv)
case 'P':
use_pango = 1;
break;
- case 'S':
- sexpr();
- return 0;
case 'V':
fprintf(stderr, "%s %sZ\n", version, build_date);
return 1;
@@ -210,32 +170,6 @@ int main(int argc, char **argv)
usage(*argv);
}
- if (cat) {
- struct file file;
-
- if (argc != optind)
- usage(*argv);
- if (!file_open(&file, cat, NULL))
- return 1;
- if (!file_read(&file, file_cat, NULL))
- return 1;
- file_close(&file);
- return 0;
- }
-
- if (history) {
- dump_hist(vcs_git_history(history));
- return 0;
- }
-
- if (fmt) {
- char *buf;
-
- buf = fmt_pango(fmt, argv[optind]);
- printf("\"%s\"\n", buf);
- return 0;
- }
-
if (dashdash - optind < 1)
usage(*argv);
diff --git a/main/eetest.c b/main/eetest.c
new file mode 100644
index 0000000..e345c5f
--- /dev/null
+++ b/main/eetest.c
@@ -0,0 +1,124 @@
+/*
+ * main/eetest.c - Subsystem tests (for development)
+ *
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "misc/util.h"
+#include "misc/diag.h"
+#include "file/file.h"
+#include "kicad/sexpr.h"
+#include "gui/fmt-pango.h"
+#include "file/git-hist.h"
+#include "version.h"
+#include "main/common.h"
+
+
+static void sexpr(void)
+{
+ struct sexpr_ctx *parser = sexpr_new();
+ struct expr *expr;
+ char *buf = NULL;
+ size_t n = 0;
+
+ while (getline(&buf, &n, stdin) > 0)
+ sexpr_parse(parser, buf);
+ if (sexpr_finish(parser, &expr))
+ dump_expr(expr);
+ else
+ exit(1);
+}
+
+
+static void usage(const char *name)
+{
+ fprintf(stderr,
+"usage: %s [-v ...] -C [rev:]file\n"
+" %s [-v ...] -H path_into_repo\n"
+" %s -S\n"
+" %s -V\n"
+" %s gdb ...\n"
+"\n"
+" -v increase verbosity of diagnostic output\n"
+" -C 'cat' the file to standard output\n"
+" -H show history of repository on standard output\n"
+" -S parse S-expressions from stdin and dump to stdout\n"
+" -V print revision (version) number and exit\n"
+" gdb run eeshow under gdb\n"
+ , name, name, name, name, name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ const char *cat = NULL;
+ const char *history = NULL;
+ const char *fmt = NULL;
+ int c;
+
+ run_under_gdb(argc, argv);
+
+ while ((c = getopt(argc, argv, "vC:F:H:SV")) != EOF)
+ switch (c) {
+ case 'v':
+ verbose++;
+ break;
+ case 'C':
+ cat = optarg;
+ break;
+ case 'F':
+ fmt = optarg;
+ break;
+ case 'H':
+ history = optarg;
+ break;
+ case 'S':
+ sexpr();
+ return 0;
+ case 'V':
+ fprintf(stderr, "%s %sZ\n", version, build_date);
+ return 1;
+ default:
+ usage(*argv);
+ }
+
+ if (cat) {
+ struct file file;
+
+ if (argc != optind)
+ usage(*argv);
+ if (!file_open(&file, cat, NULL))
+ return 1;
+ if (!file_read(&file, file_cat, NULL))
+ return 1;
+ file_close(&file);
+ return 0;
+ }
+
+ if (history) {
+ dump_hist(vcs_git_history(history));
+ return 0;
+ }
+
+ if (fmt) {
+ char *buf;
+
+ buf = fmt_pango(fmt, argv[optind]);
+ printf("\"%s\"\n", buf);
+ return 0;
+ }
+
+ abort();
+}