diff options
author | David Walter Seikel | 2014-05-20 23:34:25 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-05-20 23:34:25 +1000 |
commit | 909fd6e2c4369020707782e20656069fbb3030d1 (patch) | |
tree | 15590f94950be42916fff1b3ba00124bce157751 /src/libraries | |
parent | The results of a session with valgrind. (diff) | |
download | SledjHamr-909fd6e2c4369020707782e20656069fbb3030d1.zip SledjHamr-909fd6e2c4369020707782e20656069fbb3030d1.tar.gz SledjHamr-909fd6e2c4369020707782e20656069fbb3030d1.tar.bz2 SledjHamr-909fd6e2c4369020707782e20656069fbb3030d1.tar.xz |
Found a way to deal with the PACKAGE_* stuff outside of Elm. It's undocumented.
Diffstat (limited to 'src/libraries')
-rw-r--r-- | src/libraries/LumbrJack.c | 81 | ||||
-rw-r--r-- | src/libraries/LumbrJack.h | 19 | ||||
-rw-r--r-- | src/libraries/SledjHamr.h | 8 | ||||
-rwxr-xr-x | src/libraries/build.lua | 11 | ||||
-rw-r--r-- | src/libraries/winFang.c | 40 | ||||
-rw-r--r-- | src/libraries/winFang.h | 11 |
6 files changed, 105 insertions, 65 deletions
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 @@ | |||
4 | 4 | ||
5 | 5 | ||
6 | #include "LumbrJack.h" | 6 | #include "LumbrJack.h" |
7 | #include <unistd.h> | ||
7 | 8 | ||
8 | 9 | ||
9 | static char dateTime[DATE_TIME_LEN]; | 10 | static char dateTime[DATE_TIME_LEN]; |
11 | static Eina_Prefix *prefix = NULL; | ||
10 | 12 | ||
11 | 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) | 13 | |
14 | int HamrTime(char *argv0, void *main, int logDom) | ||
15 | { | ||
16 | Eina_Array *path; | ||
17 | char *env, name[PATH_MAX], cwd[PATH_MAX], temp[PATH_MAX * 2]; | ||
18 | int i, len = strlen(argv0); | ||
19 | |||
20 | if (!eina_init()) | ||
21 | { | ||
22 | printf("Can't load eina library, nothing else will work!\n"); | ||
23 | exit(0); | ||
24 | } | ||
25 | |||
26 | // Coz eina_file_split splits the string in place, instead of making a copy first. | ||
27 | snprintf(temp, sizeof(temp), "%s", argv0); | ||
28 | path = eina_file_split(temp); | ||
29 | snprintf(name, sizeof(name), "%s", (char *) eina_array_data_get(path, eina_array_count(path) - 1)); | ||
30 | logDom = loggingStartup(name, logDom); | ||
31 | eina_array_free(path); | ||
32 | |||
33 | temp[len] = 0; | ||
34 | cwd[len] = 0; | ||
35 | for (i = 0; i < len; i++) | ||
36 | { | ||
37 | temp[i] = toupper(name[i]); | ||
38 | cwd[i] = tolower(name[i]); | ||
39 | } | ||
40 | |||
41 | if (!(prefix = eina_prefix_new(argv0, main, temp, cwd, "checkme.txt", PACKAGE_BIN_DIR, PACKAGE_LIB_DIR, PACKAGE_DATA_DIR, PACKAGE_LOCALE_DIR))) | ||
42 | { | ||
43 | PC("Can't find application prefix!"); | ||
44 | } | ||
45 | |||
46 | PD("%s is installed in %s", name, eina_prefix_get(prefix)); | ||
47 | PD("The binaries are in %s", eina_prefix_bin_get(prefix)); | ||
48 | PD("The data files are in %s", eina_prefix_data_get(prefix)); | ||
49 | PD("The libraries are in %s", eina_prefix_lib_get(prefix)); | ||
50 | PD("The locale files are in %s", eina_prefix_locale_get(prefix)); | ||
51 | |||
52 | getcwd(cwd, PATH_MAX); | ||
53 | env = getenv("LUA_CPATH"); | ||
54 | if (!env) env = ""; | ||
55 | sprintf(temp, "%s;%s/lib?.so;%s/?.so;%s/?.so", env, eina_prefix_lib_get(prefix), eina_prefix_lib_get(prefix), cwd); | ||
56 | setenv("LUA_CPATH", temp, 1); | ||
57 | |||
58 | env = getenv("LUA_PATH"); | ||
59 | if (!env) env = ""; | ||
60 | sprintf(temp, "%s;%s/?.lua;%s/?.lua", env, eina_prefix_lib_get(prefix), cwd); | ||
61 | setenv("LUA_PATH", temp, 1); | ||
62 | |||
63 | return logDom; | ||
64 | } | ||
65 | |||
66 | const char *prefix_get() {return eina_prefix_get(prefix);} | ||
67 | const char *prefix_bin_get() {return eina_prefix_bin_get(prefix);} | ||
68 | const char *prefix_data_get() {return eina_prefix_data_get(prefix);} | ||
69 | const char *prefix_lib_get() {return eina_prefix_lib_get(prefix);} | ||
70 | const char *prefix_locale_get() {return eina_prefix_locale_get(prefix);} | ||
71 | |||
72 | void pantsOff(int logDom) | ||
73 | { | ||
74 | if (logDom >= 0) | ||
75 | eina_log_domain_unregister(logDom); | ||
76 | |||
77 | eina_prefix_free(prefix); | ||
78 | |||
79 | eina_shutdown(); | ||
80 | } | ||
81 | |||
82 | 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) | ||
12 | { | 83 | { |
13 | FILE *f = data; | 84 | FILE *f = data; |
14 | char dt[DATE_TIME_LEN + 1]; | 85 | 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 | |||
31 | 102 | ||
32 | int loggingStartup(char *name, int logDom) | 103 | int loggingStartup(char *name, int logDom) |
33 | { | 104 | { |
105 | eina_log_threads_enable(); | ||
106 | |||
34 | if (logDom < 0) | 107 | if (logDom < 0) |
35 | { | 108 | { |
36 | logDom = eina_log_domain_register(name, NULL); | 109 | logDom = eina_log_domain_register(name, EINA_COLOR_ORANGE); |
37 | if (logDom < 0) | 110 | if (logDom < 0) |
38 | { | 111 | { |
39 | EINA_LOG_CRIT("could not register log domain '%s'", name); | 112 | EINA_LOG_CRIT("could not register log domain '%s'", name); |
@@ -42,7 +115,7 @@ int loggingStartup(char *name, int logDom) | |||
42 | } | 115 | } |
43 | eina_log_level_set(EINA_LOG_LEVEL_DBG); | 116 | eina_log_level_set(EINA_LOG_LEVEL_DBG); |
44 | eina_log_domain_level_set(name, EINA_LOG_LEVEL_DBG); | 117 | eina_log_domain_level_set(name, EINA_LOG_LEVEL_DBG); |
45 | eina_log_print_cb_set(_ggg_log_print_cb, stderr); | 118 | eina_log_print_cb_set(_logPrint, stderr); |
46 | 119 | ||
47 | // Shut up the excess debugging shit from EFL. | 120 | // Shut up the excess debugging shit from EFL. |
48 | eina_log_domain_level_set("eo", EINA_LOG_LEVEL_WARN); | 121 | eina_log_domain_level_set("eo", EINA_LOG_LEVEL_WARN); |
@@ -83,7 +156,7 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) | |||
83 | *timeOut = szClock; | 156 | *timeOut = szClock; |
84 | 157 | ||
85 | // format | 158 | // format |
86 | strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); | 159 | strftime(date, DATE_TIME_LEN, "%Y-%m-%d %H:%M:%S\r", newTime); |
87 | return (dateTime); | 160 | return (dateTime); |
88 | } | 161 | } |
89 | 162 | ||
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 @@ | |||
2 | #define _LUMBRJACK_H_ | 2 | #define _LUMBRJACK_H_ |
3 | 3 | ||
4 | 4 | ||
5 | #define EFL_API_OVERRIDE 1 | ||
6 | /* Enable access to unstable EFL API that are still in beta */ | ||
7 | #define EFL_BETA_API_SUPPORT 1 | ||
8 | /* Enable access to unstable EFL EO API. */ | ||
9 | #define EFL_EO_API_SUPPORT 1 | ||
10 | |||
11 | #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) | ||
12 | |||
13 | |||
5 | #include <stdio.h> | 14 | #include <stdio.h> |
6 | #include <ctype.h> | 15 | #include <ctype.h> |
7 | 16 | ||
@@ -31,6 +40,16 @@ typedef enum | |||
31 | #endif | 40 | #endif |
32 | 41 | ||
33 | 42 | ||
43 | extern int logDom; | ||
44 | |||
45 | int HamrTime(char *argv0, void *main, int logDom); | ||
46 | const char *prefix_get(void); | ||
47 | const char *prefix_bin_get(void); | ||
48 | const char *prefix_data_get(void); | ||
49 | const char *prefix_lib_get(void); | ||
50 | const char *prefix_locale_get(void); | ||
51 | void pantsOff(int logDom); | ||
52 | |||
34 | int loggingStartup(char *name, int logDom); | 53 | int loggingStartup(char *name, int logDom); |
35 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); | 54 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); |
36 | float timeDiff(struct timeval *now, struct timeval *then); | 55 | 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 @@ | |||
2 | #define _SLEDJHAMR_H_ | 2 | #define _SLEDJHAMR_H_ |
3 | 3 | ||
4 | 4 | ||
5 | #define EFL_API_OVERRIDE 1 | ||
6 | /* Enable access to unstable EFL API that are still in beta */ | ||
7 | #define EFL_BETA_API_SUPPORT 1 | ||
8 | /* Enable access to unstable EFL EO API. */ | ||
9 | #define EFL_EO_API_SUPPORT 1 | ||
10 | |||
11 | #include <stdlib.h> | 5 | #include <stdlib.h> |
12 | 6 | ||
13 | #include <Ecore.h> | 7 | #include <Ecore.h> |
14 | #include <Ecore_Con.h> | 8 | #include <Ecore_Con.h> |
15 | 9 | ||
16 | 10 | ||
17 | #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) | ||
18 | |||
19 | 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); | 11 | 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); |
20 | void sendBack(Ecore_Con_Client *client, const char *SID, const char *message, ...); | 12 | void sendBack(Ecore_Con_Client *client, const char *SID, const char *message, ...); |
21 | void sendForth(Ecore_Con_Server *server, const char *SID, const char *message, ...); | 13 | 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 | |||
13 | dir = workingDir | 13 | dir = workingDir |
14 | end | 14 | end |
15 | 15 | ||
16 | -- For EFL apps, these are all centrally controlled in libLumbrJack. | ||
17 | CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' | ||
18 | CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' | ||
19 | CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' | ||
20 | CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' | ||
21 | |||
16 | LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS | 22 | LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS |
17 | 23 | ||
18 | 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'}) | 24 | 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 | |||
23 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c Runnr.c') | 29 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c Runnr.c') |
24 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libRunnr.so -o ' .. lib_d .. '/libRunnr.so Runnr.o') | 30 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libRunnr.so -o ' .. lib_d .. '/libRunnr.so Runnr.o') |
25 | 31 | ||
26 | -- For Elm apps, these are all centrally controlled in libSledjHamr. | ||
27 | CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' | ||
28 | CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' | ||
29 | CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' | ||
30 | CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' | ||
31 | 32 | ||
32 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c SledjHamr.c') | 33 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c SledjHamr.c') |
33 | runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libSledjHamr.so -o ' .. lib_d .. '/libSledjHamr.so SledjHamr.o') | 34 | 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 @@ | |||
1 | #include "LumbrJack.h" | ||
1 | #include "winFang.h" | 2 | #include "winFang.h" |
2 | 3 | ||
3 | 4 | ||
4 | void HamrTime(void *elm_main, char *domain) | ||
5 | { | ||
6 | char *env, cwd[PATH_MAX], temp[PATH_MAX * 2]; | ||
7 | |||
8 | elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); | ||
9 | elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); | ||
10 | elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); | ||
11 | elm_app_compile_locale_set(PACKAGE_LOCALE_DIR); | ||
12 | // Do this after the above calls, but before changing the working directory, or screwing with argv[0]. | ||
13 | // It tries to set up the package paths depending on where the executable is, so things are relocatable. | ||
14 | // First argument is the elm_main() function that Elementary starts us from. | ||
15 | // Second argument should be a lower case string used as the "domain", which is different from the log domain. | ||
16 | // It's used lower case as part of the data directory path. | ||
17 | // So, if prefix is /usr/local, then the system data dir is /usr/local/share, | ||
18 | // and this apps data dir is /usr/local/share/"domain". | ||
19 | // It's used upper case as part of environment variables to override directory paths at run time. | ||
20 | // So "DOMAIN"_PREFIX, "DOMAIN"_BIN_DIR, "DOMAIN"_LIB_DIR, "DOMAIN"_DATA_DIR, and "DOMAIN"_LOCALE_DIR | ||
21 | // Third argument is the name of a file it can check for to make sure it found the correct path. | ||
22 | // This file is looked for in the data dir. | ||
23 | elm_app_info_set(elm_main, domain, "checkme.txt"); | ||
24 | // Once this is all setup, the code can do - | ||
25 | // elm_app_prefix_dir_get(); // or bin, lib, data, locale. | ||
26 | |||
27 | getcwd(cwd, PATH_MAX); | ||
28 | env = getenv("LUA_CPATH"); | ||
29 | if (!env) env = ""; | ||
30 | sprintf(temp, "%s;%s/lib?.so;%s/?.so;%s/?.so", env, elm_app_lib_dir_get(), elm_app_lib_dir_get(), cwd); | ||
31 | setenv("LUA_CPATH", temp, 1); | ||
32 | |||
33 | env = getenv("LUA_PATH"); | ||
34 | if (!env) env = ""; | ||
35 | sprintf(temp, "%s;%s/?.lua;%s/?.lua", env, elm_app_lib_dir_get(), cwd); | ||
36 | setenv("LUA_PATH", temp, 1); | ||
37 | } | ||
38 | |||
39 | static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) | 5 | static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) |
40 | { | 6 | { |
41 | Evas_Object *test; | 7 | Evas_Object *test; |
@@ -244,7 +210,7 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch | |||
244 | x = 0; y = 0; | 210 | x = 0; y = 0; |
245 | } | 211 | } |
246 | 212 | ||
247 | snprintf(buf, sizeof(buf), "%s/winFang.edj", elm_app_data_dir_get()); | 213 | snprintf(buf, sizeof(buf), "%s/winFang.edj", prefix_data_get()); |
248 | result->layout = eo_add(ELM_OBJ_LAYOUT_CLASS, obj, | 214 | result->layout = eo_add(ELM_OBJ_LAYOUT_CLASS, obj, |
249 | evas_obj_size_set(w, h), | 215 | evas_obj_size_set(w, h), |
250 | evas_obj_position_set(x, y), | 216 | 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 | |||
275 | eo_unref(obj); | 241 | eo_unref(obj); |
276 | 242 | ||
277 | // Create corner handles. | 243 | // Create corner handles. |
278 | snprintf(buf, sizeof(buf), "%s/pt.png", elm_app_data_dir_get()); | 244 | snprintf(buf, sizeof(buf), "%s/pt.png", prefix_data_get()); |
279 | for (i = 0; i < 4; i++) | 245 | for (i = 0; i < 4; i++) |
280 | { | 246 | { |
281 | int cx = result->x, cy = result->y; | 247 | 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 @@ | |||
2 | #define _WINFANG_H_ | 2 | #define _WINFANG_H_ |
3 | 3 | ||
4 | 4 | ||
5 | #define EFL_API_OVERRIDE 1 | ||
6 | /* Enable access to unstable EFL API that are still in beta */ | ||
7 | #define EFL_BETA_API_SUPPORT 1 | ||
8 | /* Enable access to unstable EFL EO API. */ | ||
9 | #define EFL_EO_API_SUPPORT 1 | ||
10 | |||
11 | #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) | ||
12 | |||
13 | |||
14 | #include <Eo.h> | 5 | #include <Eo.h> |
15 | #include <Eina.h> | 6 | #include <Eina.h> |
16 | #include <Evas.h> | 7 | #include <Evas.h> |
@@ -89,8 +80,6 @@ typedef struct _Widget | |||
89 | Evas_Smart_Cb on_del; | 80 | Evas_Smart_Cb on_del; |
90 | } Widget; | 81 | } Widget; |
91 | 82 | ||
92 | void HamrTime(void *elm_main, char *domain); | ||
93 | |||
94 | winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world); | 83 | winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world); |
95 | void winFangHide(winFang *win); | 84 | void winFangHide(winFang *win); |
96 | void winFangShow(winFang *win); | 85 | void winFangShow(winFang *win); |