diff options
author | Rikky <Rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-07-03 21:41:05 +0000 |
---|---|---|
committer | Rikky <Rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2010-07-03 21:41:05 +0000 |
commit | 490dbcc240fae761a39f78f21f143dd081b77a03 (patch) | |
tree | 0c03ff1e3c828133ba1eeaf03169236f99208083 | |
parent | d80e27e3b98bb513beb2124e5e57701c9b4cf3bb (diff) | |
download | navit-490dbcc240fae761a39f78f21f143dd081b77a03.tar.gz |
Add:support/glib:Added g_slice* support to internal glib with virtual memory quirks for WinCE. Fix for some crashs while calculating long routes.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3472 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | navit/start_real.c | 8 | ||||
-rw-r--r-- | navit/support/glib/fake.c | 96 | ||||
-rw-r--r-- | navit/support/glib/fake.h | 40 | ||||
-rw-r--r-- | navit/support/glib/gatomic.c | 206 | ||||
-rw-r--r-- | navit/support/glib/glib.h | 3 | ||||
-rw-r--r-- | navit/support/glib/glibconfig.h | 2 | ||||
-rw-r--r-- | navit/support/glib/gslice.c | 47 | ||||
-rw-r--r-- | navit/support/glib/gstrfuncs.c | 359 | ||||
-rw-r--r-- | navit/support/glib/gutf8.c | 383 | ||||
-rw-r--r-- | navit/support/glib/gutils.c | 501 | ||||
-rwxr-xr-x | navit/support/glib/gutils.h | 490 |
11 files changed, 1396 insertions, 739 deletions
diff --git a/navit/start_real.c b/navit/start_real.c index b755dab6e..b6391a3fa 100644 --- a/navit/start_real.c +++ b/navit/start_real.c @@ -45,7 +45,7 @@ #include <winbase.h> #endif -char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT; +char *version=PACKAGE_VERSION" "SVN_VERSION""NAVIT_VARIANT; int main_argc; char **main_argv; @@ -71,12 +71,14 @@ int main_real(int argc, char **argv) #ifdef HAVE_GLIB event_glib_init(); +#else + _g_slice_thread_init_nomessage(); #endif atom_init(); main_init(argv[0]); main_init_nls(); debug_init(argv[0]); - + cp = getenv("NAVIT_LOGFILE"); if (cp) debug_set_logfile(cp); @@ -105,7 +107,7 @@ int main_real(int argc, char **argv) exit(0); break; case 'v': - printf("%s %s\n", "navit", version); + printf("%s %s\n", "navit", version); exit(0); break; case 'c': diff --git a/navit/support/glib/fake.c b/navit/support/glib/fake.c index 7da37182c..60b7b8e8a 100644 --- a/navit/support/glib/fake.c +++ b/navit/support/glib/fake.c @@ -1,5 +1,101 @@ +#include "fake.h" + +#include <stdlib.h> /* posix_memalign() */ +#include <string.h> +#include <errno.h> +#include "gmem.h" /* gslice.h */ +#include "gthreadprivate.h" +#include "glib.h" +#include "galias.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> /* sysconf() */ +#endif +#ifdef G_OS_WIN32 +#include <windows.h> +#include <process.h> +#endif + +#include <stdio.h> /* fputs/fprintf */ + char * g_convert(char *in) { return g_strdup(in); } + + +#if USE_POSIX_THREADS +pthread_mutex_t* g_mutex_new_navit(void) +{ + pthread_mutex_t *ret = malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(ret, NULL); + return ret; +} +#else +#if HAVE_API_WIN32_BASE +CRITICAL_SECTION* g_mutex_new_navit(void) +{ + CRITICAL_SECTION *ret = malloc(sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(ret); + return ret; +} +#endif +#endif + +int g_private_new_navit () +{ + int dwTlsIndex; +#if HAVE_API_WIN32_BASE + + if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) + printf(0, "TlsAlloc failed"); + printf("return dwTlsIndex = 0x%x\n",dwTlsIndex); +#else +#warning g_private implementation is missing +#endif + return dwTlsIndex; +} + +/** + * g_get_current_time: + * @result: #GTimeVal structure in which to store current time. + * + * Equivalent to the UNIX gettimeofday() function, but portable. + **/ +void +g_get_current_time (GTimeVal *result) +{ +#ifndef G_OS_WIN32 + struct timeval r; + + g_return_if_fail (result != NULL); + + /*this is required on alpha, there the timeval structs are int's + not longs and a cast only would fail horribly*/ + gettimeofday (&r, NULL); + result->tv_sec = r.tv_sec; + result->tv_usec = r.tv_usec; +#else + FILETIME ft; + guint64 time64; + + g_return_if_fail (result != NULL); + +#if defined(HAVE_API_WIN32_CE) + GetCurrentFT(&ft); +#else + GetSystemTimeAsFileTime (&ft); +#endif + memmove (&time64, &ft, sizeof (FILETIME)); + + /* Convert from 100s of nanoseconds since 1601-01-01 + * to Unix epoch. Yes, this is Y2038 unsafe. + */ + time64 -= G_GINT64_CONSTANT (116444736000000000); + time64 /= 10; + + result->tv_sec = time64 / 1000000; + result->tv_usec = time64 % 1000000; +#endif +} + diff --git a/navit/support/glib/fake.h b/navit/support/glib/fake.h index 6fc9d55f7..798bcf86d 100644 --- a/navit/support/glib/fake.h +++ b/navit/support/glib/fake.h @@ -1,6 +1,36 @@ +#include "config.h" +#if USE_POSIX_THREADS +#include <pthread.h> +#endif +#include "debug.h" + #define g_return_if_fail -#define GMutex void -#define GPrivate void -#define g_mutex_new() NULL -#define g_mutex_lock(x) -#define g_mutex_unlock(x) + +#if USE_POSIX_THREADS +# define GMutex pthread_mutex_t +# define g_mutex_new g_mutex_new_navit +# define g_mutex_lock(lock) (pthread_mutex_lock(lock)) +# define g_mutex_unlock(lock) (pthread_mutex_unlock(lock)) +# define g_mutex_trylock(lock) (pthread_mutex_trylock(lock)) +#else +# if HAVE_API_WIN32_BASE +# define GMutex CRITICAL_SECTION +# define g_mutex_new g_mutex_new_navit +# define g_mutex_lock(lock) (EnterCriticalSection(lock)) +# define g_mutex_unlock(lock) (LeaveCriticalSection(lock)) +# define g_mutex_trylock(lock) (TryEnterCriticalSection(lock)) +# endif +#endif + +#define GPrivate int +#define g_private_new(xd) g_private_new_navit() +#define g_private_get(xd) TlsGetValue(xd) +#define g_private_set(a,b) TlsSetValue(a, b) + +#define G_LOCK_DEFINE_STATIC(name) void +#define G_LOCK(name) void //g_mutex_lock (&G_LOCK_NAME (name)) +#define G_UNLOCK(name) void //g_mutex_unlock (&G_LOCK_NAME (name)) + +#define g_thread_supported() TRUE + +#define g_assert(expr) dbg_assert (expr) diff --git a/navit/support/glib/gatomic.c b/navit/support/glib/gatomic.c index b75a8c5ea..c881ec68e 100644 --- a/navit/support/glib/gatomic.c +++ b/navit/support/glib/gatomic.c @@ -31,41 +31,49 @@ #include "gthreadprivate.h" #include "galias.h" +# if HAVE_API_WIN32_BASE +#include <windows.h> +#endif + +#if USE_POSIX_THREADS +#include <pthread.h> +#endif + #if defined (__GNUC__) # if defined (G_ATOMIC_I486) -/* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h +/* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h */ gint -g_atomic_int_exchange_and_add (volatile gint *atomic, +g_atomic_int_exchange_and_add (volatile gint *atomic, gint val) { gint result; __asm__ __volatile__ ("lock; xaddl %0,%1" - : "=r" (result), "=m" (*atomic) + : "=r" (result), "=m" (*atomic) : "0" (val), "m" (*atomic)); return result; } - + void -g_atomic_int_add (volatile gint *atomic, +g_atomic_int_add (volatile gint *atomic, gint val) { __asm__ __volatile__ ("lock; addl %1,%0" - : "=m" (*atomic) + : "=m" (*atomic) : "ir" (val), "m" (*atomic)); } gboolean -g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, +g_atomic_int_compare_and_exchange (volatile gint *atomic, + gint oldval, gint newval) { gint result; - + __asm__ __volatile__ ("lock; cmpxchgl %2, %1" : "=a" (result), "=m" (*atomic) - : "r" (newval), "m" (*atomic), "0" (oldval)); + : "r" (newval), "m" (*atomic), "0" (oldval)); return result == oldval; } @@ -75,15 +83,15 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, * arguments and calling the former function */ gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; - + __asm__ __volatile__ ("lock; cmpxchgl %2, %1" : "=a" (result), "=m" (*atomic) - : "r" (newval), "m" (*atomic), "0" (oldval)); + : "r" (newval), "m" (*atomic), "0" (oldval)); return result == oldval; } @@ -103,8 +111,8 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, # if GLIB_SIZEOF_VOID_P == 4 /* 32-bit system */ gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; @@ -116,8 +124,8 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, } # elif GLIB_SIZEOF_VOID_P == 8 /* 64-bit system */ gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; @@ -162,8 +170,8 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, }) # if GLIB_SIZEOF_VOID_P == 4 /* 32-bit system */ gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gint result; @@ -178,7 +186,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, " beq %1,1b\n" " mb\n" "2:" - : "=&r" (prev), + : "=&r" (prev), "=&r" (result) : "m" (*atomic), "Ir" (oldval), @@ -188,8 +196,8 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, } # elif GLIB_SIZEOF_VOID_P == 8 /* 64-bit system */ gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gint result; @@ -204,7 +212,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, " beq %1,1b\n" " mb\n" "2:" - : "=&r" (prev), + : "=&r" (prev), "=&r" (result) : "m" (*atomic), "Ir" (oldval), @@ -217,7 +225,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, # endif /* GLIB_SIZEOF_VOID_P */ # define G_ATOMIC_MEMORY_BARRIER __asm__ ("mb" : : : "memory") # elif defined (G_ATOMIC_X86_64) -/* Adapted from CVS version 1.9 of glibc's sysdeps/x86_64/bits/atomic.h +/* Adapted from CVS version 1.9 of glibc's sysdeps/x86_64/bits/atomic.h */ gint g_atomic_int_exchange_and_add (volatile gint *atomic, @@ -226,58 +234,58 @@ g_atomic_int_exchange_and_add (volatile gint *atomic, gint result; __asm__ __volatile__ ("lock; xaddl %0,%1" - : "=r" (result), "=m" (*atomic) + : "=r" (result), "=m" (*atomic) : "0" (val), "m" (*atomic)); return result; } - + void -g_atomic_int_add (volatile gint *atomic, +g_atomic_int_add (volatile gint *atomic, gint val) { __asm__ __volatile__ ("lock; addl %1,%0" - : "=m" (*atomic) + : "=m" (*atomic) : "ir" (val), "m" (*atomic)); } gboolean -g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, +g_atomic_int_compare_and_exchange (volatile gint *atomic, + gint oldval, gint newval) { gint result; - + __asm__ __volatile__ ("lock; cmpxchgl %2, %1" : "=a" (result), "=m" (*atomic) - : "r" (newval), "m" (*atomic), "0" (oldval)); + : "r" (newval), "m" (*atomic), "0" (oldval)); return result == oldval; } gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; - + __asm__ __volatile__ ("lock; cmpxchgq %q2, %1" : "=a" (result), "=m" (*atomic) - : "r" (newval), "m" (*atomic), "0" (oldval)); + : "r" (newval), "m" (*atomic), "0" (oldval)); return result == oldval; } # elif defined (G_ATOMIC_POWERPC) -/* Adapted from CVS version 1.16 of glibc's sysdeps/powerpc/bits/atomic.h - * and CVS version 1.4 of glibc's sysdeps/powerpc/powerpc32/bits/atomic.h - * and CVS version 1.7 of glibc's sysdeps/powerpc/powerpc64/bits/atomic.h +/* Adapted from CVS version 1.16 of glibc's sysdeps/powerpc/bits/atomic.h + * and CVS version 1.4 of glibc's sysdeps/powerpc/powerpc32/bits/atomic.h + * and CVS version 1.7 of glibc's sysdeps/powerpc/powerpc64/bits/atomic.h */ # ifdef __OPTIMIZE__ /* Non-optimizing compile bails on the following two asm statements * for reasons unknown to the author */ gint -g_atomic_int_exchange_and_add (volatile gint *atomic, +g_atomic_int_exchange_and_add (volatile gint *atomic, gint val) { gint result, temp; @@ -300,13 +308,13 @@ g_atomic_int_exchange_and_add (volatile gint *atomic, #endif return result; } - + /* The same as above, to save a function call repeated here */ void -g_atomic_int_add (volatile gint *atomic, +g_atomic_int_add (volatile gint *atomic, gint val) { - gint result, temp; + gint result, temp; #if ASM_NUMERIC_LABELS __asm__ __volatile__ ("1: lwarx %0,0,%3\n" " add %1,%0,%4\n" @@ -327,7 +335,7 @@ g_atomic_int_add (volatile gint *atomic, } # else /* !__OPTIMIZE__ */ gint -g_atomic_int_exchange_and_add (volatile gint *atomic, +g_atomic_int_exchange_and_add (volatile gint *atomic, gint val) { gint result; @@ -337,7 +345,7 @@ g_atomic_int_exchange_and_add (volatile gint *atomic, return result; } - + void g_atomic_int_add (volatile gint *atomic, gint val) @@ -351,8 +359,8 @@ g_atomic_int_add (volatile gint *atomic, # if GLIB_SIZEOF_VOID_P == 4 /* 32-bit system */ gboolean -g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, +g_atomic_int_compare_and_exchange (volatile gint *atomic, + gint oldval, gint newval) { gint result; @@ -366,7 +374,7 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, "2: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #else __asm__ __volatile__ ("sync\n" ".L1icae%=: lwarx %0,0,%1\n" @@ -377,14 +385,14 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, ".L2icae%=: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #endif return result == 0; } gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; @@ -398,7 +406,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, "2: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #else __asm__ __volatile__ ("sync\n" ".L1pcae%=: lwarx %0,0,%1\n" @@ -409,14 +417,14 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, ".L2pcae%=: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #endif return result == 0; } # elif GLIB_SIZEOF_VOID_P == 8 /* 64-bit system */ gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, + gint oldval, gint newval) { gpointer result; @@ -431,7 +439,7 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, "2: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #else __asm__ __volatile__ ("sync\n" ".L1icae%=: lwarx %0,0,%1\n" @@ -443,14 +451,14 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, ".L2icae%=: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #endif return result == 0; } gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gpointer result; @@ -464,7 +472,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, "2: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #else __asm__ __volatile__ ("sync\n" ".L1pcae%=: ldarx %0,0,%1\n" @@ -475,7 +483,7 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, ".L2pcae%=: isync" : "=&r" (result) : "b" (atomic), "r" (oldval), "r" (newval) - : "cr0", "memory"); + : "cr0", "memory"); #endif return result == 0; } @@ -494,9 +502,9 @@ g_atomic_int_exchange_and_add (volatile gint *atomic, { return __sync_fetch_and_add (atomic, val); } - + void -g_atomic_int_add (volatile gint *atomic, +g_atomic_int_add (volatile gint *atomic, gint val) { __sync_fetch_and_add (atomic, val); @@ -504,7 +512,7 @@ g_atomic_int_add (volatile gint *atomic, gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, + gint oldval, gint newval) { return __sync_bool_compare_and_swap (atomic, oldval, newval); @@ -512,10 +520,10 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, + gpointer oldval, gpointer newval) { - return __sync_bool_compare_and_swap ((long *)atomic, + return __sync_bool_compare_and_swap ((long *)atomic, (long)oldval, (long)newval); } @@ -590,12 +598,12 @@ static void atomic_spin_unlock (void) } gint -g_atomic_int_exchange_and_add (volatile gint *atomic, +g_atomic_int_exchange_and_add (volatile gint *atomic, gint val) { gint result; - - atomic_spin_lock(); + + atomic_spin_lock(); result = *atomic; *atomic += val; atomic_spin_unlock(); @@ -613,8 +621,8 @@ g_atomic_int_add (volatile gint *atomic, } gboolean -g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, +g_atomic_int_compare_and_exchange (volatile gint *atomic, + gint oldval, gint newval) { gboolean result; @@ -633,12 +641,12 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, } gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gboolean result; - + atomic_spin_lock(); if (*atomic == oldval) { @@ -651,7 +659,9 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, return result; } -# else /* !G_ATOMIC_ARM */ +# elif defined(G_PLATFORM_WIN32) +# define DEFINE_WITH_WIN32_INTERLOCKED +# else # define DEFINE_WITH_MUTEXES # endif /* G_ATOMIC_IA64 */ #else /* !__GNUC__ */ @@ -681,30 +691,30 @@ g_atomic_int_exchange_and_add (volatile gint32 *atomic, return InterlockedExchangeAdd (atomic, val); } -void -g_atomic_int_add (volatile gint32 *atomic, +void +g_atomic_int_add (volatile gint32 *atomic, gint32 val) { InterlockedExchangeAdd (atomic, val); } -gboolean +gboolean g_atomic_int_compare_and_exchange (volatile gint32 *atomic, gint32 oldval, gint32 newval) { #ifndef HAVE_INTERLOCKED_COMPARE_EXCHANGE_POINTER - return (guint32) InterlockedCompareExchange ((PVOID*)atomic, - (PVOID)newval, + return (guint32) InterlockedCompareExchange ((PVOID*)atomic, + (PVOID)newval, (PVOID)oldval) == oldval; #else - return InterlockedCompareExchange (atomic, - newval, + return InterlockedCompareExchange (atomic, + newval, oldval) == oldval; #endif } -gboolean +gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, gpointer oldval, gpointer newval) @@ -723,14 +733,14 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, #ifdef DEFINE_WITH_MUTEXES /* We have to use the slow, but safe locking method */ -static GMutex *g_atomic_mutex; +static GMutex *g_atomic_mutex; gint -g_atomic_int_exchange_and_add (volatile gint *atomic, +g_atomic_int_exchange_and_add (volatile gint *atomic, gint val) { gint result; - + g_mutex_lock (g_atomic_mutex); result = *atomic; *atomic += val; @@ -750,12 +760,12 @@ g_atomic_int_add (volatile gint *atomic, } gboolean -g_atomic_int_compare_and_exchange (volatile gint *atomic, - gint oldval, +g_atomic_int_compare_and_exchange (volatile gint *atomic, + gint oldval, gint newval) { gboolean result; - + g_mutex_lock (g_atomic_mutex); if (*atomic == oldval) { @@ -770,12 +780,12 @@ g_atomic_int_compare_and_exchange (volatile gint *atomic, } gboolean -g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, - gpointer oldval, +g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, + gpointer oldval, gpointer newval) { gboolean result; - + g_mutex_lock (g_atomic_mutex); if (*atomic == oldval) { @@ -831,7 +841,7 @@ g_atomic_pointer_set (volatile gpointer *atomic, *atomic = newval; g_mutex_unlock (g_atomic_mutex); } -#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ +#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ #elif defined (G_ATOMIC_OP_MEMORY_BARRIER_NEEDED) gint g_atomic_int_get (volatile gint *atomic) @@ -845,7 +855,7 @@ g_atomic_int_set (volatile gint *atomic, gint newval) { *atomic = newval; - G_ATOMIC_MEMORY_BARRIER; + G_ATOMIC_MEMORY_BARRIER; } gpointer @@ -853,14 +863,14 @@ g_atomic_pointer_get (volatile gpointer *atomic) { G_ATOMIC_MEMORY_BARRIER; return *atomic; -} +} void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval) { *atomic = newval; - G_ATOMIC_MEMORY_BARRIER; + G_ATOMIC_MEMORY_BARRIER; } #endif /* DEFINE_WITH_MUTEXES || G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ @@ -884,7 +894,7 @@ g_atomic_int_exchange_and_add (volatile gint *atomic, return result; } - + void g_atomic_int_add (volatile gint *atomic, gint val) @@ -896,7 +906,7 @@ g_atomic_int_add (volatile gint *atomic, } #endif /* ATOMIC_INT_CMP_XCHG */ -void +void _g_atomic_thread_init (void) { #ifdef DEFINE_WITH_MUTEXES diff --git a/navit/support/glib/glib.h b/navit/support/glib/glib.h index 349019496..8f98575b3 100644 --- a/navit/support/glib/glib.h +++ b/navit/support/glib/glib.h @@ -28,12 +28,13 @@ #define __G_LIB_H__ #define __GLIB_H_INSIDE__ +#include <glib/gerror.h> #include <glib/fake.h> #include <glib/ghash.h> -#include <glib/gerror.h> #include <glib/gmessages.h> #include <glib/gstrfuncs.h> #include <glib/gunicode.h> +#include <glib/gutils.h> #undef __GLIB_H_INSIDE__ diff --git a/navit/support/glib/glibconfig.h b/navit/support/glib/glibconfig.h index ac1334872..de0d9dedf 100644 --- a/navit/support/glib/glibconfig.h +++ b/navit/support/glib/glibconfig.h @@ -190,10 +190,8 @@ typedef unsigned __int64 guintptr; #define G_GNUC_INTERNAL -#if NOT_NEEDED_FOR_NAVIT #define G_THREADS_ENABLED #define G_THREADS_IMPL_WIN32 -#endif /* NOT_NEEDED_FOR_NAVIT */ typedef struct _GMutex* GStaticMutex; #define G_STATIC_MUTEX_INIT NULL #define g_static_mutex_get_mutex(mutex) \ diff --git a/navit/support/glib/gslice.c b/navit/support/glib/gslice.c index d61420d25..29165bc5a 100644 --- a/navit/support/glib/gslice.c +++ b/navit/support/glib/gslice.c @@ -99,13 +99,12 @@ * [4] allocating ca. 8 chunks per block/page keeps a good balance between * external and internal fragmentation (<= 12.5%). [Bonwick94] */ -#if NOT_NEEDED_FOR_NAVIT /* --- macros and constants --- */ #define LARGEALIGNMENT (256) #define P2ALIGNMENT (2 * sizeof (gsize)) /* fits 2 pointers (assumed to be 2 * GLIB_SIZEOF_SIZE_T below) */ #define ALIGN(size, base) ((base) * (gsize) (((size) + (base) - 1) / (base))) -#define NATIVE_MALLOC_PADDING P2ALIGNMENT /* per-page padding left for native malloc(3) see [1] */ +#define NATIVE_MALLOC_PADDING 0 /* per-page padding left for native malloc(3) see [1] */ #define SLAB_INFO_SIZE P2ALIGN (sizeof (SlabInfo) + NATIVE_MALLOC_PADDING) #define MAX_MAGAZINE_SIZE (256) /* see [3] and allocator_get_magazine_threshold() for this */ #define MIN_MAGAZINE_SIZE (4) @@ -197,6 +196,8 @@ static int smc_notify_free (void *pointer, /* --- variables --- */ static GPrivate *private_thread_memory = NULL; static gsize sys_page_size = 0; +static gsize sys_valignment = ((32*1024*1024)); +static guint8 *virtual_mem = 0; static Allocator allocator[1] = { { 0, }, }; static SliceConfig slice_config = { FALSE, /* always_malloc */ @@ -276,6 +277,7 @@ static void slice_config_init (SliceConfig *config) { /* don't use g_malloc/g_message here */ +#if NOT_NEEDED_FOR_NAVIT gchar buffer[1024]; const gchar *val = _g_getenv_nomalloc ("G_SLICE", buffer); const GDebugKey keys[] = { @@ -283,11 +285,14 @@ slice_config_init (SliceConfig *config) { "debug-blocks", 1 << 1 }, }; gint flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys)); +#endif *config = slice_config; +#if NOT_NEEDED_FOR_NAVIT if (flags & (1 << 0)) /* always-malloc */ config->always_malloc = TRUE; if (flags & (1 << 1)) /* debug-blocks */ config->debug_blocks = TRUE; +#endif } static void @@ -302,9 +307,14 @@ g_slice_init_nomessage (void) SYSTEM_INFO system_info; GetSystemInfo (&system_info); sys_page_size = system_info.dwPageSize; + virtual_mem = VirtualAlloc (NULL, sys_valignment, MEM_RESERVE, PAGE_NOACCESS); +// sys_valignment = system_info.dwAllocationGranularity; + //sys_valignment = 2*1024*1024 + sys_page_size; + printf("SPAGE_SIZE: %d, SVALIGN:%d\n", sys_page_size, sys_valignment); } #else sys_page_size = sysconf (_SC_PAGESIZE); /* = sysconf (_SC_PAGE_SIZE); = getpagesize(); */ + sys_valignment = sys_page_size; #endif mem_assert (sys_page_size >= 2 * LARGEALIGNMENT); mem_assert ((sys_page_size & (sys_page_size - 1)) == 0); @@ -794,12 +804,10 @@ thread_memory_magazine2_free (ThreadMemory *tmem, mag->count++; } -#endif /* NOT_NEEDED_FOR_NAVIT */ /* --- API functions --- */ gpointer g_slice_alloc (gsize mem_size) { -#if NOT_NEEDED_FOR_NAVIT gsize chunk_size; gpointer mem; guint acat; @@ -828,9 +836,6 @@ g_slice_alloc (gsize mem_size) if (G_UNLIKELY (allocator->config.debug_blocks)) smc_notify_alloc (mem, mem_size); return mem; -#else /* NOT_NEEDED_FOR_NAVIT */ - return g_malloc(mem_size); -#endif /* NOT_NEEDED_FOR_NAVIT */ } gpointer @@ -856,7 +861,6 @@ void g_slice_free1 (gsize mem_size, gpointer mem_block) { -#if NOT_NEEDED_FOR_NAVIT gsize chunk_size = P2ALIGN (mem_size); guint acat = allocator_categorize (chunk_size); if (G_UNLIKELY (!mem_block)) @@ -892,9 +896,6 @@ g_slice_free1 (gsize mem_size, memset (mem_block, 0, mem_size); g_free (mem_block); } -#else /* NOT_NEEDED_FOR_NAVIT */ - g_free(mem_block); -#endif /* NOT_NEEDED_FOR_NAVIT */ } void @@ -903,7 +904,6 @@ g_slice_free_chain_with_offset (gsize mem_size, gsize next_offset) { gpointer slice = mem_chain; -#if NOT_NEEDED_FOR_NAVIT /* while the thread magazines and the magazine cache are implemented so that * they can easily be extended to allow for free lists containing more free * lists for the first level nodes, which would allow O(1) freeing in this @@ -960,24 +960,19 @@ g_slice_free_chain_with_offset (gsize mem_size, g_mutex_unlock (allocator->slab_mutex); } else /* delegate to system malloc */ -#else /* NOT_NEEDED_FOR_NAVIT */ while (slice) { guint8 *current = slice; slice = *(gpointer*) (current + next_offset); -#if NOT_NEEDED_FOR_NAVIT if (G_UNLIKELY (allocator->config.debug_blocks) && !smc_notify_free (current, mem_size)) abort(); -#endif /* NOT_NEEDED_FOR_NAVIT */ if (G_UNLIKELY (g_mem_gc_friendly)) memset (current, 0, mem_size); g_free (current); } -#endif /* NOT_NEEDED_FOR_NAVIT */ } -#if NOT_NEEDED_FOR_NAVIT /* --- single page allocator --- */ static void allocator_slab_stack_push (Allocator *allocator, @@ -1163,7 +1158,15 @@ allocator_memalign (gsize alignment, mem_assert (alignment == sys_page_size); mem_assert (memsize <= sys_page_size); if (!compat_valloc_trash) +#ifdef G_OS_WIN32 + { + aligned_memory = VirtualAlloc (virtual_mem, sys_page_size, MEM_COMMIT, PAGE_READWRITE); + virtual_mem += sys_page_size; + } + else +#else { + const guint n_pages = 16; guint8 *mem = malloc (n_pages * sys_page_size); err = errno; @@ -1177,7 +1180,8 @@ allocator_memalign (gsize alignment, g_trash_stack_push (&compat_valloc_trash, amem + i * sys_page_size); } } - aligned_memory = g_trash_stack_pop (&compat_valloc_trash); +#endif + aligned_memory = g_trash_stack_pop (&compat_valloc_trash); #endif if (!aligned_memory) errno = err; @@ -1205,7 +1209,7 @@ mem_error (const char *format, /* at least, put out "MEMORY-ERROR", in case we segfault during the rest of the function */ fputs ("\n***MEMORY-ERROR***: ", stderr); pname = g_get_prgname(); - fprintf (stderr, "%s[%ld]: GSlice: ", pname ? pname : "", (long)getpid()); + fprintf (stderr, "%s: GSlice: ", pname ? pname : ""); va_start (args, format); vfprintf (stderr, format, args); va_end (args); @@ -1463,13 +1467,13 @@ g_slice_debug_tree_statistics (void) else fprintf (stderr, "GSlice: MemChecker: root=NULL\n"); g_mutex_unlock (smc_tree_mutex); - + /* sample statistics (beast + GSLice + 24h scripted core & GUI activity): * PID %CPU %MEM VSZ RSS COMMAND * 8887 30.3 45.8 456068 414856 beast-0.7.1 empty.bse * $ cat /proc/8887/statm # total-program-size resident-set-size shared-pages text/code data/stack library dirty-pages * 114017 103714 2354 344 0 108676 0 - * $ cat /proc/8887/status + * $ cat /proc/8887/status * Name: beast-0.7.1 * VmSize: 456068 kB * VmLck: 0 kB @@ -1490,4 +1494,3 @@ g_slice_debug_tree_statistics (void) #define __G_SLICE_C__ #include "galiasdef.c" -#endif /* NOT_NEEDED_FOR_NAVIT */ diff --git a/navit/support/glib/gstrfuncs.c b/navit/support/glib/gstrfuncs.c index f063c1f5e..f2e1a1c26 100644 --- a/navit/support/glib/gstrfuncs.c +++ b/navit/support/glib/gstrfuncs.c @@ -21,7 +21,7 @@ * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GLib at ftp://ftp.gtk.org/pub/gtk/. + * GLib at ftp://ftp.gtk.org/pub/gtk/. */ /* @@ -125,18 +125,18 @@ g_memdup (gconstpointer mem, * If @str is less than @n bytes long the buffer is padded with nuls. * If @str is %NULL it returns %NULL. * The returned value should be freed when no longer needed. - * + * * <note><para> * To copy a number of characters from a UTF-8 encoded string, use * g_utf8_strncpy() instead. * </para></note> - * - * Returns: a newly-allocated buffer containing the first @n bytes - * of @str, nul-terminated + * + * Returns: a newly-allocated buffer containing the first @n bytes + * of @str, nul-terminated */ gchar* g_strndup (const gchar *str, - gsize n) + gsize n) { gchar *new_str; @@ -159,11 +159,11 @@ g_strndup (const gchar *str, * * Creates a new string @length bytes long filled with @fill_char. * The returned string should be freed when no longer needed. - * + * * Returns: a newly-allocated string filled the @fill_char */ gchar* -g_strnfill (gsize length, +g_strnfill (gsize length, gchar fill_char) { gchar *str; @@ -179,12 +179,12 @@ g_strnfill (gsize length, * g_stpcpy: * @dest: destination buffer. * @src: source string. - * + * * Copies a nul-terminated string into the dest buffer, include the * trailing nul, and return a pointer to the trailing nul byte. * This is useful for concatenating multiple strings together * without having to repeatedly scan for the end. - * + * * Return value: a pointer to trailing nul byte. **/ gchar * @@ -237,7 +237,7 @@ g_strdup_printf (const gchar *format, gchar* g_strconcat (const gchar *string1, ...) { - gsize l; + gsize l; va_list args; gchar *s; gchar *concat; @@ -277,7 +277,7 @@ g_strconcat (const gchar *string1, ...) * @nptr: the string to convert to a numeric value. * @endptr: if non-%NULL, it returns the character after * the last character used in the conversion. - * + * * Converts a string to a #gdouble value. * It calls the standard strtod() function to handle the conversion, but * if the string is not completely converted it attempts the conversion @@ -289,7 +289,7 @@ g_strconcat (const gchar *string1, ...) * should you use this. Make sure that you don't pass strings such as comma * separated lists of values, since the commas may be interpreted as a decimal * point in some locales, causing unexpected results. - * + * * Return value: the #gdouble value. **/ gdouble @@ -330,14 +330,14 @@ g_strtod (const gchar *nptr, * @nptr: the string to convert to a numeric value. * @endptr: if non-%NULL, it returns the character after * the last character used in the conversion. - * + * * Converts a string to a #gdouble value. * * This function behaves like the standard strtod() function - * does in the C locale. It does this without actually changing - * the current locale, since that would not be thread-safe. + * does in the C locale. It does this without actually changing + * the current locale, since that would not be thread-safe. * A limitation of the implementation is that this function - * will still accept localized versions of infinities and NANs. + * will still accept localized versions of infinities and NANs. * * This function is typically used when reading configuration * files or other non-user input that should be locale independent. @@ -351,7 +351,7 @@ g_strtod (const gchar *nptr, * is returned (according to the sign of the value), and %ERANGE is * stored in %errno. If the correct value would cause underflow, * zero is returned and %ERANGE is stored in %errno. - * + * * This function resets %errno before calling strtod() so that * you can reliably detect overflow and underflow. * @@ -386,37 +386,37 @@ g_ascii_strtod (const gchar *nptr, #if NOT_NEEDED_FOR_NAVIT g_assert (decimal_point_len != 0); #endif /* NOT_NEEDED_FOR_NAVIT */ - + decimal_point_pos = NULL; end = NULL; - if (decimal_point[0] != '.' || + if (decimal_point[0] != '.' || decimal_point[1] != 0) { p = nptr; /* Skip leading space */ while (g_ascii_isspace (*p)) p++; - + /* Skip leading optional sign */ if (*p == '+' || *p == '-') p++; - - if (p[0] == '0' && + + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { p += 2; /* HEX - find the (optional) decimal point */ - + while (g_ascii_isxdigit (*p)) p++; - + if (*p == '.') decimal_point_pos = p++; - + while (g_ascii_isxdigit (*p)) p++; - + if (*p == 'p' || *p == 'P') p++; if (*p == '+' || *p == '-') @@ -430,13 +430,13 @@ g_ascii_strtod (const gchar *nptr, { while (g_ascii_isdigit (*p)) p++; - + if (*p == '.') decimal_point_pos = p++; - + while (g_ascii_isdigit (*p)) p++; - + if (*p == 'e' || *p == 'E') p++; if (*p == '+' || *p == '-') @@ -455,7 +455,7 @@ g_ascii_strtod (const gchar *nptr, /* We need to convert the '.' to the locale specific decimal point */ copy = g_malloc (end - nptr + 1 + decimal_point_len); - + c = copy; memcpy (c, nptr, decimal_point_pos - nptr); c += decimal_point_pos - nptr; @@ -476,18 +476,18 @@ g_ascii_strtod (const gchar *nptr, else fail_pos = (char *)nptr + (fail_pos - copy); } - + g_free (copy); - + } else if (end) { char *copy; - + copy = g_malloc (end - (char *)nptr + 1); memcpy (copy, nptr, end - nptr); *(copy + (end - (char *)nptr)) = 0; - + errno = 0; val = strtod (copy, &fail_pos); strtod_errno = errno; @@ -496,7 +496,7 @@ g_ascii_strtod (const gchar *nptr, { fail_pos = (char *)nptr + (fail_pos - copy); } - + g_free (copy); } else @@ -522,8 +522,8 @@ g_ascii_strtod (const gchar *nptr, * @d: The #gdouble to convert * * Converts a #gdouble to a string, using the '.' as - * decimal point. - * + * decimal point. + * * This functions generates enough precision that converting * the string back using g_ascii_strtod() gives the same machine-number * (on machines with IEEE compatible 64bit doubles). It is @@ -545,14 +545,14 @@ g_ascii_dtostr (gchar *buffer, * @buffer: A buffer to place the resulting string in * @buf_len: The length of the buffer. * @format: The printf()-style format to use for the - * code to use for converting. + * code to use for converting. * @d: The #gdouble to convert * * Converts a #gdouble to a string, using the '.' as * decimal point. To format the number you pass in * a printf()-style format string. Allowed conversion - * specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'. - * + * specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'. + * * If you just want to want to serialize the value into a * string, use g_ascii_dtostr(). * @@ -574,9 +574,9 @@ g_ascii_formatd (gchar *buffer, g_return_val_if_fail (buffer != NULL, NULL); g_return_val_if_fail (format[0] == '%', NULL); g_return_val_if_fail (strpbrk (format + 1, "'l%") == NULL, NULL); - + format_char = format[strlen (format) - 1]; - + g_return_val_if_fail (format_char == 'e' || format_char == 'E' || format_char == 'f' || format_char == 'F' || format_char == 'g' || format_char == 'G', @@ -593,7 +593,7 @@ g_ascii_formatd (gchar *buffer, format_char == 'g' || format_char == 'G')) return NULL; - + _g_snprintf (buffer, buf_len, format, d); #ifdef HAVE_API_ANDROID @@ -627,7 +627,7 @@ g_ascii_formatd (gchar *buffer, { *p = '.'; p++; - if (decimal_point_len > 1) + if (decimal_point_len > 1) { rest_len = strlen (p + (decimal_point_len-1)); memmove (p, p + (decimal_point_len-1), rest_len); @@ -635,7 +635,7 @@ g_ascii_formatd (gchar *buffer, } } } - + return buffer; } @@ -664,9 +664,9 @@ g_parse_long_long (const gchar *nptr, guint64 ui64; const gchar *s, *save; guchar c; - + g_return_val_if_fail (nptr != NULL, 0); - + *negative = FALSE; if (base == 1 || base > 36) { @@ -675,16 +675,16 @@ g_parse_long_long (const gchar *nptr, *endptr = nptr; return 0; } - + save = s = nptr; - + /* Skip white space. */ while (ISSPACE (*s)) ++s; if (G_UNLIKELY (!*s)) goto noconv; - + /* Check for a sign. */ if (*s == '-') { @@ -693,7 +693,7 @@ g_parse_long_long (const gchar *nptr, } else if (*s == '+') ++s; - + /* Recognize number prefix and if BASE is zero, figure it out ourselves. */ if (*s == '0') { @@ -707,12 +707,12 @@ g_parse_long_long (const gchar *nptr, } else if (base == 0) base = 10; - + /* Save the pointer so we can check later if anything happened. */ save = s; cutoff = G_MAXUINT64 / base; cutlim = G_MAXUINT64 % base; - + overflow = FALSE; ui64 = 0; c = *s; @@ -735,16 +735,16 @@ g_parse_long_long (const gchar *nptr, ui64 += c; } } - + /* Check if anything actually happened. */ if (s == save) goto noconv; - + /* Store in ENDPTR the address of one character past the last character we converted. */ if (endptr) *endptr = s; - + if (G_UNLIKELY (overflow)) { errno = ERANGE; @@ -752,7 +752,7 @@ g_parse_long_long (const gchar *nptr, } return ui64; - + noconv: /* We must handle a special case here: the base is 0 or 16 and the first two characters are '0' and 'x', but the rest are no @@ -840,7 +840,7 @@ g_ascii_strtoull (const gchar *nptr, * * Since: 2.12 **/ -gint64 +gint64 g_ascii_strtoll (const gchar *nptr, gchar **endptr, guint base) @@ -892,7 +892,7 @@ g_strerror (gint errnum) */ GQuark msg_quark = g_quark_from_string (msg_utf8); g_free (msg_utf8); - + msg_utf8 = (gchar *) g_quark_to_string (msg_quark); errno = saved_errno; return msg_utf8; @@ -1346,7 +1346,7 @@ g_strsignal (gint signum) #ifdef HAVE_STRSIGNAL const char *msg_locale; - + #if defined(G_OS_BEOS) || defined(G_WITH_CYGWIN) extern const char *strsignal(int); #else @@ -1365,7 +1365,7 @@ extern const char *strsignal(int); */ GQuark msg_quark = g_quark_from_string (msg_utf8); g_free (msg_utf8); - + return g_quark_to_string (msg_quark); } } @@ -1487,7 +1487,7 @@ extern const char *strsignal(int); } _g_sprintf (msg, "unknown signal (%d)", signum); - + return msg; } #endif /* NOT_NEEDED_FOR_NAVIT */ @@ -1507,7 +1507,7 @@ g_strlcpy (gchar *dest, { g_return_val_if_fail (dest != NULL, 0); g_return_val_if_fail (src != NULL, 0); - + return strlcpy (dest, src, dest_size); } @@ -1518,7 +1518,7 @@ g_strlcat (gchar *dest, { g_return_val_if_fail (dest != NULL, 0); g_return_val_if_fail (src != NULL, 0); - + return strlcat (dest, src, dest_size); } @@ -1540,22 +1540,22 @@ g_strlcpy (gchar *dest, register gchar *d = dest; register const gchar *s = src; register gsize n = dest_size; - + g_return_val_if_fail (dest != NULL, 0); g_return_val_if_fail (src != NULL, 0); - + /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) do { register gchar c = *s++; - + *d++ = c; if (c == 0) break; } while (--n != 0); - + /* If not enough room in dest, add NUL and traverse rest of src */ if (n == 0) { @@ -1564,7 +1564,7 @@ g_strlcpy (gchar *dest, while (*s++) ; } - + return s - src - 1; /* count does not include NUL */ } @@ -1589,19 +1589,19 @@ g_strlcat (gchar *dest, register const gchar *s = src; register gsize bytes_left = dest_size; gsize dlength; /* Logically, MIN (strlen (d), dest_size) */ - + g_return_val_if_fail (dest != NULL, 0); g_return_val_if_fail (src != NULL, 0); - + /* Find the end of dst and adjust bytes left but don't go past end */ while (*d != 0 && bytes_left-- != 0) d++; dlength = d - dest; bytes_left = dest_size - dlength; - + if (bytes_left == 0) return dlength + strlen (s); - + while (*s != 0) { if (bytes_left != 1) @@ -1612,7 +1612,7 @@ g_strlcat (gchar *dest, s++; } *d = 0; - + return dlength + (s - src); /* count does not include NUL */ } #endif /* ! HAVE_STRLCPY */ @@ -1621,9 +1621,9 @@ g_strlcat (gchar *dest, * g_ascii_strdown: * @str: a string. * @len: length of @str in bytes, or -1 if @str is nul-terminated. - * + * * Converts all upper case ASCII letters to lower case ASCII letters. - * + * * Return value: a newly-allocated string, with all the upper case * characters in @str converted to lower case, with * semantics that exactly match g_ascii_tolower(). (Note @@ -1635,7 +1635,7 @@ g_ascii_strdown (const gchar *str, gssize len) { gchar *result, *s; - + g_return_val_if_fail (str != NULL, NULL); if (len < 0) @@ -1644,7 +1644,7 @@ g_ascii_strdown (const gchar *str, result = g_strndup (str, len); for (s = result; *s; s++) *s = g_ascii_tolower (*s); - + return result; } @@ -1652,9 +1652,9 @@ g_ascii_strdown (const gchar *str, * g_ascii_strup: * @str: a string. * @len: length of @str in bytes, or -1 if @str is nul-terminated. - * + * * Converts all lower case ASCII letters to upper case ASCII letters. - * + * * Return value: a newly allocated string, with all the lower case * characters in @str converted to upper case, with * semantics that exactly match g_ascii_toupper(). (Note @@ -1682,43 +1682,43 @@ g_ascii_strup (const gchar *str, /** * g_strdown: * @string: the string to convert. - * - * Converts a string to lower case. - * - * Return value: the string * - * Deprecated:2.2: This function is totally broken for the reasons discussed - * in the g_strncasecmp() docs - use g_ascii_strdown() or g_utf8_strdown() + * Converts a string to lower case. + * + * Return value: the string + * + * Deprecated:2.2: This function is totally broken for the reasons discussed + * in the g_strncasecmp() docs - use g_ascii_strdown() or g_utf8_strdown() * instead. **/ gchar* g_strdown (gchar *string) { register guchar *s; - + g_return_val_if_fail (string != NULL, NULL); - + s = (guchar *) string; - + while (*s) { if (isupper (*s)) *s = tolower (*s); s++; } - + return (gchar *) string; } /** * g_strup: * @string: the string to convert. - * - * Converts a string to upper case. - * + * + * Converts a string to upper case. + * * Return value: the string * - * Deprecated:2.2: This function is totally broken for the reasons discussed + * Deprecated:2.2: This function is totally broken for the reasons discussed * in the g_strncasecmp() docs - use g_ascii_strup() or g_utf8_strup() instead. **/ gchar* @@ -1770,7 +1770,7 @@ g_strreverse (gchar *string) /** * g_ascii_tolower: * @c: any character. - * + * * Convert a character to ASCII lower case. * * Unlike the standard C library tolower() function, this only @@ -1780,7 +1780,7 @@ g_strreverse (gchar *string) * library function, this takes and returns a char, not an int, so * don't call it on %EOF but no need to worry about casting to #guchar * before passing a possibly non-ASCII character in. - * + * * Return value: the result of converting @c to lower case. * If @c is not an ASCII upper case letter, * @c is returned unchanged. @@ -1794,7 +1794,7 @@ g_ascii_tolower (gchar c) /** * g_ascii_toupper: * @c: any character. - * + * * Convert a character to ASCII upper case. * * Unlike the standard C library toupper() function, this only @@ -1804,7 +1804,7 @@ g_ascii_tolower (gchar c) * library function, this takes and returns a char, not an int, so * don't call it on %EOF but no need to worry about casting to #guchar * before passing a possibly non-ASCII character in. - * + * * Return value: the result of converting @c to upper case. * If @c is not an ASCII lower case letter, * @c is returned unchanged. @@ -1861,7 +1861,7 @@ g_ascii_xdigit_value (gchar c) * g_ascii_strcasecmp: * @s1: string to compare with @s2. * @s2: string to compare with @s1. - * + * * Compare two strings, ignoring the case of ASCII characters. * * Unlike the BSD strcasecmp() function, this only recognizes standard @@ -1876,7 +1876,7 @@ g_ascii_xdigit_value (gchar c) * characters include all ASCII letters. If you compare two CP932 * strings using this function, you will get false matches. * - * Return value: 0 if the strings match, a negative value if @s1 < @s2, + * Return value: 0 if the strings match, a negative value if @s1 < @s2, * or a positive value if @s1 > @s2. **/ gint @@ -1905,19 +1905,19 @@ g_ascii_strcasecmp (const gchar *s1, * @s1: string to compare with @s2. * @s2: string to compare with @s1. * @n: number of characters to compare. - * + * * Compare @s1 and @s2, ignoring the case of ASCII characters and any * characters after the first @n in each string. * * Unlike the BSD strcasecmp() function, this only recognizes standard * ASCII letters and ignores the locale, treating all non-ASCII * characters as if they are not letters. - * + * * The same warning as in g_ascii_strcasecmp() applies: Use this * function only on strings known to be in encodings where bytes * corresponding to ASCII letters always represent themselves. * - * Return value: 0 if the strings match, a negative value if @s1 < @s2, + * Return value: 0 if the strings match, a negative value if @s1 < @s2, * or a positive value if @s1 > @s2. **/ gint @@ -1950,14 +1950,14 @@ g_ascii_strncasecmp (const gchar *s1, * g_strcasecmp: * @s1: a string. * @s2: a string to compare with @s1. - * + * * A case-insensitive string comparison, corresponding to the standard * strcasecmp() function on platforms which support it. * - * Return value: 0 if the strings match, a negative value if @s1 < @s2, + * Return value: 0 if the strings match, a negative value if @s1 < @s2, * or a positive value if @s1 > @s2. * - * Deprecated:2.2: See g_strncasecmp() for a discussion of why this function + * Deprecated:2.2: See g_strncasecmp() for a discussion of why this function * is deprecated and how to replace it. **/ gint @@ -1996,16 +1996,16 @@ g_strcasecmp (const gchar *s1, * @s1: a string. * @s2: a string to compare with @s1. * @n: the maximum number of characters to compare. - * + * * A case-insensitive string comparison, corresponding to the standard * strncasecmp() function on platforms which support it. - * It is similar to g_strcasecmp() except it only compares the first @n + * It is similar to g_strcasecmp() except it only compares the first @n * characters of the strings. - * - * Return value: 0 if the strings match, a negative value if @s1 < @s2, + * + * Return value: 0 if the strings match, a negative value if @s1 < @s2, * or a positive value if @s1 > @s2. * - * Deprecated:2.2: The problem with g_strncasecmp() is that it does the + * Deprecated:2.2: The problem with g_strncasecmp() is that it does the * comparison by calling toupper()/tolower(). These functions are * locale-specific and operate on single bytes. However, it is impossible * to handle things correctly from an I18N standpoint by operating on @@ -2022,7 +2022,7 @@ g_strcasecmp (const gchar *s1, gint g_strncasecmp (const gchar *s1, const gchar *s2, - guint n) + guint n) { #ifdef HAVE_STRNCASECMP return strncasecmp (s1, s2, n); @@ -2098,7 +2098,7 @@ g_strcompress (const gchar *source) const gchar *p = source, *octal; gchar *dest = g_malloc (strlen (source) + 1); gchar *q = dest; - + while (*p) { if (*p == '\\') @@ -2149,7 +2149,7 @@ g_strcompress (const gchar *source) } out: *q = 0; - + return dest; } @@ -2161,7 +2161,7 @@ g_strescape (const gchar *source, gchar *dest; gchar *q; guchar excmap[256]; - + g_return_val_if_fail (source != NULL, NULL); p = (guchar *) source; @@ -2278,10 +2278,10 @@ g_strchomp (gchar *string) * @max_tokens is reached. * @max_tokens: the maximum number of pieces to split @string into. If this is * less than 1, the string is split completely. - * + * * Splits a string into a maximum of @max_tokens pieces, using the given * @delimiter. If @max_tokens is reached, the remainder of @string is appended - * to the last token. + * to the last token. * * As a special case, the result of splitting the empty string "" is an empty * vector, not a vector containing a single string. The reason for this @@ -2289,8 +2289,8 @@ g_strchomp (gchar *string) * more useful than consistent handling of empty elements. If you do need * to represent empty elements, you'll need to check for the empty string * before calling g_strsplit(). - * - * Return value: a newly-allocated %NULL-terminated array of strings. Use + * + * Return value: a newly-allocated %NULL-terminated array of strings. Use * g_strfreev() to free it. **/ gchar** @@ -2314,11 +2314,11 @@ g_strsplit (const gchar *string, s = strstr (remainder, delimiter); if (s) { - gsize delimiter_len = strlen (delimiter); + gsize delimiter_len = strlen (delimiter); while (--max_tokens && s) { - gsize len; + gsize len; len = s - remainder; string_list = g_slist_prepend (string_list, @@ -2350,21 +2350,21 @@ g_strsplit (const gchar *string, * @string: The string to be tokenized * @delimiters: A nul-terminated string containing bytes that are used * to split the string. - * @max_tokens: The maximum number of tokens to split @string into. + * @max_tokens: The maximum number of tokens to split @string into. * If this is less than 1, the string is split completely - * + * * Splits @string into a number of tokens not containing any of the characters * in @delimiter. A token is the (possibly empty) longest string that does not * contain any of the characters in @delimiters. If @max_tokens is reached, the * remainder is appended to the last token. * * For example the result of g_strsplit_set ("abc:def/ghi", ":/", -1) is a - * %NULL-terminated vector containing the three strings "abc", "def", + * %NULL-terminated vector containing the three strings "abc", "def", * and "ghi". * * The result if g_strsplit_set (":def/ghi:", ":/", -1) is a %NULL-terminated * vector containing the four strings "", "def", "ghi", and "". - * + * * As a special case, the result of splitting the empty string "" is an empty * vector, not a vector containing a single string. The reason for this * special case is that being able to represent a empty vector is typically @@ -2372,12 +2372,12 @@ g_strsplit (const gchar *string, * to represent empty elements, you'll need to check for the empty string * before calling g_strsplit_set(). * - * Note that this function works on bytes not characters, so it can't be used + * Note that this function works on bytes not characters, so it can't be used * to delimit UTF-8 strings for anything but ASCII characters. - * - * Return value: a newly-allocated %NULL-terminated array of strings. Use + * + * Return value: a newly-allocated %NULL-terminated array of strings. Use * g_strfreev() to free it. - * + * * Since: 2.4 **/ gchar ** @@ -2392,7 +2392,7 @@ g_strsplit_set (const gchar *string, const gchar *current; gchar *token; gchar **result; - + g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (delimiters != NULL, NULL); @@ -2405,7 +2405,7 @@ g_strsplit_set (const gchar *string, result[0] = NULL; return result; } - + memset (delim_table, FALSE, sizeof (delim_table)); for (s = delimiters; *s != '\0'; ++s) delim_table[*(guchar *)s] = TRUE; @@ -2426,7 +2426,7 @@ g_strsplit_set (const gchar *string, current = s + 1; } - + ++s; } @@ -2441,7 +2441,7 @@ g_strsplit_set (const gchar *string, result[--n_tokens] = list->data; g_slist_free (tokens); - + return result; } #endif /* NOT_NEEDED_FOR_NAVIT */ @@ -2451,7 +2451,7 @@ g_strsplit_set (const gchar *string, * @str_array: a %NULL-terminated array of strings to free. * Frees a %NULL-terminated array of strings, and the array itself. - * If called on a %NULL value, g_strfreev() simply returns. + * If called on a %NULL value, g_strfreev() simply returns. **/ void g_strfreev (gchar **str_array) @@ -2470,12 +2470,12 @@ g_strfreev (gchar **str_array) /** * g_strdupv: * @str_array: %NULL-terminated array of strings. - * + * * Copies %NULL-terminated array of strings. The copy is a deep copy; * the new array should be freed by first freeing each string, then * the array itself. g_strfreev() does this for you. If called * on a %NULL value, g_strdupv() simply returns %NULL. - * + * * Return value: a new %NULL-terminated array of strings. **/ gchar** @@ -2489,7 +2489,7 @@ g_strdupv (gchar **str_array) i = 0; while (str_array[i]) ++i; - + retval = g_new (gchar*, i + 1); i = 0; @@ -2522,7 +2522,7 @@ g_strjoinv (const gchar *separator, { gint i; gsize len; - gsize separator_len; + gsize separator_len; separator_len = strlen (separator); /* First part, getting length */ @@ -2552,8 +2552,8 @@ g_strjoin (const gchar *separator, { gchar *string, *s; va_list args; - gsize len; - gsize separator_len; + gsize len; + gsize separator_len; gchar *ptr; if (separator == NULL) @@ -2602,8 +2602,6 @@ g_strjoin (const gchar *separator, return string; } -#if NOT_NEEDED_FOR_NAVIT - /** * g_strstr_len: * @haystack: a string. @@ -2614,7 +2612,7 @@ g_strjoin (const gchar *separator, * * Searches the string @haystack for the first occurrence * of the string @needle, limiting the length of the search - * to @haystack_len. + * to @haystack_len. * * Return value: a pointer to the found occurrence, or * %NULL if not found. @@ -2641,25 +2639,24 @@ g_strstr_len (const gchar *haystack, if (haystack_len < needle_len) return NULL; - + end = haystack + haystack_len - needle_len; - + while (p <= end && *p) { for (i = 0; i < needle_len; i++) if (p[i] != needle[i]) goto next; - + return (gchar *)p; - + next: p++; } - + return NULL; } } -#endif /* NOT_NEEDED_FOR_NAVIT */ /** * g_strrstr: @@ -2680,7 +2677,7 @@ g_strrstr (const gchar *haystack, gsize needle_len; gsize haystack_len; const gchar *p; - + g_return_val_if_fail (haystack != NULL, NULL); g_return_val_if_fail (needle != NULL, NULL); @@ -2692,7 +2689,7 @@ g_strrstr (const gchar *haystack, if (haystack_len < needle_len) return NULL; - + p = haystack + haystack_len - needle_len; while (p >= haystack) @@ -2700,17 +2697,16 @@ g_strrstr (const gchar *haystack, for (i = 0; i < needle_len; i++) if (p[i] != needle[i]) goto next; - + return (gchar *)p; - + next: p--; } - + return NULL; } -#if NOT_NEEDED_FOR_NAVIT /** * g_strrstr_len: * @haystack: a nul-terminated string. @@ -2719,7 +2715,7 @@ g_strrstr (const gchar *haystack, * * Searches the string @haystack for the last occurrence * of the string @needle, limiting the length of the search - * to @haystack_len. + * to @haystack_len. * * Return value: a pointer to the found occurrence, or * %NULL if not found. @@ -2731,7 +2727,7 @@ g_strrstr_len (const gchar *haystack, { g_return_val_if_fail (haystack != NULL, NULL); g_return_val_if_fail (needle != NULL, NULL); - + if (haystack_len < 0) return g_strrstr (haystack, needle); else @@ -2746,7 +2742,7 @@ g_strrstr_len (const gchar *haystack, if (p < haystack + needle_len) return NULL; - + p -= needle_len; while (p >= haystack) @@ -2754,9 +2750,9 @@ g_strrstr_len (const gchar *haystack, for (i = 0; i < needle_len; i++) if (p[i] != needle[i]) goto next; - + return (gchar *)p; - + next: p--; } @@ -2764,6 +2760,7 @@ g_strrstr_len (const gchar *haystack, return NULL; } } +#if NOT_NEEDED_FOR_NAVIT /** @@ -2783,7 +2780,7 @@ g_str_has_suffix (const gchar *str, { int str_len; int suffix_len; - + g_return_val_if_fail (str != NULL, FALSE); g_return_val_if_fail (suffix != NULL, FALSE); @@ -2813,7 +2810,7 @@ g_str_has_prefix (const gchar *str, { int str_len; int prefix_len; - + g_return_val_if_fail (str != NULL, FALSE); g_return_val_if_fail (prefix != NULL, FALSE); @@ -2822,7 +2819,7 @@ g_str_has_prefix (const gchar *str, if (str_len < prefix_len) return FALSE; - + return strncmp (str, prefix, prefix_len) == 0; } @@ -2831,17 +2828,17 @@ g_str_has_prefix (const gchar *str, * g_strip_context: * @msgid: a string * @msgval: another string - * + * * An auxiliary function for gettext() support (see Q_()). - * + * * Return value: @msgval, unless @msgval is identical to @msgid and contains * a '|' character, in which case a pointer to the substring of msgid after - * the first '|' character is returned. + * the first '|' character is returned. * * Since: 2.4 **/ G_CONST_RETURN gchar * -g_strip_context (const gchar *msgid, +g_strip_context (const gchar *msgid, const gchar *msgval) { if (msgval == msgid) @@ -2850,7 +2847,7 @@ g_strip_context (const gchar *msgid, if (c != NULL) return c + 1; } - + return msgval; } @@ -2858,10 +2855,10 @@ g_strip_context (const gchar *msgid, /** * g_strv_length: * @str_array: a %NULL-terminated array of strings. - * - * Returns the length of the given %NULL-terminated + * + * Returns the length of the given %NULL-terminated * string array @str_array. - * + * * Return value: length of @str_array. * * Since: 2.6 @@ -2907,8 +2904,8 @@ g_strv_length (gchar **str_array) * Since: 2.16 */ G_CONST_RETURN gchar * -g_dpgettext (const gchar *domain, - const gchar *msgctxtid, +g_dpgettext (const gchar *domain, + const gchar *msgctxtid, gsize msgidoffset) { const gchar *translation; @@ -2922,7 +2919,7 @@ g_dpgettext (const gchar *domain, return msgctxtid + msgidoffset; sep = strchr (msgctxtid, '|'); - + if (sep) { /* try with '\004' instead of '|', in case @@ -2933,16 +2930,16 @@ g_dpgettext (const gchar *domain, tmp[sep - msgctxtid] = '\004'; translation = g_dgettext (domain, tmp); - + if (translation == tmp) - return sep + 1; + return sep + 1; } } return translation; } -/* This function is taken from gettext.h +/* This function is taken from gettext.h * GNU gettext uses '\004' to separate context and msgid in .mo files. */ /** @@ -2960,7 +2957,7 @@ g_dpgettext (const gchar *domain, * This uses g_dgettext() internally. See that functions for differences * with dgettext() proper. * - * This function differs from C_() in that it is not a macro and + * This function differs from C_() in that it is not a macro and * thus you may use non-string-literals as context and msgid arguments. * * Returns: The translated string @@ -2985,7 +2982,7 @@ g_dpgettext2 (const char *domain, translation = g_dgettext (domain, msg_ctxt_id); - if (translation == msg_ctxt_id) + if (translation == msg_ctxt_id) { /* try the old way of doing message contexts, too */ msg_ctxt_id[msgctxt_len - 1] = '|'; @@ -3037,7 +3034,7 @@ _g_dgettext_should_translate (void) 0 != strncmp (translate_locale, "en_", 3) && 0 != strcmp (translate_locale, "C")) should_translate = FALSE; - + g_once_init_leave (&translate, should_translate ? SHOULD_TRANSLATE : diff --git a/navit/support/glib/gutf8.c b/navit/support/glib/gutf8.c index 56163f80e..d6cd83bbf 100644 --- a/navit/support/glib/gutf8.c +++ b/navit/support/glib/gutf8.c @@ -83,7 +83,7 @@ ((Char) < 0x10000 ? 3 : \ ((Char) < 0x200000 ? 4 : \ ((Char) < 0x4000000 ? 5 : 6))))) - + #define UTF8_GET(Result, Chars, Count, Mask, Len) \ (Result) = (Chars)[0] & (Mask); \ @@ -103,8 +103,8 @@ (((Char) & 0xFFFFF800) != 0xD800) && \ ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \ ((Char) & 0xFFFE) != 0xFFFE) - - + + static const gchar utf8_skip_data[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, @@ -122,7 +122,7 @@ const gchar * const g_utf8_skip = utf8_skip_data; * g_utf8_find_prev_char: * @str: pointer to the beginning of a UTF-8 encoded string * @p: pointer to some position within @str - * + * * Given a position @p with a UTF-8 encoded string @str, find the start * of the previous UTF-8 character starting before @p. Returns %NULL if no * UTF-8 characters are present in @str before @p. @@ -156,7 +156,7 @@ g_utf8_find_prev_char (const char *str, * @p does not have to be at the beginning of a UTF-8 character. No check * is made to see if the character found is actually valid other than * it starts with an appropriate byte. - * + * * Return value: a pointer to the found character or %NULL **/ gchar * @@ -185,7 +185,7 @@ g_utf8_find_next_char (const gchar *p, * is made to see if the character found is actually valid other than * it starts with an appropriate byte. If @p might be the first * character of the string, you must use g_utf8_find_prev_char() instead. - * + * * Return value: a pointer to the found character. **/ gchar * @@ -204,9 +204,9 @@ g_utf8_prev_char (const gchar *p) * @p: pointer to the start of a UTF-8 encoded string. * @max: the maximum number of bytes to examine. If @max * is less than 0, then the string is assumed to be - * nul-terminated. If @max is 0, @p will not be examined and + * nul-terminated. If @max is 0, @p will not be examined and * may be %NULL. - * + * * Returns the length of the string in characters. * * Return value: the length of the string in characters @@ -231,13 +231,13 @@ g_utf8_strlen (const gchar *p, { if (max == 0 || !*p) return 0; - - p = g_utf8_next_char (p); + + p = g_utf8_next_char (p); while (p - start < max && *p) { ++len; - p = g_utf8_next_char (p); + p = g_utf8_next_char (p); } /* only do the last len increment if we got a complete @@ -253,13 +253,13 @@ g_utf8_strlen (const gchar *p, /** * g_utf8_get_char: * @p: a pointer to Unicode character encoded as UTF-8 - * + * * Converts a sequence of bytes encoded as UTF-8 to a Unicode character. * If @p does not point to a valid UTF-8 encoded character, results are * undefined. If you are not sure that the bytes are complete * valid Unicode characters, you should use g_utf8_get_char_validated() * instead. - * + * * Return value: the resulting character **/ gunichar @@ -277,38 +277,37 @@ g_utf8_get_char (const gchar *p) return result; } -#ifdef NOT_NEEDED_FOR_NAVIT /** * g_utf8_offset_to_pointer: * @str: a UTF-8 encoded string * @offset: a character offset within @str - * + * * Converts from an integer character offset to a pointer to a position * within the string. - * + * * Since 2.10, this function allows to pass a negative @offset to * step backwards. It is usually worth stepping backwards from the end - * instead of forwards if @offset is in the last fourth of the string, + * instead of forwards if @offset is in the last fourth of the string, * since moving forward is about 3 times faster than moving backward. - * + * * Return value: the resulting pointer **/ gchar * g_utf8_offset_to_pointer (const gchar *str, - glong offset) + glong offset) { const gchar *s = str; - if (offset > 0) + if (offset > 0) while (offset--) s = g_utf8_next_char (s); else { const char *s1; - /* This nice technique for fast backwards stepping - * through a UTF-8 string was dubbed "stutter stepping" + /* This nice technique for fast backwards stepping + * through a UTF-8 string was dubbed "stutter stepping" * by its inventor, Larry Ewing. */ while (offset) @@ -329,23 +328,23 @@ g_utf8_offset_to_pointer (const gchar *str, * g_utf8_pointer_to_offset: * @str: a UTF-8 encoded string * @pos: a pointer to a position within @str - * + * * Converts from a pointer to position within a string to a integer * character offset. * * Since 2.10, this function allows @pos to be before @str, and returns * a negative offset in this case. - * + * * Return value: the resulting character offset **/ -glong +glong g_utf8_pointer_to_offset (const gchar *str, const gchar *pos) { const gchar *s = str; - glong offset = 0; + glong offset = 0; - if (pos < str) + if (pos < str) offset = - g_utf8_pointer_to_offset (pos, str); else while (s < pos) @@ -353,7 +352,7 @@ g_utf8_pointer_to_offset (const gchar *str, s = g_utf8_next_char (s); offset++; } - + return offset; } @@ -363,13 +362,13 @@ g_utf8_pointer_to_offset (const gchar *str, * @dest: buffer to fill with characters from @src * @src: UTF-8 encoded string * @n: character count - * - * Like the standard C strncpy() function, but - * copies a given number of characters instead of a given number of - * bytes. The @src string must be valid UTF-8 encoded text. - * (Use g_utf8_validate() on all text before trying to use UTF-8 + * + * Like the standard C strncpy() function, but + * copies a given number of characters instead of a given number of + * bytes. The @src string must be valid UTF-8 encoded text. + * (Use g_utf8_validate() on all text before trying to use UTF-8 * utility functions with it.) - * + * * Return value: @dest **/ gchar * @@ -388,6 +387,7 @@ g_utf8_strncpy (gchar *dest, return dest; } +#if NOT_NEEDED_FOR_NAVIT G_LOCK_DEFINE_STATIC (aliases); static GHashTable * @@ -401,7 +401,7 @@ get_alias_hash (void) if (!alias_hash) { alias_hash = g_hash_table_new (g_str_hash, g_str_equal); - + aliases = _g_locale_get_charset_aliases (); while (*aliases != '\0') { @@ -409,23 +409,23 @@ get_alias_hash (void) const char *alias; const char **alias_array; int count = 0; - + alias = aliases; aliases += strlen (aliases) + 1; canonical = aliases; aliases += strlen (aliases) + 1; - + alias_array = g_hash_table_lookup (alias_hash, canonical); if (alias_array) { while (alias_array[count]) count++; } - + alias_array = g_renew (const char *, alias_array, count + 2); alias_array[count] = alias; alias_array[count + 1] = NULL; - + g_hash_table_insert (alias_hash, (char *)canonical, alias_array); } } @@ -438,7 +438,7 @@ get_alias_hash (void) /* As an abuse of the alias table, the following routines gets * the charsets that are aliases for the canonical name. */ -G_GNUC_INTERNAL const char ** +G_GNUC_INTERNAL const char ** _g_charset_get_aliases (const char *canonical_name) { GHashTable *alias_hash = get_alias_hash (); @@ -469,11 +469,11 @@ g_utf8_get_charset_internal (const char *raw_data, G_LOCK (aliases); charset = _g_locale_charset_unalias (raw_data); G_UNLOCK (aliases); - + if (charset && *charset) { *a = charset; - + if (charset && strstr (charset, "UTF-8")) return TRUE; else @@ -482,7 +482,7 @@ g_utf8_get_charset_internal (const char *raw_data, /* Assume this for compatibility at present. */ *a = "US-ASCII"; - + return FALSE; } @@ -506,10 +506,10 @@ charset_cache_free (gpointer data) /** * g_get_charset: * @charset: return location for character set name - * - * Obtains the character set for the <link linkend="setlocale">current - * locale</link>; you might use this character set as an argument to - * g_convert(), to convert from the current locale's encoding to some + * + * Obtains the character set for the <link linkend="setlocale">current + * locale</link>; you might use this character set as an argument to + * g_convert(), to convert from the current locale's encoding to some * other encoding. (Frequently g_locale_to_utf8() and g_locale_from_utf8() * are nice shortcuts, though.) * @@ -524,11 +524,11 @@ charset_cache_free (gpointer data) * * The string returned in @charset is not allocated, and should not be * freed. - * + * * Return value: %TRUE if the returned charset is UTF-8 **/ gboolean -g_get_charset (G_CONST_RETURN char **charset) +g_get_charset (G_CONST_RETURN char **charset) { static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; GCharsetCache *cache = g_static_private_get (&cache_private); @@ -541,11 +541,11 @@ g_get_charset (G_CONST_RETURN char **charset) } raw = _g_locale_charset_raw (); - + if (!(cache->raw && strcmp (cache->raw, raw) == 0)) { const gchar *new_charset; - + g_free (cache->raw); g_free (cache->charset); cache->raw = g_strdup (raw); @@ -555,9 +555,10 @@ g_get_charset (G_CONST_RETURN char **charset) if (charset) *charset = cache->charset; - + return cache->is_utf8; } +#endif /* unicode_strchr */ @@ -567,9 +568,9 @@ g_get_charset (G_CONST_RETURN char **charset) * @outbuf: output buffer, must have at least 6 bytes of space. * If %NULL, the length will be computed and returned * and nothing will be written to @outbuf. - * + * * Converts a single character to UTF-8. - * + * * Return value: number of bytes written **/ int @@ -577,7 +578,7 @@ g_unichar_to_utf8 (gunichar c, gchar *outbuf) { /* If this gets modified, also update the copy in g_string_insert_unichar() */ - guint len = 0; + guint len = 0; int first; int i; @@ -630,13 +631,13 @@ g_unichar_to_utf8 (gunichar c, * @p: a nul-terminated UTF-8 encoded string * @len: the maximum length of @p * @c: a Unicode character - * + * * Finds the leftmost occurrence of the given Unicode character * in a UTF-8 encoded string, while limiting the search to @len bytes. * If @len is -1, allow unbounded search. - * - * Return value: %NULL if the string does not contain the character, - * otherwise, a pointer to the start of the leftmost occurrence of + * + * Return value: %NULL if the string does not contain the character, + * otherwise, a pointer to the start of the leftmost occurrence of * the character in the string. **/ gchar * @@ -648,7 +649,7 @@ g_utf8_strchr (const char *p, gint charlen = g_unichar_to_utf8 (c, ch); ch[charlen] = '\0'; - + return g_strstr_len (p, len, ch); } @@ -658,13 +659,13 @@ g_utf8_strchr (const char *p, * @p: a nul-terminated UTF-8 encoded string * @len: the maximum length of @p * @c: a Unicode character - * + * * Find the rightmost occurrence of the given Unicode character * in a UTF-8 encoded string, while limiting the search to @len bytes. * If @len is -1, allow unbounded search. - * - * Return value: %NULL if the string does not contain the character, - * otherwise, a pointer to the start of the rightmost occurrence of the + * + * Return value: %NULL if the string does not contain the character, + * otherwise, a pointer to the start of the rightmost occurrence of the * character in the string. **/ gchar * @@ -676,7 +677,7 @@ g_utf8_strrchr (const char *p, gint charlen = g_unichar_to_utf8 (c, ch); ch[charlen] = '\0'; - + return g_strrstr_len (p, len, ch); } @@ -686,7 +687,7 @@ g_utf8_strrchr (const char *p, */ static inline gunichar g_utf8_get_char_extended (const gchar *p, - gssize max_len) + gssize max_len) { guint i, len; gunichar wc = (guchar) *p; @@ -728,7 +729,7 @@ g_utf8_get_char_extended (const gchar *p, { return (gunichar)-1; } - + if (max_len >= 0 && len > max_len) { for (i = 1; i < max_len; i++) @@ -742,7 +743,7 @@ g_utf8_get_char_extended (const gchar *p, for (i = 1; i < len; ++i) { gunichar ch = ((guchar *)p)[i]; - + if ((ch & 0xc0) != 0x80) { if (ch) @@ -757,7 +758,7 @@ g_utf8_get_char_extended (const gchar *p, if (UTF8_LENGTH(wc) != len) return (gunichar)-1; - + return wc; } @@ -766,16 +767,16 @@ g_utf8_get_char_extended (const gchar *p, * @p: a pointer to Unicode character encoded as UTF-8 * @max_len: the maximum number of bytes to read, or -1, for no maximum or * if @p is nul-terminated - * + * * Convert a sequence of bytes encoded as UTF-8 to a Unicode character. * This function checks for incomplete characters, for invalid characters * such as characters that are out of the range of Unicode, and for * overlong encodings of valid characters. - * + * * Return value: the resulting character. If @p points to a partial - * sequence at the end of a string that could begin a valid - * character (or if @max_len is zero), returns (gunichar)-2; - * otherwise, if @p does not point to a valid UTF-8 encoded + * sequence at the end of a string that could begin a valid + * character (or if @max_len is zero), returns (gunichar)-2; + * otherwise, if @p does not point to a valid UTF-8 encoded * Unicode character, returns (gunichar)-1. **/ gunichar @@ -809,14 +810,14 @@ g_utf8_get_char_validated (const gchar *p, * representation as UCS-4, assuming valid UTF-8 input. * This function is roughly twice as fast as g_utf8_to_ucs4() * but does no error checking on the input. - * + * * Return value: a pointer to a newly allocated UCS-4 string. * This value must be freed with g_free(). **/ gunichar * g_utf8_to_ucs4_fast (const gchar *str, - glong len, - glong *items_written) + glong len, + glong *items_written) { gint j, charlen; gunichar *result; @@ -843,9 +844,9 @@ g_utf8_to_ucs4_fast (const gchar *str, ++n_chars; } } - + result = g_new (gunichar, n_chars + 1); - + p = str; for (i=0; i < n_chars; i++) { @@ -857,7 +858,7 @@ g_utf8_to_ucs4_fast (const gchar *str, p++; } else - { + { if (wc < 0xe0) { charlen = 2; @@ -902,6 +903,7 @@ g_utf8_to_ucs4_fast (const gchar *str, return result; } +#if NOT_NEEDED_FOR_NAVIT /** * g_utf8_to_ucs4: * @str: a UTF-8 encoded string @@ -914,7 +916,7 @@ g_utf8_to_ucs4_fast (const gchar *str, * invalid input is stored here. * @items_written: location to store number of characters written or %NULL. * The value here stored does not include the trailing 0 - * character. + * character. * @error: location to store the error occuring, or %NULL to ignore * errors. Any of the errors in #GConvertError other than * %G_CONVERT_ERROR_NO_CONVERSION may occur. @@ -922,7 +924,7 @@ g_utf8_to_ucs4_fast (const gchar *str, * Convert a string from UTF-8 to a 32-bit fixed width * representation as UCS-4. A trailing 0 will be added to the * string after the converted text. - * + * * Return value: a pointer to a newly allocated UCS-4 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and @@ -930,15 +932,15 @@ g_utf8_to_ucs4_fast (const gchar *str, **/ gunichar * g_utf8_to_ucs4 (const gchar *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { gunichar *result = NULL; gint n_chars, i; const gchar *in; - + in = str; n_chars = 0; while ((len < 0 || str + len - in > 0) && *in) @@ -967,7 +969,7 @@ g_utf8_to_ucs4 (const gchar *str, } result = g_new (gunichar, n_chars + 1); - + in = str; for (i=0; i < n_chars; i++) { @@ -989,31 +991,31 @@ g_utf8_to_ucs4 (const gchar *str, /** * g_ucs4_to_utf8: * @str: a UCS-4 encoded string - * @len: the maximum length (number of characters) of @str to use. + * @len: the maximum length (number of characters) of @str to use. * If @len < 0, then the string is nul-terminated. * @items_read: location to store number of characters read, or %NULL. * @items_written: location to store number of bytes written or %NULL. * The value here stored does not include the trailing 0 - * byte. + * byte. * @error: location to store the error occuring, or %NULL to ignore * errors. Any of the errors in #GConvertError other than * %G_CONVERT_ERROR_NO_CONVERSION may occur. * * Convert a string from a 32-bit fixed width representation as UCS-4. * to UTF-8. The result will be terminated with a 0 byte. - * + * * Return value: a pointer to a newly allocated UTF-8 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and * @error set. In that case, @items_read will be - * set to the position of the first invalid input + * set to the position of the first invalid input * character. **/ gchar * g_ucs4_to_utf8 (const gunichar *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { gint result_length; @@ -1033,7 +1035,7 @@ g_ucs4_to_utf8 (const gunichar *str, _("Character out of range for UTF-8")); goto err_out; } - + result_length += UTF8_LENGTH (str[i]); } @@ -1043,7 +1045,7 @@ g_ucs4_to_utf8 (const gunichar *str, i = 0; while (p < result + result_length) p += g_unichar_to_utf8 (str[i++], p); - + *p = '\0'; if (items_written) @@ -1055,13 +1057,13 @@ g_ucs4_to_utf8 (const gunichar *str, return result; } - +#endif #define SURROGATE_VALUE(h,l) (((h) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000) /** * g_utf16_to_utf8: * @str: a UTF-16 encoded string - * @len: the maximum length (number of <type>gunichar2</type>) of @str to use. + * @len: the maximum length (number of <type>gunichar2</type>) of @str to use. * If @len < 0, then the string is nul-terminated. * @items_read: location to store number of words read, or %NULL. * If %NULL, then %G_CONVERT_ERROR_PARTIAL_INPUT will be @@ -1080,9 +1082,9 @@ g_ucs4_to_utf8 (const gunichar *str, * * Note that the input is expected to be already in native endianness, * an initial byte-order-mark character is not handled specially. - * g_convert() can be used to convert a byte buffer of UTF-16 data of + * g_convert() can be used to convert a byte buffer of UTF-16 data of * ambiguous endianess. - * + * * Return value: a pointer to a newly allocated UTF-8 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and @@ -1090,9 +1092,9 @@ g_ucs4_to_utf8 (const gunichar *str, **/ gchar * g_utf16_to_utf8 (const gunichar2 *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { /* This function and g_utf16_to_ucs4 are almost exactly identical - The lines that differ @@ -1123,8 +1125,10 @@ g_utf16_to_utf8 (const gunichar2 *str, } else { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } } @@ -1132,8 +1136,10 @@ g_utf16_to_utf8 (const gunichar2 *str, { if (high_surrogate) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } @@ -1155,16 +1161,18 @@ g_utf16_to_utf8 (const gunichar2 *str, if (high_surrogate && !items_read) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT, _("Partial character sequence at end of input")); +#endif goto err_out; } - + /* At this point, everything is valid, and we just need to convert */ /********** DIFFERENT for UTF8/UCS4 **********/ result = g_malloc (n_bytes + 1); - + high_surrogate = 0; out = result; in = str; @@ -1192,7 +1200,7 @@ g_utf16_to_utf8 (const gunichar2 *str, next2: in++; } - + /********** DIFFERENT for UTF8/UCS4 **********/ *out = '\0'; @@ -1210,7 +1218,7 @@ g_utf16_to_utf8 (const gunichar2 *str, /** * g_utf16_to_ucs4: * @str: a UTF-16 encoded string - * @len: the maximum length (number of <type>gunichar2</type>) of @str to use. + * @len: the maximum length (number of <type>gunichar2</type>) of @str to use. * If @len < 0, then the string is nul-terminated. * @items_read: location to store number of words read, or %NULL. * If %NULL, then %G_CONVERT_ERROR_PARTIAL_INPUT will be @@ -1226,7 +1234,7 @@ g_utf16_to_utf8 (const gunichar2 *str, * * Convert a string from UTF-16 to UCS-4. The result will be * nul-terminated. - * + * * Return value: a pointer to a newly allocated UCS-4 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and @@ -1234,9 +1242,9 @@ g_utf16_to_utf8 (const gunichar2 *str, **/ gunichar * g_utf16_to_ucs4 (const gunichar2 *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { const gunichar2 *in; @@ -1264,8 +1272,10 @@ g_utf16_to_ucs4 (const gunichar2 *str, } else { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } } @@ -1273,8 +1283,10 @@ g_utf16_to_ucs4 (const gunichar2 *str, { if (high_surrogate) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } @@ -1296,16 +1308,18 @@ g_utf16_to_ucs4 (const gunichar2 *str, if (high_surrogate && !items_read) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT, _("Partial character sequence at end of input")); +#endif goto err_out; } - + /* At this point, everything is valid, and we just need to convert */ /********** DIFFERENT for UTF8/UCS4 **********/ result = g_malloc (n_bytes + 4); - + high_surrogate = 0; out = result; in = str; @@ -1352,14 +1366,14 @@ g_utf16_to_ucs4 (const gunichar2 *str, /** * g_utf8_to_utf16: * @str: a UTF-8 encoded string - * @len: the maximum length (number of characters) of @str to use. + * @len: the maximum length (number of characters) of @str to use. * If @len < 0, then the string is nul-terminated. * @items_read: location to store number of bytes read, or %NULL. * If %NULL, then %G_CONVERT_ERROR_PARTIAL_INPUT will be * returned in case @str contains a trailing partial * character. If an error occurs then the index of the * invalid input is stored here. - * @items_written: location to store number of <type>gunichar2</type> written, + * @items_written: location to store number of <type>gunichar2</type> written, * or %NULL. * The value stored here does not include the trailing 0. * @error: location to store the error occuring, or %NULL to ignore @@ -1368,7 +1382,7 @@ g_utf16_to_ucs4 (const gunichar2 *str, * * Convert a string from UTF-8 to UTF-16. A 0 character will be * added to the result after the converted text. - * + * * Return value: a pointer to a newly allocated UTF-16 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and @@ -1376,9 +1390,9 @@ g_utf16_to_ucs4 (const gunichar2 *str, **/ gunichar2 * g_utf8_to_utf16 (const gchar *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { gunichar2 *result = NULL; @@ -1399,14 +1413,17 @@ g_utf8_to_utf16 (const gchar *str, { if (items_read) break; +#if NOT_NEEDED_FOR_NAVIT else g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT, _("Partial character sequence at end of input")); +#endif } +#if NOT_NEEDED_FOR_NAVIT else g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid byte sequence in conversion input")); - +#endif goto err_out; } @@ -1414,8 +1431,10 @@ g_utf8_to_utf16 (const gchar *str, n16 += 1; else if (wc < 0xe000) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } @@ -1425,17 +1444,19 @@ g_utf8_to_utf16 (const gchar *str, n16 += 2; else { - g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, - _("Character out of range for UTF-16")); +#if NOT_NEEDED_FOR_NAVIT +// g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, +// _("Character out of range for UTF-16")); +#endif goto err_out; } - + in = g_utf8_next_char (in); } result = g_new (gunichar2, n16 + 1); - + in = str; for (i = 0; i < n16;) { @@ -1450,7 +1471,7 @@ g_utf8_to_utf16 (const gchar *str, result[i++] = (wc - 0x10000) / 0x400 + 0xd800; result[i++] = (wc - 0x10000) % 0x400 + 0xdc00; } - + in = g_utf8_next_char (in); } @@ -1462,20 +1483,20 @@ g_utf8_to_utf16 (const gchar *str, err_out: if (items_read) *items_read = in - str; - + return result; } /** * g_ucs4_to_utf16: * @str: a UCS-4 encoded string - * @len: the maximum length (number of characters) of @str to use. + * @len: the maximum length (number of characters) of @str to use. * If @len < 0, then the string is nul-terminated. * @items_read: location to store number of bytes read, or %NULL. * If an error occurs then the index of the invalid input * is stored here. - * @items_written: location to store number of <type>gunichar2</type> - * written, or %NULL. The value stored here does not + * @items_written: location to store number of <type>gunichar2</type> + * written, or %NULL. The value stored here does not * include the trailing 0. * @error: location to store the error occuring, or %NULL to ignore * errors. Any of the errors in #GConvertError other than @@ -1483,7 +1504,7 @@ g_utf8_to_utf16 (const gchar *str, * * Convert a string from UCS-4 to UTF-16. A 0 character will be * added to the result after the converted text. - * + * * Return value: a pointer to a newly allocated UTF-16 string. * This value must be freed with g_free(). If an * error occurs, %NULL will be returned and @@ -1491,9 +1512,9 @@ g_utf8_to_utf16 (const gchar *str, **/ gunichar2 * g_ucs4_to_utf16 (const gunichar *str, - glong len, - glong *items_read, - glong *items_written, + glong len, + glong *items_read, + glong *items_written, GError **error) { gunichar2 *result = NULL; @@ -1510,8 +1531,10 @@ g_ucs4_to_utf16 (const gunichar *str, n16 += 1; else if (wc < 0xe000) { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid sequence in conversion input")); +#endif goto err_out; } @@ -1521,17 +1544,19 @@ g_ucs4_to_utf16 (const gunichar *str, n16 += 2; else { +#if NOT_NEEDED_FOR_NAVIT g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Character out of range for UTF-16")); +#endif goto err_out; } i++; } - + result = g_new (gunichar2, n16 + 1); - + for (i = 0, j = 0; j < n16; i++) { gunichar wc = str[i]; @@ -1550,11 +1575,11 @@ g_ucs4_to_utf16 (const gunichar *str, if (items_written) *items_written = n16; - + err_out: if (items_read) *items_read = i; - + return result; } @@ -1578,10 +1603,10 @@ fast_validate (const char *str) { if (*(guchar *)p < 128) /* done */; - else + else { const gchar *last; - + last = p; if ((*(guchar *)p & 0xe0) == 0xc0) /* 110xxxxx */ { @@ -1606,7 +1631,7 @@ fast_validate (const char *str) } else goto error; - + p++; CONTINUATION_CHAR; TWO_REMAINING: @@ -1614,16 +1639,16 @@ fast_validate (const char *str) CONTINUATION_CHAR; p++; CONTINUATION_CHAR; - + if (G_UNLIKELY (val < min)) goto error; if (G_UNLIKELY (!UNICODE_VALID(val))) goto error; - } - + } + continue; - + error: return last; } @@ -1647,16 +1672,16 @@ fast_validate_len (const char *str, { if (*(guchar *)p < 128) /* done */; - else + else { const gchar *last; - + last = p; if ((*(guchar *)p & 0xe0) == 0xc0) /* 110xxxxx */ { if (G_UNLIKELY (max_len - (p - str) < 2)) goto error; - + if (G_UNLIKELY ((*(guchar *)p & 0x1e) == 0)) goto error; p++; @@ -1669,7 +1694,7 @@ fast_validate_len (const char *str, { if (G_UNLIKELY (max_len - (p - str) < 3)) goto error; - + min = (1 << 11); val = *(guchar *)p & 0x0f; goto TWO_REMAINING; @@ -1678,13 +1703,13 @@ fast_validate_len (const char *str, { if (G_UNLIKELY (max_len - (p - str) < 4)) goto error; - + min = (1 << 16); val = *(guchar *)p & 0x07; } else goto error; - + p++; CONTINUATION_CHAR; TWO_REMAINING: @@ -1692,15 +1717,15 @@ fast_validate_len (const char *str, CONTINUATION_CHAR; p++; CONTINUATION_CHAR; - + if (G_UNLIKELY (val < min)) goto error; if (G_UNLIKELY (!UNICODE_VALID(val))) goto error; - } - + } + continue; - + error: return last; } @@ -1714,28 +1739,28 @@ fast_validate_len (const char *str, * @str: a pointer to character data * @max_len: max bytes to validate, or -1 to go until NUL * @end: return location for end of valid data - * + * * Validates UTF-8 encoded text. @str is the text to validate; * if @str is nul-terminated, then @max_len can be -1, otherwise * @max_len should be the number of bytes to validate. * If @end is non-%NULL, then the end of the valid range - * will be stored there (i.e. the start of the first invalid - * character if some bytes were invalid, or the end of the text + * will be stored there (i.e. the start of the first invalid + * character if some bytes were invalid, or the end of the text * being validated otherwise). * - * Note that g_utf8_validate() returns %FALSE if @max_len is + * Note that g_utf8_validate() returns %FALSE if @max_len is * positive and NUL is met before @max_len bytes have been read. * * Returns %TRUE if all of @str was valid. Many GLib and GTK+ * routines <emphasis>require</emphasis> valid UTF-8 as input; * so data read from a file or the network should be checked * with g_utf8_validate() before doing anything else with it. - * + * * Return value: %TRUE if the text was valid UTF-8 **/ gboolean g_utf8_validate (const char *str, - gssize max_len, + gssize max_len, const gchar **end) { @@ -1759,11 +1784,11 @@ g_utf8_validate (const char *str, /** * g_unichar_validate: * @ch: a Unicode character - * + * * Checks whether @ch is a valid Unicode character. Some possible * integer values of @ch will not be valid. 0 is considered a valid * character, though it's normally a string terminator. - * + * * Return value: %TRUE if @ch is a valid Unicode character **/ gboolean @@ -1778,19 +1803,19 @@ g_unichar_validate (gunichar ch) * @len: the maximum length of @str to use, in bytes. If @len < 0, * then the string is nul-terminated. * - * Reverses a UTF-8 string. @str must be valid UTF-8 encoded text. - * (Use g_utf8_validate() on all text before trying to use UTF-8 + * Reverses a UTF-8 string. @str must be valid UTF-8 encoded text. + * (Use g_utf8_validate() on all text before trying to use UTF-8 * utility functions with it.) * * This function is intended for programmatic uses of reversed strings. - * It pays no attention to decomposed characters, combining marks, byte - * order marks, directional indicators (LRM, LRO, etc) and similar - * characters which might need special handling when reversing a string + * It pays no attention to decomposed characters, combining marks, byte + * order marks, directional indicators (LRM, LRO, etc) and similar + * characters which might need special handling when reversing a string * for display purposes. * * Note that unlike g_strreverse(), this function returns * newly-allocated memory, which should be freed with g_free() when - * no longer needed. + * no longer needed. * * Returns: a newly-allocated string which is the reverse of @str. * @@ -1821,6 +1846,7 @@ g_utf8_strreverse (const gchar *str, return result; } +#if NOT_NEEDED_FOR_NAVIT gchar * _g_utf8_make_valid (const gchar *name) @@ -1828,38 +1854,37 @@ _g_utf8_make_valid (const gchar *name) GString *string; const gchar *remainder, *invalid; gint remaining_bytes, valid_bytes; - + string = NULL; remainder = name; remaining_bytes = strlen (name); - - while (remaining_bytes != 0) + + while (remaining_bytes != 0) { - if (g_utf8_validate (remainder, remaining_bytes, &invalid)) + if (g_utf8_validate (remainder, remaining_bytes, &invalid)) break; valid_bytes = invalid - remainder; - - if (string == NULL) + + if (string == NULL) string = g_string_sized_new (remaining_bytes); g_string_append_len (string, remainder, valid_bytes); /* append U+FFFD REPLACEMENT CHARACTER */ g_string_append (string, "\357\277\275"); - + remaining_bytes -= valid_bytes + 1; remainder = invalid + 1; } - + if (string == NULL) return g_strdup (name); - + g_string_append (string, remainder); g_assert (g_utf8_validate (string->str, -1, NULL)); - + return g_string_free (string, FALSE); } - #endif #define __G_UTF8_C__ diff --git a/navit/support/glib/gutils.c b/navit/support/glib/gutils.c index f88890cd5..2871e381b 100644 --- a/navit/support/glib/gutils.c +++ b/navit/support/glib/gutils.c @@ -21,10 +21,10 @@ * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GLib at ftp://ftp.gtk.org/pub/gtk/. + * GLib at ftp://ftp.gtk.org/pub/gtk/. */ -/* +/* * MT safe for the unix part, FIXME: make the win32 part MT safe as well. */ @@ -49,7 +49,7 @@ #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef HAVE_CRT_EXTERNS_H +#ifdef HAVE_CRT_EXTERNS_H #include <crt_externs.h> /* for _NSGetEnviron */ #endif @@ -69,7 +69,7 @@ #define G_PATH_LENGTH PATH_MAX #elif defined (_PC_PATH_MAX) #define G_PATH_LENGTH sysconf(_PC_PATH_MAX) -#else +#else #define G_PATH_LENGTH 2048 #endif @@ -216,7 +216,7 @@ glib_check_version (guint required_major, #if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY) /** - * g_memmove: + * g_memmove: * @dest: the destination address to copy the bytes to. * @src: the source address to copy the bytes from. * @len: the number of bytes to copy. @@ -224,14 +224,14 @@ glib_check_version (guint required_major, * Copies a block of memory @len bytes long, from @src to @dest. * The source and destination areas may overlap. * - * In order to use this function, you must include - * <filename>string.h</filename> yourself, because this macro will - * typically simply resolve to memmove() and GLib does not include + * In order to use this function, you must include + * <filename>string.h</filename> yourself, because this macro will + * typically simply resolve to memmove() and GLib does not include * <filename>string.h</filename> for you. */ -void -g_memmove (gpointer dest, - gconstpointer src, +void +g_memmove (gpointer dest, + gconstpointer src, gulong len) { gchar* destptr = dest; @@ -263,7 +263,7 @@ g_memmove (gpointer dest, /** * g_atexit: * @func: the function to call on normal program termination. - * + * * Specifies a function to be called at normal program termination. * * Since GLib 2.8.2, on Windows g_atexit() actually is a preprocessor @@ -335,7 +335,7 @@ g_atexit (GVoidFunc func) */ static gchar* -my_strchrnul (const gchar *str, +my_strchrnul (const gchar *str, gchar c) { gchar *p = (gchar*)str; @@ -376,7 +376,7 @@ g_find_program_in_path (const gchar *program) memcpy (decorated_program, program, program_length); memcpy (decorated_program+program_length, p, q-p); decorated_program [program_length + (q-p)] = '\0'; - + retval = inner_find_program_in_path (decorated_program); g_free (decorated_program); @@ -399,23 +399,23 @@ g_find_program_in_path (const gchar *program) /** * g_find_program_in_path: * @program: a program name in the GLib file name encoding - * + * * Locates the first executable named @program in the user's path, in the * same way that execvp() would locate it. Returns an allocated string * with the absolute path name, or %NULL if the program is not found in * the path. If @program is already an absolute path, returns a copy of * @program if @program exists and is executable, and %NULL otherwise. - * + * * On Windows, if @program does not have a file type suffix, tries * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in - * the <envar>PATHEXT</envar> environment variable. - * - * On Windows, it looks for the file in the same way as CreateProcess() + * the <envar>PATHEXT</envar> environment variable. + * + * On Windows, it looks for the file in the same way as CreateProcess() * would. This means first in the directory where the executing * program was loaded from, then in the current directory, then in the * Windows 32-bit system directory, then in the Windows directory, and - * finally in the directories in the <envar>PATH</envar> environment - * variable. If the program is found, the return value contains the + * finally in the directories in the <envar>PATH</envar> environment + * variable. If the program is found, the return value contains the * full name including the type suffix. * * Return value: absolute path, or %NULL @@ -459,7 +459,7 @@ g_find_program_in_path (const gchar *program) else return NULL; } - + path = g_getenv ("PATH"); #if defined(G_OS_UNIX) || defined(G_OS_BEOS) if (path == NULL) @@ -468,33 +468,33 @@ g_find_program_in_path (const gchar *program) * search path in GNU libc is the current directory followed by * the path `confstr' returns for `_CS_PATH'. */ - + /* In GLib we put . last, for security, and don't use the * unportable confstr(); UNIX98 does not actually specify * what to search if PATH is unset. POSIX may, dunno. */ - + path = "/bin:/usr/bin:."; } #else n = GetModuleFileNameW (NULL, wfilename, MAXPATHLEN); if (n > 0 && n < MAXPATHLEN) filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL); - + n = GetSystemDirectoryW (wsysdir, MAXPATHLEN); if (n > 0 && n < MAXPATHLEN) sysdir = g_utf16_to_utf8 (wsysdir, -1, NULL, NULL, NULL); - + n = GetWindowsDirectoryW (wwindir, MAXPATHLEN); if (n > 0 && n < MAXPATHLEN) windir = g_utf16_to_utf8 (wwindir, -1, NULL, NULL, NULL); - + if (filename) { appdir = g_path_get_dirname (filename); g_free (filename); } - + path = g_strdup (path); if (windir) @@ -504,7 +504,7 @@ g_find_program_in_path (const gchar *program) g_free ((gchar *) tem); g_free (windir); } - + if (sysdir) { const gchar *tem = path; @@ -512,13 +512,13 @@ g_find_program_in_path (const gchar *program) g_free ((gchar *) tem); g_free (sysdir); } - + { const gchar *tem = path; path = g_strconcat (".;", path, NULL); g_free ((gchar *) tem); } - + if (appdir) { const gchar *tem = path; @@ -529,17 +529,17 @@ g_find_program_in_path (const gchar *program) path_copy = path; #endif - + len = strlen (program) + 1; pathlen = strlen (path); freeme = name = g_malloc (pathlen + len + 1); - + /* Copy the file name at the top, including '\0' */ memcpy (name + pathlen + 1, program, len); name = name + pathlen; /* And add the slash before the filename */ *name = G_DIR_SEPARATOR; - + p = path; do { @@ -569,7 +569,7 @@ g_find_program_in_path (const gchar *program) } } while (*p++ != '\0'); - + g_free (freeme); #ifdef G_OS_WIN32 g_free ((gchar *) path_copy); @@ -599,25 +599,25 @@ debug_key_matches (const gchar *key, * g_parse_debug_string: * @string: a list of debug options separated by colons, spaces, or * commas; or the string "all" to set all flags, or %NULL. - * @keys: pointer to an array of #GDebugKey which associate + * @keys: pointer to an array of #GDebugKey which associate * strings with bit flags. * @nkeys: the number of #GDebugKey<!-- -->s in the array. * * Parses a string containing debugging options - * into a %guint containing bit flags. This is used + * into a %guint containing bit flags. This is used * within GDK and GTK+ to parse the debug options passed on the * command line or through environment variables. * * Returns: the combined set of bit flags. */ -guint -g_parse_debug_string (const gchar *string, - const GDebugKey *keys, +guint +g_parse_debug_string (const gchar *string, + const GDebugKey *keys, guint nkeys) { guint i; guint result = 0; - + if (string == NULL) return 0; @@ -625,7 +625,7 @@ g_parse_debug_string (const gchar *string, * so introducing malloc dependencies here would require adaptions * of those code portions. */ - + if (!g_ascii_strcasecmp (string, "all")) { for (i=0; i<nkeys; i++) @@ -635,33 +635,33 @@ g_parse_debug_string (const gchar *string, { const gchar *p = string; const gchar *q; - + while (*p) { q = strpbrk (p, ":;, \t"); if (!q) q = p + strlen(p); - + for (i = 0; i < nkeys; i++) if (debug_key_matches (keys[i].key, p, q - p)) result |= keys[i].value; - + p = q; if (*p) p++; } } - + return result; } /** * g_basename: * @file_name: the name of the file. - * - * Gets the name of the file without any leading directory components. + * + * Gets the name of the file without any leading directory components. * It returns a pointer into the given file name string. - * + * * Return value: the name of the file without any leading directory components. * * Deprecated:2.2: Use g_path_get_basename() instead, but notice that @@ -672,9 +672,9 @@ G_CONST_RETURN gchar* g_basename (const gchar *file_name) { register gchar *base; - + g_return_val_if_fail (file_name != NULL, NULL); - + base = strrchr (file_name, G_DIR_SEPARATOR); #ifdef G_OS_WIN32 @@ -692,37 +692,38 @@ g_basename (const gchar *file_name) if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':') return (gchar*) file_name + 2; #endif /* G_OS_WIN32 */ - + return (gchar*) file_name; } +#endif /** * g_path_get_basename: * @file_name: the name of the file. * - * Gets the last component of the filename. If @file_name ends with a - * directory separator it gets the component before the last slash. If - * @file_name consists only of directory separators (and on Windows, + * Gets the last component of the filename. If @file_name ends with a + * directory separator it gets the component before the last slash. If + * @file_name consists only of directory separators (and on Windows, * possibly a drive letter), a single separator is returned. If * @file_name is empty, it gets ".". * - * Return value: a newly allocated string containing the last component of + * Return value: a newly allocated string containing the last component of * the filename. */ gchar* g_path_get_basename (const gchar *file_name) { - register gssize base; - register gssize last_nonslash; - gsize len; + register gssize base; + register gssize last_nonslash; + gsize len; gchar *retval; - + g_return_val_if_fail (file_name != NULL, NULL); if (file_name[0] == '\0') /* empty string */ return g_strdup ("."); - + last_nonslash = strlen (file_name) - 1; while (last_nonslash >= 0 && G_IS_DIR_SEPARATOR (file_name [last_nonslash])) @@ -755,6 +756,7 @@ g_path_get_basename (const gchar *file_name) return retval; } +#if NOT_NEEDED_FOR_NAVIT /** * g_path_is_absolute: * @file_name: a file name. @@ -763,19 +765,19 @@ g_path_get_basename (const gchar *file_name) * i.e. it contains a full path from the root directory such as "/usr/local" * on UNIX or "C:\windows" on Windows systems. * - * Returns: %TRUE if @file_name is an absolute path. + * Returns: %TRUE if @file_name is an absolute path. */ gboolean g_path_is_absolute (const gchar *file_name) { g_return_val_if_fail (file_name != NULL, FALSE); - + if (G_IS_DIR_SEPARATOR (file_name[0])) return TRUE; #ifdef G_OS_WIN32 /* Recognize drive letter on native Windows */ - if (g_ascii_isalpha (file_name[0]) && + if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':' && G_IS_DIR_SEPARATOR (file_name[2])) return TRUE; #endif /* G_OS_WIN32 */ @@ -797,7 +799,7 @@ G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name) { g_return_val_if_fail (file_name != NULL, NULL); - + #ifdef G_PLATFORM_WIN32 /* Skip \\server\share or //server/share */ if (G_IS_DIR_SEPARATOR (file_name[0]) && @@ -832,7 +834,7 @@ g_path_skip_root (const gchar *file_name) } } #endif - + /* Skip initial slashes */ if (G_IS_DIR_SEPARATOR (file_name[0])) { @@ -857,17 +859,17 @@ g_path_skip_root (const gchar *file_name) * Gets the directory components of a file name. If the file name has no * directory components "." is returned. The returned string should be * freed when no longer needed. - * + * * Returns: the directory components of the file. */ gchar* g_path_get_dirname (const gchar *file_name) { register gchar *base; - register gsize len; - + register gsize len; + g_return_val_if_fail (file_name != NULL, NULL); - + base = strrchr (file_name, G_DIR_SEPARATOR); #ifdef G_OS_WIN32 { @@ -942,11 +944,11 @@ g_path_get_dirname (const gchar *file_name) #endif len = (guint) 1 + base - file_name; - + base = g_new (gchar, len + 1); g_memmove (base, file_name, len); base[len] = 0; - + return base; } @@ -954,9 +956,9 @@ g_path_get_dirname (const gchar *file_name) * g_get_current_dir: * * Gets the current directory. - * The returned string should be freed when no longer needed. The encoding + * The returned string should be freed when no longer needed. The encoding * of the returned string is system defined. On Windows, it is always UTF-8. - * + * * Returns: the current directory. */ gchar* @@ -973,7 +975,7 @@ g_get_current_dir (void) if (GetCurrentDirectoryW (len, wdir) == len - 1) dir = g_utf16_to_utf8 (wdir, -1, NULL, NULL, NULL); - + g_free (wdir); if (dir == NULL) @@ -987,9 +989,9 @@ g_get_current_dir (void) gchar *dir = NULL; static gulong max_len = 0; - if (max_len == 0) + if (max_len == 0) max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH; - + /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd") * and, if that wasn't bad enough, hangs in doing so. */ @@ -1011,7 +1013,7 @@ g_get_current_dir (void) max_len *= 2; } #endif /* !sun || !HAVE_GETCWD */ - + if (!dir || !*buffer) { /* hm, should we g_error() out here? @@ -1023,7 +1025,7 @@ g_get_current_dir (void) dir = g_strdup (buffer); g_free (buffer); - + return dir; #endif /* !Win32 */ } @@ -1031,14 +1033,14 @@ g_get_current_dir (void) /** * g_getenv: * @variable: the environment variable to get, in the GLib file name encoding. - * + * * Returns the value of an environment variable. The name and value * are in the GLib file name encoding. On UNIX, this means the actual * bytes which might or might not be in some consistent character set * and encoding. On Windows, it is in UTF-8. On Windows, in case the * environment variable's value contains references to other * environment variables, they are expanded. - * + * * Return value: the value of the environment variable, or %NULL if * the environment variable is not found. The returned string may be * overwritten by the next call to g_getenv(), g_setenv() or @@ -1121,7 +1123,7 @@ g_getenv (const gchar *variable) quark = g_quark_from_string (value); g_free (value); - + return g_quark_to_string (quark); #endif /* G_OS_WIN32 */ @@ -1162,7 +1164,7 @@ _g_getenv_nomalloc (const gchar *variable, * they can be any sequence of bytes. On Windows, they should be in * UTF-8. * - * Note that on some systems, when variables are overwritten, the memory + * Note that on some systems, when variables are overwritten, the memory * used for the previous variables and its value isn't reclaimed. * * Returns: %FALSE if the environment variable couldn't be set. @@ -1170,8 +1172,8 @@ _g_getenv_nomalloc (const gchar *variable, * Since: 2.4 */ gboolean -g_setenv (const gchar *variable, - const gchar *value, +g_setenv (const gchar *variable, + const gchar *value, gboolean overwrite) { #ifndef G_OS_WIN32 @@ -1189,7 +1191,7 @@ g_setenv (const gchar *variable, #else if (!overwrite && getenv (variable) != NULL) return TRUE; - + /* This results in a leak when you overwrite existing * settings. It would be fairly easy to fix this by keeping * our own parallel array or hash table. @@ -1231,7 +1233,7 @@ g_setenv (const gchar *variable, wvalue = g_utf8_to_utf16 (value, -1, NULL, NULL, NULL); tem = g_strconcat (variable, "=", value, NULL); wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL); - + g_free (tem); _wputenv (wassignment); g_free (wassignment); @@ -1250,7 +1252,7 @@ g_setenv (const gchar *variable, #define environ (*_NSGetEnviron()) #elif !defined(G_OS_WIN32) -/* According to the Single Unix Specification, environ is not in +/* According to the Single Unix Specification, environ is not in * any system header, although unistd.h often declares it. */ extern char **environ; @@ -1259,15 +1261,15 @@ extern char **environ; /** * g_unsetenv: * @variable: the environment variable to remove, must not contain '='. - * + * * Removes an environment variable from the environment. * - * Note that on some systems, when variables are overwritten, the memory + * Note that on some systems, when variables are overwritten, the memory * used for the previous variables and its value isn't reclaimed. - * Furthermore, this function can't be guaranteed to operate in a + * Furthermore, this function can't be guaranteed to operate in a * threadsafe way. * - * Since: 2.4 + * Since: 2.4 **/ void g_unsetenv (const gchar *variable) @@ -1287,7 +1289,7 @@ g_unsetenv (const gchar *variable) g_return_if_fail (strchr (variable, '=') == NULL); len = strlen (variable); - + /* Mess directly with the environ array. * This seems to be the only portable way to do this. * @@ -1295,9 +1297,9 @@ g_unsetenv (const gchar *variable) * the variable name, not just the first. */ e = f = environ; - while (*e != NULL) + while (*e != NULL) { - if (strncmp (*e, variable, len) != 0 || (*e)[len] != '=') + if (strncmp (*e, variable, len) != 0 || (*e)[len] != '=') { *f = *e; f++; @@ -1319,7 +1321,7 @@ g_unsetenv (const gchar *variable) wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL); tem = g_strconcat (variable, "=", NULL); wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL); - + g_free (tem); _wputenv (wassignment); g_free (wassignment); @@ -1335,7 +1337,7 @@ g_unsetenv (const gchar *variable) * g_listenv: * * Gets the names of all variables set in the environment. - * + * * Returns: a %NULL-terminated list of strings which must be freed * with g_strfreev(). * @@ -1357,7 +1359,7 @@ g_listenv (void) len = g_strv_length (environ); result = g_new0 (gchar *, len + 1); - + j = 0; for (i = 0; i < len; i++) { @@ -1505,24 +1507,24 @@ g_get_any_init_do (void) #ifdef G_OS_WIN32 if (!g_tmp_dir) g_tmp_dir = get_windows_directory_root (); -#else +#else #ifdef P_tmpdir if (!g_tmp_dir) { - gsize k; + gsize k; g_tmp_dir = g_strdup (P_tmpdir); k = strlen (g_tmp_dir); if (k > 1 && G_IS_DIR_SEPARATOR (g_tmp_dir[k - 1])) g_tmp_dir[k - 1] = '\0'; } #endif - + if (!g_tmp_dir) { g_tmp_dir = g_strdup ("/tmp"); } #endif /* !G_OS_WIN32 */ - + #ifdef G_OS_WIN32 /* We check $HOME first for Win32, though it is a last resort for Unix * where we prefer the results of getpwuid(). @@ -1539,7 +1541,7 @@ g_get_any_init_do (void) g_home_dir = NULL; } } - + /* In case HOME is Unix-style (it happens), convert it to * Windows style. */ @@ -1559,11 +1561,11 @@ g_get_any_init_do (void) if (!g_home_dir) g_home_dir = get_special_folder (CSIDL_PROFILE); - + if (!g_home_dir) g_home_dir = get_windows_directory_root (); #endif /* G_OS_WIN32 */ - + #ifdef HAVE_PWD_H { struct passwd *pw = NULL; @@ -1573,10 +1575,10 @@ g_get_any_init_do (void) # if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R) struct passwd pwd; -# ifdef _SC_GETPW_R_SIZE_MAX +# ifdef _SC_GETPW_R_SIZE_MAX /* This reurns the maximum length */ glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX); - + if (bufsize < 0) bufsize = 64; # else /* _SC_GETPW_R_SIZE_MAX */ @@ -1584,16 +1586,16 @@ g_get_any_init_do (void) # endif /* _SC_GETPW_R_SIZE_MAX */ logname = (gchar *) g_getenv ("LOGNAME"); - + do { g_free (buffer); - /* we allocate 6 extra bytes to work around a bug in + /* we allocate 6 extra bytes to work around a bug in * Mac OS < 10.3. See #156446 */ buffer = g_malloc (bufsize + 6); errno = 0; - + # ifdef HAVE_POSIX_GETPWUID_R if (logname) { error = getpwnam_r (logname, &pwd, buffer, bufsize, &pw); @@ -1621,9 +1623,9 @@ g_get_any_init_do (void) pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); } error = pw ? 0 : errno; -# endif /* !_AIX */ +# endif /* !_AIX */ # endif /* HAVE_NONPOSIX_GETPWUID_R */ - + if (!pw) { /* we bail out prematurely if the user id can't be found @@ -1643,13 +1645,13 @@ g_get_any_init_do (void) g_strerror (error)); break; } - + bufsize *= 2; } } while (!pw); # endif /* HAVE_POSIX_GETPWUID_R || HAVE_NONPOSIX_GETPWUID_R */ - + if (!pw) { setpwent (); @@ -1660,7 +1662,7 @@ g_get_any_init_do (void) { g_user_name = g_strdup (pw->pw_name); - if (pw->pw_gecos && *pw->pw_gecos != '\0') + if (pw->pw_gecos && *pw->pw_gecos != '\0') { gchar **gecos_fields; gchar **name_parts; @@ -1679,14 +1681,14 @@ g_get_any_init_do (void) } g_free (buffer); } - + #else /* !HAVE_PWD_H */ - + #ifdef G_OS_WIN32 { guint len = UNLEN+1; wchar_t buffer[UNLEN+1]; - + if (GetUserNameW (buffer, (LPDWORD) &len)) { g_user_name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL); @@ -1779,10 +1781,10 @@ g_get_user_name (void) /** * g_get_real_name: * - * Gets the real name of the user. This usually comes from the user's entry - * in the <filename>passwd</filename> file. The encoding of the returned - * string is system-defined. (On Windows, it is, however, always UTF-8.) - * If the real user name cannot be determined, the string "Unknown" is + * Gets the real name of the user. This usually comes from the user's entry + * in the <filename>passwd</filename> file. The encoding of the returned + * string is system-defined. (On Windows, it is, however, always UTF-8.) + * If the real user name cannot be determined, the string "Unknown" is * returned. * * Returns: the user's real name. @@ -1797,24 +1799,24 @@ g_get_real_name (void) /** * g_get_home_dir: * - * Gets the current user's home directory as defined in the + * Gets the current user's home directory as defined in the * password database. * - * Note that in contrast to traditional UNIX tools, this function - * prefers <filename>passwd</filename> entries over the <envar>HOME</envar> - * environment variable. + * Note that in contrast to traditional UNIX tools, this function + * prefers <filename>passwd</filename> entries over the <envar>HOME</envar> + * environment variable. * - * One of the reasons for this decision is that applications in many - * cases need special handling to deal with the case where + * One of the reasons for this decision is that applications in many + * cases need special handling to deal with the case where * <envar>HOME</envar> is * <simplelist> * <member>Not owned by the user</member> * <member>Not writeable</member> * <member>Not even readable</member> * </simplelist> - * Since applications are in general <emphasis>not</emphasis> written - * to deal with these situations it was considered better to make - * g_get_home_dir() not pay attention to <envar>HOME</envar> and to + * Since applications are in general <emphasis>not</emphasis> written + * to deal with these situations it was considered better to make + * g_get_home_dir() not pay attention to <envar>HOME</envar> and to * return the real home directory for the user. If applications * want to pay attention to <envar>HOME</envar>, they can do: * |[ @@ -1835,11 +1837,11 @@ g_get_home_dir (void) /** * g_get_tmp_dir: * - * Gets the directory to use for temporary files. This is found from - * inspecting the environment variables <envar>TMPDIR</envar>, - * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none - * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows. - * The encoding of the returned string is system-defined. On Windows, + * Gets the directory to use for temporary files. This is found from + * inspecting the environment variables <envar>TMPDIR</envar>, + * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none + * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows. + * The encoding of the returned string is system-defined. On Windows, * it is always UTF-8. The return value is never %NULL. * * Returns: the directory to use for temporary files. @@ -1854,7 +1856,7 @@ g_get_tmp_dir (void) /** * g_get_host_name: * - * Return a name for the machine. + * Return a name for the machine. * * The returned name is not necessarily a fully-qualified domain name, * or even present in DNS or some other name service at all. It need @@ -1877,6 +1879,7 @@ g_get_host_name (void) g_get_any_init_locked (); return g_host_name; } +#endif G_LOCK_DEFINE_STATIC (g_prgname); static gchar *g_prgname = NULL; @@ -1884,13 +1887,13 @@ static gchar *g_prgname = NULL; /** * g_get_prgname: * - * Gets the name of the program. This name should <emphasis>not</emphasis> + * Gets the name of the program. This name should <emphasis>not</emphasis> * be localized, contrast with g_get_application_name(). - * (If you are using GDK or GTK+ the program name is set in gdk_init(), - * which is called by gtk_init(). The program name is found by taking + * (If you are using GDK or GTK+ the program name is set in gdk_init(), + * which is called by gtk_init(). The program name is found by taking * the last component of <literal>argv[0]</literal>.) * - * Returns: the name of the program. The returned string belongs + * Returns: the name of the program. The returned string belongs * to GLib and must not be modified or freed. */ gchar* @@ -1898,42 +1901,43 @@ g_get_prgname (void) { gchar* retval; - G_LOCK (g_prgname); -#ifdef G_OS_WIN32 - if (g_prgname == NULL) - { - static gboolean beenhere = FALSE; - - if (!beenhere) - { - gchar *utf8_buf = NULL; - wchar_t buf[MAX_PATH+1]; - - beenhere = TRUE; - if (GetModuleFileNameW (GetModuleHandle (NULL), - buf, G_N_ELEMENTS (buf)) > 0) - utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); - - if (utf8_buf) - { - g_prgname = g_path_get_basename (utf8_buf); - g_free (utf8_buf); - } - } - } -#endif - retval = g_prgname; - G_UNLOCK (g_prgname); - - return retval; +return 0; +// G_LOCK (g_prgname); +//#ifdef G_OS_WIN32 +// if (g_prgname == NULL) +// { +// static gboolean beenhere = FALSE; +// +// if (!beenhere) +// { +// gchar *utf8_buf = NULL; +// wchar_t buf[MAX_PATH+1]; +// +// beenhere = TRUE; +// if (GetModuleFileNameW (GetModuleHandle (NULL), +// buf, G_N_ELEMENTS (buf)) > 0) +// utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); +// +// if (utf8_buf) +// { +// g_prgname = g_path_get_basename (utf8_buf); +// g_free (utf8_buf); +// } +// } +// } +//#endif +// retval = g_prgname; +// G_UNLOCK (g_prgname); +// +// return retval; } /** * g_set_prgname: * @prgname: the name of the program. * - * Sets the name of the program. This name should <emphasis>not</emphasis> - * be localized, contrast with g_set_application_name(). Note that for + * Sets the name of the program. This name should <emphasis>not</emphasis> + * be localized, contrast with g_set_application_name(). Note that for * thread-safety reasons this function can only be called once. */ void @@ -1945,12 +1949,13 @@ g_set_prgname (const gchar *prgname) G_UNLOCK (g_prgname); } +#if NOT_NEEDED_FOR_NAVIT G_LOCK_DEFINE_STATIC (g_application_name); static gchar *g_application_name = NULL; /** * g_get_application_name: - * + * * Gets a human-readable name for the application, as set by * g_set_application_name(). This name should be localized if * possible, and is intended for display to the user. Contrast with @@ -1958,7 +1963,7 @@ static gchar *g_application_name = NULL; * g_set_application_name() has not been called, returns the result of * g_get_prgname() (which may be %NULL if g_set_prgname() has also not * been called). - * + * * Return value: human-readable application name. may return %NULL * * Since: 2.2 @@ -1974,7 +1979,7 @@ g_get_application_name (void) if (retval == NULL) return g_get_prgname (); - + return retval; } @@ -1993,14 +1998,14 @@ g_get_application_name (void) * * The application name will be used in contexts such as error messages, * or when displaying an application's name in the task list. - * + * * Since: 2.2 **/ void g_set_application_name (const gchar *application_name) { gboolean already_set = FALSE; - + G_LOCK (g_application_name); if (g_application_name) already_set = TRUE; @@ -2014,22 +2019,22 @@ g_set_application_name (const gchar *application_name) /** * g_get_user_data_dir: - * + * * Returns a base directory in which to access application data such - * as icons that is customized for a particular user. + * as icons that is customized for a particular user. * * On UNIX platforms this is determined using the mechanisms described in * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> * XDG Base Directory Specification</ulink> - * - * Return value: a string owned by GLib that must not be modified + * + * Return value: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ G_CONST_RETURN gchar* g_get_user_data_dir (void) { - gchar *data_dir; + gchar *data_dir; G_LOCK (g_utils_global); @@ -2048,10 +2053,10 @@ g_get_user_data_dir (void) g_get_any_init (); if (g_home_dir) - data_dir = g_build_filename (g_home_dir, ".local", + data_dir = g_build_filename (g_home_dir, ".local", "share", NULL); else - data_dir = g_build_filename (g_tmp_dir, g_user_name, ".local", + data_dir = g_build_filename (g_tmp_dir, g_user_name, ".local", "share", NULL); } @@ -2096,15 +2101,15 @@ g_init_user_config_dir (void) /** * g_get_user_config_dir: - * - * Returns a base directory in which to store user-specific application - * configuration information such as user preferences and settings. + * + * Returns a base directory in which to store user-specific application + * configuration information such as user preferences and settings. * * On UNIX platforms this is determined using the mechanisms described in * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> * XDG Base Directory Specification</ulink> - * - * Return value: a string owned by GLib that must not be modified + * + * Return value: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ @@ -2122,22 +2127,22 @@ g_get_user_config_dir (void) /** * g_get_user_cache_dir: - * + * * Returns a base directory in which to store non-essential, cached * data specific to particular user. * * On UNIX platforms this is determined using the mechanisms described in * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> * XDG Base Directory Specification</ulink> - * - * Return value: a string owned by GLib that must not be modified + * + * Return value: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ G_CONST_RETURN gchar* g_get_user_cache_dir (void) { - gchar *cache_dir; + gchar *cache_dir; G_LOCK (g_utils_global); @@ -2154,7 +2159,7 @@ g_get_user_cache_dir (void) if (!cache_dir || !cache_dir[0]) { g_get_any_init (); - + if (g_home_dir) cache_dir = g_build_filename (g_home_dir, ".cache", NULL); else @@ -2276,7 +2281,7 @@ load_user_special_dirs (void) g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = get_special_folder (CSIDL_COMMON_DOCUMENTS); CoTaskMemFree (wcp); } - + g_user_special_dirs[G_USER_DIRECTORY_TEMPLATES] = get_special_folder (CSIDL_TEMPLATES); g_user_special_dirs[G_USER_DIRECTORY_VIDEOS] = get_special_folder (CSIDL_MYVIDEO); } @@ -2296,10 +2301,10 @@ static void g_init_user_config_dir (void); * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: + * subject to the following conditions: * * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. + * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF @@ -2317,12 +2322,12 @@ load_user_special_dirs (void) gchar *data; gchar **lines; gint n_lines, i; - + g_init_user_config_dir (); config_file = g_build_filename (g_user_config_dir, "user-dirs.dirs", NULL); - + if (!g_file_get_contents (config_file, &data, NULL, NULL)) { g_free (config_file); @@ -2332,7 +2337,7 @@ load_user_special_dirs (void) lines = g_strsplit (data, "\n", -1); n_lines = g_strv_length (lines); g_free (data); - + for (i = 0; i < n_lines; i++) { gchar *buffer = lines[i]; @@ -2345,11 +2350,11 @@ load_user_special_dirs (void) len = strlen (buffer); if (len > 0 && buffer[len - 1] == '\n') buffer[len - 1] = 0; - + p = buffer; while (*p == ' ' || *p == '\t') p++; - + if (strncmp (p, "XDG_DESKTOP_DIR", strlen ("XDG_DESKTOP_DIR")) == 0) { directory = G_USER_DIRECTORY_DESKTOP; @@ -2421,12 +2426,12 @@ load_user_special_dirs (void) *d = 0; d = p; - + /* remove trailing slashes */ len = strlen (d); if (d[len - 1] == '/') d[len - 1] = 0; - + if (is_relative) { g_get_any_init (); @@ -2451,7 +2456,7 @@ load_user_special_dirs (void) * On Unix this is done using the XDG special user directories. * For compatibility with existing practise, %G_USER_DIRECTORY_DESKTOP * falls back to <filename>$HOME/Desktop</filename> when XDG special - * user directories have not been set up. + * user directories have not been set up. * * Depending on the platform, the user might be able to change the path * of the special directory without requiring the session to restart; GLib @@ -2557,7 +2562,7 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) gchar **retval; gchar *p; gchar *exe_root; - + if (address) { G_LOCK (g_utils_global); @@ -2569,7 +2574,7 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) else { retval = g_hash_table_lookup (per_module_data_dirs, hmodule); - + if (retval != NULL) { G_UNLOCK (g_utils_global); @@ -2585,12 +2590,12 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) p = get_special_folder (CSIDL_COMMON_APPDATA); if (p) g_array_append_val (data_dirs, p); - + /* Documents and Settings\All Users\Documents */ p = get_special_folder (CSIDL_COMMON_DOCUMENTS); if (p) g_array_append_val (data_dirs, p); - + /* Using the above subfolders of Documents and Settings perhaps * makes sense from a Windows perspective. * @@ -2616,7 +2621,7 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) p = get_module_share_dir (address); if (p) g_array_append_val (data_dirs, p); - + if (glib_dll != NULL) { gchar *glib_root = g_win32_get_package_installation_directory_of_module (glib_dll); @@ -2625,7 +2630,7 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) g_array_append_val (data_dirs, p); g_free (glib_root); } - + exe_root = g_win32_get_package_installation_directory_of_module (NULL); p = g_build_filename (exe_root, "share", NULL); if (p) @@ -2648,14 +2653,14 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) /** * g_get_system_data_dirs: - * - * Returns an ordered list of base directories in which to access + * + * Returns an ordered list of base directories in which to access * system-wide application data. * * On UNIX platforms this is determined using the mechanisms described in * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> * XDG Base Directory Specification</ulink> - * + * * On Windows the first elements in the list are the Application Data * and Documents folders for All Users. (These can be determined only * on Windows 2000 or later and are not present in the list on other @@ -2665,7 +2670,7 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) * Then follows the "share" subfolder in the installation folder for * the package containing the DLL that calls this function, if it can * be determined. - * + * * Finally the list contains the "share" subfolder in the installation * folder for GLib, and in the installation folder for the package the * application's .exe file belongs to. @@ -2678,11 +2683,11 @@ g_win32_get_system_data_dirs_for_module (gconstpointer address) * Note that on Windows the returned list can vary depending on where * this function is called. * - * Return value: a %NULL-terminated array of strings owned by GLib that must + * Return value: a %NULL-terminated array of strings owned by GLib that must * not be modified or freed. * Since: 2.6 **/ -G_CONST_RETURN gchar * G_CONST_RETURN * +G_CONST_RETURN gchar * G_CONST_RETURN * g_get_system_data_dirs (void) { gchar **data_dir_vector; @@ -2714,15 +2719,15 @@ g_get_system_data_dirs (void) /** * g_get_system_config_dirs: - * - * Returns an ordered list of base directories in which to access + * + * Returns an ordered list of base directories in which to access * system-wide configuration information. * * On UNIX platforms this is determined using the mechanisms described in * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec"> * XDG Base Directory Specification</ulink> - * - * Return value: a %NULL-terminated array of strings owned by GLib that must + * + * Return value: a %NULL-terminated array of strings owned by GLib that must * not be modified or freed. * Since: 2.6 **/ @@ -2775,7 +2780,7 @@ read_aliases (gchar *file) { FILE *fp; char buf[256]; - + if (!alias_table) alias_table = g_hash_table_new (g_str_hash, g_str_equal); fp = fopen (file,"r"); @@ -2805,7 +2810,7 @@ read_aliases (gchar *file) /* The line only had one column */ if (!q || *q == '\0') continue; - + /* Read second column */ for (p = q; *p; p++) { if ((*p == '\t') || (*p == ' ')) { @@ -2866,9 +2871,9 @@ enum */ static guint explode_locale (const gchar *locale, - gchar **language, - gchar **territory, - gchar **codeset, + gchar **language, + gchar **territory, + gchar **codeset, gchar **modifier) { const gchar *uscore_pos; @@ -2983,7 +2988,7 @@ guess_category_value (const gchar *category_name) systems this can be done by the `setlocale' function itself. */ /* Setting of LC_ALL overwrites all other. */ - retval = g_getenv ("LC_ALL"); + retval = g_getenv ("LC_ALL"); if ((retval != NULL) && (retval[0] != '\0')) return retval; @@ -3007,7 +3012,7 @@ guess_category_value (const gchar *category_name) retval = g_win32_getlocale (); if ((retval != NULL) && (retval[0] != '\0')) return retval; -#endif +#endif return NULL; } @@ -3030,25 +3035,25 @@ language_names_cache_free (gpointer data) /** * g_get_language_names: - * - * Computes a list of applicable locale names, which can be used to - * e.g. construct locale-dependent filenames or search paths. The returned - * list is sorted from most desirable to least desirable and always contains + * + * Computes a list of applicable locale names, which can be used to + * e.g. construct locale-dependent filenames or search paths. The returned + * list is sorted from most desirable to least desirable and always contains * the default locale "C". * * For example, if LANGUAGE=de:en_US, then the returned list is * "de", "en_US", "en", "C". * - * This function consults the environment variables <envar>LANGUAGE</envar>, - * <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar> + * This function consults the environment variables <envar>LANGUAGE</envar>, + * <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar> * to find the list of locales specified by the user. - * - * Return value: a %NULL-terminated array of strings owned by GLib + * + * Return value: a %NULL-terminated array of strings owned by GLib * that must not be modified or freed. * * Since: 2.6 **/ -G_CONST_RETURN gchar * G_CONST_RETURN * +G_CONST_RETURN gchar * G_CONST_RETURN * g_get_language_names (void) { static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; @@ -3103,7 +3108,7 @@ g_get_language_names (void) * @v: a #gpointer key * * Converts a gpointer to a hash value. - * It can be passed to g_hash_table_new() as the @hash_func parameter, + * It can be passed to g_hash_table_new() as the @hash_func parameter, * when using pointers as keys in a #GHashTable. * * Returns: a hash value corresponding to the key. @@ -3122,7 +3127,7 @@ g_direct_hash (gconstpointer v) * Compares two #gpointer arguments and returns %TRUE if they are equal. * It can be passed to g_hash_table_new() as the @key_equal_func * parameter, when using pointers as keys in a #GHashTable. - * + * * Returns: %TRUE if the two keys match. */ gboolean @@ -3137,11 +3142,11 @@ g_direct_equal (gconstpointer v1, * @v1: a pointer to a #gint key. * @v2: a pointer to a #gint key to compare with @v1. * - * Compares the two #gint values being pointed to and returns + * Compares the two #gint values being pointed to and returns * %TRUE if they are equal. * It can be passed to g_hash_table_new() as the @key_equal_func * parameter, when using pointers to integers as keys in a #GHashTable. - * + * * Returns: %TRUE if the two keys match. */ gboolean @@ -3156,7 +3161,7 @@ g_int_equal (gconstpointer v1, * @v: a pointer to a #gint key * * Converts a pointer to a #gint to a hash value. - * It can be passed to g_hash_table_new() as the @hash_func parameter, + * It can be passed to g_hash_table_new() as the @hash_func parameter, * when using pointers to integers values as keys in a #GHashTable. * * Returns: a hash value corresponding to the key. @@ -3167,11 +3172,11 @@ g_int_hash (gconstpointer v) return *(const gint*) v; } -#if NOT_NEEDED_FOR_NAVIT +#if NOT_NEEDED_FOR_NAVIT /** * g_nullify_pointer: * @nullify_location: the memory address of the pointer. - * + * * Set the pointer at the specified location to %NULL. **/ void @@ -3184,9 +3189,9 @@ g_nullify_pointer (gpointer *nullify_location) /** * g_get_codeset: - * + * * Get the codeset for the current locale. - * + * * Return value: a newly allocated string containing the name * of the codeset. This string must be freed with g_free(). **/ @@ -3287,7 +3292,7 @@ glib_gettext (const gchar *str) # endif _glib_gettext_initialized = TRUE; } - + return g_dgettext (GETTEXT_PACKAGE, str); } @@ -3347,8 +3352,8 @@ g_getenv (const gchar *variable) #undef g_setenv gboolean -g_setenv (const gchar *variable, - const gchar *value, +g_setenv (const gchar *variable, + const gchar *value, gboolean overwrite) { gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL); diff --git a/navit/support/glib/gutils.h b/navit/support/glib/gutils.h new file mode 100755 index 000000000..bb4da8055 --- /dev/null +++ b/navit/support/glib/gutils.h @@ -0,0 +1,490 @@ +/* GLIB - Library of useful routines for C programming + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GLib Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GLib Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GLib at ftp://ftp.gtk.org/pub/gtk/. + */ + +#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) +#error "Only <glib.h> can be included directly." +#endif + +#ifndef __G_UTILS_H__ +#define __G_UTILS_H__ + +#include <glib/gtypes.h> +#include <stdarg.h> + +G_BEGIN_DECLS + +#ifdef G_OS_WIN32 + +/* On Win32, the canonical directory separator is the backslash, and + * the search path separator is the semicolon. Note that also the + * (forward) slash works as directory separator. + */ +#define G_DIR_SEPARATOR '\\' +#define G_DIR_SEPARATOR_S "\\" +#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/') +#define G_SEARCHPATH_SEPARATOR ';' +#define G_SEARCHPATH_SEPARATOR_S ";" + +#else /* !G_OS_WIN32 */ + +/* Unix */ + +#define G_DIR_SEPARATOR '/' +#define G_DIR_SEPARATOR_S "/" +#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR) +#define G_SEARCHPATH_SEPARATOR ':' +#define G_SEARCHPATH_SEPARATOR_S ":" + +#endif /* !G_OS_WIN32 */ + +/* Define G_VA_COPY() to do the right thing for copying va_list variables. + * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy. + */ +#if !defined (G_VA_COPY) +# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) +# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) +# elif defined (G_VA_COPY_AS_ARRAY) +# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list)) +# else /* va_list is a pointer */ +# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2)) +# endif /* va_list is a pointer */ +#endif /* !G_VA_COPY */ + +/* inlining hassle. for compilers that don't allow the `inline' keyword, + * mostly because of strict ANSI C compliance or dumbness, we try to fall + * back to either `__inline__' or `__inline'. + * G_CAN_INLINE is defined in glibconfig.h if the compiler seems to be + * actually *capable* to do function inlining, in which case inline + * function bodies do make sense. we also define G_INLINE_FUNC to properly + * export the function prototypes if no inlining can be performed. + * inline function bodies have to be special cased with G_CAN_INLINE and a + * .c file specific macro to allow one compiled instance with extern linkage + * of the functions by defining G_IMPLEMENT_INLINES and the .c file macro. + */ +#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__) +# undef inline +# define inline __inline__ +#elif !defined (G_HAVE_INLINE) +# undef inline +# if defined (G_HAVE___INLINE__) +# define inline __inline__ +# elif defined (G_HAVE___INLINE) +# define inline __inline +# else /* !inline && !__inline__ && !__inline */ +# define inline /* don't inline, then */ +# endif +#endif +#ifdef G_IMPLEMENT_INLINES +# define G_INLINE_FUNC +# undef G_CAN_INLINE +#elif defined (__GNUC__) +# define G_INLINE_FUNC static __inline __attribute__ ((unused)) +#elif defined (G_CAN_INLINE) +# define G_INLINE_FUNC static inline +#else /* can't inline */ +# define G_INLINE_FUNC +#endif /* !G_INLINE_FUNC */ + +/* Retrive static string info + */ +#ifdef G_OS_WIN32 +#define g_get_user_name g_get_user_name_utf8 +#define g_get_real_name g_get_real_name_utf8 +#define g_get_home_dir g_get_home_dir_utf8 +#define g_get_tmp_dir g_get_tmp_dir_utf8 +#endif + +G_CONST_RETURN gchar* g_get_user_name (void); +G_CONST_RETURN gchar* g_get_real_name (void); +G_CONST_RETURN gchar* g_get_home_dir (void); +G_CONST_RETURN gchar* g_get_tmp_dir (void); +G_CONST_RETURN gchar* g_get_host_name (void); +gchar* g_get_prgname (void); +void g_set_prgname (const gchar *prgname); +G_CONST_RETURN gchar* g_get_application_name (void); +void g_set_application_name (const gchar *application_name); + +void g_reload_user_special_dirs_cache (void); +G_CONST_RETURN gchar* g_get_user_data_dir (void); +G_CONST_RETURN gchar* g_get_user_config_dir (void); +G_CONST_RETURN gchar* g_get_user_cache_dir (void); +G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_data_dirs (void); + +#ifdef G_OS_WIN32 +/* This functions is not part of the public GLib API */ +G_CONST_RETURN gchar* G_CONST_RETURN * g_win32_get_system_data_dirs_for_module (void (*address_of_function)(void)); +#endif + +#if defined (G_OS_WIN32) && defined (G_CAN_INLINE) && !defined (__cplusplus) +/* This function is not part of the public GLib API either. Just call + * g_get_system_data_dirs() in your code, never mind that that is + * actually a macro and you will in fact call this inline function. + */ +static inline G_CONST_RETURN gchar * G_CONST_RETURN * +_g_win32_get_system_data_dirs (void) +{ + return g_win32_get_system_data_dirs_for_module ((void (*)(void)) &_g_win32_get_system_data_dirs); +} +#define g_get_system_data_dirs _g_win32_get_system_data_dirs +#endif + +G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void); + +G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void); + +/** + * GUserDirectory: + * @G_USER_DIRECTORY_DESKTOP: the user's Desktop directory + * @G_USER_DIRECTORY_DOCUMENTS: the user's Documents directory + * @G_USER_DIRECTORY_DOWNLOAD: the user's Downloads directory + * @G_USER_DIRECTORY_MUSIC: the user's Music directory + * @G_USER_DIRECTORY_PICTURES: the user's Pictures directory + * @G_USER_DIRECTORY_PUBLIC_SHARE: the user's shared directory + * @G_USER_DIRECTORY_TEMPLATES: the user's Templates directory + * @G_USER_DIRECTORY_VIDEOS: the user's Movies directory + * @G_USER_N_DIRECTORIES: the number of enum values + * + * These are logical ids for special directories which are defined + * depending on the platform used. You should use g_get_user_special_dir() + * to retrieve the full path associated to the logical id. + * + * The #GUserDirectory enumeration can be extended at later date. Not + * every platform has a directory for every logical id in this + * enumeration. + * + * Since: 2.14 + */ +typedef enum { + G_USER_DIRECTORY_DESKTOP, + G_USER_DIRECTORY_DOCUMENTS, + G_USER_DIRECTORY_DOWNLOAD, + G_USER_DIRECTORY_MUSIC, + G_USER_DIRECTORY_PICTURES, + G_USER_DIRECTORY_PUBLIC_SHARE, + G_USER_DIRECTORY_TEMPLATES, + G_USER_DIRECTORY_VIDEOS, + + G_USER_N_DIRECTORIES +} GUserDirectory; + +G_CONST_RETURN gchar* g_get_user_special_dir (GUserDirectory directory); + +typedef struct _GDebugKey GDebugKey; +struct _GDebugKey +{ + const gchar *key; + guint value; +}; + +/* Miscellaneous utility functions + */ +guint g_parse_debug_string (const gchar *string, + const GDebugKey *keys, + guint nkeys); + +gint g_snprintf (gchar *string, + gulong n, + gchar const *format, + ...) G_GNUC_PRINTF (3, 4); +gint g_vsnprintf (gchar *string, + gulong n, + gchar const *format, + va_list args); + +/* Check if a file name is an absolute path */ +gboolean g_path_is_absolute (const gchar *file_name); + +/* In case of absolute paths, skip the root part */ +G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name); + +#ifndef G_DISABLE_DEPRECATED + +/* These two functions are deprecated and will be removed in the next + * major release of GLib. Use g_path_get_dirname/g_path_get_basename + * instead. Whatch out! The string returned by g_path_get_basename + * must be g_freed, while the string returned by g_basename must not.*/ +G_CONST_RETURN gchar* g_basename (const gchar *file_name); +#define g_dirname g_path_get_dirname + +#endif /* G_DISABLE_DEPRECATED */ + +#ifdef G_OS_WIN32 +#define g_get_current_dir g_get_current_dir_utf8 +#endif + +/* The returned strings are newly allocated with g_malloc() */ +gchar* g_get_current_dir (void); +gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC; +gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC; + +/* Set the pointer at the specified location to NULL */ +void g_nullify_pointer (gpointer *nullify_location); + +/* return the environment string for the variable. The returned memory + * must not be freed. */ +#ifdef G_OS_WIN32 +#define g_getenv g_getenv_utf8 +#define g_setenv g_setenv_utf8 +#define g_unsetenv g_unsetenv_utf8 +#define g_find_program_in_path g_find_program_in_path_utf8 +#endif + +G_CONST_RETURN gchar* g_getenv (const gchar *variable); +gboolean g_setenv (const gchar *variable, + const gchar *value, + gboolean overwrite); +void g_unsetenv (const gchar *variable); +gchar** g_listenv (void); + +/* private */ +const gchar* _g_getenv_nomalloc (const gchar *variable, + gchar buffer[1024]); + +/* we try to provide a useful equivalent for ATEXIT if it is + * not defined, but use is actually abandoned. people should + * use g_atexit() instead. + */ +typedef void (*GVoidFunc) (void); +#ifndef ATEXIT +# define ATEXIT(proc) g_ATEXIT(proc) +#else +# define G_NATIVE_ATEXIT +#endif /* ATEXIT */ +/* we use a GLib function as a replacement for ATEXIT, so + * the programmer is not required to check the return value + * (if there is any in the implementation) and doesn't encounter + * missing include files. + */ +void g_atexit (GVoidFunc func); + +#ifdef G_OS_WIN32 +/* It's a bad idea to wrap atexit() on Windows. If the GLib DLL calls + * atexit(), the function will be called when the GLib DLL is detached + * from the program, which is not what the caller wants. The caller + * wants the function to be called when it *itself* exits (or is + * detached, in case the caller, too, is a DLL). + */ +#if (defined(__MINGW_H) && !defined(_STDLIB_H_)) || (defined(_MSC_VER) && !defined(_INC_STDLIB)) +int atexit (void (*)(void)); +#endif +#define g_atexit(func) atexit(func) +#endif + +/* Look for an executable in PATH, following execvp() rules */ +gchar* g_find_program_in_path (const gchar *program); + +/* Bit tests + */ +G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask, + gint nth_bit) G_GNUC_CONST; +G_INLINE_FUNC gint g_bit_nth_msf (gulong mask, + gint nth_bit) G_GNUC_CONST; +G_INLINE_FUNC guint g_bit_storage (gulong number) G_GNUC_CONST; + +/* Trash Stacks + * elements need to be >= sizeof (gpointer) + */ +typedef struct _GTrashStack GTrashStack; +struct _GTrashStack +{ + GTrashStack *next; +}; + +G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p, + gpointer data_p); +G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p); +G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p); +G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p); + +/* inline function implementations + */ +#if defined (G_CAN_INLINE) || defined (__G_UTILS_C__) +G_INLINE_FUNC gint +g_bit_nth_lsf (gulong mask, + gint nth_bit) +{ + if (G_UNLIKELY (nth_bit < -1)) + nth_bit = -1; + while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1)) + { + nth_bit++; + if (mask & (1UL << nth_bit)) + return nth_bit; + } + return -1; +} +G_INLINE_FUNC gint +g_bit_nth_msf (gulong mask, + gint nth_bit) +{ + if (nth_bit < 0 || G_UNLIKELY (nth_bit > GLIB_SIZEOF_LONG * 8)) + nth_bit = GLIB_SIZEOF_LONG * 8; + while (nth_bit > 0) + { + nth_bit--; + if (mask & (1UL << nth_bit)) + return nth_bit; + } + return -1; +} +G_INLINE_FUNC guint +g_bit_storage (gulong number) +{ +#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) + return G_LIKELY (number) ? + ((GLIB_SIZEOF_LONG * 8 - 1) ^ __builtin_clzl(number)) + 1 : 1; +#else + register guint n_bits = 0; + + do + { + n_bits++; + number >>= 1; + } + while (number); + return n_bits; +#endif +} +G_INLINE_FUNC void +g_trash_stack_push (GTrashStack **stack_p, + gpointer data_p) +{ + GTrashStack *data = (GTrashStack *) data_p; + + data->next = *stack_p; + *stack_p = data; +} +G_INLINE_FUNC gpointer +g_trash_stack_pop (GTrashStack **stack_p) +{ + GTrashStack *data; + + data = *stack_p; + if (data) + { + *stack_p = data->next; + /* NULLify private pointer here, most platforms store NULL as + * subsequent 0 bytes + */ + data->next = NULL; + } + + return data; +} +G_INLINE_FUNC gpointer +g_trash_stack_peek (GTrashStack **stack_p) +{ + GTrashStack *data; + + data = *stack_p; + + return data; +} +G_INLINE_FUNC guint +g_trash_stack_height (GTrashStack **stack_p) +{ + GTrashStack *data; + guint i = 0; + + for (data = *stack_p; data; data = data->next) + i++; + + return i; +} +#endif /* G_CAN_INLINE || __G_UTILS_C__ */ + +/* Glib version. + * we prefix variable declarations so they can + * properly get exported in windows dlls. + */ +GLIB_VAR const guint glib_major_version; +GLIB_VAR const guint glib_minor_version; +GLIB_VAR const guint glib_micro_version; +GLIB_VAR const guint glib_interface_age; +GLIB_VAR const guint glib_binary_age; + +const gchar * glib_check_version (guint required_major, + guint required_minor, + guint required_micro); + +#define GLIB_CHECK_VERSION(major,minor,micro) \ + (GLIB_MAJOR_VERSION > (major) || \ + (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \ + (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \ + GLIB_MICRO_VERSION >= (micro))) + +G_END_DECLS + +#ifndef G_DISABLE_DEPRECATED + +/* + * This macro is deprecated. This DllMain() is too complex. It is + * recommended to write an explicit minimal DLlMain() that just saves + * the handle to the DLL and then use that handle instead, for + * instance passing it to + * g_win32_get_package_installation_directory_of_module(). + * + * On Windows, this macro defines a DllMain function that stores the + * actual DLL name that the code being compiled will be included in. + * STATIC should be empty or 'static'. DLL_NAME is the name of the + * (pointer to the) char array where the DLL name will be stored. If + * this is used, you must also include <windows.h>. If you need a more complex + * DLL entry point function, you cannot use this. + * + * On non-Windows platforms, expands to nothing. + */ + +#ifndef G_PLATFORM_WIN32 +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) +#else +# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \ +static char *dll_name; \ + \ +BOOL WINAPI \ +DllMain (HINSTANCE hinstDLL, \ + DWORD fdwReason, \ + LPVOID lpvReserved) \ +{ \ + wchar_t wcbfr[1000]; \ + char *tem; \ + switch (fdwReason) \ + { \ + case DLL_PROCESS_ATTACH: \ + GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \ + tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \ + dll_name = g_path_get_basename (tem); \ + g_free (tem); \ + break; \ + } \ + \ + return TRUE; \ +} + +#endif /* !G_DISABLE_DEPRECATED */ + +#endif /* G_PLATFORM_WIN32 */ + +#endif /* __G_UTILS_H__ */ |