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 */
88 /* the #pragma } statment is used to fix up emacs' c-mode which gets
89 * confused by extern "C" {. the ansi standard says that compilers
90 * have to ignore #pragma directives that they don't know about,
91 * so we should be save in using this.
96 #endif /* __cplusplus */
99 /* Provide definitions for some commonly used macros.
100 * Some of them are only provided if they haven't already
101 * been defined. It is assumed that if they are already
102 * defined then the current definition is correct.
105 #define NULL ((void*) 0)
113 #define TRUE (!FALSE)
117 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
120 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
123 #define ABS(a) (((a) < 0) ? -(a) : (a))
126 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
129 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
130 * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
132 #if !defined (G_VA_COPY)
133 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
134 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
135 # elif defined (G_VA_COPY_AS_ARRAY)
136 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
137 # else /* va_list is a pointer */
138 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
139 # endif /* va_list is a pointer */
140 #endif /* !G_VA_COPY */
143 /* Provide simple enum value macro wrappers that ease automated
144 * enum value stringification code. [abandoned]
146 #if !defined (G_CODE_GENERATION)
147 #define G_ENUM( EnumerationName ) EnumerationName
148 #define G_FLAGS( EnumerationName ) EnumerationName
149 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
150 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
151 #else /* G_CODE_GENERATION */
152 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
153 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
154 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
155 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
156 #endif /* G_CODE_GENERATION */
159 /* inlining hassle. for compilers that don't allow the `inline' keyword,
160 * mostly because of strict ANSI C compliance or dumbness, we try to fall
161 * back to either `__inline__' or `__inline'.
162 * we define G_CAN_INLINE, if the compiler seems to be actually
163 * *capable* to do function inlining, in which case inline function bodys
164 * do make sense. we also define G_INLINE_FUNC to properly export the
165 * function prototypes if no inlinig can be performed.
166 * we special case most of the stuff, so inline functions can have a normal
167 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
169 #ifndef G_INLINE_FUNC
170 # define G_CAN_INLINE 1
173 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
175 # define inline __inline__
177 #else /* !G_HAVE_INLINE */
179 # if defined (G_HAVE___INLINE__)
180 # define inline __inline__
181 # else /* !inline && !__inline__ */
182 # if defined (G_HAVE___INLINE)
183 # define inline __inline
184 # else /* !inline && !__inline__ && !__inline */
185 # define inline /* don't inline, then */
186 # ifndef G_INLINE_FUNC
192 #ifndef G_INLINE_FUNC
195 # define G_INLINE_FUNC extern inline
198 # define G_INLINE_FUNC extern
200 # else /* !__GNUC__ */
202 # define G_INLINE_FUNC static inline
204 # define G_INLINE_FUNC extern
206 # endif /* !__GNUC__ */
207 #endif /* !G_INLINE_FUNC */
210 /* Provide simple macro statement wrappers (adapted from Perl):
211 * G_STMT_START { statements; } G_STMT_END;
212 * can be used as a single statement, as in
213 * if (x) G_STMT_START { ... } G_STMT_END; else ...
215 * For gcc we will wrap the statements within `({' and `})' braces.
216 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
217 * and otherwise within `do' and `while (0)'.
219 #if !(defined (G_STMT_START) && defined (G_STMT_END))
220 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
221 # define G_STMT_START (void)(
222 # define G_STMT_END )
224 # if (defined (sun) || defined (__sun__))
225 # define G_STMT_START if (1)
226 # define G_STMT_END else (void)0
228 # define G_STMT_START do
229 # define G_STMT_END while (0)
235 /* Provide macros to feature the GCC function attribute.
237 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
238 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
239 __attribute__((format (printf, format_idx, arg_idx)))
240 #define G_GNUC_SCANF( format_idx, arg_idx ) \
241 __attribute__((format (scanf, format_idx, arg_idx)))
242 #define G_GNUC_FORMAT( arg_idx ) \
243 __attribute__((format_arg (arg_idx)))
244 #define G_GNUC_NORETURN \
245 __attribute__((noreturn))
246 #define G_GNUC_CONST \
247 __attribute__((const))
248 #else /* !__GNUC__ */
249 #define G_GNUC_PRINTF( format_idx, arg_idx )
250 #define G_GNUC_SCANF( format_idx, arg_idx )
251 #define G_GNUC_FORMAT( arg_idx )
252 #define G_GNUC_NORETURN
254 #endif /* !__GNUC__ */
257 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
258 * macros, so we can refer to them as strings unconditionally.
261 #define G_GNUC_FUNCTION (__FUNCTION__)
262 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
263 #else /* !__GNUC__ */
264 #define G_GNUC_FUNCTION ("")
265 #define G_GNUC_PRETTY_FUNCTION ("")
266 #endif /* !__GNUC__ */
269 /* we try to provide a usefull equivalent for ATEXIT if it is
270 * not defined, but use is actually abandoned. people should
271 * use g_atexit() instead.
272 * keep this in sync with gutils.c.
276 # ifdef NeXT /* @#%@! NeXTStep */
277 # define ATEXIT(proc) (!atexit (proc))
279 # define ATEXIT(proc) (atexit (proc))
281 # elif defined (HAVE_ON_EXIT)
282 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
284 # error Could not determine proper atexit() implementation
287 # define G_NATIVE_ATEXIT
290 /* Hacker macro to place breakpoints for x86 machines.
291 * Actual use is strongly deprecated of course ;)
293 #if defined (__i386__) && defined (__GNUC__)
294 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
295 #else /* !__i386__ */
296 #define G_BREAKPOINT()
297 #endif /* __i386__ */
300 /* Provide macros for easily allocating memory. The macros
301 * will cast the allocated memory to the specified type
302 * in order to avoid compiler warnings. (Makes the code neater).
307 #define g_new(type, count) (ALLOC (type, count))
308 #define g_new0(type, count) (CALLOC (type, count))
310 #else /* __DMALLOC_H__ */
312 #define g_new(type, count) \
313 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
314 #define g_new0(type, count) \
315 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
316 #endif /* __DMALLOC_H__ */
318 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
319 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
321 sizeof (type) * (pre_alloc), \
324 #define g_chunk_new(type, chunk) ( \
325 (type *) g_mem_chunk_alloc (chunk) \
327 #define g_chunk_new0(type, chunk) ( \
328 (type *) g_mem_chunk_alloc0 (chunk) \
330 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
331 g_mem_chunk_free ((mem_chunk), (mem)); \
335 #define g_string(x) #x
338 /* Provide macros for error handling. The "assert" macros will
339 * exit on failure. The "return" macros will exit the current
340 * function. Two different definitions are given for the macros
341 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
342 * __PRETTY_FUNCTION__ capability.
345 #ifdef G_DISABLE_ASSERT
347 #define g_assert(expr)
348 #define g_assert_not_reached()
350 #else /* !G_DISABLE_ASSERT */
354 #define g_assert(expr) G_STMT_START{ \
356 g_log (G_LOG_DOMAIN, \
358 "file %s: line %d (%s): assertion failed: (%s)", \
361 __PRETTY_FUNCTION__, \
364 #define g_assert_not_reached() G_STMT_START{ \
365 g_log (G_LOG_DOMAIN, \
367 "file %s: line %d (%s): should not be reached", \
370 __PRETTY_FUNCTION__); }G_STMT_END
372 #else /* !__GNUC__ */
374 #define g_assert(expr) G_STMT_START{ \
376 g_log (G_LOG_DOMAIN, \
378 "file %s: line %d: assertion failed: (%s)", \
383 #define g_assert_not_reached() G_STMT_START{ \
384 g_log (G_LOG_DOMAIN, \
386 "file %s: line %d: should not be reached", \
388 __LINE__); }G_STMT_END
390 #endif /* __GNUC__ */
392 #endif /* !G_DISABLE_ASSERT */
395 #ifdef G_DISABLE_CHECKS
397 #define g_return_if_fail(expr)
398 #define g_return_val_if_fail(expr,val)
400 #else /* !G_DISABLE_CHECKS */
404 #define g_return_if_fail(expr) G_STMT_START{ \
407 g_log (G_LOG_DOMAIN, \
408 G_LOG_LEVEL_CRITICAL, \
409 "file %s: line %d (%s): assertion `%s' failed.", \
412 __PRETTY_FUNCTION__, \
417 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
420 g_log (G_LOG_DOMAIN, \
421 G_LOG_LEVEL_CRITICAL, \
422 "file %s: line %d (%s): assertion `%s' failed.", \
425 __PRETTY_FUNCTION__, \
430 #else /* !__GNUC__ */
432 #define g_return_if_fail(expr) G_STMT_START{ \
435 g_log (G_LOG_DOMAIN, \
436 G_LOG_LEVEL_CRITICAL, \
437 "file %s: line %d: assertion `%s' failed.", \
444 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
447 g_log (G_LOG_DOMAIN, \
448 G_LOG_LEVEL_CRITICAL, \
449 "file %s: line %d: assertion `%s' failed.", \
456 #endif /* !__GNUC__ */
458 #endif /* !G_DISABLE_CHECKS */
461 /* Provide type definitions for commonly used types.
462 * These are useful because a "gint8" can be adjusted
463 * to be 1 byte (8 bits) on all platforms. Similarly and
464 * more importantly, "gint32" can be adjusted to be
465 * 4 bytes (32 bits) on all platforms.
469 typedef short gshort;
472 typedef gint gboolean;
474 typedef unsigned char guchar;
475 typedef unsigned short gushort;
476 typedef unsigned long gulong;
477 typedef unsigned int guint;
479 typedef float gfloat;
480 typedef double gdouble;
482 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
483 * Since gldouble isn't used anywhere, just disable it for now */
486 #ifdef HAVE_LONG_DOUBLE
487 typedef long double gldouble;
488 #else /* HAVE_LONG_DOUBLE */
489 typedef double gldouble;
490 #endif /* HAVE_LONG_DOUBLE */
493 typedef void* gpointer;
494 typedef const void *gconstpointer;
496 #if (SIZEOF_CHAR == 1)
497 typedef signed char gint8;
498 typedef unsigned char guint8;
499 #endif /* SIZEOF_CHAR */
501 #if (SIZEOF_SHORT == 2)
502 typedef signed short gint16;
503 typedef unsigned short guint16;
504 #endif /* SIZEOF_SHORT */
506 #if (SIZEOF_INT == 4)
507 typedef signed int gint32;
508 typedef unsigned int guint32;
509 #elif (SIZEOF_LONG == 4)
510 typedef signed long gint32;
511 typedef unsigned long guint32;
512 #endif /* SIZEOF_INT */
514 #if (SIZEOF_LONG == 8)
515 #define HAVE_GINT64 1
516 typedef signed long gint64;
517 typedef unsigned long guint64;
518 #elif (SIZEOF_LONG_LONG == 8)
519 #define HAVE_GINT64 1
520 typedef signed long long gint64;
521 typedef unsigned long long guint64;
528 /* Define macros for storing integers inside pointers
530 #if (SIZEOF_INT == SIZEOF_VOID_P)
532 #define GPOINTER_TO_INT(p) ((gint)(p))
533 #define GPOINTER_TO_UINT(p) ((guint)(p))
535 #define GINT_TO_POINTER(i) ((gpointer)(i))
536 #define GUINT_TO_POINTER(u) ((gpointer)(u))
538 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
540 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
541 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
543 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
544 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
547 #error SIZEOF_VOID_P unknown - This should never happen
550 typedef gint32 gssize;
551 typedef guint32 gsize;
552 typedef guint32 GQuark;
553 typedef gint32 GTime;
558 extern const guint glib_major_version;
559 extern const guint glib_minor_version;
560 extern const guint glib_micro_version;
561 extern const guint glib_interface_age;
562 extern const guint glib_binary_age;
565 /* Forward declarations of glib types.
568 typedef struct _GArray GArray;
569 typedef struct _GByteArray GByteArray;
570 typedef struct _GCache GCache;
571 typedef struct _GCompletion GCompletion;
572 typedef struct _GData GData;
573 typedef struct _GDebugKey GDebugKey;
574 typedef struct _GHashTable GHashTable;
575 typedef struct _GList GList;
576 typedef struct _GListAllocator GListAllocator;
577 typedef struct _GMemChunk GMemChunk;
578 typedef struct _GNode GNode;
579 typedef struct _GPtrArray GPtrArray;
580 typedef struct _GRelation GRelation;
581 typedef struct _GScanner GScanner;
582 typedef struct _GScannerConfig GScannerConfig;
583 typedef struct _GSList GSList;
584 typedef struct _GString GString;
585 typedef struct _GStringChunk GStringChunk;
586 typedef struct _GTimer GTimer;
587 typedef struct _GTree GTree;
588 typedef struct _GTuples GTuples;
589 typedef union _GTokenValue GTokenValue;
594 G_TRAVERSE_LEAFS = 1 << 0,
595 G_TRAVERSE_NON_LEAFS = 1 << 1,
596 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
597 G_TRAVERSE_MASK = 0x03
608 /* Log level shift offset for user defined
609 * log levels (0-7 are used by GLib).
611 #define G_LOG_LEVEL_USER_SHIFT (8)
613 /* Glib log levels and flags.
618 G_LOG_FLAG_RECURSION = 1 << 0,
619 G_LOG_FLAG_FATAL = 1 << 1,
621 /* GLib log levels */
622 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
623 G_LOG_LEVEL_CRITICAL = 1 << 3,
624 G_LOG_LEVEL_WARNING = 1 << 4,
625 G_LOG_LEVEL_MESSAGE = 1 << 5,
626 G_LOG_LEVEL_INFO = 1 << 6,
627 G_LOG_LEVEL_DEBUG = 1 << 7,
629 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
632 /* GLib log levels that are considered fatal by default */
633 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
636 typedef gpointer (*GCacheNewFunc) (gpointer key);
637 typedef gpointer (*GCacheDupFunc) (gpointer value);
638 typedef void (*GCacheDestroyFunc) (gpointer value);
639 typedef gint (*GCompareFunc) (gconstpointer a,
641 typedef gchar* (*GCompletionFunc) (gpointer);
642 typedef void (*GDestroyNotify) (gpointer data);
643 typedef void (*GDataForeachFunc) (GQuark key_id,
646 typedef void (*GFunc) (gpointer data,
648 typedef guint (*GHashFunc) (gconstpointer key);
649 typedef void (*GHFunc) (gpointer key,
652 typedef gboolean (*GHRFunc) (gpointer key,
655 typedef void (*GLogFunc) (const gchar *log_domain,
656 GLogLevelFlags log_level,
657 const gchar *message,
659 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
661 typedef void (*GNodeForeachFunc) (GNode *node,
663 typedef gint (*GSearchFunc) (gpointer key,
665 typedef void (*GScannerMsgFunc) (GScanner *scanner,
668 typedef gint (*GTraverseFunc) (gpointer key,
671 typedef void (*GVoidFunc) (void);
722 struct _GCache { gint dummy; };
723 struct _GTree { gint dummy; };
724 struct _GTimer { gint dummy; };
725 struct _GMemChunk { gint dummy; };
726 struct _GListAllocator { gint dummy; };
727 struct _GStringChunk { gint dummy; };
730 /* Doubly linked lists
732 GList* g_list_alloc (void);
733 void g_list_free (GList *list);
734 void g_list_free_1 (GList *list);
735 GList* g_list_append (GList *list,
737 GList* g_list_prepend (GList *list,
739 GList* g_list_insert (GList *list,
742 GList* g_list_insert_sorted (GList *list,
745 GList* g_list_concat (GList *list1,
747 GList* g_list_remove (GList *list,
749 GList* g_list_remove_link (GList *list,
751 GList* g_list_reverse (GList *list);
752 GList* g_list_nth (GList *list,
754 GList* g_list_find (GList *list,
756 GList* g_list_find_custom (GList *list,
759 gint g_list_position (GList *list,
761 gint g_list_index (GList *list,
763 GList* g_list_last (GList *list);
764 GList* g_list_first (GList *list);
765 guint g_list_length (GList *list);
766 void g_list_foreach (GList *list,
769 gpointer g_list_nth_data (GList *list,
771 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
772 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
775 /* Singly linked lists
777 GSList* g_slist_alloc (void);
778 void g_slist_free (GSList *list);
779 void g_slist_free_1 (GSList *list);
780 GSList* g_slist_append (GSList *list,
782 GSList* g_slist_prepend (GSList *list,
784 GSList* g_slist_insert (GSList *list,
787 GSList* g_slist_insert_sorted (GSList *list,
790 GSList* g_slist_concat (GSList *list1,
792 GSList* g_slist_remove (GSList *list,
794 GSList* g_slist_remove_link (GSList *list,
796 GSList* g_slist_reverse (GSList *list);
797 GSList* g_slist_nth (GSList *list,
799 GSList* g_slist_find (GSList *list,
801 GSList* g_slist_find_custom (GSList *list,
804 gint g_slist_position (GSList *list,
806 gint g_slist_index (GSList *list,
808 GSList* g_slist_last (GSList *list);
809 guint g_slist_length (GSList *list);
810 void g_slist_foreach (GSList *list,
813 gpointer g_slist_nth_data (GSList *list,
815 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
820 GListAllocator* g_list_allocator_new (void);
821 void g_list_allocator_free (GListAllocator* allocator);
822 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
823 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
828 GHashTable* g_hash_table_new (GHashFunc hash_func,
829 GCompareFunc key_compare_func);
830 void g_hash_table_destroy (GHashTable *hash_table);
831 void g_hash_table_insert (GHashTable *hash_table,
834 void g_hash_table_remove (GHashTable *hash_table,
836 gpointer g_hash_table_lookup (GHashTable *hash_table,
838 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
839 gconstpointer lookup_key,
842 void g_hash_table_freeze (GHashTable *hash_table);
843 void g_hash_table_thaw (GHashTable *hash_table);
844 void g_hash_table_foreach (GHashTable *hash_table,
847 gint g_hash_table_foreach_remove (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);
1198 gpointer g_memdup (gconstpointer mem,
1201 /* calculate a string size, guarranteed to fit format + args.
1203 guint g_printf_string_upper_bound (const gchar* format,
1207 /* Retrive static string info
1209 gchar* g_get_user_name (void);
1210 gchar* g_get_real_name (void);
1211 gchar* g_get_home_dir (void);
1212 gchar* g_get_tmp_dir (void);
1213 gchar* g_get_prgname (void);
1214 void g_set_prgname (const gchar *prgname);
1217 /* Miscellaneous utility functions
1219 guint g_parse_debug_string (const gchar *string,
1222 gint g_snprintf (gchar *string,
1224 gchar const *format,
1225 ...) G_GNUC_PRINTF (3, 4);
1226 gint g_vsnprintf (gchar *string,
1228 gchar const *format,
1230 gchar* g_basename (const gchar *file_name);
1232 /* strings are newly allocated with g_malloc() */
1233 gchar* g_dirname (const gchar *file_name);
1234 gchar* g_get_current_dir (void);
1236 /* We make the assumption that if memmove isn't available, then
1237 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1238 * necessarily handle overlapping copies).
1239 * Either way, g_memmove() will not return a value.
1242 #define g_memmove(dest, src, size) G_STMT_START { \
1243 memmove ((dest), (src), (size)); \
1246 #define g_memmove(dest, src, size) G_STMT_START { \
1247 bcopy ((src), (dest), (size)); \
1251 /* we use a GLib function as a replacement for ATEXIT, so
1252 * the programmer is not required to check the return value
1253 * (if there is any in the implementation) and doesn't encounter
1254 * missing include files.
1256 void g_atexit (GVoidFunc func);
1261 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1265 g_bit_nth_lsf (guint32 mask,
1271 if (mask & (1 << (guint) nth_bit))
1274 while (nth_bit < 32);
1277 #endif /* G_CAN_INLINE */
1279 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1283 g_bit_nth_msf (guint32 mask,
1291 if (mask & (1 << (guint) nth_bit))
1294 while (nth_bit > 0);
1297 #endif /* G_CAN_INLINE */
1299 G_INLINE_FUNC guint g_bit_storage (guint number);
1302 g_bit_storage (guint number)
1304 register guint n_bits = 0;
1314 #endif /* G_CAN_INLINE */
1319 GStringChunk* g_string_chunk_new (gint size);
1320 void g_string_chunk_free (GStringChunk *chunk);
1321 gchar* g_string_chunk_insert (GStringChunk *chunk,
1322 const gchar *string);
1323 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1324 const gchar *string);
1329 GString* g_string_new (const gchar *init);
1330 GString* g_string_sized_new (guint dfl_size);
1331 void g_string_free (GString *string,
1333 GString* g_string_assign (GString *lval,
1335 GString* g_string_truncate (GString *string,
1337 GString* g_string_append (GString *string,
1339 GString* g_string_append_c (GString *string,
1341 GString* g_string_prepend (GString *string,
1343 GString* g_string_prepend_c (GString *string,
1345 GString* g_string_insert (GString *string,
1348 GString* g_string_insert_c (GString *string,
1351 GString* g_string_erase (GString *string,
1354 GString* g_string_down (GString *string);
1355 GString* g_string_up (GString *string);
1356 void g_string_sprintf (GString *string,
1357 const gchar *format,
1358 ...) G_GNUC_PRINTF (2, 3);
1359 void g_string_sprintfa (GString *string,
1360 const gchar *format,
1361 ...) G_GNUC_PRINTF (2, 3);
1367 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1368 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1369 #define g_array_index(a,t,i) (((t*)a->data)[i])
1371 GArray* g_array_new (gboolean zero_terminated,
1373 guint element_size);
1374 void g_array_free (GArray *array,
1375 gboolean free_segment);
1376 GArray* g_array_append_vals (GArray *array,
1379 GArray* g_array_prepend_vals (GArray *array,
1382 GArray* g_array_set_size (GArray *array,
1385 /* Resizable pointer array. This interface is much less complicated
1386 * than the above. Add appends appends a pointer. Remove fills any
1387 * cleared spot and shortens the array.
1389 #define g_ptr_array_index(array,index) (array->pdata)[index]
1390 GPtrArray* g_ptr_array_new (void);
1391 void g_ptr_array_free (GPtrArray *array,
1393 void g_ptr_array_set_size (GPtrArray *array,
1395 gpointer g_ptr_array_remove_index (GPtrArray *array,
1397 gboolean g_ptr_array_remove (GPtrArray *array,
1399 void g_ptr_array_add (GPtrArray *array,
1402 /* Byte arrays, an array of guint8. Implemented as a GArray,
1406 GByteArray* g_byte_array_new (void);
1407 void g_byte_array_free (GByteArray *array,
1408 gboolean free_segment);
1409 GByteArray* g_byte_array_append (GByteArray *array,
1412 GByteArray* g_byte_array_prepend (GByteArray *array,
1415 GByteArray* g_byte_array_set_size (GByteArray *array,
1421 gint g_str_equal (gconstpointer v,
1423 guint g_str_hash (gconstpointer v);
1425 gint g_int_equal (gconstpointer v,
1427 guint g_int_hash (gconstpointer v);
1429 /* This "hash" function will just return the key's adress as an
1430 * unsigned integer. Useful for hashing on plain adresses or
1431 * simple integer values.
1433 guint g_direct_hash (gconstpointer v);
1434 gint g_direct_equal (gconstpointer v,
1438 /* Quarks (string<->id association)
1440 GQuark g_quark_try_string (const gchar *string);
1441 GQuark g_quark_from_static_string (const gchar *string);
1442 GQuark g_quark_from_string (const gchar *string);
1443 gchar* g_quark_to_string (GQuark quark);
1448 void g_datalist_init (GData **datalist);
1449 void g_datalist_clear (GData **datalist);
1450 gpointer g_datalist_id_get_data (GData **datalist,
1452 void g_datalist_id_set_data_full (GData **datalist,
1455 GDestroyNotify destroy_func);
1456 void g_datalist_id_set_destroy (GData **datalist,
1458 GDestroyNotify destroy_func);
1459 void g_datalist_foreach (GData **datalist,
1460 GDataForeachFunc func,
1461 gpointer user_data);
1462 #define g_datalist_id_set_data(dl, q, d) \
1463 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1464 #define g_datalist_id_remove_data(dl, q) \
1465 g_datalist_id_set_data ((dl), (q), NULL)
1466 #define g_datalist_get_data(dl, k) \
1467 (g_datalist_id_get_data ((dl), g_quark_try_string ((k))))
1468 #define g_datalist_set_data_full(dl, k, d, f) \
1469 g_datalist_id_set_data_full ((dl), g_quark_from_string ((k)), (d), (f))
1470 #define g_datalist_set_destroy(dl, k, f) \
1471 g_datalist_id_set_destroy ((dl), g_quark_try_string ((k)), (f))
1472 #define g_datalist_set_data(dl, k, d) \
1473 g_datalist_set_data_full ((dl), (k), (d), NULL)
1474 #define g_datalist_remove_data(dl, k) \
1475 g_datalist_id_set_data ((dl), g_quark_try_string ((k)), NULL)
1478 /* Location Associated Keyed Data
1480 void g_dataset_destroy (gconstpointer dataset_location);
1481 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1483 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1486 GDestroyNotify destroy_func);
1487 void g_dataset_id_set_destroy (gconstpointer dataset_location,
1489 GDestroyNotify destroy_func);
1490 void g_dataset_foreach (gconstpointer dataset_location,
1491 GDataForeachFunc func,
1492 gpointer user_data);
1493 #define g_dataset_id_set_data(l, k, d) \
1494 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1495 #define g_dataset_id_remove_data(l, k) \
1496 g_dataset_id_set_data ((l), (k), NULL)
1497 #define g_dataset_get_data(l, k) \
1498 (g_dataset_id_get_data ((l), g_quark_try_string ((k))))
1499 #define g_dataset_set_data_full(l, k, d, f) \
1500 g_dataset_id_set_data_full ((l), g_quark_from_string ((k)), (d), (f))
1501 #define g_dataset_set_destroy(l, k, f) \
1502 g_dataset_id_set_destroy ((l), g_quark_try_string ((k)), (f))
1503 #define g_dataset_set_data(l, k, d) \
1504 g_dataset_set_data_full ((l), (k), (d), NULL)
1505 #define g_dataset_remove_data(l, k) \
1506 g_dataset_id_set_data ((l), g_quark_try_string ((k)), NULL)
1509 /* GScanner: Flexible lexical scanner for general purpose.
1512 /* Character sets */
1513 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1514 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1515 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1516 "\307\310\311\312\313\314\315\316\317\320"\
1517 "\321\322\323\324\325\326"\
1518 "\330\331\332\333\334\335\336"
1519 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1520 "\347\350\351\352\353\354\355\356\357\360"\
1521 "\361\362\363\364\365\366"\
1522 "\370\371\372\373\374\375\376\377"
1529 G_ERR_UNEXP_EOF_IN_STRING,
1530 G_ERR_UNEXP_EOF_IN_COMMENT,
1531 G_ERR_NON_DIGIT_IN_CONST,
1534 G_ERR_FLOAT_MALFORMED
1542 G_TOKEN_LEFT_PAREN = '(',
1543 G_TOKEN_RIGHT_PAREN = ')',
1544 G_TOKEN_LEFT_CURLY = '{',
1545 G_TOKEN_RIGHT_CURLY = '}',
1546 G_TOKEN_LEFT_BRACE = '[',
1547 G_TOKEN_RIGHT_BRACE = ']',
1548 G_TOKEN_EQUAL_SIGN = '=',
1549 G_TOKEN_COMMA = ',',
1565 G_TOKEN_IDENTIFIER_NULL,
1567 G_TOKEN_COMMENT_SINGLE,
1568 G_TOKEN_COMMENT_MULTI,
1575 gchar *v_identifier;
1587 struct _GScannerConfig
1591 gchar *cset_skip_characters; /* default: " \t\n" */
1592 gchar *cset_identifier_first;
1593 gchar *cset_identifier_nth;
1594 gchar *cpair_comment_single; /* default: "#\n" */
1596 /* Should symbol lookup work case sensitive?
1598 guint case_sensitive : 1;
1600 /* Boolean values to be adjusted "on the fly"
1601 * to configure scanning behaviour.
1603 guint skip_comment_multi : 1; /* C like comment */
1604 guint skip_comment_single : 1; /* single line comment */
1605 guint scan_comment_multi : 1; /* scan multi line comments? */
1606 guint scan_identifier : 1;
1607 guint scan_identifier_1char : 1;
1608 guint scan_identifier_NULL : 1;
1609 guint scan_symbols : 1;
1610 guint scan_binary : 1;
1611 guint scan_octal : 1;
1612 guint scan_float : 1;
1613 guint scan_hex : 1; /* `0x0ff0' */
1614 guint scan_hex_dollar : 1; /* `$0ff0' */
1615 guint scan_string_sq : 1; /* string: 'anything' */
1616 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1617 guint numbers_2_int : 1; /* bin, octal, hex => int */
1618 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1619 guint identifier_2_string : 1;
1620 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1621 guint symbol_2_token : 1;
1622 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1629 guint max_parse_errors;
1631 /* g_scanner_error() increments this field */
1634 /* name of input stream, featured by the default message handler */
1635 const gchar *input_name;
1637 /* data pointer for derived structures */
1638 gpointer derived_data;
1640 /* link into the scanner configuration */
1641 GScannerConfig *config;
1643 /* fields filled in after g_scanner_get_next_token() */
1649 /* fields filled in after g_scanner_peek_next_token() */
1650 GTokenType next_token;
1651 GTokenValue next_value;
1653 guint next_position;
1655 /* to be considered private */
1656 GHashTable *symbol_table;
1663 /* handler function for _warn and _error */
1664 GScannerMsgFunc msg_handler;
1667 GScanner* g_scanner_new (GScannerConfig *config_templ);
1668 void g_scanner_destroy (GScanner *scanner);
1669 void g_scanner_input_file (GScanner *scanner,
1671 void g_scanner_input_text (GScanner *scanner,
1674 GTokenType g_scanner_get_next_token (GScanner *scanner);
1675 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1676 GTokenType g_scanner_cur_token (GScanner *scanner);
1677 GTokenValue g_scanner_cur_value (GScanner *scanner);
1678 guint g_scanner_cur_line (GScanner *scanner);
1679 guint g_scanner_cur_position (GScanner *scanner);
1680 gboolean g_scanner_eof (GScanner *scanner);
1681 guint g_scanner_set_scope (GScanner *scanner,
1683 void g_scanner_scope_add_symbol (GScanner *scanner,
1685 const gchar *symbol,
1687 void g_scanner_scope_remove_symbol (GScanner *scanner,
1689 const gchar *symbol);
1690 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1692 const gchar *symbol);
1693 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1696 gpointer func_data);
1697 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1698 const gchar *symbol);
1699 void g_scanner_freeze_symbol_table (GScanner *scanner);
1700 void g_scanner_thaw_symbol_table (GScanner *scanner);
1701 void g_scanner_unexp_token (GScanner *scanner,
1702 GTokenType expected_token,
1703 const gchar *identifier_spec,
1704 const gchar *symbol_spec,
1705 const gchar *symbol_name,
1706 const gchar *message,
1708 void g_scanner_error (GScanner *scanner,
1709 const gchar *format,
1710 ...) G_GNUC_PRINTF (2,3);
1711 void g_scanner_warn (GScanner *scanner,
1712 const gchar *format,
1713 ...) G_GNUC_PRINTF (2,3);
1714 gint g_scanner_stat_mode (const gchar *filename);
1715 /* keep downward source compatibility */
1716 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1717 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1719 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1720 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1722 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1723 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1732 GCompletionFunc func;
1738 GCompletion* g_completion_new (GCompletionFunc func);
1739 void g_completion_add_items (GCompletion* cmp,
1741 void g_completion_remove_items (GCompletion* cmp,
1743 void g_completion_clear_items (GCompletion* cmp);
1744 GList* g_completion_complete (GCompletion* cmp,
1746 gchar** new_prefix);
1747 void g_completion_free (GCompletion* cmp);
1750 /* GRelation: Indexed Relations. Imagine a really simple table in a
1751 * database. Relations are not ordered. This data type is meant for
1752 * maintaining a N-way mapping.
1754 * g_relation_new() creates a relation with FIELDS fields
1756 * g_relation_destroy() frees all resources
1757 * g_tuples_destroy() frees the result of g_relation_select()
1759 * g_relation_index() indexes relation FIELD with the provided
1760 * equality and hash functions. this must be done before any
1761 * calls to insert are made.
1763 * g_relation_insert() inserts a new tuple. you are expected to
1764 * provide the right number of fields.
1766 * g_relation_delete() deletes all relations with KEY in FIELD
1767 * g_relation_select() returns ...
1768 * g_relation_count() counts ...
1771 GRelation* g_relation_new (gint fields);
1772 void g_relation_destroy (GRelation *relation);
1773 void g_relation_index (GRelation *relation,
1775 GHashFunc hash_func,
1776 GCompareFunc key_compare_func);
1777 void g_relation_insert (GRelation *relation,
1779 gint g_relation_delete (GRelation *relation,
1782 GTuples* g_relation_select (GRelation *relation,
1785 gint g_relation_count (GRelation *relation,
1788 gboolean g_relation_exists (GRelation *relation,
1790 void g_relation_print (GRelation *relation);
1792 void g_tuples_destroy (GTuples *tuples);
1793 gpointer g_tuples_index (GTuples *tuples,
1801 /* This function returns prime numbers spaced by approximately 1.5-2.0
1802 * and is for use in resizing data structures which prefer
1803 * prime-valued sizes. The closest spaced prime function returns the
1804 * next largest prime, or the highest it knows about which is about
1808 guint g_spaced_primes_closest (guint num);
1812 extern const guint glib_major_version;
1813 extern const guint glib_minor_version;
1814 extern const guint glib_micro_version;
1818 #endif /* __cplusplus */
1821 #endif /* __G_LIB_H__ */