From 909fd6e2c4369020707782e20656069fbb3030d1 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 20 May 2014 23:34:25 +1000 Subject: Found a way to deal with the PACKAGE_* stuff outside of Elm. It's undocumented. --- src/libraries/LumbrJack.c | 81 ++++++++++++++++++++++++++++++++++++++++++++--- src/libraries/LumbrJack.h | 19 +++++++++++ src/libraries/SledjHamr.h | 8 ----- src/libraries/build.lua | 11 ++++--- src/libraries/winFang.c | 40 ++--------------------- src/libraries/winFang.h | 11 ------- 6 files changed, 105 insertions(+), 65 deletions(-) (limited to 'src/libraries') diff --git a/src/libraries/LumbrJack.c b/src/libraries/LumbrJack.c index 8d08622..56d4c50 100644 --- a/src/libraries/LumbrJack.c +++ b/src/libraries/LumbrJack.c @@ -4,11 +4,82 @@ #include "LumbrJack.h" +#include static char dateTime[DATE_TIME_LEN]; +static Eina_Prefix *prefix = NULL; -static void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args) + +int HamrTime(char *argv0, void *main, int logDom) +{ + Eina_Array *path; + char *env, name[PATH_MAX], cwd[PATH_MAX], temp[PATH_MAX * 2]; + int i, len = strlen(argv0); + + if (!eina_init()) + { + printf("Can't load eina library, nothing else will work!\n"); + exit(0); + } + + // Coz eina_file_split splits the string in place, instead of making a copy first. + snprintf(temp, sizeof(temp), "%s", argv0); + path = eina_file_split(temp); + snprintf(name, sizeof(name), "%s", (char *) eina_array_data_get(path, eina_array_count(path) - 1)); + logDom = loggingStartup(name, logDom); + eina_array_free(path); + + temp[len] = 0; + cwd[len] = 0; + for (i = 0; i < len; i++) + { + temp[i] = toupper(name[i]); + cwd[i] = tolower(name[i]); + } + + if (!(prefix = eina_prefix_new(argv0, main, temp, cwd, "checkme.txt", PACKAGE_BIN_DIR, PACKAGE_LIB_DIR, PACKAGE_DATA_DIR, PACKAGE_LOCALE_DIR))) + { + PC("Can't find application prefix!"); + } + + PD("%s is installed in %s", name, eina_prefix_get(prefix)); + PD("The binaries are in %s", eina_prefix_bin_get(prefix)); + PD("The data files are in %s", eina_prefix_data_get(prefix)); + PD("The libraries are in %s", eina_prefix_lib_get(prefix)); + PD("The locale files are in %s", eina_prefix_locale_get(prefix)); + + getcwd(cwd, PATH_MAX); + env = getenv("LUA_CPATH"); + if (!env) env = ""; + sprintf(temp, "%s;%s/lib?.so;%s/?.so;%s/?.so", env, eina_prefix_lib_get(prefix), eina_prefix_lib_get(prefix), cwd); + setenv("LUA_CPATH", temp, 1); + + env = getenv("LUA_PATH"); + if (!env) env = ""; + sprintf(temp, "%s;%s/?.lua;%s/?.lua", env, eina_prefix_lib_get(prefix), cwd); + setenv("LUA_PATH", temp, 1); + + return logDom; +} + +const char *prefix_get() {return eina_prefix_get(prefix);} +const char *prefix_bin_get() {return eina_prefix_bin_get(prefix);} +const char *prefix_data_get() {return eina_prefix_data_get(prefix);} +const char *prefix_lib_get() {return eina_prefix_lib_get(prefix);} +const char *prefix_locale_get() {return eina_prefix_locale_get(prefix);} + +void pantsOff(int logDom) +{ + if (logDom >= 0) + eina_log_domain_unregister(logDom); + + eina_prefix_free(prefix); + + eina_shutdown(); +} + +static void _logPrint(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args) { FILE *f = data; char dt[DATE_TIME_LEN + 1]; @@ -31,9 +102,11 @@ static void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, co int loggingStartup(char *name, int logDom) { + eina_log_threads_enable(); + if (logDom < 0) { - logDom = eina_log_domain_register(name, NULL); + logDom = eina_log_domain_register(name, EINA_COLOR_ORANGE); if (logDom < 0) { EINA_LOG_CRIT("could not register log domain '%s'", name); @@ -42,7 +115,7 @@ int loggingStartup(char *name, int logDom) } eina_log_level_set(EINA_LOG_LEVEL_DBG); eina_log_domain_level_set(name, EINA_LOG_LEVEL_DBG); - eina_log_print_cb_set(_ggg_log_print_cb, stderr); + eina_log_print_cb_set(_logPrint, stderr); // Shut up the excess debugging shit from EFL. eina_log_domain_level_set("eo", EINA_LOG_LEVEL_WARN); @@ -83,7 +156,7 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) *timeOut = szClock; // format - strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); + strftime(date, DATE_TIME_LEN, "%Y-%m-%d %H:%M:%S\r", newTime); return (dateTime); } diff --git a/src/libraries/LumbrJack.h b/src/libraries/LumbrJack.h index 1912bef..74249ed 100644 --- a/src/libraries/LumbrJack.h +++ b/src/libraries/LumbrJack.h @@ -2,6 +2,15 @@ #define _LUMBRJACK_H_ +#define EFL_API_OVERRIDE 1 +/* Enable access to unstable EFL API that are still in beta */ +#define EFL_BETA_API_SUPPORT 1 +/* Enable access to unstable EFL EO API. */ +#define EFL_EO_API_SUPPORT 1 + +#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) + + #include #include @@ -31,6 +40,16 @@ typedef enum #endif +extern int logDom; + +int HamrTime(char *argv0, void *main, int logDom); +const char *prefix_get(void); +const char *prefix_bin_get(void); +const char *prefix_data_get(void); +const char *prefix_lib_get(void); +const char *prefix_locale_get(void); +void pantsOff(int logDom); + int loggingStartup(char *name, int logDom); char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); float timeDiff(struct timeval *now, struct timeval *then); diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index 6c63bcc..7ce32b9 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h @@ -2,20 +2,12 @@ #define _SLEDJHAMR_H_ -#define EFL_API_OVERRIDE 1 -/* Enable access to unstable EFL API that are still in beta */ -#define EFL_BETA_API_SUPPORT 1 -/* Enable access to unstable EFL EO API. */ -#define EFL_EO_API_SUPPORT 1 - #include #include #include -#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) - Ecore_Con_Server *reachOut(char *address, int port, void *data, Ecore_Event_Handler_Cb _add, Ecore_Event_Handler_Cb _data, Ecore_Event_Handler_Cb _del); void sendBack(Ecore_Con_Client *client, const char *SID, const char *message, ...); void sendForth(Ecore_Con_Server *server, const char *SID, const char *message, ...); diff --git a/src/libraries/build.lua b/src/libraries/build.lua index 45c436d..76e9d94 100755 --- a/src/libraries/build.lua +++ b/src/libraries/build.lua @@ -13,6 +13,12 @@ if 'nil' == type(dir) then dir = workingDir end +-- For EFL apps, these are all centrally controlled in libLumbrJack. +CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' + LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS removeFiles(dir, {'LumbrJack.o', lib_d .. '/libLumbrJack.so', 'Runnr.o', lib_d .. '/libRunnr.so', 'SledjHamr.o', lib_d .. '/libSledjHamr.so', '../../media/winFang.edj', 'winFang.o', lib_d .. '/libwinFang.so'}) @@ -23,11 +29,6 @@ runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libLumbrJack.so runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c Runnr.c') runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libRunnr.so -o ' .. lib_d .. '/libRunnr.so Runnr.o') --- For Elm apps, these are all centrally controlled in libSledjHamr. -CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' -CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' -CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' -CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c SledjHamr.c') runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libSledjHamr.so -o ' .. lib_d .. '/libSledjHamr.so SledjHamr.o') diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index bfd9327..9319a18 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -1,41 +1,7 @@ +#include "LumbrJack.h" #include "winFang.h" -void HamrTime(void *elm_main, char *domain) -{ - char *env, cwd[PATH_MAX], temp[PATH_MAX * 2]; - - elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); - elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); - elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); - elm_app_compile_locale_set(PACKAGE_LOCALE_DIR); - // Do this after the above calls, but before changing the working directory, or screwing with argv[0]. - // It tries to set up the package paths depending on where the executable is, so things are relocatable. - // First argument is the elm_main() function that Elementary starts us from. - // Second argument should be a lower case string used as the "domain", which is different from the log domain. - // It's used lower case as part of the data directory path. - // So, if prefix is /usr/local, then the system data dir is /usr/local/share, - // and this apps data dir is /usr/local/share/"domain". - // It's used upper case as part of environment variables to override directory paths at run time. - // So "DOMAIN"_PREFIX, "DOMAIN"_BIN_DIR, "DOMAIN"_LIB_DIR, "DOMAIN"_DATA_DIR, and "DOMAIN"_LOCALE_DIR - // Third argument is the name of a file it can check for to make sure it found the correct path. - // This file is looked for in the data dir. - elm_app_info_set(elm_main, domain, "checkme.txt"); - // Once this is all setup, the code can do - - // elm_app_prefix_dir_get(); // or bin, lib, data, locale. - - getcwd(cwd, PATH_MAX); - env = getenv("LUA_CPATH"); - if (!env) env = ""; - sprintf(temp, "%s;%s/lib?.so;%s/?.so;%s/?.so", env, elm_app_lib_dir_get(), elm_app_lib_dir_get(), cwd); - setenv("LUA_CPATH", temp, 1); - - env = getenv("LUA_PATH"); - if (!env) env = ""; - sprintf(temp, "%s;%s/?.lua;%s/?.lua", env, elm_app_lib_dir_get(), cwd); - setenv("LUA_PATH", temp, 1); -} - static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) { Evas_Object *test; @@ -244,7 +210,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch x = 0; y = 0; } - snprintf(buf, sizeof(buf), "%s/winFang.edj", elm_app_data_dir_get()); + snprintf(buf, sizeof(buf), "%s/winFang.edj", prefix_data_get()); result->layout = eo_add(ELM_OBJ_LAYOUT_CLASS, obj, evas_obj_size_set(w, h), evas_obj_position_set(x, y), @@ -275,7 +241,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch eo_unref(obj); // Create corner handles. - snprintf(buf, sizeof(buf), "%s/pt.png", elm_app_data_dir_get()); + snprintf(buf, sizeof(buf), "%s/pt.png", prefix_data_get()); for (i = 0; i < 4; i++) { int cx = result->x, cy = result->y; diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index f3f4170..7a84a7e 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -2,15 +2,6 @@ #define _WINFANG_H_ -#define EFL_API_OVERRIDE 1 -/* Enable access to unstable EFL API that are still in beta */ -#define EFL_BETA_API_SUPPORT 1 -/* Enable access to unstable EFL EO API. */ -#define EFL_EO_API_SUPPORT 1 - -#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) - - #include #include #include @@ -89,8 +80,6 @@ typedef struct _Widget Evas_Smart_Cb on_del; } Widget; -void HamrTime(void *elm_main, char *domain); - winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world); void winFangHide(winFang *win); void winFangShow(winFang *win); -- cgit v1.1