Enlightenment CVS committal Author : handyande Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore_config Modified Files: ecore_config_ipc_main.c ecore_config_util.c ecore_config_util.h Log Message: Cleanup of lib from Morten Nilsen - thanks =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_ipc_main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- ecore_config_ipc_main.c 24 Dec 2005 10:28:08 -0000 1.7 +++ ecore_config_ipc_main.c 30 Dec 2005 20:10:01 -0000 1.8 @@ -1,6 +1,7 @@ /* ############## bad */ #define HAVE_EVAS2 +#include "Ecore.h" #include "Ecore_Config.h" #include "ecore_config_util.h" #include "ecore_config_ipc.h" @@ -18,7 +19,7 @@ #include <stdlib.h> /* malloc(), free() */ static Ecore_Config_Server *__ecore_config_servers; -static unsigned long ipc_timer = 0L; +Ecore_Timer *ipc_timer = NULL; extern int _ecore_config_ipc_ecore_init(const char *pipe_name, void **data); extern int _ecore_config_ipc_ecore_exit(void **data); @@ -232,7 +233,8 @@ Ecore_Config_Server *l; if (ipc_timer) - timeout_remove(ipc_timer); + ecore_timer_del(ipc_timer); + l = __ecore_config_servers; while (l) { @@ -274,7 +276,7 @@ ret_srv = list; if (!ipc_timer) - ipc_timer = timeout_add(100, _ecore_config_ipc_poll, NULL); + ipc_timer = ecore_timer_add(100, _ecore_config_ipc_poll, NULL); return ret_srv; } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ecore_config_util.c 2 Mar 2005 07:06:34 -0000 1.2 +++ ecore_config_util.c 30 Dec 2005 20:10:01 -0000 1.3 @@ -1,20 +1,10 @@ /* azundris */ -/*#include <glib.h>*/ - #include <sys/types.h> -#include <sys/time.h> /* gimetimeofday() */ -#include <stdio.h> /* NULL */ #include <stdlib.h> /* malloc(), free() */ #include <string.h> /* str...() */ -#include <ctype.h> /* isspace() */ - -#include <stdarg.h> /* varargs in dlmulti() */ -#include <dlfcn.h> /* dlopen() and friends for dlmulti() */ -/* #ifdef HAVE_GLIB2 */ -/* # include <glib/gmain.h> */ -/* #endif */ +#include <stdarg.h> /* varargs in sprintf/appendf */ #include "ecore_private.h" @@ -23,468 +13,6 @@ #include "ecore_config_private.h" -#define CHUNKLEN 4096 - -/*****************************************************************************/ -/* MISC */ -/********/ - -int -dlmulti(const char *name, const char *file, int flag, void **libr, const char *fmt, ...) -{ -#define MAX_SYM_LEN 256 - va_list ap; - void *lib; - int ret = ECORE_CONFIG_ERR_SUCC; - char buf[MAX_SYM_LEN] = "\0"; - - if (!libr) - return ECORE_CONFIG_ERR_FAIL; - - if (!name) - name = file; - - *libr = NULL; - - if ((lib = dlopen(file, flag))) - { - void **funr, *fun; - char *b, *e; - size_t l; - int required = 1; - - va_start(ap, fmt); - while (*fmt) - { - switch (*fmt) - { - case '?': - required = 0; - fmt++; - break; - - case '!': - case '.': - required = 1; - fmt++; - break; - - case '\t': - case '\n': - case '\r': - case ';': - case ',': - case ' ': - fmt++; - break; - - default: - e = b = (char *)fmt; - while (*e && (strchr("?!.,; \t\n\r", *e) == NULL)) - e++; - - fmt = e; - if (e == b) - ret = ECORE_CONFIG_ERR_NODATA; - else if ((l = (e - b)) >= MAX_SYM_LEN) - ret = ECORE_CONFIG_ERR_OOM; - else - { - memcpy(buf, b, l); - buf[l] = '\0'; - funr = va_arg(ap, void **); - - if (!(fun = dlsym(lib, buf))) - { - if ((ret = - required ? ECORE_CONFIG_ERR_NOTFOUND : - ECORE_CONFIG_ERR_PARTIAL) == - ECORE_CONFIG_ERR_NOTFOUND) - E(1, - "DLMulti: library/plugin/engine \"%s\" (\"%s\") did not contain required function \"%s\"...\n", - name, file, buf); - } - E(2, "DLMulti: %p => %p %c\"%s\"\n", fun, funr, - required ? '!' : '?', buf); - if (funr) - *funr = fun; - } - required = 1; - } - } - - va_end(ap); - - if ((ret == ECORE_CONFIG_ERR_SUCC) || (ret == ECORE_CONFIG_ERR_PARTIAL)) - *libr = lib; - else - dlclose(lib); - } - else - ret = ECORE_CONFIG_ERR_NODATA; - - return ret; -} - -#if 0 /* Unused */ -/*****************************************************************************/ - -unsigned long -now(long delay) -{ - static struct timeval tv; - unsigned long r; - - gettimeofday(&tv, NULL); - r = tv.tv_sec * 1000 + (((float)tv.tv_usec) / 1000.0) + delay; - return r; -} -#endif - -/*****************************************************************************/ - -int -parse_line(char *in, char **o1, char **o2, char **o3, char **o4) -{ -#define PLMAX 16 - int c; - char *p = in; - char *r[PLMAX]; - - for (c = 0; c < PLMAX; c++) - r[c] = NULL; - - c = 0; - if (!in || !*in) - goto pl_end; - - do - { - while (isspace(*p)) - *(p++) = '\0'; - - if (!*p || (strchr("#;", *p) && (!p[1] || isspace(p[1])))) - *p = '\0'; /* it ends HERE */ - else - { - if (*p == '\"') - { - r[c++] = ++p; - while (*p && (*p != '\"')) - { - if ((*p == '\\') && p[1]) - p += 2; - else - p++; - } - if (*p) - *(p++) = '\0'; - } - else - { - r[c++] = p; - while (*p && !isspace(*p)) - p++; - } - } - } - while (*p); - - pl_end: - if (o1) - *o1 = r[0]; - if (o2) - *o2 = r[1]; - if (o3) - *o3 = r[2]; - if (o4) - *o4 = r[3]; - - return c; -} - -/*****************************************************************************/ - -/*char *unit_size(char *size) { - gchar *unit="byte"; - long s; - - if((s=atol(size))&&(s>=1024)) { - if((s>(1024*1024*1024))) { - unit="GB"; - s=(long)(s/(1024*1024)); } - else if((s>(1024*1024))) { - unit="MB"; - s=(long)(s/1024); } - else - unit="KB"; - - if((s/1024)>31) - sprintf(size,"%ld %s",(long)(s/1024),unit); - else - sprintf(size,"%.1f %s",((float)s)/1024,unit); } - else - sprintf(size,"%ld %s",s,unit); - - return size; } - -*/ - -/*****************************************************************************/ - -void -qsrt(void *a[], void *data, int lo, int hi, - int (*compare) (const void *, const void *, const void *)) -{ - int h, l; - void *p, *t; - - if (lo < hi) - { - l = lo; - h = hi; - p = a[hi]; - - do - { - while ((l < h) && (compare(data, a[l], p) <= 0)) - l = l + 1; - while ((h > l) && (compare(data, a[h], p) >= 0)) - h = h - 1; - if (l < h) - { - t = a[l]; - a[l] = a[h]; - a[h] = t; - } - } - while (l < h); - - t = a[l]; - a[l] = a[hi]; - a[hi] = t; - - qsrt(a, data, lo, l - 1, compare); - qsrt(a, data, l + 1, hi, compare); - } -} - -/*****************************************************************************/ -/* TIMERS */ -/**********/ - -#ifdef HAVE_GLIB2 - -unsigned long -timeout_add(uint f, int (*fun) (void *), void *data) -{ - return g_timeout_add((guint) f, (GSourceFunc) fun, (gpointer) data); -} - -int -timeout_remove(unsigned long handle) -{ - return g_source_remove(handle) ? ECORE_CONFIG_ERR_SUCC : - ECORE_CONFIG_ERR_FAIL; -} - -#else - -unsigned long -timeout_add(uint f __UNUSED__, int (*fun) (void *) __UNUSED__, void *data __UNUSED__) -{ - return 0; -} - -int -timeout_remove(unsigned long handle __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -#endif /* HAVE_GLIB2 */ - -/*****************************************************************************/ -/* HASHES */ -/**********/ - -int -eslist_free(eslist ** l) -{ - eslist *e, *f; - - if (!l) - return ECORE_CONFIG_ERR_NODATA; - for (e = *l; e; e = f) - { - f = e->next; - free(e); - } - *l = NULL; - return ECORE_CONFIG_ERR_SUCC; -} - -int -eslist_next(eslist ** e) -{ - if (!e || !*e) - return ECORE_CONFIG_ERR_NODATA; - *e = (*e)->next; - return ECORE_CONFIG_ERR_SUCC; -} - -void * -eslist_payload(eslist ** e) -{ - return (!e || !*e) ? NULL : (*e)->payload; -} - -int -eslist_prepend(eslist ** e, void *p) -{ - eslist *f; - - if (!e) - return ECORE_CONFIG_ERR_NODATA; - - if (!(f = malloc(sizeof(eslist)))) - return ECORE_CONFIG_ERR_OOM; - - f->payload = p; - f->next = *e; - - *e = f; - - return ECORE_CONFIG_ERR_SUCC; -} - -int -eslist_append(eslist ** e, void *p) -{ - eslist *f; - - if (!e) - return ECORE_CONFIG_ERR_NODATA; - - if (!(f = malloc(sizeof(eslist)))) - return ECORE_CONFIG_ERR_OOM; - - f->payload = p; - f->next = NULL; - - if (!*e) - *e = f; - else - { - eslist *g = *e; - - while (g->next) - g = g->next; - g->next = f; - } - - return ECORE_CONFIG_ERR_SUCC; -} - -/*****************************************************************************/ -/* HASHES */ -/**********/ - -#ifdef HAVE_GLIB2 - -void * -hash_table_new(void (*freekey), void (*freeval)) -{ - return g_hash_table_new_full(g_str_hash, g_str_equal, freekey, freeval); -} - -void * -hash_table_fetch(void *hashtable, char *key) -{ - return g_hash_table_lookup(hashtable, key); -} - -int -hash_table_insert(void *hashtable, char *key, void *value) -{ - g_hash_table_insert(hashtable, key, value); - return ECORE_CONFIG_ERR_SUCC; -} - -int -hash_table_replace(void *hashtable, char *key, void *value) -{ - g_hash_table_replace(hashtable, key, value); - return ECORE_CONFIG_ERR_SUCC; -} - -int -hash_table_remove(void *hashtable, char *key) -{ - g_hash_table_remove(hashtable, key); - return ECORE_CONFIG_ERR_SUCC; -} - -int -hash_table_dst(void *hashtable) -{ - g_hash_table_destroy(hashtable); - return ECORE_CONFIG_ERR_SUCC; -} - -int -hash_table_walk(void *hashtable, hash_walker fun, void *data) -{ - g_hash_table_foreach(hashtable, (GHFunc) fun, data); - return ECORE_CONFIG_ERR_SUCC; -} - -#else - -void * -hash_table_new(void (*freekey) __UNUSED__, void (*freeval) __UNUSED__) -{ - return NULL; -} - -void * -hash_table_fetch(void *hashtable __UNUSED__, char *key __UNUSED__) -{ - return NULL; -} - -int -hash_table_insert(void *hashtable __UNUSED__, char *key __UNUSED__, void *value __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -int -hash_table_replace(void *hashtable __UNUSED__, char *key __UNUSED__, void *value __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -int -hash_table_remove(void *hashtable __UNUSED__, char *key __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -int -hash_table_dst(void *hashtable __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -int -hash_table_walk(void *hashtable __UNUSED__, hash_walker fun __UNUSED__, void *data __UNUSED__) -{ - return ECORE_CONFIG_ERR_NOTSUPP; -} - -#endif /* HAVE_GLIB2 */ - /*****************************************************************************/ /* STRINGS */ /***********/ @@ -503,18 +31,6 @@ return e; } -estring * -estring_dst(estring * e) -{ - if (e) - { - if (e->str) - free(e->str); - free(e); - } - return NULL; -} - char * estring_disown(estring * e) { @@ -528,254 +44,72 @@ return NULL; } -char * -estring_free(estring * e, int release_payload) -{ /* glib compat */ - if (release_payload) - { - estring_dst(e); - return NULL; - } - return estring_disown(e); -} - -int -estring_truncate(estring * e, int size) -{ - if (!e || (size < 0)) - return ECORE_CONFIG_ERR_FAIL; - if (e->used <= size) - return e->used; - e->str[size] = '\0'; - e->used = size; - return size; -} - -int -estring_printf(estring * e, const char *fmt, ...) -{ - int need; - va_list ap; - char *p; - - if (!e) - return ECORE_CONFIG_ERR_FAIL; - - if (!(e->str)) - { - if (!(e->str = (char *)malloc(e->alloc = 512))) - return ECORE_CONFIG_ERR_OOM; - } - - retry: - va_start(ap, fmt); - need = vsnprintf(e->str, e->alloc, fmt, ap); - va_end(ap); - - if ((need >= e->alloc) || (need < 0)) - { - if (need < 0) - need = 2 * e->alloc; - else - need++; - if (!(p = (char *)realloc(e->str, need))) - { - free(e->str); - e->alloc = e->used = 0; - return ECORE_CONFIG_ERR_OOM; - } - e->alloc = need; - e->str = p; - goto retry; - } - - return e->used = need; -} - int estring_appendf(estring * e, const char *fmt, ...) { - int need; - va_list ap; - char *p; + va_list ap; + size_t need; + char *p; if (!e) return ECORE_CONFIG_ERR_FAIL; if (!e->str) - { - e->used = e->alloc = 0; - if (!(e->str = (char *)malloc(e->alloc = 512))) - return ECORE_CONFIG_ERR_OOM; - } + e->used = e->alloc = 0; - retry: va_start(ap, fmt); - need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap); + need = vsnprintf(NULL, 0, fmt, ap); va_end(ap); - - if ((need >= (e->alloc - e->used)) || (need < 0)) + if(need >= (e->alloc - e->used)) { - if (need < 0) - need = 2 * e->alloc; - else - need++; - need += e->used; - need += (CHUNKLEN - (need % CHUNKLEN)); - - if (!(p = (char *)realloc(e->str, need))) - { + if( !(p = (char *)realloc( e->str, need + e->used + 1 )) ) + { free(e->str); e->alloc = e->used = 0; return ECORE_CONFIG_ERR_OOM; - } - e->alloc = need; + } + e->alloc += need + 1; e->str = p; - goto retry; } - return e->used += need; -} - -int -esprintf(char **result, const char *fmt, ...) -{ - int need, have; - va_list ap; - char *n; - - if (!result) - return ECORE_CONFIG_ERR_FAIL; - - if (!(n = (char *)malloc(have = 512))) - return ECORE_CONFIG_ERR_OOM; - - retry: va_start(ap, fmt); - need = vsnprintf(n, have, fmt, ap); + vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap); va_end(ap); - if ((need >= have) || (need < 0)) - { - char *p; - - if (need < 0) - need = 2 * have; - else - need++; - if (!(p = (char *)realloc(n, need))) - { - free(n); - return ECORE_CONFIG_ERR_OOM; - } - have = need; - n = p; - goto retry; - } - - if (*result) - free(*result); - *result = n; - - return need; + return e->used; } -#if 0 int -ejoin(char **result, char *delim, ...) +esprintf(char **result, const char *fmt, ...) { - int dl, cl, ret = ECORE_CONFIG_ERR_SUCC; - va_list ap; - char *e, *n; + va_list ap; + size_t need; + char *n; if (!result) return ECORE_CONFIG_ERR_FAIL; - if (!delim) - delim = ""; - dl = strlen(delim); - - va_start(ap, delim); - cl = -dl; - while ((e = va_arg(ap, char *))) - cl += strlen(e) + dl; + va_start(ap, fmt); + need = vsnprintf(NULL, 0, fmt, ap) + 1; va_end(ap); + n = malloc(need + 1); - if (cl <= 0) - { - if (!(n = strdup(""))) - ret = ECORE_CONFIG_ERR_OOM; - } - else if (!(n = malloc(cl + 1))) - ret = ECORE_CONFIG_ERR_OOM; - else + if (n) { - char *p = n; - - va_start(ap, delim); - while ((e = va_arg(ap, char *))) - { - if (dl && (p != n)) - { - strcpy(p, delim); - p += dl; - } - strcpy(p, e); - p += strlen(p); - } + va_start(ap, fmt); + need = vsnprintf(n, need, fmt, ap); va_end(ap); - } - if (*result) - free(*result); - *result = n; + n[need] = 0; - return ret; -} + if(*result) + free(result); + *result = n; -int -ecat(char **result, ...) -{ - int cl, ret = ECORE_CONFIG_ERR_SUCC; - va_list ap; - char *e, *n; - - if (!result) - return ECORE_CONFIG_ERR_FAIL; - - va_start(ap, result); - cl = 0; - while ((e = va_arg(ap, char *))) - cl += strlen(e); - - va_end(ap); - - if (cl <= 0) - { - if (!(n = strdup(""))) - ret = ECORE_CONFIG_ERR_OOM; + return need; } - else if (!(n = malloc(cl + 1))) - ret = ECORE_CONFIG_ERR_OOM; - else - { - char *p = n; - - va_start(ap, result); - while ((e = va_arg(ap, char *))) - { - strcpy(p, e); - p += strlen(p); - } - va_end(ap); - } - - if (*result) - free(*result); - *result = n; - return ret; + return ECORE_CONFIG_ERR_OOM; } -#endif /*****************************************************************************/ =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_util.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ecore_config_util.h 2 Mar 2005 07:06:34 -0000 1.2 +++ ecore_config_util.h 30 Dec 2005 20:10:01 -0000 1.3 @@ -7,57 +7,8 @@ int alloc, used; } estring; -typedef struct _eslist -{ - void *payload; - struct _eslist *next; -} eslist; - -int parse_line(char *, char **, char **, char **, char **); -char *unit_size(char *size); - -/*unsigned long now(long delay);*/ -void qsrt(void *a[], void *data, int lo, int hi, - int (*compare) (const void *, const void *, - const void *)); -int dlmulti(const char *name, const char *file, int flag, void **libr, - const char *fmt, ...); - -typedef void (*hash_walker) (char *key, void *value, void *data); - -void *hash_table_new(void (*freekey), void (*freeval)); -void *hash_table_fetch(void *hashtable, char *key); -int hash_table_insert(void *hashtable, char *key, void *value); -int hash_table_replace(void *hashtable, char *key, void *value); -int hash_table_remove(void *hashtable, char *key); -int hash_table_dst(void *hashtable); -int hash_table_walk(void *hashtable, hash_walker fun, - void *data); - -int eslist_free(eslist **); -int eslist_next(eslist **); - -#define ESLIST_NEXT(e) (e=e->next) -void *eslist_payload(eslist **); - -#define ESLIST_PAYLOAD(e) ((e)->payload) -int eslist_prepend(eslist **, void *); -int eslist_append(eslist **, void *); - estring *estring_new(int size); -estring *estring_dst(estring * e); char *estring_disown(estring * e); -char *estring_free(estring * e, int release_payload); /* glib compat */ -int estring_printf(estring * e, const char *fmt, ...); int estring_appendf(estring * e, const char *fmt, ...); -int estring_truncate(estring * e, int size); - -#define ESTRING_GET_CSTRING(a) ((a)->str) int esprintf(char **result, const char *fmt, ...); -int ejoin(char **result, const char *delim, ...); -int ecat(char **result, ...); - -unsigned long timeout_add(unsigned int f, int (*fun) (void *), - void *data); -int timeout_remove(unsigned long handle); ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs