2014-02-12 12:56:20 -08:00
|
|
|
#ifdef HAVE_CONFIG
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-22 14:41:23 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2016-11-06 08:24:17 -08:00
|
|
|
#include <libgen.h>
|
2014-10-22 14:41:23 -07:00
|
|
|
|
2017-05-30 15:30:39 -07:00
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ecore.h>
|
2015-05-16 02:05:54 -07:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2014-02-12 12:56:20 -08:00
|
|
|
#include "Edi.h"
|
|
|
|
|
|
|
|
#include "edi_private.h"
|
|
|
|
|
|
|
|
static int _edi_init = 0;
|
|
|
|
int _edi_lib_log_dom = -1;
|
2014-04-27 09:36:20 -07:00
|
|
|
static const char *_edi_project_path;
|
2014-02-12 12:56:20 -08:00
|
|
|
|
|
|
|
EAPI int
|
|
|
|
edi_init(void)
|
|
|
|
{
|
|
|
|
_edi_init++;
|
|
|
|
if (_edi_init > 1) return _edi_init;
|
|
|
|
|
|
|
|
eina_init();
|
2017-05-30 15:30:39 -07:00
|
|
|
ecore_init();
|
2014-02-12 12:56:20 -08:00
|
|
|
|
2014-12-21 15:32:14 -08:00
|
|
|
_edi_lib_log_dom = eina_log_domain_register("edi-lib", EINA_COLOR_CYAN);
|
2014-02-12 12:56:20 -08:00
|
|
|
if (_edi_lib_log_dom < 0)
|
|
|
|
{
|
2014-12-21 15:32:14 -08:00
|
|
|
EINA_LOG_ERR("Edi lib cannot create its log domain.");
|
2014-02-15 16:31:10 -08:00
|
|
|
goto shutdown_eina;
|
2014-02-12 12:56:20 -08:00
|
|
|
}
|
2014-12-21 15:32:14 -08:00
|
|
|
INF("Edi library loaded");
|
2014-02-12 12:56:20 -08:00
|
|
|
|
|
|
|
// Put here your initialization logic of your library
|
|
|
|
|
|
|
|
eina_log_timing(_edi_lib_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT);
|
|
|
|
|
|
|
|
return _edi_init;
|
|
|
|
|
2014-02-12 15:02:09 -08:00
|
|
|
shutdown_eina:
|
2017-05-30 15:30:39 -07:00
|
|
|
ecore_shutdown();
|
2014-02-12 12:56:20 -08:00
|
|
|
eina_shutdown();
|
|
|
|
_edi_init--;
|
|
|
|
|
|
|
|
return _edi_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
edi_shutdown(void)
|
|
|
|
{
|
|
|
|
_edi_init--;
|
|
|
|
if (_edi_init != 0) return _edi_init;
|
|
|
|
|
|
|
|
eina_log_timing(_edi_lib_log_dom,
|
2014-02-15 16:31:10 -08:00
|
|
|
EINA_LOG_STATE_START,
|
|
|
|
EINA_LOG_STATE_SHUTDOWN);
|
2014-02-12 12:56:20 -08:00
|
|
|
|
2014-12-21 15:32:14 -08:00
|
|
|
INF("Edi library shut down");
|
|
|
|
|
2014-02-12 12:56:20 -08:00
|
|
|
// Put here your shutdown logic
|
|
|
|
|
|
|
|
eina_log_domain_unregister(_edi_lib_log_dom);
|
|
|
|
_edi_lib_log_dom = -1;
|
|
|
|
|
|
|
|
eina_shutdown();
|
|
|
|
|
|
|
|
return _edi_init;
|
|
|
|
}
|
|
|
|
|
2014-10-22 14:41:23 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_edi_path_isdir(const char *path)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
stat(path, &buf);
|
|
|
|
return S_ISDIR(buf.st_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2014-04-27 09:36:20 -07:00
|
|
|
edi_project_set(const char *path)
|
2014-02-12 12:56:20 -08:00
|
|
|
{
|
2014-10-22 14:41:23 -07:00
|
|
|
char *real = NULL;
|
|
|
|
|
2014-11-12 15:43:18 -08:00
|
|
|
real = realpath(path, NULL);
|
2014-10-22 14:41:23 -07:00
|
|
|
if (!_edi_path_isdir(path))
|
|
|
|
{
|
|
|
|
free(real);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-27 10:43:15 -07:00
|
|
|
if (_edi_project_path)
|
|
|
|
eina_stringshare_del(_edi_project_path);
|
|
|
|
|
2014-11-12 15:43:18 -08:00
|
|
|
_edi_project_path = eina_stringshare_add(real);
|
2014-10-22 14:41:23 -07:00
|
|
|
free(real);
|
|
|
|
return EINA_TRUE;
|
2014-04-27 09:36:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
|
|
|
edi_project_get()
|
|
|
|
{
|
|
|
|
return _edi_project_path;
|
|
|
|
}
|
|
|
|
|
2016-11-04 07:49:39 -07:00
|
|
|
EAPI const char *
|
|
|
|
edi_project_name_get()
|
|
|
|
{
|
|
|
|
return basename((char*)edi_project_get());
|
|
|
|
}
|
|
|
|
|
2017-02-19 08:22:53 -08:00
|
|
|
EAPI char *
|
2014-04-27 09:36:20 -07:00
|
|
|
edi_project_file_path_get(const char *file)
|
|
|
|
{
|
2015-07-17 10:30:25 -07:00
|
|
|
return edi_path_append(edi_project_get(), file);
|
2014-04-27 09:36:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
edi_project_file_exists(const char *file)
|
|
|
|
{
|
2017-02-19 08:22:53 -08:00
|
|
|
char *path;
|
2014-04-27 09:36:20 -07:00
|
|
|
Eina_Bool exists;
|
|
|
|
|
|
|
|
path = edi_project_file_path_get(file);
|
|
|
|
exists = ecore_file_exists(path);
|
|
|
|
|
2017-02-19 08:22:53 -08:00
|
|
|
free(path);
|
2014-04-27 09:36:20 -07:00
|
|
|
return exists;
|
2014-02-12 12:56:20 -08:00
|
|
|
}
|