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
37 /* glib provides definitions for the extrema of many
38 * of the standard types. These are:
50 * We include limits.h before float.h to work around a egcs 1.1
51 * oddity on Solaris 2.5.1
55 # define G_MINSHORT SHRT_MIN
56 # define G_MAXSHORT SHRT_MAX
57 # define G_MININT INT_MIN
58 # define G_MAXINT INT_MAX
59 # define G_MINLONG LONG_MIN
60 # define G_MAXLONG LONG_MAX
64 # endif /* HAVE_FLOAT_H */
65 # define G_MINSHORT MINSHORT
66 # define G_MAXSHORT MAXSHORT
67 # define G_MININT MININT
68 # define G_MAXINT MAXINT
69 # define G_MINLONG MINLONG
70 # define G_MAXLONG MAXLONG
71 #endif /* HAVE_VALUES_H */
75 # define G_MINFLOAT FLT_MIN
76 # define G_MAXFLOAT FLT_MAX
77 # define G_MINDOUBLE DBL_MIN
78 # define G_MAXDOUBLE DBL_MAX
81 # define G_MINFLOAT MINFLOAT
82 # define G_MAXFLOAT MAXFLOAT
83 # define G_MINDOUBLE MINDOUBLE
84 # define G_MAXDOUBLE MAXDOUBLE
85 #endif /* HAVE_VALUES_H */
90 #endif /* __cplusplus */
93 /* Provide definitions for some commonly used macros.
94 * Some of them are only provided if they haven't already
95 * been defined. It is assumed that if they are already
96 * defined then the current definition is correct.
99 #define NULL ((void*) 0)
107 #define TRUE (!FALSE)
111 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
114 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
117 #define ABS(a) (((a) < 0) ? -(a) : (a))
120 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
123 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
124 * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
126 #if !defined (G_VA_COPY)
127 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
128 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
129 # elif defined (G_VA_COPY_AS_ARRAY)
130 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
131 # else /* va_list is a pointer */
132 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
133 # endif /* va_list is a pointer */
134 #endif /* !G_VA_COPY */
137 /* Provide simple enum value macro wrappers that ease automated
138 * enum value stringification code. [abandoned]
140 #if !defined (G_CODE_GENERATION)
141 #define G_ENUM( EnumerationName ) EnumerationName
142 #define G_FLAGS( EnumerationName ) EnumerationName
143 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
144 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
145 #else /* G_CODE_GENERATION */
146 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
147 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
148 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
149 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
150 #endif /* G_CODE_GENERATION */
153 /* inlining hassle. for compilers that don't allow the `inline' keyword,
154 * mostly because of strict ANSI C compliance or dumbness, we try to fall
155 * back to either `__inline__' or `__inline'.
156 * we define G_CAN_INLINE, if the compiler seems to be actually
157 * *capable* to do function inlining, in which case inline function bodys
158 * do make sense. we also define G_INLINE_FUNC to properly export the
159 * function prototypes if no inlinig can be performed.
160 * we special case most of the stuff, so inline functions can have a normal
161 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
163 #ifndef G_INLINE_FUNC
164 # define G_CAN_INLINE 1
167 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
169 # define inline __inline__
171 #else /* !G_HAVE_INLINE */
173 # if defined (G_HAVE___INLINE__)
174 # define inline __inline__
175 # else /* !inline && !__inline__ */
176 # if defined (G_HAVE___INLINE)
177 # define inline __inline
178 # else /* !inline && !__inline__ && !__inline */
179 # define inline /* don't inline, then */
180 # ifndef G_INLINE_FUNC
186 #ifndef G_INLINE_FUNC
189 # define G_INLINE_FUNC extern inline
192 # define G_INLINE_FUNC extern
194 # else /* !__GNUC__ */
196 # define G_INLINE_FUNC static inline
198 # define G_INLINE_FUNC extern
200 # endif /* !__GNUC__ */
201 #endif /* !G_INLINE_FUNC */
204 /* Provide simple macro statement wrappers (adapted from Perl):
205 * G_STMT_START { statements; } G_STMT_END;
206 * can be used as a single statement, as in
207 * if (x) G_STMT_START { ... } G_STMT_END; else ...
209 * For gcc we will wrap the statements within `({' and `})' braces.
210 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
211 * and otherwise within `do' and `while (0)'.
213 #if !(defined (G_STMT_START) && defined (G_STMT_END))
214 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
215 # define G_STMT_START (void)(
216 # define G_STMT_END )
218 # if (defined (sun) || defined (__sun__))
219 # define G_STMT_START if (1)
220 # define G_STMT_END else (void)0
222 # define G_STMT_START do
223 # define G_STMT_END while (0)
229 /* Provide macros to feature the GCC function attribute.
231 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
232 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
233 __attribute__((format (printf, format_idx, arg_idx)))
234 #define G_GNUC_SCANF( format_idx, arg_idx ) \
235 __attribute__((format (scanf, format_idx, arg_idx)))
236 #define G_GNUC_FORMAT( arg_idx ) \
237 __attribute__((format_arg (arg_idx)))
238 #define G_GNUC_NORETURN \
239 __attribute__((noreturn))
240 #define G_GNUC_CONST \
241 __attribute__((const))
242 #define G_GNUC_UNUSED \
243 __attribute__((unused))
244 #else /* !__GNUC__ */
245 #define G_GNUC_PRINTF( format_idx, arg_idx )
246 #define G_GNUC_SCANF( format_idx, arg_idx )
247 #define G_GNUC_FORMAT( arg_idx )
248 #define G_GNUC_NORETURN
250 #define G_GNUC_UNUSED
251 #endif /* !__GNUC__ */
254 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
255 * macros, so we can refer to them as strings unconditionally.
258 #define G_GNUC_FUNCTION (__FUNCTION__)
259 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
260 #else /* !__GNUC__ */
261 #define G_GNUC_FUNCTION ("")
262 #define G_GNUC_PRETTY_FUNCTION ("")
263 #endif /* !__GNUC__ */
266 /* we try to provide a usefull equivalent for ATEXIT if it is
267 * not defined, but use is actually abandoned. people should
268 * use g_atexit() instead.
269 * keep this in sync with gutils.c.
273 # ifdef NeXT /* @#%@! NeXTStep */
274 # define ATEXIT(proc) (!atexit (proc))
276 # define ATEXIT(proc) (atexit (proc))
278 # elif defined (HAVE_ON_EXIT)
279 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
281 # error Could not determine proper atexit() implementation
284 # define G_NATIVE_ATEXIT
287 /* Hacker macro to place breakpoints for x86 machines.
288 * Actual use is strongly deprecated of course ;)
290 #if defined (__i386__) && defined (__GNUC__)
291 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
292 #else /* !__i386__ */
293 #define G_BREAKPOINT()
294 #endif /* __i386__ */
297 /* Provide macros for easily allocating memory. The macros
298 * will cast the allocated memory to the specified type
299 * in order to avoid compiler warnings. (Makes the code neater).
303 # define g_new(type, count) (ALLOC (type, count))
304 # define g_new0(type, count) (CALLOC (type, count))
305 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
306 #else /* __DMALLOC_H__ */
307 # define g_new(type, count) \
308 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
309 # define g_new0(type, count) \
310 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
311 # define g_renew(type, mem, count) \
312 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
313 #endif /* __DMALLOC_H__ */
315 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
316 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
318 sizeof (type) * (pre_alloc), \
321 #define g_chunk_new(type, chunk) ( \
322 (type *) g_mem_chunk_alloc (chunk) \
324 #define g_chunk_new0(type, chunk) ( \
325 (type *) g_mem_chunk_alloc0 (chunk) \
327 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
328 g_mem_chunk_free ((mem_chunk), (mem)); \
332 #define g_string(x) #x
335 /* Provide macros for error handling. The "assert" macros will
336 * exit on failure. The "return" macros will exit the current
337 * function. Two different definitions are given for the macros
338 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
339 * __PRETTY_FUNCTION__ capability.
342 #ifdef G_DISABLE_ASSERT
344 #define g_assert(expr)
345 #define g_assert_not_reached()
347 #else /* !G_DISABLE_ASSERT */
351 #define g_assert(expr) G_STMT_START{ \
353 g_log (G_LOG_DOMAIN, \
355 "file %s: line %d (%s): assertion failed: (%s)", \
358 __PRETTY_FUNCTION__, \
361 #define g_assert_not_reached() G_STMT_START{ \
362 g_log (G_LOG_DOMAIN, \
364 "file %s: line %d (%s): should not be reached", \
367 __PRETTY_FUNCTION__); }G_STMT_END
369 #else /* !__GNUC__ */
371 #define g_assert(expr) G_STMT_START{ \
373 g_log (G_LOG_DOMAIN, \
375 "file %s: line %d: assertion failed: (%s)", \
380 #define g_assert_not_reached() G_STMT_START{ \
381 g_log (G_LOG_DOMAIN, \
383 "file %s: line %d: should not be reached", \
385 __LINE__); }G_STMT_END
387 #endif /* __GNUC__ */
389 #endif /* !G_DISABLE_ASSERT */
392 #ifdef G_DISABLE_CHECKS
394 #define g_return_if_fail(expr)
395 #define g_return_val_if_fail(expr,val)
397 #else /* !G_DISABLE_CHECKS */
401 #define g_return_if_fail(expr) G_STMT_START{ \
404 g_log (G_LOG_DOMAIN, \
405 G_LOG_LEVEL_CRITICAL, \
406 "file %s: line %d (%s): assertion `%s' failed.", \
409 __PRETTY_FUNCTION__, \
414 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
417 g_log (G_LOG_DOMAIN, \
418 G_LOG_LEVEL_CRITICAL, \
419 "file %s: line %d (%s): assertion `%s' failed.", \
422 __PRETTY_FUNCTION__, \
427 #else /* !__GNUC__ */
429 #define g_return_if_fail(expr) G_STMT_START{ \
432 g_log (G_LOG_DOMAIN, \
433 G_LOG_LEVEL_CRITICAL, \
434 "file %s: line %d: assertion `%s' failed.", \
441 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
444 g_log (G_LOG_DOMAIN, \
445 G_LOG_LEVEL_CRITICAL, \
446 "file %s: line %d: assertion `%s' failed.", \
453 #endif /* !__GNUC__ */
455 #endif /* !G_DISABLE_CHECKS */
458 /* Portable endian checks and conversions
461 #define G_LITTLE_ENDIAN 1234
462 #define G_BIG_ENDIAN 4321
463 #define G_PDP_ENDIAN 3412 / /* unused, need specific PDP check */
465 #ifdef WORDS_BIGENDIAN
466 #define G_BYTE_ORDER G_BIG_ENDIAN
468 #define G_BYTE_ORDER G_LITTLE_ENDIAN
471 #define GULONG_SWAP_LE_BE(long_val) (((gulong) \
472 (((gulong) (long_val)) & 0x000000ffU) << 24) | \
473 (((gulong) (long_val)) & 0x0000ff00U) << 8) | \
474 (((gulong) (long_val)) & 0x00ff0000U) >> 8) | \
475 (((gulong) (long_val)) & 0xff000000U) >> 24)))
476 #define GULONG_SWAP_LE_PDP(long_val) (((gulong) \
477 (((gulong) (long_val)) & 0x0000ffffU) << 16) | \
478 (((gulong) (long_val)) & 0xffff0000U) >> 16)))
479 #define GULONG_SWAP_BE_PDP(long_val) (((gulong) \
480 (((gulong) (long_val)) & 0x000000ffU) << 8) | \
481 (((gulong) (long_val)) & 0x0000ff00U) >> 8) | \
482 (((gulong) (long_val)) & 0x00ff0000U) << 8) | \
483 (((gulong) (long_val)) & 0xff000000U) >> 8)))
485 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
486 # define GLONG_TO_LE(long_val) ((glong) (long_val))
487 # define GULONG_TO_LE(long_val) ((gulong) (long_val))
488 # define GLONG_TO_BE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
489 # define GULONG_TO_BE(long_val) (GULONG_SWAP_LE_BE (long_val))
490 # define GLONG_FROM_LE(long_val) ((glong) (long_val))
491 # define GULONG_FROM_LE(long_val) ((gulong) (long_val))
492 # define GLONG_FROM_BE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
493 # define GULONG_FROM_BE(long_val) (GULONG_SWAP_LE_BE (long_val))
494 #elif G_BYTE_ORDER == G_BIG_ENDIAN
495 # define GLONG_TO_LE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
496 # define GULONG_TO_LE(long_val) (GULONG_SWAP_LE_BE (long_val))
497 # define GLONG_TO_BE(long_val) ((glong) (long_val))
498 # define GULONG_TO_BE(long_val) ((gulong) (long_val))
499 # define GLONG_FROM_LE(long_val) ((glong) GULONG_SWAP_LE_BE (long_val))
500 # define GULONG_FROM_LE(long_val) (GULONG_SWAP_LE_BE (long_val))
501 # define GLONG_FROM_BE(long_val) ((glong) (long_val))
502 # define GULONG_FROM_BE(long_val) ((gulong) (long_val))
506 /* Provide type definitions for commonly used types.
507 * These are useful because a "gint8" can be adjusted
508 * to be 1 byte (8 bits) on all platforms. Similarly and
509 * more importantly, "gint32" can be adjusted to be
510 * 4 bytes (32 bits) on all platforms.
514 typedef short gshort;
517 typedef gint gboolean;
519 typedef unsigned char guchar;
520 typedef unsigned short gushort;
521 typedef unsigned long gulong;
522 typedef unsigned int guint;
524 typedef float gfloat;
525 typedef double gdouble;
527 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
528 * Since gldouble isn't used anywhere, just disable it for now */
531 #ifdef HAVE_LONG_DOUBLE
532 typedef long double gldouble;
533 #else /* HAVE_LONG_DOUBLE */
534 typedef double gldouble;
535 #endif /* HAVE_LONG_DOUBLE */
538 typedef void* gpointer;
539 typedef const void *gconstpointer;
541 #if (SIZEOF_CHAR == 1)
542 typedef signed char gint8;
543 typedef unsigned char guint8;
544 #endif /* SIZEOF_CHAR */
546 #if (SIZEOF_SHORT == 2)
547 typedef signed short gint16;
548 typedef unsigned short guint16;
549 #endif /* SIZEOF_SHORT */
551 #if (SIZEOF_INT == 4)
552 typedef signed int gint32;
553 typedef unsigned int guint32;
554 #elif (SIZEOF_LONG == 4)
555 typedef signed long gint32;
556 typedef unsigned long guint32;
557 #endif /* SIZEOF_INT */
559 #if (SIZEOF_LONG == 8)
560 #define HAVE_GINT64 1
561 typedef signed long gint64;
562 typedef unsigned long guint64;
563 #elif (SIZEOF_LONG_LONG == 8)
564 #define HAVE_GINT64 1
565 typedef signed long long gint64;
566 typedef unsigned long long guint64;
573 /* Define macros for storing integers inside pointers
575 #if (SIZEOF_INT == SIZEOF_VOID_P)
577 #define GPOINTER_TO_INT(p) ((gint)(p))
578 #define GPOINTER_TO_UINT(p) ((guint)(p))
580 #define GINT_TO_POINTER(i) ((gpointer)(i))
581 #define GUINT_TO_POINTER(u) ((gpointer)(u))
583 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
585 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
586 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
588 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
589 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
592 #error SIZEOF_VOID_P unknown - This should never happen
595 typedef gint32 gssize;
596 typedef guint32 gsize;
597 typedef guint32 GQuark;
598 typedef gint32 GTime;
603 extern const guint glib_major_version;
604 extern const guint glib_minor_version;
605 extern const guint glib_micro_version;
606 extern const guint glib_interface_age;
607 extern const guint glib_binary_age;
610 /* Forward declarations of glib types.
613 typedef struct _GArray GArray;
614 typedef struct _GByteArray GByteArray;
615 typedef struct _GCache GCache;
616 typedef struct _GCompletion GCompletion;
617 typedef struct _GData GData;
618 typedef struct _GDebugKey GDebugKey;
619 typedef struct _GHashTable GHashTable;
620 typedef struct _GHook GHook;
621 typedef struct _GHookList GHookList;
622 typedef struct _GList GList;
623 typedef struct _GListAllocator GListAllocator;
624 typedef struct _GMemChunk GMemChunk;
625 typedef struct _GNode GNode;
626 typedef struct _GPtrArray GPtrArray;
627 typedef struct _GRelation GRelation;
628 typedef struct _GScanner GScanner;
629 typedef struct _GScannerConfig GScannerConfig;
630 typedef struct _GSList GSList;
631 typedef struct _GString GString;
632 typedef struct _GStringChunk GStringChunk;
633 typedef struct _GTimer GTimer;
634 typedef struct _GTree GTree;
635 typedef struct _GTuples GTuples;
636 typedef union _GTokenValue GTokenValue;
641 G_TRAVERSE_LEAFS = 1 << 0,
642 G_TRAVERSE_NON_LEAFS = 1 << 1,
643 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
644 G_TRAVERSE_MASK = 0x03
655 /* Log level shift offset for user defined
656 * log levels (0-7 are used by GLib).
658 #define G_LOG_LEVEL_USER_SHIFT (8)
660 /* Glib log levels and flags.
665 G_LOG_FLAG_RECURSION = 1 << 0,
666 G_LOG_FLAG_FATAL = 1 << 1,
668 /* GLib log levels */
669 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
670 G_LOG_LEVEL_CRITICAL = 1 << 3,
671 G_LOG_LEVEL_WARNING = 1 << 4,
672 G_LOG_LEVEL_MESSAGE = 1 << 5,
673 G_LOG_LEVEL_INFO = 1 << 6,
674 G_LOG_LEVEL_DEBUG = 1 << 7,
676 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
679 /* GLib log levels that are considered fatal by default */
680 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
683 typedef gpointer (*GCacheNewFunc) (gpointer key);
684 typedef gpointer (*GCacheDupFunc) (gpointer value);
685 typedef void (*GCacheDestroyFunc) (gpointer value);
686 typedef gint (*GCompareFunc) (gconstpointer a,
688 typedef gchar* (*GCompletionFunc) (gpointer);
689 typedef void (*GDestroyNotify) (gpointer data);
690 typedef void (*GDataForeachFunc) (GQuark key_id,
693 typedef void (*GFunc) (gpointer data,
695 typedef guint (*GHashFunc) (gconstpointer key);
696 typedef void (*GHFunc) (gpointer key,
699 typedef gboolean (*GHRFunc) (gpointer key,
702 typedef gint (*GHookCompareFunc) (GHook *new_hook,
704 typedef gboolean (*GHookFindFunc) (GHook *hook,
706 typedef void (*GHookMarshaller) (GHook *hook,
708 typedef void (*GHookFunc) (gpointer data);
709 typedef gboolean (*GHookCheckFunc) (gpointer data);
710 typedef void (*GLogFunc) (const gchar *log_domain,
711 GLogLevelFlags log_level,
712 const gchar *message,
714 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
716 typedef void (*GNodeForeachFunc) (GNode *node,
718 typedef gint (*GSearchFunc) (gpointer key,
720 typedef void (*GScannerMsgFunc) (GScanner *scanner,
723 typedef gint (*GTraverseFunc) (gpointer key,
726 typedef void (*GVoidFunc) (void);
777 struct _GCache { gint dummy; };
778 struct _GTree { gint dummy; };
779 struct _GTimer { gint dummy; };
780 struct _GMemChunk { gint dummy; };
781 struct _GListAllocator { gint dummy; };
782 struct _GStringChunk { gint dummy; };
785 /* Doubly linked lists
787 GList* g_list_alloc (void);
788 void g_list_free (GList *list);
789 void g_list_free_1 (GList *list);
790 GList* g_list_append (GList *list,
792 GList* g_list_prepend (GList *list,
794 GList* g_list_insert (GList *list,
797 GList* g_list_insert_sorted (GList *list,
800 GList* g_list_concat (GList *list1,
802 GList* g_list_remove (GList *list,
804 GList* g_list_remove_link (GList *list,
806 GList* g_list_reverse (GList *list);
807 GList* g_list_nth (GList *list,
809 GList* g_list_find (GList *list,
811 GList* g_list_find_custom (GList *list,
814 gint g_list_position (GList *list,
816 gint g_list_index (GList *list,
818 GList* g_list_last (GList *list);
819 GList* g_list_first (GList *list);
820 guint g_list_length (GList *list);
821 void g_list_foreach (GList *list,
824 gpointer g_list_nth_data (GList *list,
826 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
827 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
830 /* Singly linked lists
832 GSList* g_slist_alloc (void);
833 void g_slist_free (GSList *list);
834 void g_slist_free_1 (GSList *list);
835 GSList* g_slist_append (GSList *list,
837 GSList* g_slist_prepend (GSList *list,
839 GSList* g_slist_insert (GSList *list,
842 GSList* g_slist_insert_sorted (GSList *list,
845 GSList* g_slist_concat (GSList *list1,
847 GSList* g_slist_remove (GSList *list,
849 GSList* g_slist_remove_link (GSList *list,
851 GSList* g_slist_reverse (GSList *list);
852 GSList* g_slist_nth (GSList *list,
854 GSList* g_slist_find (GSList *list,
856 GSList* g_slist_find_custom (GSList *list,
859 gint g_slist_position (GSList *list,
861 gint g_slist_index (GSList *list,
863 GSList* g_slist_last (GSList *list);
864 guint g_slist_length (GSList *list);
865 void g_slist_foreach (GSList *list,
868 gpointer g_slist_nth_data (GSList *list,
870 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
875 GListAllocator* g_list_allocator_new (void);
876 void g_list_allocator_free (GListAllocator* allocator);
877 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
878 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
883 GHashTable* g_hash_table_new (GHashFunc hash_func,
884 GCompareFunc key_compare_func);
885 void g_hash_table_destroy (GHashTable *hash_table);
886 void g_hash_table_insert (GHashTable *hash_table,
889 void g_hash_table_remove (GHashTable *hash_table,
891 gpointer g_hash_table_lookup (GHashTable *hash_table,
893 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
894 gconstpointer lookup_key,
897 void g_hash_table_freeze (GHashTable *hash_table);
898 void g_hash_table_thaw (GHashTable *hash_table);
899 void g_hash_table_foreach (GHashTable *hash_table,
902 gint g_hash_table_foreach_remove (GHashTable *hash_table,
905 gint g_hash_table_size (GHashTable *hash_table);
910 GCache* g_cache_new (GCacheNewFunc value_new_func,
911 GCacheDestroyFunc value_destroy_func,
912 GCacheDupFunc key_dup_func,
913 GCacheDestroyFunc key_destroy_func,
914 GHashFunc hash_key_func,
915 GHashFunc hash_value_func,
916 GCompareFunc key_compare_func);
917 void g_cache_destroy (GCache *cache);
918 gpointer g_cache_insert (GCache *cache,
920 void g_cache_remove (GCache *cache,
922 void g_cache_key_foreach (GCache *cache,
925 void g_cache_value_foreach (GCache *cache,
930 /* Balanced binary trees
932 GTree* g_tree_new (GCompareFunc key_compare_func);
933 void g_tree_destroy (GTree *tree);
934 void g_tree_insert (GTree *tree,
937 void g_tree_remove (GTree *tree,
939 gpointer g_tree_lookup (GTree *tree,
941 void g_tree_traverse (GTree *tree,
942 GTraverseFunc traverse_func,
943 GTraverseType traverse_type,
945 gpointer g_tree_search (GTree *tree,
946 GSearchFunc search_func,
948 gint g_tree_height (GTree *tree);
949 gint g_tree_nnodes (GTree *tree);
953 /* N-way tree implementation
964 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
965 ((GNode*) (node))->prev == NULL && \
966 ((GNode*) (node))->next == NULL)
967 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
969 GNode* g_node_new (gpointer data);
970 void g_node_destroy (GNode *root);
971 void g_node_unlink (GNode *node);
972 GNode* g_node_insert (GNode *parent,
975 GNode* g_node_insert_before (GNode *parent,
978 GNode* g_node_prepend (GNode *parent,
980 guint g_node_n_nodes (GNode *root,
981 GTraverseFlags flags);
982 GNode* g_node_get_root (GNode *node);
983 gboolean g_node_is_ancestor (GNode *node,
985 guint g_node_depth (GNode *node);
986 GNode* g_node_find (GNode *root,
988 GTraverseFlags flags,
991 /* convenience macros */
992 #define g_node_append(parent, node) \
993 g_node_insert_before ((parent), NULL, (node))
994 #define g_node_insert_data(parent, position, data) \
995 g_node_insert ((parent), (position), g_node_new (data))
996 #define g_node_insert_data_before(parent, sibling, data) \
997 g_node_insert_before ((parent), (sibling), g_node_new (data))
998 #define g_node_prepend_data(parent, data) \
999 g_node_prepend ((parent), g_node_new (data))
1000 #define g_node_append_data(parent, data) \
1001 g_node_insert_before ((parent), NULL, g_node_new (data))
1003 /* traversal function, assumes that `node' is root
1004 * (only traverses `node' and its subtree).
1005 * this function is just a high level interface to
1006 * low level traversal functions, optimized for speed.
1008 void g_node_traverse (GNode *root,
1009 GTraverseType order,
1010 GTraverseFlags flags,
1012 GNodeTraverseFunc func,
1015 /* return the maximum tree height starting with `node', this is an expensive
1016 * operation, since we need to visit all nodes. this could be shortened by
1017 * adding `guint height' to struct _GNode, but then again, this is not very
1018 * often needed, and would make g_node_insert() more time consuming.
1020 guint g_node_max_height (GNode *root);
1022 void g_node_children_foreach (GNode *node,
1023 GTraverseFlags flags,
1024 GNodeForeachFunc func,
1026 void g_node_reverse_children (GNode *node);
1027 guint g_node_n_children (GNode *node);
1028 GNode* g_node_nth_child (GNode *node,
1030 GNode* g_node_last_child (GNode *node);
1031 GNode* g_node_find_child (GNode *node,
1032 GTraverseFlags flags,
1034 gint g_node_child_position (GNode *node,
1036 gint g_node_child_index (GNode *node,
1039 GNode* g_node_first_sibling (GNode *node);
1040 GNode* g_node_last_sibling (GNode *node);
1042 #define g_node_prev_sibling(node) ((node) ? \
1043 ((GNode*) (node))->prev : NULL)
1044 #define g_node_next_sibling(node) ((node) ? \
1045 ((GNode*) (node))->next : NULL)
1046 #define g_node_first_child(node) ((node) ? \
1047 ((GNode*) (node))->children : NULL)
1050 /* Callback maintenance functions
1052 #define G_HOOK_FLAG_USER_SHIFT (4)
1055 G_HOOK_FLAG_ACTIVE = 1 << 0,
1056 G_HOOK_FLAG_IN_CALL = 1 << 1,
1057 G_HOOK_FLAG_MASK = 0x0f
1066 GMemChunk *hook_memchunk;
1078 GDestroyNotify destroy;
1081 #define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \
1082 G_HOOK_FLAG_ACTIVE) != 0)
1083 #define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \
1084 G_HOOK_FLAG_IN_CALL) != 0)
1085 #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
1086 G_HOOK_ACTIVE (hook))
1087 #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
1088 ((GHook*) hook)->prev == NULL && \
1089 ((GHook*) hook)->hook_id == 0 && \
1090 ((GHook*) hook)->ref_count == 0)
1092 void g_hook_list_init (GHookList *hook_list,
1094 void g_hook_list_clear (GHookList *hook_list);
1095 GHook* g_hook_alloc (GHookList *hook_list);
1096 void g_hook_free (GHookList *hook_list,
1098 void g_hook_ref (GHookList *hook_list,
1100 void g_hook_unref (GHookList *hook_list,
1102 gboolean g_hook_destroy (GHookList *hook_list,
1104 void g_hook_destroy_link (GHookList *hook_list,
1106 void g_hook_prepend (GHookList *hook_list,
1108 void g_hook_insert_before (GHookList *hook_list,
1111 void g_hook_insert_sorted (GHookList *hook_list,
1113 GHookCompareFunc func);
1114 GHook* g_hook_get (GHookList *hook_list,
1116 GHook* g_hook_find (GHookList *hook_list,
1117 gboolean need_valids,
1120 GHook* g_hook_find_data (GHookList *hook_list,
1121 gboolean need_valids,
1123 GHook* g_hook_find_func (GHookList *hook_list,
1124 gboolean need_valids,
1126 GHook* g_hook_find_func_data (GHookList *hook_list,
1127 gboolean need_valids,
1130 GHook* g_hook_first_valid (GHookList *hook_list,
1131 gboolean may_be_in_call);
1132 GHook* g_hook_next_valid (GHook *hook,
1133 gboolean may_be_in_call);
1135 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1136 gint g_hook_compare_ids (GHook *new_hook,
1139 /* convenience macros */
1140 #define g_hook_append( hook_list, hook ) \
1141 g_hook_insert_before ((hook_list), NULL, (hook))
1143 /* invoke all valid hooks with the (*GHookFunc) signature.
1145 void g_hook_list_invoke (GHookList *hook_list,
1146 gboolean may_recurse);
1147 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1148 * and destroy the hook if FALSE is returned.
1150 void g_hook_list_invoke_check (GHookList *hook_list,
1151 gboolean may_recurse);
1152 /* invoke a marshaller on all valid hooks.
1154 void g_hook_list_marshal (GHookList *hook_list,
1155 gboolean may_recurse,
1156 GHookMarshaller marshaller,
1160 /* Fatal error handlers.
1161 * g_on_error_query() will prompt the user to either
1162 * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1163 * g_on_error_stack_trace() invokes gdb, which attaches to the current
1164 * process and shows a stack trace.
1165 * These function may cause different actions on non-unix platforms.
1166 * The prg_name arg is required by gdb to find the executable, if it is
1167 * passed as NULL, g_on_error_query() will try g_get_prgname().
1169 void g_on_error_query (const gchar *prg_name);
1170 void g_on_error_stack_trace (const gchar *prg_name);
1173 /* Logging mechanism
1175 extern const gchar *g_log_domain_glib;
1176 guint g_log_set_handler (const gchar *log_domain,
1177 GLogLevelFlags log_levels,
1179 gpointer user_data);
1180 void g_log_remove_handler (const gchar *log_domain,
1182 void g_log_default_handler (const gchar *log_domain,
1183 GLogLevelFlags log_level,
1184 const gchar *message,
1185 gpointer unused_data);
1186 void g_log (const gchar *log_domain,
1187 GLogLevelFlags log_level,
1188 const gchar *format,
1189 ...) G_GNUC_PRINTF (3, 4);
1190 void g_logv (const gchar *log_domain,
1191 GLogLevelFlags log_level,
1192 const gchar *format,
1194 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
1195 GLogLevelFlags fatal_mask);
1196 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
1197 #ifndef G_LOG_DOMAIN
1198 #define G_LOG_DOMAIN (NULL)
1199 #endif /* G_LOG_DOMAIN */
1201 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1202 G_LOG_LEVEL_ERROR, \
1204 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1205 G_LOG_LEVEL_MESSAGE, \
1207 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1208 G_LOG_LEVEL_WARNING, \
1210 #else /* !__GNUC__ */
1212 g_error (const gchar *format,
1216 va_start (args, format);
1217 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1221 g_message (const gchar *format,
1225 va_start (args, format);
1226 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1230 g_warning (const gchar *format,
1234 va_start (args, format);
1235 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1238 #endif /* !__GNUC__ */
1240 typedef void (*GPrintFunc) (const gchar *string);
1241 void g_print (const gchar *format,
1242 ...) G_GNUC_PRINTF (1, 2);
1243 GPrintFunc g_set_print_handler (GPrintFunc func);
1244 void g_printerr (const gchar *format,
1245 ...) G_GNUC_PRINTF (1, 2);
1246 GPrintFunc g_set_printerr_handler (GPrintFunc func);
1248 /* deprecated compatibility functions, use g_log_set_handler() instead */
1249 typedef void (*GErrorFunc) (const gchar *str);
1250 typedef void (*GWarningFunc) (const gchar *str);
1251 GErrorFunc g_set_error_handler (GErrorFunc func);
1252 GWarningFunc g_set_warning_handler (GWarningFunc func);
1253 GPrintFunc g_set_message_handler (GPrintFunc func);
1256 /* Memory allocation and debugging
1260 #define g_malloc(size) ((gpointer) MALLOC (size))
1261 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
1262 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
1263 #define g_free(mem) FREE (mem)
1265 #else /* !USE_DMALLOC */
1267 gpointer g_malloc (gulong size);
1268 gpointer g_malloc0 (gulong size);
1269 gpointer g_realloc (gpointer mem,
1271 void g_free (gpointer mem);
1273 #endif /* !USE_DMALLOC */
1275 void g_mem_profile (void);
1276 void g_mem_check (gpointer mem);
1279 /* "g_mem_chunk_new" creates a new memory chunk.
1280 * Memory chunks are used to allocate pieces of memory which are
1281 * always the same size. Lists are a good example of such a data type.
1282 * The memory chunk allocates and frees blocks of memory as needed.
1283 * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1284 * allocated in a mem chunk. ("g_free" will most likely cause a seg
1285 * fault...somewhere).
1287 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1288 * want to know what's going on inside do you?)
1291 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1292 * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1293 * atom. (They are also useful for lists which use MemChunk to allocate
1294 * memory but are also part of the MemChunk implementation).
1295 * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1298 #define G_ALLOC_ONLY 1
1299 #define G_ALLOC_AND_FREE 2
1301 GMemChunk* g_mem_chunk_new (gchar *name,
1305 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
1306 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
1307 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1308 void g_mem_chunk_free (GMemChunk *mem_chunk,
1310 void g_mem_chunk_clean (GMemChunk *mem_chunk);
1311 void g_mem_chunk_reset (GMemChunk *mem_chunk);
1312 void g_mem_chunk_print (GMemChunk *mem_chunk);
1313 void g_mem_chunk_info (void);
1315 /* Ah yes...we have a "g_blow_chunks" function.
1316 * "g_blow_chunks" simply compresses all the chunks. This operation
1317 * consists of freeing every memory area that should be freed (but
1318 * which we haven't gotten around to doing yet). And, no,
1319 * "g_blow_chunks" doesn't follow the naming scheme, but it is a
1320 * much better name than "g_mem_chunk_clean_all" or something
1323 void g_blow_chunks (void);
1328 GTimer* g_timer_new (void);
1329 void g_timer_destroy (GTimer *timer);
1330 void g_timer_start (GTimer *timer);
1331 void g_timer_stop (GTimer *timer);
1332 void g_timer_reset (GTimer *timer);
1333 gdouble g_timer_elapsed (GTimer *timer,
1334 gulong *microseconds);
1337 /* String utility functions
1339 #define G_STR_DELIMITERS "_-|> <."
1340 void g_strdelimit (gchar *string,
1341 const gchar *delimiters,
1342 gchar new_delimiter);
1343 gchar* g_strdup (const gchar *str);
1344 gchar* g_strdup_printf (const gchar *format,
1345 ...) G_GNUC_PRINTF (1, 2);
1346 gchar* g_strdup_vprintf (const gchar *format,
1348 gchar* g_strndup (const gchar *str,
1350 gchar* g_strnfill (guint length,
1352 gchar* g_strconcat (const gchar *string1,
1353 ...); /* NULL terminated */
1354 gdouble g_strtod (const gchar *nptr,
1356 gchar* g_strerror (gint errnum);
1357 gchar* g_strsignal (gint signum);
1358 gint g_strcasecmp (const gchar *s1,
1360 void g_strdown (gchar *string);
1361 void g_strup (gchar *string);
1362 void g_strreverse (gchar *string);
1363 gpointer g_memdup (gconstpointer mem,
1366 /* calculate a string size, guarranteed to fit format + args.
1368 guint g_printf_string_upper_bound (const gchar* format,
1372 /* Retrive static string info
1374 gchar* g_get_user_name (void);
1375 gchar* g_get_real_name (void);
1376 gchar* g_get_home_dir (void);
1377 gchar* g_get_tmp_dir (void);
1378 gchar* g_get_prgname (void);
1379 void g_set_prgname (const gchar *prgname);
1382 /* Miscellaneous utility functions
1384 guint g_parse_debug_string (const gchar *string,
1387 gint g_snprintf (gchar *string,
1389 gchar const *format,
1390 ...) G_GNUC_PRINTF (3, 4);
1391 gint g_vsnprintf (gchar *string,
1393 gchar const *format,
1395 gchar* g_basename (const gchar *file_name);
1397 /* strings are newly allocated with g_malloc() */
1398 gchar* g_dirname (const gchar *file_name);
1399 gchar* g_get_current_dir (void);
1401 /* We make the assumption that if memmove isn't available, then
1402 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1403 * necessarily handle overlapping copies).
1404 * Either way, g_memmove() will not return a value.
1407 #define g_memmove(dest, src, size) G_STMT_START { \
1408 memmove ((dest), (src), (size)); \
1411 #define g_memmove(dest, src, size) G_STMT_START { \
1412 bcopy ((src), (dest), (size)); \
1416 /* we use a GLib function as a replacement for ATEXIT, so
1417 * the programmer is not required to check the return value
1418 * (if there is any in the implementation) and doesn't encounter
1419 * missing include files.
1421 void g_atexit (GVoidFunc func);
1426 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1430 g_bit_nth_lsf (guint32 mask,
1436 if (mask & (1 << (guint) nth_bit))
1439 while (nth_bit < 32);
1442 #endif /* G_CAN_INLINE */
1444 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1448 g_bit_nth_msf (guint32 mask,
1456 if (mask & (1 << (guint) nth_bit))
1459 while (nth_bit > 0);
1462 #endif /* G_CAN_INLINE */
1464 G_INLINE_FUNC guint g_bit_storage (guint number);
1467 g_bit_storage (guint number)
1469 register guint n_bits = 0;
1479 #endif /* G_CAN_INLINE */
1484 GStringChunk* g_string_chunk_new (gint size);
1485 void g_string_chunk_free (GStringChunk *chunk);
1486 gchar* g_string_chunk_insert (GStringChunk *chunk,
1487 const gchar *string);
1488 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1489 const gchar *string);
1494 GString* g_string_new (const gchar *init);
1495 GString* g_string_sized_new (guint dfl_size);
1496 void g_string_free (GString *string,
1498 GString* g_string_assign (GString *lval,
1500 GString* g_string_truncate (GString *string,
1502 GString* g_string_append (GString *string,
1504 GString* g_string_append_c (GString *string,
1506 GString* g_string_prepend (GString *string,
1508 GString* g_string_prepend_c (GString *string,
1510 GString* g_string_insert (GString *string,
1513 GString* g_string_insert_c (GString *string,
1516 GString* g_string_erase (GString *string,
1519 GString* g_string_down (GString *string);
1520 GString* g_string_up (GString *string);
1521 void g_string_sprintf (GString *string,
1522 const gchar *format,
1523 ...) G_GNUC_PRINTF (2, 3);
1524 void g_string_sprintfa (GString *string,
1525 const gchar *format,
1526 ...) G_GNUC_PRINTF (2, 3);
1532 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1533 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1534 #define g_array_index(a,t,i) (((t*)a->data)[i])
1536 GArray* g_array_new (gboolean zero_terminated,
1538 guint element_size);
1539 void g_array_free (GArray *array,
1540 gboolean free_segment);
1541 GArray* g_array_append_vals (GArray *array,
1544 GArray* g_array_prepend_vals (GArray *array,
1547 GArray* g_array_set_size (GArray *array,
1550 /* Resizable pointer array. This interface is much less complicated
1551 * than the above. Add appends appends a pointer. Remove fills any
1552 * cleared spot and shortens the array.
1554 #define g_ptr_array_index(array,index) (array->pdata)[index]
1555 GPtrArray* g_ptr_array_new (void);
1556 void g_ptr_array_free (GPtrArray *array,
1558 void g_ptr_array_set_size (GPtrArray *array,
1560 gpointer g_ptr_array_remove_index (GPtrArray *array,
1562 gboolean g_ptr_array_remove (GPtrArray *array,
1564 void g_ptr_array_add (GPtrArray *array,
1567 /* Byte arrays, an array of guint8. Implemented as a GArray,
1571 GByteArray* g_byte_array_new (void);
1572 void g_byte_array_free (GByteArray *array,
1573 gboolean free_segment);
1574 GByteArray* g_byte_array_append (GByteArray *array,
1577 GByteArray* g_byte_array_prepend (GByteArray *array,
1580 GByteArray* g_byte_array_set_size (GByteArray *array,
1586 gint g_str_equal (gconstpointer v,
1588 guint g_str_hash (gconstpointer v);
1590 gint g_int_equal (gconstpointer v,
1592 guint g_int_hash (gconstpointer v);
1594 /* This "hash" function will just return the key's adress as an
1595 * unsigned integer. Useful for hashing on plain adresses or
1596 * simple integer values.
1598 guint g_direct_hash (gconstpointer v);
1599 gint g_direct_equal (gconstpointer v,
1603 /* Quarks (string<->id association)
1605 GQuark g_quark_try_string (const gchar *string);
1606 GQuark g_quark_from_static_string (const gchar *string);
1607 GQuark g_quark_from_string (const gchar *string);
1608 gchar* g_quark_to_string (GQuark quark);
1613 void g_datalist_init (GData **datalist);
1614 void g_datalist_clear (GData **datalist);
1615 gpointer g_datalist_id_get_data (GData **datalist,
1617 void g_datalist_id_set_data_full (GData **datalist,
1620 GDestroyNotify destroy_func);
1621 void g_datalist_id_remove_no_notify (GData **datalist,
1623 void g_datalist_foreach (GData **datalist,
1624 GDataForeachFunc func,
1625 gpointer user_data);
1626 #define g_datalist_id_set_data(dl, q, d) \
1627 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1628 #define g_datalist_id_remove_data(dl, q) \
1629 g_datalist_id_set_data ((dl), (q), NULL)
1630 #define g_datalist_get_data(dl, k) \
1631 (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1632 #define g_datalist_set_data_full(dl, k, d, f) \
1633 g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1634 #define g_datalist_remove_no_notify(dl, k) \
1635 g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1636 #define g_datalist_set_data(dl, k, d) \
1637 g_datalist_set_data_full ((dl), (k), (d), NULL)
1638 #define g_datalist_remove_data(dl, k) \
1639 g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1642 /* Location Associated Keyed Data
1644 void g_dataset_destroy (gconstpointer dataset_location);
1645 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1647 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1650 GDestroyNotify destroy_func);
1651 void g_dataset_id_remove_no_notify (gconstpointer dataset_location,
1653 void g_dataset_foreach (gconstpointer dataset_location,
1654 GDataForeachFunc func,
1655 gpointer user_data);
1656 #define g_dataset_id_set_data(l, k, d) \
1657 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1658 #define g_dataset_id_remove_data(l, k) \
1659 g_dataset_id_set_data ((l), (k), NULL)
1660 #define g_dataset_get_data(l, k) \
1661 (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1662 #define g_dataset_set_data_full(l, k, d, f) \
1663 g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1664 #define g_dataset_remove_no_notify(l, k) \
1665 g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1666 #define g_dataset_set_data(l, k, d) \
1667 g_dataset_set_data_full ((l), (k), (d), NULL)
1668 #define g_dataset_remove_data(l, k) \
1669 g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1672 /* GScanner: Flexible lexical scanner for general purpose.
1675 /* Character sets */
1676 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1677 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1678 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1679 "\307\310\311\312\313\314\315\316\317\320"\
1680 "\321\322\323\324\325\326"\
1681 "\330\331\332\333\334\335\336"
1682 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1683 "\347\350\351\352\353\354\355\356\357\360"\
1684 "\361\362\363\364\365\366"\
1685 "\370\371\372\373\374\375\376\377"
1692 G_ERR_UNEXP_EOF_IN_STRING,
1693 G_ERR_UNEXP_EOF_IN_COMMENT,
1694 G_ERR_NON_DIGIT_IN_CONST,
1697 G_ERR_FLOAT_MALFORMED
1705 G_TOKEN_LEFT_PAREN = '(',
1706 G_TOKEN_RIGHT_PAREN = ')',
1707 G_TOKEN_LEFT_CURLY = '{',
1708 G_TOKEN_RIGHT_CURLY = '}',
1709 G_TOKEN_LEFT_BRACE = '[',
1710 G_TOKEN_RIGHT_BRACE = ']',
1711 G_TOKEN_EQUAL_SIGN = '=',
1712 G_TOKEN_COMMA = ',',
1728 G_TOKEN_IDENTIFIER_NULL,
1730 G_TOKEN_COMMENT_SINGLE,
1731 G_TOKEN_COMMENT_MULTI,
1738 gchar *v_identifier;
1750 struct _GScannerConfig
1754 gchar *cset_skip_characters; /* default: " \t\n" */
1755 gchar *cset_identifier_first;
1756 gchar *cset_identifier_nth;
1757 gchar *cpair_comment_single; /* default: "#\n" */
1759 /* Should symbol lookup work case sensitive?
1761 guint case_sensitive : 1;
1763 /* Boolean values to be adjusted "on the fly"
1764 * to configure scanning behaviour.
1766 guint skip_comment_multi : 1; /* C like comment */
1767 guint skip_comment_single : 1; /* single line comment */
1768 guint scan_comment_multi : 1; /* scan multi line comments? */
1769 guint scan_identifier : 1;
1770 guint scan_identifier_1char : 1;
1771 guint scan_identifier_NULL : 1;
1772 guint scan_symbols : 1;
1773 guint scan_binary : 1;
1774 guint scan_octal : 1;
1775 guint scan_float : 1;
1776 guint scan_hex : 1; /* `0x0ff0' */
1777 guint scan_hex_dollar : 1; /* `$0ff0' */
1778 guint scan_string_sq : 1; /* string: 'anything' */
1779 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1780 guint numbers_2_int : 1; /* bin, octal, hex => int */
1781 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1782 guint identifier_2_string : 1;
1783 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1784 guint symbol_2_token : 1;
1785 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1792 guint max_parse_errors;
1794 /* g_scanner_error() increments this field */
1797 /* name of input stream, featured by the default message handler */
1798 const gchar *input_name;
1800 /* data pointer for derived structures */
1801 gpointer derived_data;
1803 /* link into the scanner configuration */
1804 GScannerConfig *config;
1806 /* fields filled in after g_scanner_get_next_token() */
1812 /* fields filled in after g_scanner_peek_next_token() */
1813 GTokenType next_token;
1814 GTokenValue next_value;
1816 guint next_position;
1818 /* to be considered private */
1819 GHashTable *symbol_table;
1822 const gchar *text_end;
1826 /* handler function for _warn and _error */
1827 GScannerMsgFunc msg_handler;
1830 GScanner* g_scanner_new (GScannerConfig *config_templ);
1831 void g_scanner_destroy (GScanner *scanner);
1832 void g_scanner_input_file (GScanner *scanner,
1834 void g_scanner_input_text (GScanner *scanner,
1837 GTokenType g_scanner_get_next_token (GScanner *scanner);
1838 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1839 GTokenType g_scanner_cur_token (GScanner *scanner);
1840 GTokenValue g_scanner_cur_value (GScanner *scanner);
1841 guint g_scanner_cur_line (GScanner *scanner);
1842 guint g_scanner_cur_position (GScanner *scanner);
1843 gboolean g_scanner_eof (GScanner *scanner);
1844 guint g_scanner_set_scope (GScanner *scanner,
1846 void g_scanner_scope_add_symbol (GScanner *scanner,
1848 const gchar *symbol,
1850 void g_scanner_scope_remove_symbol (GScanner *scanner,
1852 const gchar *symbol);
1853 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1855 const gchar *symbol);
1856 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1859 gpointer func_data);
1860 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1861 const gchar *symbol);
1862 void g_scanner_freeze_symbol_table (GScanner *scanner);
1863 void g_scanner_thaw_symbol_table (GScanner *scanner);
1864 void g_scanner_unexp_token (GScanner *scanner,
1865 GTokenType expected_token,
1866 const gchar *identifier_spec,
1867 const gchar *symbol_spec,
1868 const gchar *symbol_name,
1869 const gchar *message,
1871 void g_scanner_error (GScanner *scanner,
1872 const gchar *format,
1873 ...) G_GNUC_PRINTF (2,3);
1874 void g_scanner_warn (GScanner *scanner,
1875 const gchar *format,
1876 ...) G_GNUC_PRINTF (2,3);
1877 gint g_scanner_stat_mode (const gchar *filename);
1878 /* keep downward source compatibility */
1879 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1880 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1882 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1883 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1885 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1886 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1895 GCompletionFunc func;
1901 GCompletion* g_completion_new (GCompletionFunc func);
1902 void g_completion_add_items (GCompletion* cmp,
1904 void g_completion_remove_items (GCompletion* cmp,
1906 void g_completion_clear_items (GCompletion* cmp);
1907 GList* g_completion_complete (GCompletion* cmp,
1909 gchar** new_prefix);
1910 void g_completion_free (GCompletion* cmp);
1913 /* GRelation: Indexed Relations. Imagine a really simple table in a
1914 * database. Relations are not ordered. This data type is meant for
1915 * maintaining a N-way mapping.
1917 * g_relation_new() creates a relation with FIELDS fields
1919 * g_relation_destroy() frees all resources
1920 * g_tuples_destroy() frees the result of g_relation_select()
1922 * g_relation_index() indexes relation FIELD with the provided
1923 * equality and hash functions. this must be done before any
1924 * calls to insert are made.
1926 * g_relation_insert() inserts a new tuple. you are expected to
1927 * provide the right number of fields.
1929 * g_relation_delete() deletes all relations with KEY in FIELD
1930 * g_relation_select() returns ...
1931 * g_relation_count() counts ...
1934 GRelation* g_relation_new (gint fields);
1935 void g_relation_destroy (GRelation *relation);
1936 void g_relation_index (GRelation *relation,
1938 GHashFunc hash_func,
1939 GCompareFunc key_compare_func);
1940 void g_relation_insert (GRelation *relation,
1942 gint g_relation_delete (GRelation *relation,
1945 GTuples* g_relation_select (GRelation *relation,
1948 gint g_relation_count (GRelation *relation,
1951 gboolean g_relation_exists (GRelation *relation,
1953 void g_relation_print (GRelation *relation);
1955 void g_tuples_destroy (GTuples *tuples);
1956 gpointer g_tuples_index (GTuples *tuples,
1964 /* This function returns prime numbers spaced by approximately 1.5-2.0
1965 * and is for use in resizing data structures which prefer
1966 * prime-valued sizes. The closest spaced prime function returns the
1967 * next largest prime, or the highest it knows about which is about
1971 guint g_spaced_primes_closest (guint num);
1975 extern const guint glib_major_version;
1976 extern const guint glib_minor_version;
1977 extern const guint glib_micro_version;
1981 #endif /* __cplusplus */
1984 #endif /* __G_LIB_H__ */