1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 /* system specific config file
24 #include <glibconfig.h>
26 /* include varargs functions for assertment macros
30 /* optionally feature DMALLOC memory allocation debugger
37 /* glib provides definitions for the extrema of many
38 * of the standard types. These are:
50 * We include limits.h before float.h to work around a egcs 1.1
51 * oddity on Solaris 2.5.1
55 # define G_MINSHORT SHRT_MIN
56 # define G_MAXSHORT SHRT_MAX
57 # define G_MININT INT_MIN
58 # define G_MAXINT INT_MAX
59 # define G_MINLONG LONG_MIN
60 # define G_MAXLONG LONG_MAX
64 # endif /* HAVE_FLOAT_H */
65 # define G_MINSHORT MINSHORT
66 # define G_MAXSHORT MAXSHORT
67 # define G_MININT MININT
68 # define G_MAXINT MAXINT
69 # define G_MINLONG MINLONG
70 # define G_MAXLONG MAXLONG
71 #endif /* HAVE_VALUES_H */
75 # define G_MINFLOAT FLT_MIN
76 # define G_MAXFLOAT FLT_MAX
77 # define G_MINDOUBLE DBL_MIN
78 # define G_MAXDOUBLE DBL_MAX
81 # define G_MINFLOAT MINFLOAT
82 # define G_MAXFLOAT MAXFLOAT
83 # define G_MINDOUBLE MINDOUBLE
84 # define G_MAXDOUBLE MAXDOUBLE
85 #endif /* HAVE_VALUES_H */
90 #endif /* __cplusplus */
93 /* Provide definitions for some commonly used macros.
94 * Some of them are only provided if they haven't already
95 * been defined. It is assumed that if they are already
96 * defined then the current definition is correct.
99 #define NULL ((void*) 0)
107 #define TRUE (!FALSE)
111 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
114 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
117 #define ABS(a) (((a) < 0) ? -(a) : (a))
120 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
123 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
124 * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
126 #if !defined (G_VA_COPY)
127 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
128 # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
129 # elif defined (G_VA_COPY_AS_ARRAY)
130 # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
131 # else /* va_list is a pointer */
132 # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
133 # endif /* va_list is a pointer */
134 #endif /* !G_VA_COPY */
137 /* Provide simple enum value macro wrappers that ease automated
138 * enum value stringification code. [abandoned]
140 #if !defined (G_CODE_GENERATION)
141 #define G_ENUM( EnumerationName ) EnumerationName
142 #define G_FLAGS( EnumerationName ) EnumerationName
143 #define G_NV( VALUE_NAME , value_nick, VALUE) VALUE_NAME = (VALUE)
144 #define G_SV( VALUE_NAME, value_nick ) VALUE_NAME
145 #else /* G_CODE_GENERATION */
146 #define G_ENUM( EnumerationName ) G_ENUM_E + EnumerationName +
147 #define G_FLAGS( EnumerationName ) G_ENUM_F + EnumerationName +
148 #define G_NV( VALUE_NAME , value_nick, VALUE) G_ENUM_V + VALUE_NAME + value_nick +
149 #define G_SV( VALUE_NAME, value_nick ) G_ENUM_V + VALUE_NAME + value_nick +
150 #endif /* G_CODE_GENERATION */
153 /* inlining hassle. for compilers that don't allow the `inline' keyword,
154 * mostly because of strict ANSI C compliance or dumbness, we try to fall
155 * back to either `__inline__' or `__inline'.
156 * we define G_CAN_INLINE, if the compiler seems to be actually
157 * *capable* to do function inlining, in which case inline function bodys
158 * do make sense. we also define G_INLINE_FUNC to properly export the
159 * function prototypes if no inlinig can be performed.
160 * we special case most of the stuff, so inline functions can have a normal
161 * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
163 #ifndef G_INLINE_FUNC
164 # define G_CAN_INLINE 1
167 # if defined (__GNUC__) && defined (__STRICT_ANSI__)
169 # define inline __inline__
171 #else /* !G_HAVE_INLINE */
173 # if defined (G_HAVE___INLINE__)
174 # define inline __inline__
175 # else /* !inline && !__inline__ */
176 # if defined (G_HAVE___INLINE)
177 # define inline __inline
178 # else /* !inline && !__inline__ && !__inline */
179 # define inline /* don't inline, then */
180 # ifndef G_INLINE_FUNC
186 #ifndef G_INLINE_FUNC
189 # define G_INLINE_FUNC extern inline
192 # define G_INLINE_FUNC extern
194 # else /* !__GNUC__ */
196 # define G_INLINE_FUNC static inline
198 # define G_INLINE_FUNC extern
200 # endif /* !__GNUC__ */
201 #endif /* !G_INLINE_FUNC */
204 /* Provide simple macro statement wrappers (adapted from Perl):
205 * G_STMT_START { statements; } G_STMT_END;
206 * can be used as a single statement, as in
207 * if (x) G_STMT_START { ... } G_STMT_END; else ...
209 * For gcc we will wrap the statements within `({' and `})' braces.
210 * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
211 * and otherwise within `do' and `while (0)'.
213 #if !(defined (G_STMT_START) && defined (G_STMT_END))
214 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
215 # define G_STMT_START (void)(
216 # define G_STMT_END )
218 # if (defined (sun) || defined (__sun__))
219 # define G_STMT_START if (1)
220 # define G_STMT_END else (void)0
222 # define G_STMT_START do
223 # define G_STMT_END while (0)
229 /* Provide macros to feature the GCC function attribute.
231 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
232 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
233 __attribute__((format (printf, format_idx, arg_idx)))
234 #define G_GNUC_SCANF( format_idx, arg_idx ) \
235 __attribute__((format (scanf, format_idx, arg_idx)))
236 #define G_GNUC_FORMAT( arg_idx ) \
237 __attribute__((format_arg (arg_idx)))
238 #define G_GNUC_NORETURN \
239 __attribute__((noreturn))
240 #define G_GNUC_CONST \
241 __attribute__((const))
242 #define G_GNUC_UNUSED \
243 __attribute__((unused))
244 #else /* !__GNUC__ */
245 #define G_GNUC_PRINTF( format_idx, arg_idx )
246 #define G_GNUC_SCANF( format_idx, arg_idx )
247 #define G_GNUC_FORMAT( arg_idx )
248 #define G_GNUC_NORETURN
250 #define G_GNUC_UNUSED
251 #endif /* !__GNUC__ */
254 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
255 * macros, so we can refer to them as strings unconditionally.
258 #define G_GNUC_FUNCTION (__FUNCTION__)
259 #define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__)
260 #else /* !__GNUC__ */
261 #define G_GNUC_FUNCTION ("")
262 #define G_GNUC_PRETTY_FUNCTION ("")
263 #endif /* !__GNUC__ */
266 /* we try to provide a usefull equivalent for ATEXIT if it is
267 * not defined, but use is actually abandoned. people should
268 * use g_atexit() instead.
269 * keep this in sync with gutils.c.
273 # ifdef NeXT /* @#%@! NeXTStep */
274 # define ATEXIT(proc) (!atexit (proc))
276 # define ATEXIT(proc) (atexit (proc))
278 # elif defined (HAVE_ON_EXIT)
279 # define ATEXIT(proc) (on_exit ((void (*)(int, void *))(proc), NULL))
281 # error Could not determine proper atexit() implementation
284 # define G_NATIVE_ATEXIT
287 /* Hacker macro to place breakpoints for x86 machines.
288 * Actual use is strongly deprecated of course ;)
290 #if defined (__i386__) && defined (__GNUC__)
291 #define G_BREAKPOINT() G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
292 #else /* !__i386__ */
293 #define G_BREAKPOINT()
294 #endif /* __i386__ */
297 /* Provide macros for easily allocating memory. The macros
298 * will cast the allocated memory to the specified type
299 * in order to avoid compiler warnings. (Makes the code neater).
303 # define g_new(type, count) (ALLOC (type, count))
304 # define g_new0(type, count) (CALLOC (type, count))
305 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
306 #else /* __DMALLOC_H__ */
307 # define g_new(type, count) \
308 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
309 # define g_new0(type, count) \
310 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
311 # define g_renew(type, mem, count) \
312 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
313 #endif /* __DMALLOC_H__ */
315 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
316 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
318 sizeof (type) * (pre_alloc), \
321 #define g_chunk_new(type, chunk) ( \
322 (type *) g_mem_chunk_alloc (chunk) \
324 #define g_chunk_new0(type, chunk) ( \
325 (type *) g_mem_chunk_alloc0 (chunk) \
327 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
328 g_mem_chunk_free ((mem_chunk), (mem)); \
332 #define g_string(x) #x
335 /* Provide macros for error handling. The "assert" macros will
336 * exit on failure. The "return" macros will exit the current
337 * function. Two different definitions are given for the macros
338 * if G_DISABLE_ASSERT is not defined, in order to support gcc's
339 * __PRETTY_FUNCTION__ capability.
342 #ifdef G_DISABLE_ASSERT
344 #define g_assert(expr)
345 #define g_assert_not_reached()
347 #else /* !G_DISABLE_ASSERT */
351 #define g_assert(expr) G_STMT_START{ \
353 g_log (G_LOG_DOMAIN, \
355 "file %s: line %d (%s): assertion failed: (%s)", \
358 __PRETTY_FUNCTION__, \
361 #define g_assert_not_reached() G_STMT_START{ \
362 g_log (G_LOG_DOMAIN, \
364 "file %s: line %d (%s): should not be reached", \
367 __PRETTY_FUNCTION__); }G_STMT_END
369 #else /* !__GNUC__ */
371 #define g_assert(expr) G_STMT_START{ \
373 g_log (G_LOG_DOMAIN, \
375 "file %s: line %d: assertion failed: (%s)", \
380 #define g_assert_not_reached() G_STMT_START{ \
381 g_log (G_LOG_DOMAIN, \
383 "file %s: line %d: should not be reached", \
385 __LINE__); }G_STMT_END
387 #endif /* __GNUC__ */
389 #endif /* !G_DISABLE_ASSERT */
392 #ifdef G_DISABLE_CHECKS
394 #define g_return_if_fail(expr)
395 #define g_return_val_if_fail(expr,val)
397 #else /* !G_DISABLE_CHECKS */
401 #define g_return_if_fail(expr) G_STMT_START{ \
404 g_log (G_LOG_DOMAIN, \
405 G_LOG_LEVEL_CRITICAL, \
406 "file %s: line %d (%s): assertion `%s' failed.", \
409 __PRETTY_FUNCTION__, \
414 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
417 g_log (G_LOG_DOMAIN, \
418 G_LOG_LEVEL_CRITICAL, \
419 "file %s: line %d (%s): assertion `%s' failed.", \
422 __PRETTY_FUNCTION__, \
427 #else /* !__GNUC__ */
429 #define g_return_if_fail(expr) G_STMT_START{ \
432 g_log (G_LOG_DOMAIN, \
433 G_LOG_LEVEL_CRITICAL, \
434 "file %s: line %d: assertion `%s' failed.", \
441 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
444 g_log (G_LOG_DOMAIN, \
445 G_LOG_LEVEL_CRITICAL, \
446 "file %s: line %d: assertion `%s' failed.", \
453 #endif /* !__GNUC__ */
455 #endif /* !G_DISABLE_CHECKS */
458 /* Provide type definitions for commonly used types.
459 * These are useful because a "gint8" can be adjusted
460 * to be 1 byte (8 bits) on all platforms. Similarly and
461 * more importantly, "gint32" can be adjusted to be
462 * 4 bytes (32 bits) on all platforms.
466 typedef short gshort;
469 typedef gint gboolean;
471 typedef unsigned char guchar;
472 typedef unsigned short gushort;
473 typedef unsigned long gulong;
474 typedef unsigned int guint;
476 typedef float gfloat;
477 typedef double gdouble;
479 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
480 * Since gldouble isn't used anywhere, just disable it for now */
483 #ifdef HAVE_LONG_DOUBLE
484 typedef long double gldouble;
485 #else /* HAVE_LONG_DOUBLE */
486 typedef double gldouble;
487 #endif /* HAVE_LONG_DOUBLE */
490 typedef void* gpointer;
491 typedef const void *gconstpointer;
493 #if (SIZEOF_CHAR == 1)
494 typedef signed char gint8;
495 typedef unsigned char guint8;
496 #endif /* SIZEOF_CHAR */
498 #if (SIZEOF_SHORT == 2)
499 typedef signed short gint16;
500 typedef unsigned short guint16;
501 #endif /* SIZEOF_SHORT */
503 #if (SIZEOF_INT == 4)
504 typedef signed int gint32;
505 typedef unsigned int guint32;
506 #elif (SIZEOF_LONG == 4)
507 typedef signed long gint32;
508 typedef unsigned long guint32;
509 #endif /* SIZEOF_INT */
511 #if (SIZEOF_LONG == 8)
512 #define HAVE_GINT64 1
513 typedef signed long gint64;
514 typedef unsigned long guint64;
515 #elif (SIZEOF_LONG_LONG == 8)
516 #define HAVE_GINT64 1
517 typedef signed long long gint64;
518 typedef unsigned long long guint64;
525 /* Define macros for storing integers inside pointers
527 #if (SIZEOF_INT == SIZEOF_VOID_P)
529 #define GPOINTER_TO_INT(p) ((gint)(p))
530 #define GPOINTER_TO_UINT(p) ((guint)(p))
532 #define GINT_TO_POINTER(i) ((gpointer)(i))
533 #define GUINT_TO_POINTER(u) ((gpointer)(u))
535 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
537 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
538 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
540 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
541 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
544 #error SIZEOF_VOID_P unknown - This should never happen
547 typedef gint32 gssize;
548 typedef guint32 gsize;
549 typedef guint32 GQuark;
550 typedef gint32 GTime;
555 extern const guint glib_major_version;
556 extern const guint glib_minor_version;
557 extern const guint glib_micro_version;
558 extern const guint glib_interface_age;
559 extern const guint glib_binary_age;
562 /* Forward declarations of glib types.
565 typedef struct _GArray GArray;
566 typedef struct _GByteArray GByteArray;
567 typedef struct _GCache GCache;
568 typedef struct _GCompletion GCompletion;
569 typedef struct _GData GData;
570 typedef struct _GDebugKey GDebugKey;
571 typedef struct _GHashTable GHashTable;
572 typedef struct _GHook GHook;
573 typedef struct _GHookList GHookList;
574 typedef struct _GList GList;
575 typedef struct _GListAllocator GListAllocator;
576 typedef struct _GMemChunk GMemChunk;
577 typedef struct _GNode GNode;
578 typedef struct _GPtrArray GPtrArray;
579 typedef struct _GRelation GRelation;
580 typedef struct _GScanner GScanner;
581 typedef struct _GScannerConfig GScannerConfig;
582 typedef struct _GSList GSList;
583 typedef struct _GString GString;
584 typedef struct _GStringChunk GStringChunk;
585 typedef struct _GTimer GTimer;
586 typedef struct _GTree GTree;
587 typedef struct _GTuples GTuples;
588 typedef union _GTokenValue GTokenValue;
593 G_TRAVERSE_LEAFS = 1 << 0,
594 G_TRAVERSE_NON_LEAFS = 1 << 1,
595 G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
596 G_TRAVERSE_MASK = 0x03
607 /* Log level shift offset for user defined
608 * log levels (0-7 are used by GLib).
610 #define G_LOG_LEVEL_USER_SHIFT (8)
612 /* Glib log levels and flags.
617 G_LOG_FLAG_RECURSION = 1 << 0,
618 G_LOG_FLAG_FATAL = 1 << 1,
620 /* GLib log levels */
621 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
622 G_LOG_LEVEL_CRITICAL = 1 << 3,
623 G_LOG_LEVEL_WARNING = 1 << 4,
624 G_LOG_LEVEL_MESSAGE = 1 << 5,
625 G_LOG_LEVEL_INFO = 1 << 6,
626 G_LOG_LEVEL_DEBUG = 1 << 7,
628 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
631 /* GLib log levels that are considered fatal by default */
632 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
635 typedef gpointer (*GCacheNewFunc) (gpointer key);
636 typedef gpointer (*GCacheDupFunc) (gpointer value);
637 typedef void (*GCacheDestroyFunc) (gpointer value);
638 typedef gint (*GCompareFunc) (gconstpointer a,
640 typedef gchar* (*GCompletionFunc) (gpointer);
641 typedef void (*GDestroyNotify) (gpointer data);
642 typedef void (*GDataForeachFunc) (GQuark key_id,
645 typedef void (*GFunc) (gpointer data,
647 typedef guint (*GHashFunc) (gconstpointer key);
648 typedef void (*GHFunc) (gpointer key,
651 typedef gboolean (*GHRFunc) (gpointer key,
654 typedef gint (*GHookCompareFunc) (GHook *new_hook,
656 typedef gboolean (*GHookFindFunc) (GHook *hook,
658 typedef void (*GHookMarshaller) (GHook *hook,
660 typedef void (*GHookFunc) (gpointer data);
661 typedef gboolean (*GHookCheckFunc) (gpointer data);
662 typedef void (*GLogFunc) (const gchar *log_domain,
663 GLogLevelFlags log_level,
664 const gchar *message,
666 typedef gboolean (*GNodeTraverseFunc) (GNode *node,
668 typedef void (*GNodeForeachFunc) (GNode *node,
670 typedef gint (*GSearchFunc) (gpointer key,
672 typedef void (*GScannerMsgFunc) (GScanner *scanner,
675 typedef gint (*GTraverseFunc) (gpointer key,
678 typedef void (*GVoidFunc) (void);
729 struct _GCache { gint dummy; };
730 struct _GTree { gint dummy; };
731 struct _GTimer { gint dummy; };
732 struct _GMemChunk { gint dummy; };
733 struct _GListAllocator { gint dummy; };
734 struct _GStringChunk { gint dummy; };
737 /* Doubly linked lists
739 GList* g_list_alloc (void);
740 void g_list_free (GList *list);
741 void g_list_free_1 (GList *list);
742 GList* g_list_append (GList *list,
744 GList* g_list_prepend (GList *list,
746 GList* g_list_insert (GList *list,
749 GList* g_list_insert_sorted (GList *list,
752 GList* g_list_concat (GList *list1,
754 GList* g_list_remove (GList *list,
756 GList* g_list_remove_link (GList *list,
758 GList* g_list_reverse (GList *list);
759 GList* g_list_nth (GList *list,
761 GList* g_list_find (GList *list,
763 GList* g_list_find_custom (GList *list,
766 gint g_list_position (GList *list,
768 gint g_list_index (GList *list,
770 GList* g_list_last (GList *list);
771 GList* g_list_first (GList *list);
772 guint g_list_length (GList *list);
773 void g_list_foreach (GList *list,
776 gpointer g_list_nth_data (GList *list,
778 #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
779 #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
782 /* Singly linked lists
784 GSList* g_slist_alloc (void);
785 void g_slist_free (GSList *list);
786 void g_slist_free_1 (GSList *list);
787 GSList* g_slist_append (GSList *list,
789 GSList* g_slist_prepend (GSList *list,
791 GSList* g_slist_insert (GSList *list,
794 GSList* g_slist_insert_sorted (GSList *list,
797 GSList* g_slist_concat (GSList *list1,
799 GSList* g_slist_remove (GSList *list,
801 GSList* g_slist_remove_link (GSList *list,
803 GSList* g_slist_reverse (GSList *list);
804 GSList* g_slist_nth (GSList *list,
806 GSList* g_slist_find (GSList *list,
808 GSList* g_slist_find_custom (GSList *list,
811 gint g_slist_position (GSList *list,
813 gint g_slist_index (GSList *list,
815 GSList* g_slist_last (GSList *list);
816 guint g_slist_length (GSList *list);
817 void g_slist_foreach (GSList *list,
820 gpointer g_slist_nth_data (GSList *list,
822 #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
827 GListAllocator* g_list_allocator_new (void);
828 void g_list_allocator_free (GListAllocator* allocator);
829 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
830 GListAllocator* g_list_set_allocator (GListAllocator* allocator);
835 GHashTable* g_hash_table_new (GHashFunc hash_func,
836 GCompareFunc key_compare_func);
837 void g_hash_table_destroy (GHashTable *hash_table);
838 void g_hash_table_insert (GHashTable *hash_table,
841 void g_hash_table_remove (GHashTable *hash_table,
843 gpointer g_hash_table_lookup (GHashTable *hash_table,
845 gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
846 gconstpointer lookup_key,
849 void g_hash_table_freeze (GHashTable *hash_table);
850 void g_hash_table_thaw (GHashTable *hash_table);
851 void g_hash_table_foreach (GHashTable *hash_table,
854 gint g_hash_table_foreach_remove (GHashTable *hash_table,
857 gint g_hash_table_size (GHashTable *hash_table);
862 GCache* g_cache_new (GCacheNewFunc value_new_func,
863 GCacheDestroyFunc value_destroy_func,
864 GCacheDupFunc key_dup_func,
865 GCacheDestroyFunc key_destroy_func,
866 GHashFunc hash_key_func,
867 GHashFunc hash_value_func,
868 GCompareFunc key_compare_func);
869 void g_cache_destroy (GCache *cache);
870 gpointer g_cache_insert (GCache *cache,
872 void g_cache_remove (GCache *cache,
874 void g_cache_key_foreach (GCache *cache,
877 void g_cache_value_foreach (GCache *cache,
882 /* Balanced binary trees
884 GTree* g_tree_new (GCompareFunc key_compare_func);
885 void g_tree_destroy (GTree *tree);
886 void g_tree_insert (GTree *tree,
889 void g_tree_remove (GTree *tree,
891 gpointer g_tree_lookup (GTree *tree,
893 void g_tree_traverse (GTree *tree,
894 GTraverseFunc traverse_func,
895 GTraverseType traverse_type,
897 gpointer g_tree_search (GTree *tree,
898 GSearchFunc search_func,
900 gint g_tree_height (GTree *tree);
901 gint g_tree_nnodes (GTree *tree);
905 /* N-way tree implementation
916 #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
917 ((GNode*) (node))->prev == NULL && \
918 ((GNode*) (node))->next == NULL)
919 #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
921 GNode* g_node_new (gpointer data);
922 void g_node_destroy (GNode *root);
923 void g_node_unlink (GNode *node);
924 GNode* g_node_insert (GNode *parent,
927 GNode* g_node_insert_before (GNode *parent,
930 GNode* g_node_prepend (GNode *parent,
932 guint g_node_n_nodes (GNode *root,
933 GTraverseFlags flags);
934 GNode* g_node_get_root (GNode *node);
935 gboolean g_node_is_ancestor (GNode *node,
937 guint g_node_depth (GNode *node);
938 GNode* g_node_find (GNode *root,
940 GTraverseFlags flags,
943 /* convenience macros */
944 #define g_node_append(parent, node) \
945 g_node_insert_before ((parent), NULL, (node))
946 #define g_node_insert_data(parent, position, data) \
947 g_node_insert ((parent), (position), g_node_new (data))
948 #define g_node_insert_data_before(parent, sibling, data) \
949 g_node_insert_before ((parent), (sibling), g_node_new (data))
950 #define g_node_prepend_data(parent, data) \
951 g_node_prepend ((parent), g_node_new (data))
952 #define g_node_append_data(parent, data) \
953 g_node_insert_before ((parent), NULL, g_node_new (data))
955 /* traversal function, assumes that `node' is root
956 * (only traverses `node' and its subtree).
957 * this function is just a high level interface to
958 * low level traversal functions, optimized for speed.
960 void g_node_traverse (GNode *root,
962 GTraverseFlags flags,
964 GNodeTraverseFunc func,
967 /* return the maximum tree height starting with `node', this is an expensive
968 * operation, since we need to visit all nodes. this could be shortened by
969 * adding `guint height' to struct _GNode, but then again, this is not very
970 * often needed, and would make g_node_insert() more time consuming.
972 guint g_node_max_height (GNode *root);
974 void g_node_children_foreach (GNode *node,
975 GTraverseFlags flags,
976 GNodeForeachFunc func,
978 void g_node_reverse_children (GNode *node);
979 guint g_node_n_children (GNode *node);
980 GNode* g_node_nth_child (GNode *node,
982 GNode* g_node_last_child (GNode *node);
983 GNode* g_node_find_child (GNode *node,
984 GTraverseFlags flags,
986 gint g_node_child_position (GNode *node,
988 gint g_node_child_index (GNode *node,
991 GNode* g_node_first_sibling (GNode *node);
992 GNode* g_node_last_sibling (GNode *node);
994 #define g_node_prev_sibling(node) ((node) ? \
995 ((GNode*) (node))->prev : NULL)
996 #define g_node_next_sibling(node) ((node) ? \
997 ((GNode*) (node))->next : NULL)
998 #define g_node_first_child(node) ((node) ? \
999 ((GNode*) (node))->children : NULL)
1002 /* Callback maintenance functions
1004 #define G_HOOK_FLAG_USER_SHIFT (4)
1007 G_HOOK_FLAG_ACTIVE = 1 << 0,
1008 G_HOOK_FLAG_IN_CALL = 1 << 1,
1009 G_HOOK_FLAG_MASK = 0x0f
1018 GMemChunk *hook_memchunk;
1030 GDestroyNotify destroy;
1033 #define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \
1034 G_HOOK_FLAG_ACTIVE) != 0)
1035 #define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \
1036 G_HOOK_FLAG_IN_CALL) != 0)
1037 #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
1038 G_HOOK_ACTIVE (hook))
1039 #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
1040 ((GHook*) hook)->prev == NULL && \
1041 ((GHook*) hook)->hook_id == 0 && \
1042 ((GHook*) hook)->ref_count == 0)
1044 void g_hook_list_init (GHookList *hook_list,
1046 void g_hook_list_clear (GHookList *hook_list);
1047 GHook* g_hook_alloc (GHookList *hook_list);
1048 void g_hook_free (GHookList *hook_list,
1050 void g_hook_ref (GHookList *hook_list,
1052 void g_hook_unref (GHookList *hook_list,
1054 gboolean g_hook_destroy (GHookList *hook_list,
1056 void g_hook_destroy_link (GHookList *hook_list,
1058 void g_hook_prepend (GHookList *hook_list,
1060 void g_hook_insert_before (GHookList *hook_list,
1063 void g_hook_insert_sorted (GHookList *hook_list,
1065 GHookCompareFunc func);
1066 GHook* g_hook_get (GHookList *hook_list,
1068 GHook* g_hook_find (GHookList *hook_list,
1069 gboolean need_valids,
1072 GHook* g_hook_find_data (GHookList *hook_list,
1073 gboolean need_valids,
1075 GHook* g_hook_find_func (GHookList *hook_list,
1076 gboolean need_valids,
1078 GHook* g_hook_find_func_data (GHookList *hook_list,
1079 gboolean need_valids,
1082 GHook* g_hook_first_valid (GHookList *hook_list,
1083 gboolean may_be_in_call);
1084 GHook* g_hook_next_valid (GHook *hook,
1085 gboolean may_be_in_call);
1087 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1088 gint g_hook_compare_ids (GHook *new_hook,
1091 /* convenience macros */
1092 #define g_hook_append( hook_list, hook ) \
1093 g_hook_insert_before ((hook_list), NULL, (hook))
1095 /* invoke all valid hooks with the (*GHookFunc) signature.
1097 void g_hook_list_invoke (GHookList *hook_list,
1098 gboolean may_recurse);
1099 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1100 * and destroy the hook if FALSE is returned.
1102 void g_hook_list_invoke_check (GHookList *hook_list,
1103 gboolean may_recurse);
1104 /* invoke a marshaller on all valid hooks.
1106 void g_hook_list_marshal (GHookList *hook_list,
1107 gboolean may_recurse,
1108 GHookMarshaller marshaller,
1112 /* Fatal error handlers.
1113 * g_on_error_query() will prompt the user to either
1114 * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1115 * g_on_error_stack_trace() invokes gdb, which attaches to the current
1116 * process and shows a stack trace.
1117 * These function may cause different actions on non-unix platforms.
1118 * The prg_name arg is required by gdb to find the executable, if it is
1119 * passed as NULL, g_on_error_query() will try g_get_prgname().
1121 void g_on_error_query (const gchar *prg_name);
1122 void g_on_error_stack_trace (const gchar *prg_name);
1125 /* Logging mechanism
1127 extern const gchar *g_log_domain_glib;
1128 guint g_log_set_handler (const gchar *log_domain,
1129 GLogLevelFlags log_levels,
1131 gpointer user_data);
1132 void g_log_remove_handler (const gchar *log_domain,
1134 void g_log_default_handler (const gchar *log_domain,
1135 GLogLevelFlags log_level,
1136 const gchar *message,
1137 gpointer unused_data);
1138 void g_log (const gchar *log_domain,
1139 GLogLevelFlags log_level,
1140 const gchar *format,
1141 ...) G_GNUC_PRINTF (3, 4);
1142 void g_logv (const gchar *log_domain,
1143 GLogLevelFlags log_level,
1144 const gchar *format,
1146 GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
1147 GLogLevelFlags fatal_mask);
1148 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
1149 #ifndef G_LOG_DOMAIN
1150 #define G_LOG_DOMAIN (NULL)
1151 #endif /* G_LOG_DOMAIN */
1153 #define g_error(format, args...) g_log (G_LOG_DOMAIN, \
1154 G_LOG_LEVEL_ERROR, \
1156 #define g_message(format, args...) g_log (G_LOG_DOMAIN, \
1157 G_LOG_LEVEL_MESSAGE, \
1159 #define g_warning(format, args...) g_log (G_LOG_DOMAIN, \
1160 G_LOG_LEVEL_WARNING, \
1162 #else /* !__GNUC__ */
1164 g_error (const gchar *format,
1168 va_start (args, format);
1169 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1173 g_message (const gchar *format,
1177 va_start (args, format);
1178 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1182 g_warning (const gchar *format,
1186 va_start (args, format);
1187 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1190 #endif /* !__GNUC__ */
1192 typedef void (*GPrintFunc) (const gchar *string);
1193 void g_print (const gchar *format,
1194 ...) G_GNUC_PRINTF (1, 2);
1195 GPrintFunc g_set_print_handler (GPrintFunc func);
1196 void g_printerr (const gchar *format,
1197 ...) G_GNUC_PRINTF (1, 2);
1198 GPrintFunc g_set_printerr_handler (GPrintFunc func);
1200 /* deprecated compatibility functions, use g_log_set_handler() instead */
1201 typedef void (*GErrorFunc) (const gchar *str);
1202 typedef void (*GWarningFunc) (const gchar *str);
1203 GErrorFunc g_set_error_handler (GErrorFunc func);
1204 GWarningFunc g_set_warning_handler (GWarningFunc func);
1205 GPrintFunc g_set_message_handler (GPrintFunc func);
1208 /* Memory allocation and debugging
1212 #define g_malloc(size) ((gpointer) MALLOC (size))
1213 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
1214 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
1215 #define g_free(mem) FREE (mem)
1217 #else /* !USE_DMALLOC */
1219 gpointer g_malloc (gulong size);
1220 gpointer g_malloc0 (gulong size);
1221 gpointer g_realloc (gpointer mem,
1223 void g_free (gpointer mem);
1225 #endif /* !USE_DMALLOC */
1227 void g_mem_profile (void);
1228 void g_mem_check (gpointer mem);
1231 /* "g_mem_chunk_new" creates a new memory chunk.
1232 * Memory chunks are used to allocate pieces of memory which are
1233 * always the same size. Lists are a good example of such a data type.
1234 * The memory chunk allocates and frees blocks of memory as needed.
1235 * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1236 * allocated in a mem chunk. ("g_free" will most likely cause a seg
1237 * fault...somewhere).
1239 * Oh yeah, GMemChunk is an opaque data type. (You don't really
1240 * want to know what's going on inside do you?)
1243 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1244 * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1245 * atom. (They are also useful for lists which use MemChunk to allocate
1246 * memory but are also part of the MemChunk implementation).
1247 * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1250 #define G_ALLOC_ONLY 1
1251 #define G_ALLOC_AND_FREE 2
1253 GMemChunk* g_mem_chunk_new (gchar *name,
1257 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
1258 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
1259 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
1260 void g_mem_chunk_free (GMemChunk *mem_chunk,
1262 void g_mem_chunk_clean (GMemChunk *mem_chunk);
1263 void g_mem_chunk_reset (GMemChunk *mem_chunk);
1264 void g_mem_chunk_print (GMemChunk *mem_chunk);
1265 void g_mem_chunk_info (void);
1267 /* Ah yes...we have a "g_blow_chunks" function.
1268 * "g_blow_chunks" simply compresses all the chunks. This operation
1269 * consists of freeing every memory area that should be freed (but
1270 * which we haven't gotten around to doing yet). And, no,
1271 * "g_blow_chunks" doesn't follow the naming scheme, but it is a
1272 * much better name than "g_mem_chunk_clean_all" or something
1275 void g_blow_chunks (void);
1280 GTimer* g_timer_new (void);
1281 void g_timer_destroy (GTimer *timer);
1282 void g_timer_start (GTimer *timer);
1283 void g_timer_stop (GTimer *timer);
1284 void g_timer_reset (GTimer *timer);
1285 gdouble g_timer_elapsed (GTimer *timer,
1286 gulong *microseconds);
1289 /* String utility functions
1291 #define G_STR_DELIMITERS "_-|> <."
1292 void g_strdelimit (gchar *string,
1293 const gchar *delimiters,
1294 gchar new_delimiter);
1295 gchar* g_strdup (const gchar *str);
1296 gchar* g_strdup_printf (const gchar *format,
1297 ...) G_GNUC_PRINTF (1, 2);
1298 gchar* g_strdup_vprintf (const gchar *format,
1300 gchar* g_strndup (const gchar *str,
1302 gchar* g_strnfill (guint length,
1304 gchar* g_strconcat (const gchar *string1,
1305 ...); /* NULL terminated */
1306 gdouble g_strtod (const gchar *nptr,
1308 gchar* g_strerror (gint errnum);
1309 gchar* g_strsignal (gint signum);
1310 gint g_strcasecmp (const gchar *s1,
1312 void g_strdown (gchar *string);
1313 void g_strup (gchar *string);
1314 void g_strreverse (gchar *string);
1315 gpointer g_memdup (gconstpointer mem,
1318 /* calculate a string size, guarranteed to fit format + args.
1320 guint g_printf_string_upper_bound (const gchar* format,
1324 /* Retrive static string info
1326 gchar* g_get_user_name (void);
1327 gchar* g_get_real_name (void);
1328 gchar* g_get_home_dir (void);
1329 gchar* g_get_tmp_dir (void);
1330 gchar* g_get_prgname (void);
1331 void g_set_prgname (const gchar *prgname);
1334 /* Miscellaneous utility functions
1336 guint g_parse_debug_string (const gchar *string,
1339 gint g_snprintf (gchar *string,
1341 gchar const *format,
1342 ...) G_GNUC_PRINTF (3, 4);
1343 gint g_vsnprintf (gchar *string,
1345 gchar const *format,
1347 gchar* g_basename (const gchar *file_name);
1349 /* strings are newly allocated with g_malloc() */
1350 gchar* g_dirname (const gchar *file_name);
1351 gchar* g_get_current_dir (void);
1353 /* We make the assumption that if memmove isn't available, then
1354 * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1355 * necessarily handle overlapping copies).
1356 * Either way, g_memmove() will not return a value.
1359 #define g_memmove(dest, src, size) G_STMT_START { \
1360 memmove ((dest), (src), (size)); \
1363 #define g_memmove(dest, src, size) G_STMT_START { \
1364 bcopy ((src), (dest), (size)); \
1368 /* we use a GLib function as a replacement for ATEXIT, so
1369 * the programmer is not required to check the return value
1370 * (if there is any in the implementation) and doesn't encounter
1371 * missing include files.
1373 void g_atexit (GVoidFunc func);
1378 G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
1382 g_bit_nth_lsf (guint32 mask,
1388 if (mask & (1 << (guint) nth_bit))
1391 while (nth_bit < 32);
1394 #endif /* G_CAN_INLINE */
1396 G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
1400 g_bit_nth_msf (guint32 mask,
1408 if (mask & (1 << (guint) nth_bit))
1411 while (nth_bit > 0);
1414 #endif /* G_CAN_INLINE */
1416 G_INLINE_FUNC guint g_bit_storage (guint number);
1419 g_bit_storage (guint number)
1421 register guint n_bits = 0;
1431 #endif /* G_CAN_INLINE */
1436 GStringChunk* g_string_chunk_new (gint size);
1437 void g_string_chunk_free (GStringChunk *chunk);
1438 gchar* g_string_chunk_insert (GStringChunk *chunk,
1439 const gchar *string);
1440 gchar* g_string_chunk_insert_const (GStringChunk *chunk,
1441 const gchar *string);
1446 GString* g_string_new (const gchar *init);
1447 GString* g_string_sized_new (guint dfl_size);
1448 void g_string_free (GString *string,
1450 GString* g_string_assign (GString *lval,
1452 GString* g_string_truncate (GString *string,
1454 GString* g_string_append (GString *string,
1456 GString* g_string_append_c (GString *string,
1458 GString* g_string_prepend (GString *string,
1460 GString* g_string_prepend_c (GString *string,
1462 GString* g_string_insert (GString *string,
1465 GString* g_string_insert_c (GString *string,
1468 GString* g_string_erase (GString *string,
1471 GString* g_string_down (GString *string);
1472 GString* g_string_up (GString *string);
1473 void g_string_sprintf (GString *string,
1474 const gchar *format,
1475 ...) G_GNUC_PRINTF (2, 3);
1476 void g_string_sprintfa (GString *string,
1477 const gchar *format,
1478 ...) G_GNUC_PRINTF (2, 3);
1484 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1485 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1486 #define g_array_index(a,t,i) (((t*)a->data)[i])
1488 GArray* g_array_new (gboolean zero_terminated,
1490 guint element_size);
1491 void g_array_free (GArray *array,
1492 gboolean free_segment);
1493 GArray* g_array_append_vals (GArray *array,
1496 GArray* g_array_prepend_vals (GArray *array,
1499 GArray* g_array_set_size (GArray *array,
1502 /* Resizable pointer array. This interface is much less complicated
1503 * than the above. Add appends appends a pointer. Remove fills any
1504 * cleared spot and shortens the array.
1506 #define g_ptr_array_index(array,index) (array->pdata)[index]
1507 GPtrArray* g_ptr_array_new (void);
1508 void g_ptr_array_free (GPtrArray *array,
1510 void g_ptr_array_set_size (GPtrArray *array,
1512 gpointer g_ptr_array_remove_index (GPtrArray *array,
1514 gboolean g_ptr_array_remove (GPtrArray *array,
1516 void g_ptr_array_add (GPtrArray *array,
1519 /* Byte arrays, an array of guint8. Implemented as a GArray,
1523 GByteArray* g_byte_array_new (void);
1524 void g_byte_array_free (GByteArray *array,
1525 gboolean free_segment);
1526 GByteArray* g_byte_array_append (GByteArray *array,
1529 GByteArray* g_byte_array_prepend (GByteArray *array,
1532 GByteArray* g_byte_array_set_size (GByteArray *array,
1538 gint g_str_equal (gconstpointer v,
1540 guint g_str_hash (gconstpointer v);
1542 gint g_int_equal (gconstpointer v,
1544 guint g_int_hash (gconstpointer v);
1546 /* This "hash" function will just return the key's adress as an
1547 * unsigned integer. Useful for hashing on plain adresses or
1548 * simple integer values.
1550 guint g_direct_hash (gconstpointer v);
1551 gint g_direct_equal (gconstpointer v,
1555 /* Quarks (string<->id association)
1557 GQuark g_quark_try_string (const gchar *string);
1558 GQuark g_quark_from_static_string (const gchar *string);
1559 GQuark g_quark_from_string (const gchar *string);
1560 gchar* g_quark_to_string (GQuark quark);
1565 void g_datalist_init (GData **datalist);
1566 void g_datalist_clear (GData **datalist);
1567 gpointer g_datalist_id_get_data (GData **datalist,
1569 void g_datalist_id_set_data_full (GData **datalist,
1572 GDestroyNotify destroy_func);
1573 void g_datalist_id_remove_no_notify (GData **datalist,
1575 void g_datalist_foreach (GData **datalist,
1576 GDataForeachFunc func,
1577 gpointer user_data);
1578 #define g_datalist_id_set_data(dl, q, d) \
1579 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1580 #define g_datalist_id_remove_data(dl, q) \
1581 g_datalist_id_set_data ((dl), (q), NULL)
1582 #define g_datalist_get_data(dl, k) \
1583 (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1584 #define g_datalist_set_data_full(dl, k, d, f) \
1585 g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1586 #define g_datalist_remove_no_notify(dl, k) \
1587 g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1588 #define g_datalist_set_data(dl, k, d) \
1589 g_datalist_set_data_full ((dl), (k), (d), NULL)
1590 #define g_datalist_remove_data(dl, k) \
1591 g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1594 /* Location Associated Keyed Data
1596 void g_dataset_destroy (gconstpointer dataset_location);
1597 gpointer g_dataset_id_get_data (gconstpointer dataset_location,
1599 void g_dataset_id_set_data_full (gconstpointer dataset_location,
1602 GDestroyNotify destroy_func);
1603 void g_dataset_id_remove_no_notify (gconstpointer dataset_location,
1605 void g_dataset_foreach (gconstpointer dataset_location,
1606 GDataForeachFunc func,
1607 gpointer user_data);
1608 #define g_dataset_id_set_data(l, k, d) \
1609 g_dataset_id_set_data_full ((l), (k), (d), NULL)
1610 #define g_dataset_id_remove_data(l, k) \
1611 g_dataset_id_set_data ((l), (k), NULL)
1612 #define g_dataset_get_data(l, k) \
1613 (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1614 #define g_dataset_set_data_full(l, k, d, f) \
1615 g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1616 #define g_dataset_remove_no_notify(l, k) \
1617 g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1618 #define g_dataset_set_data(l, k, d) \
1619 g_dataset_set_data_full ((l), (k), (d), NULL)
1620 #define g_dataset_remove_data(l, k) \
1621 g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1624 /* GScanner: Flexible lexical scanner for general purpose.
1627 /* Character sets */
1628 #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1629 #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
1630 #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
1631 "\307\310\311\312\313\314\315\316\317\320"\
1632 "\321\322\323\324\325\326"\
1633 "\330\331\332\333\334\335\336"
1634 #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
1635 "\347\350\351\352\353\354\355\356\357\360"\
1636 "\361\362\363\364\365\366"\
1637 "\370\371\372\373\374\375\376\377"
1644 G_ERR_UNEXP_EOF_IN_STRING,
1645 G_ERR_UNEXP_EOF_IN_COMMENT,
1646 G_ERR_NON_DIGIT_IN_CONST,
1649 G_ERR_FLOAT_MALFORMED
1657 G_TOKEN_LEFT_PAREN = '(',
1658 G_TOKEN_RIGHT_PAREN = ')',
1659 G_TOKEN_LEFT_CURLY = '{',
1660 G_TOKEN_RIGHT_CURLY = '}',
1661 G_TOKEN_LEFT_BRACE = '[',
1662 G_TOKEN_RIGHT_BRACE = ']',
1663 G_TOKEN_EQUAL_SIGN = '=',
1664 G_TOKEN_COMMA = ',',
1680 G_TOKEN_IDENTIFIER_NULL,
1682 G_TOKEN_COMMENT_SINGLE,
1683 G_TOKEN_COMMENT_MULTI,
1690 gchar *v_identifier;
1702 struct _GScannerConfig
1706 gchar *cset_skip_characters; /* default: " \t\n" */
1707 gchar *cset_identifier_first;
1708 gchar *cset_identifier_nth;
1709 gchar *cpair_comment_single; /* default: "#\n" */
1711 /* Should symbol lookup work case sensitive?
1713 guint case_sensitive : 1;
1715 /* Boolean values to be adjusted "on the fly"
1716 * to configure scanning behaviour.
1718 guint skip_comment_multi : 1; /* C like comment */
1719 guint skip_comment_single : 1; /* single line comment */
1720 guint scan_comment_multi : 1; /* scan multi line comments? */
1721 guint scan_identifier : 1;
1722 guint scan_identifier_1char : 1;
1723 guint scan_identifier_NULL : 1;
1724 guint scan_symbols : 1;
1725 guint scan_binary : 1;
1726 guint scan_octal : 1;
1727 guint scan_float : 1;
1728 guint scan_hex : 1; /* `0x0ff0' */
1729 guint scan_hex_dollar : 1; /* `$0ff0' */
1730 guint scan_string_sq : 1; /* string: 'anything' */
1731 guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
1732 guint numbers_2_int : 1; /* bin, octal, hex => int */
1733 guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
1734 guint identifier_2_string : 1;
1735 guint char_2_token : 1; /* return G_TOKEN_CHAR? */
1736 guint symbol_2_token : 1;
1737 guint scope_0_fallback : 1; /* try scope 0 on lookups? */
1744 guint max_parse_errors;
1746 /* g_scanner_error() increments this field */
1749 /* name of input stream, featured by the default message handler */
1750 const gchar *input_name;
1752 /* data pointer for derived structures */
1753 gpointer derived_data;
1755 /* link into the scanner configuration */
1756 GScannerConfig *config;
1758 /* fields filled in after g_scanner_get_next_token() */
1764 /* fields filled in after g_scanner_peek_next_token() */
1765 GTokenType next_token;
1766 GTokenValue next_value;
1768 guint next_position;
1770 /* to be considered private */
1771 GHashTable *symbol_table;
1774 const gchar *text_end;
1778 /* handler function for _warn and _error */
1779 GScannerMsgFunc msg_handler;
1782 GScanner* g_scanner_new (GScannerConfig *config_templ);
1783 void g_scanner_destroy (GScanner *scanner);
1784 void g_scanner_input_file (GScanner *scanner,
1786 void g_scanner_input_text (GScanner *scanner,
1789 GTokenType g_scanner_get_next_token (GScanner *scanner);
1790 GTokenType g_scanner_peek_next_token (GScanner *scanner);
1791 GTokenType g_scanner_cur_token (GScanner *scanner);
1792 GTokenValue g_scanner_cur_value (GScanner *scanner);
1793 guint g_scanner_cur_line (GScanner *scanner);
1794 guint g_scanner_cur_position (GScanner *scanner);
1795 gboolean g_scanner_eof (GScanner *scanner);
1796 guint g_scanner_set_scope (GScanner *scanner,
1798 void g_scanner_scope_add_symbol (GScanner *scanner,
1800 const gchar *symbol,
1802 void g_scanner_scope_remove_symbol (GScanner *scanner,
1804 const gchar *symbol);
1805 gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
1807 const gchar *symbol);
1808 void g_scanner_scope_foreach_symbol (GScanner *scanner,
1811 gpointer func_data);
1812 gpointer g_scanner_lookup_symbol (GScanner *scanner,
1813 const gchar *symbol);
1814 void g_scanner_freeze_symbol_table (GScanner *scanner);
1815 void g_scanner_thaw_symbol_table (GScanner *scanner);
1816 void g_scanner_unexp_token (GScanner *scanner,
1817 GTokenType expected_token,
1818 const gchar *identifier_spec,
1819 const gchar *symbol_spec,
1820 const gchar *symbol_name,
1821 const gchar *message,
1823 void g_scanner_error (GScanner *scanner,
1824 const gchar *format,
1825 ...) G_GNUC_PRINTF (2,3);
1826 void g_scanner_warn (GScanner *scanner,
1827 const gchar *format,
1828 ...) G_GNUC_PRINTF (2,3);
1829 gint g_scanner_stat_mode (const gchar *filename);
1830 /* keep downward source compatibility */
1831 #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
1832 g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1834 #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
1835 g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1837 #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1838 g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1847 GCompletionFunc func;
1853 GCompletion* g_completion_new (GCompletionFunc func);
1854 void g_completion_add_items (GCompletion* cmp,
1856 void g_completion_remove_items (GCompletion* cmp,
1858 void g_completion_clear_items (GCompletion* cmp);
1859 GList* g_completion_complete (GCompletion* cmp,
1861 gchar** new_prefix);
1862 void g_completion_free (GCompletion* cmp);
1865 /* GRelation: Indexed Relations. Imagine a really simple table in a
1866 * database. Relations are not ordered. This data type is meant for
1867 * maintaining a N-way mapping.
1869 * g_relation_new() creates a relation with FIELDS fields
1871 * g_relation_destroy() frees all resources
1872 * g_tuples_destroy() frees the result of g_relation_select()
1874 * g_relation_index() indexes relation FIELD with the provided
1875 * equality and hash functions. this must be done before any
1876 * calls to insert are made.
1878 * g_relation_insert() inserts a new tuple. you are expected to
1879 * provide the right number of fields.
1881 * g_relation_delete() deletes all relations with KEY in FIELD
1882 * g_relation_select() returns ...
1883 * g_relation_count() counts ...
1886 GRelation* g_relation_new (gint fields);
1887 void g_relation_destroy (GRelation *relation);
1888 void g_relation_index (GRelation *relation,
1890 GHashFunc hash_func,
1891 GCompareFunc key_compare_func);
1892 void g_relation_insert (GRelation *relation,
1894 gint g_relation_delete (GRelation *relation,
1897 GTuples* g_relation_select (GRelation *relation,
1900 gint g_relation_count (GRelation *relation,
1903 gboolean g_relation_exists (GRelation *relation,
1905 void g_relation_print (GRelation *relation);
1907 void g_tuples_destroy (GTuples *tuples);
1908 gpointer g_tuples_index (GTuples *tuples,
1916 /* This function returns prime numbers spaced by approximately 1.5-2.0
1917 * and is for use in resizing data structures which prefer
1918 * prime-valued sizes. The closest spaced prime function returns the
1919 * next largest prime, or the highest it knows about which is about
1923 guint g_spaced_primes_closest (guint num);
1927 extern const guint glib_major_version;
1928 extern const guint glib_minor_version;
1929 extern const guint glib_micro_version;
1933 #endif /* __cplusplus */
1936 #endif /* __G_LIB_H__ */