added ghook.c.
[platform/upstream/glib.git] / glib / glib.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19 #ifndef __G_LIB_H__
20 #define __G_LIB_H__
21
22 /* system specific config file
23  */
24 #include <glibconfig.h>
25
26 /* include varargs functions for assertment macros
27  */
28 #include <stdarg.h>
29
30 /* optionally feature DMALLOC memory allocation debugger
31  */
32 #ifdef USE_DMALLOC
33 #include "dmalloc.h"
34 #endif
35
36
37 /* glib provides definitions for the extrema of many
38  *  of the standard types. These are:
39  * G_MINFLOAT
40  * G_MAXFLOAT
41  * G_MINDOUBLE
42  * G_MAXDOUBLE
43  * G_MINSHORT
44  * G_MAXSHORT
45  * G_MININT
46  * G_MAXINT
47  * G_MINLONG
48  * G_MAXLONG
49  *
50  * We include limits.h before float.h to work around a egcs 1.1
51  * oddity on Solaris 2.5.1
52  */
53 #ifdef HAVE_LIMITS_H
54 #  include <limits.h>
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
61 #elif HAVE_VALUES_H
62 #  ifdef HAVE_FLOAT_H
63 #    include <values.h>
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 */
72
73 #ifdef HAVE_FLOAT_H
74 #  include <float.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
79 #elif HAVE_VALUES_H
80 #  include <values.h>
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 */
86
87
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.
92  */
93 #ifdef __cplusplus
94 extern "C" {
95 #pragma }
96 #endif /* __cplusplus */
97
98
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.
103  */
104 #ifndef NULL
105 #define NULL    ((void*) 0)
106 #endif
107
108 #ifndef FALSE
109 #define FALSE   (0)
110 #endif
111
112 #ifndef TRUE
113 #define TRUE    (!FALSE)
114 #endif
115
116 #undef  MAX
117 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
118
119 #undef  MIN
120 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
121
122 #undef  ABS
123 #define ABS(a)     (((a) < 0) ? -(a) : (a))
124
125 #undef  CLAMP
126 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
127
128
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.
131  */
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 */
141
142
143 /* Provide simple enum value macro wrappers that ease automated
144  * enum value stringification code. [abandoned]
145  */
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 */
157
158
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.
168  */
169 #ifndef G_INLINE_FUNC
170 #  define G_CAN_INLINE 1
171 #endif
172 #ifdef G_HAVE_INLINE
173 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
174 #    undef inline
175 #    define inline __inline__
176 #  endif
177 #else /* !G_HAVE_INLINE */
178 #  undef 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
187 #        undef G_CAN_INLINE
188 #      endif
189 #    endif
190 #  endif
191 #endif
192 #ifndef G_INLINE_FUNC
193 #  ifdef __GNUC__
194 #    ifdef __OPTIMIZE__
195 #      define G_INLINE_FUNC extern inline
196 #    else
197 #      undef G_CAN_INLINE
198 #      define G_INLINE_FUNC extern
199 #    endif
200 #  else /* !__GNUC__ */
201 #    ifdef G_CAN_INLINE
202 #      define G_INLINE_FUNC static inline
203 #    else
204 #      define G_INLINE_FUNC extern
205 #    endif
206 #  endif /* !__GNUC__ */
207 #endif /* !G_INLINE_FUNC */
208
209
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 ...
214  *
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)'.
218  */
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          )
223 #  else
224 #    if (defined (sun) || defined (__sun__))
225 #      define G_STMT_START      if (1)
226 #      define G_STMT_END        else (void)0
227 #    else
228 #      define G_STMT_START      do
229 #      define G_STMT_END        while (0)
230 #    endif
231 #  endif
232 #endif
233
234
235 /* Provide macros to feature the GCC function attribute.
236  */
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
255 #define G_GNUC_CONST
256 #define G_GNUC_UNUSED
257 #endif  /* !__GNUC__ */
258
259
260 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
261  * macros, so we can refer to them as strings unconditionally.
262  */
263 #ifdef  __GNUC__
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__ */
270
271
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.
276  */
277 #ifndef ATEXIT
278 #  ifdef HAVE_ATEXIT
279 #    ifdef NeXT /* @#%@! NeXTStep */
280 #      define ATEXIT(proc)   (!atexit (proc))
281 #    else /* !NeXT */
282 #      define ATEXIT(proc)   (atexit (proc))
283 #    endif /* !NeXT */
284 #  elif defined (HAVE_ON_EXIT)
285 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
286 #  else
287 #  error Could not determine proper atexit() implementation
288 #  endif
289 #else
290 #  define G_NATIVE_ATEXIT
291 #endif /* ATEXIT */
292
293 /* Hacker macro to place breakpoints for x86 machines.
294  * Actual use is strongly deprecated of course ;)
295  */
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__ */
301
302
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).
306  */
307
308 #ifdef __DMALLOC_H__
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__ */
320
321 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
322   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
323                    sizeof (type), \
324                    sizeof (type) * (pre_alloc), \
325                    (alloc_type)) \
326 )
327 #define g_chunk_new(type, chunk)        ( \
328   (type *) g_mem_chunk_alloc (chunk) \
329 )
330 #define g_chunk_new0(type, chunk)       ( \
331   (type *) g_mem_chunk_alloc0 (chunk) \
332 )
333 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
334   g_mem_chunk_free ((mem_chunk), (mem)); \
335 } G_STMT_END
336
337
338 #define g_string(x) #x
339
340
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.
346  */
347
348 #ifdef G_DISABLE_ASSERT
349
350 #define g_assert(expr)
351 #define g_assert_not_reached()
352
353 #else /* !G_DISABLE_ASSERT */
354
355 #ifdef __GNUC__
356
357 #define g_assert(expr)                  G_STMT_START{           \
358      if (!(expr))                                               \
359        g_log (G_LOG_DOMAIN,                                     \
360               G_LOG_LEVEL_ERROR,                                \
361               "file %s: line %d (%s): assertion failed: (%s)",  \
362               __FILE__,                                         \
363               __LINE__,                                         \
364               __PRETTY_FUNCTION__,                              \
365               #expr);                   }G_STMT_END
366
367 #define g_assert_not_reached()          G_STMT_START{           \
368      g_log (G_LOG_DOMAIN,                                       \
369             G_LOG_LEVEL_ERROR,                                  \
370             "file %s: line %d (%s): should not be reached",     \
371             __FILE__,                                           \
372             __LINE__,                                           \
373             __PRETTY_FUNCTION__);       }G_STMT_END
374
375 #else /* !__GNUC__ */
376
377 #define g_assert(expr)                  G_STMT_START{           \
378      if (!(expr))                                               \
379        g_log (G_LOG_DOMAIN,                                     \
380               G_LOG_LEVEL_ERROR,                                \
381               "file %s: line %d: assertion failed: (%s)",       \
382               __FILE__,                                         \
383               __LINE__,                                         \
384               #expr);                   }G_STMT_END
385
386 #define g_assert_not_reached()          G_STMT_START{   \
387      g_log (G_LOG_DOMAIN,                               \
388             G_LOG_LEVEL_ERROR,                          \
389             "file %s: line %d: should not be reached",  \
390             __FILE__,                                   \
391             __LINE__);          }G_STMT_END
392
393 #endif /* __GNUC__ */
394
395 #endif /* !G_DISABLE_ASSERT */
396
397
398 #ifdef G_DISABLE_CHECKS
399
400 #define g_return_if_fail(expr)
401 #define g_return_val_if_fail(expr,val)
402
403 #else /* !G_DISABLE_CHECKS */
404
405 #ifdef __GNUC__
406
407 #define g_return_if_fail(expr)          G_STMT_START{                   \
408      if (!(expr))                                                       \
409        {                                                                \
410          g_log (G_LOG_DOMAIN,                                           \
411                 G_LOG_LEVEL_CRITICAL,                                   \
412                 "file %s: line %d (%s): assertion `%s' failed.",        \
413                 __FILE__,                                               \
414                 __LINE__,                                               \
415                 __PRETTY_FUNCTION__,                                    \
416                 #expr);                                                 \
417          return;                                                        \
418        };                               }G_STMT_END
419
420 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
421      if (!(expr))                                                       \
422        {                                                                \
423          g_log (G_LOG_DOMAIN,                                           \
424                 G_LOG_LEVEL_CRITICAL,                                   \
425                 "file %s: line %d (%s): assertion `%s' failed.",        \
426                 __FILE__,                                               \
427                 __LINE__,                                               \
428                 __PRETTY_FUNCTION__,                                    \
429                 #expr);                                                 \
430          return val;                                                    \
431        };                               }G_STMT_END
432
433 #else /* !__GNUC__ */
434
435 #define g_return_if_fail(expr)          G_STMT_START{           \
436      if (!(expr))                                               \
437        {                                                        \
438          g_log (G_LOG_DOMAIN,                                   \
439                 G_LOG_LEVEL_CRITICAL,                           \
440                 "file %s: line %d: assertion `%s' failed.",     \
441                 __FILE__,                                       \
442                 __LINE__,                                       \
443                 #expr);                                         \
444          return;                                                \
445        };                               }G_STMT_END
446
447 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
448      if (!(expr))                                               \
449        {                                                        \
450          g_log (G_LOG_DOMAIN,                                   \
451                 G_LOG_LEVEL_CRITICAL,                           \
452                 "file %s: line %d: assertion `%s' failed.",     \
453                 __FILE__,                                       \
454                 __LINE__,                                       \
455                 #expr);                                         \
456          return val;                                            \
457        };                               }G_STMT_END
458
459 #endif /* !__GNUC__ */
460
461 #endif /* !G_DISABLE_CHECKS */
462
463
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.
469  */
470
471 typedef char   gchar;
472 typedef short  gshort;
473 typedef long   glong;
474 typedef int    gint;
475 typedef gint   gboolean;
476
477 typedef unsigned char   guchar;
478 typedef unsigned short  gushort;
479 typedef unsigned long   gulong;
480 typedef unsigned int    guint;
481
482 typedef float   gfloat;
483 typedef double  gdouble;
484
485 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
486  * Since gldouble isn't used anywhere, just disable it for now */
487
488 #if 0
489 #ifdef HAVE_LONG_DOUBLE
490 typedef long double gldouble;
491 #else /* HAVE_LONG_DOUBLE */
492 typedef double gldouble;
493 #endif /* HAVE_LONG_DOUBLE */
494 #endif /* 0 */
495
496 typedef void* gpointer;
497 typedef const void *gconstpointer;
498
499 #if (SIZEOF_CHAR == 1)
500 typedef signed char     gint8;
501 typedef unsigned char   guint8;
502 #endif /* SIZEOF_CHAR */
503
504 #if (SIZEOF_SHORT == 2)
505 typedef signed short    gint16;
506 typedef unsigned short  guint16;
507 #endif /* SIZEOF_SHORT */
508
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 */
516
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;
525 #else
526 /* No gint64 */
527 #undef HAVE_GINT64
528 #endif
529
530
531 /* Define macros for storing integers inside pointers
532  */
533 #if (SIZEOF_INT == SIZEOF_VOID_P)
534
535 #define GPOINTER_TO_INT(p) ((gint)(p))
536 #define GPOINTER_TO_UINT(p) ((guint)(p))
537
538 #define GINT_TO_POINTER(i) ((gpointer)(i))
539 #define GUINT_TO_POINTER(u) ((gpointer)(u))
540
541 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
542
543 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
544 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
545
546 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
547 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
548
549 #else
550 #error SIZEOF_VOID_P unknown - This should never happen
551 #endif
552
553 typedef gint32  gssize;
554 typedef guint32 gsize;
555 typedef guint32 GQuark;
556 typedef gint32  GTime;
557
558
559 /* Glib version.
560  */
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;
566
567
568 /* Forward declarations of glib types.
569  */
570
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;
595
596
597 typedef enum
598 {
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
603 } GTraverseFlags;
604
605 typedef enum
606 {
607   G_IN_ORDER,
608   G_PRE_ORDER,
609   G_POST_ORDER,
610   G_LEVEL_ORDER
611 } GTraverseType;
612
613 /* Log level shift offset for user defined
614  * log levels (0-7 are used by GLib).
615  */
616 #define G_LOG_LEVEL_USER_SHIFT  (8)
617
618 /* Glib log levels and flags.
619  */
620 typedef enum
621 {
622   /* log flags */
623   G_LOG_FLAG_RECURSION          = 1 << 0,
624   G_LOG_FLAG_FATAL              = 1 << 1,
625   
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,
633   
634   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
635 } GLogLevelFlags;
636
637 /* GLib log levels that are considered fatal by default */
638 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
639
640
641 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
642 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
643 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
644 typedef gint            (*GCompareFunc)         (gconstpointer  a,
645                                                  gconstpointer  b);
646 typedef gchar*          (*GCompletionFunc)      (gpointer);
647 typedef void            (*GDestroyNotify)       (gpointer       data);
648 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
649                                                  gpointer       data,
650                                                  gpointer       user_data);
651 typedef void            (*GFunc)                (gpointer       data,
652                                                  gpointer       user_data);
653 typedef guint           (*GHashFunc)            (gconstpointer  key);
654 typedef void            (*GHFunc)               (gpointer       key,
655                                                  gpointer       value,
656                                                  gpointer       user_data);
657 typedef gboolean        (*GHRFunc)              (gpointer       key,
658                                                  gpointer       value,
659                                                  gpointer       user_data);
660 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
661                                                  GHook          *sibling);
662 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
663                                                  gpointer        data);
664 typedef void            (*GHookMarshaller)      (GHook          *hook,
665                                                  gpointer        data);
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,
671                                                  gpointer       user_data);
672 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
673                                                  gpointer       data);
674 typedef void            (*GNodeForeachFunc)     (GNode         *node,
675                                                  gpointer       data);
676 typedef gint            (*GSearchFunc)          (gpointer       key,
677                                                  gpointer       data);
678 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
679                                                  gchar         *message,
680                                                  gint           error);
681 typedef gint            (*GTraverseFunc)        (gpointer       key,
682                                                  gpointer       value,
683                                                  gpointer       data);
684 typedef void            (*GVoidFunc)            (void);
685
686
687 struct _GList
688 {
689   gpointer data;
690   GList *next;
691   GList *prev;
692 };
693
694 struct _GSList
695 {
696   gpointer data;
697   GSList *next;
698 };
699
700 struct _GString
701 {
702   gchar *str;
703   gint len;
704 };
705
706 struct _GArray
707 {
708   gchar *data;
709   guint len;
710 };
711
712 struct _GByteArray
713 {
714   guint8 *data;
715   guint   len;
716 };
717
718 struct _GPtrArray
719 {
720   gpointer *pdata;
721   guint     len;
722 };
723
724 struct _GTuples
725 {
726   guint len;
727 };
728
729 struct _GDebugKey
730 {
731   gchar *key;
732   guint  value;
733 };
734
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; };
741
742
743 /* Doubly linked lists
744  */
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,
749                                  gpointer        data);
750 GList* g_list_prepend           (GList          *list,
751                                  gpointer        data);
752 GList* g_list_insert            (GList          *list,
753                                  gpointer        data,
754                                  gint            position);
755 GList* g_list_insert_sorted     (GList          *list,
756                                  gpointer        data,
757                                  GCompareFunc    func);
758 GList* g_list_concat            (GList          *list1,
759                                  GList          *list2);
760 GList* g_list_remove            (GList          *list,
761                                  gpointer        data);
762 GList* g_list_remove_link       (GList          *list,
763                                  GList          *llink);
764 GList* g_list_reverse           (GList          *list);
765 GList* g_list_nth               (GList          *list,
766                                  guint           n);
767 GList* g_list_find              (GList          *list,
768                                  gpointer        data);
769 GList* g_list_find_custom       (GList          *list,
770                                  gpointer        data,
771                                  GCompareFunc    func);
772 gint   g_list_position          (GList          *list,
773                                  GList          *llink);
774 gint   g_list_index             (GList          *list,
775                                  gpointer        data);
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,
780                                  GFunc           func,
781                                  gpointer        user_data);
782 gpointer g_list_nth_data        (GList          *list,
783                                  guint           n);
784 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
785 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
786
787
788 /* Singly linked lists
789  */
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,
794                                  gpointer        data);
795 GSList* g_slist_prepend         (GSList         *list,
796                                  gpointer        data);
797 GSList* g_slist_insert          (GSList         *list,
798                                  gpointer        data,
799                                  gint            position);
800 GSList* g_slist_insert_sorted   (GSList         *list,
801                                  gpointer        data,
802                                  GCompareFunc    func);
803 GSList* g_slist_concat          (GSList         *list1,
804                                  GSList         *list2);
805 GSList* g_slist_remove          (GSList         *list,
806                                  gpointer        data);
807 GSList* g_slist_remove_link     (GSList         *list,
808                                  GSList         *llink);
809 GSList* g_slist_reverse         (GSList         *list);
810 GSList* g_slist_nth             (GSList         *list,
811                                  guint           n);
812 GSList* g_slist_find            (GSList         *list,
813                                  gpointer        data);
814 GSList* g_slist_find_custom     (GSList         *list,
815                                  gpointer        data,
816                                  GCompareFunc    func);
817 gint    g_slist_position        (GSList         *list,
818                                  GSList         *llink);
819 gint    g_slist_index           (GSList         *list,
820                                  gpointer        data);
821 GSList* g_slist_last            (GSList         *list);
822 guint   g_slist_length          (GSList         *list);
823 void    g_slist_foreach         (GSList         *list,
824                                  GFunc           func,
825                                  gpointer        user_data);
826 gpointer g_slist_nth_data       (GSList         *list,
827                                  guint           n);
828 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
829
830
831 /* List Allocators
832  */
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);
837
838
839 /* Hash tables
840  */
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,
845                                          gpointer        key,
846                                          gpointer        value);
847 void        g_hash_table_remove         (GHashTable     *hash_table,
848                                          gconstpointer   key);
849 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
850                                          gconstpointer   key);
851 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
852                                          gconstpointer   lookup_key,
853                                          gpointer       *orig_key,
854                                          gpointer       *value);
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,
858                                          GHFunc          func,
859                                          gpointer        user_data);
860 gint        g_hash_table_foreach_remove (GHashTable     *hash_table,
861                                          GHRFunc         func,
862                                          gpointer        user_data);
863 gint        g_hash_table_size           (GHashTable     *hash_table);
864
865
866 /* Caches
867  */
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,
877                                 gpointer           key);
878 void     g_cache_remove        (GCache            *cache,
879                                 gpointer           value);
880 void     g_cache_key_foreach   (GCache            *cache,
881                                 GHFunc             func,
882                                 gpointer           user_data);
883 void     g_cache_value_foreach (GCache            *cache,
884                                 GHFunc             func,
885                                 gpointer           user_data);
886
887
888 /* Balanced binary trees
889  */
890 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
891 void     g_tree_destroy  (GTree         *tree);
892 void     g_tree_insert   (GTree         *tree,
893                           gpointer       key,
894                           gpointer       value);
895 void     g_tree_remove   (GTree         *tree,
896                           gpointer       key);
897 gpointer g_tree_lookup   (GTree         *tree,
898                           gpointer       key);
899 void     g_tree_traverse (GTree         *tree,
900                           GTraverseFunc  traverse_func,
901                           GTraverseType  traverse_type,
902                           gpointer       data);
903 gpointer g_tree_search   (GTree         *tree,
904                           GSearchFunc    search_func,
905                           gpointer       data);
906 gint     g_tree_height   (GTree         *tree);
907 gint     g_tree_nnodes   (GTree         *tree);
908
909
910
911 /* N-way tree implementation
912  */
913 struct _GNode
914 {
915   gpointer data;
916   GNode   *next;
917   GNode   *prev;
918   GNode   *parent;
919   GNode   *children;
920 };
921
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)
926
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,
931                                  gint              position,
932                                  GNode            *node);
933 GNode*   g_node_insert_before   (GNode            *parent,
934                                  GNode            *sibling,
935                                  GNode            *node);
936 GNode*   g_node_prepend         (GNode            *parent,
937                                  GNode            *node);
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,
942                                  GNode            *descendant);
943 guint    g_node_depth           (GNode            *node);
944 GNode*   g_node_find            (GNode            *root,
945                                  GTraverseType     order,
946                                  GTraverseFlags    flags,
947                                  gpointer          data);
948
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))
960
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.
965  */
966 void     g_node_traverse        (GNode            *root,
967                                  GTraverseType     order,
968                                  GTraverseFlags    flags,
969                                  gint              max_depth,
970                                  GNodeTraverseFunc func,
971                                  gpointer          data);
972
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.
977  */
978 guint    g_node_max_height       (GNode *root);
979
980 void     g_node_children_foreach (GNode           *node,
981                                   GTraverseFlags   flags,
982                                   GNodeForeachFunc func,
983                                   gpointer         data);
984 void     g_node_reverse_children (GNode           *node);
985 guint    g_node_n_children       (GNode           *node);
986 GNode*   g_node_nth_child        (GNode           *node,
987                                   guint            n);
988 GNode*   g_node_last_child       (GNode           *node);
989 GNode*   g_node_find_child       (GNode           *node,
990                                   GTraverseFlags   flags,
991                                   gpointer         data);
992 gint     g_node_child_position   (GNode           *node,
993                                   GNode           *child);
994 gint     g_node_child_index      (GNode           *node,
995                                   gpointer         data);
996
997 GNode*   g_node_first_sibling    (GNode           *node);
998 GNode*   g_node_last_sibling     (GNode           *node);
999
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)
1006
1007
1008 /* Callback maintenance functions
1009  */
1010 #define G_HOOK_FLAG_USER_SHIFT  (4)
1011 typedef enum
1012 {
1013   G_HOOK_ACTIVE         = 1 << 0,
1014   G_HOOK_IN_CALL        = 1 << 1,
1015   G_HOOK_FLAG_MASK      = 0x0f
1016 } GHookFlagMask;
1017
1018 struct _GHookList
1019 {
1020   guint          seq_id;
1021   guint          hook_size;
1022   guint          is_setup : 1;
1023   GHook         *hooks;
1024   GMemChunk     *hook_memchunk;
1025 };
1026
1027 struct _GHook
1028 {
1029   gpointer       data;
1030   GHook         *next;
1031   GHook         *prev;
1032   guint          ref_count;
1033   guint          id;
1034   guint          flags;
1035   gpointer       func;
1036   GDestroyNotify destroy;
1037 };
1038
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)->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)->id == 0 && \
1048                                          ((GHook*) hook)->ref_count == 0)
1049
1050 void     g_hook_list_init               (GHookList              *hook_list,
1051                                          guint                   hook_size);
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,
1055                                          GHook                  *hook);
1056 void     g_hook_ref                     (GHookList              *hook_list,
1057                                          GHook                  *hook);
1058 void     g_hook_unref                   (GHookList              *hook_list,
1059                                          GHook                  *hook);
1060 gboolean g_hook_destroy                 (GHookList              *hook_list,
1061                                          guint                   id);
1062 void     g_hook_destroy_link            (GHookList              *hook_list,
1063                                          GHook                  *hook);
1064 void     g_hook_prepend                 (GHookList              *hook_list,
1065                                          GHook                  *hook);
1066 void     g_hook_insert_before           (GHookList              *hook_list,
1067                                          GHook                  *sibling,
1068                                          GHook                  *hook);
1069 void     g_hook_insert_sorted           (GHookList              *hook_list,
1070                                          GHook                  *hook,
1071                                          GHookCompareFunc        func);
1072 GHook*   g_hook_get                     (GHookList              *hook_list,
1073                                          guint                   id);
1074 GHook*   g_hook_find                    (GHookList              *hook_list,
1075                                          gboolean                need_valids,
1076                                          GHookFindFunc           func,
1077                                          gpointer                data);
1078 GHook*   g_hook_find_data               (GHookList              *hook_list,
1079                                          gboolean                need_valids,
1080                                          gpointer                data);
1081 GHook*   g_hook_find_func               (GHookList              *hook_list,
1082                                          gboolean                need_valids,
1083                                          gpointer                func);
1084 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1085                                          gboolean                need_valids,
1086                                          gpointer                func,
1087                                          gpointer                data);
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,
1091                                          GHook                  *sibling);
1092
1093 /* convenience macros */
1094 #define  g_hook_append( hook_list, hook )  \
1095      g_hook_insert_before ((hook_list), NULL, (hook))
1096
1097 /* invoke all valid hooks with the (*GHookFunc) signature.
1098  */
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.
1103  */
1104 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1105                                          gboolean                may_recurse);
1106 /* invoke a marshaller on all valid hooks.
1107  */
1108 void     g_hook_list_marshall           (GHookList              *hook_list,
1109                                          gboolean                may_recurse,
1110                                          GHookMarshaller         marshaller,
1111                                          gpointer                data);
1112
1113
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().
1122  */
1123 void g_on_error_query (const gchar *prg_name);
1124 void g_on_error_stack_trace (const gchar *prg_name);
1125
1126
1127 /* Logging mechanism
1128  */
1129 extern const gchar                      *g_log_domain_glib;
1130 guint           g_log_set_handler       (const gchar    *log_domain,
1131                                          GLogLevelFlags  log_levels,
1132                                          GLogFunc        log_func,
1133                                          gpointer        user_data);
1134 void            g_log_remove_handler    (const gchar    *log_domain,
1135                                          guint           handler_id);
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,
1147                                          va_list         args);
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 */
1154 #ifdef  __GNUC__
1155 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1156                                                G_LOG_LEVEL_ERROR, \
1157                                                format, ##args)
1158 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1159                                                G_LOG_LEVEL_MESSAGE, \
1160                                                format, ##args)
1161 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1162                                                G_LOG_LEVEL_WARNING, \
1163                                                format, ##args)
1164 #else   /* !__GNUC__ */
1165 static inline void
1166 g_error (const gchar *format,
1167          ...)
1168 {
1169   va_list args;
1170   va_start (args, format);
1171   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1172   va_end (args);
1173 }
1174 static inline void
1175 g_message (const gchar *format,
1176            ...)
1177 {
1178   va_list args;
1179   va_start (args, format);
1180   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1181   va_end (args);
1182 }
1183 static inline void
1184 g_warning (const gchar *format,
1185            ...)
1186 {
1187   va_list args;
1188   va_start (args, format);
1189   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1190   va_end (args);
1191 }
1192 #endif  /* !__GNUC__ */
1193
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);
1201
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);
1208
1209
1210 /* Memory allocation and debugging
1211  */
1212 #ifdef USE_DMALLOC
1213
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)
1218
1219 #else /* !USE_DMALLOC */
1220
1221 gpointer g_malloc      (gulong    size);
1222 gpointer g_malloc0     (gulong    size);
1223 gpointer g_realloc     (gpointer  mem,
1224                         gulong    size);
1225 void     g_free        (gpointer  mem);
1226
1227 #endif /* !USE_DMALLOC */
1228
1229 void     g_mem_profile (void);
1230 void     g_mem_check   (gpointer  mem);
1231
1232
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).
1240  *
1241  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1242  *  want to know what's going on inside do you?)
1243  */
1244
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.
1250  */
1251
1252 #define G_ALLOC_ONLY      1
1253 #define G_ALLOC_AND_FREE  2
1254
1255 GMemChunk* g_mem_chunk_new     (gchar     *name,
1256                                 gint       atom_size,
1257                                 gulong     area_size,
1258                                 gint       type);
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,
1263                                 gpointer   mem);
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);
1268
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
1275  *  similar.
1276  */
1277 void g_blow_chunks (void);
1278
1279
1280 /* Timer
1281  */
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);
1289
1290
1291 /* String utility functions
1292  */
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,
1301                                  va_list      args);
1302 gchar*   g_strndup              (const gchar *str,
1303                                  guint        n);
1304 gchar*   g_strnfill             (guint        length,
1305                                  gchar        fill_char);
1306 gchar*   g_strconcat            (const gchar *string1,
1307                                  ...); /* NULL terminated */
1308 gdouble  g_strtod               (const gchar *nptr,
1309                                  gchar      **endptr);
1310 gchar*   g_strerror             (gint         errnum);
1311 gchar*   g_strsignal            (gint         signum);
1312 gint     g_strcasecmp           (const gchar *s1,
1313                                  const gchar *s2);
1314 void     g_strdown              (gchar       *string);
1315 void     g_strup                (gchar       *string);
1316 void     g_strreverse           (gchar       *string);
1317 gpointer g_memdup               (gconstpointer mem,
1318                                  guint         byte_size);
1319
1320 /* calculate a string size, guarranteed to fit format + args.
1321  */
1322 guint   g_printf_string_upper_bound (const gchar* format,
1323                                      va_list      args);
1324
1325
1326 /* Retrive static string info
1327  */
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);
1334
1335
1336 /* Miscellaneous utility functions
1337  */
1338 guint   g_parse_debug_string    (const gchar *string,
1339                                  GDebugKey   *keys,
1340                                  guint        nkeys);
1341 gint    g_snprintf              (gchar       *string,
1342                                  gulong       n,
1343                                  gchar const *format,
1344                                  ...) G_GNUC_PRINTF (3, 4);
1345 gint    g_vsnprintf             (gchar       *string,
1346                                  gulong       n,
1347                                  gchar const *format,
1348                                  va_list      args);
1349 gchar*  g_basename              (const gchar *file_name);
1350
1351 /* strings are newly allocated with g_malloc() */
1352 gchar*  g_dirname               (const gchar *file_name);
1353 gchar*  g_get_current_dir       (void);
1354
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.
1359  */
1360 #ifdef HAVE_MEMMOVE
1361 #define g_memmove(dest, src, size)      G_STMT_START {  \
1362      memmove ((dest), (src), (size));                   \
1363 } G_STMT_END
1364 #else
1365 #define g_memmove(dest, src, size)      G_STMT_START {  \
1366      bcopy ((src), (dest), (size));                     \
1367 } G_STMT_END
1368 #endif
1369
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.
1374  */
1375 void    g_atexit                (GVoidFunc    func);
1376
1377
1378 /* Bit tests
1379  */
1380 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1381                                        gint    nth_bit);
1382 #ifdef  G_CAN_INLINE
1383 G_INLINE_FUNC gint
1384 g_bit_nth_lsf (guint32 mask,
1385                gint    nth_bit)
1386 {
1387   do
1388     {
1389       nth_bit++;
1390       if (mask & (1 << (guint) nth_bit))
1391         return nth_bit;
1392     }
1393   while (nth_bit < 32);
1394   return -1;
1395 }
1396 #endif  /* G_CAN_INLINE */
1397
1398 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1399                                        gint    nth_bit);
1400 #ifdef G_CAN_INLINE
1401 G_INLINE_FUNC gint
1402 g_bit_nth_msf (guint32 mask,
1403                gint    nth_bit)
1404 {
1405   if (nth_bit < 0)
1406     nth_bit = 33;
1407   do
1408     {
1409       nth_bit--;
1410       if (mask & (1 << (guint) nth_bit))
1411         return nth_bit;
1412     }
1413   while (nth_bit > 0);
1414   return -1;
1415 }
1416 #endif  /* G_CAN_INLINE */
1417
1418 G_INLINE_FUNC guint     g_bit_storage (guint number);
1419 #ifdef G_CAN_INLINE
1420 G_INLINE_FUNC guint
1421 g_bit_storage (guint number)
1422 {
1423   register guint n_bits = 0;
1424   
1425   do
1426     {
1427       n_bits++;
1428       number >>= 1;
1429     }
1430   while (number);
1431   return n_bits;
1432 }
1433 #endif  /* G_CAN_INLINE */
1434
1435
1436 /* String Chunks
1437  */
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);
1444
1445
1446 /* Strings
1447  */
1448 GString* g_string_new       (const gchar *init);
1449 GString* g_string_sized_new (guint        dfl_size);
1450 void     g_string_free      (GString     *string,
1451                              gint         free_segment);
1452 GString* g_string_assign    (GString     *lval,
1453                              const gchar *rval);
1454 GString* g_string_truncate  (GString     *string,
1455                              gint         len);
1456 GString* g_string_append    (GString     *string,
1457                              const gchar *val);
1458 GString* g_string_append_c  (GString     *string,
1459                              gchar        c);
1460 GString* g_string_prepend   (GString     *string,
1461                              const gchar *val);
1462 GString* g_string_prepend_c (GString     *string,
1463                              gchar        c);
1464 GString* g_string_insert    (GString     *string,
1465                              gint         pos,
1466                              const gchar *val);
1467 GString* g_string_insert_c  (GString     *string,
1468                              gint         pos,
1469                              gchar        c);
1470 GString* g_string_erase     (GString     *string,
1471                              gint         pos,
1472                              gint         len);
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);
1481
1482
1483 /* Resizable arrays
1484  */
1485
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])
1489
1490 GArray* g_array_new          (gboolean      zero_terminated,
1491                               gboolean      clear,
1492                               guint         element_size);
1493 void    g_array_free         (GArray       *array,
1494                               gboolean      free_segment);
1495 GArray* g_array_append_vals  (GArray       *array,
1496                               gconstpointer data,
1497                               guint         len);
1498 GArray* g_array_prepend_vals (GArray       *array,
1499                               gconstpointer data,
1500                               guint         len);
1501 GArray* g_array_set_size     (GArray       *array,
1502                               guint         length);
1503
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.
1507  */
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,
1511                                             gboolean     free_seg);
1512 void        g_ptr_array_set_size           (GPtrArray   *array,
1513                                             gint         length);
1514 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1515                                             gint         index);
1516 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1517                                             gpointer     data);
1518 void        g_ptr_array_add                (GPtrArray   *array,
1519                                             gpointer     data);
1520
1521 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1522  * but type-safe.
1523  */
1524
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,
1529                                    const guint8 *data,
1530                                    guint         len);
1531 GByteArray* g_byte_array_prepend  (GByteArray   *array,
1532                                    const guint8 *data,
1533                                    guint         len);
1534 GByteArray* g_byte_array_set_size (GByteArray   *array,
1535                                    guint         length);
1536
1537
1538 /* Hash Functions
1539  */
1540 gint  g_str_equal (gconstpointer   v,
1541                    gconstpointer   v2);
1542 guint g_str_hash  (gconstpointer   v);
1543
1544 gint  g_int_equal (gconstpointer   v,
1545                    gconstpointer   v2);
1546 guint g_int_hash  (gconstpointer   v);
1547
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.
1551  */
1552 guint g_direct_hash  (gconstpointer v);
1553 gint  g_direct_equal (gconstpointer v,
1554                       gconstpointer v2);
1555
1556
1557 /* Quarks (string<->id association)
1558  */
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);
1563
1564
1565 /* Keyed Data List
1566  */
1567 void      g_datalist_init               (GData          **datalist);
1568 void      g_datalist_clear              (GData          **datalist);
1569 gpointer  g_datalist_id_get_data        (GData          **datalist,
1570                                          GQuark           key_id);
1571 void      g_datalist_id_set_data_full   (GData          **datalist,
1572                                          GQuark           key_id,
1573                                          gpointer         data,
1574                                          GDestroyNotify   destroy_func);
1575 void      g_datalist_id_set_destroy     (GData          **datalist,
1576                                          GQuark           key_id,
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)
1595
1596
1597 /* Location Associated Keyed Data
1598  */
1599 void      g_dataset_destroy             (gconstpointer    dataset_location);
1600 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1601                                          GQuark           key_id);
1602 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1603                                          GQuark           key_id,
1604                                          gpointer         data,
1605                                          GDestroyNotify   destroy_func);
1606 void      g_dataset_id_set_destroy      (gconstpointer    dataset_location,
1607                                          GQuark           key_id,
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)
1626
1627
1628 /* GScanner: Flexible lexical scanner for general purpose.
1629  */
1630
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"
1642
1643 /* Error types */
1644 typedef enum
1645 {
1646   G_ERR_UNKNOWN,
1647   G_ERR_UNEXP_EOF,
1648   G_ERR_UNEXP_EOF_IN_STRING,
1649   G_ERR_UNEXP_EOF_IN_COMMENT,
1650   G_ERR_NON_DIGIT_IN_CONST,
1651   G_ERR_DIGIT_RADIX,
1652   G_ERR_FLOAT_RADIX,
1653   G_ERR_FLOAT_MALFORMED
1654 } GErrorType;
1655
1656 /* Token types */
1657 typedef enum
1658 {
1659   G_TOKEN_EOF                   =   0,
1660   
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                 = ',',
1669   
1670   G_TOKEN_NONE                  = 256,
1671   
1672   G_TOKEN_ERROR,
1673   
1674   G_TOKEN_CHAR,
1675   G_TOKEN_BINARY,
1676   G_TOKEN_OCTAL,
1677   G_TOKEN_INT,
1678   G_TOKEN_HEX,
1679   G_TOKEN_FLOAT,
1680   G_TOKEN_STRING,
1681   
1682   G_TOKEN_SYMBOL,
1683   G_TOKEN_IDENTIFIER,
1684   G_TOKEN_IDENTIFIER_NULL,
1685   
1686   G_TOKEN_COMMENT_SINGLE,
1687   G_TOKEN_COMMENT_MULTI,
1688   G_TOKEN_LAST
1689 } GTokenType;
1690
1691 union   _GTokenValue
1692 {
1693   gpointer      v_symbol;
1694   gchar         *v_identifier;
1695   gulong        v_binary;
1696   gulong        v_octal;
1697   gulong        v_int;
1698   gdouble       v_float;
1699   gulong        v_hex;
1700   gchar         *v_string;
1701   gchar         *v_comment;
1702   guchar        v_char;
1703   guint         v_error;
1704 };
1705
1706 struct  _GScannerConfig
1707 {
1708   /* Character sets
1709    */
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" */
1714   
1715   /* Should symbol lookup work case sensitive?
1716    */
1717   guint         case_sensitive : 1;
1718   
1719   /* Boolean values to be adjusted "on the fly"
1720    * to configure scanning behaviour.
1721    */
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? */
1742 };
1743
1744 struct  _GScanner
1745 {
1746   /* unused fields */
1747   gpointer              user_data;
1748   guint                 max_parse_errors;
1749   
1750   /* g_scanner_error() increments this field */
1751   guint                 parse_errors;
1752   
1753   /* name of input stream, featured by the default message handler */
1754   const gchar           *input_name;
1755   
1756   /* data pointer for derived structures */
1757   gpointer              derived_data;
1758   
1759   /* link into the scanner configuration */
1760   GScannerConfig        *config;
1761   
1762   /* fields filled in after g_scanner_get_next_token() */
1763   GTokenType            token;
1764   GTokenValue           value;
1765   guint                 line;
1766   guint                 position;
1767   
1768   /* fields filled in after g_scanner_peek_next_token() */
1769   GTokenType            next_token;
1770   GTokenValue           next_value;
1771   guint                 next_line;
1772   guint                 next_position;
1773   
1774   /* to be considered private */
1775   GHashTable            *symbol_table;
1776   gint                  input_fd;
1777   const gchar           *text;
1778   const gchar           *text_end;
1779   gchar                 *buffer;
1780   guint                 scope_id;
1781   
1782   /* handler function for _warn and _error */
1783   GScannerMsgFunc       msg_handler;
1784 };
1785
1786 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
1787 void            g_scanner_destroy               (GScanner       *scanner);
1788 void            g_scanner_input_file            (GScanner       *scanner,
1789                                                  gint           input_fd);
1790 void            g_scanner_input_text            (GScanner       *scanner,
1791                                                  const  gchar   *text,
1792                                                  guint          text_len);
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,
1801                                                  guint           scope_id);
1802 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
1803                                                  guint           scope_id,
1804                                                  const gchar    *symbol,
1805                                                  gpointer       value);
1806 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
1807                                                  guint           scope_id,
1808                                                  const gchar    *symbol);
1809 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
1810                                                  guint           scope_id,
1811                                                  const gchar    *symbol);
1812 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
1813                                                  guint           scope_id,
1814                                                  GHFunc          func,
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,
1826                                                  gint            is_error);
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)); \
1837 } G_STMT_END
1838 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
1839   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1840 } G_STMT_END
1841 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1842   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1843 } G_STMT_END
1844
1845
1846 /* Completion */
1847
1848 struct _GCompletion
1849 {
1850   GList* items;
1851   GCompletionFunc func;
1852   
1853   gchar* prefix;
1854   GList* cache;
1855 };
1856
1857 GCompletion* g_completion_new          (GCompletionFunc func);
1858 void         g_completion_add_items    (GCompletion*    cmp,
1859                                         GList*          items);
1860 void         g_completion_remove_items (GCompletion*    cmp,
1861                                         GList*          items);
1862 void         g_completion_clear_items  (GCompletion*    cmp);
1863 GList*       g_completion_complete     (GCompletion*    cmp,
1864                                         gchar*          prefix,
1865                                         gchar**         new_prefix);
1866 void         g_completion_free         (GCompletion*    cmp);
1867
1868
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.
1872  *
1873  * g_relation_new() creates a relation with FIELDS fields
1874  *
1875  * g_relation_destroy() frees all resources
1876  * g_tuples_destroy() frees the result of g_relation_select()
1877  *
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.
1881  *
1882  * g_relation_insert() inserts a new tuple.  you are expected to
1883  *   provide the right number of fields.
1884  *
1885  * g_relation_delete() deletes all relations with KEY in FIELD
1886  * g_relation_select() returns ...
1887  * g_relation_count() counts ...
1888  */
1889
1890 GRelation* g_relation_new     (gint         fields);
1891 void       g_relation_destroy (GRelation   *relation);
1892 void       g_relation_index   (GRelation   *relation,
1893                                gint         field,
1894                                GHashFunc    hash_func,
1895                                GCompareFunc key_compare_func);
1896 void       g_relation_insert  (GRelation   *relation,
1897                                ...);
1898 gint       g_relation_delete  (GRelation   *relation,
1899                                gconstpointer  key,
1900                                gint         field);
1901 GTuples*   g_relation_select  (GRelation   *relation,
1902                                gconstpointer  key,
1903                                gint         field);
1904 gint       g_relation_count   (GRelation   *relation,
1905                                gconstpointer  key,
1906                                gint         field);
1907 gboolean   g_relation_exists  (GRelation   *relation,
1908                                ...);
1909 void       g_relation_print   (GRelation   *relation);
1910
1911 void       g_tuples_destroy   (GTuples     *tuples);
1912 gpointer   g_tuples_index     (GTuples     *tuples,
1913                                gint         index,
1914                                gint         field);
1915
1916
1917 /* Prime numbers.
1918  */
1919
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
1924  * MAXINT/4.
1925  */
1926
1927 guint      g_spaced_primes_closest (guint num);
1928
1929 /* Glib version.
1930  */
1931 extern const guint glib_major_version;
1932 extern const guint glib_minor_version;
1933 extern const guint glib_micro_version;
1934
1935 #ifdef __cplusplus
1936 }
1937 #endif /* __cplusplus */
1938
1939
1940 #endif /* __G_LIB_H__ */