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