1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 /* system specific config file
24 #include <glibconfig.h>
26 /* include varargs functions for assertment macros
30 /* optionally feature DMALLOC memory allocation debugger
39 /* On native Win32, directory separator is the backslash, and search path
40 * separator is the semicolon.
42 #define G_DIR_SEPARATOR '\\'
43 #define G_DIR_SEPARATOR_S "\\"
44 #define G_SEARCHPATH_SEPARATOR ';'
45 #define G_SEARCHPATH_SEPARATOR_S ";"
47 #else /* !NATIVE_WIN32 */
51 #define G_DIR_SEPARATOR '/'
52 #define G_DIR_SEPARATOR_S "/"
53 #define G_SEARCHPATH_SEPARATOR ':'
54 #define G_SEARCHPATH_SEPARATOR_S ":"
56 #endif /* !NATIVE_WIN32 */
59 /* Make MSVC more pedantic, this is a recommended pragma list
60 * from _Win32_Programming_ by Rector and Newcomer.
62 #pragma warning(error:4002)
63 #pragma warning(error:4003)
64 #pragma warning(1:4010)
65 #pragma warning(error:4013)
66 #pragma warning(1:4016)
67 #pragma warning(error:4020)
68 #pragma warning(error:4021)
69 #pragma warning(error:4027)
70 #pragma warning(error:4029)
71 #pragma warning(error:4033)
72 #pragma warning(error:4035)
73 #pragma warning(error:4045)
74 #pragma warning(error:4047)
75 #pragma warning(error:4049)
76 #pragma warning(error:4053)
77 #pragma warning(error:4071)
78 #pragma warning(disable:4101)
79 #pragma warning(error:4150)
81 #pragma warning(disable:4244) /* No possible loss of data warnings, please */
84 /* glib provides definitions for the extrema of many
85 * of the standard types. These are:
97 * We include limits.h before float.h to work around a egcs 1.1
98 * oddity on Solaris 2.5.1
102 # define G_MINSHORT SHRT_MIN
103 # define G_MAXSHORT SHRT_MAX
104 # define G_MININT INT_MIN
105 # define G_MAXINT INT_MAX
106 # define G_MINLONG LONG_MIN
107 # define G_MAXLONG LONG_MAX
111 # endif /* HAVE_FLOAT_H */
112 # define G_MINSHORT MINSHORT
113 # define G_MAXSHORT MAXSHORT
114 # define G_MININT MININT
115 # define G_MAXINT MAXINT
116 # define G_MINLONG MINLONG
117 # define G_MAXLONG MAXLONG
118 #endif /* HAVE_VALUES_H */
122 # define G_MINFLOAT FLT_MIN
123 # define G_MAXFLOAT FLT_MAX
124 # define G_MINDOUBLE DBL_MIN
125 # define G_MAXDOUBLE DBL_MAX
128 # define G_MINFLOAT MINFLOAT
129 # define G_MAXFLOAT MAXFLOAT
130 # define G_MINDOUBLE MINDOUBLE
131 # define G_MAXDOUBLE MAXDOUBLE
132 #endif /* HAVE_VALUES_H */
137 #endif /* __cplusplus */
140 /* Provide definitions for some commonly used macros.
141 * Some of them are only provided if they haven't already
142 * been defined. It is assumed that if they are already
143 * defined then the current definition is correct.
146 #define NULL ((void*) 0)
154 #define TRUE (!FALSE)
158 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
161 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
164 #define ABS(a) (((a) < 0) ? -(a) : (a))
167 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
170 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
171 * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
173 #if !defined (G_VA_COPY)
174 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
175 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
176 # elif defined (G_VA_COPY_AS_ARRAY)
177 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
178 # else /* va_list is a pointer */
179 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
180 # endif /* va_list is a pointer */
181 #endif /* !G_VA_COPY */
184 /* Provide simple enum value macro wrappers that ease automated
185 * enum value stringification code. [abandoned]
187 #if !defined (G_CODE_GENERATION)
188 #define G_ENUM( EnumerationName ) EnumerationName
189 #define G_FLAGS( EnumerationName ) EnumerationName
190 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
191 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
192 #else /* G_CODE_GENERATION */
193 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
194 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
195 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
196 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
197 #endif /* G_CODE_GENERATION */
200 /* inlining hassle. for compilers that don't allow the `inline' keyword,
201 * mostly because of strict ANSI C compliance or dumbness, we try to fall
202 * back to either `__inline__' or `__inline'.
203 * we define G_CAN_INLINE, if the compiler seems to be actually
204 * *capable* to do function inlining, in which case inline function bodys
205 * do make sense. we also define G_INLINE_FUNC to properly export the
206 * function prototypes if no inlinig can be performed.
207 * we special case most of the stuff, so inline functions can have a normal
208 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
210 #ifndef G_INLINE_FUNC
211 # define G_CAN_INLINE 1
214 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
216 # define inline __inline__
218 #else /* !G_HAVE_INLINE */
220 # if defined (G_HAVE___INLINE__)
221 # define inline __inline__
222 # else /* !inline && !__inline__ */
223 # if defined (G_HAVE___INLINE)
224 # define inline __inline
225 # else /* !inline && !__inline__ && !__inline */
226 # define inline /* don't inline, then */
227 # ifndef G_INLINE_FUNC
233 #ifndef G_INLINE_FUNC
236 # define G_INLINE_FUNC extern inline
239 # define G_INLINE_FUNC extern
241 # else /* !__GNUC__ */
243 # define G_INLINE_FUNC static inline
245 # define G_INLINE_FUNC extern
247 # endif /* !__GNUC__ */
248 #endif /* !G_INLINE_FUNC */
251 /* Provide simple macro statement wrappers (adapted from Perl):
252 * G_STMT_START { statements; } G_STMT_END;
253 * can be used as a single statement, as in
254 * if (x) G_STMT_START { ... } G_STMT_END; else ...
256 * For gcc we will wrap the statements within `({' and `})' braces.
257 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
258 * and otherwise within `do' and `while (0)'.
260 #if !(defined (G_STMT_START) && defined (G_STMT_END))
261 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
262 # define G_STMT_START (void)(
263 # define G_STMT_END )
265 # if (defined (sun) || defined (__sun__))
266 # define G_STMT_START if (1)
267 # define G_STMT_END else (void)0
269 # define G_STMT_START do
270 # define G_STMT_END while (0)
276 /* Provide macros to feature the GCC function attribute.
278 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
279 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
280 __attribute__((format (printf, format_idx, arg_idx)))
281 #define G_GNUC_SCANF( format_idx, arg_idx ) \
282 __attribute__((format (scanf, format_idx, arg_idx)))
283 #define G_GNUC_FORMAT( arg_idx ) \
284 __attribute__((format_arg (arg_idx)))
285 #define G_GNUC_NORETURN \
286 __attribute__((noreturn))
287 #define G_GNUC_CONST \
288 __attribute__((const))
289 #define G_GNUC_UNUSED \
290 __attribute__((unused))
291 #else /* !__GNUC__ */
292 #define G_GNUC_PRINTF( format_idx, arg_idx )
293 #define G_GNUC_SCANF( format_idx, arg_idx )
294 #define G_GNUC_FORMAT( arg_idx )
295 #define G_GNUC_NORETURN
297 #define G_GNUC_UNUSED
298 #endif /* !__GNUC__ */
301 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
302 * macros, so we can refer to them as strings unconditionally.
305 #define G_GNUC_FUNCTION (__FUNCTION__)
306 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
307 #else /* !__GNUC__ */
308 #define G_GNUC_FUNCTION ("")
309 #define G_GNUC_PRETTY_FUNCTION ("")
310 #endif /* !__GNUC__ */
313 /* we try to provide a usefull equivalent for ATEXIT if it is
314 * not defined, but use is actually abandoned. people should
315 * use g_atexit() instead.
316 * keep this in sync with gutils.c.
320 # ifdef NeXT /* @#%@! NeXTStep */
321 # define ATEXIT(proc) (!atexit (proc))
323 # define ATEXIT(proc) (atexit (proc))
325 # elif defined (HAVE_ON_EXIT)
326 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
328 # error Could not determine proper atexit() implementation
331 # define G_NATIVE_ATEXIT
334 /* Hacker macro to place breakpoints for x86 machines.
335 * Actual use is strongly deprecated of course ;)
337 #if defined (__i386__) && defined (__GNUC__)
338 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
339 #else /* !__i386__ */
340 #define G_BREAKPOINT()
341 #endif /* __i386__ */
344 /* Provide macros for easily allocating memory. The macros
345 * will cast the allocated memory to the specified type
346 * in order to avoid compiler warnings. (Makes the code neater).
350 # define g_new(type, count) (ALLOC (type, count))
351 # define g_new0(type, count) (CALLOC (type, count))
352 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
353 #else /* __DMALLOC_H__ */
354 # define g_new(type, count) \
355 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
356 # define g_new0(type, count) \
357 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
358 # define g_renew(type, mem, count) \
359 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
360 #endif /* __DMALLOC_H__ */
362 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
363 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
365 sizeof (type) * (pre_alloc), \
368 #define g_chunk_new(type, chunk) ( \
369 (type *) g_mem_chunk_alloc (chunk) \
371 #define g_chunk_new0(type, chunk) ( \
372 (type *) g_mem_chunk_alloc0 (chunk) \
374 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
375 g_mem_chunk_free ((mem_chunk), (mem)); \
379 #define g_string(x) #x
382 /* Provide macros for error handling. The "assert" macros will
383 * exit on failure. The "return" macros will exit the current
384 * function. Two different definitions are given for the macros
385 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
386 * __PRETTY_FUNCTION__ capability.
389 #ifdef G_DISABLE_ASSERT
391 #define g_assert(expr)
392 #define g_assert_not_reached()
394 #else /* !G_DISABLE_ASSERT */
398 #define g_assert(expr) G_STMT_START{ \
400 g_log (G_LOG_DOMAIN, \
402 "file %s: line %d (%s): assertion failed: (%s)", \
405 __PRETTY_FUNCTION__, \
408 #define g_assert_not_reached() G_STMT_START{ \
409 g_log (G_LOG_DOMAIN, \
411 "file %s: line %d (%s): should not be reached", \
414 __PRETTY_FUNCTION__); }G_STMT_END
416 #else /* !__GNUC__ */
418 #define g_assert(expr) G_STMT_START{ \
420 g_log (G_LOG_DOMAIN, \
422 "file %s: line %d: assertion failed: (%s)", \
427 #define g_assert_not_reached() G_STMT_START{ \
428 g_log (G_LOG_DOMAIN, \
430 "file %s: line %d: should not be reached", \
432 __LINE__); }G_STMT_END
434 #endif /* __GNUC__ */
436 #endif /* !G_DISABLE_ASSERT */
439 #ifdef G_DISABLE_CHECKS
441 #define g_return_if_fail(expr)
442 #define g_return_val_if_fail(expr,val)
444 #else /* !G_DISABLE_CHECKS */
448 #define g_return_if_fail(expr) G_STMT_START{ \
451 g_log (G_LOG_DOMAIN, \
452 G_LOG_LEVEL_CRITICAL, \
453 "file %s: line %d (%s): assertion `%s' failed.", \
456 __PRETTY_FUNCTION__, \
461 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
464 g_log (G_LOG_DOMAIN, \
465 G_LOG_LEVEL_CRITICAL, \
466 "file %s: line %d (%s): assertion `%s' failed.", \
469 __PRETTY_FUNCTION__, \
474 #else /* !__GNUC__ */
476 #define g_return_if_fail(expr) G_STMT_START{ \
479 g_log (G_LOG_DOMAIN, \
480 G_LOG_LEVEL_CRITICAL, \
481 "file %s: line %d: assertion `%s' failed.", \
488 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
491 g_log (G_LOG_DOMAIN, \
492 G_LOG_LEVEL_CRITICAL, \
493 "file %s: line %d: assertion `%s' failed.", \
500 #endif /* !__GNUC__ */
502 #endif /* !G_DISABLE_CHECKS */
505 /* Portable endian checks and conversions
508 #define G_LITTLE_ENDIAN 1234
509 #define G_BIG_ENDIAN 4321
510 #define G_PDP_ENDIAN 3412 / /* unused, need specific PDP check */
512 #ifdef WORDS_BIGENDIAN
513 #define G_BYTE_ORDER G_BIG_ENDIAN
515 #define G_BYTE_ORDER G_LITTLE_ENDIAN
518 #define GULONG_SWAP_LE_BE(long_val) (((gulong) \
519 (((gulong) (long_val)) & 0x000000ffU) << 24) | \
520 (((gulong) (long_val)) & 0x0000ff00U) << 8) | \
521 (((gulong) (long_val)) & 0x00ff0000U) >> 8) | \
522 (((gulong) (long_val)) & 0xff000000U) >> 24)))
523 #define GULONG_SWAP_LE_PDP(long_val) (((gulong) \
524 (((gulong) (long_val)) & 0x0000ffffU) << 16) | \
525 (((gulong) (long_val)) & 0xffff0000U) >> 16)))
526 #define GULONG_SWAP_BE_PDP(long_val) (((gulong) \
527 (((gulong) (long_val)) & 0x000000ffU) << 8) | \
528 (((gulong) (long_val)) & 0x0000ff00U) >> 8) | \
529 (((gulong) (long_val)) & 0x00ff0000U) << 8) | \
530 (((gulong) (long_val)) & 0xff000000U) >> 8)))
532 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
533 # define GLONG_TO_LE(long_val) ((glong) (long_val))
534 # define GULONG_TO_LE(long_val) ((gulong) (long_val))
535 # define GLONG_TO_BE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
536 # define GULONG_TO_BE(long_val) (GULONG_SWAP_LE_BE (long_val))
537 # define GLONG_FROM_LE(long_val) ((glong) (long_val))
538 # define GULONG_FROM_LE(long_val) ((gulong) (long_val))
539 # define GLONG_FROM_BE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
540 # define GULONG_FROM_BE(long_val) (GULONG_SWAP_LE_BE (long_val))
541 #elif G_BYTE_ORDER == G_BIG_ENDIAN
542 # define GLONG_TO_LE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
543 # define GULONG_TO_LE(long_val) (GULONG_SWAP_LE_BE (long_val))
544 # define GLONG_TO_BE(long_val) ((glong) (long_val))
545 # define GULONG_TO_BE(long_val) ((gulong) (long_val))
546 # define GLONG_FROM_LE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
547 # define GULONG_FROM_LE(long_val) (GULONG_SWAP_LE_BE (long_val))
548 # define GLONG_FROM_BE(long_val) ((glong) (long_val))
549 # define GULONG_FROM_BE(long_val) ((gulong) (long_val))
553 /* Provide type definitions for commonly used types.
554 * These are useful because a "gint8" can be adjusted
555 * to be 1 byte (8 bits) on all platforms. Similarly and
556 * more importantly, "gint32" can be adjusted to be
557 * 4 bytes (32 bits) on all platforms.
561 typedef short gshort;
564 typedef gint gboolean;
566 typedef unsigned char guchar;
567 typedef unsigned short gushort;
568 typedef unsigned long gulong;
569 typedef unsigned int guint;
571 typedef float gfloat;
572 typedef double gdouble;
574 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
575 * Since gldouble isn't used anywhere, just disable it for now */
578 #ifdef HAVE_LONG_DOUBLE
579 typedef long double gldouble;
580 #else /* HAVE_LONG_DOUBLE */
581 typedef double gldouble;
582 #endif /* HAVE_LONG_DOUBLE */
585 typedef void* gpointer;
586 typedef const void *gconstpointer;
588 #if (SIZEOF_CHAR == 1)
589 typedef signed char gint8;
590 typedef unsigned char guint8;
591 #endif /* SIZEOF_CHAR */
593 #if (SIZEOF_SHORT == 2)
594 typedef signed short gint16;
595 typedef unsigned short guint16;
596 #endif /* SIZEOF_SHORT */
598 #if (SIZEOF_INT == 4)
599 typedef signed int gint32;
600 typedef unsigned int guint32;
601 #elif (SIZEOF_LONG == 4)
602 typedef signed long gint32;
603 typedef unsigned long guint32;
604 #endif /* SIZEOF_INT */
606 #if (SIZEOF_LONG == 8)
607 #define HAVE_GINT64 1
608 typedef signed long gint64;
609 typedef unsigned long guint64;
610 #elif (SIZEOF_LONG_LONG == 8)
611 #define HAVE_GINT64 1
612 typedef signed long long gint64;
613 typedef unsigned long long guint64;
620 /* Define macros for storing integers inside pointers
622 #if (SIZEOF_INT == SIZEOF_VOID_P)
624 #define GPOINTER_TO_INT(p) ((gint)(p))
625 #define GPOINTER_TO_UINT(p) ((guint)(p))
627 #define GINT_TO_POINTER(i) ((gpointer)(i))
628 #define GUINT_TO_POINTER(u) ((gpointer)(u))
630 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
632 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
633 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
635 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
636 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
639 #error SIZEOF_VOID_P unknown - This should never happen
642 typedef gint32 gssize;
643 typedef guint32 gsize;
644 typedef guint32 GQuark;
645 typedef gint32 GTime;
649 * we prefix variable declarations so they can
650 * properly get exported in windows dlls.
653 # ifdef GLIB_COMPILATION
654 # define GUTILS_C_VAR __declspec(dllexport)
655 # else /* !GLIB_COMPILATION */
656 # define GUTILS_C_VAR __declspec(dllimport)
657 # endif /* !GLIB_COMPILATION */
658 #else /* !NATIVE_WIN32 */
659 # define GUTILS_C_VAR extern
660 #endif /* !NATIVE_WIN32 */
662 GUTILS_C_VAR const guint glib_major_version;
663 GUTILS_C_VAR const guint glib_minor_version;
664 GUTILS_C_VAR const guint glib_micro_version;
665 GUTILS_C_VAR const guint glib_interface_age;
666 GUTILS_C_VAR const guint glib_binary_age;
668 /* Forward declarations of glib types.
671 typedef struct _GArray GArray;
672 typedef struct _GByteArray GByteArray;
673 typedef struct _GCache GCache;
674 typedef struct _GCompletion GCompletion;
675 typedef struct _GData GData;
676 typedef struct _GDebugKey GDebugKey;
677 typedef struct _GHashTable GHashTable;
678 typedef struct _GHook GHook;
679 typedef struct _GHookList GHookList;
680 typedef struct _GList GList;
681 typedef struct _GListAllocator GListAllocator;
682 typedef struct _GMemChunk GMemChunk;
683 typedef struct _GNode GNode;
684 typedef struct _GPtrArray GPtrArray;
685 typedef struct _GRelation GRelation;
686 typedef struct _GScanner GScanner;
687 typedef struct _GScannerConfig GScannerConfig;
688 typedef struct _GSList GSList;
689 typedef struct _GString GString;
690 typedef struct _GStringChunk GStringChunk;
691 typedef struct _GTimer GTimer;
692 typedef struct _GTree GTree;
693 typedef struct _GTuples GTuples;
694 typedef union _GTokenValue GTokenValue;
695 typedef struct _GIOChannel GIOChannel;
700 G_TRAVERSE_LEAFS = 1 << 0,
701 G_TRAVERSE_NON_LEAFS = 1 << 1,
702 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
703 G_TRAVERSE_MASK = 0x03
714 /* Log level shift offset for user defined
715 * log levels (0-7 are used by GLib).
717 #define G_LOG_LEVEL_USER_SHIFT (8)
719 /* Glib log levels and flags.
724 G_LOG_FLAG_RECURSION = 1 << 0,
725 G_LOG_FLAG_FATAL = 1 << 1,
727 /* GLib log levels */
728 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
729 G_LOG_LEVEL_CRITICAL = 1 << 3,
730 G_LOG_LEVEL_WARNING = 1 << 4,
731 G_LOG_LEVEL_MESSAGE = 1 << 5,
732 G_LOG_LEVEL_INFO = 1 << 6,
733 G_LOG_LEVEL_DEBUG = 1 << 7,
735 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
738 /* GLib log levels that are considered fatal by default */
739 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
742 typedef gpointer (*GCacheNewFunc) (gpointer key);
743 typedef gpointer (*GCacheDupFunc) (gpointer value);
744 typedef void (*GCacheDestroyFunc) (gpointer value);
745 typedef gint (*GCompareFunc) (gconstpointer a,
747 typedef gchar* (*GCompletionFunc) (gpointer);
748 typedef void (*GDestroyNotify) (gpointer data);
749 typedef void (*GDataForeachFunc) (GQuark key_id,
752 typedef void (*GFunc) (gpointer data,
754 typedef guint (*GHashFunc) (gconstpointer key);
755 typedef void (*GHFunc) (gpointer key,
758 typedef gboolean (*GHRFunc) (gpointer key,
761 typedef gint (*GHookCompareFunc) (GHook *new_hook,
763 typedef gboolean (*GHookFindFunc) (GHook *hook,
765 typedef void (*GHookMarshaller) (GHook *hook,
767 typedef void (*GHookFunc) (gpointer data);
768 typedef gboolean (*GHookCheckFunc) (gpointer data);
769 typedef void (*GLogFunc) (const gchar *log_domain,
770 GLogLevelFlags log_level,
771 const gchar *message,
773 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
775 typedef void (*GNodeForeachFunc) (GNode *node,
777 typedef gint (*GSearchFunc) (gpointer key,
779 typedef void (*GScannerMsgFunc) (GScanner *scanner,
782 typedef gint (*GTraverseFunc) (gpointer key,
785 typedef void (*GVoidFunc) (void);
837 /* Doubly linked lists
839 GList* g_list_alloc (void);
840 void g_list_free (GList *list);
841 void g_list_free_1 (GList *list);
842 GList* g_list_append (GList *list,
844 GList* g_list_prepend (GList *list,
846 GList* g_list_insert (GList *list,
849 GList* g_list_insert_sorted (GList *list,
852 GList* g_list_concat (GList *list1,
854 GList* g_list_remove (GList *list,
856 GList* g_list_remove_link (GList *list,
858 GList* g_list_reverse (GList *list);
859 GList* g_list_nth (GList *list,
861 GList* g_list_find (GList *list,
863 GList* g_list_find_custom (GList *list,
866 gint g_list_position (GList *list,
868 gint g_list_index (GList *list,
870 GList* g_list_last (GList *list);
871 GList* g_list_first (GList *list);
872 guint g_list_length (GList *list);
873 void g_list_foreach (GList *list,
876 gpointer g_list_nth_data (GList *list,
878 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
879 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
882 /* Singly linked lists
884 GSList* g_slist_alloc (void);
885 void g_slist_free (GSList *list);
886 void g_slist_free_1 (GSList *list);
887 GSList* g_slist_append (GSList *list,
889 GSList* g_slist_prepend (GSList *list,
891 GSList* g_slist_insert (GSList *list,
894 GSList* g_slist_insert_sorted (GSList *list,
897 GSList* g_slist_concat (GSList *list1,
899 GSList* g_slist_remove (GSList *list,
901 GSList* g_slist_remove_link (GSList *list,
903 GSList* g_slist_reverse (GSList *list);
904 GSList* g_slist_nth (GSList *list,
906 GSList* g_slist_find (GSList *list,
908 GSList* g_slist_find_custom (GSList *list,
911 gint g_slist_position (GSList *list,
913 gint g_slist_index (GSList *list,
915 GSList* g_slist_last (GSList *list);
916 guint g_slist_length (GSList *list);
917 void g_slist_foreach (GSList *list,
920 gpointer g_slist_nth_data (GSList *list,
922 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
927 GListAllocator* g_list_allocator_new (void);
928 void g_list_allocator_free (GListAllocator* allocator);
929 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
930 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
935 GHashTable* g_hash_table_new (GHashFunc hash_func,
936 GCompareFunc key_compare_func);
937 void g_hash_table_destroy (GHashTable *hash_table);
938 void g_hash_table_insert (GHashTable *hash_table,
941 void g_hash_table_remove (GHashTable *hash_table,
943 gpointer g_hash_table_lookup (GHashTable *hash_table,
945 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
946 gconstpointer lookup_key,
949 void g_hash_table_freeze (GHashTable *hash_table);
950 void g_hash_table_thaw (GHashTable *hash_table);
951 void g_hash_table_foreach (GHashTable *hash_table,
954 gint g_hash_table_foreach_remove (GHashTable *hash_table,
957 gint g_hash_table_size (GHashTable *hash_table);
962 GCache* g_cache_new (GCacheNewFunc value_new_func,
963 GCacheDestroyFunc value_destroy_func,
964 GCacheDupFunc key_dup_func,
965 GCacheDestroyFunc key_destroy_func,
966 GHashFunc hash_key_func,
967 GHashFunc hash_value_func,
968 GCompareFunc key_compare_func);
969 void g_cache_destroy (GCache *cache);
970 gpointer g_cache_insert (GCache *cache,
972 void g_cache_remove (GCache *cache,
974 void g_cache_key_foreach (GCache *cache,
977 void g_cache_value_foreach (GCache *cache,
982 /* Balanced binary trees
984 GTree* g_tree_new (GCompareFunc key_compare_func);
985 void g_tree_destroy (GTree *tree);
986 void g_tree_insert (GTree *tree,
989 void g_tree_remove (GTree *tree,
991 gpointer g_tree_lookup (GTree *tree,
993 void g_tree_traverse (GTree *tree,
994 GTraverseFunc traverse_func,
995 GTraverseType traverse_type,
997 gpointer g_tree_search (GTree *tree,
998 GSearchFunc search_func,
1000 gint g_tree_height (GTree *tree);
1001 gint g_tree_nnodes (GTree *tree);
1005 /* N-way tree implementation
1016 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
1017 ((GNode*) (node))->prev == NULL && \
1018 ((GNode*) (node))->next == NULL)
1019 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
1021 GNode* g_node_new (gpointer data);
1022 void g_node_destroy (GNode *root);
1023 void g_node_unlink (GNode *node);
1024 GNode* g_node_insert (GNode *parent,
1027 GNode* g_node_insert_before (GNode *parent,
1030 GNode* g_node_prepend (GNode *parent,
1032 guint g_node_n_nodes (GNode *root,
1033 GTraverseFlags flags);
1034 GNode* g_node_get_root (GNode *node);
1035 gboolean g_node_is_ancestor (GNode *node,
1037 guint g_node_depth (GNode *node);
1038 GNode* g_node_find (GNode *root,
1039 GTraverseType order,
1040 GTraverseFlags flags,
1043 /* convenience macros */
1044 #define g_node_append(parent, node) \
1045 g_node_insert_before ((parent), NULL, (node))
1046 #define g_node_insert_data(parent, position, data) \
1047 g_node_insert ((parent), (position), g_node_new (data))
1048 #define g_node_insert_data_before(parent, sibling, data) \
1049 g_node_insert_before ((parent), (sibling), g_node_new (data))
1050 #define g_node_prepend_data(parent, data) \
1051 g_node_prepend ((parent), g_node_new (data))
1052 #define g_node_append_data(parent, data) \
1053 g_node_insert_before ((parent), NULL, g_node_new (data))
1055 /* traversal function, assumes that `node' is root
1056 * (only traverses `node' and its subtree).
1057 * this function is just a high level interface to
1058 * low level traversal functions, optimized for speed.
1060 void g_node_traverse (GNode *root,
1061 GTraverseType order,
1062 GTraverseFlags flags,
1064 GNodeTraverseFunc func,
1067 /* return the maximum tree height starting with `node', this is an expensive
1068 * operation, since we need to visit all nodes. this could be shortened by
1069 * adding `guint height' to struct _GNode, but then again, this is not very
1070 * often needed, and would make g_node_insert() more time consuming.
1072 guint g_node_max_height (GNode *root);
1074 void g_node_children_foreach (GNode *node,
1075 GTraverseFlags flags,
1076 GNodeForeachFunc func,
1078 void g_node_reverse_children (GNode *node);
1079 guint g_node_n_children (GNode *node);
1080 GNode* g_node_nth_child (GNode *node,
1082 GNode* g_node_last_child (GNode *node);
1083 GNode* g_node_find_child (GNode *node,
1084 GTraverseFlags flags,
1086 gint g_node_child_position (GNode *node,
1088 gint g_node_child_index (GNode *node,
1091 GNode* g_node_first_sibling (GNode *node);
1092 GNode* g_node_last_sibling (GNode *node);
1094 #define g_node_prev_sibling(node) ((node) ? \
1095 ((GNode*) (node))->prev : NULL)
1096 #define g_node_next_sibling(node) ((node) ? \
1097 ((GNode*) (node))->next : NULL)
1098 #define g_node_first_child(node) ((node) ? \
1099 ((GNode*) (node))->children : NULL)
1102 /* Callback maintenance functions
1104 #define G_HOOK_FLAG_USER_SHIFT (4)
1107 G_HOOK_FLAG_ACTIVE = 1 << 0,
1108 G_HOOK_FLAG_IN_CALL = 1 << 1,
1109 G_HOOK_FLAG_MASK = 0x0f
1118 GMemChunk *hook_memchunk;
1130 GDestroyNotify destroy;
1133 #define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \
1134 G_HOOK_FLAG_ACTIVE) != 0)
1135 #define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \
1136 G_HOOK_FLAG_IN_CALL) != 0)
1137 #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
1138 G_HOOK_ACTIVE (hook))
1139 #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
1140 ((GHook*) hook)->prev == NULL && \
1141 ((GHook*) hook)->hook_id == 0 && \
1142 ((GHook*) hook)->ref_count == 0)
1144 void g_hook_list_init (GHookList *hook_list,
1146 void g_hook_list_clear (GHookList *hook_list);
1147 GHook* g_hook_alloc (GHookList *hook_list);
1148 void g_hook_free (GHookList *hook_list,
1150 void g_hook_ref (GHookList *hook_list,
1152 void g_hook_unref (GHookList *hook_list,
1154 gboolean g_hook_destroy (GHookList *hook_list,
1156 void g_hook_destroy_link (GHookList *hook_list,
1158 void g_hook_prepend (GHookList *hook_list,
1160 void g_hook_insert_before (GHookList *hook_list,
1163 void g_hook_insert_sorted (GHookList *hook_list,
1165 GHookCompareFunc func);
1166 GHook* g_hook_get (GHookList *hook_list,
1168 GHook* g_hook_find (GHookList *hook_list,
1169 gboolean need_valids,
1172 GHook* g_hook_find_data (GHookList *hook_list,
1173 gboolean need_valids,
1175 GHook* g_hook_find_func (GHookList *hook_list,
1176 gboolean need_valids,
1178 GHook* g_hook_find_func_data (GHookList *hook_list,
1179 gboolean need_valids,
1182 GHook* g_hook_first_valid (GHookList *hook_list,
1183 gboolean may_be_in_call);
1184 GHook* g_hook_next_valid (GHook *hook,
1185 gboolean may_be_in_call);
1187 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1188 gint g_hook_compare_ids (GHook *new_hook,
1191 /* convenience macros */
1192 #define g_hook_append( hook_list, hook ) \
1193 g_hook_insert_before ((hook_list), NULL, (hook))
1195 /* invoke all valid hooks with the (*GHookFunc) signature.
1197 void g_hook_list_invoke (GHookList *hook_list,
1198 gboolean may_recurse);
1199 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1200 * and destroy the hook if FALSE is returned.
1202 void g_hook_list_invoke_check (GHookList *hook_list,
1203 gboolean may_recurse);
1204 /* invoke a marshaller on all valid hooks.
1206 void g_hook_list_marshal (GHookList *hook_list,
1207 gboolean may_recurse,
1208 GHookMarshaller marshaller,
1212 /* Fatal error handlers.
1213 * g_on_error_query() will prompt the user to either
1214 * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1215 * g_on_error_stack_trace() invokes gdb, which attaches to the current
1216 * process and shows a stack trace.
1217 * These function may cause different actions on non-unix platforms.
1218 * The prg_name arg is required by gdb to find the executable, if it is
1219 * passed as NULL, g_on_error_query() will try g_get_prgname().
1221 void g_on_error_query (const gchar *prg_name);
1222 void g_on_error_stack_trace (const gchar *prg_name);
1225 /* Logging mechanism
1227 extern const gchar *g_log_domain_glib;
1228 guint g_log_set_handler (const gchar *log_domain,
1229 GLogLevelFlags log_levels,
1231 gpointer user_data);
1232 void g_log_remove_handler (const gchar *log_domain,
1234 void g_log_default_handler (const gchar *log_domain,
1235 GLogLevelFlags log_level,
1236 const gchar *message,
1237 gpointer unused_data);
1238 void g_log (const gchar *log_domain,
1239 GLogLevelFlags log_level,
1240 const gchar *format,
1241 ...) G_GNUC_PRINTF (3, 4);
1242 void g_logv (const gchar *log_domain,
1243 GLogLevelFlags log_level,
1244 const gchar *format,
1246 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
1247 GLogLevelFlags fatal_mask);
1248 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
1249 #ifndef G_LOG_DOMAIN
1250 #define G_LOG_DOMAIN (NULL)
1251 #endif /* G_LOG_DOMAIN */
1253 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1254 G_LOG_LEVEL_ERROR, \
1256 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1257 G_LOG_LEVEL_MESSAGE, \
1259 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1260 G_LOG_LEVEL_WARNING, \
1262 #else /* !__GNUC__ */
1264 g_error (const gchar *format,
1268 va_start (args, format);
1269 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1273 g_message (const gchar *format,
1277 va_start (args, format);
1278 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1282 g_warning (const gchar *format,
1286 va_start (args, format);
1287 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1290 #endif /* !__GNUC__ */
1292 typedef void (*GPrintFunc) (const gchar *string);
1293 void g_print (const gchar *format,
1294 ...) G_GNUC_PRINTF (1, 2);
1295 GPrintFunc g_set_print_handler (GPrintFunc func);
1296 void g_printerr (const gchar *format,
1297 ...) G_GNUC_PRINTF (1, 2);
1298 GPrintFunc g_set_printerr_handler (GPrintFunc func);
1300 /* deprecated compatibility functions, use g_log_set_handler() instead */
1301 typedef void (*GErrorFunc) (const gchar *str);
1302 typedef void (*GWarningFunc) (const gchar *str);
1303 GErrorFunc g_set_error_handler (GErrorFunc func);
1304 GWarningFunc g_set_warning_handler (GWarningFunc func);
1305 GPrintFunc g_set_message_handler (GPrintFunc func);
1308 /* Memory allocation and debugging
1312 #define g_malloc(size) ((gpointer) MALLOC (size))
1313 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
1314 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
1315 #define g_free(mem) FREE (mem)
1317 #else /* !USE_DMALLOC */
1319 gpointer g_malloc (gulong size);
1320 gpointer g_malloc0 (gulong size);
1321 gpointer g_realloc (gpointer mem,
1323 void g_free (gpointer mem);
1325 #endif /* !USE_DMALLOC */
1327 void g_mem_profile (void);
1328 void g_mem_check (gpointer mem);
1331 /* "g_mem_chunk_new" creates a new memory chunk.
1332 * Memory chunks are used to allocate pieces of memory which are
1333 * always the same size. Lists are a good example of such a data type.
1334 * The memory chunk allocates and frees blocks of memory as needed.
1335 * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1336 * allocated in a mem chunk. ("g_free" will most likely cause a seg
1337 * fault...somewhere).
1339 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1340 * want to know what's going on inside do you?)
1343 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1344 * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1345 * atom. (They are also useful for lists which use MemChunk to allocate
1346 * memory but are also part of the MemChunk implementation).
1347 * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1350 #define G_ALLOC_ONLY 1
1351 #define G_ALLOC_AND_FREE 2
1353 GMemChunk* g_mem_chunk_new (gchar *name,
1357 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
1358 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
1359 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1360 void g_mem_chunk_free (GMemChunk *mem_chunk,
1362 void g_mem_chunk_clean (GMemChunk *mem_chunk);
1363 void g_mem_chunk_reset (GMemChunk *mem_chunk);
1364 void g_mem_chunk_print (GMemChunk *mem_chunk);
1365 void g_mem_chunk_info (void);
1367 /* Ah yes...we have a "g_blow_chunks" function.
1368 * "g_blow_chunks" simply compresses all the chunks. This operation
1369 * consists of freeing every memory area that should be freed (but
1370 * which we haven't gotten around to doing yet). And, no,
1371 * "g_blow_chunks" doesn't follow the naming scheme, but it is a
1372 * much better name than "g_mem_chunk_clean_all" or something
1375 void g_blow_chunks (void);
1380 GTimer* g_timer_new (void);
1381 void g_timer_destroy (GTimer *timer);
1382 void g_timer_start (GTimer *timer);
1383 void g_timer_stop (GTimer *timer);
1384 void g_timer_reset (GTimer *timer);
1385 gdouble g_timer_elapsed (GTimer *timer,
1386 gulong *microseconds);
1389 /* String utility functions that modify a string argument or
1390 * return a constant string that must not be freed.
1392 #define G_STR_DELIMITERS "_-|> <."
1393 gchar* g_strdelimit (gchar *string,
1394 const gchar *delimiters,
1395 gchar new_delimiter);
1396 gdouble g_strtod (const gchar *nptr,
1398 gchar* g_strerror (gint errnum);
1399 gchar* g_strsignal (gint signum);
1400 gint g_strcasecmp (const gchar *s1,
1402 void g_strdown (gchar *string);
1403 void g_strup (gchar *string);
1404 void g_strreverse (gchar *string);
1405 /* removes leading spaces */
1406 gchar* g_strchug (gchar *string);
1407 /* removes trailing spaces */
1408 gchar* g_strchomp (gchar *string);
1409 /* removes leading & trailing spaces */
1410 #define g_strstrip( string ) g_strchomp (g_strchug (string))
1412 /* String utility functions that return a newly allocated string which
1413 * ought to be freed from the caller at some point.
1415 gchar* g_strdup (const gchar *str);
1416 gchar* g_strdup_printf (const gchar *format,
1417 ...) G_GNUC_PRINTF (1, 2);
1418 gchar* g_strdup_vprintf (const gchar *format,
1420 gchar* g_strndup (const gchar *str,
1422 gchar* g_strnfill (guint length,
1424 gchar* g_strconcat (const gchar *string1,
1425 ...); /* NULL terminated */
1426 gchar* g_strjoin (const gchar *separator,
1427 ...); /* NULL terminated */
1428 gchar* g_strescape (gchar *string);
1429 gpointer g_memdup (gconstpointer mem,
1432 /* NULL terminated string arrays.
1433 * g_strsplit() splits up string into max_tokens tokens at delim and
1434 * returns a newly allocated string array.
1435 * g_strjoinv() concatenates all of str_array's strings, sliding in an
1436 * optional separator, the returned string is newly allocated.
1437 * g_strfreev() frees the array itself and all of its strings.
1439 gchar** g_strsplit (const gchar *string,
1440 const gchar *delimiter,
1442 gchar* g_strjoinv (const gchar *separator,
1444 void g_strfreev (gchar **str_array);
1448 /* calculate a string size, guarranteed to fit format + args.
1450 guint g_printf_string_upper_bound (const gchar* format,
1454 /* Retrive static string info
1456 gchar* g_get_user_name (void);
1457 gchar* g_get_real_name (void);
1458 gchar* g_get_home_dir (void);
1459 gchar* g_get_tmp_dir (void);
1460 gchar* g_get_prgname (void);
1461 void g_set_prgname (const gchar *prgname);
1464 /* Miscellaneous utility functions
1466 guint g_parse_debug_string (const gchar *string,
1469 gint g_snprintf (gchar *string,
1471 gchar const *format,
1472 ...) G_GNUC_PRINTF (3, 4);
1473 gint g_vsnprintf (gchar *string,
1475 gchar const *format,
1477 gchar* g_basename (const gchar *file_name);
1478 /* Check if a file name is an absolute path */
1479 gboolean g_path_is_absolute (const gchar *file_name);
1480 /* In case of absolute paths, skip the root part */
1481 gchar* g_path_skip_root (gchar *file_name);
1483 /* strings are newly allocated with g_malloc() */
1484 gchar* g_dirname (const gchar *file_name);
1485 gchar* g_get_current_dir (void);
1486 gchar* g_getenv (const gchar *variable);
1488 /* We make the assumption that if memmove isn't available, then
1489 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1490 * necessarily handle overlapping copies).
1491 * Either way, g_memmove() will not return a value.
1494 #define g_memmove(dest, src, size) G_STMT_START { \
1495 memmove ((dest), (src), (size)); \
1498 #define g_memmove(dest, src, size) G_STMT_START { \
1499 bcopy ((src), (dest), (size)); \
1503 /* we use a GLib function as a replacement for ATEXIT, so
1504 * the programmer is not required to check the return value
1505 * (if there is any in the implementation) and doesn't encounter
1506 * missing include files.
1508 void g_atexit (GVoidFunc func);
1513 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1517 g_bit_nth_lsf (guint32 mask,
1523 if (mask & (1 << (guint) nth_bit))
1526 while (nth_bit < 32);
1529 #endif /* G_CAN_INLINE */
1531 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1535 g_bit_nth_msf (guint32 mask,
1543 if (mask & (1 << (guint) nth_bit))
1546 while (nth_bit > 0);
1549 #endif /* G_CAN_INLINE */
1551 G_INLINE_FUNC guint g_bit_storage (guint number);
1554 g_bit_storage (guint number)
1556 register guint n_bits = 0;
1566 #endif /* G_CAN_INLINE */
1570 GStringChunk* g_string_chunk_new (gint size);
1571 void g_string_chunk_free (GStringChunk *chunk);
1572 gchar* g_string_chunk_insert (GStringChunk *chunk,
1573 const gchar *string);
1574 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1575 const gchar *string);
1580 GString* g_string_new (const gchar *init);
1581 GString* g_string_sized_new (guint dfl_size);
1582 void g_string_free (GString *string,
1584 GString* g_string_assign (GString *lval,
1586 GString* g_string_truncate (GString *string,
1588 GString* g_string_append (GString *string,
1590 GString* g_string_append_c (GString *string,
1592 GString* g_string_prepend (GString *string,
1594 GString* g_string_prepend_c (GString *string,
1596 GString* g_string_insert (GString *string,
1599 GString* g_string_insert_c (GString *string,
1602 GString* g_string_erase (GString *string,
1605 GString* g_string_down (GString *string);
1606 GString* g_string_up (GString *string);
1607 void g_string_sprintf (GString *string,
1608 const gchar *format,
1609 ...) G_GNUC_PRINTF (2, 3);
1610 void g_string_sprintfa (GString *string,
1611 const gchar *format,
1612 ...) G_GNUC_PRINTF (2, 3);
1618 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1619 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1620 #define g_array_index(a,t,i) (((t*)a->data)[i])
1622 GArray* g_array_new (gboolean zero_terminated,
1624 guint element_size);
1625 void g_array_free (GArray *array,
1626 gboolean free_segment);
1627 GArray* g_array_append_vals (GArray *array,
1630 GArray* g_array_prepend_vals (GArray *array,
1633 GArray* g_array_set_size (GArray *array,
1636 /* Resizable pointer array. This interface is much less complicated
1637 * than the above. Add appends appends a pointer. Remove fills any
1638 * cleared spot and shortens the array.
1640 #define g_ptr_array_index(array,index) (array->pdata)[index]
1641 GPtrArray* g_ptr_array_new (void);
1642 void g_ptr_array_free (GPtrArray *array,
1644 void g_ptr_array_set_size (GPtrArray *array,
1646 gpointer g_ptr_array_remove_index (GPtrArray *array,
1648 gboolean g_ptr_array_remove (GPtrArray *array,
1650 void g_ptr_array_add (GPtrArray *array,
1653 /* Byte arrays, an array of guint8. Implemented as a GArray,
1657 GByteArray* g_byte_array_new (void);
1658 void g_byte_array_free (GByteArray *array,
1659 gboolean free_segment);
1660 GByteArray* g_byte_array_append (GByteArray *array,
1663 GByteArray* g_byte_array_prepend (GByteArray *array,
1666 GByteArray* g_byte_array_set_size (GByteArray *array,
1672 gint g_str_equal (gconstpointer v,
1674 guint g_str_hash (gconstpointer v);
1676 gint g_int_equal (gconstpointer v,
1678 guint g_int_hash (gconstpointer v);
1680 /* This "hash" function will just return the key's adress as an
1681 * unsigned integer. Useful for hashing on plain adresses or
1682 * simple integer values.
1684 guint g_direct_hash (gconstpointer v);
1685 gint g_direct_equal (gconstpointer v,
1689 /* Quarks (string<->id association)
1691 GQuark g_quark_try_string (const gchar *string);
1692 GQuark g_quark_from_static_string (const gchar *string);
1693 GQuark g_quark_from_string (const gchar *string);
1694 gchar* g_quark_to_string (GQuark quark);
1699 void g_datalist_init (GData **datalist);
1700 void g_datalist_clear (GData **datalist);
1701 gpointer g_datalist_id_get_data (GData **datalist,
1703 void g_datalist_id_set_data_full (GData **datalist,
1706 GDestroyNotify destroy_func);
1707 void g_datalist_id_remove_no_notify (GData **datalist,
1709 void g_datalist_foreach (GData **datalist,
1710 GDataForeachFunc func,
1711 gpointer user_data);
1712 #define g_datalist_id_set_data(dl, q, d) \
1713 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1714 #define g_datalist_id_remove_data(dl, q) \
1715 g_datalist_id_set_data ((dl), (q), NULL)
1716 #define g_datalist_get_data(dl, k) \
1717 (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1718 #define g_datalist_set_data_full(dl, k, d, f) \
1719 g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1720 #define g_datalist_remove_no_notify(dl, k) \
1721 g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1722 #define g_datalist_set_data(dl, k, d) \
1723 g_datalist_set_data_full ((dl), (k), (d), NULL)
1724 #define g_datalist_remove_data(dl, k) \
1725 g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1728 /* Location Associated Keyed Data
1730 void g_dataset_destroy (gconstpointer dataset_location);
1731 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1733 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1736 GDestroyNotify destroy_func);
1737 void g_dataset_id_remove_no_notify (gconstpointer dataset_location,
1739 void g_dataset_foreach (gconstpointer dataset_location,
1740 GDataForeachFunc func,
1741 gpointer user_data);
1742 #define g_dataset_id_set_data(l, k, d) \
1743 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1744 #define g_dataset_id_remove_data(l, k) \
1745 g_dataset_id_set_data ((l), (k), NULL)
1746 #define g_dataset_get_data(l, k) \
1747 (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1748 #define g_dataset_set_data_full(l, k, d, f) \
1749 g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1750 #define g_dataset_remove_no_notify(l, k) \
1751 g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1752 #define g_dataset_set_data(l, k, d) \
1753 g_dataset_set_data_full ((l), (k), (d), NULL)
1754 #define g_dataset_remove_data(l, k) \
1755 g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1758 /* GScanner: Flexible lexical scanner for general purpose.
1761 /* Character sets */
1762 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1763 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1764 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1765 "\307\310\311\312\313\314\315\316\317\320"\
1766 "\321\322\323\324\325\326"\
1767 "\330\331\332\333\334\335\336"
1768 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1769 "\347\350\351\352\353\354\355\356\357\360"\
1770 "\361\362\363\364\365\366"\
1771 "\370\371\372\373\374\375\376\377"
1778 G_ERR_UNEXP_EOF_IN_STRING,
1779 G_ERR_UNEXP_EOF_IN_COMMENT,
1780 G_ERR_NON_DIGIT_IN_CONST,
1783 G_ERR_FLOAT_MALFORMED
1791 G_TOKEN_LEFT_PAREN = '(',
1792 G_TOKEN_RIGHT_PAREN = ')',
1793 G_TOKEN_LEFT_CURLY = '{',
1794 G_TOKEN_RIGHT_CURLY = '}',
1795 G_TOKEN_LEFT_BRACE = '[',
1796 G_TOKEN_RIGHT_BRACE = ']',
1797 G_TOKEN_EQUAL_SIGN = '=',
1798 G_TOKEN_COMMA = ',',
1814 G_TOKEN_IDENTIFIER_NULL,
1816 G_TOKEN_COMMENT_SINGLE,
1817 G_TOKEN_COMMENT_MULTI,
1824 gchar *v_identifier;
1836 struct _GScannerConfig
1840 gchar *cset_skip_characters; /* default: " \t\n" */
1841 gchar *cset_identifier_first;
1842 gchar *cset_identifier_nth;
1843 gchar *cpair_comment_single; /* default: "#\n" */
1845 /* Should symbol lookup work case sensitive?
1847 guint case_sensitive : 1;
1849 /* Boolean values to be adjusted "on the fly"
1850 * to configure scanning behaviour.
1852 guint skip_comment_multi : 1; /* C like comment */
1853 guint skip_comment_single : 1; /* single line comment */
1854 guint scan_comment_multi : 1; /* scan multi line comments? */
1855 guint scan_identifier : 1;
1856 guint scan_identifier_1char : 1;
1857 guint scan_identifier_NULL : 1;
1858 guint scan_symbols : 1;
1859 guint scan_binary : 1;
1860 guint scan_octal : 1;
1861 guint scan_float : 1;
1862 guint scan_hex : 1; /* `0x0ff0' */
1863 guint scan_hex_dollar : 1; /* `$0ff0' */
1864 guint scan_string_sq : 1; /* string: 'anything' */
1865 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1866 guint numbers_2_int : 1; /* bin, octal, hex => int */
1867 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1868 guint identifier_2_string : 1;
1869 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1870 guint symbol_2_token : 1;
1871 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1878 guint max_parse_errors;
1880 /* g_scanner_error() increments this field */
1883 /* name of input stream, featured by the default message handler */
1884 const gchar *input_name;
1886 /* data pointer for derived structures */
1887 gpointer derived_data;
1889 /* link into the scanner configuration */
1890 GScannerConfig *config;
1892 /* fields filled in after g_scanner_get_next_token() */
1898 /* fields filled in after g_scanner_peek_next_token() */
1899 GTokenType next_token;
1900 GTokenValue next_value;
1902 guint next_position;
1904 /* to be considered private */
1905 GHashTable *symbol_table;
1908 const gchar *text_end;
1912 /* handler function for _warn and _error */
1913 GScannerMsgFunc msg_handler;
1916 GScanner* g_scanner_new (GScannerConfig *config_templ);
1917 void g_scanner_destroy (GScanner *scanner);
1918 void g_scanner_input_file (GScanner *scanner,
1920 void g_scanner_input_text (GScanner *scanner,
1923 GTokenType g_scanner_get_next_token (GScanner *scanner);
1924 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1925 GTokenType g_scanner_cur_token (GScanner *scanner);
1926 GTokenValue g_scanner_cur_value (GScanner *scanner);
1927 guint g_scanner_cur_line (GScanner *scanner);
1928 guint g_scanner_cur_position (GScanner *scanner);
1929 gboolean g_scanner_eof (GScanner *scanner);
1930 guint g_scanner_set_scope (GScanner *scanner,
1932 void g_scanner_scope_add_symbol (GScanner *scanner,
1934 const gchar *symbol,
1936 void g_scanner_scope_remove_symbol (GScanner *scanner,
1938 const gchar *symbol);
1939 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1941 const gchar *symbol);
1942 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1945 gpointer func_data);
1946 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1947 const gchar *symbol);
1948 void g_scanner_freeze_symbol_table (GScanner *scanner);
1949 void g_scanner_thaw_symbol_table (GScanner *scanner);
1950 void g_scanner_unexp_token (GScanner *scanner,
1951 GTokenType expected_token,
1952 const gchar *identifier_spec,
1953 const gchar *symbol_spec,
1954 const gchar *symbol_name,
1955 const gchar *message,
1957 void g_scanner_error (GScanner *scanner,
1958 const gchar *format,
1959 ...) G_GNUC_PRINTF (2,3);
1960 void g_scanner_warn (GScanner *scanner,
1961 const gchar *format,
1962 ...) G_GNUC_PRINTF (2,3);
1963 gint g_scanner_stat_mode (const gchar *filename);
1964 /* keep downward source compatibility */
1965 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1966 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1968 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1969 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1971 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1972 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1981 GCompletionFunc func;
1987 GCompletion* g_completion_new (GCompletionFunc func);
1988 void g_completion_add_items (GCompletion* cmp,
1990 void g_completion_remove_items (GCompletion* cmp,
1992 void g_completion_clear_items (GCompletion* cmp);
1993 GList* g_completion_complete (GCompletion* cmp,
1995 gchar** new_prefix);
1996 void g_completion_free (GCompletion* cmp);
1999 /* GRelation: Indexed Relations. Imagine a really simple table in a
2000 * database. Relations are not ordered. This data type is meant for
2001 * maintaining a N-way mapping.
2003 * g_relation_new() creates a relation with FIELDS fields
2005 * g_relation_destroy() frees all resources
2006 * g_tuples_destroy() frees the result of g_relation_select()
2008 * g_relation_index() indexes relation FIELD with the provided
2009 * equality and hash functions. this must be done before any
2010 * calls to insert are made.
2012 * g_relation_insert() inserts a new tuple. you are expected to
2013 * provide the right number of fields.
2015 * g_relation_delete() deletes all relations with KEY in FIELD
2016 * g_relation_select() returns ...
2017 * g_relation_count() counts ...
2020 GRelation* g_relation_new (gint fields);
2021 void g_relation_destroy (GRelation *relation);
2022 void g_relation_index (GRelation *relation,
2024 GHashFunc hash_func,
2025 GCompareFunc key_compare_func);
2026 void g_relation_insert (GRelation *relation,
2028 gint g_relation_delete (GRelation *relation,
2031 GTuples* g_relation_select (GRelation *relation,
2034 gint g_relation_count (GRelation *relation,
2037 gboolean g_relation_exists (GRelation *relation,
2039 void g_relation_print (GRelation *relation);
2041 void g_tuples_destroy (GTuples *tuples);
2042 gpointer g_tuples_index (GTuples *tuples,
2050 /* This function returns prime numbers spaced by approximately 1.5-2.0
2051 * and is for use in resizing data structures which prefer
2052 * prime-valued sizes. The closest spaced prime function returns the
2053 * next largest prime, or the highest it knows about which is about
2056 guint g_spaced_primes_closest (guint num);
2060 * These are used for plug-in communication in the GIMP, for instance.
2061 * On Unix, it's simply an encapsulated file descriptor (a pipe).
2062 * On Windows, it's a handle to an anonymouos pipe, *and* (in the case
2063 * of the writable end) a thread id to post a message to when you have written
2068 gint fd; /* file handle (pseudo such in Win32) */
2070 guint peer; /* thread to post message to */
2071 guint peer_fd; /* read handle (in the other process) */
2072 guint offset; /* counter of accumulated bytes, to
2073 * be included in the message posted
2074 * so we keep in sync.
2076 guint peer_offset; /* in input channels where the writer's
2077 * offset is, so we don't try to read too much
2082 GIOChannel *g_iochannel_new (gint fd);
2083 void g_iochannel_free (GIOChannel *channel);
2084 void g_iochannel_close_and_free (GIOChannel *channel);
2085 void g_iochannel_wakeup_peer (GIOChannel *channel);
2086 #ifndef NATIVE_WIN32
2087 # define g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END
2091 /* Windows emulation stubs for common unix functions
2095 #define MAXPATHLEN 1024
2100 /* These POSIXish functions are available in the Microsoft C library
2101 * prefixed with underscore (which of course technically speaking is
2102 * the Right Thing, as they are non-ANSI. Not that being non-ANSI
2103 * prevents Microsoft from practically requiring you to include
2104 * <windows.h> every now and then...).
2106 * You still need to include the appropriate headers to get the
2107 * prototypes, <io.h> or <direct.h>.
2109 * For some functions, we provide emulators in glib, which are prefixed
2112 #define getcwd _getcwd
2113 #define getpid _getpid
2114 #define access _access
2117 #define write _write
2118 #define lseek _lseek
2119 #define close _close
2120 #define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
2121 #define popen _popen
2122 #define pclose _pclose
2123 #define fdopen _fdopen
2124 #define ftruncate(fd, size) gwin_ftruncate (fd, size)
2125 #define opendir gwin_opendir
2126 #define readdir gwin_readdir
2127 #define rewinddir gwin_rewinddir
2128 #define closedir gwin_closedir
2130 #define NAME_MAX 255
2136 gboolean just_opened;
2137 guint find_file_handle;
2138 gpointer find_file_data;
2140 typedef struct DIR DIR;
2143 gchar d_name[NAME_MAX + 1];
2146 /* emulation functions */
2147 extern int gwin_ftruncate (gint f,
2149 DIR* gwin_opendir (const gchar *dirname);
2150 struct dirent* gwin_readdir (DIR *dir);
2151 void gwin_rewinddir (DIR *dir);
2152 gint gwin_closedir (DIR *dir);
2154 #endif /* _MSC_VER */
2156 #define g_ntohl(x) \
2157 ((guint32)((((guint32)(x) & 0x000000ffU) << 24) | \
2158 (((guint32)(x) & 0x0000ff00U) << 8) | \
2159 (((guint32)(x) & 0x00ff0000U) >> 8) | \
2160 (((guint32)(x) & 0xff000000U) >> 24)))
2162 #define g_htonl(x) g_ntohl(x)
2164 #define g_ntohs(x) \
2165 ((guint16)((((guint16)(x) & 0x00ff) << 8) | \
2166 (((guint16)(x) & 0xff00) >> 8)))
2168 #define g_htons(x) g_ntohs(x)
2170 #endif /* NATIVE_WIN32 */
2177 #endif /* __cplusplus */
2180 #endif /* __G_LIB_H__ */