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:
55 #define G_MINFLOAT FLT_MIN
56 #define G_MAXFLOAT FLT_MAX
57 #define G_MINDOUBLE DBL_MIN
58 #define G_MAXDOUBLE DBL_MAX
64 #define G_MINFLOAT MINFLOAT
65 #define G_MAXFLOAT MAXFLOAT
66 #define G_MINDOUBLE MINDOUBLE
67 #define G_MAXDOUBLE MAXDOUBLE
69 #endif /* HAVE_VALUES_H */
75 #define G_MINSHORT SHRT_MIN
76 #define G_MAXSHORT SHRT_MAX
77 #define G_MININT INT_MIN
78 #define G_MAXINT INT_MAX
79 #define G_MINLONG LONG_MIN
80 #define G_MAXLONG LONG_MAX
86 #endif /* HAVE_FLOAT_H */
88 #define G_MINSHORT MINSHORT
89 #define G_MAXSHORT MAXSHORT
90 #define G_MININT MININT
91 #define G_MAXINT MAXINT
92 #define G_MINLONG MINLONG
93 #define G_MAXLONG MAXLONG
95 #endif /* HAVE_VALUES_H */
98 /* the #pragma } statment is used to fix up emacs' c-mode which gets
99 * confused by extern "C" {. the ansi standard says that compilers
100 * have to ignore #pragma directives that they don't know about,
101 * so we should be save in using this.
106 #endif /* __cplusplus */
109 /* Provide definitions for some commonly used macros.
110 * Some of them are only provided if they haven't already
111 * been defined. It is assumed that if they are already
112 * defined then the current definition is correct.
115 #define NULL ((void*) 0)
123 #define TRUE (!FALSE)
127 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
130 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
133 #define ABS(a) (((a) < 0) ? -(a) : (a))
136 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
139 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
140 * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
142 #if !defined (G_VA_COPY)
143 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
144 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
145 # elif defined (G_VA_COPY_AS_ARRAY)
146 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
147 # else /* va_list is a pointer */
148 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
149 # endif /* va_list is a pointer */
150 #endif /* !G_VA_COPY */
153 /* Provide simple enum value macro wrappers that ease automated
154 * enum value stringification code. [abandoned]
156 #if !defined (G_CODE_GENERATION)
157 #define G_ENUM( EnumerationName ) EnumerationName
158 #define G_FLAGS( EnumerationName ) EnumerationName
159 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
160 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
161 #else /* G_CODE_GENERATION */
162 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
163 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
164 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
165 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
166 #endif /* G_CODE_GENERATION */
169 /* inlining hassle. for compilers that don't allow the `inline' keyword,
170 * mostly because of strict ANSI C compliance or dumbness, we try to fall
171 * back to either `__inline__' or `__inline'.
172 * we define G_CAN_INLINE, if the compiler seems to be actually
173 * *capable* to do function inlining, in which case inline function bodys
174 * do make sense. we also define G_INLINE_FUNC to properly export the
175 * function prototypes if no inlinig can be performed.
176 * we special case most of the stuff, so inline functions can have a normal
177 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
179 #ifndef G_INLINE_FUNC
180 # define G_CAN_INLINE 1
183 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
185 # define inline __inline__
187 #else /* !G_HAVE_INLINE */
189 # if defined (G_HAVE___INLINE__)
190 # define inline __inline__
191 # else /* !inline && !__inline__ */
192 # if defined (G_HAVE___INLINE)
193 # define inline __inline
194 # else /* !inline && !__inline__ && !__inline */
195 # define inline /* don't inline, then */
196 # ifndef G_INLINE_FUNC
202 #ifndef G_INLINE_FUNC
205 # define G_INLINE_FUNC extern inline
208 # define G_INLINE_FUNC extern
210 # else /* !__GNUC__ */
212 # define G_INLINE_FUNC static inline
214 # define G_INLINE_FUNC extern
216 # endif /* !__GNUC__ */
217 #endif /* !G_INLINE_FUNC */
220 /* Provide simple macro statement wrappers (adapted from Perl):
221 * G_STMT_START { statements; } G_STMT_END;
222 * can be used as a single statement, as in
223 * if (x) G_STMT_START { ... } G_STMT_END; else ...
225 * For gcc we will wrap the statements within `({' and `})' braces.
226 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
227 * and otherwise within `do' and `while (0)'.
229 #if !(defined (G_STMT_START) && defined (G_STMT_END))
230 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
231 # define G_STMT_START (void)(
232 # define G_STMT_END )
234 # if (defined (sun) || defined (__sun__))
235 # define G_STMT_START if (1)
236 # define G_STMT_END else (void)0
238 # define G_STMT_START do
239 # define G_STMT_END while (0)
245 /* Provide macros to feature the GCC function attribute.
247 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
248 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
249 __attribute__((format (printf, format_idx, arg_idx)))
250 #define G_GNUC_SCANF( format_idx, arg_idx ) \
251 __attribute__((format (scanf, format_idx, arg_idx)))
252 #define G_GNUC_FORMAT( arg_idx ) \
253 __attribute__((format_arg (arg_idx)))
254 #define G_GNUC_NORETURN \
255 __attribute__((noreturn))
256 #define G_GNUC_CONST \
257 __attribute__((const))
258 #else /* !__GNUC__ */
259 #define G_GNUC_PRINTF( format_idx, arg_idx )
260 #define G_GNUC_SCANF( format_idx, arg_idx )
261 #define G_GNUC_FORMAT( arg_idx )
262 #define G_GNUC_NORETURN
264 #endif /* !__GNUC__ */
267 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
268 * macros, so we can refer to them as strings unconditionally.
271 #define G_GNUC_FUNCTION (__FUNCTION__)
272 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
273 #else /* !__GNUC__ */
274 #define G_GNUC_FUNCTION ("")
275 #define G_GNUC_PRETTY_FUNCTION ("")
276 #endif /* !__GNUC__ */
279 /* we try to provide a usefull equivalent for ATEXIT if it is
280 * not defined, but use is actually abandoned. people should
281 * use g_atexit() instead.
282 * keep this in sync with gutils.c.
286 # ifdef NeXT /* @#%@! NeXTStep */
287 # define ATEXIT(proc) (!atexit (proc))
289 # define ATEXIT(proc) (atexit (proc))
291 # elif defined (HAVE_ON_EXIT)
292 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
294 # error Could not determine proper atexit() implementation
297 # define G_NATIVE_ATEXIT
300 /* Hacker macro to place breakpoints for x86 machines.
301 * Actual use is strongly deprecated of course ;)
303 #if defined (__i386__) && defined (__GNUC__)
304 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
305 #else /* !__i386__ */
306 #define G_BREAKPOINT()
307 #endif /* __i386__ */
310 /* Provide macros for easily allocating memory. The macros
311 * will cast the allocated memory to the specified type
312 * in order to avoid compiler warnings. (Makes the code neater).
317 #define g_new(type, count) (ALLOC (type, count))
318 #define g_new0(type, count) (CALLOC (type, count))
320 #else /* __DMALLOC_H__ */
322 #define g_new(type, count) \
323 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
324 #define g_new0(type, count) \
325 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
326 #endif /* __DMALLOC_H__ */
328 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
329 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
331 sizeof (type) * (pre_alloc), \
334 #define g_chunk_new(type, chunk) ( \
335 (type *) g_mem_chunk_alloc (chunk) \
337 #define g_chunk_new0(type, chunk) ( \
338 (type *) g_mem_chunk_alloc0 (chunk) \
340 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
341 g_mem_chunk_free ((mem_chunk), (mem)); \
345 #define g_string(x) #x
348 /* Provide macros for error handling. The "assert" macros will
349 * exit on failure. The "return" macros will exit the current
350 * function. Two different definitions are given for the macros
351 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
352 * __PRETTY_FUNCTION__ capability.
355 #ifdef G_DISABLE_ASSERT
357 #define g_assert(expr)
358 #define g_assert_not_reached()
360 #else /* !G_DISABLE_ASSERT */
364 #define g_assert(expr) G_STMT_START{ \
366 g_log (G_LOG_DOMAIN, \
368 "file %s: line %d (%s): assertion failed: (%s)", \
371 __PRETTY_FUNCTION__, \
374 #define g_assert_not_reached() G_STMT_START{ \
375 g_log (G_LOG_DOMAIN, \
377 "file %s: line %d (%s): should not be reached", \
380 __PRETTY_FUNCTION__); }G_STMT_END
382 #else /* !__GNUC__ */
384 #define g_assert(expr) G_STMT_START{ \
386 g_log (G_LOG_DOMAIN, \
388 "file %s: line %d: assertion failed: (%s)", \
393 #define g_assert_not_reached() G_STMT_START{ \
394 g_log (G_LOG_DOMAIN, \
396 "file %s: line %d: should not be reached", \
398 __LINE__); }G_STMT_END
400 #endif /* __GNUC__ */
402 #endif /* !G_DISABLE_ASSERT */
405 #ifdef G_DISABLE_CHECKS
407 #define g_return_if_fail(expr)
408 #define g_return_val_if_fail(expr,val)
410 #else /* !G_DISABLE_CHECKS */
414 #define g_return_if_fail(expr) 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 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
430 g_log (G_LOG_DOMAIN, \
431 G_LOG_LEVEL_CRITICAL, \
432 "file %s: line %d (%s): assertion `%s' failed.", \
435 __PRETTY_FUNCTION__, \
440 #else /* !__GNUC__ */
442 #define g_return_if_fail(expr) G_STMT_START{ \
445 g_log (G_LOG_DOMAIN, \
446 G_LOG_LEVEL_CRITICAL, \
447 "file %s: line %d: assertion `%s' failed.", \
454 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
457 g_log (G_LOG_DOMAIN, \
458 G_LOG_LEVEL_CRITICAL, \
459 "file %s: line %d: assertion `%s' failed.", \
466 #endif /* !__GNUC__ */
468 #endif /* !G_DISABLE_CHECKS */
471 /* Provide type definitions for commonly used types.
472 * These are useful because a "gint8" can be adjusted
473 * to be 1 byte (8 bits) on all platforms. Similarly and
474 * more importantly, "gint32" can be adjusted to be
475 * 4 bytes (32 bits) on all platforms.
479 typedef short gshort;
482 typedef gint gboolean;
484 typedef unsigned char guchar;
485 typedef unsigned short gushort;
486 typedef unsigned long gulong;
487 typedef unsigned int guint;
489 typedef float gfloat;
490 typedef double gdouble;
492 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
493 * Since gldouble isn't used anywhere, just disable it for now */
496 #ifdef HAVE_LONG_DOUBLE
497 typedef long double gldouble;
498 #else /* HAVE_LONG_DOUBLE */
499 typedef double gldouble;
500 #endif /* HAVE_LONG_DOUBLE */
503 typedef void* gpointer;
504 typedef const void *gconstpointer;
506 #if (SIZEOF_CHAR == 1)
507 typedef signed char gint8;
508 typedef unsigned char guint8;
509 #endif /* SIZEOF_CHAR */
511 #if (SIZEOF_SHORT == 2)
512 typedef signed short gint16;
513 typedef unsigned short guint16;
514 #endif /* SIZEOF_SHORT */
516 #if (SIZEOF_INT == 4)
517 typedef signed int gint32;
518 typedef unsigned int guint32;
519 #elif (SIZEOF_LONG == 4)
520 typedef signed long gint32;
521 typedef unsigned long guint32;
522 #endif /* SIZEOF_INT */
524 #if (SIZEOF_LONG == 8)
525 #define HAVE_GINT64 1
526 typedef signed long gint64;
527 typedef unsigned long guint64;
528 #elif (SIZEOF_LONG_LONG == 8)
529 #define HAVE_GINT64 1
530 typedef signed long long gint64;
531 typedef unsigned long long guint64;
538 /* Define macros for storing integers inside pointers
540 #if (SIZEOF_INT == SIZEOF_VOID_P)
542 #define GPOINTER_TO_INT(p) ((gint)(p))
543 #define GPOINTER_TO_UINT(p) ((guint)(p))
545 #define GINT_TO_POINTER(i) ((gpointer)(i))
546 #define GUINT_TO_POINTER(u) ((gpointer)(u))
548 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
550 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
551 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
553 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
554 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
557 #error SIZEOF_VOID_P unknown - This should never happen
560 typedef gint32 gssize;
561 typedef guint32 gsize;
562 typedef guint32 GQuark;
563 typedef gint32 GTime;
568 extern const guint glib_major_version;
569 extern const guint glib_minor_version;
570 extern const guint glib_micro_version;
571 extern const guint glib_interface_age;
572 extern const guint glib_binary_age;
575 /* Forward declarations of glib types.
578 typedef struct _GList GList;
579 typedef struct _GSList GSList;
580 typedef struct _GHashTable GHashTable;
581 typedef struct _GCache GCache;
582 typedef struct _GTree GTree;
583 typedef struct _GTimer GTimer;
584 typedef struct _GMemChunk GMemChunk;
585 typedef struct _GListAllocator GListAllocator;
586 typedef struct _GStringChunk GStringChunk;
587 typedef struct _GString GString;
588 typedef struct _GArray GArray;
589 typedef struct _GPtrArray GPtrArray;
590 typedef struct _GByteArray GByteArray;
591 typedef struct _GDebugKey GDebugKey;
592 typedef struct _GScannerConfig GScannerConfig;
593 typedef struct _GScanner GScanner;
594 typedef union _GValue GValue;
595 typedef struct _GCompletion GCompletion;
596 typedef struct _GRelation GRelation;
597 typedef struct _GTuples GTuples;
598 typedef struct _GNode GNode;
603 G_TRAVERSE_LEAFS = 1 << 0,
604 G_TRAVERSE_NON_LEAFS = 1 << 1,
605 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
606 G_TRAVERSE_MASK = 0x03
617 /* Log level shift offset for user defined
618 * log levels (0-7 are used by GLib).
620 #define G_LOG_LEVEL_USER_SHIFT (8)
622 /* Glib log levels and flags.
627 G_LOG_FLAG_RECURSION = 1 << 0,
628 G_LOG_FLAG_FATAL = 1 << 1,
630 /* GLib log levels */
631 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
632 G_LOG_LEVEL_CRITICAL = 1 << 3,
633 G_LOG_LEVEL_WARNING = 1 << 4,
634 G_LOG_LEVEL_MESSAGE = 1 << 5,
635 G_LOG_LEVEL_INFO = 1 << 6,
636 G_LOG_LEVEL_DEBUG = 1 << 7,
638 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
641 /* GLib log levels that are considered fatal by default */
642 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
645 typedef gpointer (*GCacheNewFunc) (gpointer key);
646 typedef gpointer (*GCacheDupFunc) (gpointer value);
647 typedef void (*GCacheDestroyFunc) (gpointer value);
648 typedef gint (*GCompareFunc) (gconstpointer a,
650 typedef gchar* (*GCompletionFunc) (gpointer);
651 typedef void (*GDestroyNotify) (gpointer data);
652 typedef void (*GFunc) (gpointer data,
654 typedef guint (*GHashFunc) (gconstpointer key);
655 typedef void (*GHFunc) (gpointer key,
658 typedef void (*GLogFunc) (const gchar *log_domain,
659 GLogLevelFlags log_level,
660 const gchar *message,
662 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
664 typedef void (*GNodeForeachFunc) (GNode *node,
666 typedef gint (*GSearchFunc) (gpointer key,
668 typedef void (*GScannerMsgFunc) (GScanner *scanner,
671 typedef gint (*GTraverseFunc) (gpointer key,
674 typedef void (*GVoidFunc) (void);
725 struct _GCache { gint dummy; };
726 struct _GTree { gint dummy; };
727 struct _GTimer { gint dummy; };
728 struct _GMemChunk { gint dummy; };
729 struct _GListAllocator { gint dummy; };
730 struct _GStringChunk { gint dummy; };
733 /* Doubly linked lists
735 GList* g_list_alloc (void);
736 void g_list_free (GList *list);
737 void g_list_free_1 (GList *list);
738 GList* g_list_append (GList *list,
740 GList* g_list_prepend (GList *list,
742 GList* g_list_insert (GList *list,
745 GList* g_list_insert_sorted (GList *list,
748 GList* g_list_concat (GList *list1,
750 GList* g_list_remove (GList *list,
752 GList* g_list_remove_link (GList *list,
754 GList* g_list_reverse (GList *list);
755 GList* g_list_nth (GList *list,
757 GList* g_list_find (GList *list,
759 GList* g_list_find_custom (GList *list,
762 gint g_list_position (GList *list,
764 gint g_list_index (GList *list,
766 GList* g_list_last (GList *list);
767 GList* g_list_first (GList *list);
768 guint g_list_length (GList *list);
769 void g_list_foreach (GList *list,
772 gpointer g_list_nth_data (GList *list,
774 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
775 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
778 /* Singly linked lists
780 GSList* g_slist_alloc (void);
781 void g_slist_free (GSList *list);
782 void g_slist_free_1 (GSList *list);
783 GSList* g_slist_append (GSList *list,
785 GSList* g_slist_prepend (GSList *list,
787 GSList* g_slist_insert (GSList *list,
790 GSList* g_slist_insert_sorted (GSList *list,
793 GSList* g_slist_concat (GSList *list1,
795 GSList* g_slist_remove (GSList *list,
797 GSList* g_slist_remove_link (GSList *list,
799 GSList* g_slist_reverse (GSList *list);
800 GSList* g_slist_nth (GSList *list,
802 GSList* g_slist_find (GSList *list,
804 GSList* g_slist_find_custom (GSList *list,
807 gint g_slist_position (GSList *list,
809 gint g_slist_index (GSList *list,
811 GSList* g_slist_last (GSList *list);
812 guint g_slist_length (GSList *list);
813 void g_slist_foreach (GSList *list,
816 gpointer g_slist_nth_data (GSList *list,
818 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
823 GListAllocator* g_list_allocator_new (void);
824 void g_list_allocator_free (GListAllocator* allocator);
825 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
826 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
831 GHashTable* g_hash_table_new (GHashFunc hash_func,
832 GCompareFunc key_compare_func);
833 void g_hash_table_destroy (GHashTable *hash_table);
834 void g_hash_table_insert (GHashTable *hash_table,
837 void g_hash_table_remove (GHashTable *hash_table,
839 gpointer g_hash_table_lookup (GHashTable *hash_table,
841 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
842 gconstpointer lookup_key,
845 void g_hash_table_freeze (GHashTable *hash_table);
846 void g_hash_table_thaw (GHashTable *hash_table);
847 void g_hash_table_foreach (GHashTable *hash_table,
850 gint g_hash_table_size (GHashTable *hash_table);
855 GCache* g_cache_new (GCacheNewFunc value_new_func,
856 GCacheDestroyFunc value_destroy_func,
857 GCacheDupFunc key_dup_func,
858 GCacheDestroyFunc key_destroy_func,
859 GHashFunc hash_key_func,
860 GHashFunc hash_value_func,
861 GCompareFunc key_compare_func);
862 void g_cache_destroy (GCache *cache);
863 gpointer g_cache_insert (GCache *cache,
865 void g_cache_remove (GCache *cache,
867 void g_cache_key_foreach (GCache *cache,
870 void g_cache_value_foreach (GCache *cache,
875 /* Balanced binary trees
877 GTree* g_tree_new (GCompareFunc key_compare_func);
878 void g_tree_destroy (GTree *tree);
879 void g_tree_insert (GTree *tree,
882 void g_tree_remove (GTree *tree,
884 gpointer g_tree_lookup (GTree *tree,
886 void g_tree_traverse (GTree *tree,
887 GTraverseFunc traverse_func,
888 GTraverseType traverse_type,
890 gpointer g_tree_search (GTree *tree,
891 GSearchFunc search_func,
893 gint g_tree_height (GTree *tree);
894 gint g_tree_nnodes (GTree *tree);
898 /* N-way tree implementation
909 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
910 ((GNode*) (node))->prev == NULL && \
911 ((GNode*) (node))->next == NULL)
912 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
914 GNode* g_node_new (gpointer data);
915 void g_node_destroy (GNode *root);
916 void g_node_unlink (GNode *node);
917 GNode* g_node_insert (GNode *parent,
920 GNode* g_node_insert_before (GNode *parent,
923 GNode* g_node_prepend (GNode *parent,
925 guint g_node_n_nodes (GNode *root,
926 GTraverseFlags flags);
927 GNode* g_node_get_root (GNode *node);
928 gboolean g_node_is_ancestor (GNode *node,
930 guint g_node_depth (GNode *node);
931 GNode* g_node_find (GNode *root,
933 GTraverseFlags flags,
936 /* convenience macros */
937 #define g_node_append(parent, node) \
938 g_node_insert_before ((parent), NULL, (node))
939 #define g_node_insert_data(parent, position, data) \
940 g_node_insert ((parent), (position), g_node_new (data))
941 #define g_node_insert_data_before(parent, sibling, data) \
942 g_node_insert_before ((parent), (sibling), g_node_new (data))
943 #define g_node_prepend_data(parent, data) \
944 g_node_prepend ((parent), g_node_new (data))
945 #define g_node_append_data(parent, data) \
946 g_node_insert_before ((parent), NULL, g_node_new (data))
948 /* traversal function, assumes that `node' is root
949 * (only traverses `node' and its subtree).
950 * this function is just a high level interface to
951 * low level traversal functions, optimized for speed.
953 void g_node_traverse (GNode *root,
955 GTraverseFlags flags,
957 GNodeTraverseFunc func,
960 /* return the maximum tree height starting with `node', this is an expensive
961 * operation, since we need to visit all nodes. this could be shortened by
962 * adding `guint height' to struct _GNode, but then again, this is not very
963 * often needed, and would make g_node_insert() more time consuming.
965 guint g_node_max_height (GNode *root);
967 void g_node_children_foreach (GNode *node,
968 GTraverseFlags flags,
969 GNodeForeachFunc func,
971 void g_node_reverse_children (GNode *node);
972 guint g_node_n_children (GNode *node);
973 GNode* g_node_nth_child (GNode *node,
975 GNode* g_node_last_child (GNode *node);
976 GNode* g_node_find_child (GNode *node,
977 GTraverseFlags flags,
979 gint g_node_child_position (GNode *node,
981 gint g_node_child_index (GNode *node,
984 GNode* g_node_first_sibling (GNode *node);
985 GNode* g_node_last_sibling (GNode *node);
987 #define g_node_prev_sibling(node) ((node) ? \
988 ((GNode*) (node))->prev : NULL)
989 #define g_node_next_sibling(node) ((node) ? \
990 ((GNode*) (node))->next : NULL)
991 #define g_node_first_child(node) ((node) ? \
992 ((GNode*) (node))->children : NULL)
995 /* Fatal error handlers.
996 * g_on_error_query() will prompt the user to either
997 * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
998 * g_on_error_stack_trace() invokes gdb, which attaches to the current
999 * process and shows a stack trace.
1000 * These function may cause different actions on non-unix platforms.
1001 * The prg_name arg is required by gdb to find the executable, if it is
1002 * passed as NULL, g_on_error_query() will try g_get_prgname().
1004 void g_on_error_query (const gchar *prg_name);
1005 void g_on_error_stack_trace (const gchar *prg_name);
1008 /* Logging mechanism
1010 extern const gchar *g_log_domain_glib;
1011 guint g_log_set_handler (const gchar *log_domain,
1012 GLogLevelFlags log_levels,
1014 gpointer user_data);
1015 void g_log_remove_handler (const gchar *log_domain,
1017 void g_log_default_handler (const gchar *log_domain,
1018 GLogLevelFlags log_level,
1019 const gchar *message,
1020 gpointer unused_data);
1021 void g_log (const gchar *log_domain,
1022 GLogLevelFlags log_level,
1023 const gchar *format,
1024 ...) G_GNUC_PRINTF (3, 4);
1025 void g_logv (const gchar *log_domain,
1026 GLogLevelFlags log_level,
1027 const gchar *format,
1029 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
1030 GLogLevelFlags fatal_mask);
1031 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
1032 #ifndef G_LOG_DOMAIN
1033 #define G_LOG_DOMAIN (NULL)
1034 #endif /* G_LOG_DOMAIN */
1036 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1037 G_LOG_LEVEL_ERROR, \
1039 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1040 G_LOG_LEVEL_MESSAGE, \
1042 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1043 G_LOG_LEVEL_WARNING, \
1045 #else /* !__GNUC__ */
1047 g_error (const gchar *format,
1051 va_start (args, format);
1052 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1056 g_message (const gchar *format,
1060 va_start (args, format);
1061 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1065 g_warning (const gchar *format,
1069 va_start (args, format);
1070 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1073 #endif /* !__GNUC__ */
1075 typedef void (*GPrintFunc) (const gchar *string);
1076 void g_print (const gchar *format,
1077 ...) G_GNUC_PRINTF (1, 2);
1078 GPrintFunc g_set_print_handler (GPrintFunc func);
1079 void g_printerr (const gchar *format,
1080 ...) G_GNUC_PRINTF (1, 2);
1081 GPrintFunc g_set_printerr_handler (GPrintFunc func);
1083 /* deprecated compatibility functions, use g_log_set_handler() instead */
1084 typedef void (*GErrorFunc) (const gchar *str);
1085 typedef void (*GWarningFunc) (const gchar *str);
1086 GErrorFunc g_set_error_handler (GErrorFunc func);
1087 GWarningFunc g_set_warning_handler (GWarningFunc func);
1088 GPrintFunc g_set_message_handler (GPrintFunc func);
1091 /* Memory allocation and debugging
1095 #define g_malloc(size) ((gpointer) MALLOC (size))
1096 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
1097 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
1098 #define g_free(mem) FREE (mem)
1100 #else /* !USE_DMALLOC */
1102 gpointer g_malloc (gulong size);
1103 gpointer g_malloc0 (gulong size);
1104 gpointer g_realloc (gpointer mem,
1106 void g_free (gpointer mem);
1108 #endif /* !USE_DMALLOC */
1110 void g_mem_profile (void);
1111 void g_mem_check (gpointer mem);
1114 /* "g_mem_chunk_new" creates a new memory chunk.
1115 * Memory chunks are used to allocate pieces of memory which are
1116 * always the same size. Lists are a good example of such a data type.
1117 * The memory chunk allocates and frees blocks of memory as needed.
1118 * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1119 * allocated in a mem chunk. ("g_free" will most likely cause a seg
1120 * fault...somewhere).
1122 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1123 * want to know what's going on inside do you?)
1126 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1127 * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1128 * atom. (They are also useful for lists which use MemChunk to allocate
1129 * memory but are also part of the MemChunk implementation).
1130 * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1133 #define G_ALLOC_ONLY 1
1134 #define G_ALLOC_AND_FREE 2
1136 GMemChunk* g_mem_chunk_new (gchar *name,
1140 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
1141 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
1142 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1143 void g_mem_chunk_free (GMemChunk *mem_chunk,
1145 void g_mem_chunk_clean (GMemChunk *mem_chunk);
1146 void g_mem_chunk_reset (GMemChunk *mem_chunk);
1147 void g_mem_chunk_print (GMemChunk *mem_chunk);
1148 void g_mem_chunk_info (void);
1150 /* Ah yes...we have a "g_blow_chunks" function.
1151 * "g_blow_chunks" simply compresses all the chunks. This operation
1152 * consists of freeing every memory area that should be freed (but
1153 * which we haven't gotten around to doing yet). And, no,
1154 * "g_blow_chunks" doesn't follow the naming scheme, but it is a
1155 * much better name than "g_mem_chunk_clean_all" or something
1158 void g_blow_chunks (void);
1163 GTimer* g_timer_new (void);
1164 void g_timer_destroy (GTimer *timer);
1165 void g_timer_start (GTimer *timer);
1166 void g_timer_stop (GTimer *timer);
1167 void g_timer_reset (GTimer *timer);
1168 gdouble g_timer_elapsed (GTimer *timer,
1169 gulong *microseconds);
1172 /* String utility functions
1174 #define G_STR_DELIMITERS "_-|> <."
1175 void g_strdelimit (gchar *string,
1176 const gchar *delimiters,
1177 gchar new_delimiter);
1178 gchar* g_strdup (const gchar *str);
1179 gchar* g_strdup_printf (const gchar *format,
1180 ...) G_GNUC_PRINTF (1, 2);
1181 gchar* g_strdup_vprintf (const gchar *format,
1183 gchar* g_strndup (const gchar *str,
1185 gchar* g_strnfill (guint length,
1187 gchar* g_strconcat (const gchar *string1,
1188 ...); /* NULL terminated */
1189 gdouble g_strtod (const gchar *nptr,
1191 gchar* g_strerror (gint errnum);
1192 gchar* g_strsignal (gint signum);
1193 gint g_strcasecmp (const gchar *s1,
1195 void g_strdown (gchar *string);
1196 void g_strup (gchar *string);
1197 void g_strreverse (gchar *string);
1199 /* calculate a string size, guarranteed to fit format + args.
1201 guint g_printf_string_upper_bound (const gchar* format,
1205 /* Retrive static string info
1207 gchar* g_get_user_name (void);
1208 gchar* g_get_real_name (void);
1209 gchar* g_get_home_dir (void);
1210 gchar* g_get_tmp_dir (void);
1211 gchar* g_get_prgname (void);
1212 void g_set_prgname (const gchar *prgname);
1215 /* Miscellaneous utility functions
1217 guint g_parse_debug_string (const gchar *string,
1220 gint g_snprintf (gchar *string,
1222 gchar const *format,
1223 ...) G_GNUC_PRINTF (3, 4);
1224 gint g_vsnprintf (gchar *string,
1226 gchar const *format,
1228 gchar* g_basename (const gchar *file_name);
1230 /* strings are newly allocated with g_malloc() */
1231 gchar* g_dirname (const gchar *file_name);
1232 gchar* g_get_current_dir (void);
1234 /* We make the assumption that if memmove isn't available, then
1235 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1236 * necessarily handle overlapping copies).
1237 * Either way, g_memmove() will not return a value.
1240 #define g_memmove(dest, src, size) G_STMT_START { \
1241 memmove ((dest), (src), (size)); \
1244 #define g_memmove(dest, src, size) G_STMT_START { \
1245 bcopy ((src), (dest), (size)); \
1249 /* we use a GLib function as a replacement for ATEXIT, so
1250 * the programmer is not required to check the return value
1251 * (if there is any in the implementation) and doesn't encounter
1252 * missing include files.
1254 void g_atexit (GVoidFunc func);
1259 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1263 g_bit_nth_lsf (guint32 mask,
1269 if (mask & (1 << (guint) nth_bit))
1272 while (nth_bit < 32);
1275 #endif /* G_CAN_INLINE */
1277 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1281 g_bit_nth_msf (guint32 mask,
1289 if (mask & (1 << (guint) nth_bit))
1292 while (nth_bit > 0);
1295 #endif /* G_CAN_INLINE */
1297 G_INLINE_FUNC guint g_bit_storage (guint number);
1300 g_bit_storage (guint number)
1302 register guint n_bits = 0;
1312 #endif /* G_CAN_INLINE */
1317 GStringChunk* g_string_chunk_new (gint size);
1318 void g_string_chunk_free (GStringChunk *chunk);
1319 gchar* g_string_chunk_insert (GStringChunk *chunk,
1320 const gchar *string);
1321 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1322 const gchar *string);
1327 GString* g_string_new (const gchar *init);
1328 GString* g_string_sized_new (guint dfl_size);
1329 void g_string_free (GString *string,
1331 GString* g_string_assign (GString *lval,
1333 GString* g_string_truncate (GString *string,
1335 GString* g_string_append (GString *string,
1337 GString* g_string_append_c (GString *string,
1339 GString* g_string_prepend (GString *string,
1341 GString* g_string_prepend_c (GString *string,
1343 GString* g_string_insert (GString *string,
1346 GString* g_string_insert_c (GString *string,
1349 GString* g_string_erase (GString *string,
1352 GString* g_string_down (GString *string);
1353 GString* g_string_up (GString *string);
1354 void g_string_sprintf (GString *string,
1355 const gchar *format,
1356 ...) G_GNUC_PRINTF (2, 3);
1357 void g_string_sprintfa (GString *string,
1358 const gchar *format,
1359 ...) G_GNUC_PRINTF (2, 3);
1365 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1366 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1367 #define g_array_index(a,t,i) (((t*)a->data)[i])
1369 GArray* g_array_new (gboolean zero_terminated,
1371 guint element_size);
1372 void g_array_free (GArray *array,
1373 gboolean free_segment);
1374 GArray* g_array_append_vals (GArray *array,
1377 GArray* g_array_prepend_vals (GArray *array,
1380 GArray* g_array_set_size (GArray *array,
1383 /* Resizable pointer array. This interface is much less complicated
1384 * than the above. Add appends appends a pointer. Remove fills any
1385 * cleared spot and shortens the array.
1387 #define g_ptr_array_index(array,index) (array->pdata)[index]
1388 GPtrArray* g_ptr_array_new (void);
1389 void g_ptr_array_free (GPtrArray *array,
1391 void g_ptr_array_set_size (GPtrArray *array,
1393 gpointer g_ptr_array_remove_index (GPtrArray *array,
1395 gboolean g_ptr_array_remove (GPtrArray *array,
1397 void g_ptr_array_add (GPtrArray *array,
1400 /* Byte arrays, an array of guint8. Implemented as a GArray,
1404 GByteArray* g_byte_array_new (void);
1405 void g_byte_array_free (GByteArray *array,
1406 gboolean free_segment);
1407 GByteArray* g_byte_array_append (GByteArray *array,
1410 GByteArray* g_byte_array_prepend (GByteArray *array,
1413 GByteArray* g_byte_array_set_size (GByteArray *array,
1419 gint g_str_equal (gconstpointer v,
1421 guint g_str_hash (gconstpointer v);
1423 gint g_int_equal (gconstpointer v,
1425 guint g_int_hash (gconstpointer v);
1427 /* This "hash" function will just return the key's adress as an
1428 * unsigned integer. Useful for hashing on plain adresses or
1429 * simple integer values.
1431 guint g_direct_hash (gconstpointer v);
1432 gint g_direct_equal (gconstpointer v,
1436 /* Quarks (string<->id association)
1438 GQuark g_quark_try_string (const gchar *string);
1439 GQuark g_quark_from_static_string (const gchar *string);
1440 GQuark g_quark_from_string (const gchar *string);
1441 gchar* g_quark_to_string (GQuark quark);
1446 void g_datalist_init (gpointer *datalist);
1447 void g_datalist_clear (gpointer *datalist);
1448 gpointer g_datalist_id_get_data (gpointer *datalist,
1450 void g_datalist_id_set_data_full (gpointer *datalist,
1453 GDestroyNotify destroy_func);
1454 void g_datalist_id_set_destroy (gpointer *datalist,
1456 GDestroyNotify destroy_func);
1457 #define g_datalist_id_set_data(dl, q, d) \
1458 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1459 #define g_datalist_id_remove_data(dl, q) \
1460 g_datalist_id_set_data ((dl), (q), NULL)
1461 #define g_datalist_get_data(dl, k) \
1462 (g_datalist_id_get_data ((dl), g_quark_try_string ((k))))
1463 #define g_datalist_set_data_full(dl, k, d, f) \
1464 g_datalist_id_set_data_full ((dl), g_quark_from_string ((k)), (d), (f))
1465 #define g_datalist_set_destroy(dl, k, f) \
1466 g_datalist_id_set_destroy ((dl), g_quark_try_string ((k)), (f))
1467 #define g_datalist_set_data(dl, k, d) \
1468 g_datalist_set_data_full ((dl), (k), (d), NULL)
1469 #define g_datalist_remove_data(dl, k) \
1470 g_datalist_id_set_data ((dl), g_quark_try_string ((k)), NULL)
1473 /* Location Associated Keyed Data
1475 void g_dataset_destroy (gconstpointer dataset_location);
1476 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1478 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1481 GDestroyNotify destroy_func);
1482 void g_dataset_id_set_destroy (gconstpointer dataset_location,
1484 GDestroyNotify destroy_func);
1485 #define g_dataset_id_set_data(l, k, d) \
1486 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1487 #define g_dataset_id_remove_data(l, k) \
1488 g_dataset_id_set_data ((l), (k), NULL)
1489 #define g_dataset_get_data(l, k) \
1490 (g_dataset_id_get_data ((l), g_quark_try_string ((k))))
1491 #define g_dataset_set_data_full(l, k, d, f) \
1492 g_dataset_id_set_data_full ((l), g_quark_from_string ((k)), (d), (f))
1493 #define g_dataset_set_destroy(l, k, f) \
1494 g_dataset_id_set_destroy ((l), g_quark_try_string ((k)), (f))
1495 #define g_dataset_set_data(l, k, d) \
1496 g_dataset_set_data_full ((l), (k), (d), NULL)
1497 #define g_dataset_remove_data(l, k) \
1498 g_dataset_id_set_data ((l), g_quark_try_string ((k)), NULL)
1501 /* GScanner: Flexible lexical scanner for general purpose.
1504 /* Character sets */
1505 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1506 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1507 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1508 "\307\310\311\312\313\314\315\316\317\320"\
1509 "\321\322\323\324\325\326"\
1510 "\330\331\332\333\334\335\336"
1511 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1512 "\347\350\351\352\353\354\355\356\357\360"\
1513 "\361\362\363\364\365\366"\
1514 "\370\371\372\373\374\375\376\377"
1521 G_ERR_UNEXP_EOF_IN_STRING,
1522 G_ERR_UNEXP_EOF_IN_COMMENT,
1523 G_ERR_NON_DIGIT_IN_CONST,
1526 G_ERR_FLOAT_MALFORMED
1534 G_TOKEN_LEFT_PAREN = '(',
1535 G_TOKEN_RIGHT_PAREN = ')',
1536 G_TOKEN_LEFT_CURLY = '{',
1537 G_TOKEN_RIGHT_CURLY = '}',
1538 G_TOKEN_LEFT_BRACE = '[',
1539 G_TOKEN_RIGHT_BRACE = ']',
1540 G_TOKEN_EQUAL_SIGN = '=',
1541 G_TOKEN_COMMA = ',',
1557 G_TOKEN_IDENTIFIER_NULL,
1559 G_TOKEN_COMMENT_SINGLE,
1560 G_TOKEN_COMMENT_MULTI,
1567 gchar *v_identifier;
1579 struct _GScannerConfig
1583 gchar *cset_skip_characters; /* default: " \t\n" */
1584 gchar *cset_identifier_first;
1585 gchar *cset_identifier_nth;
1586 gchar *cpair_comment_single; /* default: "#\n" */
1588 /* Should symbol lookup work case sensitive?
1590 guint case_sensitive : 1;
1592 /* Boolean values to be adjusted "on the fly"
1593 * to configure scanning behaviour.
1595 guint skip_comment_multi : 1; /* C like comment */
1596 guint skip_comment_single : 1; /* single line comment */
1597 guint scan_comment_multi : 1; /* scan multi line comments? */
1598 guint scan_identifier : 1;
1599 guint scan_identifier_1char : 1;
1600 guint scan_identifier_NULL : 1;
1601 guint scan_symbols : 1;
1602 guint scan_binary : 1;
1603 guint scan_octal : 1;
1604 guint scan_float : 1;
1605 guint scan_hex : 1; /* `0x0ff0' */
1606 guint scan_hex_dollar : 1; /* `$0ff0' */
1607 guint scan_string_sq : 1; /* string: 'anything' */
1608 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1609 guint numbers_2_int : 1; /* bin, octal, hex => int */
1610 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1611 guint identifier_2_string : 1;
1612 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1613 guint symbol_2_token : 1;
1614 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1621 guint max_parse_errors;
1623 /* g_scanner_error() increments this field */
1626 /* name of input stream, featured by the default message handler */
1627 const gchar *input_name;
1629 /* data pointer for derived structures */
1630 gpointer derived_data;
1632 /* link into the scanner configuration */
1633 GScannerConfig *config;
1635 /* fields filled in after g_scanner_get_next_token() */
1641 /* fields filled in after g_scanner_peek_next_token() */
1642 GTokenType next_token;
1645 guint next_position;
1647 /* to be considered private */
1648 GHashTable *symbol_table;
1655 /* handler function for _warn and _error */
1656 GScannerMsgFunc msg_handler;
1659 GScanner* g_scanner_new (GScannerConfig *config_templ);
1660 void g_scanner_destroy (GScanner *scanner);
1661 void g_scanner_input_file (GScanner *scanner,
1663 void g_scanner_input_text (GScanner *scanner,
1666 GTokenType g_scanner_get_next_token (GScanner *scanner);
1667 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1668 GTokenType g_scanner_cur_token (GScanner *scanner);
1669 GValue g_scanner_cur_value (GScanner *scanner);
1670 guint g_scanner_cur_line (GScanner *scanner);
1671 guint g_scanner_cur_position (GScanner *scanner);
1672 gboolean g_scanner_eof (GScanner *scanner);
1673 guint g_scanner_set_scope (GScanner *scanner,
1675 void g_scanner_scope_add_symbol (GScanner *scanner,
1677 const gchar *symbol,
1679 void g_scanner_scope_remove_symbol (GScanner *scanner,
1681 const gchar *symbol);
1682 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1684 const gchar *symbol);
1685 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1688 gpointer func_data);
1689 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1690 const gchar *symbol);
1691 void g_scanner_freeze_symbol_table (GScanner *scanner);
1692 void g_scanner_thaw_symbol_table (GScanner *scanner);
1693 void g_scanner_unexp_token (GScanner *scanner,
1694 GTokenType expected_token,
1695 const gchar *identifier_spec,
1696 const gchar *symbol_spec,
1697 const gchar *symbol_name,
1698 const gchar *message,
1700 void g_scanner_error (GScanner *scanner,
1701 const gchar *format,
1702 ...) G_GNUC_PRINTF (2,3);
1703 void g_scanner_warn (GScanner *scanner,
1704 const gchar *format,
1705 ...) G_GNUC_PRINTF (2,3);
1706 gint g_scanner_stat_mode (const gchar *filename);
1707 /* keep downward source compatibility */
1708 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1709 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1711 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1712 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1714 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1715 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1724 GCompletionFunc func;
1730 GCompletion* g_completion_new (GCompletionFunc func);
1731 void g_completion_add_items (GCompletion* cmp,
1733 void g_completion_remove_items (GCompletion* cmp,
1735 void g_completion_clear_items (GCompletion* cmp);
1736 GList* g_completion_complete (GCompletion* cmp,
1738 gchar** new_prefix);
1739 void g_completion_free (GCompletion* cmp);
1742 /* GRelation: Indexed Relations. Imagine a really simple table in a
1743 * database. Relations are not ordered. This data type is meant for
1744 * maintaining a N-way mapping.
1746 * g_relation_new() creates a relation with FIELDS fields
1748 * g_relation_destroy() frees all resources
1749 * g_tuples_destroy() frees the result of g_relation_select()
1751 * g_relation_index() indexes relation FIELD with the provided
1752 * equality and hash functions. this must be done before any
1753 * calls to insert are made.
1755 * g_relation_insert() inserts a new tuple. you are expected to
1756 * provide the right number of fields.
1758 * g_relation_delete() deletes all relations with KEY in FIELD
1759 * g_relation_select() returns ...
1760 * g_relation_count() counts ...
1763 GRelation* g_relation_new (gint fields);
1764 void g_relation_destroy (GRelation *relation);
1765 void g_relation_index (GRelation *relation,
1767 GHashFunc hash_func,
1768 GCompareFunc key_compare_func);
1769 void g_relation_insert (GRelation *relation,
1771 gint g_relation_delete (GRelation *relation,
1774 GTuples* g_relation_select (GRelation *relation,
1777 gint g_relation_count (GRelation *relation,
1780 gboolean g_relation_exists (GRelation *relation,
1782 void g_relation_print (GRelation *relation);
1784 void g_tuples_destroy (GTuples *tuples);
1785 gpointer g_tuples_index (GTuples *tuples,
1793 /* This function returns prime numbers spaced by approximately 1.5-2.0
1794 * and is for use in resizing data structures which prefer
1795 * prime-valued sizes. The closest spaced prime function returns the
1796 * next largest prime, or the highest it knows about which is about
1800 guint g_spaced_primes_closest (guint num);
1804 extern const guint glib_major_version;
1805 extern const guint glib_minor_version;
1806 extern const guint glib_micro_version;
1810 #endif /* __cplusplus */
1813 #endif /* __G_LIB_H__ */