Commit e4536e344131be7c8cfc62187cb5bd6c4f29eb90

Thomas de Grivel 2020-05-11T12:39:16

refactor cli to separate main function

diff --git a/cli/Makefile.am b/cli/Makefile.am
index 071286f..5648be6 100644
--- a/cli/Makefile.am
+++ b/cli/Makefile.am
@@ -1,5 +1,14 @@
-bin_PROGRAMS = rtbuf
-rtbuf_LDADD = ../librtbuf/.libs/librtbuf.la ${RTBUF_LIBS}
-rtbuf_SOURCES = \
+lib_LTLIBRARIES = librtbuf_cli.la
+librtbuf_cli_la_LIBADD = ../librtbuf/.libs/librtbuf.la ${RTBUF_LIBS}
+librtbuf_cli_la_SOURCES = \
 	cli.c \
 	rtbuf_cli.c
+
+bin_PROGRAMS = rtbuf
+rtbuf_LDADD = librtbuf_cli.la
+rtbuf_SOURCES = \
+	rtbuf_cli_main.c
+
+rtbuf_includedir = $(includedir)/rtbuf
+rtbuf_include_HEADERS = \
+	include/rtbuf/cli.h
diff --git a/cli/include/rtbuf/cli.h b/cli/include/rtbuf/cli.h
new file mode 100644
index 0000000..0624aad
--- /dev/null
+++ b/cli/include/rtbuf/cli.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef RTBUF_CLI_H
+#define RTBUF_CLI_H
+
+int rtbuf_cli_exit (int argc, const char *argv[]);
+void repl_init ();
+int load (const char *path);
+int repl ();
+void rtbuf_cli_args (int argc, char *argv[]);
+
+#endif /* RTBUF_CLI_H */
diff --git a/cli/rtbuf_cli.c b/cli/rtbuf_cli.c
index c4bbc5d..5e25329 100644
--- a/cli/rtbuf_cli.c
+++ b/cli/rtbuf_cli.c
@@ -365,13 +365,3 @@ void rtbuf_cli_args (int argc, char *argv[])
     load(arg);
   }
 }
-
-int main (int argc, char *argv[])
-{
-  symbols_init();
-  librtbuf_init();
-  assert(g_rtbuf);
-  repl_init();
-  rtbuf_cli_args(argc, argv);
-  return repl();
-}
diff --git a/cli/rtbuf_cli_main.c b/cli/rtbuf_cli_main.c
new file mode 100644
index 0000000..cced2b6
--- /dev/null
+++ b/cli/rtbuf_cli_main.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/cli.h>
+
+int main (int argc, char *argv[])
+{
+  symbols_init();
+  librtbuf_init();
+  assert(g_rtbuf);
+  repl_init();
+  rtbuf_cli_args(argc, argv);
+  return repl();
+}
diff --git a/configure.ac b/configure.ac
index 95271d5..6184c2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,7 +28,7 @@ if test -d /usr/lib; then
   LDFLAGS="$LDFLAGS -L/usr/lib"
 fi
 
-CPPFLAGS="-I${PWD}/librtbuf/include -I${PWD}/lib/include $CPPFLAGS"
+CPPFLAGS="-I${PWD}/librtbuf/include -I${PWD}/cli/include -I${PWD}/lib/include $CPPFLAGS"
 CFLAGS="$CFLAGS -std=c89 -W -Wall -Werror -D_DEFAULT_SOURCE"
 
 AC_CHECK_FUNC([strlcpy], [echo using system strlcpy],