version bump to 1.1.4, binary age 0, interface age 0.
[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 #else   /* !__GNUC__ */
249 #define G_GNUC_PRINTF( format_idx, arg_idx )
250 #define G_GNUC_SCANF( format_idx, arg_idx )
251 #define G_GNUC_FORMAT( arg_idx )
252 #define G_GNUC_NORETURN
253 #define G_GNUC_CONST
254 #endif  /* !__GNUC__ */
255
256
257 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
258  * macros, so we can refer to them as strings unconditionally.
259  */
260 #ifdef  __GNUC__
261 #define G_GNUC_FUNCTION         (__FUNCTION__)
262 #define G_GNUC_PRETTY_FUNCTION  (__PRETTY_FUNCTION__)
263 #else   /* !__GNUC__ */
264 #define G_GNUC_FUNCTION         ("")
265 #define G_GNUC_PRETTY_FUNCTION  ("")
266 #endif  /* !__GNUC__ */
267
268
269 /* we try to provide a usefull equivalent for ATEXIT if it is
270  * not defined, but use is actually abandoned. people should
271  * use g_atexit() instead.
272  * keep this in sync with gutils.c.
273  */
274 #ifndef ATEXIT
275 #  ifdef HAVE_ATEXIT
276 #    ifdef NeXT /* @#%@! NeXTStep */
277 #      define ATEXIT(proc)   (!atexit (proc))
278 #    else /* !NeXT */
279 #      define ATEXIT(proc)   (atexit (proc))
280 #    endif /* !NeXT */
281 #  elif defined (HAVE_ON_EXIT)
282 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
283 #  else
284 #  error Could not determine proper atexit() implementation
285 #  endif
286 #else
287 #  define G_NATIVE_ATEXIT
288 #endif /* ATEXIT */
289
290 /* Hacker macro to place breakpoints for x86 machines.
291  * Actual use is strongly deprecated of course ;)
292  */
293 #if     defined (__i386__) && defined (__GNUC__)
294 #define G_BREAKPOINT()          G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
295 #else   /* !__i386__ */
296 #define G_BREAKPOINT()
297 #endif  /* __i386__ */
298
299
300 /* Provide macros for easily allocating memory. The macros
301  *  will cast the allocated memory to the specified type
302  *  in order to avoid compiler warnings. (Makes the code neater).
303  */
304
305 #ifdef __DMALLOC_H__
306 #  define g_new(type, count)            (ALLOC (type, count))
307 #  define g_new0(type, count)           (CALLOC (type, count))
308 #  define g_renew(type, mem, count)     (REALLOC (mem, type, count))
309 #else /* __DMALLOC_H__ */
310 #  define g_new(type, count)      \
311       ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
312 #  define g_new0(type, count)     \
313       ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
314 #  define g_renew(type, mem, count)       \
315       ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
316 #endif /* __DMALLOC_H__ */
317
318 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
319   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
320                    sizeof (type), \
321                    sizeof (type) * (pre_alloc), \
322                    (alloc_type)) \
323 )
324 #define g_chunk_new(type, chunk)        ( \
325   (type *) g_mem_chunk_alloc (chunk) \
326 )
327 #define g_chunk_new0(type, chunk)       ( \
328   (type *) g_mem_chunk_alloc0 (chunk) \
329 )
330 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
331   g_mem_chunk_free ((mem_chunk), (mem)); \
332 } G_STMT_END
333
334
335 #define g_string(x) #x
336
337
338 /* Provide macros for error handling. The "assert" macros will
339  *  exit on failure. The "return" macros will exit the current
340  *  function. Two different definitions are given for the macros
341  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
342  *  __PRETTY_FUNCTION__ capability.
343  */
344
345 #ifdef G_DISABLE_ASSERT
346
347 #define g_assert(expr)
348 #define g_assert_not_reached()
349
350 #else /* !G_DISABLE_ASSERT */
351
352 #ifdef __GNUC__
353
354 #define g_assert(expr)                  G_STMT_START{           \
355      if (!(expr))                                               \
356        g_log (G_LOG_DOMAIN,                                     \
357               G_LOG_LEVEL_ERROR,                                \
358               "file %s: line %d (%s): assertion failed: (%s)",  \
359               __FILE__,                                         \
360               __LINE__,                                         \
361               __PRETTY_FUNCTION__,                              \
362               #expr);                   }G_STMT_END
363
364 #define g_assert_not_reached()          G_STMT_START{           \
365      g_log (G_LOG_DOMAIN,                                       \
366             G_LOG_LEVEL_ERROR,                                  \
367             "file %s: line %d (%s): should not be reached",     \
368             __FILE__,                                           \
369             __LINE__,                                           \
370             __PRETTY_FUNCTION__);       }G_STMT_END
371
372 #else /* !__GNUC__ */
373
374 #define g_assert(expr)                  G_STMT_START{           \
375      if (!(expr))                                               \
376        g_log (G_LOG_DOMAIN,                                     \
377               G_LOG_LEVEL_ERROR,                                \
378               "file %s: line %d: assertion failed: (%s)",       \
379               __FILE__,                                         \
380               __LINE__,                                         \
381               #expr);                   }G_STMT_END
382
383 #define g_assert_not_reached()          G_STMT_START{   \
384      g_log (G_LOG_DOMAIN,                               \
385             G_LOG_LEVEL_ERROR,                          \
386             "file %s: line %d: should not be reached",  \
387             __FILE__,                                   \
388             __LINE__);          }G_STMT_END
389
390 #endif /* __GNUC__ */
391
392 #endif /* !G_DISABLE_ASSERT */
393
394
395 #ifdef G_DISABLE_CHECKS
396
397 #define g_return_if_fail(expr)
398 #define g_return_val_if_fail(expr,val)
399
400 #else /* !G_DISABLE_CHECKS */
401
402 #ifdef __GNUC__
403
404 #define g_return_if_fail(expr)          G_STMT_START{                   \
405      if (!(expr))                                                       \
406        {                                                                \
407          g_log (G_LOG_DOMAIN,                                           \
408                 G_LOG_LEVEL_CRITICAL,                                   \
409                 "file %s: line %d (%s): assertion `%s' failed.",        \
410                 __FILE__,                                               \
411                 __LINE__,                                               \
412                 __PRETTY_FUNCTION__,                                    \
413                 #expr);                                                 \
414          return;                                                        \
415        };                               }G_STMT_END
416
417 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
418      if (!(expr))                                                       \
419        {                                                                \
420          g_log (G_LOG_DOMAIN,                                           \
421                 G_LOG_LEVEL_CRITICAL,                                   \
422                 "file %s: line %d (%s): assertion `%s' failed.",        \
423                 __FILE__,                                               \
424                 __LINE__,                                               \
425                 __PRETTY_FUNCTION__,                                    \
426                 #expr);                                                 \
427          return val;                                                    \
428        };                               }G_STMT_END
429
430 #else /* !__GNUC__ */
431
432 #define g_return_if_fail(expr)          G_STMT_START{           \
433      if (!(expr))                                               \
434        {                                                        \
435          g_log (G_LOG_DOMAIN,                                   \
436                 G_LOG_LEVEL_CRITICAL,                           \
437                 "file %s: line %d: assertion `%s' failed.",     \
438                 __FILE__,                                       \
439                 __LINE__,                                       \
440                 #expr);                                         \
441          return;                                                \
442        };                               }G_STMT_END
443
444 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
445      if (!(expr))                                               \
446        {                                                        \
447          g_log (G_LOG_DOMAIN,                                   \
448                 G_LOG_LEVEL_CRITICAL,                           \
449                 "file %s: line %d: assertion `%s' failed.",     \
450                 __FILE__,                                       \
451                 __LINE__,                                       \
452                 #expr);                                         \
453          return val;                                            \
454        };                               }G_STMT_END
455
456 #endif /* !__GNUC__ */
457
458 #endif /* !G_DISABLE_CHECKS */
459
460
461 /* Provide type definitions for commonly used types.
462  *  These are useful because a "gint8" can be adjusted
463  *  to be 1 byte (8 bits) on all platforms. Similarly and
464  *  more importantly, "gint32" can be adjusted to be
465  *  4 bytes (32 bits) on all platforms.
466  */
467
468 typedef char   gchar;
469 typedef short  gshort;
470 typedef long   glong;
471 typedef int    gint;
472 typedef gint   gboolean;
473
474 typedef unsigned char   guchar;
475 typedef unsigned short  gushort;
476 typedef unsigned long   gulong;
477 typedef unsigned int    guint;
478
479 typedef float   gfloat;
480 typedef double  gdouble;
481
482 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
483  * Since gldouble isn't used anywhere, just disable it for now */
484
485 #if 0
486 #ifdef HAVE_LONG_DOUBLE
487 typedef long double gldouble;
488 #else /* HAVE_LONG_DOUBLE */
489 typedef double gldouble;
490 #endif /* HAVE_LONG_DOUBLE */
491 #endif /* 0 */
492
493 typedef void* gpointer;
494 typedef const void *gconstpointer;
495
496 #if (SIZEOF_CHAR == 1)
497 typedef signed char     gint8;
498 typedef unsigned char   guint8;
499 #endif /* SIZEOF_CHAR */
500
501 #if (SIZEOF_SHORT == 2)
502 typedef signed short    gint16;
503 typedef unsigned short  guint16;
504 #endif /* SIZEOF_SHORT */
505
506 #if (SIZEOF_INT == 4)
507 typedef signed int      gint32;
508 typedef unsigned int    guint32;
509 #elif (SIZEOF_LONG == 4)
510 typedef signed long     gint32;
511 typedef unsigned long   guint32;
512 #endif /* SIZEOF_INT */
513
514 #if (SIZEOF_LONG == 8)
515 #define HAVE_GINT64 1
516 typedef signed long gint64;
517 typedef unsigned long guint64;
518 #elif (SIZEOF_LONG_LONG == 8)
519 #define HAVE_GINT64 1
520 typedef signed long long gint64;
521 typedef unsigned long long guint64;
522 #else
523 /* No gint64 */
524 #undef HAVE_GINT64
525 #endif
526
527
528 /* Define macros for storing integers inside pointers
529  */
530 #if (SIZEOF_INT == SIZEOF_VOID_P)
531
532 #define GPOINTER_TO_INT(p) ((gint)(p))
533 #define GPOINTER_TO_UINT(p) ((guint)(p))
534
535 #define GINT_TO_POINTER(i) ((gpointer)(i))
536 #define GUINT_TO_POINTER(u) ((gpointer)(u))
537
538 #elif (SIZEOF_LONG == SIZEOF_VOID_P)
539
540 #define GPOINTER_TO_INT(p) ((gint)(glong)(p))
541 #define GPOINTER_TO_UINT(p) ((guint)(gulong)(p))
542
543 #define GINT_TO_POINTER(i) ((gpointer)(glong)(i))
544 #define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u))
545
546 #else
547 #error SIZEOF_VOID_P unknown - This should never happen
548 #endif
549
550 typedef gint32  gssize;
551 typedef guint32 gsize;
552 typedef guint32 GQuark;
553 typedef gint32  GTime;
554
555
556 /* Glib version.
557  */
558 extern const guint glib_major_version;
559 extern const guint glib_minor_version;
560 extern const guint glib_micro_version;
561 extern const guint glib_interface_age;
562 extern const guint glib_binary_age;
563
564
565 /* Forward declarations of glib types.
566  */
567
568 typedef struct _GArray          GArray;
569 typedef struct _GByteArray      GByteArray;
570 typedef struct _GCache          GCache;
571 typedef struct _GCompletion     GCompletion;
572 typedef struct _GData           GData;
573 typedef struct _GDebugKey       GDebugKey;
574 typedef struct _GHashTable      GHashTable;
575 typedef struct _GList           GList;
576 typedef struct _GListAllocator  GListAllocator;
577 typedef struct _GMemChunk       GMemChunk;
578 typedef struct _GNode           GNode;
579 typedef struct _GPtrArray       GPtrArray;
580 typedef struct _GRelation       GRelation;
581 typedef struct _GScanner        GScanner;
582 typedef struct _GScannerConfig  GScannerConfig;
583 typedef struct _GSList          GSList;
584 typedef struct _GString         GString;
585 typedef struct _GStringChunk    GStringChunk;
586 typedef struct _GTimer          GTimer;
587 typedef struct _GTree           GTree;
588 typedef struct _GTuples         GTuples;
589 typedef union  _GTokenValue     GTokenValue;
590
591
592 typedef enum
593 {
594   G_TRAVERSE_LEAFS      = 1 << 0,
595   G_TRAVERSE_NON_LEAFS  = 1 << 1,
596   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
597   G_TRAVERSE_MASK       = 0x03
598 } GTraverseFlags;
599
600 typedef enum
601 {
602   G_IN_ORDER,
603   G_PRE_ORDER,
604   G_POST_ORDER,
605   G_LEVEL_ORDER
606 } GTraverseType;
607
608 /* Log level shift offset for user defined
609  * log levels (0-7 are used by GLib).
610  */
611 #define G_LOG_LEVEL_USER_SHIFT  (8)
612
613 /* Glib log levels and flags.
614  */
615 typedef enum
616 {
617   /* log flags */
618   G_LOG_FLAG_RECURSION          = 1 << 0,
619   G_LOG_FLAG_FATAL              = 1 << 1,
620
621   /* GLib log levels */
622   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
623   G_LOG_LEVEL_CRITICAL          = 1 << 3,
624   G_LOG_LEVEL_WARNING           = 1 << 4,
625   G_LOG_LEVEL_MESSAGE           = 1 << 5,
626   G_LOG_LEVEL_INFO              = 1 << 6,
627   G_LOG_LEVEL_DEBUG             = 1 << 7,
628
629   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
630 } GLogLevelFlags;
631
632 /* GLib log levels that are considered fatal by default */
633 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
634
635
636 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
637 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
638 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
639 typedef gint            (*GCompareFunc)         (gconstpointer  a,
640                                                  gconstpointer  b);
641 typedef gchar*          (*GCompletionFunc)      (gpointer);
642 typedef void            (*GDestroyNotify)       (gpointer       data);
643 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
644                                                  gpointer       data,
645                                                  gpointer       user_data);
646 typedef void            (*GFunc)                (gpointer       data,
647                                                  gpointer       user_data);
648 typedef guint           (*GHashFunc)            (gconstpointer  key);
649 typedef void            (*GHFunc)               (gpointer       key,
650                                                  gpointer       value,
651                                                  gpointer       user_data);
652 typedef gboolean        (*GHRFunc)              (gpointer       key,
653                                                  gpointer       value,
654                                                  gpointer       user_data);
655 typedef void            (*GLogFunc)             (const gchar   *log_domain,
656                                                  GLogLevelFlags log_level,
657                                                  const gchar   *message,
658                                                  gpointer       user_data);
659 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
660                                                  gpointer       data);
661 typedef void            (*GNodeForeachFunc)     (GNode         *node,
662                                                  gpointer       data);
663 typedef gint            (*GSearchFunc)          (gpointer       key,
664                                                  gpointer       data);
665 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
666                                                  gchar         *message,
667                                                  gint           error);
668 typedef gint            (*GTraverseFunc)        (gpointer       key,
669                                                  gpointer       value,
670                                                  gpointer       data);
671 typedef void            (*GVoidFunc)            (void);
672
673
674 struct _GList
675 {
676   gpointer data;
677   GList *next;
678   GList *prev;
679 };
680
681 struct _GSList
682 {
683   gpointer data;
684   GSList *next;
685 };
686
687 struct _GString
688 {
689   gchar *str;
690   gint len;
691 };
692
693 struct _GArray
694 {
695   gchar *data;
696   guint len;
697 };
698
699 struct _GByteArray
700 {
701   guint8 *data;
702   guint   len;
703 };
704
705 struct _GPtrArray
706 {
707   gpointer *pdata;
708   guint     len;
709 };
710
711 struct _GTuples
712 {
713   guint len;
714 };
715
716 struct _GDebugKey
717 {
718   gchar *key;
719   guint  value;
720 };
721
722 struct _GCache { gint dummy; };
723 struct _GTree { gint dummy; };
724 struct _GTimer { gint dummy; };
725 struct _GMemChunk { gint dummy; };
726 struct _GListAllocator { gint dummy; };
727 struct _GStringChunk { gint dummy; };
728
729
730 /* Doubly linked lists
731  */
732 GList* g_list_alloc             (void);
733 void   g_list_free              (GList          *list);
734 void   g_list_free_1            (GList          *list);
735 GList* g_list_append            (GList          *list,
736                                  gpointer        data);
737 GList* g_list_prepend           (GList          *list,
738                                  gpointer        data);
739 GList* g_list_insert            (GList          *list,
740                                  gpointer        data,
741                                  gint            position);
742 GList* g_list_insert_sorted     (GList          *list,
743                                  gpointer        data,
744                                  GCompareFunc    func);
745 GList* g_list_concat            (GList          *list1,
746                                  GList          *list2);
747 GList* g_list_remove            (GList          *list,
748                                  gpointer        data);
749 GList* g_list_remove_link       (GList          *list,
750                                  GList          *llink);
751 GList* g_list_reverse           (GList          *list);
752 GList* g_list_nth               (GList          *list,
753                                  guint           n);
754 GList* g_list_find              (GList          *list,
755                                  gpointer        data);
756 GList* g_list_find_custom       (GList          *list,
757                                  gpointer        data,
758                                  GCompareFunc    func);
759 gint   g_list_position          (GList          *list,
760                                  GList          *llink);
761 gint   g_list_index             (GList          *list,
762                                  gpointer        data);
763 GList* g_list_last              (GList          *list);
764 GList* g_list_first             (GList          *list);
765 guint  g_list_length            (GList          *list);
766 void   g_list_foreach           (GList          *list,
767                                  GFunc           func,
768                                  gpointer        user_data);
769 gpointer g_list_nth_data        (GList          *list,
770                                  guint           n);
771 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
772 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
773
774
775 /* Singly linked lists
776  */
777 GSList* g_slist_alloc           (void);
778 void    g_slist_free            (GSList         *list);
779 void    g_slist_free_1          (GSList         *list);
780 GSList* g_slist_append          (GSList         *list,
781                                  gpointer        data);
782 GSList* g_slist_prepend         (GSList         *list,
783                                  gpointer        data);
784 GSList* g_slist_insert          (GSList         *list,
785                                  gpointer        data,
786                                  gint            position);
787 GSList* g_slist_insert_sorted   (GSList         *list,
788                                  gpointer        data,
789                                  GCompareFunc    func);
790 GSList* g_slist_concat          (GSList         *list1,
791                                  GSList         *list2);
792 GSList* g_slist_remove          (GSList         *list,
793                                  gpointer        data);
794 GSList* g_slist_remove_link     (GSList         *list,
795                                  GSList         *llink);
796 GSList* g_slist_reverse         (GSList         *list);
797 GSList* g_slist_nth             (GSList         *list,
798                                  guint           n);
799 GSList* g_slist_find            (GSList         *list,
800                                  gpointer        data);
801 GSList* g_slist_find_custom     (GSList         *list,
802                                  gpointer        data,
803                                  GCompareFunc    func);
804 gint    g_slist_position        (GSList         *list,
805                                  GSList         *llink);
806 gint    g_slist_index           (GSList         *list,
807                                  gpointer        data);
808 GSList* g_slist_last            (GSList         *list);
809 guint   g_slist_length          (GSList         *list);
810 void    g_slist_foreach         (GSList         *list,
811                                  GFunc           func,
812                                  gpointer        user_data);
813 gpointer g_slist_nth_data       (GSList         *list,
814                                  guint           n);
815 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
816
817
818 /* List Allocators
819  */
820 GListAllocator* g_list_allocator_new  (void);
821 void            g_list_allocator_free (GListAllocator* allocator);
822 GListAllocator* g_slist_set_allocator (GListAllocator* allocator);
823 GListAllocator* g_list_set_allocator  (GListAllocator* allocator);
824
825
826 /* Hash tables
827  */
828 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
829                                          GCompareFunc    key_compare_func);
830 void        g_hash_table_destroy        (GHashTable     *hash_table);
831 void        g_hash_table_insert         (GHashTable     *hash_table,
832                                          gpointer        key,
833                                          gpointer        value);
834 void        g_hash_table_remove         (GHashTable     *hash_table,
835                                          gconstpointer   key);
836 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
837                                          gconstpointer   key);
838 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
839                                          gconstpointer   lookup_key,
840                                          gpointer       *orig_key,
841                                          gpointer       *value);
842 void        g_hash_table_freeze         (GHashTable     *hash_table);
843 void        g_hash_table_thaw           (GHashTable     *hash_table);
844 void        g_hash_table_foreach        (GHashTable     *hash_table,
845                                          GHFunc          func,
846                                          gpointer        user_data);
847 gint        g_hash_table_foreach_remove (GHashTable     *hash_table,
848                                          GHRFunc         func,
849                                          gpointer        user_data);
850 gint        g_hash_table_size           (GHashTable     *hash_table);
851
852
853 /* Caches
854  */
855 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
856                                 GCacheDestroyFunc  value_destroy_func,
857                                 GCacheDupFunc      key_dup_func,
858                                 GCacheDestroyFunc  key_destroy_func,
859                                 GHashFunc          hash_key_func,
860                                 GHashFunc          hash_value_func,
861                                 GCompareFunc       key_compare_func);
862 void     g_cache_destroy       (GCache            *cache);
863 gpointer g_cache_insert        (GCache            *cache,
864                                 gpointer           key);
865 void     g_cache_remove        (GCache            *cache,
866                                 gpointer           value);
867 void     g_cache_key_foreach   (GCache            *cache,
868                                 GHFunc             func,
869                                 gpointer           user_data);
870 void     g_cache_value_foreach (GCache            *cache,
871                                 GHFunc             func,
872                                 gpointer           user_data);
873
874
875 /* Balanced binary trees
876  */
877 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
878 void     g_tree_destroy  (GTree         *tree);
879 void     g_tree_insert   (GTree         *tree,
880                           gpointer       key,
881                           gpointer       value);
882 void     g_tree_remove   (GTree         *tree,
883                           gpointer       key);
884 gpointer g_tree_lookup   (GTree         *tree,
885                           gpointer       key);
886 void     g_tree_traverse (GTree         *tree,
887                           GTraverseFunc  traverse_func,
888                           GTraverseType  traverse_type,
889                           gpointer       data);
890 gpointer g_tree_search   (GTree         *tree,
891                           GSearchFunc    search_func,
892                           gpointer       data);
893 gint     g_tree_height   (GTree         *tree);
894 gint     g_tree_nnodes   (GTree         *tree);
895
896
897
898 /* N-way tree implementation
899  */
900 struct _GNode
901 {
902   gpointer data;
903   GNode   *next;
904   GNode   *prev;
905   GNode   *parent;
906   GNode   *children;
907 };
908
909 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
910                                  ((GNode*) (node))->prev == NULL && \
911                                  ((GNode*) (node))->next == NULL)
912 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
913
914 GNode*   g_node_new             (gpointer          data);
915 void     g_node_destroy         (GNode            *root);
916 void     g_node_unlink          (GNode            *node);
917 GNode*   g_node_insert          (GNode            *parent,
918                                  gint              position,
919                                  GNode            *node);
920 GNode*   g_node_insert_before   (GNode            *parent,
921                                  GNode            *sibling,
922                                  GNode            *node);
923 GNode*   g_node_prepend         (GNode            *parent,
924                                  GNode            *node);
925 guint    g_node_n_nodes         (GNode            *root,
926                                  GTraverseFlags    flags);
927 GNode*   g_node_get_root        (GNode            *node);
928 gboolean g_node_is_ancestor     (GNode            *node,
929                                  GNode            *descendant);
930 guint    g_node_depth           (GNode            *node);
931 GNode*   g_node_find            (GNode            *root,
932                                  GTraverseType     order,
933                                  GTraverseFlags    flags,
934                                  gpointer          data);
935
936 /* convenience macros */
937 #define g_node_append(parent, node)                             \
938      g_node_insert_before ((parent), NULL, (node))
939 #define g_node_insert_data(parent, position, data)              \
940      g_node_insert ((parent), (position), g_node_new (data))
941 #define g_node_insert_data_before(parent, sibling, data)        \
942      g_node_insert_before ((parent), (sibling), g_node_new (data))
943 #define g_node_prepend_data(parent, data)                       \
944      g_node_prepend ((parent), g_node_new (data))
945 #define g_node_append_data(parent, data)                        \
946      g_node_insert_before ((parent), NULL, g_node_new (data))
947
948 /* traversal function, assumes that `node' is root
949  * (only traverses `node' and its subtree).
950  * this function is just a high level interface to
951  * low level traversal functions, optimized for speed.
952  */
953 void     g_node_traverse        (GNode            *root,
954                                  GTraverseType     order,
955                                  GTraverseFlags    flags,
956                                  gint              max_depth,
957                                  GNodeTraverseFunc func,
958                                  gpointer          data);
959
960 /* return the maximum tree height starting with `node', this is an expensive
961  * operation, since we need to visit all nodes. this could be shortened by
962  * adding `guint height' to struct _GNode, but then again, this is not very
963  * often needed, and would make g_node_insert() more time consuming.
964  */
965 guint    g_node_max_height       (GNode *root);
966
967 void     g_node_children_foreach (GNode           *node,
968                                   GTraverseFlags   flags,
969                                   GNodeForeachFunc func,
970                                   gpointer         data);
971 void     g_node_reverse_children (GNode           *node);
972 guint    g_node_n_children       (GNode           *node);
973 GNode*   g_node_nth_child        (GNode           *node,
974                                   guint            n);
975 GNode*   g_node_last_child       (GNode           *node);
976 GNode*   g_node_find_child       (GNode           *node,
977                                   GTraverseFlags   flags,
978                                   gpointer         data);
979 gint     g_node_child_position   (GNode           *node,
980                                   GNode           *child);
981 gint     g_node_child_index      (GNode           *node,
982                                   gpointer         data);
983
984 GNode*   g_node_first_sibling    (GNode           *node);
985 GNode*   g_node_last_sibling     (GNode           *node);
986
987 #define  g_node_prev_sibling(node)      ((node) ? \
988                                          ((GNode*) (node))->prev : NULL)
989 #define  g_node_next_sibling(node)      ((node) ? \
990                                          ((GNode*) (node))->next : NULL)
991 #define  g_node_first_child(node)       ((node) ? \
992                                          ((GNode*) (node))->children : NULL)
993
994
995 /* Fatal error handlers.
996  * g_on_error_query() will prompt the user to either
997  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
998  * g_on_error_stack_trace() invokes gdb, which attaches to the current
999  * process and shows a stack trace.
1000  * These function may cause different actions on non-unix platforms.
1001  * The prg_name arg is required by gdb to find the executable, if it is
1002  * passed as NULL, g_on_error_query() will try g_get_prgname().
1003  */
1004 void g_on_error_query (const gchar *prg_name);
1005 void g_on_error_stack_trace (const gchar *prg_name);
1006
1007
1008 /* Logging mechanism
1009  */
1010 extern const gchar                      *g_log_domain_glib;
1011 guint           g_log_set_handler       (const gchar    *log_domain,
1012                                          GLogLevelFlags  log_levels,
1013                                          GLogFunc        log_func,
1014                                          gpointer        user_data);
1015 void            g_log_remove_handler    (const gchar    *log_domain,
1016                                          guint           handler_id);
1017 void            g_log_default_handler   (const gchar    *log_domain,
1018                                          GLogLevelFlags  log_level,
1019                                          const gchar    *message,
1020                                          gpointer        unused_data);
1021 void            g_log                   (const gchar    *log_domain,
1022                                          GLogLevelFlags  log_level,
1023                                          const gchar    *format,
1024                                          ...) G_GNUC_PRINTF (3, 4);
1025 void            g_logv                  (const gchar    *log_domain,
1026                                          GLogLevelFlags  log_level,
1027                                          const gchar    *format,
1028                                          va_list         args);
1029 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1030                                          GLogLevelFlags  fatal_mask);
1031 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1032 #ifndef G_LOG_DOMAIN
1033 #define G_LOG_DOMAIN    (NULL)
1034 #endif  /* G_LOG_DOMAIN */
1035 #ifdef  __GNUC__
1036 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1037                                                G_LOG_LEVEL_ERROR, \
1038                                                format, ##args)
1039 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1040                                                G_LOG_LEVEL_MESSAGE, \
1041                                                format, ##args)
1042 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1043                                                G_LOG_LEVEL_WARNING, \
1044                                                format, ##args)
1045 #else   /* !__GNUC__ */
1046 static inline void
1047 g_error (const gchar *format,
1048          ...)
1049 {
1050   va_list args;
1051   va_start (args, format);
1052   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1053   va_end (args);
1054 }
1055 static inline void
1056 g_message (const gchar *format,
1057            ...)
1058 {
1059   va_list args;
1060   va_start (args, format);
1061   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1062   va_end (args);
1063 }
1064 static inline void
1065 g_warning (const gchar *format,
1066            ...)
1067 {
1068   va_list args;
1069   va_start (args, format);
1070   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1071   va_end (args);
1072 }
1073 #endif  /* !__GNUC__ */
1074
1075 typedef void    (*GPrintFunc)           (const gchar    *string);
1076 void            g_print                 (const gchar    *format,
1077                                          ...) G_GNUC_PRINTF (1, 2);
1078 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1079 void            g_printerr              (const gchar    *format,
1080                                          ...) G_GNUC_PRINTF (1, 2);
1081 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1082
1083 /* deprecated compatibility functions, use g_log_set_handler() instead */
1084 typedef void            (*GErrorFunc)           (const gchar *str);
1085 typedef void            (*GWarningFunc)         (const gchar *str);
1086 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1087 GWarningFunc g_set_warning_handler (GWarningFunc func);
1088 GPrintFunc   g_set_message_handler (GPrintFunc func);
1089
1090
1091 /* Memory allocation and debugging
1092  */
1093 #ifdef USE_DMALLOC
1094
1095 #define g_malloc(size)       ((gpointer) MALLOC (size))
1096 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1097 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1098 #define g_free(mem)          FREE (mem)
1099
1100 #else /* !USE_DMALLOC */
1101
1102 gpointer g_malloc      (gulong    size);
1103 gpointer g_malloc0     (gulong    size);
1104 gpointer g_realloc     (gpointer  mem,
1105                         gulong    size);
1106 void     g_free        (gpointer  mem);
1107
1108 #endif /* !USE_DMALLOC */
1109
1110 void     g_mem_profile (void);
1111 void     g_mem_check   (gpointer  mem);
1112
1113
1114 /* "g_mem_chunk_new" creates a new memory chunk.
1115  * Memory chunks are used to allocate pieces of memory which are
1116  *  always the same size. Lists are a good example of such a data type.
1117  * The memory chunk allocates and frees blocks of memory as needed.
1118  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1119  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1120  *  fault...somewhere).
1121  *
1122  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1123  *  want to know what's going on inside do you?)
1124  */
1125
1126 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1127  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1128  *  atom. (They are also useful for lists which use MemChunk to allocate
1129  *  memory but are also part of the MemChunk implementation).
1130  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1131  */
1132
1133 #define G_ALLOC_ONLY      1
1134 #define G_ALLOC_AND_FREE  2
1135
1136 GMemChunk* g_mem_chunk_new     (gchar     *name,
1137                                 gint       atom_size,
1138                                 gulong     area_size,
1139                                 gint       type);
1140 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1141 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1142 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1143 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1144                                 gpointer   mem);
1145 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1146 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1147 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1148 void       g_mem_chunk_info    (void);
1149
1150 /* Ah yes...we have a "g_blow_chunks" function.
1151  * "g_blow_chunks" simply compresses all the chunks. This operation
1152  *  consists of freeing every memory area that should be freed (but
1153  *  which we haven't gotten around to doing yet). And, no,
1154  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1155  *  much better name than "g_mem_chunk_clean_all" or something
1156  *  similar.
1157  */
1158 void g_blow_chunks (void);
1159
1160
1161 /* Timer
1162  */
1163 GTimer* g_timer_new     (void);
1164 void    g_timer_destroy (GTimer  *timer);
1165 void    g_timer_start   (GTimer  *timer);
1166 void    g_timer_stop    (GTimer  *timer);
1167 void    g_timer_reset   (GTimer  *timer);
1168 gdouble g_timer_elapsed (GTimer  *timer,
1169                          gulong  *microseconds);
1170
1171
1172 /* String utility functions
1173  */
1174 #define  G_STR_DELIMITERS       "_-|> <."
1175 void     g_strdelimit           (gchar       *string,
1176                                  const gchar *delimiters,
1177                                  gchar        new_delimiter);
1178 gchar*   g_strdup               (const gchar *str);
1179 gchar*   g_strdup_printf        (const gchar *format,
1180                                  ...) G_GNUC_PRINTF (1, 2);
1181 gchar*   g_strdup_vprintf       (const gchar *format,
1182                                  va_list      args);
1183 gchar*   g_strndup              (const gchar *str,
1184                                  guint        n);
1185 gchar*   g_strnfill             (guint        length,
1186                                  gchar        fill_char);
1187 gchar*   g_strconcat            (const gchar *string1,
1188                                  ...); /* NULL terminated */
1189 gdouble  g_strtod               (const gchar *nptr,
1190                                  gchar      **endptr);
1191 gchar*   g_strerror             (gint         errnum);
1192 gchar*   g_strsignal            (gint         signum);
1193 gint     g_strcasecmp           (const gchar *s1,
1194                                  const gchar *s2);
1195 void     g_strdown              (gchar       *string);
1196 void     g_strup                (gchar       *string);
1197 void     g_strreverse           (gchar       *string);
1198 gpointer g_memdup               (gconstpointer mem,
1199                                  guint         byte_size);
1200
1201 /* calculate a string size, guarranteed to fit format + args.
1202  */
1203 guint   g_printf_string_upper_bound (const gchar* format,
1204                                      va_list      args);
1205
1206
1207 /* Retrive static string info
1208  */
1209 gchar*  g_get_user_name         (void);
1210 gchar*  g_get_real_name         (void);
1211 gchar*  g_get_home_dir          (void);
1212 gchar*  g_get_tmp_dir           (void);
1213 gchar*  g_get_prgname           (void);
1214 void    g_set_prgname           (const gchar *prgname);
1215
1216
1217 /* Miscellaneous utility functions
1218  */
1219 guint   g_parse_debug_string    (const gchar *string,
1220                                  GDebugKey   *keys,
1221                                  guint        nkeys);
1222 gint    g_snprintf              (gchar       *string,
1223                                  gulong       n,
1224                                  gchar const *format,
1225                                  ...) G_GNUC_PRINTF (3, 4);
1226 gint    g_vsnprintf             (gchar       *string,
1227                                  gulong       n,
1228                                  gchar const *format,
1229                                  va_list      args);
1230 gchar*  g_basename              (const gchar *file_name);
1231
1232 /* strings are newly allocated with g_malloc() */
1233 gchar*  g_dirname               (const gchar *file_name);
1234 gchar*  g_get_current_dir       (void);
1235
1236 /* We make the assumption that if memmove isn't available, then
1237  * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1238  * necessarily handle overlapping copies).
1239  * Either way, g_memmove() will not return a value.
1240  */
1241 #ifdef HAVE_MEMMOVE
1242 #define g_memmove(dest, src, size)      G_STMT_START {  \
1243      memmove ((dest), (src), (size));                   \
1244 } G_STMT_END
1245 #else
1246 #define g_memmove(dest, src, size)      G_STMT_START {  \
1247      bcopy ((src), (dest), (size));                     \
1248 } G_STMT_END
1249 #endif
1250
1251 /* we use a GLib function as a replacement for ATEXIT, so
1252  * the programmer is not required to check the return value
1253  * (if there is any in the implementation) and doesn't encounter
1254  * missing include files.
1255  */
1256 void    g_atexit                (GVoidFunc    func);
1257
1258
1259 /* Bit tests
1260  */
1261 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1262                                        gint    nth_bit);
1263 #ifdef  G_CAN_INLINE
1264 G_INLINE_FUNC gint
1265 g_bit_nth_lsf (guint32 mask,
1266                gint    nth_bit)
1267 {
1268   do
1269     {
1270       nth_bit++;
1271       if (mask & (1 << (guint) nth_bit))
1272         return nth_bit;
1273     }
1274   while (nth_bit < 32);
1275   return -1;
1276 }
1277 #endif  /* G_CAN_INLINE */
1278
1279 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1280                                        gint    nth_bit);
1281 #ifdef G_CAN_INLINE
1282 G_INLINE_FUNC gint
1283 g_bit_nth_msf (guint32 mask,
1284                gint    nth_bit)
1285 {
1286   if (nth_bit < 0)
1287     nth_bit = 33;
1288   do
1289     {
1290       nth_bit--;
1291       if (mask & (1 << (guint) nth_bit))
1292         return nth_bit;
1293     }
1294   while (nth_bit > 0);
1295   return -1;
1296 }
1297 #endif  /* G_CAN_INLINE */
1298
1299 G_INLINE_FUNC guint     g_bit_storage (guint number);
1300 #ifdef G_CAN_INLINE
1301 G_INLINE_FUNC guint
1302 g_bit_storage (guint number)
1303 {
1304   register guint n_bits = 0;
1305
1306   do
1307     {
1308       n_bits++;
1309       number >>= 1;
1310     }
1311   while (number);
1312   return n_bits;
1313 }
1314 #endif  /* G_CAN_INLINE */
1315
1316
1317 /* String Chunks
1318  */
1319 GStringChunk* g_string_chunk_new           (gint size);
1320 void          g_string_chunk_free          (GStringChunk *chunk);
1321 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1322                                             const gchar  *string);
1323 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1324                                             const gchar  *string);
1325
1326
1327 /* Strings
1328  */
1329 GString* g_string_new       (const gchar *init);
1330 GString* g_string_sized_new (guint        dfl_size);
1331 void     g_string_free      (GString     *string,
1332                              gint         free_segment);
1333 GString* g_string_assign    (GString     *lval,
1334                              const gchar *rval);
1335 GString* g_string_truncate  (GString     *string,
1336                              gint         len);
1337 GString* g_string_append    (GString     *string,
1338                              const gchar *val);
1339 GString* g_string_append_c  (GString     *string,
1340                              gchar        c);
1341 GString* g_string_prepend   (GString     *string,
1342                              const gchar *val);
1343 GString* g_string_prepend_c (GString     *string,
1344                              gchar        c);
1345 GString* g_string_insert    (GString     *string,
1346                              gint         pos,
1347                              const gchar *val);
1348 GString* g_string_insert_c  (GString     *string,
1349                              gint         pos,
1350                              gchar        c);
1351 GString* g_string_erase     (GString     *string,
1352                              gint         pos,
1353                              gint         len);
1354 GString* g_string_down      (GString     *string);
1355 GString* g_string_up        (GString     *string);
1356 void     g_string_sprintf   (GString     *string,
1357                              const gchar *format,
1358                              ...) G_GNUC_PRINTF (2, 3);
1359 void     g_string_sprintfa  (GString     *string,
1360                              const gchar *format,
1361                              ...) G_GNUC_PRINTF (2, 3);
1362
1363
1364 /* Resizable arrays
1365  */
1366
1367 #define g_array_append_val(a,v) g_array_append_vals(a,&v,1)
1368 #define g_array_prepend_val(a,v) g_array_prepend_vals(a,&v,1)
1369 #define g_array_index(a,t,i) (((t*)a->data)[i])
1370
1371 GArray* g_array_new          (gboolean      zero_terminated,
1372                               gboolean      clear,
1373                               guint         element_size);
1374 void    g_array_free         (GArray       *array,
1375                               gboolean      free_segment);
1376 GArray* g_array_append_vals  (GArray       *array,
1377                               gconstpointer data,
1378                               guint         len);
1379 GArray* g_array_prepend_vals (GArray       *array,
1380                               gconstpointer data,
1381                               guint         len);
1382 GArray* g_array_set_size     (GArray       *array,
1383                               guint         length);
1384
1385 /* Resizable pointer array.  This interface is much less complicated
1386  * than the above.  Add appends appends a pointer.  Remove fills any
1387  * cleared spot and shortens the array.
1388  */
1389 #define     g_ptr_array_index(array,index) (array->pdata)[index]
1390 GPtrArray*  g_ptr_array_new                (void);
1391 void        g_ptr_array_free               (GPtrArray   *array,
1392                                             gboolean     free_seg);
1393 void        g_ptr_array_set_size           (GPtrArray   *array,
1394                                             gint         length);
1395 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1396                                             gint         index);
1397 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1398                                             gpointer     data);
1399 void        g_ptr_array_add                (GPtrArray   *array,
1400                                             gpointer     data);
1401
1402 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1403  * but type-safe.
1404  */
1405
1406 GByteArray* g_byte_array_new      (void);
1407 void        g_byte_array_free     (GByteArray   *array,
1408                                    gboolean      free_segment);
1409 GByteArray* g_byte_array_append   (GByteArray   *array,
1410                                    const guint8 *data,
1411                                    guint         len);
1412 GByteArray* g_byte_array_prepend  (GByteArray   *array,
1413                                    const guint8 *data,
1414                                    guint         len);
1415 GByteArray* g_byte_array_set_size (GByteArray   *array,
1416                                    guint         length);
1417
1418
1419 /* Hash Functions
1420  */
1421 gint  g_str_equal (gconstpointer   v,
1422                    gconstpointer   v2);
1423 guint g_str_hash  (gconstpointer   v);
1424
1425 gint  g_int_equal (gconstpointer   v,
1426                    gconstpointer   v2);
1427 guint g_int_hash  (gconstpointer   v);
1428
1429 /* This "hash" function will just return the key's adress as an
1430  * unsigned integer. Useful for hashing on plain adresses or
1431  * simple integer values.
1432  */
1433 guint g_direct_hash  (gconstpointer v);
1434 gint  g_direct_equal (gconstpointer v,
1435                       gconstpointer v2);
1436
1437
1438 /* Quarks (string<->id association)
1439  */
1440 GQuark    g_quark_try_string            (const gchar    *string);
1441 GQuark    g_quark_from_static_string    (const gchar    *string);
1442 GQuark    g_quark_from_string           (const gchar    *string);
1443 gchar*    g_quark_to_string             (GQuark          quark);
1444
1445
1446 /* Keyed Data List
1447  */
1448 void      g_datalist_init               (GData          **datalist);
1449 void      g_datalist_clear              (GData          **datalist);
1450 gpointer  g_datalist_id_get_data        (GData          **datalist,
1451                                          GQuark           key_id);
1452 void      g_datalist_id_set_data_full   (GData          **datalist,
1453                                          GQuark           key_id,
1454                                          gpointer         data,
1455                                          GDestroyNotify   destroy_func);
1456 void      g_datalist_id_set_destroy     (GData          **datalist,
1457                                          GQuark           key_id,
1458                                          GDestroyNotify   destroy_func);
1459 void      g_datalist_foreach            (GData          **datalist,
1460                                          GDataForeachFunc func,
1461                                          gpointer         user_data);
1462 #define   g_datalist_id_set_data(dl, q, d)      \
1463      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1464 #define   g_datalist_id_remove_data(dl, q)      \
1465      g_datalist_id_set_data ((dl), (q), NULL)
1466 #define   g_datalist_get_data(dl, k)            \
1467      (g_datalist_id_get_data ((dl), g_quark_try_string ((k))))
1468 #define   g_datalist_set_data_full(dl, k, d, f) \
1469      g_datalist_id_set_data_full ((dl), g_quark_from_string ((k)), (d), (f))
1470 #define   g_datalist_set_destroy(dl, k, f)      \
1471      g_datalist_id_set_destroy ((dl), g_quark_try_string ((k)), (f))
1472 #define   g_datalist_set_data(dl, k, d)         \
1473      g_datalist_set_data_full ((dl), (k), (d), NULL)
1474 #define   g_datalist_remove_data(dl, k)         \
1475      g_datalist_id_set_data ((dl), g_quark_try_string ((k)), NULL)
1476
1477
1478 /* Location Associated Keyed Data
1479  */
1480 void      g_dataset_destroy             (gconstpointer    dataset_location);
1481 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1482                                          GQuark           key_id);
1483 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1484                                          GQuark           key_id,
1485                                          gpointer         data,
1486                                          GDestroyNotify   destroy_func);
1487 void      g_dataset_id_set_destroy      (gconstpointer    dataset_location,
1488                                          GQuark           key_id,
1489                                          GDestroyNotify   destroy_func);
1490 void      g_dataset_foreach             (gconstpointer    dataset_location,
1491                                          GDataForeachFunc func,
1492                                          gpointer         user_data);
1493 #define   g_dataset_id_set_data(l, k, d)        \
1494      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1495 #define   g_dataset_id_remove_data(l, k)        \
1496      g_dataset_id_set_data ((l), (k), NULL)
1497 #define   g_dataset_get_data(l, k)              \
1498      (g_dataset_id_get_data ((l), g_quark_try_string ((k))))
1499 #define   g_dataset_set_data_full(l, k, d, f)   \
1500      g_dataset_id_set_data_full ((l), g_quark_from_string ((k)), (d), (f))
1501 #define   g_dataset_set_destroy(l, k, f)        \
1502      g_dataset_id_set_destroy ((l), g_quark_try_string ((k)), (f))
1503 #define   g_dataset_set_data(l, k, d)           \
1504      g_dataset_set_data_full ((l), (k), (d), NULL)
1505 #define   g_dataset_remove_data(l, k)           \
1506      g_dataset_id_set_data ((l), g_quark_try_string ((k)), NULL)
1507
1508
1509 /* GScanner: Flexible lexical scanner for general purpose.
1510  */
1511
1512 /* Character sets */
1513 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1514 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1515 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1516                         "\307\310\311\312\313\314\315\316\317\320"\
1517                         "\321\322\323\324\325\326"\
1518                         "\330\331\332\333\334\335\336"
1519 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1520                         "\347\350\351\352\353\354\355\356\357\360"\
1521                         "\361\362\363\364\365\366"\
1522                         "\370\371\372\373\374\375\376\377"
1523
1524 /* Error types */
1525 typedef enum
1526 {
1527   G_ERR_UNKNOWN,
1528   G_ERR_UNEXP_EOF,
1529   G_ERR_UNEXP_EOF_IN_STRING,
1530   G_ERR_UNEXP_EOF_IN_COMMENT,
1531   G_ERR_NON_DIGIT_IN_CONST,
1532   G_ERR_DIGIT_RADIX,
1533   G_ERR_FLOAT_RADIX,
1534   G_ERR_FLOAT_MALFORMED
1535 } GErrorType;
1536
1537 /* Token types */
1538 typedef enum
1539 {
1540   G_TOKEN_EOF                   =   0,
1541
1542   G_TOKEN_LEFT_PAREN            = '(',
1543   G_TOKEN_RIGHT_PAREN           = ')',
1544   G_TOKEN_LEFT_CURLY            = '{',
1545   G_TOKEN_RIGHT_CURLY           = '}',
1546   G_TOKEN_LEFT_BRACE            = '[',
1547   G_TOKEN_RIGHT_BRACE           = ']',
1548   G_TOKEN_EQUAL_SIGN            = '=',
1549   G_TOKEN_COMMA                 = ',',
1550
1551   G_TOKEN_NONE                  = 256,
1552
1553   G_TOKEN_ERROR,
1554
1555   G_TOKEN_CHAR,
1556   G_TOKEN_BINARY,
1557   G_TOKEN_OCTAL,
1558   G_TOKEN_INT,
1559   G_TOKEN_HEX,
1560   G_TOKEN_FLOAT,
1561   G_TOKEN_STRING,
1562
1563   G_TOKEN_SYMBOL,
1564   G_TOKEN_IDENTIFIER,
1565   G_TOKEN_IDENTIFIER_NULL,
1566
1567   G_TOKEN_COMMENT_SINGLE,
1568   G_TOKEN_COMMENT_MULTI,
1569   G_TOKEN_LAST
1570 } GTokenType;
1571
1572 union   _GTokenValue
1573 {
1574   gpointer      v_symbol;
1575   gchar         *v_identifier;
1576   gulong        v_binary;
1577   gulong        v_octal;
1578   gulong        v_int;
1579   gdouble       v_float;
1580   gulong        v_hex;
1581   gchar         *v_string;
1582   gchar         *v_comment;
1583   guchar        v_char;
1584   guint         v_error;
1585 };
1586
1587 struct  _GScannerConfig
1588 {
1589   /* Character sets
1590    */
1591   gchar         *cset_skip_characters;          /* default: " \t\n" */
1592   gchar         *cset_identifier_first;
1593   gchar         *cset_identifier_nth;
1594   gchar         *cpair_comment_single;          /* default: "#\n" */
1595
1596   /* Should symbol lookup work case sensitive?
1597    */
1598   guint         case_sensitive : 1;
1599
1600   /* Boolean values to be adjusted "on the fly"
1601    * to configure scanning behaviour.
1602    */
1603   guint         skip_comment_multi : 1;         /* C like comment */
1604   guint         skip_comment_single : 1;        /* single line comment */
1605   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1606   guint         scan_identifier : 1;
1607   guint         scan_identifier_1char : 1;
1608   guint         scan_identifier_NULL : 1;
1609   guint         scan_symbols : 1;
1610   guint         scan_binary : 1;
1611   guint         scan_octal : 1;
1612   guint         scan_float : 1;
1613   guint         scan_hex : 1;                   /* `0x0ff0' */
1614   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1615   guint         scan_string_sq : 1;             /* string: 'anything' */
1616   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1617   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
1618   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
1619   guint         identifier_2_string : 1;
1620   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
1621   guint         symbol_2_token : 1;
1622   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
1623 };
1624
1625 struct  _GScanner
1626 {
1627   /* unused fields */
1628   gpointer              user_data;
1629   guint                 max_parse_errors;
1630
1631   /* g_scanner_error() increments this field */
1632   guint                 parse_errors;
1633
1634   /* name of input stream, featured by the default message handler */
1635   const gchar           *input_name;
1636
1637   /* data pointer for derived structures */
1638   gpointer              derived_data;
1639
1640   /* link into the scanner configuration */
1641   GScannerConfig        *config;
1642
1643   /* fields filled in after g_scanner_get_next_token() */
1644   GTokenType            token;
1645   GTokenValue           value;
1646   guint                 line;
1647   guint                 position;
1648
1649   /* fields filled in after g_scanner_peek_next_token() */
1650   GTokenType            next_token;
1651   GTokenValue           next_value;
1652   guint                 next_line;
1653   guint                 next_position;
1654
1655   /* to be considered private */
1656   GHashTable            *symbol_table;
1657   gint                  input_fd;
1658   const gchar           *text;
1659   const gchar           *text_end;
1660   gchar                 *buffer;
1661   guint                 scope_id;
1662
1663   /* handler function for _warn and _error */
1664   GScannerMsgFunc       msg_handler;
1665 };
1666
1667 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
1668 void            g_scanner_destroy               (GScanner       *scanner);
1669 void            g_scanner_input_file            (GScanner       *scanner,
1670                                                  gint           input_fd);
1671 void            g_scanner_input_text            (GScanner       *scanner,
1672                                                  const  gchar   *text,
1673                                                  guint          text_len);
1674 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
1675 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
1676 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
1677 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
1678 guint           g_scanner_cur_line              (GScanner       *scanner);
1679 guint           g_scanner_cur_position          (GScanner       *scanner);
1680 gboolean        g_scanner_eof                   (GScanner       *scanner);
1681 guint           g_scanner_set_scope             (GScanner       *scanner,
1682                                                  guint           scope_id);
1683 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
1684                                                  guint           scope_id,
1685                                                  const gchar    *symbol,
1686                                                  gpointer       value);
1687 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
1688                                                  guint           scope_id,
1689                                                  const gchar    *symbol);
1690 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
1691                                                  guint           scope_id,
1692                                                  const gchar    *symbol);
1693 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
1694                                                  guint           scope_id,
1695                                                  GHFunc          func,
1696                                                  gpointer        func_data);
1697 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
1698                                                  const gchar    *symbol);
1699 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
1700 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
1701 void            g_scanner_unexp_token           (GScanner       *scanner,
1702                                                  GTokenType     expected_token,
1703                                                  const gchar    *identifier_spec,
1704                                                  const gchar    *symbol_spec,
1705                                                  const gchar    *symbol_name,
1706                                                  const gchar    *message,
1707                                                  gint            is_error);
1708 void            g_scanner_error                 (GScanner       *scanner,
1709                                                  const gchar    *format,
1710                                                  ...) G_GNUC_PRINTF (2,3);
1711 void            g_scanner_warn                  (GScanner       *scanner,
1712                                                  const gchar    *format,
1713                                                  ...) G_GNUC_PRINTF (2,3);
1714 gint            g_scanner_stat_mode             (const gchar    *filename);
1715 /* keep downward source compatibility */
1716 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
1717   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
1718 } G_STMT_END
1719 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
1720   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
1721 } G_STMT_END
1722 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
1723   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
1724 } G_STMT_END
1725
1726
1727 /* Completion */
1728
1729 struct _GCompletion
1730 {
1731   GList* items;
1732   GCompletionFunc func;
1733
1734   gchar* prefix;
1735   GList* cache;
1736 };
1737
1738 GCompletion* g_completion_new          (GCompletionFunc func);
1739 void         g_completion_add_items    (GCompletion*    cmp,
1740                                         GList*          items);
1741 void         g_completion_remove_items (GCompletion*    cmp,
1742                                         GList*          items);
1743 void         g_completion_clear_items  (GCompletion*    cmp);
1744 GList*       g_completion_complete     (GCompletion*    cmp,
1745                                         gchar*          prefix,
1746                                         gchar**         new_prefix);
1747 void         g_completion_free         (GCompletion*    cmp);
1748
1749
1750 /* GRelation: Indexed Relations.  Imagine a really simple table in a
1751  * database.  Relations are not ordered.  This data type is meant for
1752  * maintaining a N-way mapping.
1753  *
1754  * g_relation_new() creates a relation with FIELDS fields
1755  *
1756  * g_relation_destroy() frees all resources
1757  * g_tuples_destroy() frees the result of g_relation_select()
1758  *
1759  * g_relation_index() indexes relation FIELD with the provided
1760  *   equality and hash functions.  this must be done before any
1761  *   calls to insert are made.
1762  *
1763  * g_relation_insert() inserts a new tuple.  you are expected to
1764  *   provide the right number of fields.
1765  *
1766  * g_relation_delete() deletes all relations with KEY in FIELD
1767  * g_relation_select() returns ...
1768  * g_relation_count() counts ...
1769  */
1770
1771 GRelation* g_relation_new     (gint         fields);
1772 void       g_relation_destroy (GRelation   *relation);
1773 void       g_relation_index   (GRelation   *relation,
1774                                gint         field,
1775                                GHashFunc    hash_func,
1776                                GCompareFunc key_compare_func);
1777 void       g_relation_insert  (GRelation   *relation,
1778                                ...);
1779 gint       g_relation_delete  (GRelation   *relation,
1780                                gconstpointer  key,
1781                                gint         field);
1782 GTuples*   g_relation_select  (GRelation   *relation,
1783                                gconstpointer  key,
1784                                gint         field);
1785 gint       g_relation_count   (GRelation   *relation,
1786                                gconstpointer  key,
1787                                gint         field);
1788 gboolean   g_relation_exists  (GRelation   *relation,
1789                                ...);
1790 void       g_relation_print   (GRelation   *relation);
1791
1792 void       g_tuples_destroy   (GTuples     *tuples);
1793 gpointer   g_tuples_index     (GTuples     *tuples,
1794                                gint         index,
1795                                gint         field);
1796
1797
1798 /* Prime numbers.
1799  */
1800
1801 /* This function returns prime numbers spaced by approximately 1.5-2.0
1802  * and is for use in resizing data structures which prefer
1803  * prime-valued sizes.  The closest spaced prime function returns the
1804  * next largest prime, or the highest it knows about which is about
1805  * MAXINT/4.
1806  */
1807
1808 guint      g_spaced_primes_closest (guint num);
1809
1810 /* Glib version.
1811  */
1812 extern const guint glib_major_version;
1813 extern const guint glib_minor_version;
1814 extern const guint glib_micro_version;
1815
1816 #ifdef __cplusplus
1817 }
1818 #endif /* __cplusplus */
1819
1820
1821 #endif /* __G_LIB_H__ */