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 #define G_GNUC_UNUSED \
249 __attribute__((unused))
250 #else /* !__GNUC__ */
251 #define G_GNUC_PRINTF( format_idx, arg_idx )
252 #define G_GNUC_SCANF( format_idx, arg_idx )
253 #define G_GNUC_FORMAT( arg_idx )
254 #define G_GNUC_NORETURN
256 #define G_GNUC_UNUSED
257 #endif /* !__GNUC__ */
260 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
261 * macros, so we can refer to them as strings unconditionally.
264 #define G_GNUC_FUNCTION (__FUNCTION__)
265 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
266 #else /* !__GNUC__ */
267 #define G_GNUC_FUNCTION ("")
268 #define G_GNUC_PRETTY_FUNCTION ("")
269 #endif /* !__GNUC__ */
272 /* we try to provide a usefull equivalent for ATEXIT if it is
273 * not defined, but use is actually abandoned. people should
274 * use g_atexit() instead.
275 * keep this in sync with gutils.c.
279 # ifdef NeXT /* @#%@! NeXTStep */
280 # define ATEXIT(proc) (!atexit (proc))
282 # define ATEXIT(proc) (atexit (proc))
284 # elif defined (HAVE_ON_EXIT)
285 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
287 # error Could not determine proper atexit() implementation
290 # define G_NATIVE_ATEXIT
293 /* Hacker macro to place breakpoints for x86 machines.
294 * Actual use is strongly deprecated of course ;)
296 #if defined (__i386__) && defined (__GNUC__)
297 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
298 #else /* !__i386__ */
299 #define G_BREAKPOINT()
300 #endif /* __i386__ */
303 /* Provide macros for easily allocating memory. The macros
304 * will cast the allocated memory to the specified type
305 * in order to avoid compiler warnings. (Makes the code neater).
309 # define g_new(type, count) (ALLOC (type, count))
310 # define g_new0(type, count) (CALLOC (type, count))
311 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
312 #else /* __DMALLOC_H__ */
313 # define g_new(type, count) \
314 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
315 # define g_new0(type, count) \
316 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
317 # define g_renew(type, mem, count) \
318 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
319 #endif /* __DMALLOC_H__ */
321 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
322 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
324 sizeof (type) * (pre_alloc), \
327 #define g_chunk_new(type, chunk) ( \
328 (type *) g_mem_chunk_alloc (chunk) \
330 #define g_chunk_new0(type, chunk) ( \
331 (type *) g_mem_chunk_alloc0 (chunk) \
333 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
334 g_mem_chunk_free ((mem_chunk), (mem)); \
338 #define g_string(x) #x
341 /* Provide macros for error handling. The "assert" macros will
342 * exit on failure. The "return" macros will exit the current
343 * function. Two different definitions are given for the macros
344 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
345 * __PRETTY_FUNCTION__ capability.
348 #ifdef G_DISABLE_ASSERT
350 #define g_assert(expr)
351 #define g_assert_not_reached()
353 #else /* !G_DISABLE_ASSERT */
357 #define g_assert(expr) G_STMT_START{ \
359 g_log (G_LOG_DOMAIN, \
361 "file %s: line %d (%s): assertion failed: (%s)", \
364 __PRETTY_FUNCTION__, \
367 #define g_assert_not_reached() G_STMT_START{ \
368 g_log (G_LOG_DOMAIN, \
370 "file %s: line %d (%s): should not be reached", \
373 __PRETTY_FUNCTION__); }G_STMT_END
375 #else /* !__GNUC__ */
377 #define g_assert(expr) G_STMT_START{ \
379 g_log (G_LOG_DOMAIN, \
381 "file %s: line %d: assertion failed: (%s)", \
386 #define g_assert_not_reached() G_STMT_START{ \
387 g_log (G_LOG_DOMAIN, \
389 "file %s: line %d: should not be reached", \
391 __LINE__); }G_STMT_END
393 #endif /* __GNUC__ */
395 #endif /* !G_DISABLE_ASSERT */
398 #ifdef G_DISABLE_CHECKS
400 #define g_return_if_fail(expr)
401 #define g_return_val_if_fail(expr,val)
403 #else /* !G_DISABLE_CHECKS */
407 #define g_return_if_fail(expr) G_STMT_START{ \
410 g_log (G_LOG_DOMAIN, \
411 G_LOG_LEVEL_CRITICAL, \
412 "file %s: line %d (%s): assertion `%s' failed.", \
415 __PRETTY_FUNCTION__, \
420 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
423 g_log (G_LOG_DOMAIN, \
424 G_LOG_LEVEL_CRITICAL, \
425 "file %s: line %d (%s): assertion `%s' failed.", \
428 __PRETTY_FUNCTION__, \
433 #else /* !__GNUC__ */
435 #define g_return_if_fail(expr) G_STMT_START{ \
438 g_log (G_LOG_DOMAIN, \
439 G_LOG_LEVEL_CRITICAL, \
440 "file %s: line %d: assertion `%s' failed.", \
447 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
450 g_log (G_LOG_DOMAIN, \
451 G_LOG_LEVEL_CRITICAL, \
452 "file %s: line %d: assertion `%s' failed.", \
459 #endif /* !__GNUC__ */
461 #endif /* !G_DISABLE_CHECKS */
464 /* Provide type definitions for commonly used types.
465 * These are useful because a "gint8" can be adjusted
466 * to be 1 byte (8 bits) on all platforms. Similarly and
467 * more importantly, "gint32" can be adjusted to be
468 * 4 bytes (32 bits) on all platforms.
472 typedef short gshort;
475 typedef gint gboolean;
477 typedef unsigned char guchar;
478 typedef unsigned short gushort;
479 typedef unsigned long gulong;
480 typedef unsigned int guint;
482 typedef float gfloat;
483 typedef double gdouble;
485 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
486 * Since gldouble isn't used anywhere, just disable it for now */
489 #ifdef HAVE_LONG_DOUBLE
490 typedef long double gldouble;
491 #else /* HAVE_LONG_DOUBLE */
492 typedef double gldouble;
493 #endif /* HAVE_LONG_DOUBLE */
496 typedef void* gpointer;
497 typedef const void *gconstpointer;
499 #if (SIZEOF_CHAR == 1)
500 typedef signed char gint8;
501 typedef unsigned char guint8;
502 #endif /* SIZEOF_CHAR */
504 #if (SIZEOF_SHORT == 2)
505 typedef signed short gint16;
506 typedef unsigned short guint16;
507 #endif /* SIZEOF_SHORT */
509 #if (SIZEOF_INT == 4)
510 typedef signed int gint32;
511 typedef unsigned int guint32;
512 #elif (SIZEOF_LONG == 4)
513 typedef signed long gint32;
514 typedef unsigned long guint32;
515 #endif /* SIZEOF_INT */
517 #if (SIZEOF_LONG == 8)
518 #define HAVE_GINT64 1
519 typedef signed long gint64;
520 typedef unsigned long guint64;
521 #elif (SIZEOF_LONG_LONG == 8)
522 #define HAVE_GINT64 1
523 typedef signed long long gint64;
524 typedef unsigned long long guint64;
531 /* Define macros for storing integers inside pointers
533 #if (SIZEOF_INT == SIZEOF_VOID_P)
535 #define GPOINTER_TO_INT(p) ((gint)(p))
536 #define GPOINTER_TO_UINT(p) ((guint)(p))
538 #define GINT_TO_POINTER(i) ((gpointer)(i))
539 #define GUINT_TO_POINTER(u) ((gpointer)(u))
541 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
543 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
544 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
546 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
547 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
550 #error SIZEOF_VOID_P unknown - This should never happen
553 typedef gint32 gssize;
554 typedef guint32 gsize;
555 typedef guint32 GQuark;
556 typedef gint32 GTime;
561 extern const guint glib_major_version;
562 extern const guint glib_minor_version;
563 extern const guint glib_micro_version;
564 extern const guint glib_interface_age;
565 extern const guint glib_binary_age;
568 /* Forward declarations of glib types.
571 typedef struct _GArray GArray;
572 typedef struct _GByteArray GByteArray;
573 typedef struct _GCache GCache;
574 typedef struct _GCompletion GCompletion;
575 typedef struct _GData GData;
576 typedef struct _GDebugKey GDebugKey;
577 typedef struct _GHashTable GHashTable;
578 typedef struct _GHook GHook;
579 typedef struct _GHookList GHookList;
580 typedef struct _GList GList;
581 typedef struct _GListAllocator GListAllocator;
582 typedef struct _GMemChunk GMemChunk;
583 typedef struct _GNode GNode;
584 typedef struct _GPtrArray GPtrArray;
585 typedef struct _GRelation GRelation;
586 typedef struct _GScanner GScanner;
587 typedef struct _GScannerConfig GScannerConfig;
588 typedef struct _GSList GSList;
589 typedef struct _GString GString;
590 typedef struct _GStringChunk GStringChunk;
591 typedef struct _GTimer GTimer;
592 typedef struct _GTree GTree;
593 typedef struct _GTuples GTuples;
594 typedef union _GTokenValue GTokenValue;
599 G_TRAVERSE_LEAFS = 1 << 0,
600 G_TRAVERSE_NON_LEAFS = 1 << 1,
601 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
602 G_TRAVERSE_MASK = 0x03
613 /* Log level shift offset for user defined
614 * log levels (0-7 are used by GLib).
616 #define G_LOG_LEVEL_USER_SHIFT (8)
618 /* Glib log levels and flags.
623 G_LOG_FLAG_RECURSION = 1 << 0,
624 G_LOG_FLAG_FATAL = 1 << 1,
626 /* GLib log levels */
627 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
628 G_LOG_LEVEL_CRITICAL = 1 << 3,
629 G_LOG_LEVEL_WARNING = 1 << 4,
630 G_LOG_LEVEL_MESSAGE = 1 << 5,
631 G_LOG_LEVEL_INFO = 1 << 6,
632 G_LOG_LEVEL_DEBUG = 1 << 7,
634 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
637 /* GLib log levels that are considered fatal by default */
638 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
641 typedef gpointer (*GCacheNewFunc) (gpointer key);
642 typedef gpointer (*GCacheDupFunc) (gpointer value);
643 typedef void (*GCacheDestroyFunc) (gpointer value);
644 typedef gint (*GCompareFunc) (gconstpointer a,
646 typedef gchar* (*GCompletionFunc) (gpointer);
647 typedef void (*GDestroyNotify) (gpointer data);
648 typedef void (*GDataForeachFunc) (GQuark key_id,
651 typedef void (*GFunc) (gpointer data,
653 typedef guint (*GHashFunc) (gconstpointer key);
654 typedef void (*GHFunc) (gpointer key,
657 typedef gboolean (*GHRFunc) (gpointer key,
660 typedef gint (*GHookCompareFunc) (GHook *new_hook,
662 typedef gboolean (*GHookFindFunc) (GHook *hook,
664 typedef void (*GHookMarshaller) (GHook *hook,
666 typedef void (*GHookFunc) (gpointer data);
667 typedef gboolean (*GHookCheckFunc) (gpointer data);
668 typedef void (*GLogFunc) (const gchar *log_domain,
669 GLogLevelFlags log_level,
670 const gchar *message,
672 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
674 typedef void (*GNodeForeachFunc) (GNode *node,
676 typedef gint (*GSearchFunc) (gpointer key,
678 typedef void (*GScannerMsgFunc) (GScanner *scanner,
681 typedef gint (*GTraverseFunc) (gpointer key,
684 typedef void (*GVoidFunc) (void);
735 struct _GCache { gint dummy; };
736 struct _GTree { gint dummy; };
737 struct _GTimer { gint dummy; };
738 struct _GMemChunk { gint dummy; };
739 struct _GListAllocator { gint dummy; };
740 struct _GStringChunk { gint dummy; };
743 /* Doubly linked lists
745 GList* g_list_alloc (void);
746 void g_list_free (GList *list);
747 void g_list_free_1 (GList *list);
748 GList* g_list_append (GList *list,
750 GList* g_list_prepend (GList *list,
752 GList* g_list_insert (GList *list,
755 GList* g_list_insert_sorted (GList *list,
758 GList* g_list_concat (GList *list1,
760 GList* g_list_remove (GList *list,
762 GList* g_list_remove_link (GList *list,
764 GList* g_list_reverse (GList *list);
765 GList* g_list_nth (GList *list,
767 GList* g_list_find (GList *list,
769 GList* g_list_find_custom (GList *list,
772 gint g_list_position (GList *list,
774 gint g_list_index (GList *list,
776 GList* g_list_last (GList *list);
777 GList* g_list_first (GList *list);
778 guint g_list_length (GList *list);
779 void g_list_foreach (GList *list,
782 gpointer g_list_nth_data (GList *list,
784 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
785 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
788 /* Singly linked lists
790 GSList* g_slist_alloc (void);
791 void g_slist_free (GSList *list);
792 void g_slist_free_1 (GSList *list);
793 GSList* g_slist_append (GSList *list,
795 GSList* g_slist_prepend (GSList *list,
797 GSList* g_slist_insert (GSList *list,
800 GSList* g_slist_insert_sorted (GSList *list,
803 GSList* g_slist_concat (GSList *list1,
805 GSList* g_slist_remove (GSList *list,
807 GSList* g_slist_remove_link (GSList *list,
809 GSList* g_slist_reverse (GSList *list);
810 GSList* g_slist_nth (GSList *list,
812 GSList* g_slist_find (GSList *list,
814 GSList* g_slist_find_custom (GSList *list,
817 gint g_slist_position (GSList *list,
819 gint g_slist_index (GSList *list,
821 GSList* g_slist_last (GSList *list);
822 guint g_slist_length (GSList *list);
823 void g_slist_foreach (GSList *list,
826 gpointer g_slist_nth_data (GSList *list,
828 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
833 GListAllocator* g_list_allocator_new (void);
834 void g_list_allocator_free (GListAllocator* allocator);
835 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
836 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
841 GHashTable* g_hash_table_new (GHashFunc hash_func,
842 GCompareFunc key_compare_func);
843 void g_hash_table_destroy (GHashTable *hash_table);
844 void g_hash_table_insert (GHashTable *hash_table,
847 void g_hash_table_remove (GHashTable *hash_table,
849 gpointer g_hash_table_lookup (GHashTable *hash_table,
851 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
852 gconstpointer lookup_key,
855 void g_hash_table_freeze (GHashTable *hash_table);
856 void g_hash_table_thaw (GHashTable *hash_table);
857 void g_hash_table_foreach (GHashTable *hash_table,
860 gint g_hash_table_foreach_remove (GHashTable *hash_table,
863 gint g_hash_table_size (GHashTable *hash_table);
868 GCache* g_cache_new (GCacheNewFunc value_new_func,
869 GCacheDestroyFunc value_destroy_func,
870 GCacheDupFunc key_dup_func,
871 GCacheDestroyFunc key_destroy_func,
872 GHashFunc hash_key_func,
873 GHashFunc hash_value_func,
874 GCompareFunc key_compare_func);
875 void g_cache_destroy (GCache *cache);
876 gpointer g_cache_insert (GCache *cache,
878 void g_cache_remove (GCache *cache,
880 void g_cache_key_foreach (GCache *cache,
883 void g_cache_value_foreach (GCache *cache,
888 /* Balanced binary trees
890 GTree* g_tree_new (GCompareFunc key_compare_func);
891 void g_tree_destroy (GTree *tree);
892 void g_tree_insert (GTree *tree,
895 void g_tree_remove (GTree *tree,
897 gpointer g_tree_lookup (GTree *tree,
899 void g_tree_traverse (GTree *tree,
900 GTraverseFunc traverse_func,
901 GTraverseType traverse_type,
903 gpointer g_tree_search (GTree *tree,
904 GSearchFunc search_func,
906 gint g_tree_height (GTree *tree);
907 gint g_tree_nnodes (GTree *tree);
911 /* N-way tree implementation
922 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
923 ((GNode*) (node))->prev == NULL && \
924 ((GNode*) (node))->next == NULL)
925 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
927 GNode* g_node_new (gpointer data);
928 void g_node_destroy (GNode *root);
929 void g_node_unlink (GNode *node);
930 GNode* g_node_insert (GNode *parent,
933 GNode* g_node_insert_before (GNode *parent,
936 GNode* g_node_prepend (GNode *parent,
938 guint g_node_n_nodes (GNode *root,
939 GTraverseFlags flags);
940 GNode* g_node_get_root (GNode *node);
941 gboolean g_node_is_ancestor (GNode *node,
943 guint g_node_depth (GNode *node);
944 GNode* g_node_find (GNode *root,
946 GTraverseFlags flags,
949 /* convenience macros */
950 #define g_node_append(parent, node) \
951 g_node_insert_before ((parent), NULL, (node))
952 #define g_node_insert_data(parent, position, data) \
953 g_node_insert ((parent), (position), g_node_new (data))
954 #define g_node_insert_data_before(parent, sibling, data) \
955 g_node_insert_before ((parent), (sibling), g_node_new (data))
956 #define g_node_prepend_data(parent, data) \
957 g_node_prepend ((parent), g_node_new (data))
958 #define g_node_append_data(parent, data) \
959 g_node_insert_before ((parent), NULL, g_node_new (data))
961 /* traversal function, assumes that `node' is root
962 * (only traverses `node' and its subtree).
963 * this function is just a high level interface to
964 * low level traversal functions, optimized for speed.
966 void g_node_traverse (GNode *root,
968 GTraverseFlags flags,
970 GNodeTraverseFunc func,
973 /* return the maximum tree height starting with `node', this is an expensive
974 * operation, since we need to visit all nodes. this could be shortened by
975 * adding `guint height' to struct _GNode, but then again, this is not very
976 * often needed, and would make g_node_insert() more time consuming.
978 guint g_node_max_height (GNode *root);
980 void g_node_children_foreach (GNode *node,
981 GTraverseFlags flags,
982 GNodeForeachFunc func,
984 void g_node_reverse_children (GNode *node);
985 guint g_node_n_children (GNode *node);
986 GNode* g_node_nth_child (GNode *node,
988 GNode* g_node_last_child (GNode *node);
989 GNode* g_node_find_child (GNode *node,
990 GTraverseFlags flags,
992 gint g_node_child_position (GNode *node,
994 gint g_node_child_index (GNode *node,
997 GNode* g_node_first_sibling (GNode *node);
998 GNode* g_node_last_sibling (GNode *node);
1000 #define g_node_prev_sibling(node) ((node) ? \
1001 ((GNode*) (node))->prev : NULL)
1002 #define g_node_next_sibling(node) ((node) ? \
1003 ((GNode*) (node))->next : NULL)
1004 #define g_node_first_child(node) ((node) ? \
1005 ((GNode*) (node))->children : NULL)
1008 /* Callback maintenance functions
1010 #define G_HOOK_FLAG_USER_SHIFT (4)
1013 G_HOOK_ACTIVE = 1 << 0,
1014 G_HOOK_IN_CALL = 1 << 1,
1015 G_HOOK_FLAG_MASK = 0x0f
1024 GMemChunk *hook_memchunk;
1036 GDestroyNotify destroy;
1039 #define G_HOOK_IS_ACTIVE(hook) ((((GHook*) hook)->flags & \
1040 G_HOOK_ACTIVE) != 0)
1041 #define G_HOOK_IS_IN_CALL(hook) ((((GHook*) hook)->flags & \
1042 G_HOOK_IN_CALL) != 0)
1043 #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
1044 G_HOOK_IS_ACTIVE (hook))
1045 #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
1046 ((GHook*) hook)->prev == NULL && \
1047 ((GHook*) hook)->hook_id == 0 && \
1048 ((GHook*) hook)->ref_count == 0)
1050 void g_hook_list_init (GHookList *hook_list,
1052 void g_hook_list_clear (GHookList *hook_list);
1053 GHook* g_hook_alloc (GHookList *hook_list);
1054 void g_hook_free (GHookList *hook_list,
1056 void g_hook_ref (GHookList *hook_list,
1058 void g_hook_unref (GHookList *hook_list,
1060 gboolean g_hook_destroy (GHookList *hook_list,
1062 void g_hook_destroy_link (GHookList *hook_list,
1064 void g_hook_prepend (GHookList *hook_list,
1066 void g_hook_insert_before (GHookList *hook_list,
1069 void g_hook_insert_sorted (GHookList *hook_list,
1071 GHookCompareFunc func);
1072 GHook* g_hook_get (GHookList *hook_list,
1074 GHook* g_hook_find (GHookList *hook_list,
1075 gboolean need_valids,
1078 GHook* g_hook_find_data (GHookList *hook_list,
1079 gboolean need_valids,
1081 GHook* g_hook_find_func (GHookList *hook_list,
1082 gboolean need_valids,
1084 GHook* g_hook_find_func_data (GHookList *hook_list,
1085 gboolean need_valids,
1088 GHook* g_hook_first_valid (GHookList *hook_list);
1089 GHook* g_hook_next_valid (GHook *hook);
1090 gint g_hook_compare_ids (GHook *new_hook,
1093 /* convenience macros */
1094 #define g_hook_append( hook_list, hook ) \
1095 g_hook_insert_before ((hook_list), NULL, (hook))
1097 /* invoke all valid hooks with the (*GHookFunc) signature.
1099 void g_hook_list_invoke (GHookList *hook_list,
1100 gboolean may_recurse);
1101 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1102 * and destroy the hook if FALSE is returned.
1104 void g_hook_list_invoke_check (GHookList *hook_list,
1105 gboolean may_recurse);
1106 /* invoke a marshaller on all valid hooks.
1108 void g_hook_list_marshal (GHookList *hook_list,
1109 gboolean may_recurse,
1110 GHookMarshaller marshaller,
1114 /* Fatal error handlers.
1115 * g_on_error_query() will prompt the user to either
1116 * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1117 * g_on_error_stack_trace() invokes gdb, which attaches to the current
1118 * process and shows a stack trace.
1119 * These function may cause different actions on non-unix platforms.
1120 * The prg_name arg is required by gdb to find the executable, if it is
1121 * passed as NULL, g_on_error_query() will try g_get_prgname().
1123 void g_on_error_query (const gchar *prg_name);
1124 void g_on_error_stack_trace (const gchar *prg_name);
1127 /* Logging mechanism
1129 extern const gchar *g_log_domain_glib;
1130 guint g_log_set_handler (const gchar *log_domain,
1131 GLogLevelFlags log_levels,
1133 gpointer user_data);
1134 void g_log_remove_handler (const gchar *log_domain,
1136 void g_log_default_handler (const gchar *log_domain,
1137 GLogLevelFlags log_level,
1138 const gchar *message,
1139 gpointer unused_data);
1140 void g_log (const gchar *log_domain,
1141 GLogLevelFlags log_level,
1142 const gchar *format,
1143 ...) G_GNUC_PRINTF (3, 4);
1144 void g_logv (const gchar *log_domain,
1145 GLogLevelFlags log_level,
1146 const gchar *format,
1148 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
1149 GLogLevelFlags fatal_mask);
1150 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
1151 #ifndef G_LOG_DOMAIN
1152 #define G_LOG_DOMAIN (NULL)
1153 #endif /* G_LOG_DOMAIN */
1155 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1156 G_LOG_LEVEL_ERROR, \
1158 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1159 G_LOG_LEVEL_MESSAGE, \
1161 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1162 G_LOG_LEVEL_WARNING, \
1164 #else /* !__GNUC__ */
1166 g_error (const gchar *format,
1170 va_start (args, format);
1171 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1175 g_message (const gchar *format,
1179 va_start (args, format);
1180 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1184 g_warning (const gchar *format,
1188 va_start (args, format);
1189 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1192 #endif /* !__GNUC__ */
1194 typedef void (*GPrintFunc) (const gchar *string);
1195 void g_print (const gchar *format,
1196 ...) G_GNUC_PRINTF (1, 2);
1197 GPrintFunc g_set_print_handler (GPrintFunc func);
1198 void g_printerr (const gchar *format,
1199 ...) G_GNUC_PRINTF (1, 2);
1200 GPrintFunc g_set_printerr_handler (GPrintFunc func);
1202 /* deprecated compatibility functions, use g_log_set_handler() instead */
1203 typedef void (*GErrorFunc) (const gchar *str);
1204 typedef void (*GWarningFunc) (const gchar *str);
1205 GErrorFunc g_set_error_handler (GErrorFunc func);
1206 GWarningFunc g_set_warning_handler (GWarningFunc func);
1207 GPrintFunc g_set_message_handler (GPrintFunc func);
1210 /* Memory allocation and debugging
1214 #define g_malloc(size) ((gpointer) MALLOC (size))
1215 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
1216 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
1217 #define g_free(mem) FREE (mem)
1219 #else /* !USE_DMALLOC */
1221 gpointer g_malloc (gulong size);
1222 gpointer g_malloc0 (gulong size);
1223 gpointer g_realloc (gpointer mem,
1225 void g_free (gpointer mem);
1227 #endif /* !USE_DMALLOC */
1229 void g_mem_profile (void);
1230 void g_mem_check (gpointer mem);
1233 /* "g_mem_chunk_new" creates a new memory chunk.
1234 * Memory chunks are used to allocate pieces of memory which are
1235 * always the same size. Lists are a good example of such a data type.
1236 * The memory chunk allocates and frees blocks of memory as needed.
1237 * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1238 * allocated in a mem chunk. ("g_free" will most likely cause a seg
1239 * fault...somewhere).
1241 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1242 * want to know what's going on inside do you?)
1245 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1246 * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1247 * atom. (They are also useful for lists which use MemChunk to allocate
1248 * memory but are also part of the MemChunk implementation).
1249 * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1252 #define G_ALLOC_ONLY 1
1253 #define G_ALLOC_AND_FREE 2
1255 GMemChunk* g_mem_chunk_new (gchar *name,
1259 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
1260 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
1261 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1262 void g_mem_chunk_free (GMemChunk *mem_chunk,
1264 void g_mem_chunk_clean (GMemChunk *mem_chunk);
1265 void g_mem_chunk_reset (GMemChunk *mem_chunk);
1266 void g_mem_chunk_print (GMemChunk *mem_chunk);
1267 void g_mem_chunk_info (void);
1269 /* Ah yes...we have a "g_blow_chunks" function.
1270 * "g_blow_chunks" simply compresses all the chunks. This operation
1271 * consists of freeing every memory area that should be freed (but
1272 * which we haven't gotten around to doing yet). And, no,
1273 * "g_blow_chunks" doesn't follow the naming scheme, but it is a
1274 * much better name than "g_mem_chunk_clean_all" or something
1277 void g_blow_chunks (void);
1282 GTimer* g_timer_new (void);
1283 void g_timer_destroy (GTimer *timer);
1284 void g_timer_start (GTimer *timer);
1285 void g_timer_stop (GTimer *timer);
1286 void g_timer_reset (GTimer *timer);
1287 gdouble g_timer_elapsed (GTimer *timer,
1288 gulong *microseconds);
1291 /* String utility functions
1293 #define G_STR_DELIMITERS "_-|> <."
1294 void g_strdelimit (gchar *string,
1295 const gchar *delimiters,
1296 gchar new_delimiter);
1297 gchar* g_strdup (const gchar *str);
1298 gchar* g_strdup_printf (const gchar *format,
1299 ...) G_GNUC_PRINTF (1, 2);
1300 gchar* g_strdup_vprintf (const gchar *format,
1302 gchar* g_strndup (const gchar *str,
1304 gchar* g_strnfill (guint length,
1306 gchar* g_strconcat (const gchar *string1,
1307 ...); /* NULL terminated */
1308 gdouble g_strtod (const gchar *nptr,
1310 gchar* g_strerror (gint errnum);
1311 gchar* g_strsignal (gint signum);
1312 gint g_strcasecmp (const gchar *s1,
1314 void g_strdown (gchar *string);
1315 void g_strup (gchar *string);
1316 void g_strreverse (gchar *string);
1317 gpointer g_memdup (gconstpointer mem,
1320 /* calculate a string size, guarranteed to fit format + args.
1322 guint g_printf_string_upper_bound (const gchar* format,
1326 /* Retrive static string info
1328 gchar* g_get_user_name (void);
1329 gchar* g_get_real_name (void);
1330 gchar* g_get_home_dir (void);
1331 gchar* g_get_tmp_dir (void);
1332 gchar* g_get_prgname (void);
1333 void g_set_prgname (const gchar *prgname);
1336 /* Miscellaneous utility functions
1338 guint g_parse_debug_string (const gchar *string,
1341 gint g_snprintf (gchar *string,
1343 gchar const *format,
1344 ...) G_GNUC_PRINTF (3, 4);
1345 gint g_vsnprintf (gchar *string,
1347 gchar const *format,
1349 gchar* g_basename (const gchar *file_name);
1351 /* strings are newly allocated with g_malloc() */
1352 gchar* g_dirname (const gchar *file_name);
1353 gchar* g_get_current_dir (void);
1355 /* We make the assumption that if memmove isn't available, then
1356 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1357 * necessarily handle overlapping copies).
1358 * Either way, g_memmove() will not return a value.
1361 #define g_memmove(dest, src, size) G_STMT_START { \
1362 memmove ((dest), (src), (size)); \
1365 #define g_memmove(dest, src, size) G_STMT_START { \
1366 bcopy ((src), (dest), (size)); \
1370 /* we use a GLib function as a replacement for ATEXIT, so
1371 * the programmer is not required to check the return value
1372 * (if there is any in the implementation) and doesn't encounter
1373 * missing include files.
1375 void g_atexit (GVoidFunc func);
1380 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1384 g_bit_nth_lsf (guint32 mask,
1390 if (mask & (1 << (guint) nth_bit))
1393 while (nth_bit < 32);
1396 #endif /* G_CAN_INLINE */
1398 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1402 g_bit_nth_msf (guint32 mask,
1410 if (mask & (1 << (guint) nth_bit))
1413 while (nth_bit > 0);
1416 #endif /* G_CAN_INLINE */
1418 G_INLINE_FUNC guint g_bit_storage (guint number);
1421 g_bit_storage (guint number)
1423 register guint n_bits = 0;
1433 #endif /* G_CAN_INLINE */
1438 GStringChunk* g_string_chunk_new (gint size);
1439 void g_string_chunk_free (GStringChunk *chunk);
1440 gchar* g_string_chunk_insert (GStringChunk *chunk,
1441 const gchar *string);
1442 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1443 const gchar *string);
1448 GString* g_string_new (const gchar *init);
1449 GString* g_string_sized_new (guint dfl_size);
1450 void g_string_free (GString *string,
1452 GString* g_string_assign (GString *lval,
1454 GString* g_string_truncate (GString *string,
1456 GString* g_string_append (GString *string,
1458 GString* g_string_append_c (GString *string,
1460 GString* g_string_prepend (GString *string,
1462 GString* g_string_prepend_c (GString *string,
1464 GString* g_string_insert (GString *string,
1467 GString* g_string_insert_c (GString *string,
1470 GString* g_string_erase (GString *string,
1473 GString* g_string_down (GString *string);
1474 GString* g_string_up (GString *string);
1475 void g_string_sprintf (GString *string,
1476 const gchar *format,
1477 ...) G_GNUC_PRINTF (2, 3);
1478 void g_string_sprintfa (GString *string,
1479 const gchar *format,
1480 ...) G_GNUC_PRINTF (2, 3);
1486 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1487 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1488 #define g_array_index(a,t,i) (((t*)a->data)[i])
1490 GArray* g_array_new (gboolean zero_terminated,
1492 guint element_size);
1493 void g_array_free (GArray *array,
1494 gboolean free_segment);
1495 GArray* g_array_append_vals (GArray *array,
1498 GArray* g_array_prepend_vals (GArray *array,
1501 GArray* g_array_set_size (GArray *array,
1504 /* Resizable pointer array. This interface is much less complicated
1505 * than the above. Add appends appends a pointer. Remove fills any
1506 * cleared spot and shortens the array.
1508 #define g_ptr_array_index(array,index) (array->pdata)[index]
1509 GPtrArray* g_ptr_array_new (void);
1510 void g_ptr_array_free (GPtrArray *array,
1512 void g_ptr_array_set_size (GPtrArray *array,
1514 gpointer g_ptr_array_remove_index (GPtrArray *array,
1516 gboolean g_ptr_array_remove (GPtrArray *array,
1518 void g_ptr_array_add (GPtrArray *array,
1521 /* Byte arrays, an array of guint8. Implemented as a GArray,
1525 GByteArray* g_byte_array_new (void);
1526 void g_byte_array_free (GByteArray *array,
1527 gboolean free_segment);
1528 GByteArray* g_byte_array_append (GByteArray *array,
1531 GByteArray* g_byte_array_prepend (GByteArray *array,
1534 GByteArray* g_byte_array_set_size (GByteArray *array,
1540 gint g_str_equal (gconstpointer v,
1542 guint g_str_hash (gconstpointer v);
1544 gint g_int_equal (gconstpointer v,
1546 guint g_int_hash (gconstpointer v);
1548 /* This "hash" function will just return the key's adress as an
1549 * unsigned integer. Useful for hashing on plain adresses or
1550 * simple integer values.
1552 guint g_direct_hash (gconstpointer v);
1553 gint g_direct_equal (gconstpointer v,
1557 /* Quarks (string<->id association)
1559 GQuark g_quark_try_string (const gchar *string);
1560 GQuark g_quark_from_static_string (const gchar *string);
1561 GQuark g_quark_from_string (const gchar *string);
1562 gchar* g_quark_to_string (GQuark quark);
1567 void g_datalist_init (GData **datalist);
1568 void g_datalist_clear (GData **datalist);
1569 gpointer g_datalist_id_get_data (GData **datalist,
1571 void g_datalist_id_set_data_full (GData **datalist,
1574 GDestroyNotify destroy_func);
1575 void g_datalist_id_set_destroy (GData **datalist,
1577 GDestroyNotify destroy_func);
1578 void g_datalist_foreach (GData **datalist,
1579 GDataForeachFunc func,
1580 gpointer user_data);
1581 #define g_datalist_id_set_data(dl, q, d) \
1582 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1583 #define g_datalist_id_remove_data(dl, q) \
1584 g_datalist_id_set_data ((dl), (q), NULL)
1585 #define g_datalist_get_data(dl, k) \
1586 (g_datalist_id_get_data ((dl), g_quark_try_string ((k))))
1587 #define g_datalist_set_data_full(dl, k, d, f) \
1588 g_datalist_id_set_data_full ((dl), g_quark_from_string ((k)), (d), (f))
1589 #define g_datalist_set_destroy(dl, k, f) \
1590 g_datalist_id_set_destroy ((dl), g_quark_try_string ((k)), (f))
1591 #define g_datalist_set_data(dl, k, d) \
1592 g_datalist_set_data_full ((dl), (k), (d), NULL)
1593 #define g_datalist_remove_data(dl, k) \
1594 g_datalist_id_set_data ((dl), g_quark_try_string ((k)), NULL)
1597 /* Location Associated Keyed Data
1599 void g_dataset_destroy (gconstpointer dataset_location);
1600 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1602 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1605 GDestroyNotify destroy_func);
1606 void g_dataset_id_set_destroy (gconstpointer dataset_location,
1608 GDestroyNotify destroy_func);
1609 void g_dataset_foreach (gconstpointer dataset_location,
1610 GDataForeachFunc func,
1611 gpointer user_data);
1612 #define g_dataset_id_set_data(l, k, d) \
1613 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1614 #define g_dataset_id_remove_data(l, k) \
1615 g_dataset_id_set_data ((l), (k), NULL)
1616 #define g_dataset_get_data(l, k) \
1617 (g_dataset_id_get_data ((l), g_quark_try_string ((k))))
1618 #define g_dataset_set_data_full(l, k, d, f) \
1619 g_dataset_id_set_data_full ((l), g_quark_from_string ((k)), (d), (f))
1620 #define g_dataset_set_destroy(l, k, f) \
1621 g_dataset_id_set_destroy ((l), g_quark_try_string ((k)), (f))
1622 #define g_dataset_set_data(l, k, d) \
1623 g_dataset_set_data_full ((l), (k), (d), NULL)
1624 #define g_dataset_remove_data(l, k) \
1625 g_dataset_id_set_data ((l), g_quark_try_string ((k)), NULL)
1628 /* GScanner: Flexible lexical scanner for general purpose.
1631 /* Character sets */
1632 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1633 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1634 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1635 "\307\310\311\312\313\314\315\316\317\320"\
1636 "\321\322\323\324\325\326"\
1637 "\330\331\332\333\334\335\336"
1638 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1639 "\347\350\351\352\353\354\355\356\357\360"\
1640 "\361\362\363\364\365\366"\
1641 "\370\371\372\373\374\375\376\377"
1648 G_ERR_UNEXP_EOF_IN_STRING,
1649 G_ERR_UNEXP_EOF_IN_COMMENT,
1650 G_ERR_NON_DIGIT_IN_CONST,
1653 G_ERR_FLOAT_MALFORMED
1661 G_TOKEN_LEFT_PAREN = '(',
1662 G_TOKEN_RIGHT_PAREN = ')',
1663 G_TOKEN_LEFT_CURLY = '{',
1664 G_TOKEN_RIGHT_CURLY = '}',
1665 G_TOKEN_LEFT_BRACE = '[',
1666 G_TOKEN_RIGHT_BRACE = ']',
1667 G_TOKEN_EQUAL_SIGN = '=',
1668 G_TOKEN_COMMA = ',',
1684 G_TOKEN_IDENTIFIER_NULL,
1686 G_TOKEN_COMMENT_SINGLE,
1687 G_TOKEN_COMMENT_MULTI,
1694 gchar *v_identifier;
1706 struct _GScannerConfig
1710 gchar *cset_skip_characters; /* default: " \t\n" */
1711 gchar *cset_identifier_first;
1712 gchar *cset_identifier_nth;
1713 gchar *cpair_comment_single; /* default: "#\n" */
1715 /* Should symbol lookup work case sensitive?
1717 guint case_sensitive : 1;
1719 /* Boolean values to be adjusted "on the fly"
1720 * to configure scanning behaviour.
1722 guint skip_comment_multi : 1; /* C like comment */
1723 guint skip_comment_single : 1; /* single line comment */
1724 guint scan_comment_multi : 1; /* scan multi line comments? */
1725 guint scan_identifier : 1;
1726 guint scan_identifier_1char : 1;
1727 guint scan_identifier_NULL : 1;
1728 guint scan_symbols : 1;
1729 guint scan_binary : 1;
1730 guint scan_octal : 1;
1731 guint scan_float : 1;
1732 guint scan_hex : 1; /* `0x0ff0' */
1733 guint scan_hex_dollar : 1; /* `$0ff0' */
1734 guint scan_string_sq : 1; /* string: 'anything' */
1735 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1736 guint numbers_2_int : 1; /* bin, octal, hex => int */
1737 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1738 guint identifier_2_string : 1;
1739 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1740 guint symbol_2_token : 1;
1741 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1748 guint max_parse_errors;
1750 /* g_scanner_error() increments this field */
1753 /* name of input stream, featured by the default message handler */
1754 const gchar *input_name;
1756 /* data pointer for derived structures */
1757 gpointer derived_data;
1759 /* link into the scanner configuration */
1760 GScannerConfig *config;
1762 /* fields filled in after g_scanner_get_next_token() */
1768 /* fields filled in after g_scanner_peek_next_token() */
1769 GTokenType next_token;
1770 GTokenValue next_value;
1772 guint next_position;
1774 /* to be considered private */
1775 GHashTable *symbol_table;
1778 const gchar *text_end;
1782 /* handler function for _warn and _error */
1783 GScannerMsgFunc msg_handler;
1786 GScanner* g_scanner_new (GScannerConfig *config_templ);
1787 void g_scanner_destroy (GScanner *scanner);
1788 void g_scanner_input_file (GScanner *scanner,
1790 void g_scanner_input_text (GScanner *scanner,
1793 GTokenType g_scanner_get_next_token (GScanner *scanner);
1794 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1795 GTokenType g_scanner_cur_token (GScanner *scanner);
1796 GTokenValue g_scanner_cur_value (GScanner *scanner);
1797 guint g_scanner_cur_line (GScanner *scanner);
1798 guint g_scanner_cur_position (GScanner *scanner);
1799 gboolean g_scanner_eof (GScanner *scanner);
1800 guint g_scanner_set_scope (GScanner *scanner,
1802 void g_scanner_scope_add_symbol (GScanner *scanner,
1804 const gchar *symbol,
1806 void g_scanner_scope_remove_symbol (GScanner *scanner,
1808 const gchar *symbol);
1809 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1811 const gchar *symbol);
1812 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1815 gpointer func_data);
1816 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1817 const gchar *symbol);
1818 void g_scanner_freeze_symbol_table (GScanner *scanner);
1819 void g_scanner_thaw_symbol_table (GScanner *scanner);
1820 void g_scanner_unexp_token (GScanner *scanner,
1821 GTokenType expected_token,
1822 const gchar *identifier_spec,
1823 const gchar *symbol_spec,
1824 const gchar *symbol_name,
1825 const gchar *message,
1827 void g_scanner_error (GScanner *scanner,
1828 const gchar *format,
1829 ...) G_GNUC_PRINTF (2,3);
1830 void g_scanner_warn (GScanner *scanner,
1831 const gchar *format,
1832 ...) G_GNUC_PRINTF (2,3);
1833 gint g_scanner_stat_mode (const gchar *filename);
1834 /* keep downward source compatibility */
1835 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1836 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1838 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1839 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1841 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1842 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1851 GCompletionFunc func;
1857 GCompletion* g_completion_new (GCompletionFunc func);
1858 void g_completion_add_items (GCompletion* cmp,
1860 void g_completion_remove_items (GCompletion* cmp,
1862 void g_completion_clear_items (GCompletion* cmp);
1863 GList* g_completion_complete (GCompletion* cmp,
1865 gchar** new_prefix);
1866 void g_completion_free (GCompletion* cmp);
1869 /* GRelation: Indexed Relations. Imagine a really simple table in a
1870 * database. Relations are not ordered. This data type is meant for
1871 * maintaining a N-way mapping.
1873 * g_relation_new() creates a relation with FIELDS fields
1875 * g_relation_destroy() frees all resources
1876 * g_tuples_destroy() frees the result of g_relation_select()
1878 * g_relation_index() indexes relation FIELD with the provided
1879 * equality and hash functions. this must be done before any
1880 * calls to insert are made.
1882 * g_relation_insert() inserts a new tuple. you are expected to
1883 * provide the right number of fields.
1885 * g_relation_delete() deletes all relations with KEY in FIELD
1886 * g_relation_select() returns ...
1887 * g_relation_count() counts ...
1890 GRelation* g_relation_new (gint fields);
1891 void g_relation_destroy (GRelation *relation);
1892 void g_relation_index (GRelation *relation,
1894 GHashFunc hash_func,
1895 GCompareFunc key_compare_func);
1896 void g_relation_insert (GRelation *relation,
1898 gint g_relation_delete (GRelation *relation,
1901 GTuples* g_relation_select (GRelation *relation,
1904 gint g_relation_count (GRelation *relation,
1907 gboolean g_relation_exists (GRelation *relation,
1909 void g_relation_print (GRelation *relation);
1911 void g_tuples_destroy (GTuples *tuples);
1912 gpointer g_tuples_index (GTuples *tuples,
1920 /* This function returns prime numbers spaced by approximately 1.5-2.0
1921 * and is for use in resizing data structures which prefer
1922 * prime-valued sizes. The closest spaced prime function returns the
1923 * next largest prime, or the highest it knows about which is about
1927 guint g_spaced_primes_closest (guint num);
1931 extern const guint glib_major_version;
1932 extern const guint glib_minor_version;
1933 extern const guint glib_micro_version;
1937 #endif /* __cplusplus */
1940 #endif /* __G_LIB_H__ */