From 75d5ac790c0293b93821e77d2e21395c9988d5e5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 27 Apr 2014 18:31:08 +0100 Subject: [PATCH] Added edi_build command line application for headless operation --- .gitignore | 1 + ChangeLog | 1 + NEWS | 3 + src/bin/Makefile.am | 7 ++- src/bin/edi_build_main.c | 117 +++++++++++++++++++++++++++++++++++++++ src/lib/Edi.h | 2 + 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/bin/edi_build_main.c diff --git a/.gitignore b/.gitignore index 3edc949..4b2544a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.gcda /src/bin/edi +/src/bin/edi_build /src/tests/edi_tests /data/desktop/edi.desktop /doc/edi.1 diff --git a/ChangeLog b/ChangeLog index e7c3321..f7421c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2014-04-27 ajwillia.ms (Andy Williams) * Add simple build functions + * Create an edi_build binary for command line building 2014-03-31 ajwillia.ms (Andy Williams) diff --git a/NEWS b/NEWS index 4d49966..a3260f0 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ +Changes since Edi project started: +---------------------------------- pre-1.0 phase 2 "Code aware editor" - Simple build functions + - Added a command line builder application pre-1.0 phase 1 "Basic text editing" diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 7dca58b..d42b924 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -1,6 +1,6 @@ MAINTAINERCLEANFILES = Makefile.in -bin_PROGRAMS = edi +bin_PROGRAMS = edi edi_build AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -I$(top_builddir)/src/bin/ \ @@ -18,6 +18,11 @@ edi_main.c edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la +edi_build_SOURCES = \ +edi_build_main.c + +edi_build_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la + localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ diff --git a/src/bin/edi_build_main.c b/src/bin/edi_build_main.c new file mode 100644 index 0000000..66cb049 --- /dev/null +++ b/src/bin/edi_build_main.c @@ -0,0 +1,117 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* NOTE: Respecting header order is important for portability. + * Always put system first, then EFL, then your public header, + * and finally your private one. */ + +#include +#include + +#include "gettext.h" + +#include "Edi.h" + +#include "edi_private.h" + +#define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." + +static Eina_Bool +exe_data(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Data *ev) +{ + Ecore_Exe_Event_Data_Line *el; + + for (el = ev->lines; el && el->line; el++) + fprintf(stdout, "%s\n", el->line); + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool +exe_del(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Data *ev) +{ + ecore_main_loop_quit(); + + return ECORE_CALLBACK_DONE; +} + +static const Ecore_Getopt optdesc = { + "edi_build", + "%prog [options]", + PACKAGE_VERSION, + COPYRIGHT, + "BSD with advertisement clause", + "The EFL IDE builder", + EINA_TRUE, + { + ECORE_GETOPT_LICENSE('L', "license"), + ECORE_GETOPT_COPYRIGHT('C', "copyright"), + ECORE_GETOPT_VERSION('V', "version"), + ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_SENTINEL + } +}; + +EAPI_MAIN int +main(int argc EINA_UNUSED, char **argv EINA_UNUSED) +{ + int args; + char path[PATH_MAX]; + Eina_Bool quit_option = EINA_FALSE; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + }; + +#if ENABLE_NLS + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + bind_textdomain_codeset(PACKAGE, "UTF-8"); + textdomain(PACKAGE); +#endif + + if (!ecore_init()) + goto exit; + edi_init(); + + args = ecore_getopt_parse(&optdesc, values, argc, argv); + if (args < 0) + { + EINA_LOG_CRIT("Could not parse arguments."); + goto end; + } + else if (quit_option) + { + goto end; + } + + getcwd(path, PATH_MAX); + edi_project_set(path); + + if (!edi_builder_can_build()) + { + fprintf(stderr, "Cowardly refusing to build unknown project type.\n"); + ecore_shutdown(); + goto exit; + } + + ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data, NULL); + ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, exe_data, NULL); + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, exe_del, NULL); + + edi_builder_build(); + ecore_main_loop_begin(); + + end: + edi_shutdown(); + ecore_shutdown(); + return EXIT_SUCCESS; + + exit: + return EXIT_FAILURE; +} + diff --git a/src/lib/Edi.h b/src/lib/Edi.h index bd5406b..529bf0a 100644 --- a/src/lib/Edi.h +++ b/src/lib/Edi.h @@ -33,6 +33,8 @@ extern "C" { #endif +#include + /** * @file * @brief These routines are used for Edi library interaction.