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