summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-02 19:08:23 -0300
committerWerner Almesberger <werner@almesberger.net>2016-09-02 19:08:23 -0300
commit63c47828b196e6740d98cc150992ecc7aba0dc79 (patch)
treebffa5692315d3ecf3d94fa34fe31b3a246a59ace
parente7c21fc83758b9431bce474c5ba12eec2e20ac10 (diff)
downloadeeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.tar.gz
eeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.tar.bz2
eeshow-63c47828b196e6740d98cc150992ecc7aba0dc79.zip
main/common.c: split gdb launcher off main.c (beginning of big main.c split)
-rw-r--r--Makefile1
-rw-r--r--main.c14
-rw-r--r--main/common.c38
-rw-r--r--main/common.h18
4 files changed, 59 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index cb975bc..645e280 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ SHELL = /bin/bash
NAME = eeshow
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 \
diff --git a/main.c b/main.c
index 1248802..35ab15f 100644
--- a/main.c
+++ b/main.c
@@ -38,6 +38,7 @@
#include "file/git-hist.h"
#include "gui/gui.h"
#include "version.h"
+#include "main/common.h"
#include "main.h"
@@ -149,18 +150,7 @@ int main(int argc, char **argv)
struct gfx *gfx;
int retval;
- if (argc > 1 && !strcmp(argv[1], "gdb")) {
- char **args;
-
- args = alloc_type_n(char *, argc + 2);
- args[0] = "gdb";
- args[1] = "--args";
- args[2] = *argv;
- memcpy(args + 3, argv + 2, sizeof(char *) * (argc - 1));
- execvp("gdb", args);
- perror(*argv);
- return 1;
- }
+ run_under_gdb(argc, argv);
for (dashdash = 1; dashdash != argc; dashdash++)
if (!strcmp(argv[dashdash], "--")) {
diff --git a/main/common.c b/main/common.c
new file mode 100644
index 0000000..50cee63
--- /dev/null
+++ b/main/common.c
@@ -0,0 +1,38 @@
+/*
+ * main/common.c - Functions common to more than one form of invocation
+ *
+ * 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 <string.h>
+
+#include "misc/util.h"
+#include "main/common.h"
+
+
+void run_under_gdb(int argc, char *const *argv)
+{
+ char **args;
+
+ if (argc < 1 || strcmp(argv[1], "gdb"))
+ return;
+
+ args = alloc_type_n(char *, argc + 2);
+ args[0] = "gdb";
+ args[1] = "--args";
+ args[2] = *argv;
+ memcpy(args + 3, argv + 2, sizeof(char *) * (argc - 1));
+ execvp("gdb", args);
+ perror(*argv);
+ exit(1);
+}
diff --git a/main/common.h b/main/common.h
new file mode 100644
index 0000000..05af4f1
--- /dev/null
+++ b/main/common.h
@@ -0,0 +1,18 @@
+/*
+ * main/common.h - Functions common to more than one form of invocation
+ *
+ * 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.
+ */
+
+#ifndef MAIN_COMMON_H
+#define MAIN_COMMON_H
+
+void run_under_gdb(int argc, char *const *argv);
+
+#endif /* !MAIN_COMMON_H */