removed the #pragma } statement after extern "C" {. use (c-set-offset
[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 #ifdef __cplusplus
89 extern "C" {
90 #endif /* __cplusplus */
91
92
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.
97  */
98 #ifndef NULL
99 #define NULL    ((void*) 0)
100 #endif
101
102 #ifndef FALSE
103 #define FALSE   (0)
104 #endif
105
106 #ifndef TRUE
107 #define TRUE    (!FALSE)
108 #endif
109
110 #undef  MAX
111 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
112
113 #undef  MIN
114 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
115
116 #undef  ABS
117 #define ABS(a)     (((a) < 0) ? -(a) : (a))
118
119 #undef  CLAMP
120 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
121
122
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.
125  */
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 */
135
136
137 /* Provide simple enum value macro wrappers that ease automated
138  * enum value stringification code. [abandoned]
139  */
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 */
151
152
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.
162  */
163 #ifndef G_INLINE_FUNC
164 #  define G_CAN_INLINE 1
165 #endif
166 #ifdef G_HAVE_INLINE
167 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
168 #    undef inline
169 #    define inline __inline__
170 #  endif
171 #else /* !G_HAVE_INLINE */
172 #  undef 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
181 #        undef G_CAN_INLINE
182 #      endif
183 #    endif
184 #  endif
185 #endif
186 #ifndef G_INLINE_FUNC
187 #  ifdef __GNUC__
188 #    ifdef __OPTIMIZE__
189 #      define G_INLINE_FUNC extern inline
190 #    else
191 #      undef G_CAN_INLINE
192 #      define G_INLINE_FUNC extern
193 #    endif
194 #  else /* !__GNUC__ */
195 #    ifdef G_CAN_INLINE
196 #      define G_INLINE_FUNC static inline
197 #    else
198 #      define G_INLINE_FUNC extern
199 #    endif
200 #  endif /* !__GNUC__ */
201 #endif /* !G_INLINE_FUNC */
202
203
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 ...
208  *
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)'.
212  */
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          )
217 #  else
218 #    if (defined (sun) || defined (__sun__))
219 #      define G_STMT_START      if (1)
220 #      define G_STMT_END        else (void)0
221 #    else
222 #      define G_STMT_START      do
223 #      define G_STMT_END        while (0)
224 #    endif
225 #  endif
226 #endif
227
228
229 /* Provide macros to feature the GCC function attribute.
230  */
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
249 #define G_GNUC_CONST
250 #define G_GNUC_UNUSED
251 #endif  /* !__GNUC__ */
252
253
254 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
255  * macros, so we can refer to them as strings unconditionally.
256  */
257 #ifdef  __GNUC__
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__ */
264
265
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.
270  */
271 #ifndef ATEXIT
272 #  ifdef HAVE_ATEXIT
273 #    ifdef NeXT /* @#%@! NeXTStep */
274 #      define ATEXIT(proc)   (!atexit (proc))
275 #    else /* !NeXT */
276 #      define ATEXIT(proc)   (atexit (proc))
277 #    endif /* !NeXT */
278 #  elif defined (HAVE_ON_EXIT)
279 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
280 #  else
281 #  error Could not determine proper atexit() implementation
282 #  endif
283 #else
284 #  define G_NATIVE_ATEXIT
285 #endif /* ATEXIT */
286
287 /* Hacker macro to place breakpoints for x86 machines.
288  * Actual use is strongly deprecated of course ;)
289  */
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__ */
295
296
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).
300  */
301
302 #ifdef __DMALLOC_H__
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__ */
314
315 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
316   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
317                    sizeof (type), \
318                    sizeof (type) * (pre_alloc), \
319                    (alloc_type)) \
320 )
321 #define g_chunk_new(type, chunk)        ( \
322   (type *) g_mem_chunk_alloc (chunk) \
323 )
324 #define g_chunk_new0(type, chunk)       ( \
325   (type *) g_mem_chunk_alloc0 (chunk) \
326 )
327 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
328   g_mem_chunk_free ((mem_chunk), (mem)); \
329 } G_STMT_END
330
331
332 #define g_string(x) #x
333
334
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.
340  */
341
342 #ifdef G_DISABLE_ASSERT
343
344 #define g_assert(expr)
345 #define g_assert_not_reached()
346
347 #else /* !G_DISABLE_ASSERT */
348
349 #ifdef __GNUC__
350
351 #define g_assert(expr)                  G_STMT_START{           \
352      if (!(expr))                                               \
353        g_log (G_LOG_DOMAIN,                                     \
354               G_LOG_LEVEL_ERROR,                                \
355               "file %s: line %d (%s): assertion failed: (%s)",  \
356               __FILE__,                                         \
357               __LINE__,                                         \
358               __PRETTY_FUNCTION__,                              \
359               #expr);                   }G_STMT_END
360
361 #define g_assert_not_reached()          G_STMT_START{           \
362      g_log (G_LOG_DOMAIN,                                       \
363             G_LOG_LEVEL_ERROR,                                  \
364             "file %s: line %d (%s): should not be reached",     \
365             __FILE__,                                           \
366             __LINE__,                                           \
367             __PRETTY_FUNCTION__);       }G_STMT_END
368
369 #else /* !__GNUC__ */
370
371 #define g_assert(expr)                  G_STMT_START{           \
372      if (!(expr))                                               \
373        g_log (G_LOG_DOMAIN,                                     \
374               G_LOG_LEVEL_ERROR,                                \
375               "file %s: line %d: assertion failed: (%s)",       \
376               __FILE__,                                         \
377               __LINE__,                                         \
378               #expr);                   }G_STMT_END
379
380 #define g_assert_not_reached()          G_STMT_START{   \
381      g_log (G_LOG_DOMAIN,                               \
382             G_LOG_LEVEL_ERROR,                          \
383             "file %s: line %d: should not be reached",  \
384             __FILE__,                                   \
385             __LINE__);          }G_STMT_END
386
387 #endif /* __GNUC__ */
388
389 #endif /* !G_DISABLE_ASSERT */
390
391
392 #ifdef G_DISABLE_CHECKS
393
394 #define g_return_if_fail(expr)
395 #define g_return_val_if_fail(expr,val)
396
397 #else /* !G_DISABLE_CHECKS */
398
399 #ifdef __GNUC__
400
401 #define g_return_if_fail(expr)          G_STMT_START{                   \
402      if (!(expr))                                                       \
403        {                                                                \
404          g_log (G_LOG_DOMAIN,                                           \
405                 G_LOG_LEVEL_CRITICAL,                                   \
406                 "file %s: line %d (%s): assertion `%s' failed.",        \
407                 __FILE__,                                               \
408                 __LINE__,                                               \
409                 __PRETTY_FUNCTION__,                                    \
410                 #expr);                                                 \
411          return;                                                        \
412        };                               }G_STMT_END
413
414 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
415      if (!(expr))                                                       \
416        {                                                                \
417          g_log (G_LOG_DOMAIN,                                           \
418                 G_LOG_LEVEL_CRITICAL,                                   \
419                 "file %s: line %d (%s): assertion `%s' failed.",        \
420                 __FILE__,                                               \
421                 __LINE__,                                               \
422                 __PRETTY_FUNCTION__,                                    \
423                 #expr);                                                 \
424          return val;                                                    \
425        };                               }G_STMT_END
426
427 #else /* !__GNUC__ */
428
429 #define g_return_if_fail(expr)          G_STMT_START{           \
430      if (!(expr))                                               \
431        {                                                        \
432          g_log (G_LOG_DOMAIN,                                   \
433                 G_LOG_LEVEL_CRITICAL,                           \
434                 "file %s: line %d: assertion `%s' failed.",     \
435                 __FILE__,                                       \
436                 __LINE__,                                       \
437                 #expr);                                         \
438          return;                                                \
439        };                               }G_STMT_END
440
441 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
442      if (!(expr))                                               \
443        {                                                        \
444          g_log (G_LOG_DOMAIN,                                   \
445                 G_LOG_LEVEL_CRITICAL,                           \
446                 "file %s: line %d: assertion `%s' failed.",     \
447                 __FILE__,                                       \
448                 __LINE__,                                       \
449                 #expr);                                         \
450          return val;                                            \
451        };                               }G_STMT_END
452
453 #endif /* !__GNUC__ */
454
455 #endif /* !G_DISABLE_CHECKS */
456
457
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.
463  */
464
465 typedef char   gchar;
466 typedef short  gshort;
467 typedef long   glong;
468 typedef int    gint;
469 typedef gint   gboolean;
470
471 typedef unsigned char   guchar;
472 typedef unsigned short  gushort;
473 typedef unsigned long   gulong;
474 typedef unsigned int    guint;
475
476 typedef float   gfloat;
477 typedef double  gdouble;
478
479 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
480  * Since gldouble isn't used anywhere, just disable it for now */
481
482 #if 0
483 #ifdef HAVE_LONG_DOUBLE
484 typedef long double gldouble;
485 #else /* HAVE_LONG_DOUBLE */
486 typedef double gldouble;
487 #endif /* HAVE_LONG_DOUBLE */
488 #endif /* 0 */
489
490 typedef void* gpointer;
491 typedef const void *gconstpointer;
492
493 #if (SIZEOF_CHAR == 1)
494 typedef signed char     gint8;
495 typedef unsigned char   guint8;
496 #endif /* SIZEOF_CHAR */
497
498 #if (SIZEOF_SHORT == 2)
499 typedef signed short    gint16;
500 typedef unsigned short  guint16;
501 #endif /* SIZEOF_SHORT */
502
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 */
510
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;
519 #else
520 /* No gint64 */
521 #undef HAVE_GINT64
522 #endif
523
524
525 /* Define macros for storing integers inside pointers
526  */
527 #if (SIZEOF_INT == SIZEOF_VOID_P)
528
529 #define GPOINTER_TO_INT(p) ((gint)(p))
530 #define GPOINTER_TO_UINT(p) ((guint)(p))
531
532 #define GINT_TO_POINTER(i) ((gpointer)(i))
533 #define GUINT_TO_POINTER(u) ((gpointer)(u))
534
535 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
536
537 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
538 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
539
540 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
541 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
542
543 #else
544 #error SIZEOF_VOID_P unknown - This should never happen
545 #endif
546
547 typedef gint32  gssize;
548 typedef guint32 gsize;
549 typedef guint32 GQuark;
550 typedef gint32  GTime;
551
552
553 /* Glib version.
554  */
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;
560
561
562 /* Forward declarations of glib types.
563  */
564
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;
589
590
591 typedef enum
592 {
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
597 } GTraverseFlags;
598
599 typedef enum
600 {
601   G_IN_ORDER,
602   G_PRE_ORDER,
603   G_POST_ORDER,
604   G_LEVEL_ORDER
605 } GTraverseType;
606
607 /* Log level shift offset for user defined
608  * log levels (0-7 are used by GLib).
609  */
610 #define G_LOG_LEVEL_USER_SHIFT  (8)
611
612 /* Glib log levels and flags.
613  */
614 typedef enum
615 {
616   /* log flags */
617   G_LOG_FLAG_RECURSION          = 1 << 0,
618   G_LOG_FLAG_FATAL              = 1 << 1,
619   
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,
627   
628   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
629 } GLogLevelFlags;
630
631 /* GLib log levels that are considered fatal by default */
632 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
633
634
635 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
636 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
637 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
638 typedef gint            (*GCompareFunc)         (gconstpointer  a,
639                                                  gconstpointer  b);
640 typedef gchar*          (*GCompletionFunc)      (gpointer);
641 typedef void            (*GDestroyNotify)       (gpointer       data);
642 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
643                                                  gpointer       data,
644                                                  gpointer       user_data);
645 typedef void            (*GFunc)                (gpointer       data,
646                                                  gpointer       user_data);
647 typedef guint           (*GHashFunc)            (gconstpointer  key);
648 typedef void            (*GHFunc)               (gpointer       key,
649                                                  gpointer       value,
650                                                  gpointer       user_data);
651 typedef gboolean        (*GHRFunc)              (gpointer       key,
652                                                  gpointer       value,
653                                                  gpointer       user_data);
654 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
655                                                  GHook          *sibling);
656 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
657                                                  gpointer        data);
658 typedef void            (*GHookMarshaller)      (GHook          *hook,
659                                                  gpointer        data);
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,
665                                                  gpointer       user_data);
666 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
667                                                  gpointer       data);
668 typedef void            (*GNodeForeachFunc)     (GNode         *node,
669                                                  gpointer       data);
670 typedef gint            (*GSearchFunc)          (gpointer       key,
671                                                  gpointer       data);
672 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
673                                                  gchar         *message,
674                                                  gint           error);
675 typedef gint            (*GTraverseFunc)        (gpointer       key,
676                                                  gpointer       value,
677                                                  gpointer       data);
678 typedef void            (*GVoidFunc)            (void);
679
680
681 struct _GList
682 {
683   gpointer data;
684   GList *next;
685   GList *prev;
686 };
687
688 struct _GSList
689 {
690   gpointer data;
691   GSList *next;
692 };
693
694 struct _GString
695 {
696   gchar *str;
697   gint len;
698 };
699
700 struct _GArray
701 {
702   gchar *data;
703   guint len;
704 };
705
706 struct _GByteArray
707 {
708   guint8 *data;
709   guint   len;
710 };
711
712 struct _GPtrArray
713 {
714   gpointer *pdata;
715   guint     len;
716 };
717
718 struct _GTuples
719 {
720   guint len;
721 };
722
723 struct _GDebugKey
724 {
725   gchar *key;
726   guint  value;
727 };
728
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; };
735
736
737 /* Doubly linked lists
738  */
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,
743                                  gpointer        data);
744 GList* g_list_prepend           (GList          *list,
745                                  gpointer        data);
746 GList* g_list_insert            (GList          *list,
747                                  gpointer        data,
748                                  gint            position);
749 GList* g_list_insert_sorted     (GList          *list,
750                                  gpointer        data,
751                                  GCompareFunc    func);
752 GList* g_list_concat            (GList          *list1,
753                                  GList          *list2);
754 GList* g_list_remove            (GList          *list,
755                                  gpointer        data);
756 GList* g_list_remove_link       (GList          *list,
757                                  GList          *llink);
758 GList* g_list_reverse           (GList          *list);
759 GList* g_list_nth               (GList          *list,
760                                  guint           n);
761 GList* g_list_find              (GList          *list,
762                                  gpointer        data);
763 GList* g_list_find_custom       (GList          *list,
764                                  gpointer        data,
765                                  GCompareFunc    func);
766 gint   g_list_position          (GList          *list,
767                                  GList          *llink);
768 gint   g_list_index             (GList          *list,
769                                  gpointer        data);
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,
774                                  GFunc           func,
775                                  gpointer        user_data);
776 gpointer g_list_nth_data        (GList          *list,
777                                  guint           n);
778 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
779 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
780
781
782 /* Singly linked lists
783  */
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,
788                                  gpointer        data);
789 GSList* g_slist_prepend         (GSList         *list,
790                                  gpointer        data);
791 GSList* g_slist_insert          (GSList         *list,
792                                  gpointer        data,
793                                  gint            position);
794 GSList* g_slist_insert_sorted   (GSList         *list,
795                                  gpointer        data,
796                                  GCompareFunc    func);
797 GSList* g_slist_concat          (GSList         *list1,
798                                  GSList         *list2);
799 GSList* g_slist_remove          (GSList         *list,
800                                  gpointer        data);
801 GSList* g_slist_remove_link     (GSList         *list,
802                                  GSList         *llink);
803 GSList* g_slist_reverse         (GSList         *list);
804 GSList* g_slist_nth             (GSList         *list,
805                                  guint           n);
806 GSList* g_slist_find            (GSList         *list,
807                                  gpointer        data);
808 GSList* g_slist_find_custom     (GSList         *list,
809                                  gpointer        data,
810                                  GCompareFunc    func);
811 gint    g_slist_position        (GSList         *list,
812                                  GSList         *llink);
813 gint    g_slist_index           (GSList         *list,
814                                  gpointer        data);
815 GSList* g_slist_last            (GSList         *list);
816 guint   g_slist_length          (GSList         *list);
817 void    g_slist_foreach         (GSList         *list,
818                                  GFunc           func,
819                                  gpointer        user_data);
820 gpointer g_slist_nth_data       (GSList         *list,
821                                  guint           n);
822 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
823
824
825 /* List Allocators
826  */
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);
831
832
833 /* Hash tables
834  */
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,
839                                          gpointer        key,
840                                          gpointer        value);
841 void        g_hash_table_remove         (GHashTable     *hash_table,
842                                          gconstpointer   key);
843 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
844                                          gconstpointer   key);
845 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
846                                          gconstpointer   lookup_key,
847                                          gpointer       *orig_key,
848                                          gpointer       *value);
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,
852                                          GHFunc          func,
853                                          gpointer        user_data);
854 gint        g_hash_table_foreach_remove (GHashTable     *hash_table,
855                                          GHRFunc         func,
856                                          gpointer        user_data);
857 gint        g_hash_table_size           (GHashTable     *hash_table);
858
859
860 /* Caches
861  */
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,
871                                 gpointer           key);
872 void     g_cache_remove        (GCache            *cache,
873                                 gpointer           value);
874 void     g_cache_key_foreach   (GCache            *cache,
875                                 GHFunc             func,
876                                 gpointer           user_data);
877 void     g_cache_value_foreach (GCache            *cache,
878                                 GHFunc             func,
879                                 gpointer           user_data);
880
881
882 /* Balanced binary trees
883  */
884 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
885 void     g_tree_destroy  (GTree         *tree);
886 void     g_tree_insert   (GTree         *tree,
887                           gpointer       key,
888                           gpointer       value);
889 void     g_tree_remove   (GTree         *tree,
890                           gpointer       key);
891 gpointer g_tree_lookup   (GTree         *tree,
892                           gpointer       key);
893 void     g_tree_traverse (GTree         *tree,
894                           GTraverseFunc  traverse_func,
895                           GTraverseType  traverse_type,
896                           gpointer       data);
897 gpointer g_tree_search   (GTree         *tree,
898                           GSearchFunc    search_func,
899                           gpointer       data);
900 gint     g_tree_height   (GTree         *tree);
901 gint     g_tree_nnodes   (GTree         *tree);
902
903
904
905 /* N-way tree implementation
906  */
907 struct _GNode
908 {
909   gpointer data;
910   GNode   *next;
911   GNode   *prev;
912   GNode   *parent;
913   GNode   *children;
914 };
915
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)
920
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,
925                                  gint              position,
926                                  GNode            *node);
927 GNode*   g_node_insert_before   (GNode            *parent,
928                                  GNode            *sibling,
929                                  GNode            *node);
930 GNode*   g_node_prepend         (GNode            *parent,
931                                  GNode            *node);
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,
936                                  GNode            *descendant);
937 guint    g_node_depth           (GNode            *node);
938 GNode*   g_node_find            (GNode            *root,
939                                  GTraverseType     order,
940                                  GTraverseFlags    flags,
941                                  gpointer          data);
942
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))
954
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.
959  */
960 void     g_node_traverse        (GNode            *root,
961                                  GTraverseType     order,
962                                  GTraverseFlags    flags,
963                                  gint              max_depth,
964                                  GNodeTraverseFunc func,
965                                  gpointer          data);
966
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.
971  */
972 guint    g_node_max_height       (GNode *root);
973
974 void     g_node_children_foreach (GNode           *node,
975                                   GTraverseFlags   flags,
976                                   GNodeForeachFunc func,
977                                   gpointer         data);
978 void     g_node_reverse_children (GNode           *node);
979 guint    g_node_n_children       (GNode           *node);
980 GNode*   g_node_nth_child        (GNode           *node,
981                                   guint            n);
982 GNode*   g_node_last_child       (GNode           *node);
983 GNode*   g_node_find_child       (GNode           *node,
984                                   GTraverseFlags   flags,
985                                   gpointer         data);
986 gint     g_node_child_position   (GNode           *node,
987                                   GNode           *child);
988 gint     g_node_child_index      (GNode           *node,
989                                   gpointer         data);
990
991 GNode*   g_node_first_sibling    (GNode           *node);
992 GNode*   g_node_last_sibling     (GNode           *node);
993
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)
1000
1001
1002 /* Callback maintenance functions
1003  */
1004 #define G_HOOK_FLAG_USER_SHIFT  (4)
1005 typedef enum
1006 {
1007   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1008   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1009   G_HOOK_FLAG_MASK      = 0x0f
1010 } GHookFlagMask;
1011
1012 struct _GHookList
1013 {
1014   guint          seq_id;
1015   guint          hook_size;
1016   guint          is_setup : 1;
1017   GHook         *hooks;
1018   GMemChunk     *hook_memchunk;
1019 };
1020
1021 struct _GHook
1022 {
1023   gpointer       data;
1024   GHook         *next;
1025   GHook         *prev;
1026   guint          ref_count;
1027   guint          hook_id;
1028   guint          flags;
1029   gpointer       func;
1030   GDestroyNotify destroy;
1031 };
1032
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)
1043
1044 void     g_hook_list_init               (GHookList              *hook_list,
1045                                          guint                   hook_size);
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,
1049                                          GHook                  *hook);
1050 void     g_hook_ref                     (GHookList              *hook_list,
1051                                          GHook                  *hook);
1052 void     g_hook_unref                   (GHookList              *hook_list,
1053                                          GHook                  *hook);
1054 gboolean g_hook_destroy                 (GHookList              *hook_list,
1055                                          guint                   hook_id);
1056 void     g_hook_destroy_link            (GHookList              *hook_list,
1057                                          GHook                  *hook);
1058 void     g_hook_prepend                 (GHookList              *hook_list,
1059                                          GHook                  *hook);
1060 void     g_hook_insert_before           (GHookList              *hook_list,
1061                                          GHook                  *sibling,
1062                                          GHook                  *hook);
1063 void     g_hook_insert_sorted           (GHookList              *hook_list,
1064                                          GHook                  *hook,
1065                                          GHookCompareFunc        func);
1066 GHook*   g_hook_get                     (GHookList              *hook_list,
1067                                          guint                   hook_id);
1068 GHook*   g_hook_find                    (GHookList              *hook_list,
1069                                          gboolean                need_valids,
1070                                          GHookFindFunc           func,
1071                                          gpointer                data);
1072 GHook*   g_hook_find_data               (GHookList              *hook_list,
1073                                          gboolean                need_valids,
1074                                          gpointer                data);
1075 GHook*   g_hook_find_func               (GHookList              *hook_list,
1076                                          gboolean                need_valids,
1077                                          gpointer                func);
1078 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1079                                          gboolean                need_valids,
1080                                          gpointer                func,
1081                                          gpointer                data);
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);
1086
1087 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1088 gint     g_hook_compare_ids             (GHook                  *new_hook,
1089                                          GHook                  *sibling);
1090
1091 /* convenience macros */
1092 #define  g_hook_append( hook_list, hook )  \
1093      g_hook_insert_before ((hook_list), NULL, (hook))
1094
1095 /* invoke all valid hooks with the (*GHookFunc) signature.
1096  */
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.
1101  */
1102 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1103                                          gboolean                may_recurse);
1104 /* invoke a marshaller on all valid hooks.
1105  */
1106 void     g_hook_list_marshal            (GHookList              *hook_list,
1107                                          gboolean                may_recurse,
1108                                          GHookMarshaller         marshaller,
1109                                          gpointer                data);
1110
1111
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().
1120  */
1121 void g_on_error_query (const gchar *prg_name);
1122 void g_on_error_stack_trace (const gchar *prg_name);
1123
1124
1125 /* Logging mechanism
1126  */
1127 extern const gchar                      *g_log_domain_glib;
1128 guint           g_log_set_handler       (const gchar    *log_domain,
1129                                          GLogLevelFlags  log_levels,
1130                                          GLogFunc        log_func,
1131                                          gpointer        user_data);
1132 void            g_log_remove_handler    (const gchar    *log_domain,
1133                                          guint           handler_id);
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,
1145                                          va_list         args);
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 */
1152 #ifdef  __GNUC__
1153 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1154                                                G_LOG_LEVEL_ERROR, \
1155                                                format, ##args)
1156 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1157                                                G_LOG_LEVEL_MESSAGE, \
1158                                                format, ##args)
1159 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1160                                                G_LOG_LEVEL_WARNING, \
1161                                                format, ##args)
1162 #else   /* !__GNUC__ */
1163 static inline void
1164 g_error (const gchar *format,
1165          ...)
1166 {
1167   va_list args;
1168   va_start (args, format);
1169   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1170   va_end (args);
1171 }
1172 static inline void
1173 g_message (const gchar *format,
1174            ...)
1175 {
1176   va_list args;
1177   va_start (args, format);
1178   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1179   va_end (args);
1180 }
1181 static inline void
1182 g_warning (const gchar *format,
1183            ...)
1184 {
1185   va_list args;
1186   va_start (args, format);
1187   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1188   va_end (args);
1189 }
1190 #endif  /* !__GNUC__ */
1191
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);
1199
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);
1206
1207
1208 /* Memory allocation and debugging
1209  */
1210 #ifdef USE_DMALLOC
1211
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)
1216
1217 #else /* !USE_DMALLOC */
1218
1219 gpointer g_malloc      (gulong    size);
1220 gpointer g_malloc0     (gulong    size);
1221 gpointer g_realloc     (gpointer  mem,
1222                         gulong    size);
1223 void     g_free        (gpointer  mem);
1224
1225 #endif /* !USE_DMALLOC */
1226
1227 void     g_mem_profile (void);
1228 void     g_mem_check   (gpointer  mem);
1229
1230
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).
1238  *
1239  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1240  *  want to know what's going on inside do you?)
1241  */
1242
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.
1248  */
1249
1250 #define G_ALLOC_ONLY      1
1251 #define G_ALLOC_AND_FREE  2
1252
1253 GMemChunk* g_mem_chunk_new     (gchar     *name,
1254                                 gint       atom_size,
1255                                 gulong     area_size,
1256                                 gint       type);
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,
1261                                 gpointer   mem);
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);
1266
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
1273  *  similar.
1274  */
1275 void g_blow_chunks (void);
1276
1277
1278 /* Timer
1279  */
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);
1287
1288
1289 /* String utility functions
1290  */
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,
1299                                  va_list      args);
1300 gchar*   g_strndup              (const gchar *str,
1301                                  guint        n);
1302 gchar*   g_strnfill             (guint        length,
1303                                  gchar        fill_char);
1304 gchar*   g_strconcat            (const gchar *string1,
1305                                  ...); /* NULL terminated */
1306 gdouble  g_strtod               (const gchar *nptr,
1307                                  gchar      **endptr);
1308 gchar*   g_strerror             (gint         errnum);
1309 gchar*   g_strsignal            (gint         signum);
1310 gint     g_strcasecmp           (const gchar *s1,
1311                                  const gchar *s2);
1312 void     g_strdown              (gchar       *string);
1313 void     g_strup                (gchar       *string);
1314 void     g_strreverse           (gchar       *string);
1315 gpointer g_memdup               (gconstpointer mem,
1316                                  guint         byte_size);
1317
1318 /* calculate a string size, guarranteed to fit format + args.
1319  */
1320 guint   g_printf_string_upper_bound (const gchar* format,
1321                                      va_list      args);
1322
1323
1324 /* Retrive static string info
1325  */
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);
1332
1333
1334 /* Miscellaneous utility functions
1335  */
1336 guint   g_parse_debug_string    (const gchar *string,
1337                                  GDebugKey   *keys,
1338                                  guint        nkeys);
1339 gint    g_snprintf              (gchar       *string,
1340                                  gulong       n,
1341                                  gchar const *format,
1342                                  ...) G_GNUC_PRINTF (3, 4);
1343 gint    g_vsnprintf             (gchar       *string,
1344                                  gulong       n,
1345                                  gchar const *format,
1346                                  va_list      args);
1347 gchar*  g_basename              (const gchar *file_name);
1348
1349 /* strings are newly allocated with g_malloc() */
1350 gchar*  g_dirname               (const gchar *file_name);
1351 gchar*  g_get_current_dir       (void);
1352
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.
1357  */
1358 #ifdef HAVE_MEMMOVE
1359 #define g_memmove(dest, src, size)      G_STMT_START {  \
1360      memmove ((dest), (src), (size));                   \
1361 } G_STMT_END
1362 #else
1363 #define g_memmove(dest, src, size)      G_STMT_START {  \
1364      bcopy ((src), (dest), (size));                     \
1365 } G_STMT_END
1366 #endif
1367
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.
1372  */
1373 void    g_atexit                (GVoidFunc    func);
1374
1375
1376 /* Bit tests
1377  */
1378 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1379                                        gint    nth_bit);
1380 #ifdef  G_CAN_INLINE
1381 G_INLINE_FUNC gint
1382 g_bit_nth_lsf (guint32 mask,
1383                gint    nth_bit)
1384 {
1385   do
1386     {
1387       nth_bit++;
1388       if (mask & (1 << (guint) nth_bit))
1389         return nth_bit;
1390     }
1391   while (nth_bit < 32);
1392   return -1;
1393 }
1394 #endif  /* G_CAN_INLINE */
1395
1396 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1397                                        gint    nth_bit);
1398 #ifdef G_CAN_INLINE
1399 G_INLINE_FUNC gint
1400 g_bit_nth_msf (guint32 mask,
1401                gint    nth_bit)
1402 {
1403   if (nth_bit < 0)
1404     nth_bit = 33;
1405   do
1406     {
1407       nth_bit--;
1408       if (mask & (1 << (guint) nth_bit))
1409         return nth_bit;
1410     }
1411   while (nth_bit > 0);
1412   return -1;
1413 }
1414 #endif  /* G_CAN_INLINE */
1415
1416 G_INLINE_FUNC guint     g_bit_storage (guint number);
1417 #ifdef G_CAN_INLINE
1418 G_INLINE_FUNC guint
1419 g_bit_storage (guint number)
1420 {
1421   register guint n_bits = 0;
1422   
1423   do
1424     {
1425       n_bits++;
1426       number >>= 1;
1427     }
1428   while (number);
1429   return n_bits;
1430 }
1431 #endif  /* G_CAN_INLINE */
1432
1433
1434 /* String Chunks
1435  */
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);
1442
1443
1444 /* Strings
1445  */
1446 GString* g_string_new       (const gchar *init);
1447 GString* g_string_sized_new (guint        dfl_size);
1448 void     g_string_free      (GString     *string,
1449                              gint         free_segment);
1450 GString* g_string_assign    (GString     *lval,
1451                              const gchar *rval);
1452 GString* g_string_truncate  (GString     *string,
1453                              gint         len);
1454 GString* g_string_append    (GString     *string,
1455                              const gchar *val);
1456 GString* g_string_append_c  (GString     *string,
1457                              gchar        c);
1458 GString* g_string_prepend   (GString     *string,
1459                              const gchar *val);
1460 GString* g_string_prepend_c (GString     *string,
1461                              gchar        c);
1462 GString* g_string_insert    (GString     *string,
1463                              gint         pos,
1464                              const gchar *val);
1465 GString* g_string_insert_c  (GString     *string,
1466                              gint         pos,
1467                              gchar        c);
1468 GString* g_string_erase     (GString     *string,
1469                              gint         pos,
1470                              gint         len);
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);
1479
1480
1481 /* Resizable arrays
1482  */
1483
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])
1487
1488 GArray* g_array_new          (gboolean      zero_terminated,
1489                               gboolean      clear,
1490                               guint         element_size);
1491 void    g_array_free         (GArray       *array,
1492                               gboolean      free_segment);
1493 GArray* g_array_append_vals  (GArray       *array,
1494                               gconstpointer data,
1495                               guint         len);
1496 GArray* g_array_prepend_vals (GArray       *array,
1497                               gconstpointer data,
1498                               guint         len);
1499 GArray* g_array_set_size     (GArray       *array,
1500                               guint         length);
1501
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.
1505  */
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,
1509                                             gboolean     free_seg);
1510 void        g_ptr_array_set_size           (GPtrArray   *array,
1511                                             gint         length);
1512 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1513                                             gint         index);
1514 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1515                                             gpointer     data);
1516 void        g_ptr_array_add                (GPtrArray   *array,
1517                                             gpointer     data);
1518
1519 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1520  * but type-safe.
1521  */
1522
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,
1527                                    const guint8 *data,
1528                                    guint         len);
1529 GByteArray* g_byte_array_prepend  (GByteArray   *array,
1530                                    const guint8 *data,
1531                                    guint         len);
1532 GByteArray* g_byte_array_set_size (GByteArray   *array,
1533                                    guint         length);
1534
1535
1536 /* Hash Functions
1537  */
1538 gint  g_str_equal (gconstpointer   v,
1539                    gconstpointer   v2);
1540 guint g_str_hash  (gconstpointer   v);
1541
1542 gint  g_int_equal (gconstpointer   v,
1543                    gconstpointer   v2);
1544 guint g_int_hash  (gconstpointer   v);
1545
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.
1549  */
1550 guint g_direct_hash  (gconstpointer v);
1551 gint  g_direct_equal (gconstpointer v,
1552                       gconstpointer v2);
1553
1554
1555 /* Quarks (string<->id association)
1556  */
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);
1561
1562
1563 /* Keyed Data List
1564  */
1565 void      g_datalist_init               (GData          **datalist);
1566 void      g_datalist_clear              (GData          **datalist);
1567 gpointer  g_datalist_id_get_data        (GData          **datalist,
1568                                          GQuark           key_id);
1569 void      g_datalist_id_set_data_full   (GData          **datalist,
1570                                          GQuark           key_id,
1571                                          gpointer         data,
1572                                          GDestroyNotify   destroy_func);
1573 void      g_datalist_id_set_destroy     (GData          **datalist,
1574                                          GQuark           key_id,
1575                                          GDestroyNotify   destroy_func);
1576 void      g_datalist_foreach            (GData          **datalist,
1577                                          GDataForeachFunc func,
1578                                          gpointer         user_data);
1579 #define   g_datalist_id_set_data(dl, q, d)      \
1580      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1581 #define   g_datalist_id_remove_data(dl, q)      \
1582      g_datalist_id_set_data ((dl), (q), NULL)
1583 #define   g_datalist_get_data(dl, k)            \
1584      (g_datalist_id_get_data ((dl), g_quark_try_string ((k))))
1585 #define   g_datalist_set_data_full(dl, k, d, f) \
1586      g_datalist_id_set_data_full ((dl), g_quark_from_string ((k)), (d), (f))
1587 #define   g_datalist_set_destroy(dl, k, f)      \
1588      g_datalist_id_set_destroy ((dl), g_quark_try_string ((k)), (f))
1589 #define   g_datalist_set_data(dl, k, d)         \
1590      g_datalist_set_data_full ((dl), (k), (d), NULL)
1591 #define   g_datalist_remove_data(dl, k)         \
1592      g_datalist_id_set_data ((dl), g_quark_try_string ((k)), NULL)
1593
1594
1595 /* Location Associated Keyed Data
1596  */
1597 void      g_dataset_destroy             (gconstpointer    dataset_location);
1598 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1599                                          GQuark           key_id);
1600 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1601                                          GQuark           key_id,
1602                                          gpointer         data,
1603                                          GDestroyNotify   destroy_func);
1604 void      g_dataset_id_set_destroy      (gconstpointer    dataset_location,
1605                                          GQuark           key_id,
1606                                          GDestroyNotify   destroy_func);
1607 void      g_dataset_foreach             (gconstpointer    dataset_location,
1608                                          GDataForeachFunc func,
1609                                          gpointer         user_data);
1610 #define   g_dataset_id_set_data(l, k, d)        \
1611      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1612 #define   g_dataset_id_remove_data(l, k)        \
1613      g_dataset_id_set_data ((l), (k), NULL)
1614 #define   g_dataset_get_data(l, k)              \
1615      (g_dataset_id_get_data ((l), g_quark_try_string ((k))))
1616 #define   g_dataset_set_data_full(l, k, d, f)   \
1617      g_dataset_id_set_data_full ((l), g_quark_from_string ((k)), (d), (f))
1618 #define   g_dataset_set_destroy(l, k, f)        \
1619      g_dataset_id_set_destroy ((l), g_quark_try_string ((k)), (f))
1620 #define   g_dataset_set_data(l, k, d)           \
1621      g_dataset_set_data_full ((l), (k), (d), NULL)
1622 #define   g_dataset_remove_data(l, k)           \
1623      g_dataset_id_set_data ((l), g_quark_try_string ((k)), NULL)
1624
1625
1626 /* GScanner: Flexible lexical scanner for general purpose.
1627  */
1628
1629 /* Character sets */
1630 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1631 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1632 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1633                         "\307\310\311\312\313\314\315\316\317\320"\
1634                         "\321\322\323\324\325\326"\
1635                         "\330\331\332\333\334\335\336"
1636 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1637                         "\347\350\351\352\353\354\355\356\357\360"\
1638                         "\361\362\363\364\365\366"\
1639                         "\370\371\372\373\374\375\376\377"
1640
1641 /* Error types */
1642 typedef enum
1643 {
1644   G_ERR_UNKNOWN,
1645   G_ERR_UNEXP_EOF,
1646   G_ERR_UNEXP_EOF_IN_STRING,
1647   G_ERR_UNEXP_EOF_IN_COMMENT,
1648   G_ERR_NON_DIGIT_IN_CONST,
1649   G_ERR_DIGIT_RADIX,
1650   G_ERR_FLOAT_RADIX,
1651   G_ERR_FLOAT_MALFORMED
1652 } GErrorType;
1653
1654 /* Token types */
1655 typedef enum
1656 {
1657   G_TOKEN_EOF                   =   0,
1658   
1659   G_TOKEN_LEFT_PAREN            = '(',
1660   G_TOKEN_RIGHT_PAREN           = ')',
1661   G_TOKEN_LEFT_CURLY            = '{',
1662   G_TOKEN_RIGHT_CURLY           = '}',
1663   G_TOKEN_LEFT_BRACE            = '[',
1664   G_TOKEN_RIGHT_BRACE           = ']',
1665   G_TOKEN_EQUAL_SIGN            = '=',
1666   G_TOKEN_COMMA                 = ',',
1667   
1668   G_TOKEN_NONE                  = 256,
1669   
1670   G_TOKEN_ERROR,
1671   
1672   G_TOKEN_CHAR,
1673   G_TOKEN_BINARY,
1674   G_TOKEN_OCTAL,
1675   G_TOKEN_INT,
1676   G_TOKEN_HEX,
1677   G_TOKEN_FLOAT,
1678   G_TOKEN_STRING,
1679   
1680   G_TOKEN_SYMBOL,
1681   G_TOKEN_IDENTIFIER,
1682   G_TOKEN_IDENTIFIER_NULL,
1683   
1684   G_TOKEN_COMMENT_SINGLE,
1685   G_TOKEN_COMMENT_MULTI,
1686   G_TOKEN_LAST
1687 } GTokenType;
1688
1689 union   _GTokenValue
1690 {
1691   gpointer      v_symbol;
1692   gchar         *v_identifier;
1693   gulong        v_binary;
1694   gulong        v_octal;
1695   gulong        v_int;
1696   gdouble       v_float;
1697   gulong        v_hex;
1698   gchar         *v_string;
1699   gchar         *v_comment;
1700   guchar        v_char;
1701   guint         v_error;
1702 };
1703
1704 struct  _GScannerConfig
1705 {
1706   /* Character sets
1707    */
1708   gchar         *cset_skip_characters;          /* default: " \t\n" */
1709   gchar         *cset_identifier_first;
1710   gchar         *cset_identifier_nth;
1711   gchar         *cpair_comment_single;          /* default: "#\n" */
1712   
1713   /* Should symbol lookup work case sensitive?
1714    */
1715   guint         case_sensitive : 1;
1716   
1717   /* Boolean values to be adjusted "on the fly"
1718    * to configure scanning behaviour.
1719    */
1720   guint         skip_comment_multi : 1;         /* C like comment */
1721   guint         skip_comment_single : 1;        /* single line comment */
1722   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1723   guint         scan_identifier : 1;
1724   guint         scan_identifier_1char : 1;
1725   guint         scan_identifier_NULL : 1;
1726   guint         scan_symbols : 1;
1727   guint         scan_binary : 1;
1728   guint         scan_octal : 1;
1729   guint         scan_float : 1;
1730   guint         scan_hex : 1;                   /* `0x0ff0' */
1731   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1732   guint         scan_string_sq : 1;             /* string: 'anything' */
1733   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1734   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
1735   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
1736   guint         identifier_2_string : 1;
1737   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
1738   guint         symbol_2_token : 1;
1739   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
1740 };
1741
1742 struct  _GScanner
1743 {
1744   /* unused fields */
1745   gpointer              user_data;
1746   guint                 max_parse_errors;
1747   
1748   /* g_scanner_error() increments this field */
1749   guint                 parse_errors;
1750   
1751   /* name of input stream, featured by the default message handler */
1752   const gchar           *input_name;
1753   
1754   /* data pointer for derived structures */
1755   gpointer              derived_data;
1756   
1757   /* link into the scanner configuration */
1758   GScannerConfig        *config;
1759   
1760   /* fields filled in after g_scanner_get_next_token() */
1761   GTokenType            token;
1762   GTokenValue           value;
1763   guint                 line;
1764   guint                 position;
1765   
1766   /* fields filled in after g_scanner_peek_next_token() */
1767   GTokenType            next_token;
1768   GTokenValue           next_value;
1769   guint                 next_line;
1770   guint                 next_position;
1771   
1772   /* to be considered private */
1773   GHashTable            *symbol_table;
1774   gint                  input_fd;
1775   const gchar           *text;
1776   const gchar           *text_end;
1777   gchar                 *buffer;
1778   guint                 scope_id;
1779   
1780   /* handler function for _warn and _error */
1781   GScannerMsgFunc       msg_handler;
1782 };
1783
1784 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
1785 void            g_scanner_destroy               (GScanner       *scanner);
1786 void            g_scanner_input_file            (GScanner       *scanner,
1787                                                  gint           input_fd);
1788 void            g_scanner_input_text            (GScanner       *scanner,
1789                                                  const  gchar   *text,
1790                                                  guint          text_len);
1791 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
1792 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
1793 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
1794 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
1795 guint           g_scanner_cur_line              (GScanner       *scanner);
1796 guint           g_scanner_cur_position          (GScanner       *scanner);
1797 gboolean        g_scanner_eof                   (GScanner       *scanner);
1798 guint           g_scanner_set_scope             (GScanner       *scanner,
1799                                                  guint           scope_id);
1800 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
1801                                                  guint           scope_id,
1802                                                  const gchar    *symbol,
1803                                                  gpointer       value);
1804 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
1805                                                  guint           scope_id,
1806                                                  const gchar    *symbol);
1807 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
1808                                                  guint           scope_id,
1809                                                  const gchar    *symbol);
1810 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
1811                                                  guint           scope_id,
1812                                                  GHFunc          func,
1813                                                  gpointer        func_data);
1814 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
1815                                                  const gchar    *symbol);
1816 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
1817 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
1818 void            g_scanner_unexp_token           (GScanner       *scanner,
1819                                                  GTokenType     expected_token,
1820                                                  const gchar    *identifier_spec,
1821                                                  const gchar    *symbol_spec,
1822                                                  const gchar    *symbol_name,
1823                                                  const gchar    *message,
1824                                                  gint            is_error);
1825 void            g_scanner_error                 (GScanner       *scanner,
1826                                                  const gchar    *format,
1827                                                  ...) G_GNUC_PRINTF (2,3);
1828 void            g_scanner_warn                  (GScanner       *scanner,
1829                                                  const gchar    *format,
1830                                                  ...) G_GNUC_PRINTF (2,3);
1831 gint            g_scanner_stat_mode             (const gchar    *filename);
1832 /* keep downward source compatibility */
1833 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
1834   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1835 } G_STMT_END
1836 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
1837   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1838 } G_STMT_END
1839 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1840   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1841 } G_STMT_END
1842
1843
1844 /* Completion */
1845
1846 struct _GCompletion
1847 {
1848   GList* items;
1849   GCompletionFunc func;
1850   
1851   gchar* prefix;
1852   GList* cache;
1853 };
1854
1855 GCompletion* g_completion_new          (GCompletionFunc func);
1856 void         g_completion_add_items    (GCompletion*    cmp,
1857                                         GList*          items);
1858 void         g_completion_remove_items (GCompletion*    cmp,
1859                                         GList*          items);
1860 void         g_completion_clear_items  (GCompletion*    cmp);
1861 GList*       g_completion_complete     (GCompletion*    cmp,
1862                                         gchar*          prefix,
1863                                         gchar**         new_prefix);
1864 void         g_completion_free         (GCompletion*    cmp);
1865
1866
1867 /* GRelation: Indexed Relations.  Imagine a really simple table in a
1868  * database.  Relations are not ordered.  This data type is meant for
1869  * maintaining a N-way mapping.
1870  *
1871  * g_relation_new() creates a relation with FIELDS fields
1872  *
1873  * g_relation_destroy() frees all resources
1874  * g_tuples_destroy() frees the result of g_relation_select()
1875  *
1876  * g_relation_index() indexes relation FIELD with the provided
1877  *   equality and hash functions.  this must be done before any
1878  *   calls to insert are made.
1879  *
1880  * g_relation_insert() inserts a new tuple.  you are expected to
1881  *   provide the right number of fields.
1882  *
1883  * g_relation_delete() deletes all relations with KEY in FIELD
1884  * g_relation_select() returns ...
1885  * g_relation_count() counts ...
1886  */
1887
1888 GRelation* g_relation_new     (gint         fields);
1889 void       g_relation_destroy (GRelation   *relation);
1890 void       g_relation_index   (GRelation   *relation,
1891                                gint         field,
1892                                GHashFunc    hash_func,
1893                                GCompareFunc key_compare_func);
1894 void       g_relation_insert  (GRelation   *relation,
1895                                ...);
1896 gint       g_relation_delete  (GRelation   *relation,
1897                                gconstpointer  key,
1898                                gint         field);
1899 GTuples*   g_relation_select  (GRelation   *relation,
1900                                gconstpointer  key,
1901                                gint         field);
1902 gint       g_relation_count   (GRelation   *relation,
1903                                gconstpointer  key,
1904                                gint         field);
1905 gboolean   g_relation_exists  (GRelation   *relation,
1906                                ...);
1907 void       g_relation_print   (GRelation   *relation);
1908
1909 void       g_tuples_destroy   (GTuples     *tuples);
1910 gpointer   g_tuples_index     (GTuples     *tuples,
1911                                gint         index,
1912                                gint         field);
1913
1914
1915 /* Prime numbers.
1916  */
1917
1918 /* This function returns prime numbers spaced by approximately 1.5-2.0
1919  * and is for use in resizing data structures which prefer
1920  * prime-valued sizes.  The closest spaced prime function returns the
1921  * next largest prime, or the highest it knows about which is about
1922  * MAXINT/4.
1923  */
1924
1925 guint      g_spaced_primes_closest (guint num);
1926
1927 /* Glib version.
1928  */
1929 extern const guint glib_major_version;
1930 extern const guint glib_minor_version;
1931 extern const guint glib_micro_version;
1932
1933 #ifdef __cplusplus
1934 }
1935 #endif /* __cplusplus */
1936
1937
1938 #endif /* __G_LIB_H__ */