use eina_log instead of weirdo printfs... multiple levels, greatness
everywhere... helped me debug emotion's warning.
It is always a pain to try to use library log and notice they are not
using their own standards :-/
export EINA_LOG_LEVELS=eina_prefix:4
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@63108
7cbeb6ba-43b4-40fd-8cce-
4c39aea84d33
S(quadtree);
S(simple_xml);
S(file);
S(quadtree);
S(simple_xml);
S(file);
#undef S
struct eina_desc_setup
#undef S
struct eina_desc_setup
S(ustrbuf),
S(quadtree),
S(simple_xml),
S(ustrbuf),
S(quadtree),
S(simple_xml),
#undef S
};
static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) /
#undef S
};
static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) /
#define STRDUP_REP(x, y) do { if (x) free(x); x = strdup(y); } while (0)
#define IF_FREE_NULL(p) do { if (p) { free(p); p = NULL; } } while (0)
#define STRDUP_REP(x, y) do { if (x) free(x); x = strdup(y); } while (0)
#define IF_FREE_NULL(p) do { if (p) { free(p); p = NULL; } } while (0)
-#define DBG(fmt, args...) do { if (getenv("EINA_PREFIX_DEBUG")) fprintf(stderr, fmt, ##args); } while (0)
+
+#ifndef EINA_LOG_COLOR_DEFAULT
+#define EINA_LOG_COLOR_DEFAULT EINA_COLOR_CYAN
+#endif
+
+#ifdef ERR
+#undef ERR
+#endif
+#define ERR(...) EINA_LOG_DOM_ERR(_eina_prefix_log_dom, __VA_ARGS__)
+
+#ifdef WRN
+#undef WRN
+#endif
+#define WRN(...) EINA_LOG_DOM_WARN(_eina_prefix_log_dom, __VA_ARGS__)
+
+#ifdef INF
+#undef INF
+#endif
+#define INF(...) EINA_LOG_DOM_INFO(_eina_prefix_log_dom, __VA_ARGS__)
+
+#ifdef DBG
+#undef DBG
+#endif
+#define DBG(...) EINA_LOG_DOM_DBG(_eina_prefix_log_dom, __VA_ARGS__)
+
+static int _eina_prefix_log_dom = -1;
static int
_fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
static int
_fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
- DBG("Try /proc/self/maps\n");
+ DBG("Try /proc/self/maps");
f = fopen("/proc/self/maps", "rb");
if (!f) return 0;
f = fopen("/proc/self/maps", "rb");
if (!f) return 0;
- DBG("Exists /proc/self/maps\n");
+ DBG("Exists /proc/self/maps");
while (fgets(buf, sizeof(buf), f))
{
int len;
while (fgets(buf, sizeof(buf), f))
{
int len;
{
if (((void *)ptr1 <= symbol) && (symbol < (void *)ptr2))
{
{
if (((void *)ptr1 <= symbol) && (symbol < (void *)ptr2))
{
- DBG("Found in /proc/self/maps: %s\n", buf);
+ DBG("Found in /proc/self/maps: %s", buf);
p = strchr(buf, '/');
if (p)
{
p = strchr(buf, '/');
if (p)
{
- DBG("Found in /proc/self/maps: found last /\n");
+ DBG("Found in /proc/self/maps: found last /");
if (len > 10)
{
if (!strcmp(buf + len - 10, " (deleted)"))
buf[len - 10] = 0;
}
STRDUP_REP(pfx->exe_path, p);
if (len > 10)
{
if (!strcmp(buf + len - 10, " (deleted)"))
buf[len - 10] = 0;
}
STRDUP_REP(pfx->exe_path, p);
- DBG("Found in /proc/self/maps: guess exe path is %s\n", pfx->exe_path);
+ INF("Found in /proc/self/maps: guess exe path is %s", pfx->exe_path);
- DBG("Failed in /proc/self/maps\n");
+ WRN("Failed in /proc/self/maps");
int len, lenexe;
char buf[PATH_MAX], buf2[PATH_MAX], buf3[PATH_MAX];
int len, lenexe;
char buf[PATH_MAX], buf2[PATH_MAX], buf3[PATH_MAX];
- DBG("Try argv0 = %s\n", argv0);
+ DBG("Try argv0 = %s", argv0);
/* 1. is argv0 abs path? */
#ifdef _WIN32
if (argv0[0] && (argv0[1] == ':'))
/* 1. is argv0 abs path? */
#ifdef _WIN32
if (argv0[0] && (argv0[1] == ':'))
if (argv0[0] == DSEP_C)
#endif
{
if (argv0[0] == DSEP_C)
#endif
{
- DBG("Match arvg0 is full path: %s\n", argv0);
+ DBG("Match arvg0 is full path: %s", argv0);
STRDUP_REP(pfx->exe_path, argv0);
if (access(pfx->exe_path, X_OK) == 0)
{
STRDUP_REP(pfx->exe_path, argv0);
if (access(pfx->exe_path, X_OK) == 0)
{
- DBG("Executable argv0 = %s\n", argv0);
+ INF("Executable argv0 = %s", argv0);
return 1;
}
IF_FREE_NULL(pfx->exe_path);
return 1;
}
IF_FREE_NULL(pfx->exe_path);
- DBG("Non existent argv0: %s\n", argv0);
+ DBG("Non existent argv0: %s", argv0);
return 0;
}
/* 2. relative path */
if (strchr(argv0, DSEP_C))
{
return 0;
}
/* 2. relative path */
if (strchr(argv0, DSEP_C))
{
- DBG("Relative path argv0: %s\n", argv0);
+ DBG("Relative path argv0: %s", argv0);
if (getcwd(buf3, sizeof(buf3)))
{
snprintf(buf2, sizeof(buf2), "%s" DSEP_S "%s", buf3, argv0);
if (getcwd(buf3, sizeof(buf3)))
{
snprintf(buf2, sizeof(buf2), "%s" DSEP_S "%s", buf3, argv0);
- DBG("Relative to CWD: %s\n", buf2);
+ DBG("Relative to CWD: %s", buf2);
if (realpath(buf2, buf))
{
if (realpath(buf2, buf))
{
- DBG("Realpath is: %s\n", buf);
+ DBG("Realpath is: %s", buf);
STRDUP_REP(pfx->exe_path, buf);
if (access(pfx->exe_path, X_OK) == 0)
{
STRDUP_REP(pfx->exe_path, buf);
if (access(pfx->exe_path, X_OK) == 0)
{
- DBG("Path %s is executable\n", pfx->exe_path);
+ INF("Path %s is executable", pfx->exe_path);
- DBG("Fail check for executable: %s\n", pfx->exe_path);
+ DBG("Fail check for executable: %s", pfx->exe_path);
IF_FREE_NULL(pfx->exe_path);
}
}
}
/* 3. argv0 no path - look in PATH */
IF_FREE_NULL(pfx->exe_path);
}
}
}
/* 3. argv0 no path - look in PATH */
- DBG("Look for argv0=%s in $PATH\n", argv0);
+ DBG("Look for argv0=%s in $PATH", argv0);
path = getenv("PATH");
if (!path) return 0;
p = path;
path = getenv("PATH");
if (!path) return 0;
p = path;
strncpy(s, cp, len);
s[len] = DSEP_C;
strcpy(s + len + 1, argv0);
strncpy(s, cp, len);
s[len] = DSEP_C;
strcpy(s + len + 1, argv0);
- DBG("Try path: %s\n", s);
+ DBG("Try path: %s", s);
- DBG("Realpath is: %s\n", buf);
+ DBG("Realpath is: %s", buf);
if (access(buf, X_OK) == 0)
{
STRDUP_REP(pfx->exe_path, buf);
if (access(buf, X_OK) == 0)
{
STRDUP_REP(pfx->exe_path, buf);
- DBG("Path %s is executable\n", pfx->exe_path);
+ INF("Path %s is executable", pfx->exe_path);
char buf[PATH_MAX];
const char *s = getenv(env);
char buf[PATH_MAX];
const char *s = getenv(env);
- DBG("Try env var %s\n", env);
+ DBG("Try env var %s", env);
- DBG("Have env %s = %s\n", env, s);
+ INF("Have env %s = %s", env, s);
STRDUP_REP(*var, s);
return 1;
}
else if (prefix)
{
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s", prefix, dir);
STRDUP_REP(*var, s);
return 1;
}
else if (prefix)
{
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s", prefix, dir);
- DBG("Have prefix %s = %s\n", prefix, buf);
+ INF("Have prefix %s = %s", prefix, buf);
STRDUP_REP(*var, buf);
return 1;
}
STRDUP_REP(*var, buf);
return 1;
}
const char *datadir = "share";
const char *localedir = "share";
const char *datadir = "share";
const char *localedir = "share";
- DBG("EINA PREFIX: argv0=%s, symbol=%p, magicsharefile=%s, envprefix=%s\n", argv0, symbol, magicsharefile, envprefix);
+ DBG("EINA PREFIX: argv0=%s, symbol=%p, magicsharefile=%s, envprefix=%s",
+ argv0, symbol, magicsharefile, envprefix);
pfx = calloc(1, sizeof(Eina_Prefix));
if (!pfx) return NULL;
pfx = calloc(1, sizeof(Eina_Prefix));
if (!pfx) return NULL;
libdir = pkg_lib_p;
datadir = pkg_data_p;
localedir = pkg_locale_p;
libdir = pkg_lib_p;
datadir = pkg_data_p;
localedir = pkg_locale_p;
- DBG("Prefix relative bindir = %s\n", bindir);
- DBG("Prefix relative libdir = %s\n", libdir);
- DBG("Prefix relative datadir = %s\n", datadir);
- DBG("Prefix relative localedir = %s\n", localedir);
+ DBG("Prefix relative bindir = %s", bindir);
+ DBG("Prefix relative libdir = %s", libdir);
+ DBG("Prefix relative datadir = %s", datadir);
+ DBG("Prefix relative localedir = %s", localedir);
}
/* 3. some galoot thought it awesome not to give us a common prefix at compile time
* so fall back to the compile time directories. we are no longer relocatable */
}
/* 3. some galoot thought it awesome not to give us a common prefix at compile time
* so fall back to the compile time directories. we are no longer relocatable */
STRDUP_REP(pfx->prefix_path_data, pkg_data);
STRDUP_REP(pfx->prefix_path_locale, pkg_locale);
pfx->no_common_prefix = 1;
STRDUP_REP(pfx->prefix_path_data, pkg_data);
STRDUP_REP(pfx->prefix_path_locale, pkg_locale);
pfx->no_common_prefix = 1;
- DBG("Can't work out a common prefix - compiled in fallback\n");
+ DBG("Can't work out a common prefix - compiled in fallback");
}
/* if user provides env vars - then use that or also more specific sub
}
/* if user provides env vars - then use that or also more specific sub
- DBG("Try dladdr on %p\n", symbol);
+ DBG("Try dladdr on %p", symbol);
if (symbol)
{
Dl_info info_dl;
if (dladdr(symbol, &info_dl))
{
if (symbol)
{
Dl_info info_dl;
if (dladdr(symbol, &info_dl))
{
- DBG("Dlinfo worked\n");
- DBG("Dlinfo dli_fname = %s\n", info_dl.dli_fname);
+ DBG("Dlinfo dli_fname = %s", info_dl.dli_fname);
# ifdef _WIN32
if (info_dl.dli_fname[0] && (info_dl.dli_fname[1] == ':'))
# else
if (info_dl.dli_fname[0] == DSEP_C)
# endif
{
# ifdef _WIN32
if (info_dl.dli_fname[0] && (info_dl.dli_fname[1] == ':'))
# else
if (info_dl.dli_fname[0] == DSEP_C)
# endif
{
- DBG("Dlsym gave full path.\n");
+ INF("Dlsym gave full path = %s", info_dl.dli_fname);
STRDUP_REP(pfx->exe_path, info_dl.dli_fname);
}
}
STRDUP_REP(pfx->exe_path, info_dl.dli_fname);
}
}
- DBG("Fallback - nothing found\n");
+ WRN("Fallback - nothing found");
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
return pfx;
}
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
return pfx;
}
* data_dir = /blah/whatever/share/enlightenment
* lib_dir = /blah/whatever/lib
*/
* data_dir = /blah/whatever/share/enlightenment
* lib_dir = /blah/whatever/lib
*/
- DBG("From exe %s figure out the rest\n", pfx->exe_path);
+ DBG("From exe %s figure out the rest", pfx->exe_path);
p = strrchr(pfx->exe_path, DSEP_C);
if (p)
{
p = strrchr(pfx->exe_path, DSEP_C);
if (p)
{
strncpy(pfx->prefix_path, pfx->exe_path,
p - pfx->exe_path);
pfx->prefix_path[p - pfx->exe_path] = 0;
strncpy(pfx->prefix_path, pfx->exe_path,
p - pfx->exe_path);
pfx->prefix_path[p - pfx->exe_path] = 0;
- DBG("Have prefix = %s\n", pfx->prefix_path);
+ DBG("Have prefix = %s", pfx->prefix_path);
/* bin */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, bindir);
STRDUP_REP(pfx->prefix_path_bin, buf);
/* bin */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, bindir);
STRDUP_REP(pfx->prefix_path_bin, buf);
- DBG("Have bin = %s\n", pfx->prefix_path_bin);
+ DBG("Have bin = %s", pfx->prefix_path_bin);
/* lib */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, libdir);
STRDUP_REP(pfx->prefix_path_lib, buf);
/* lib */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, libdir);
STRDUP_REP(pfx->prefix_path_lib, buf);
- DBG("Have lib = %s\n", pfx->prefix_path_lib);
+ DBG("Have lib = %s", pfx->prefix_path_lib);
/* locale */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, localedir);
STRDUP_REP(pfx->prefix_path_locale, buf);
/* locale */
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, localedir);
STRDUP_REP(pfx->prefix_path_locale, buf);
- DBG("Have locale = %s\n", pfx->prefix_path_locale);
+ DBG("Have locale = %s", pfx->prefix_path_locale);
/* check if magic file is there - then our guess is right */
if (magic)
{
/* check if magic file is there - then our guess is right */
if (magic)
{
- DBG("Magic = %s\n", magic);
+ DBG("Magic = %s", magic);
snprintf(buf, sizeof(buf),
"%s" DSEP_S "%s" DSEP_S "%s",
pfx->prefix_path, datadir, magic);
snprintf(buf, sizeof(buf),
"%s" DSEP_S "%s" DSEP_S "%s",
pfx->prefix_path, datadir, magic);
- DBG("Checck in %s\n", buf);
+ DBG("Check in %s", buf);
}
if ((!magic) || (stat(buf, &st) == 0))
{
if (buf[0])
}
if ((!magic) || (stat(buf, &st) == 0))
{
if (buf[0])
- DBG("Magic path %s stat passed\n", buf);
+ DBG("Magic path %s stat passed", buf);
- DBG("No magic file\n");
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, datadir);
STRDUP_REP(pfx->prefix_path_data, buf);
snprintf(buf, sizeof(buf), "%s" DSEP_S "%s",
pfx->prefix_path, datadir);
STRDUP_REP(pfx->prefix_path_data, buf);
/* magic file not there. time to start hunting! */
else
{
/* magic file not there. time to start hunting! */
else
{
_fallback(pfx, pkg_bin, pkg_lib, pkg_data,
pkg_locale, envprefix);
}
}
else
{
_fallback(pfx, pkg_bin, pkg_lib, pkg_data,
pkg_locale, envprefix);
}
}
else
{
- DBG("No Prefix path (alloc fail)\n");
+ WRN("No Prefix path (alloc fail)");
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale,
envprefix);
}
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale,
envprefix);
}
- DBG("Final fallback\n");
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
return pfx;
}
_fallback(pfx, pkg_bin, pkg_lib, pkg_data, pkg_locale, envprefix);
return pfx;
}
if (!pfx) return "";
return pfx->prefix_path_locale;
}
if (!pfx) return "";
return pfx->prefix_path_locale;
}
+
+Eina_Bool
+eina_prefix_init(void)
+{
+ _eina_prefix_log_dom = eina_log_domain_register("eina_prefix",
+ EINA_LOG_COLOR_DEFAULT);
+ if (_eina_prefix_log_dom < 0)
+ {
+ EINA_LOG_ERR("Could not register log domain: eina_prefix");
+ return EINA_FALSE;
+ }
+
+ return EINA_TRUE;
+}
+
+Eina_Bool
+eina_prefix_shutdown(void)
+{
+ eina_log_domain_unregister(_eina_prefix_log_dom);
+ _eina_prefix_log_dom = -1;
+ return EINA_TRUE;
+}