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