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