Permalink
Browse files

another try to clean up glib dependencies

  • Loading branch information...
tagoh committed Oct 5, 2012
1 parent 0a1d171 commit ade8ccaa16a6acb91816e48ca467a125b5c16141
Showing with 100 additions and 93 deletions.
  1. +3 −0 liblangtag/langtag.h
  2. +4 −0 liblangtag/lt-error.h
  3. +57 −36 liblangtag/lt-ext-module.c
  4. +4 −0 liblangtag/lt-list.h
  5. +8 −4 liblangtag/lt-macros.h
  6. +0 −1 tests/Makefile.am
  7. +17 −44 tests/main.c
  8. +7 −8 tests/main.h
View
@@ -14,9 +14,12 @@
#define __LANGTAG_H__
#define __LANGTAG_H__INSIDE
+#include <liblangtag/lt-error.h>
#include <liblangtag/lt-database.h>
#include <liblangtag/lt-ext-module.h>
#include <liblangtag/lt-extension.h>
+#include <liblangtag/lt-list.h>
+#include <liblangtag/lt-string.h>
#include <liblangtag/lt-tag.h>
#undef __LANGTAG_H__INSIDE
View
@@ -10,6 +10,10 @@
* Lesser General Public License or the Mozilla Public
* License, as specified in the README file.
*/
+#if !defined (__LANGTAG_H__INSIDE) && !defined (__LANGTAG_COMPILATION)
+#error "Only <liblangtag/langtag.h> can be included directly."
+#endif
+
#ifndef __LT_ERROR_H__
#define __LT_ERROR_H__
View
@@ -16,6 +16,7 @@
#include <ctype.h>
#include <dirent.h>
+#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -201,36 +202,43 @@ lt_ext_module_load(lt_ext_module_t *module)
lt_string_t *fullname = lt_string_new(NULL);
char *filename = lt_strdup_printf("liblangtag-ext-%s." G_MODULE_SUFFIX,
module->name);
- char **path_list, *s, *path = NULL;
+ char *path_list, *p, *s, *path;
const char *env = getenv("LANGTAG_EXT_MODULE_PATH");
- int i;
lt_bool_t retval = FALSE;
size_t len;
if (!env) {
- path_list = g_strsplit(
+ path_list = strdup(
#ifdef GNOME_ENABLE_DEBUG
- BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_SEARCHPATH_SEPARATOR_S
- BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_DIR_SEPARATOR_S ".libs" G_SEARCHPATH_SEPARATOR_S
+ BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_SEARCHPATH_SEPARATOR_S
+ BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_DIR_SEPARATOR_S ".libs" LT_SEARCHPATH_SEPARATOR_S
#endif
- LANGTAG_EXT_MODULE_PATH,
- G_SEARCHPATH_SEPARATOR_S,
- -1);
+ LANGTAG_EXT_MODULE_PATH);
} else {
- path_list = g_strsplit(env, G_SEARCHPATH_SEPARATOR_S, -1);
+ path_list = strdup(env);
}
- for (i = 0; path_list[i] != NULL && !retval; i++) {
- s = path_list[i];
-
- while (*s && isspace(*s))
+ s = path_list;
+ do {
+ if (!s)
+ break;
+ p = strchr(s, LT_SEARCHPATH_SEPARATOR);
+ if (p == s) {
s++;
- len = strlen(s);
- while (len > 0 && isspace(s[len - 1]))
+ continue;
+ }
+ path = s;
+ if (p) {
+ *p = 0;
+ p++;
+ }
+ s = p;
+ while (*path && isspace(*path))
+ path++;
+ len = strlen(path);
+ while (len > 0 && isspace(path[len - 1]))
len--;
- if (path)
- free(path);
- path = strndup(s, len);
+ path[len] = 0;
if (path[0] != 0) {
lt_string_clear(fullname);
if (!lt_string_append_filename(fullname, path, filename, NULL)) {
@@ -274,14 +282,13 @@ lt_ext_module_load(lt_ext_module_t *module)
retval = TRUE;
}
}
- }
+ } while (1);
if (!retval)
lt_warning("No such modules: %s", module->name);
lt_string_unref(fullname);
- free(path);
free(filename);
- g_strfreev(path_list);
+ free(path_list);
return retval;
}
@@ -374,7 +381,8 @@ lt_ext_module_new(const char *name)
retval = lt_mem_alloc_object(sizeof (lt_ext_module_t));
if (retval) {
- char *filename = g_path_get_basename(name), *module = NULL;
+ char *n = strdup(name);
+ char *filename = basename(n), *module = NULL;
static const char *prefix = "liblangtag-ext-";
static size_t prefix_len = 0;
char singleton_c;
@@ -399,7 +407,7 @@ lt_ext_module_new(const char *name)
lt_mem_add_ref(&retval->parent, retval->name,
(lt_destroy_func_t)free);
- g_free(filename);
+ free(n);
if (!lt_ext_module_load(retval)) {
lt_ext_module_unref(retval);
@@ -555,28 +563,40 @@ lt_ext_modules_load(void)
{
#ifdef ENABLE_GMODULE
const char *env = getenv("LANGTAG_EXT_MODULE_PATH");
- char **path_list;
- int i;
+ char *path_list, *s, *p, *path;
size_t suffix_len = strlen(G_MODULE_SUFFIX) + 1;
if (__lt_ext_module_initialized)
return;
if (!env) {
- path_list = g_strsplit(
+ path_list = strdup(
#ifdef GNOME_ENABLE_DEBUG
- BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_SEARCHPATH_SEPARATOR_S
- BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_DIR_SEPARATOR_S ".libs" G_SEARCHPATH_SEPARATOR_S
+ BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_SEARCHPATH_SEPARATOR_S
+ BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_DIR_SEPARATOR_S ".libs" LT_SEARCHPATH_SEPARATOR_S
#endif
- LANGTAG_EXT_MODULE_PATH,
- G_SEARCHPATH_SEPARATOR_S,
- -1);
+ LANGTAG_EXT_MODULE_PATH);
} else {
- path_list = g_strsplit(env, G_SEARCHPATH_SEPARATOR_S, -1);
+ path_list = strdup(env);
}
- for (i = 0; path_list[i] != NULL; i++) {
+ s = path_list;
+ do {
DIR *dir;
- dir = opendir(path_list[i]);
+ if (!s)
+ break;
+ p = strchr(s, LT_SEARCHPATH_SEPARATOR);
+ if (s == p) {
+ s++;
+ continue;
+ }
+ path = s;
+ if (p) {
+ *p = 0;
+ p++;
+ }
+ s = p;
+
+ dir = opendir(path);
if (dir) {
struct dirent dent, *dresult;
size_t len;
@@ -594,8 +614,9 @@ lt_ext_modules_load(void)
}
closedir(dir);
}
- }
- g_strfreev(path_list);
+ } while (1);
+
+ free(path_list);
#endif /* ENABLE_GMODULE */
__lt_ext_default_handler = lt_ext_module_new_with_data("default",
&__default_funcs);
View
@@ -10,6 +10,10 @@
* Lesser General Public License or the Mozilla Public
* License, as specified in the README file.
*/
+#if !defined (__LANGTAG_H__INSIDE) && !defined (__LANGTAG_COMPILATION)
+#error "Only <liblangtag/langtag.h> can be included directly."
+#endif
+
#ifndef __LT_LIST_H__
#define __LT_LIST_H__
View
@@ -99,11 +99,15 @@
/* Macros for path separator */
#ifdef _WIN32
-# define LT_DIR_SEPARATOR_S "\\"
-# define LT_DIR_SEPARATOR '\\'
+# define LT_DIR_SEPARATOR_S "\\"
+# define LT_DIR_SEPARATOR '\\'
+# define LT_SEARCHPATH_SEPARATOR_S ";"
+# define LT_SEARCHPATH_SEPARATOR ';'
#else
-# define LT_DIR_SEPARATOR_S "/"
-# define LT_DIR_SEPARATOR '/'
+# define LT_DIR_SEPARATOR_S "/"
+# define LT_DIR_SEPARATOR '/'
+# define LT_SEARCHPATH_SEPARATOR_S ":"
+# define LT_SEARCHPATH_SEPARATOR ':'
#endif
/* Macros for min/max */
View
@@ -8,7 +8,6 @@ INCLUDES = \
-DTEST_DATADIR="\"$(abs_top_builddir)/data\"" \
-DTEST_MODDIR="\"$(abs_top_builddir)/liblangtag/extensions/.libs\"" \
-D__LANGTAG_COMPILATION \
- $(GLIB_CFLAGS) \
$(CHECK_CFLAGS) \
$(NULL)
DEPS = \
View
@@ -18,80 +18,53 @@
#include <stdlib.h>
#include <unistd.h>
#include <check.h>
-#include <glib-object.h>
+#include "langtag.h"
+#include "lt-messages.h"
#include "main.h"
extern Suite *tester_suite(void);
-static GLogFunc old_logger = NULL;
-static GError *error = NULL;
-G_LOCK_DEFINE_STATIC(err);
+static lt_message_func_t old_logger = NULL;
+static lt_error_t *error = NULL;
/*
* Private functions
*/
static void
-logger(const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer user_data)
+logger(lt_message_type_t type,
+ lt_message_flags_t flags,
+ lt_message_category_t category,
+ const char *message,
+ lt_pointer_t user_data)
{
- gchar *prev = NULL;
-
- G_LOCK (err);
-
- if (error) {
- prev = g_strdup_printf("\n %s", error->message);
- g_error_free(error);
- error = NULL;
- }
- g_set_error(&error, TESTER_ERROR, log_level,
- "%s%s", message,
- (prev ? prev : ""));
- g_free(prev);
-
- G_UNLOCK (err);
+ lt_error_set(&error, type, message);
}
static void
init(int argc,
char **argv)
{
- old_logger = g_log_set_default_handler(logger, NULL);
+ old_logger = lt_message_set_default_handler(logger, NULL);
}
static void
fini(void)
{
+ tester_pop_error();
if (old_logger)
- g_log_set_default_handler(old_logger, NULL);
+ lt_message_set_default_handler(old_logger, NULL);
}
/*
* Public functions
*/
-GQuark
-tester_get_error_quark(void)
-{
- GQuark quark = 0;
-
- if (!quark)
- quark = g_quark_from_static_string("tester-error");
-
- return quark;
-}
-
-gchar *
+void
tester_pop_error(void)
{
- gchar *retval = NULL;
-
- if (error) {
- retval = g_strdup(error->message);
- g_clear_error(&error);
+ if (lt_error_is_set(error, LT_ERR_ANY)) {
+ lt_error_print(error, LT_ERR_ANY);
+ lt_error_clear(error);
}
-
- return retval;
}
int
View
@@ -15,9 +15,9 @@
#define __TEST_MAIN_H__
#include <check.h>
-#include <glib.h>
+#include <liblangtag/langtag.h>
-G_BEGIN_DECLS
+LT_BEGIN_DECLS
#define TESTER_ERROR tester_get_error_quark()
#define TDEF(fn) START_TEST (test_ ## fn)
@@ -26,12 +26,11 @@ G_BEGIN_DECLS
#define TNUL(obj) fail_unless((obj) != NULL, "Failed to create an object")
-void setup (void);
-void teardown (void);
-Suite *tester_suite (void);
-GQuark tester_get_error_quark(void);
-gchar *tester_pop_error (void) G_GNUC_MALLOC;
+void setup (void);
+void teardown (void);
+Suite *tester_suite (void);
+void tester_pop_error(void);
-G_END_DECLS
+LT_END_DECLS
#endif /* __TEST_MAIN_H__ */

0 comments on commit ade8cca

Please sign in to comment.