567bf5949789940b3983d2bcfec0ad5e98378b93
[platform/upstream/glib.git] / glib / glib.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_LIB_H__
28 #define __G_LIB_H__
29
30 /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
31  * where this is valid. This allows for warningless compilation of
32  * "long long" types even in the presence of '-ansi -pedantic'. This
33  * of course should be with the other GCC-isms below, but then
34  * glibconfig.h wouldn't load cleanly and it is better to have that
35  * here, than in glibconfig.h.  
36  */
37 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
38 #  define G_GNUC_EXTENSION __extension__
39 #else
40 #  define G_GNUC_EXTENSION
41 #endif
42
43 /* system specific config file glibconfig.h provides definitions for
44  * the extrema of many of the standard types. These are:
45  *
46  *  G_MINSHORT, G_MAXSHORT
47  *  G_MININT, G_MAXINT
48  *  G_MINLONG, G_MAXLONG
49  *  G_MINFLOAT, G_MAXFLOAT
50  *  G_MINDOUBLE, G_MAXDOUBLE
51  *
52  * It also provides the following typedefs:
53  *
54  *  gint8, guint8
55  *  gint16, guint16
56  *  gint32, guint32
57  *  gint64, guint64
58  *  gssize, gsize
59  *
60  * It defines the G_BYTE_ORDER symbol to one of G_*_ENDIAN (see later in
61  * this file). 
62  *
63  * And it provides a way to store and retrieve a `gint' in/from a `gpointer'.
64  * This is useful to pass an integer instead of a pointer to a callback.
65  *
66  *  GINT_TO_POINTER (i), GUINT_TO_POINTER (i)
67  *  GPOINTER_TO_INT (p), GPOINTER_TO_UINT (p)
68  *
69  * Finally, it provides the following wrappers to STDC functions:
70  *
71  *  void g_memmove (gpointer dest, gconstpointer void *src, gulong count);
72  *    A wrapper for STDC memmove, or an implementation, if memmove doesn't
73  *    exist.  The prototype looks like the above, give or take a const,
74  *    or size_t.
75  */
76 #include <glibconfig.h>
77
78 /* Define some mathematical constants that aren't available
79  * symbolically in some strict ISO C implementations.
80  */
81 #define G_E     2.7182818284590452354E0
82 #define G_LN2   6.9314718055994530942E-1
83 #define G_LN10  2.3025850929940456840E0
84 #define G_PI    3.14159265358979323846E0
85 #define G_PI_2  1.57079632679489661923E0
86 #define G_PI_4  0.78539816339744830962E0
87 #define G_SQRT2 1.4142135623730950488E0
88
89 /* include varargs functions for assertment macros
90  */
91 #include <stdarg.h>
92
93 /* optionally feature DMALLOC memory allocation debugger
94  */
95 #ifdef USE_DMALLOC
96 #include "dmalloc.h"
97 #endif
98
99
100 #ifdef G_OS_WIN32
101
102 /* On native Win32, directory separator is the backslash, and search path
103  * separator is the semicolon.
104  */
105 #define G_DIR_SEPARATOR '\\'
106 #define G_DIR_SEPARATOR_S "\\"
107 #define G_SEARCHPATH_SEPARATOR ';'
108 #define G_SEARCHPATH_SEPARATOR_S ";"
109
110 #else  /* !G_OS_WIN32 */
111
112 /* Unix */
113
114 #define G_DIR_SEPARATOR '/'
115 #define G_DIR_SEPARATOR_S "/"
116 #define G_SEARCHPATH_SEPARATOR ':'
117 #define G_SEARCHPATH_SEPARATOR_S ":"
118
119 #endif /* !G_OS_WIN32 */
120
121 #ifdef __cplusplus
122 extern "C" {
123 #endif /* __cplusplus */
124
125
126 /* Provide definitions for some commonly used macros.
127  *  Some of them are only provided if they haven't already
128  *  been defined. It is assumed that if they are already
129  *  defined then the current definition is correct.
130  */
131 #ifndef NULL
132 #  ifdef __cplusplus
133 #    define NULL        (0L)
134 #  else /* !__cplusplus */
135 #    define NULL        ((void*) 0)
136 #  endif /* !__cplusplus */
137 #endif
138
139 #ifndef FALSE
140 #define FALSE   (0)
141 #endif
142
143 #ifndef TRUE
144 #define TRUE    (!FALSE)
145 #endif
146
147 #undef  MAX
148 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
149
150 #undef  MIN
151 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
152
153 #undef  ABS
154 #define ABS(a)     (((a) < 0) ? -(a) : (a))
155
156 #undef  CLAMP
157 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
158
159 #define G_STRINGIFY(macro_or_string)    G_STRINGIFY_ARG (macro_or_string)
160 #define G_STRINGIFY_ARG(contents)       #contents
161
162 /* provide a string identifying the current code position */
163 #ifdef  __GNUC__
164 #  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
165 #else
166 #  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
167 #endif
168
169
170 /* Count the number of elements in an array. The array must be defined
171  * as such; using this with a dynamically allocated array will give
172  * incorrect results.
173  */
174 #define G_N_ELEMENTS(arr)               (sizeof (arr) / sizeof ((arr)[0]))
175
176 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
177  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
178  */
179 #if !defined (G_VA_COPY)
180 #  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
181 #  define G_VA_COPY(ap1, ap2)     (*(ap1) = *(ap2))
182 #  elif defined (G_VA_COPY_AS_ARRAY)
183 #  define G_VA_COPY(ap1, ap2)     g_memmove ((ap1), (ap2), sizeof (va_list))
184 #  else /* va_list is a pointer */
185 #  define G_VA_COPY(ap1, ap2)     ((ap1) = (ap2))
186 #  endif /* va_list is a pointer */
187 #endif /* !G_VA_COPY */
188
189
190 /* Provide convenience macros for handling structure
191  * fields through their offsets.
192  */
193 #define G_STRUCT_OFFSET(struct_type, member)    \
194     ((glong) ((guint8*) &((struct_type*) 0)->member))
195 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
196     ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
197 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
198     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
199
200
201 /* inlining hassle. for compilers that don't allow the `inline' keyword,
202  * mostly because of strict ANSI C compliance or dumbness, we try to fall
203  * back to either `__inline__' or `__inline'.
204  * we define G_CAN_INLINE, if the compiler seems to be actually
205  * *capable* to do function inlining, in which case inline function bodys
206  * do make sense. we also define G_INLINE_FUNC to properly export the
207  * function prototypes if no inlining can be performed.
208  * we special case most of the stuff, so inline functions can have a normal
209  * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
210  */
211 #ifndef G_INLINE_FUNC
212 #  define G_CAN_INLINE 1
213 #endif
214 #ifdef G_HAVE_INLINE
215 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
216 #    undef inline
217 #    define inline __inline__
218 #  endif
219 #else /* !G_HAVE_INLINE */
220 #  undef inline
221 #  if defined (G_HAVE___INLINE__)
222 #    define inline __inline__
223 #  else /* !inline && !__inline__ */
224 #    if defined (G_HAVE___INLINE)
225 #      define inline __inline
226 #    else /* !inline && !__inline__ && !__inline */
227 #      define inline /* don't inline, then */
228 #      ifndef G_INLINE_FUNC
229 #        undef G_CAN_INLINE
230 #      endif
231 #    endif
232 #  endif
233 #endif
234 #ifndef G_INLINE_FUNC
235 #  ifdef __GNUC__
236 #    ifdef __OPTIMIZE__
237 #      define G_INLINE_FUNC extern inline
238 #    else
239 #      undef G_CAN_INLINE
240 #      define G_INLINE_FUNC extern
241 #    endif
242 #  else /* !__GNUC__ */
243 #    ifdef G_CAN_INLINE
244 #      define G_INLINE_FUNC static inline
245 #    else
246 #      define G_INLINE_FUNC extern
247 #    endif
248 #  endif /* !__GNUC__ */
249 #endif /* !G_INLINE_FUNC */
250
251
252 /* Provide simple macro statement wrappers (adapted from Perl):
253  *  G_STMT_START { statements; } G_STMT_END;
254  *  can be used as a single statement, as in
255  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
256  *
257  *  For gcc we will wrap the statements within `({' and `})' braces.
258  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
259  *  and otherwise within `do' and `while (0)'.
260  */
261 #if !(defined (G_STMT_START) && defined (G_STMT_END))
262 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
263 #    define G_STMT_START        (void)(
264 #    define G_STMT_END          )
265 #  else
266 #    if (defined (sun) || defined (__sun__))
267 #      define G_STMT_START      if (1)
268 #      define G_STMT_END        else (void)0
269 #    else
270 #      define G_STMT_START      do
271 #      define G_STMT_END        while (0)
272 #    endif
273 #  endif
274 #endif
275
276
277 /* Provide macros to feature the GCC function attribute.
278  */
279 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
280 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
281   __attribute__((format (printf, format_idx, arg_idx)))
282 #define G_GNUC_SCANF( format_idx, arg_idx )     \
283   __attribute__((format (scanf, format_idx, arg_idx)))
284 #define G_GNUC_FORMAT( arg_idx )                \
285   __attribute__((format_arg (arg_idx)))
286 #define G_GNUC_NORETURN                         \
287   __attribute__((noreturn))
288 #define G_GNUC_CONST                            \
289   __attribute__((const))
290 #define G_GNUC_UNUSED                           \
291   __attribute__((unused))
292 #else   /* !__GNUC__ */
293 #define G_GNUC_PRINTF( format_idx, arg_idx )
294 #define G_GNUC_SCANF( format_idx, arg_idx )
295 #define G_GNUC_FORMAT( arg_idx )
296 #define G_GNUC_NORETURN
297 #define G_GNUC_CONST
298 #define G_GNUC_UNUSED
299 #endif  /* !__GNUC__ */
300
301 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
302  * macros, so we can refer to them as strings unconditionally.
303  */
304 #ifdef  __GNUC__
305 #define G_GNUC_FUNCTION         __FUNCTION__
306 #define G_GNUC_PRETTY_FUNCTION  __PRETTY_FUNCTION__
307 #else   /* !__GNUC__ */
308 #define G_GNUC_FUNCTION         ""
309 #define G_GNUC_PRETTY_FUNCTION  ""
310 #endif  /* !__GNUC__ */
311
312 /* we try to provide a usefull equivalent for ATEXIT if it is
313  * not defined, but use is actually abandoned. people should
314  * use g_atexit() instead.
315  */
316 #ifndef ATEXIT
317 # define ATEXIT(proc)   g_ATEXIT(proc)
318 #else
319 # define G_NATIVE_ATEXIT
320 #endif /* ATEXIT */
321
322 /* Hacker macro to place breakpoints for elected machines.
323  * Actual use is strongly deprecated of course ;)
324  */
325 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
326 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
327 #elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2
328 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
329 #else   /* !__i386__ && !__alpha__ */
330 #define G_BREAKPOINT()
331 #endif  /* __i386__ */
332
333
334 /* Provide macros for easily allocating memory. The macros
335  *  will cast the allocated memory to the specified type
336  *  in order to avoid compiler warnings. (Makes the code neater).
337  */
338
339 #ifdef __DMALLOC_H__
340 #  define g_new(type, count)            (ALLOC (type, count))
341 #  define g_new0(type, count)           (CALLOC (type, count))
342 #  define g_renew(type, mem, count)     (REALLOC (mem, type, count))
343 #else /* __DMALLOC_H__ */
344 #  define g_new(type, count)      \
345       ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
346 #  define g_new0(type, count)     \
347       ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
348 #  define g_renew(type, mem, count)       \
349       ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
350 #endif /* __DMALLOC_H__ */
351
352 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
353   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
354                    sizeof (type), \
355                    sizeof (type) * (pre_alloc), \
356                    (alloc_type)) \
357 )
358 #define g_chunk_new(type, chunk)        ( \
359   (type *) g_mem_chunk_alloc (chunk) \
360 )
361 #define g_chunk_new0(type, chunk)       ( \
362   (type *) g_mem_chunk_alloc0 (chunk) \
363 )
364 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
365   g_mem_chunk_free ((mem_chunk), (mem)); \
366 } G_STMT_END
367
368
369 /* Provide macros for error handling. The "assert" macros will
370  *  exit on failure. The "return" macros will exit the current
371  *  function. Two different definitions are given for the macros
372  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
373  *  __PRETTY_FUNCTION__ capability.
374  */
375
376 #ifdef G_DISABLE_ASSERT
377
378 #define g_assert(expr)
379 #define g_assert_not_reached()
380
381 #else /* !G_DISABLE_ASSERT */
382
383 #ifdef __GNUC__
384
385 #define g_assert(expr)                  G_STMT_START{           \
386      if (!(expr))                                               \
387        g_log (G_LOG_DOMAIN,                                     \
388               G_LOG_LEVEL_ERROR,                                \
389               "file %s: line %d (%s): assertion failed: (%s)",  \
390               __FILE__,                                         \
391               __LINE__,                                         \
392               __PRETTY_FUNCTION__,                              \
393               #expr);                   }G_STMT_END
394
395 #define g_assert_not_reached()          G_STMT_START{           \
396      g_log (G_LOG_DOMAIN,                                       \
397             G_LOG_LEVEL_ERROR,                                  \
398             "file %s: line %d (%s): should not be reached",     \
399             __FILE__,                                           \
400             __LINE__,                                           \
401             __PRETTY_FUNCTION__);       }G_STMT_END
402
403 #else /* !__GNUC__ */
404
405 #define g_assert(expr)                  G_STMT_START{           \
406      if (!(expr))                                               \
407        g_log (G_LOG_DOMAIN,                                     \
408               G_LOG_LEVEL_ERROR,                                \
409               "file %s: line %d: assertion failed: (%s)",       \
410               __FILE__,                                         \
411               __LINE__,                                         \
412               #expr);                   }G_STMT_END
413
414 #define g_assert_not_reached()          G_STMT_START{   \
415      g_log (G_LOG_DOMAIN,                               \
416             G_LOG_LEVEL_ERROR,                          \
417             "file %s: line %d: should not be reached",  \
418             __FILE__,                                   \
419             __LINE__);          }G_STMT_END
420
421 #endif /* __GNUC__ */
422
423 #endif /* !G_DISABLE_ASSERT */
424
425
426 #ifdef G_DISABLE_CHECKS
427
428 #define g_return_if_fail(expr)
429 #define g_return_val_if_fail(expr,val)
430 #define g_return_if_reached() return
431 #define g_return_val_if_reached(val) return (val)
432
433 #else /* !G_DISABLE_CHECKS */
434
435 #ifdef __GNUC__
436
437 #define g_return_if_fail(expr)          G_STMT_START{                   \
438      if (!(expr))                                                       \
439        {                                                                \
440          g_log (G_LOG_DOMAIN,                                           \
441                 G_LOG_LEVEL_CRITICAL,                                   \
442                 "file %s: line %d (%s): assertion `%s' failed",         \
443                 __FILE__,                                               \
444                 __LINE__,                                               \
445                 __PRETTY_FUNCTION__,                                    \
446                 #expr);                                                 \
447          return;                                                        \
448        };                               }G_STMT_END
449
450 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
451      if (!(expr))                                                       \
452        {                                                                \
453          g_log (G_LOG_DOMAIN,                                           \
454                 G_LOG_LEVEL_CRITICAL,                                   \
455                 "file %s: line %d (%s): assertion `%s' failed",         \
456                 __FILE__,                                               \
457                 __LINE__,                                               \
458                 __PRETTY_FUNCTION__,                                    \
459                 #expr);                                                 \
460          return (val);                                                  \
461        };                               }G_STMT_END
462
463 #define g_return_if_reached()           G_STMT_START{                   \
464      g_log (G_LOG_DOMAIN,                                               \
465             G_LOG_LEVEL_CRITICAL,                                       \
466             "file %s: line %d (%s): should not be reached",             \
467             __FILE__,                                                   \
468             __LINE__,                                                   \
469             __PRETTY_FUNCTION__);                                       \
470      return;                            }G_STMT_END
471
472 #define g_return_val_if_reached(val)    G_STMT_START{                   \
473      g_log (G_LOG_DOMAIN,                                               \
474             G_LOG_LEVEL_CRITICAL,                                       \
475             "file %s: line %d (%s): should not be reached",             \
476             __FILE__,                                                   \
477             __LINE__,                                                   \
478             __PRETTY_FUNCTION__);                                       \
479      return (val);                      }G_STMT_END
480
481 #else /* !__GNUC__ */
482
483 #define g_return_if_fail(expr)          G_STMT_START{           \
484      if (!(expr))                                               \
485        {                                                        \
486          g_log (G_LOG_DOMAIN,                                   \
487                 G_LOG_LEVEL_CRITICAL,                           \
488                 "file %s: line %d: assertion `%s' failed",      \
489                 __FILE__,                                       \
490                 __LINE__,                                       \
491                 #expr);                                         \
492          return;                                                \
493        };                               }G_STMT_END
494
495 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
496      if (!(expr))                                               \
497        {                                                        \
498          g_log (G_LOG_DOMAIN,                                   \
499                 G_LOG_LEVEL_CRITICAL,                           \
500                 "file %s: line %d: assertion `%s' failed",      \
501                 __FILE__,                                       \
502                 __LINE__,                                       \
503                 #expr);                                         \
504          return (val);                                          \
505        };                               }G_STMT_END
506
507 #define g_return_if_reached()           G_STMT_START{           \
508      g_log (G_LOG_DOMAIN,                                       \
509             G_LOG_LEVEL_CRITICAL,                               \
510             "file %s: line %d: should not be reached",          \
511             __FILE__,                                           \
512             __LINE__);                                          \
513      return;                            }G_STMT_END
514
515 #define g_return_val_if_reached(val)    G_STMT_START{           \
516      g_log (G_LOG_DOMAIN,                                       \
517             G_LOG_LEVEL_CRITICAL,                               \
518             "file %s: line %d: should not be reached",          \
519             __FILE__,                                           \
520             __LINE__);                                          \
521      return (val);                      }G_STMT_END
522
523 #endif /* !__GNUC__ */
524
525 #endif /* !G_DISABLE_CHECKS */
526
527
528 /* Provide type definitions for commonly used types.
529  *  These are useful because a "gint8" can be adjusted
530  *  to be 1 byte (8 bits) on all platforms. Similarly and
531  *  more importantly, "gint32" can be adjusted to be
532  *  4 bytes (32 bits) on all platforms.
533  */
534
535 typedef char   gchar;
536 typedef short  gshort;
537 typedef long   glong;
538 typedef int    gint;
539 typedef gint   gboolean;
540 typedef gchar* gstring;
541
542 typedef unsigned char   guchar;
543 typedef unsigned short  gushort;
544 typedef unsigned long   gulong;
545 typedef unsigned int    guint;
546
547 #define G_GSHORT_FORMAT  "hi"
548 #define G_GUSHORT_FORMAT "hu"
549 #define G_GINT_FORMAT    "i"
550 #define G_GUINT_FORMAT   "u"
551 #define G_GLONG_FORMAT   "li"
552 #define G_GULONG_FORMAT  "lu"
553
554 typedef float   gfloat;
555 typedef double  gdouble;
556
557 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
558  * Since gldouble isn't used anywhere, just disable it for now */
559
560 #if 0
561 #ifdef HAVE_LONG_DOUBLE
562 typedef long double gldouble;
563 #else /* HAVE_LONG_DOUBLE */
564 typedef double gldouble;
565 #endif /* HAVE_LONG_DOUBLE */
566 #endif /* 0 */
567
568 typedef void* gpointer;
569 typedef const void *gconstpointer;
570
571
572 typedef guint32 GQuark;
573 typedef gint32  GTime;
574
575
576 /* Portable endian checks and conversions
577  *
578  * glibconfig.h defines G_BYTE_ORDER which expands to one of
579  * the below macros.
580  */
581 #define G_LITTLE_ENDIAN 1234
582 #define G_BIG_ENDIAN    4321
583 #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
584
585
586 /* Basic bit swapping functions
587  */
588 #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
589     (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
590     (((guint16) (val) & (guint16) 0xff00U) >> 8)))
591 #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
592     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
593     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
594     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
595     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
596
597 /* Intel specific stuff for speed
598  */
599 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
600 #  define GUINT16_SWAP_LE_BE_X86(val) \
601      (__extension__                                     \
602       ({ register guint16 __v;                          \
603          if (__builtin_constant_p (val))                \
604            __v = GUINT16_SWAP_LE_BE_CONSTANT (val);     \
605          else                                           \
606            __asm__ __const__ ("rorw $8, %w0"            \
607                               : "=r" (__v)              \
608                               : "0" ((guint16) (val))); \
609         __v; }))
610 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val))
611 #  if !defined(__i486__) && !defined(__i586__) \
612       && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__)
613 #     define GUINT32_SWAP_LE_BE_X86(val) \
614         (__extension__                                          \
615          ({ register guint32 __v;                               \
616             if (__builtin_constant_p (val))                     \
617               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
618           else                                                  \
619             __asm__ __const__ ("rorw $8, %w0\n\t"               \
620                                "rorl $16, %0\n\t"               \
621                                "rorw $8, %w0"                   \
622                                : "=r" (__v)                     \
623                                : "0" ((guint32) (val)));        \
624         __v; }))
625 #  else /* 486 and higher has bswap */
626 #     define GUINT32_SWAP_LE_BE_X86(val) \
627         (__extension__                                          \
628          ({ register guint32 __v;                               \
629             if (__builtin_constant_p (val))                     \
630               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
631           else                                                  \
632             __asm__ __const__ ("bswap %0"                       \
633                                : "=r" (__v)                     \
634                                : "0" ((guint32) (val)));        \
635         __v; }))
636 #  endif /* processor specific 32-bit stuff */
637 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val))
638 #else /* !__i386__ */
639 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
640 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
641 #endif /* __i386__ */
642
643 #ifdef G_HAVE_GINT64
644 #  define GUINT64_SWAP_LE_BE_CONSTANT(val)      ((guint64) ( \
645       (((guint64) (val) &                                               \
646         (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) |      \
647       (((guint64) (val) &                                               \
648         (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) |      \
649       (((guint64) (val) &                                               \
650         (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) |      \
651       (((guint64) (val) &                                               \
652         (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) <<  8) |      \
653       (((guint64) (val) &                                               \
654         (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >>  8) |      \
655       (((guint64) (val) &                                               \
656         (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) |      \
657       (((guint64) (val) &                                               \
658         (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) |      \
659       (((guint64) (val) &                                               \
660         (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56)))
661 #  if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
662 #    define GUINT64_SWAP_LE_BE_X86(val) \
663         (__extension__                                          \
664          ({ union { guint64 __ll;                               \
665                     guint32 __l[2]; } __r;                      \
666             if (__builtin_constant_p (val))                     \
667               __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val);     \
668             else                                                \
669               {                                                 \
670                 union { guint64 __ll;                           \
671                         guint32 __l[2]; } __w;                  \
672                 __w.__ll = ((guint64) val);                     \
673                 __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]);   \
674                 __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]);   \
675               }                                                 \
676           __r.__ll; }))
677 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val))
678 #  else /* !__i386__ */
679 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val))
680 #  endif
681 #endif
682
683 #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
684 #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
685 #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
686     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
687     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
688 #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
689     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
690     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
691
692 /* The G*_TO_?E() macros are defined in glibconfig.h.
693  * The transformation is symmetric, so the FROM just maps to the TO.
694  */
695 #define GINT16_FROM_LE(val)     (GINT16_TO_LE (val))
696 #define GUINT16_FROM_LE(val)    (GUINT16_TO_LE (val))
697 #define GINT16_FROM_BE(val)     (GINT16_TO_BE (val))
698 #define GUINT16_FROM_BE(val)    (GUINT16_TO_BE (val))
699 #define GINT32_FROM_LE(val)     (GINT32_TO_LE (val))
700 #define GUINT32_FROM_LE(val)    (GUINT32_TO_LE (val))
701 #define GINT32_FROM_BE(val)     (GINT32_TO_BE (val))
702 #define GUINT32_FROM_BE(val)    (GUINT32_TO_BE (val))
703
704 #ifdef G_HAVE_GINT64
705 #define GINT64_FROM_LE(val)     (GINT64_TO_LE (val))
706 #define GUINT64_FROM_LE(val)    (GUINT64_TO_LE (val))
707 #define GINT64_FROM_BE(val)     (GINT64_TO_BE (val))
708 #define GUINT64_FROM_BE(val)    (GUINT64_TO_BE (val))
709 #endif
710
711 #define GLONG_FROM_LE(val)      (GLONG_TO_LE (val))
712 #define GULONG_FROM_LE(val)     (GULONG_TO_LE (val))
713 #define GLONG_FROM_BE(val)      (GLONG_TO_BE (val))
714 #define GULONG_FROM_BE(val)     (GULONG_TO_BE (val))
715
716 #define GINT_FROM_LE(val)       (GINT_TO_LE (val))
717 #define GUINT_FROM_LE(val)      (GUINT_TO_LE (val))
718 #define GINT_FROM_BE(val)       (GINT_TO_BE (val))
719 #define GUINT_FROM_BE(val)      (GUINT_TO_BE (val))
720
721
722 /* Portable versions of host-network order stuff
723  */
724 #define g_ntohl(val) (GUINT32_FROM_BE (val))
725 #define g_ntohs(val) (GUINT16_FROM_BE (val))
726 #define g_htonl(val) (GUINT32_TO_BE (val))
727 #define g_htons(val) (GUINT16_TO_BE (val))
728
729
730 /* Glib version.
731  * we prefix variable declarations so they can
732  * properly get exported in windows dlls.
733  */
734 #ifdef G_OS_WIN32
735 #  ifdef GLIB_COMPILATION
736 #    define GLIB_VAR __declspec(dllexport)
737 #  else /* !GLIB_COMPILATION */
738 #    define GLIB_VAR extern __declspec(dllimport)
739 #  endif /* !GLIB_COMPILATION */
740 #else /* !G_OS_WIN32 */
741 #  define GLIB_VAR extern
742 #endif /* !G_OS_WIN32 */
743
744 GLIB_VAR const guint glib_major_version;
745 GLIB_VAR const guint glib_minor_version;
746 GLIB_VAR const guint glib_micro_version;
747 GLIB_VAR const guint glib_interface_age;
748 GLIB_VAR const guint glib_binary_age;
749
750 #define GLIB_CHECK_VERSION(major,minor,micro)    \
751     (GLIB_MAJOR_VERSION > (major) || \
752      (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
753      (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
754       GLIB_MICRO_VERSION >= (micro)))
755
756 /* Forward declarations of glib types.
757  */
758 typedef struct _GAllocator      GAllocator;
759 typedef struct _GArray          GArray;
760 typedef struct _GByteArray      GByteArray;
761 typedef struct _GCache          GCache;
762 typedef struct _GCompletion     GCompletion;
763 typedef struct _GData           GData;
764 typedef struct _GDebugKey       GDebugKey;
765 typedef union  _GDoubleIEEE754  GDoubleIEEE754;
766 typedef union  _GFloatIEEE754   GFloatIEEE754;
767 typedef struct _GHashTable      GHashTable;
768 typedef struct _GHook           GHook;
769 typedef struct _GHookList       GHookList;
770 typedef struct _GList           GList;
771 typedef struct _GMemChunk       GMemChunk;
772 typedef struct _GNode           GNode;
773 typedef struct _GPtrArray       GPtrArray;
774 typedef struct _GQueue          GQueue;
775 typedef struct _GRand           GRand;
776 typedef struct _GRelation       GRelation;
777 typedef struct _GScanner        GScanner;
778 typedef struct _GScannerConfig  GScannerConfig;
779 typedef struct _GSList          GSList;
780 typedef struct _GString         GString;
781 typedef struct _GStringChunk    GStringChunk;
782 typedef struct _GTimer          GTimer;
783 typedef struct _GTrashStack     GTrashStack;
784 typedef struct _GTree           GTree;
785 typedef struct _GTuples         GTuples;
786 typedef union  _GTokenValue     GTokenValue;
787 typedef struct _GIOChannel      GIOChannel;
788
789 /* Tree traverse flags */
790 typedef enum
791 {
792   G_TRAVERSE_LEAFS      = 1 << 0,
793   G_TRAVERSE_NON_LEAFS  = 1 << 1,
794   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
795   G_TRAVERSE_MASK       = 0x03
796 } GTraverseFlags;
797
798 /* Tree traverse orders */
799 typedef enum
800 {
801   G_IN_ORDER,
802   G_PRE_ORDER,
803   G_POST_ORDER,
804   G_LEVEL_ORDER
805 } GTraverseType;
806
807 /* Log level shift offset for user defined
808  * log levels (0-7 are used by GLib).
809  */
810 #define G_LOG_LEVEL_USER_SHIFT  (8)
811
812 /* Glib log levels and flags.
813  */
814 typedef enum
815 {
816   /* log flags */
817   G_LOG_FLAG_RECURSION          = 1 << 0,
818   G_LOG_FLAG_FATAL              = 1 << 1,
819   
820   /* GLib log levels */
821   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
822   G_LOG_LEVEL_CRITICAL          = 1 << 3,
823   G_LOG_LEVEL_WARNING           = 1 << 4,
824   G_LOG_LEVEL_MESSAGE           = 1 << 5,
825   G_LOG_LEVEL_INFO              = 1 << 6,
826   G_LOG_LEVEL_DEBUG             = 1 << 7,
827   
828   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
829 } GLogLevelFlags;
830
831 /* GLib log levels that are considered fatal by default */
832 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
833
834
835 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
836 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
837 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
838 typedef gint            (*GCompareFunc)         (gconstpointer  a,
839                                                  gconstpointer  b);
840 typedef gchar*          (*GCompletionFunc)      (gpointer);
841 typedef void            (*GDestroyNotify)       (gpointer       data);
842 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
843                                                  gpointer       data,
844                                                  gpointer       user_data);
845 typedef void            (*GFunc)                (gpointer       data,
846                                                  gpointer       user_data);
847 typedef guint           (*GHashFunc)            (gconstpointer  key);
848 typedef void            (*GFreeFunc)            (gpointer       data);
849 typedef void            (*GHFunc)               (gpointer       key,
850                                                  gpointer       value,
851                                                  gpointer       user_data);
852 typedef gboolean        (*GHRFunc)              (gpointer       key,
853                                                  gpointer       value,
854                                                  gpointer       user_data);
855 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
856                                                  GHook          *sibling);
857 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
858                                                  gpointer        data);
859 typedef void            (*GHookMarshaller)      (GHook          *hook,
860                                                  gpointer        data);
861 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
862                                                  gpointer        data);
863 typedef void            (*GHookFunc)            (gpointer        data);
864 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
865 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
866                                                  GHook          *hook);
867 typedef void            (*GLogFunc)             (const gchar   *log_domain,
868                                                  GLogLevelFlags log_level,
869                                                  const gchar   *message,
870                                                  gpointer       user_data);
871 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
872                                                  gpointer       data);
873 typedef void            (*GNodeForeachFunc)     (GNode         *node,
874                                                  gpointer       data);
875 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
876                                                  gchar         *message,
877                                                  gint           error);
878 typedef gint            (*GTraverseFunc)        (gpointer       key,
879                                                  gpointer       value,
880                                                  gpointer       data);
881 typedef void            (*GVoidFunc)            (void);
882
883
884 struct _GArray
885 {
886   gchar *data;
887   guint len;
888 };
889
890 struct _GByteArray
891 {
892   guint8 *data;
893   guint   len;
894 };
895
896 struct _GDebugKey
897 {
898   gchar *key;
899   guint  value;
900 };
901
902 struct _GList
903 {
904   gpointer data;
905   GList *next;
906   GList *prev;
907 };
908
909 struct _GPtrArray
910 {
911   gpointer *pdata;
912   guint     len;
913 };
914
915 struct _GQueue
916 {
917   GList *head;
918   GList *tail;
919   guint  length;
920 };
921
922 struct _GSList
923 {
924   gpointer data;
925   GSList *next;
926 };
927
928 struct _GString
929 {
930   gchar *str;
931   gint len;
932 };
933
934 struct _GTrashStack
935 {
936   GTrashStack *next;
937 };
938
939 struct _GTuples
940 {
941   guint len;
942 };
943
944 #ifdef __cplusplus
945 }
946 #endif /* __cplusplus */
947
948 #include <gerror.h>
949
950 #ifdef __cplusplus
951 extern "C" {
952 #endif /* __cplusplus */
953
954 /* IEEE Standard 754 Single Precision Storage Format (gfloat):
955  *
956  *        31 30           23 22            0
957  * +--------+---------------+---------------+
958  * | s 1bit | e[30:23] 8bit | f[22:0] 23bit |
959  * +--------+---------------+---------------+
960  * B0------------------->B1------->B2-->B3-->
961  *
962  * IEEE Standard 754 Double Precision Storage Format (gdouble):
963  *
964  *        63 62            52 51            32   31            0
965  * +--------+----------------+----------------+ +---------------+
966  * | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit |
967  * +--------+----------------+----------------+ +---------------+
968  * B0--------------->B1---------->B2--->B3---->  B4->B5->B6->B7->
969  */
970 /* subtract from biased_exponent to form base2 exponent (normal numbers) */
971 #define G_IEEE754_FLOAT_BIAS    (127)
972 #define G_IEEE754_DOUBLE_BIAS   (1023)
973 /* multiply with base2 exponent to get base10 exponent (nomal numbers) */
974 #define G_LOG_2_BASE_10         (0.30102999566398119521)
975 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
976 union _GFloatIEEE754
977 {
978   gfloat v_float;
979   struct {
980     guint mantissa : 23;
981     guint biased_exponent : 8;
982     guint sign : 1;
983   } mpn;
984 };
985 union _GDoubleIEEE754
986 {
987   gdouble v_double;
988   struct {
989     guint mantissa_low : 32;
990     guint mantissa_high : 20;
991     guint biased_exponent : 11;
992     guint sign : 1;
993   } mpn;
994 };
995 #elif G_BYTE_ORDER == G_BIG_ENDIAN
996 union _GFloatIEEE754
997 {
998   gfloat v_float;
999   struct {
1000     guint sign : 1;
1001     guint biased_exponent : 8;
1002     guint mantissa : 23;
1003   } mpn;
1004 };
1005 union _GDoubleIEEE754
1006 {
1007   gdouble v_double;
1008   struct {
1009     guint sign : 1;
1010     guint biased_exponent : 11;
1011     guint mantissa_high : 20;
1012     guint mantissa_low : 32;
1013   } mpn;
1014 };
1015 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
1016 #error unknown ENDIAN type
1017 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
1018
1019
1020 /* Doubly linked lists
1021  */
1022 void   g_list_push_allocator    (GAllocator     *allocator);
1023 void   g_list_pop_allocator     (void);
1024 GList* g_list_alloc             (void);
1025 void   g_list_free              (GList          *list);
1026 void   g_list_free_1            (GList          *list);
1027 GList* g_list_append            (GList          *list,
1028                                  gpointer        data);
1029 GList* g_list_prepend           (GList          *list,
1030                                  gpointer        data);
1031 GList* g_list_insert            (GList          *list,
1032                                  gpointer        data,
1033                                  gint            position);
1034 GList* g_list_insert_sorted     (GList          *list,
1035                                  gpointer        data,
1036                                  GCompareFunc    func);
1037 GList* g_list_concat            (GList          *list1,
1038                                  GList          *list2);
1039 GList* g_list_remove            (GList          *list,
1040                                  gconstpointer   data);
1041 GList* g_list_remove_link       (GList          *list,
1042                                  GList          *llink);
1043 GList* g_list_delete_link       (GList          *list,
1044                                  GList          *link);
1045 GList* g_list_reverse           (GList          *list);
1046 GList* g_list_copy              (GList          *list);
1047 GList* g_list_nth               (GList          *list,
1048                                  guint           n);
1049 GList* g_list_find              (GList          *list,
1050                                  gconstpointer   data);
1051 GList* g_list_find_custom       (GList          *list,
1052                                  gconstpointer   data,
1053                                  GCompareFunc    func);
1054 gint   g_list_position          (GList          *list,
1055                                  GList          *llink);
1056 gint   g_list_index             (GList          *list,
1057                                  gconstpointer   data);
1058 GList* g_list_last              (GList          *list);
1059 GList* g_list_first             (GList          *list);
1060 guint  g_list_length            (GList          *list);
1061 void   g_list_foreach           (GList          *list,
1062                                  GFunc           func,
1063                                  gpointer        user_data);
1064 GList* g_list_sort              (GList          *list,
1065                                  GCompareFunc    compare_func);
1066 gpointer g_list_nth_data        (GList          *list,
1067                                  guint           n);
1068 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
1069 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
1070
1071
1072 /* Singly linked lists
1073  */
1074 void    g_slist_push_allocator  (GAllocator     *allocator);
1075 void    g_slist_pop_allocator   (void);
1076 GSList* g_slist_alloc           (void);
1077 void    g_slist_free            (GSList         *list);
1078 void    g_slist_free_1          (GSList         *list);
1079 GSList* g_slist_append          (GSList         *list,
1080                                  gpointer        data);
1081 GSList* g_slist_prepend         (GSList         *list,
1082                                  gpointer        data);
1083 GSList* g_slist_insert          (GSList         *list,
1084                                  gpointer        data,
1085                                  gint            position);
1086 GSList* g_slist_insert_sorted   (GSList         *list,
1087                                  gpointer        data,
1088                                  GCompareFunc    func);
1089 GSList* g_slist_insert_before   (GSList         *slist,
1090                                  GSList         *sibling,
1091                                  gpointer        data);
1092 GSList* g_slist_concat          (GSList         *list1,
1093                                  GSList         *list2);
1094 GSList* g_slist_remove          (GSList         *list,
1095                                  gconstpointer   data);
1096 GSList* g_slist_remove_link     (GSList         *list,
1097                                  GSList         *link);
1098 GSList* g_slist_delete_link     (GSList         *list,
1099                                  GSList         *link);
1100 GSList* g_slist_reverse         (GSList         *list);
1101 GSList* g_slist_copy            (GSList         *list);
1102 GSList* g_slist_nth             (GSList         *list,
1103                                  guint           n);
1104 GSList* g_slist_find            (GSList         *list,
1105                                  gconstpointer   data);
1106 GSList* g_slist_find_custom     (GSList         *list,
1107                                  gconstpointer   data,
1108                                  GCompareFunc    func);
1109 gint    g_slist_position        (GSList         *list,
1110                                  GSList         *llink);
1111 gint    g_slist_index           (GSList         *list,
1112                                  gconstpointer   data);
1113 GSList* g_slist_last            (GSList         *list);
1114 guint   g_slist_length          (GSList         *list);
1115 void    g_slist_foreach         (GSList         *list,
1116                                  GFunc           func,
1117                                  gpointer        user_data);
1118 GSList*  g_slist_sort           (GSList          *list,
1119                                  GCompareFunc    compare_func);
1120 gpointer g_slist_nth_data       (GSList         *list,
1121                                  guint           n);
1122 #define  g_slist_next(slist)    ((slist) ? (((GSList *)(slist))->next) : NULL)
1123
1124
1125 /* Queues
1126  */
1127 GQueue*  g_queue_new            (void);
1128 void     g_queue_free           (GQueue  *queue);
1129 void     g_queue_push_head      (GQueue  *queue,
1130                                  gpointer data);
1131 void     g_queue_push_tail      (GQueue  *queue,
1132                                  gpointer data);
1133 gpointer g_queue_pop_head       (GQueue  *queue);
1134 gpointer g_queue_pop_tail       (GQueue  *queue);
1135 gboolean g_queue_is_empty       (GQueue  *queue);
1136 gpointer g_queue_peek_head      (GQueue  *queue);
1137 gpointer g_queue_peek_tail      (GQueue  *queue);
1138 void     g_queue_push_head_link (GQueue  *queue,
1139                                  GList   *link);
1140 void     g_queue_push_tail_link (GQueue  *queue,
1141                                  GList   *link);
1142 GList*   g_queue_pop_head_link  (GQueue  *queue);
1143 GList*   g_queue_pop_tail_link  (GQueue  *queue);
1144
1145 /* Hash tables
1146  */
1147 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
1148                                          GCompareFunc    key_compare_func);
1149 void        g_hash_table_destroy        (GHashTable     *hash_table);
1150 void        g_hash_table_insert         (GHashTable     *hash_table,
1151                                          gpointer        key,
1152                                          gpointer        value);
1153 void        g_hash_table_remove         (GHashTable     *hash_table,
1154                                          gconstpointer   key);
1155 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
1156                                          gconstpointer   key);
1157 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
1158                                          gconstpointer   lookup_key,
1159                                          gpointer       *orig_key,
1160                                          gpointer       *value);
1161 void        g_hash_table_foreach        (GHashTable     *hash_table,
1162                                          GHFunc          func,
1163                                          gpointer        user_data);
1164 guint       g_hash_table_foreach_remove (GHashTable     *hash_table,
1165                                          GHRFunc         func,
1166                                          gpointer        user_data);
1167 guint       g_hash_table_size           (GHashTable     *hash_table);
1168
1169 /* The following two functions are deprecated and will be removed in
1170  * the next major release. They do no good. */
1171 void        g_hash_table_freeze         (GHashTable     *hash_table);
1172 void        g_hash_table_thaw           (GHashTable     *hash_table);
1173
1174 /* Caches
1175  */
1176 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
1177                                 GCacheDestroyFunc  value_destroy_func,
1178                                 GCacheDupFunc      key_dup_func,
1179                                 GCacheDestroyFunc  key_destroy_func,
1180                                 GHashFunc          hash_key_func,
1181                                 GHashFunc          hash_value_func,
1182                                 GCompareFunc       key_compare_func);
1183 void     g_cache_destroy       (GCache            *cache);
1184 gpointer g_cache_insert        (GCache            *cache,
1185                                 gpointer           key);
1186 void     g_cache_remove        (GCache            *cache,
1187                                 gconstpointer      value);
1188 void     g_cache_key_foreach   (GCache            *cache,
1189                                 GHFunc             func,
1190                                 gpointer           user_data);
1191 void     g_cache_value_foreach (GCache            *cache,
1192                                 GHFunc             func,
1193                                 gpointer           user_data);
1194
1195
1196 /* Balanced binary trees
1197  */
1198 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
1199 void     g_tree_destroy  (GTree         *tree);
1200 void     g_tree_insert   (GTree         *tree,
1201                           gpointer       key,
1202                           gpointer       value);
1203 void     g_tree_remove   (GTree         *tree,
1204                           gconstpointer  key);
1205 gpointer g_tree_lookup   (GTree         *tree,
1206                           gconstpointer  key);
1207 void     g_tree_traverse (GTree         *tree,
1208                           GTraverseFunc  traverse_func,
1209                           GTraverseType  traverse_type,
1210                           gpointer       data);
1211 gpointer g_tree_search   (GTree         *tree,
1212                           GCompareFunc   search_func,
1213                           gconstpointer  data);
1214 gint     g_tree_height   (GTree         *tree);
1215 gint     g_tree_nnodes   (GTree         *tree);
1216
1217
1218
1219 /* N-way tree implementation
1220  */
1221 struct _GNode
1222 {
1223   gpointer data;
1224   GNode   *next;
1225   GNode   *prev;
1226   GNode   *parent;
1227   GNode   *children;
1228 };
1229
1230 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
1231                                  ((GNode*) (node))->prev == NULL && \
1232                                  ((GNode*) (node))->next == NULL)
1233 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
1234
1235 void     g_node_push_allocator  (GAllocator       *allocator);
1236 void     g_node_pop_allocator   (void);
1237 GNode*   g_node_new             (gpointer          data);
1238 void     g_node_destroy         (GNode            *root);
1239 void     g_node_unlink          (GNode            *node);
1240 GNode*   g_node_copy            (GNode            *node);
1241 GNode*   g_node_insert          (GNode            *parent,
1242                                  gint              position,
1243                                  GNode            *node);
1244 GNode*   g_node_insert_before   (GNode            *parent,
1245                                  GNode            *sibling,
1246                                  GNode            *node);
1247 GNode*   g_node_prepend         (GNode            *parent,
1248                                  GNode            *node);
1249 guint    g_node_n_nodes         (GNode            *root,
1250                                  GTraverseFlags    flags);
1251 GNode*   g_node_get_root        (GNode            *node);
1252 gboolean g_node_is_ancestor     (GNode            *node,
1253                                  GNode            *descendant);
1254 guint    g_node_depth           (GNode            *node);
1255 GNode*   g_node_find            (GNode            *root,
1256                                  GTraverseType     order,
1257                                  GTraverseFlags    flags,
1258                                  gpointer          data);
1259
1260 /* convenience macros */
1261 #define g_node_append(parent, node)                             \
1262      g_node_insert_before ((parent), NULL, (node))
1263 #define g_node_insert_data(parent, position, data)              \
1264      g_node_insert ((parent), (position), g_node_new (data))
1265 #define g_node_insert_data_before(parent, sibling, data)        \
1266      g_node_insert_before ((parent), (sibling), g_node_new (data))
1267 #define g_node_prepend_data(parent, data)                       \
1268      g_node_prepend ((parent), g_node_new (data))
1269 #define g_node_append_data(parent, data)                        \
1270      g_node_insert_before ((parent), NULL, g_node_new (data))
1271
1272 /* traversal function, assumes that `node' is root
1273  * (only traverses `node' and its subtree).
1274  * this function is just a high level interface to
1275  * low level traversal functions, optimized for speed.
1276  */
1277 void     g_node_traverse        (GNode            *root,
1278                                  GTraverseType     order,
1279                                  GTraverseFlags    flags,
1280                                  gint              max_depth,
1281                                  GNodeTraverseFunc func,
1282                                  gpointer          data);
1283
1284 /* return the maximum tree height starting with `node', this is an expensive
1285  * operation, since we need to visit all nodes. this could be shortened by
1286  * adding `guint height' to struct _GNode, but then again, this is not very
1287  * often needed, and would make g_node_insert() more time consuming.
1288  */
1289 guint    g_node_max_height       (GNode *root);
1290
1291 void     g_node_children_foreach (GNode           *node,
1292                                   GTraverseFlags   flags,
1293                                   GNodeForeachFunc func,
1294                                   gpointer         data);
1295 void     g_node_reverse_children (GNode           *node);
1296 guint    g_node_n_children       (GNode           *node);
1297 GNode*   g_node_nth_child        (GNode           *node,
1298                                   guint            n);
1299 GNode*   g_node_last_child       (GNode           *node);
1300 GNode*   g_node_find_child       (GNode           *node,
1301                                   GTraverseFlags   flags,
1302                                   gpointer         data);
1303 gint     g_node_child_position   (GNode           *node,
1304                                   GNode           *child);
1305 gint     g_node_child_index      (GNode           *node,
1306                                   gpointer         data);
1307
1308 GNode*   g_node_first_sibling    (GNode           *node);
1309 GNode*   g_node_last_sibling     (GNode           *node);
1310
1311 #define  g_node_prev_sibling(node)      ((node) ? \
1312                                          ((GNode*) (node))->prev : NULL)
1313 #define  g_node_next_sibling(node)      ((node) ? \
1314                                          ((GNode*) (node))->next : NULL)
1315 #define  g_node_first_child(node)       ((node) ? \
1316                                          ((GNode*) (node))->children : NULL)
1317
1318
1319 /* Callback maintenance functions
1320  */
1321 #define G_HOOK_FLAG_USER_SHIFT  (4)
1322 typedef enum
1323 {
1324   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1325   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1326   G_HOOK_FLAG_MASK      = 0x0f
1327 } GHookFlagMask;
1328
1329 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
1330
1331 struct _GHookList
1332 {
1333   guint          seq_id;
1334   guint          hook_size;
1335   guint          is_setup : 1;
1336   GHook         *hooks;
1337   GMemChunk     *hook_memchunk;
1338   GHookFreeFunc  hook_free; /* virtual function */
1339   GHookFreeFunc  hook_destroy; /* virtual function */
1340 };
1341
1342 struct _GHook
1343 {
1344   gpointer       data;
1345   GHook         *next;
1346   GHook         *prev;
1347   guint          ref_count;
1348   guint          hook_id;
1349   guint          flags;
1350   gpointer       func;
1351   GDestroyNotify destroy;
1352 };
1353
1354 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
1355                                           G_HOOK_FLAG_ACTIVE) != 0)
1356 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
1357                                           G_HOOK_FLAG_IN_CALL) != 0)
1358 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
1359                                          G_HOOK_ACTIVE (hook))
1360 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
1361                                          ((GHook*) hook)->prev == NULL && \
1362                                          ((GHook*) hook)->hook_id == 0 && \
1363                                          ((GHook*) hook)->ref_count == 0)
1364
1365 void     g_hook_list_init               (GHookList              *hook_list,
1366                                          guint                   hook_size);
1367 void     g_hook_list_clear              (GHookList              *hook_list);
1368 GHook*   g_hook_alloc                   (GHookList              *hook_list);
1369 void     g_hook_free                    (GHookList              *hook_list,
1370                                          GHook                  *hook);
1371 void     g_hook_ref                     (GHookList              *hook_list,
1372                                          GHook                  *hook);
1373 void     g_hook_unref                   (GHookList              *hook_list,
1374                                          GHook                  *hook);
1375 gboolean g_hook_destroy                 (GHookList              *hook_list,
1376                                          guint                   hook_id);
1377 void     g_hook_destroy_link            (GHookList              *hook_list,
1378                                          GHook                  *hook);
1379 void     g_hook_prepend                 (GHookList              *hook_list,
1380                                          GHook                  *hook);
1381 void     g_hook_insert_before           (GHookList              *hook_list,
1382                                          GHook                  *sibling,
1383                                          GHook                  *hook);
1384 void     g_hook_insert_sorted           (GHookList              *hook_list,
1385                                          GHook                  *hook,
1386                                          GHookCompareFunc        func);
1387 GHook*   g_hook_get                     (GHookList              *hook_list,
1388                                          guint                   hook_id);
1389 GHook*   g_hook_find                    (GHookList              *hook_list,
1390                                          gboolean                need_valids,
1391                                          GHookFindFunc           func,
1392                                          gpointer                data);
1393 GHook*   g_hook_find_data               (GHookList              *hook_list,
1394                                          gboolean                need_valids,
1395                                          gpointer                data);
1396 GHook*   g_hook_find_func               (GHookList              *hook_list,
1397                                          gboolean                need_valids,
1398                                          gpointer                func);
1399 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1400                                          gboolean                need_valids,
1401                                          gpointer                func,
1402                                          gpointer                data);
1403 /* return the first valid hook, and increment its reference count */
1404 GHook*   g_hook_first_valid             (GHookList              *hook_list,
1405                                          gboolean                may_be_in_call);
1406 /* return the next valid hook with incremented reference count, and
1407  * decrement the reference count of the original hook
1408  */
1409 GHook*   g_hook_next_valid              (GHookList              *hook_list,
1410                                          GHook                  *hook,
1411                                          gboolean                may_be_in_call);
1412
1413 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1414 gint     g_hook_compare_ids             (GHook                  *new_hook,
1415                                          GHook                  *sibling);
1416
1417 /* convenience macros */
1418 #define  g_hook_append( hook_list, hook )  \
1419      g_hook_insert_before ((hook_list), NULL, (hook))
1420
1421 /* invoke all valid hooks with the (*GHookFunc) signature.
1422  */
1423 void     g_hook_list_invoke             (GHookList              *hook_list,
1424                                          gboolean                may_recurse);
1425 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1426  * and destroy the hook if FALSE is returned.
1427  */
1428 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1429                                          gboolean                may_recurse);
1430 /* invoke a marshaller on all valid hooks.
1431  */
1432 void     g_hook_list_marshal            (GHookList              *hook_list,
1433                                          gboolean                may_recurse,
1434                                          GHookMarshaller         marshaller,
1435                                          gpointer                data);
1436 void     g_hook_list_marshal_check      (GHookList              *hook_list,
1437                                          gboolean                may_recurse,
1438                                          GHookCheckMarshaller    marshaller,
1439                                          gpointer                data);
1440
1441
1442 /* Fatal error handlers.
1443  * g_on_error_query() will prompt the user to either
1444  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1445  * g_on_error_stack_trace() invokes gdb, which attaches to the current
1446  * process and shows a stack trace.
1447  * These function may cause different actions on non-unix platforms.
1448  * The prg_name arg is required by gdb to find the executable, if it is
1449  * passed as NULL, g_on_error_query() will try g_get_prgname().
1450  */
1451 void g_on_error_query (const gchar *prg_name);
1452 void g_on_error_stack_trace (const gchar *prg_name);
1453
1454
1455 /* Logging mechanism
1456  */
1457 extern          const gchar             *g_log_domain_glib;
1458 guint           g_log_set_handler       (const gchar    *log_domain,
1459                                          GLogLevelFlags  log_levels,
1460                                          GLogFunc        log_func,
1461                                          gpointer        user_data);
1462 void            g_log_remove_handler    (const gchar    *log_domain,
1463                                          guint           handler_id);
1464 void            g_log_default_handler   (const gchar    *log_domain,
1465                                          GLogLevelFlags  log_level,
1466                                          const gchar    *message,
1467                                          gpointer        unused_data);
1468 void            g_log                   (const gchar    *log_domain,
1469                                          GLogLevelFlags  log_level,
1470                                          const gchar    *format,
1471                                          ...) G_GNUC_PRINTF (3, 4);
1472 void            g_logv                  (const gchar    *log_domain,
1473                                          GLogLevelFlags  log_level,
1474                                          const gchar    *format,
1475                                          va_list         args);
1476 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1477                                          GLogLevelFlags  fatal_mask);
1478 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1479 #ifndef G_LOG_DOMAIN
1480 #define G_LOG_DOMAIN    ((gchar*) 0)
1481 #endif  /* G_LOG_DOMAIN */
1482 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1483 #define g_error(...)    g_log (G_LOG_DOMAIN,         \
1484                                G_LOG_LEVEL_ERROR,    \
1485                                __VA_ARGS__)
1486 #define g_message(...)  g_log (G_LOG_DOMAIN,         \
1487                                G_LOG_LEVEL_MESSAGE,  \
1488                                __VA_ARGS__)
1489 #define g_critical(...) g_log (G_LOG_DOMAIN,         \
1490                                G_LOG_LEVEL_CRITICAL, \
1491                                __VA_ARGS__)
1492 #define g_warning(...)  g_log (G_LOG_DOMAIN,         \
1493                                G_LOG_LEVEL_WARNING,  \
1494                                __VA_ARGS__)
1495 #elif defined (__GNUC__)
1496 #define g_error(format...)      g_log (G_LOG_DOMAIN,         \
1497                                        G_LOG_LEVEL_ERROR,    \
1498                                        format)
1499 #define g_message(format...)    g_log (G_LOG_DOMAIN,         \
1500                                        G_LOG_LEVEL_MESSAGE,  \
1501                                        format)
1502 #define g_critical(format...)   g_log (G_LOG_DOMAIN,         \
1503                                        G_LOG_LEVEL_CRITICAL, \
1504                                        format)
1505 #define g_warning(format...)    g_log (G_LOG_DOMAIN,         \
1506                                        G_LOG_LEVEL_WARNING,  \
1507                                        format)
1508 #else   /* !__GNUC__ */
1509 static void
1510 g_error (const gchar *format,
1511          ...)
1512 {
1513   va_list args;
1514   va_start (args, format);
1515   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1516   va_end (args);
1517 }
1518 static void
1519 g_message (const gchar *format,
1520            ...)
1521 {
1522   va_list args;
1523   va_start (args, format);
1524   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1525   va_end (args);
1526 }
1527 static void
1528 g_critical (const gchar *format,
1529             ...)
1530 {
1531   va_list args;
1532   va_start (args, format);
1533   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
1534   va_end (args);
1535 }
1536 static void
1537 g_warning (const gchar *format,
1538            ...)
1539 {
1540   va_list args;
1541   va_start (args, format);
1542   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1543   va_end (args);
1544 }
1545 #endif  /* !__GNUC__ */
1546
1547 typedef void    (*GPrintFunc)           (const gchar    *string);
1548 void            g_print                 (const gchar    *format,
1549                                          ...) G_GNUC_PRINTF (1, 2);
1550 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1551 void            g_printerr              (const gchar    *format,
1552                                          ...) G_GNUC_PRINTF (1, 2);
1553 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1554
1555 /* deprecated compatibility functions, use g_log_set_handler() instead */
1556 typedef void            (*GErrorFunc)           (const gchar *str);
1557 typedef void            (*GWarningFunc)         (const gchar *str);
1558 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1559 GWarningFunc g_set_warning_handler (GWarningFunc func);
1560 GPrintFunc   g_set_message_handler (GPrintFunc func);
1561
1562
1563 /* Memory allocation and debugging
1564  */
1565 #ifdef USE_DMALLOC
1566
1567 #define g_malloc(size)       ((gpointer) MALLOC (size))
1568 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1569 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1570 #define g_free(mem)          FREE (mem)
1571
1572 #else /* !USE_DMALLOC */
1573
1574 gpointer g_malloc      (gulong    size);
1575 gpointer g_malloc0     (gulong    size);
1576 gpointer g_realloc     (gpointer  mem,
1577                         gulong    size);
1578 void     g_free        (gpointer  mem);
1579
1580 #endif /* !USE_DMALLOC */
1581
1582 void     g_mem_profile (void);
1583 void     g_mem_check   (gpointer  mem);
1584
1585 /* Generic allocators
1586  */
1587 GAllocator* g_allocator_new   (const gchar  *name,
1588                                guint         n_preallocs);
1589 void        g_allocator_free  (GAllocator   *allocator);
1590
1591 #define G_ALLOCATOR_LIST        (1)
1592 #define G_ALLOCATOR_SLIST       (2)
1593 #define G_ALLOCATOR_NODE        (3)
1594
1595
1596 /* "g_mem_chunk_new" creates a new memory chunk.
1597  * Memory chunks are used to allocate pieces of memory which are
1598  *  always the same size. Lists are a good example of such a data type.
1599  * The memory chunk allocates and frees blocks of memory as needed.
1600  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1601  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1602  *  fault...somewhere).
1603  *
1604  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1605  *  want to know what's going on inside do you?)
1606  */
1607
1608 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1609  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1610  *  atom. (They are also useful for lists which use MemChunk to allocate
1611  *  memory but are also part of the MemChunk implementation).
1612  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1613  */
1614
1615 #define G_ALLOC_ONLY      1
1616 #define G_ALLOC_AND_FREE  2
1617
1618 GMemChunk* g_mem_chunk_new     (gchar     *name,
1619                                 gint       atom_size,
1620                                 gulong     area_size,
1621                                 gint       type);
1622 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1623 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1624 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1625 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1626                                 gpointer   mem);
1627 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1628 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1629 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1630 void       g_mem_chunk_info    (void);
1631
1632 /* Ah yes...we have a "g_blow_chunks" function.
1633  * "g_blow_chunks" simply compresses all the chunks. This operation
1634  *  consists of freeing every memory area that should be freed (but
1635  *  which we haven't gotten around to doing yet). And, no,
1636  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1637  *  much better name than "g_mem_chunk_clean_all" or something
1638  *  similar.
1639  */
1640 void g_blow_chunks (void);
1641
1642
1643 /* Timer
1644  */
1645
1646 #define G_MICROSEC 1000000
1647
1648 GTimer* g_timer_new     (void);
1649 void    g_timer_destroy (GTimer  *timer);
1650 void    g_timer_start   (GTimer  *timer);
1651 void    g_timer_stop    (GTimer  *timer);
1652 void    g_timer_reset   (GTimer  *timer);
1653 gdouble g_timer_elapsed (GTimer  *timer,
1654                          gulong  *microseconds);
1655 void    g_usleep        (gulong microseconds);
1656
1657 /* String utility functions that modify a string argument or
1658  * return a constant string that must not be freed.
1659  */
1660 #define  G_STR_DELIMITERS       "_-|> <."
1661 gchar*   g_strdelimit           (gchar       *string,
1662                                  const gchar *delimiters,
1663                                  gchar        new_delimiter);
1664 gchar*   g_strcanon             (gchar       *string,
1665                                  const gchar *valid_chars,
1666                                  gchar        subsitutor);
1667 gdouble  g_strtod               (const gchar *nptr,
1668                                  gchar      **endptr);
1669 gchar*   g_strerror             (gint         errnum);
1670 gchar*   g_strsignal            (gint         signum);
1671 gint     g_strcasecmp           (const gchar *s1,
1672                                  const gchar *s2);
1673 gint     g_strncasecmp          (const gchar *s1,
1674                                  const gchar *s2,
1675                                  guint        n);
1676 gchar*   g_strdown              (gchar       *string);
1677 gchar*   g_strup                (gchar       *string);
1678 gchar*   g_strreverse           (gchar       *string);
1679 gsize    g_strlcpy              (gchar       *dest,
1680                                  const gchar *src,
1681                                  gsize        dest_size);
1682 gsize    g_strlcat              (gchar       *dest,
1683                                  const gchar *src,
1684                                  gsize        dest_size);
1685 /* removes leading spaces */
1686 gchar*   g_strchug              (gchar        *string);
1687 /* removes trailing spaces */
1688 gchar*  g_strchomp              (gchar        *string);
1689 /* removes leading & trailing spaces */
1690 #define g_strstrip( string )    g_strchomp (g_strchug (string))
1691
1692 /* String utility functions that return a newly allocated string which
1693  * ought to be freed with g_free from the caller at some point.
1694  */
1695 gchar*   g_strdup               (const gchar *str);
1696 gchar*   g_strdup_printf        (const gchar *format,
1697                                  ...) G_GNUC_PRINTF (1, 2);
1698 gchar*   g_strdup_vprintf       (const gchar *format,
1699                                  va_list      args);
1700 gchar*   g_strndup              (const gchar *str,
1701                                  guint        n);
1702 gchar*   g_strnfill             (guint        length,
1703                                  gchar        fill_char);
1704 gchar*   g_strconcat            (const gchar *string1,
1705                                  ...); /* NULL terminated */
1706 gchar*   g_strjoin              (const gchar  *separator,
1707                                  ...); /* NULL terminated */
1708 /* Make a copy of a string interpreting C string -style escape
1709  * sequences. Inverse of g_strescape. The recognized sequences are \b
1710  * \f \n \r \t \\ \" and the octal format.
1711  */
1712 gchar*   g_strcompress          (const gchar *source);
1713
1714 /* Convert between the operating system (or C runtime)
1715  * representation of file names and UTF-8.
1716  */
1717 gchar*   g_filename_to_utf8 (const gchar *opsysstring);
1718 gchar*   g_filename_from_utf8 (const gchar *utf8string);
1719
1720 /* Copy a string escaping nonprintable characters like in C strings.
1721  * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
1722  * to a string containing characters that are not to be escaped.
1723  *
1724  * Deprecated API: gchar* g_strescape (const gchar *source);
1725  * Luckily this function wasn't used much, using NULL as second parameter
1726  * provides mostly identical semantics.
1727  */
1728 gchar*   g_strescape            (const gchar *source,
1729                                  const gchar *exceptions);
1730
1731 gpointer g_memdup               (gconstpointer mem,
1732                                  guint         byte_size);
1733
1734 /* NULL terminated string arrays.
1735  * g_strsplit() splits up string into max_tokens tokens at delim and
1736  * returns a newly allocated string array.
1737  * g_strjoinv() concatenates all of str_array's strings, sliding in an
1738  * optional separator, the returned string is newly allocated.
1739  * g_strfreev() frees the array itself and all of its strings.
1740  */
1741 gchar**  g_strsplit             (const gchar  *string,
1742                                  const gchar  *delimiter,
1743                                  gint          max_tokens);
1744 gchar*   g_strjoinv             (const gchar  *separator,
1745                                  gchar       **str_array);
1746 void     g_strfreev             (gchar       **str_array);
1747
1748
1749
1750 /* calculate a string size, guarranteed to fit format + args.
1751  */
1752 guint   g_printf_string_upper_bound (const gchar* format,
1753                                      va_list      args);
1754
1755
1756 /* Retrive static string info
1757  */
1758 gchar*  g_get_user_name         (void);
1759 gchar*  g_get_real_name         (void);
1760 gchar*  g_get_home_dir          (void);
1761 gchar*  g_get_tmp_dir           (void);
1762 gchar*  g_get_prgname           (void);
1763 void    g_set_prgname           (const gchar *prgname);
1764
1765
1766 /* Miscellaneous utility functions
1767  */
1768 guint   g_parse_debug_string    (const gchar *string,
1769                                  GDebugKey   *keys,
1770                                  guint        nkeys);
1771 gint    g_snprintf              (gchar       *string,
1772                                  gulong       n,
1773                                  gchar const *format,
1774                                  ...) G_GNUC_PRINTF (3, 4);
1775 gint    g_vsnprintf             (gchar       *string,
1776                                  gulong       n,
1777                                  gchar const *format,
1778                                  va_list      args);
1779 /* Check if a file name is an absolute path */
1780 gboolean g_path_is_absolute     (const gchar *file_name);
1781 /* In case of absolute paths, skip the root part */
1782 gchar*  g_path_skip_root        (gchar       *file_name);
1783
1784 /* These two functions are deprecated and will be removed in the next
1785  * major release of GLib. Use g_path_get_dirname/g_path_get_basename
1786  * instead. Whatch out! The string returned by g_path_get_basename
1787  * must be g_freed, while the string returned by g_basename must not.*/
1788 gchar*  g_basename              (const gchar *file_name);
1789 gchar*  g_dirname               (const gchar *file_name);
1790
1791 /* The returned strings are newly allocated with g_malloc() */
1792 gchar*  g_get_current_dir       (void);
1793 gchar*  g_path_get_basename     (const gchar *file_name);
1794 gchar*  g_path_get_dirname      (const gchar *file_name);
1795
1796 /* Get the codeset for the current locale */
1797 /* gchar * g_get_codeset    (void); */
1798
1799 /* return the environment string for the variable. The returned memory
1800  * must not be freed. */
1801 gchar*  g_getenv                (const gchar *variable);
1802
1803 /* we use a GLib function as a replacement for ATEXIT, so
1804  * the programmer is not required to check the return value
1805  * (if there is any in the implementation) and doesn't encounter
1806  * missing include files.
1807  */
1808 void    g_atexit                (GVoidFunc    func);
1809
1810
1811 /* Bit tests
1812  */
1813 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1814                                        gint    nth_bit);
1815 #ifdef  G_CAN_INLINE
1816 G_INLINE_FUNC gint
1817 g_bit_nth_lsf (guint32 mask,
1818                gint    nth_bit)
1819 {
1820   do
1821     {
1822       nth_bit++;
1823       if (mask & (1 << (guint) nth_bit))
1824         return nth_bit;
1825     }
1826   while (nth_bit < 32);
1827   return -1;
1828 }
1829 #endif  /* G_CAN_INLINE */
1830
1831 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1832                                        gint    nth_bit);
1833 #ifdef G_CAN_INLINE
1834 G_INLINE_FUNC gint
1835 g_bit_nth_msf (guint32 mask,
1836                gint    nth_bit)
1837 {
1838   if (nth_bit < 0)
1839     nth_bit = 32;
1840   do
1841     {
1842       nth_bit--;
1843       if (mask & (1 << (guint) nth_bit))
1844         return nth_bit;
1845     }
1846   while (nth_bit > 0);
1847   return -1;
1848 }
1849 #endif  /* G_CAN_INLINE */
1850
1851 G_INLINE_FUNC guint     g_bit_storage (guint number);
1852 #ifdef G_CAN_INLINE
1853 G_INLINE_FUNC guint
1854 g_bit_storage (guint number)
1855 {
1856   register guint n_bits = 0;
1857   
1858   do
1859     {
1860       n_bits++;
1861       number >>= 1;
1862     }
1863   while (number);
1864   return n_bits;
1865 }
1866 #endif  /* G_CAN_INLINE */
1867
1868
1869 /* Trash Stacks
1870  * elements need to be >= sizeof (gpointer)
1871  */
1872 G_INLINE_FUNC void      g_trash_stack_push      (GTrashStack **stack_p,
1873                                                  gpointer      data_p);
1874 #ifdef G_CAN_INLINE
1875 G_INLINE_FUNC void
1876 g_trash_stack_push (GTrashStack **stack_p,
1877                     gpointer      data_p)
1878 {
1879   GTrashStack *data = (GTrashStack *) data_p;
1880
1881   data->next = *stack_p;
1882   *stack_p = data;
1883 }
1884 #endif  /* G_CAN_INLINE */
1885
1886 G_INLINE_FUNC gpointer  g_trash_stack_pop       (GTrashStack **stack_p);
1887 #ifdef G_CAN_INLINE
1888 G_INLINE_FUNC gpointer
1889 g_trash_stack_pop (GTrashStack **stack_p)
1890 {
1891   GTrashStack *data;
1892
1893   data = *stack_p;
1894   if (data)
1895     {
1896       *stack_p = data->next;
1897       /* NULLify private pointer here, most platforms store NULL as
1898        * subsequent 0 bytes
1899        */
1900       data->next = NULL;
1901     }
1902
1903   return data;
1904 }
1905 #endif  /* G_CAN_INLINE */
1906
1907 G_INLINE_FUNC gpointer  g_trash_stack_peek      (GTrashStack **stack_p);
1908 #ifdef G_CAN_INLINE
1909 G_INLINE_FUNC gpointer
1910 g_trash_stack_peek (GTrashStack **stack_p)
1911 {
1912   GTrashStack *data;
1913
1914   data = *stack_p;
1915
1916   return data;
1917 }
1918 #endif  /* G_CAN_INLINE */
1919
1920 G_INLINE_FUNC guint     g_trash_stack_height    (GTrashStack **stack_p);
1921 #ifdef G_CAN_INLINE
1922 G_INLINE_FUNC guint
1923 g_trash_stack_height (GTrashStack **stack_p)
1924 {
1925   GTrashStack *data;
1926   guint i = 0;
1927
1928   for (data = *stack_p; data; data = data->next)
1929     i++;
1930
1931   return i;
1932 }
1933 #endif  /* G_CAN_INLINE */
1934
1935
1936 /* String Chunks
1937  */
1938 GStringChunk* g_string_chunk_new           (gint size);
1939 void          g_string_chunk_free          (GStringChunk *chunk);
1940 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1941                                             const gchar  *string);
1942 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1943                                             const gchar  *string);
1944
1945
1946 /* Strings
1947  */
1948 GString*     g_string_new               (const gchar     *init);
1949 GString*     g_string_sized_new         (guint            dfl_size);
1950 gchar*       g_string_free              (GString         *string,
1951                                          gboolean         free_segment);
1952 gboolean     g_string_equal             (const GString   *v,
1953                                          const GString   *v2);
1954 guint        g_string_hash              (const GString   *str);
1955 GString*     g_string_assign            (GString         *string,
1956                                          const gchar     *rval);
1957 GString*     g_string_truncate          (GString         *string,
1958                                          guint            len);
1959 GString*     g_string_insert_len        (GString         *string,
1960                                          gint             pos,
1961                                          const gchar     *val,
1962                                          gint             len);
1963 GString*     g_string_append            (GString         *string,
1964                                          const gchar     *val);
1965 GString*     g_string_append_len        (GString         *string,
1966                                          const gchar     *val,
1967                                          gint             len);
1968 GString*     g_string_append_c          (GString         *string,
1969                                          gchar            c);
1970 GString*     g_string_prepend           (GString         *string,
1971                                          const gchar     *val);
1972 GString*     g_string_prepend_c         (GString         *string,
1973                                          gchar            c);
1974 GString*     g_string_prepend_len       (GString         *string,
1975                                          const gchar     *val,
1976                                          gint             len);
1977 GString*     g_string_insert            (GString         *string,
1978                                          gint             pos,
1979                                          const gchar     *val);
1980 GString*     g_string_insert_c          (GString         *string,
1981                                          gint             pos,
1982                                          gchar            c);
1983 GString*     g_string_erase             (GString         *string,
1984                                          gint             pos,
1985                                          gint             len);
1986 GString*     g_string_down              (GString         *string);
1987 GString*     g_string_up                (GString         *string);
1988 void         g_string_sprintf           (GString         *string,
1989                                          const gchar     *format,
1990                                          ...) G_GNUC_PRINTF (2, 3);
1991 void         g_string_sprintfa          (GString         *string,
1992                                          const gchar     *format,
1993                                          ...) G_GNUC_PRINTF (2, 3);
1994
1995
1996 /* Resizable arrays, remove fills any cleared spot and shortens the
1997  * array, while preserving the order. remove_fast will distort the
1998  * order by moving the last element to the position of the removed 
1999  */
2000
2001 #define g_array_append_val(a,v)   g_array_append_vals (a, &v, 1)
2002 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &v, 1)
2003 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1)
2004 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
2005
2006 GArray* g_array_new               (gboolean         zero_terminated,
2007                                    gboolean         clear,
2008                                    guint            element_size);
2009 GArray* g_array_sized_new         (gboolean         zero_terminated,
2010                                    gboolean         clear,
2011                                    guint            element_size,
2012                                    guint            reserved_size);
2013 gchar*  g_array_free              (GArray          *array,
2014                                    gboolean         free_segment);
2015 GArray* g_array_append_vals       (GArray          *array,
2016                                    gconstpointer    data,
2017                                    guint            len);
2018 GArray* g_array_prepend_vals      (GArray          *array,
2019                                    gconstpointer    data,
2020                                    guint            len);
2021 GArray* g_array_insert_vals       (GArray          *array,
2022                                    guint            index,
2023                                    gconstpointer    data,
2024                                    guint            len);
2025 GArray* g_array_set_size          (GArray          *array,
2026                                    guint            length);
2027 GArray* g_array_remove_index      (GArray          *array,
2028                                    guint            index);
2029 GArray* g_array_remove_index_fast (GArray          *array,
2030                                    guint            index);
2031
2032 /* Resizable pointer array.  This interface is much less complicated
2033  * than the above.  Add appends appends a pointer.  Remove fills any
2034  * cleared spot and shortens the array. remove_fast will again distort
2035  * order.  
2036  */
2037 #define     g_ptr_array_index(array,index) (array->pdata)[index]
2038 GPtrArray*  g_ptr_array_new                (void);
2039 GPtrArray*  g_ptr_array_sized_new          (guint        reserved_size);
2040 gpointer*   g_ptr_array_free               (GPtrArray   *array,
2041                                             gboolean     free_seg);
2042 void        g_ptr_array_set_size           (GPtrArray   *array,
2043                                             gint         length);
2044 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
2045                                             guint        index);
2046 gpointer    g_ptr_array_remove_index_fast  (GPtrArray   *array,
2047                                             guint        index);
2048 gboolean    g_ptr_array_remove             (GPtrArray   *array,
2049                                             gpointer     data);
2050 gboolean    g_ptr_array_remove_fast        (GPtrArray   *array,
2051                                             gpointer     data);
2052 void        g_ptr_array_add                (GPtrArray   *array,
2053                                             gpointer     data);
2054
2055 /* Byte arrays, an array of guint8.  Implemented as a GArray,
2056  * but type-safe.
2057  */
2058
2059 GByteArray* g_byte_array_new               (void);
2060 GByteArray* g_byte_array_sized_new         (guint        reserved_size);
2061 guint8*     g_byte_array_free              (GByteArray   *array,
2062                                             gboolean      free_segment);
2063 GByteArray* g_byte_array_append            (GByteArray   *array,
2064                                             const guint8 *data,
2065                                             guint         len);
2066 GByteArray* g_byte_array_prepend           (GByteArray   *array,
2067                                             const guint8 *data,
2068                                             guint         len);
2069 GByteArray* g_byte_array_set_size          (GByteArray   *array,
2070                                             guint         length);
2071 GByteArray* g_byte_array_remove_index      (GByteArray   *array,
2072                                             guint         index);
2073 GByteArray* g_byte_array_remove_index_fast (GByteArray   *array,
2074                                             guint         index);
2075
2076
2077 /* Hash Functions
2078  */
2079 gboolean g_str_equal (gconstpointer   v,
2080                       gconstpointer   v2);
2081 guint    g_str_hash  (gconstpointer   v);
2082
2083 gint     g_int_equal (gconstpointer   v,
2084                       gconstpointer   v2) G_GNUC_CONST;
2085 guint    g_int_hash  (gconstpointer   v) G_GNUC_CONST;
2086
2087 /* This "hash" function will just return the key's adress as an
2088  * unsigned integer. Useful for hashing on plain adresses or
2089  * simple integer values.
2090  * passing NULL into g_hash_table_new() as GHashFunc has the
2091  * same effect as passing g_direct_hash().
2092  */
2093 guint g_direct_hash  (gconstpointer v) G_GNUC_CONST;
2094 gint  g_direct_equal (gconstpointer v,
2095                       gconstpointer v2) G_GNUC_CONST;
2096
2097
2098 /* Quarks (string<->id association)
2099  */
2100 GQuark    g_quark_try_string            (const gchar    *string);
2101 GQuark    g_quark_from_static_string    (const gchar    *string);
2102 GQuark    g_quark_from_string           (const gchar    *string);
2103 gchar*    g_quark_to_string             (GQuark          quark) G_GNUC_CONST;
2104
2105
2106 /* Keyed Data List
2107  */
2108 void      g_datalist_init                (GData          **datalist);
2109 void      g_datalist_clear               (GData          **datalist);
2110 gpointer  g_datalist_id_get_data         (GData          **datalist,
2111                                           GQuark           key_id);
2112 void      g_datalist_id_set_data_full    (GData          **datalist,
2113                                           GQuark           key_id,
2114                                           gpointer         data,
2115                                           GDestroyNotify   destroy_func);
2116 gpointer  g_datalist_id_remove_no_notify (GData          **datalist,
2117                                           GQuark           key_id);
2118 void      g_datalist_foreach             (GData          **datalist,
2119                                           GDataForeachFunc func,
2120                                           gpointer         user_data);
2121 #define   g_datalist_id_set_data(dl, q, d)      \
2122      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
2123 #define   g_datalist_id_remove_data(dl, q)      \
2124      g_datalist_id_set_data ((dl), (q), NULL)
2125 #define   g_datalist_get_data(dl, k)            \
2126      (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
2127 #define   g_datalist_set_data_full(dl, k, d, f) \
2128      g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
2129 #define   g_datalist_remove_no_notify(dl, k)    \
2130      g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
2131 #define   g_datalist_set_data(dl, k, d)         \
2132      g_datalist_set_data_full ((dl), (k), (d), NULL)
2133 #define   g_datalist_remove_data(dl, k)         \
2134      g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
2135
2136
2137 /* Location Associated Keyed Data
2138  */
2139 void      g_dataset_destroy             (gconstpointer    dataset_location);
2140 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
2141                                          GQuark           key_id);
2142 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
2143                                          GQuark           key_id,
2144                                          gpointer         data,
2145                                          GDestroyNotify   destroy_func);
2146 gpointer  g_dataset_id_remove_no_notify (gconstpointer    dataset_location,
2147                                          GQuark           key_id);
2148 void      g_dataset_foreach             (gconstpointer    dataset_location,
2149                                          GDataForeachFunc func,
2150                                          gpointer         user_data);
2151 #define   g_dataset_id_set_data(l, k, d)        \
2152      g_dataset_id_set_data_full ((l), (k), (d), NULL)
2153 #define   g_dataset_id_remove_data(l, k)        \
2154      g_dataset_id_set_data ((l), (k), NULL)
2155 #define   g_dataset_get_data(l, k)              \
2156      (g_dataset_id_get_data ((l), g_quark_try_string (k)))
2157 #define   g_dataset_set_data_full(l, k, d, f)   \
2158      g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
2159 #define   g_dataset_remove_no_notify(l, k)      \
2160      g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
2161 #define   g_dataset_set_data(l, k, d)           \
2162      g_dataset_set_data_full ((l), (k), (d), NULL)
2163 #define   g_dataset_remove_data(l, k)           \
2164      g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
2165
2166
2167 /* GScanner: Flexible lexical scanner for general purpose.
2168  */
2169
2170 /* Character sets */
2171 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2172 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
2173 #define G_CSET_DIGITS   "0123456789"
2174 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
2175                         "\307\310\311\312\313\314\315\316\317\320"\
2176                         "\321\322\323\324\325\326"\
2177                         "\330\331\332\333\334\335\336"
2178 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
2179                         "\347\350\351\352\353\354\355\356\357\360"\
2180                         "\361\362\363\364\365\366"\
2181                         "\370\371\372\373\374\375\376\377"
2182
2183 /* Error types */
2184 typedef enum
2185 {
2186   G_ERR_UNKNOWN,
2187   G_ERR_UNEXP_EOF,
2188   G_ERR_UNEXP_EOF_IN_STRING,
2189   G_ERR_UNEXP_EOF_IN_COMMENT,
2190   G_ERR_NON_DIGIT_IN_CONST,
2191   G_ERR_DIGIT_RADIX,
2192   G_ERR_FLOAT_RADIX,
2193   G_ERR_FLOAT_MALFORMED
2194 } GErrorType;
2195
2196 /* Token types */
2197 typedef enum
2198 {
2199   G_TOKEN_EOF                   =   0,
2200   
2201   G_TOKEN_LEFT_PAREN            = '(',
2202   G_TOKEN_RIGHT_PAREN           = ')',
2203   G_TOKEN_LEFT_CURLY            = '{',
2204   G_TOKEN_RIGHT_CURLY           = '}',
2205   G_TOKEN_LEFT_BRACE            = '[',
2206   G_TOKEN_RIGHT_BRACE           = ']',
2207   G_TOKEN_EQUAL_SIGN            = '=',
2208   G_TOKEN_COMMA                 = ',',
2209   
2210   G_TOKEN_NONE                  = 256,
2211   
2212   G_TOKEN_ERROR,
2213   
2214   G_TOKEN_CHAR,
2215   G_TOKEN_BINARY,
2216   G_TOKEN_OCTAL,
2217   G_TOKEN_INT,
2218   G_TOKEN_HEX,
2219   G_TOKEN_FLOAT,
2220   G_TOKEN_STRING,
2221   
2222   G_TOKEN_SYMBOL,
2223   G_TOKEN_IDENTIFIER,
2224   G_TOKEN_IDENTIFIER_NULL,
2225   
2226   G_TOKEN_COMMENT_SINGLE,
2227   G_TOKEN_COMMENT_MULTI,
2228   G_TOKEN_LAST
2229 } GTokenType;
2230
2231 union   _GTokenValue
2232 {
2233   gpointer      v_symbol;
2234   gchar         *v_identifier;
2235   gulong        v_binary;
2236   gulong        v_octal;
2237   gulong        v_int;
2238   gdouble       v_float;
2239   gulong        v_hex;
2240   gchar         *v_string;
2241   gchar         *v_comment;
2242   guchar        v_char;
2243   guint         v_error;
2244 };
2245
2246 struct  _GScannerConfig
2247 {
2248   /* Character sets
2249    */
2250   gchar         *cset_skip_characters;          /* default: " \t\n" */
2251   gchar         *cset_identifier_first;
2252   gchar         *cset_identifier_nth;
2253   gchar         *cpair_comment_single;          /* default: "#\n" */
2254   
2255   /* Should symbol lookup work case sensitive?
2256    */
2257   guint         case_sensitive : 1;
2258   
2259   /* Boolean values to be adjusted "on the fly"
2260    * to configure scanning behaviour.
2261    */
2262   guint         skip_comment_multi : 1;         /* C like comment */
2263   guint         skip_comment_single : 1;        /* single line comment */
2264   guint         scan_comment_multi : 1;         /* scan multi line comments? */
2265   guint         scan_identifier : 1;
2266   guint         scan_identifier_1char : 1;
2267   guint         scan_identifier_NULL : 1;
2268   guint         scan_symbols : 1;
2269   guint         scan_binary : 1;
2270   guint         scan_octal : 1;
2271   guint         scan_float : 1;
2272   guint         scan_hex : 1;                   /* `0x0ff0' */
2273   guint         scan_hex_dollar : 1;            /* `$0ff0' */
2274   guint         scan_string_sq : 1;             /* string: 'anything' */
2275   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
2276   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
2277   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
2278   guint         identifier_2_string : 1;
2279   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
2280   guint         symbol_2_token : 1;
2281   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
2282 };
2283
2284 struct  _GScanner
2285 {
2286   /* unused fields */
2287   gpointer              user_data;
2288   guint                 max_parse_errors;
2289   
2290   /* g_scanner_error() increments this field */
2291   guint                 parse_errors;
2292   
2293   /* name of input stream, featured by the default message handler */
2294   const gchar           *input_name;
2295   
2296   /* data pointer for derived structures */
2297   gpointer              derived_data;
2298   
2299   /* link into the scanner configuration */
2300   GScannerConfig        *config;
2301   
2302   /* fields filled in after g_scanner_get_next_token() */
2303   GTokenType            token;
2304   GTokenValue           value;
2305   guint                 line;
2306   guint                 position;
2307   
2308   /* fields filled in after g_scanner_peek_next_token() */
2309   GTokenType            next_token;
2310   GTokenValue           next_value;
2311   guint                 next_line;
2312   guint                 next_position;
2313   
2314   /* to be considered private */
2315   GHashTable            *symbol_table;
2316   gint                  input_fd;
2317   const gchar           *text;
2318   const gchar           *text_end;
2319   gchar                 *buffer;
2320   guint                 scope_id;
2321   
2322   /* handler function for _warn and _error */
2323   GScannerMsgFunc       msg_handler;
2324 };
2325
2326 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
2327 void            g_scanner_destroy               (GScanner       *scanner);
2328 void            g_scanner_input_file            (GScanner       *scanner,
2329                                                  gint           input_fd);
2330 void            g_scanner_sync_file_offset      (GScanner       *scanner);
2331 void            g_scanner_input_text            (GScanner       *scanner,
2332                                                  const  gchar   *text,
2333                                                  guint          text_len);
2334 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
2335 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
2336 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
2337 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
2338 guint           g_scanner_cur_line              (GScanner       *scanner);
2339 guint           g_scanner_cur_position          (GScanner       *scanner);
2340 gboolean        g_scanner_eof                   (GScanner       *scanner);
2341 guint           g_scanner_set_scope             (GScanner       *scanner,
2342                                                  guint           scope_id);
2343 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
2344                                                  guint           scope_id,
2345                                                  const gchar    *symbol,
2346                                                  gpointer       value);
2347 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
2348                                                  guint           scope_id,
2349                                                  const gchar    *symbol);
2350 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
2351                                                  guint           scope_id,
2352                                                  const gchar    *symbol);
2353 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
2354                                                  guint           scope_id,
2355                                                  GHFunc          func,
2356                                                  gpointer        user_data);
2357 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
2358                                                  const gchar    *symbol);
2359 void            g_scanner_unexp_token           (GScanner       *scanner,
2360                                                  GTokenType     expected_token,
2361                                                  const gchar    *identifier_spec,
2362                                                  const gchar    *symbol_spec,
2363                                                  const gchar    *symbol_name,
2364                                                  const gchar    *message,
2365                                                  gint            is_error);
2366 void            g_scanner_error                 (GScanner       *scanner,
2367                                                  const gchar    *format,
2368                                                  ...) G_GNUC_PRINTF (2,3);
2369 void            g_scanner_warn                  (GScanner       *scanner,
2370                                                  const gchar    *format,
2371                                                  ...) G_GNUC_PRINTF (2,3);
2372 gint            g_scanner_stat_mode             (const gchar    *filename);
2373 /* keep downward source compatibility */
2374 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
2375   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
2376 } G_STMT_END
2377 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
2378   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2379 } G_STMT_END
2380 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2381   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2382 } G_STMT_END
2383
2384 /* The following two functions are deprecated and will be removed in
2385  * the next major release. They do no good. */
2386 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
2387 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
2388
2389 /* GCompletion
2390  */
2391
2392 struct _GCompletion
2393 {
2394   GList* items;
2395   GCompletionFunc func;
2396   
2397   gchar* prefix;
2398   GList* cache;
2399 };
2400
2401 GCompletion* g_completion_new          (GCompletionFunc func);
2402 void         g_completion_add_items    (GCompletion*    cmp,
2403                                         GList*          items);
2404 void         g_completion_remove_items (GCompletion*    cmp,
2405                                         GList*          items);
2406 void         g_completion_clear_items  (GCompletion*    cmp);
2407 GList*       g_completion_complete     (GCompletion*    cmp,
2408                                         gchar*          prefix,
2409                                         gchar**         new_prefix);
2410 void         g_completion_free         (GCompletion*    cmp);
2411
2412
2413 /* GDate
2414  *
2415  * Date calculations (not time for now, to be resolved). These are a
2416  * mutant combination of Steffen Beyer's DateCalc routines
2417  * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
2418  * date routines (written for in-house software).  Written by Havoc
2419  * Pennington <hp@pobox.com> 
2420  */
2421
2422 typedef guint16 GDateYear;
2423 typedef guint8  GDateDay;   /* day of the month */
2424 typedef struct _GDate GDate;
2425 /* make struct tm known without having to include time.h */
2426 struct tm;
2427
2428 /* enum used to specify order of appearance in parsed date strings */
2429 typedef enum
2430 {
2431   G_DATE_DAY   = 0,
2432   G_DATE_MONTH = 1,
2433   G_DATE_YEAR  = 2
2434 } GDateDMY;
2435
2436 /* actual week and month values */
2437 typedef enum
2438 {
2439   G_DATE_BAD_WEEKDAY  = 0,
2440   G_DATE_MONDAY       = 1,
2441   G_DATE_TUESDAY      = 2,
2442   G_DATE_WEDNESDAY    = 3,
2443   G_DATE_THURSDAY     = 4,
2444   G_DATE_FRIDAY       = 5,
2445   G_DATE_SATURDAY     = 6,
2446   G_DATE_SUNDAY       = 7
2447 } GDateWeekday;
2448 typedef enum
2449 {
2450   G_DATE_BAD_MONTH = 0,
2451   G_DATE_JANUARY   = 1,
2452   G_DATE_FEBRUARY  = 2,
2453   G_DATE_MARCH     = 3,
2454   G_DATE_APRIL     = 4,
2455   G_DATE_MAY       = 5,
2456   G_DATE_JUNE      = 6,
2457   G_DATE_JULY      = 7,
2458   G_DATE_AUGUST    = 8,
2459   G_DATE_SEPTEMBER = 9,
2460   G_DATE_OCTOBER   = 10,
2461   G_DATE_NOVEMBER  = 11,
2462   G_DATE_DECEMBER  = 12
2463 } GDateMonth;
2464
2465 #define G_DATE_BAD_JULIAN 0U
2466 #define G_DATE_BAD_DAY    0U
2467 #define G_DATE_BAD_YEAR   0U
2468
2469 /* Note: directly manipulating structs is generally a bad idea, but
2470  * in this case it's an *incredibly* bad idea, because all or part
2471  * of this struct can be invalid at any given time. Use the functions,
2472  * or you will get hosed, I promise.
2473  */
2474 struct _GDate
2475
2476   guint julian_days : 32; /* julian days representation - we use a
2477                            *  bitfield hoping that 64 bit platforms
2478                            *  will pack this whole struct in one big
2479                            *  int 
2480                            */
2481
2482   guint julian : 1;    /* julian is valid */
2483   guint dmy    : 1;    /* dmy is valid */
2484
2485   /* DMY representation */
2486   guint day    : 6;  
2487   guint month  : 4; 
2488   guint year   : 16; 
2489 };
2490
2491 /* g_date_new() returns an invalid date, you then have to _set() stuff 
2492  * to get a usable object. You can also allocate a GDate statically,
2493  * then call g_date_clear() to initialize.
2494  */
2495 GDate*       g_date_new                   (void);
2496 GDate*       g_date_new_dmy               (GDateDay     day, 
2497                                            GDateMonth   month, 
2498                                            GDateYear    year);
2499 GDate*       g_date_new_julian            (guint32      julian_day);
2500 void         g_date_free                  (GDate       *date);
2501
2502 /* check g_date_valid() after doing an operation that might fail, like
2503  * _parse.  Almost all g_date operations are undefined on invalid
2504  * dates (the exceptions are the mutators, since you need those to
2505  * return to validity).  
2506  */
2507 gboolean     g_date_valid                 (GDate       *date);
2508 gboolean     g_date_valid_day             (GDateDay     day);
2509 gboolean     g_date_valid_month           (GDateMonth   month);
2510 gboolean     g_date_valid_year            (GDateYear    year);
2511 gboolean     g_date_valid_weekday         (GDateWeekday weekday);
2512 gboolean     g_date_valid_julian          (guint32      julian_date);
2513 gboolean     g_date_valid_dmy             (GDateDay     day,
2514                                            GDateMonth   month,
2515                                            GDateYear    year);
2516
2517 GDateWeekday g_date_weekday               (GDate       *date);
2518 GDateMonth   g_date_month                 (GDate       *date);
2519 GDateYear    g_date_year                  (GDate       *date);
2520 GDateDay     g_date_day                   (GDate       *date);
2521 guint32      g_date_julian                (GDate       *date);
2522 guint        g_date_day_of_year           (GDate       *date);
2523
2524 /* First monday/sunday is the start of week 1; if we haven't reached
2525  * that day, return 0. These are not ISO weeks of the year; that
2526  * routine needs to be added.
2527  * these functions return the number of weeks, starting on the
2528  * corrsponding day
2529  */
2530 guint        g_date_monday_week_of_year   (GDate      *date);
2531 guint        g_date_sunday_week_of_year   (GDate      *date);
2532
2533 /* If you create a static date struct you need to clear it to get it
2534  * in a sane state before use. You can clear a whole array at
2535  * once with the ndates argument.
2536  */
2537 void         g_date_clear                 (GDate       *date, 
2538                                            guint        n_dates);
2539
2540 /* The parse routine is meant for dates typed in by a user, so it
2541  * permits many formats but tries to catch common typos. If your data
2542  * needs to be strictly validated, it is not an appropriate function.
2543  */
2544 void         g_date_set_parse             (GDate       *date,
2545                                            const gchar *str);
2546 void         g_date_set_time              (GDate       *date, 
2547                                            GTime        time);
2548 void         g_date_set_month             (GDate       *date, 
2549                                            GDateMonth   month);
2550 void         g_date_set_day               (GDate       *date, 
2551                                            GDateDay     day);
2552 void         g_date_set_year              (GDate       *date,
2553                                            GDateYear    year);
2554 void         g_date_set_dmy               (GDate       *date,
2555                                            GDateDay     day,
2556                                            GDateMonth   month,
2557                                            GDateYear    y);
2558 void         g_date_set_julian            (GDate       *date,
2559                                            guint32      julian_date);
2560 gboolean     g_date_is_first_of_month     (GDate       *date);
2561 gboolean     g_date_is_last_of_month      (GDate       *date);
2562
2563 /* To go forward by some number of weeks just go forward weeks*7 days */
2564 void         g_date_add_days              (GDate       *date, 
2565                                            guint        n_days);
2566 void         g_date_subtract_days         (GDate       *date, 
2567                                            guint        n_days);
2568
2569 /* If you add/sub months while day > 28, the day might change */
2570 void         g_date_add_months            (GDate       *date,
2571                                            guint        n_months);
2572 void         g_date_subtract_months       (GDate       *date,
2573                                            guint        n_months);
2574
2575 /* If it's feb 29, changing years can move you to the 28th */
2576 void         g_date_add_years             (GDate       *date,
2577                                            guint        n_years);
2578 void         g_date_subtract_years        (GDate       *date,
2579                                            guint        n_years);
2580 gboolean     g_date_is_leap_year          (GDateYear    year) G_GNUC_CONST;
2581 guint8       g_date_days_in_month         (GDateMonth   month, 
2582                                            GDateYear    year) G_GNUC_CONST;
2583 guint8       g_date_monday_weeks_in_year  (GDateYear    year) G_GNUC_CONST;
2584 guint8       g_date_sunday_weeks_in_year  (GDateYear    year) G_GNUC_CONST;
2585
2586 /* qsort-friendly (with a cast...) */
2587 gint         g_date_compare               (GDate       *lhs,
2588                                            GDate       *rhs);
2589 void         g_date_to_struct_tm          (GDate       *date,
2590                                            struct tm   *tm);
2591
2592 /* Just like strftime() except you can only use date-related formats.
2593  *   Using a time format is undefined.
2594  */
2595 gsize        g_date_strftime              (gchar       *s,
2596                                            gsize        slen,
2597                                            const gchar *format,
2598                                            GDate       *date);
2599
2600
2601 /* GRelation
2602  *
2603  * Indexed Relations.  Imagine a really simple table in a
2604  * database.  Relations are not ordered.  This data type is meant for
2605  * maintaining a N-way mapping.
2606  *
2607  * g_relation_new() creates a relation with FIELDS fields
2608  *
2609  * g_relation_destroy() frees all resources
2610  * g_tuples_destroy() frees the result of g_relation_select()
2611  *
2612  * g_relation_index() indexes relation FIELD with the provided
2613  *   equality and hash functions.  this must be done before any
2614  *   calls to insert are made.
2615  *
2616  * g_relation_insert() inserts a new tuple.  you are expected to
2617  *   provide the right number of fields.
2618  *
2619  * g_relation_delete() deletes all relations with KEY in FIELD
2620  * g_relation_select() returns ...
2621  * g_relation_count() counts ...
2622  */
2623
2624 GRelation* g_relation_new     (gint         fields);
2625 void       g_relation_destroy (GRelation   *relation);
2626 void       g_relation_index   (GRelation   *relation,
2627                                gint         field,
2628                                GHashFunc    hash_func,
2629                                GCompareFunc key_compare_func);
2630 void       g_relation_insert  (GRelation   *relation,
2631                                ...);
2632 gint       g_relation_delete  (GRelation   *relation,
2633                                gconstpointer  key,
2634                                gint         field);
2635 GTuples*   g_relation_select  (GRelation   *relation,
2636                                gconstpointer  key,
2637                                gint         field);
2638 gint       g_relation_count   (GRelation   *relation,
2639                                gconstpointer  key,
2640                                gint         field);
2641 gboolean   g_relation_exists  (GRelation   *relation,
2642                                ...);
2643 void       g_relation_print   (GRelation   *relation);
2644
2645 void       g_tuples_destroy   (GTuples     *tuples);
2646 gpointer   g_tuples_index     (GTuples     *tuples,
2647                                gint         index,
2648                                gint         field);
2649
2650
2651 /* GRand - a good and fast random number generator: Mersenne Twister 
2652  * see http://www.math.keio.ac.jp/~matumoto/emt.html for more info.
2653  * The range functions return a value in the intervall [min,max).
2654  * int          -> [0..2^32-1]
2655  * int_range    -> [min..max-1]
2656  * double       -> [0..1)
2657  * double_range -> [min..max)
2658  */
2659
2660 GRand*  g_rand_new_with_seed   (guint32     seed);
2661 GRand*  g_rand_new             (void);
2662 void    g_rand_free            (GRand      *rand);
2663
2664 void    g_rand_set_seed        (GRand      *rand, 
2665                                 guint32     seed);
2666 guint32 g_rand_int             (GRand      *rand);
2667 gint32  g_rand_int_range       (GRand      *rand, 
2668                                 gint32      min, 
2669                                 gint32      max);
2670 gdouble g_rand_double          (GRand      *rand);
2671 gdouble g_rand_double_range    (GRand      *rand, 
2672                                 gdouble     min, 
2673                                 gdouble     max);
2674
2675 void    g_random_set_seed      (guint32     seed);
2676 guint32 g_random_int           (void);
2677 gint32  g_random_int_range     (gint32      min, 
2678                                 gint32      max);
2679 gdouble g_random_double        (void);
2680 gdouble g_random_double_range  (gdouble     min, 
2681                                 gdouble     max);
2682  
2683
2684 /* Prime numbers.
2685  */
2686
2687 /* This function returns prime numbers spaced by approximately 1.5-2.0
2688  * and is for use in resizing data structures which prefer
2689  * prime-valued sizes.  The closest spaced prime function returns the
2690  * next largest prime, or the highest it knows about which is about
2691  * MAXINT/4.
2692  */
2693 guint      g_spaced_primes_closest (guint num) G_GNUC_CONST;
2694
2695
2696 /* GIOChannel
2697  */
2698
2699 typedef struct _GIOFuncs GIOFuncs;
2700 typedef enum
2701 {
2702   G_IO_ERROR_NONE,
2703   G_IO_ERROR_AGAIN,
2704   G_IO_ERROR_INVAL,
2705   G_IO_ERROR_UNKNOWN
2706 } GIOError;
2707 typedef enum
2708 {
2709   G_SEEK_CUR,
2710   G_SEEK_SET,
2711   G_SEEK_END
2712 } GSeekType;
2713 typedef enum
2714 {
2715   G_IO_IN       GLIB_SYSDEF_POLLIN,
2716   G_IO_OUT      GLIB_SYSDEF_POLLOUT,
2717   G_IO_PRI      GLIB_SYSDEF_POLLPRI,
2718   G_IO_ERR      GLIB_SYSDEF_POLLERR,
2719   G_IO_HUP      GLIB_SYSDEF_POLLHUP,
2720   G_IO_NVAL     GLIB_SYSDEF_POLLNVAL
2721 } GIOCondition;
2722
2723 struct _GIOChannel
2724 {
2725   guint channel_flags;
2726   guint ref_count;
2727   GIOFuncs *funcs;
2728 };
2729
2730 typedef gboolean (*GIOFunc) (GIOChannel   *source,
2731                              GIOCondition  condition,
2732                              gpointer      data);
2733 struct _GIOFuncs
2734 {
2735   GIOError (*io_read)   (GIOChannel     *channel, 
2736                          gchar          *buf, 
2737                          guint           count,
2738                          guint          *bytes_read);
2739   GIOError (*io_write)  (GIOChannel     *channel, 
2740                          gchar          *buf, 
2741                          guint           count,
2742                          guint          *bytes_written);
2743   GIOError (*io_seek)   (GIOChannel     *channel, 
2744                          gint            offset, 
2745                          GSeekType       type);
2746   void (*io_close)      (GIOChannel     *channel);
2747   guint (*io_add_watch) (GIOChannel     *channel,
2748                          gint            priority,
2749                          GIOCondition    condition,
2750                          GIOFunc         func,
2751                          gpointer        user_data,
2752                          GDestroyNotify  notify);
2753   void (*io_free)       (GIOChannel     *channel);
2754 };
2755
2756 void        g_io_channel_init   (GIOChannel    *channel);
2757 void        g_io_channel_ref    (GIOChannel    *channel);
2758 void        g_io_channel_unref  (GIOChannel    *channel);
2759 GIOError    g_io_channel_read   (GIOChannel    *channel, 
2760                                  gchar         *buf, 
2761                                  guint          count,
2762                                  guint         *bytes_read);
2763 GIOError  g_io_channel_write    (GIOChannel    *channel, 
2764                                  gchar         *buf, 
2765                                  guint          count,
2766                                  guint         *bytes_written);
2767 GIOError  g_io_channel_seek     (GIOChannel    *channel,
2768                                  gint           offset, 
2769                                  GSeekType      type);
2770 void      g_io_channel_close    (GIOChannel    *channel);
2771 guint     g_io_add_watch_full   (GIOChannel    *channel,
2772                                  gint           priority,
2773                                  GIOCondition   condition,
2774                                  GIOFunc        func,
2775                                  gpointer       user_data,
2776                                  GDestroyNotify notify);
2777 guint    g_io_add_watch         (GIOChannel    *channel,
2778                                  GIOCondition   condition,
2779                                  GIOFunc        func,
2780                                  gpointer       user_data);
2781
2782
2783 /* Main loop
2784  */
2785 typedef struct _GTimeVal        GTimeVal;
2786 typedef struct _GSourceFuncs    GSourceFuncs;
2787 typedef struct _GMainLoop       GMainLoop;      /* Opaque */
2788
2789 struct _GTimeVal
2790 {
2791   glong tv_sec;
2792   glong tv_usec;
2793 };
2794 struct _GSourceFuncs
2795 {
2796   gboolean (*prepare)  (gpointer  source_data, 
2797                         GTimeVal *current_time,
2798                         gint     *timeout,
2799                         gpointer  user_data);
2800   gboolean (*check)    (gpointer  source_data,
2801                         GTimeVal *current_time,
2802                         gpointer  user_data);
2803   gboolean (*dispatch) (gpointer  source_data, 
2804                         GTimeVal *dispatch_time,
2805                         gpointer  user_data);
2806   GDestroyNotify destroy;
2807 };
2808
2809 /* Standard priorities */
2810
2811 #define G_PRIORITY_HIGH            -100
2812 #define G_PRIORITY_DEFAULT          0
2813 #define G_PRIORITY_HIGH_IDLE        100
2814 #define G_PRIORITY_DEFAULT_IDLE     200
2815 #define G_PRIORITY_LOW              300
2816
2817 typedef gboolean (*GSourceFunc) (gpointer data);
2818
2819 /* Hooks for adding to the main loop */
2820 guint    g_source_add                        (gint           priority, 
2821                                               gboolean       can_recurse,
2822                                               GSourceFuncs  *funcs,
2823                                               gpointer       source_data, 
2824                                               gpointer       user_data,
2825                                               GDestroyNotify notify);
2826 gboolean g_source_remove                     (guint          tag);
2827 gboolean g_source_remove_by_user_data        (gpointer       user_data);
2828 gboolean g_source_remove_by_source_data      (gpointer       source_data);
2829 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
2830                                               gpointer       user_data);
2831
2832 void g_get_current_time                 (GTimeVal       *result);
2833
2834 /* Running the main loop */
2835 GMainLoop*      g_main_new              (gboolean        is_running);
2836 void            g_main_run              (GMainLoop      *loop);
2837 void            g_main_quit             (GMainLoop      *loop);
2838 void            g_main_destroy          (GMainLoop      *loop);
2839 gboolean        g_main_is_running       (GMainLoop      *loop);
2840
2841 /* Run a single iteration of the mainloop. If block is FALSE,
2842  * will never block
2843  */
2844 gboolean        g_main_iteration        (gboolean       may_block);
2845
2846 /* See if any events are pending */
2847 gboolean        g_main_pending          (void);
2848
2849 /* Idles and timeouts */
2850 guint           g_timeout_add_full      (gint           priority,
2851                                          guint          interval, 
2852                                          GSourceFunc    function,
2853                                          gpointer       data,
2854                                          GDestroyNotify notify);
2855 guint           g_timeout_add           (guint          interval,
2856                                          GSourceFunc    function,
2857                                          gpointer       data);
2858 guint           g_idle_add              (GSourceFunc    function,
2859                                          gpointer       data);
2860 guint           g_idle_add_full         (gint           priority,
2861                                          GSourceFunc    function,
2862                                          gpointer       data,
2863                                          GDestroyNotify destroy);
2864 gboolean        g_idle_remove_by_data   (gpointer       data);
2865
2866 /* GPollFD
2867  *
2868  * System-specific IO and main loop calls
2869  *
2870  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
2871  * descriptor as provided by the C runtime) that can be used by
2872  * MsgWaitForMultipleObjects. This does *not* include file handles
2873  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
2874  * WSAEventSelect to signal events when a SOCKET is readable).
2875  *
2876  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
2877  * indicate polling for messages. These message queue GPollFDs should
2878  * be added with the g_main_poll_win32_msg_add function.
2879  *
2880  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
2881  * (GTK) programs, as GDK itself wants to read messages and convert them
2882  * to GDK events.
2883  *
2884  * So, unless you really know what you are doing, it's best not to try
2885  * to use the main loop polling stuff for your own needs on
2886  * Win32. It's really only written for the GIMP's needs so
2887  * far.
2888  */
2889
2890 typedef struct _GPollFD GPollFD;
2891 typedef gint    (*GPollFunc)    (GPollFD *ufds,
2892                                  guint    nfsd,
2893                                  gint     timeout);
2894 struct _GPollFD
2895 {
2896   gint          fd;
2897   gushort       events;
2898   gushort       revents;
2899 };
2900
2901 void        g_main_add_poll          (GPollFD    *fd,
2902                                       gint        priority);
2903 void        g_main_remove_poll       (GPollFD    *fd);
2904 void        g_main_set_poll_func     (GPollFunc   func);
2905
2906 #ifdef G_OS_WIN32
2907
2908 /* Useful on other platforms, too? */
2909
2910 GPollFunc   g_main_win32_get_poll_func (void);
2911
2912 #endif
2913
2914 /* On Unix, IO channels created with this function for any file
2915  * descriptor or socket.
2916  *
2917  * On Win32, use this only for files opened with the MSVCRT (the
2918  * Microsoft run-time C library) _open() or _pipe, including file
2919  * descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr).
2920  *
2921  * The term file descriptor as used in the context of Win32 refers to
2922  * the emulated Unix-like file descriptors MSVCRT provides. The native
2923  * corresponding concept is file HANDLE. There isn't as of yet a way to
2924  * get GIOChannels for file HANDLEs.
2925  */
2926 GIOChannel* g_io_channel_unix_new    (int         fd);
2927 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
2928
2929 #ifdef G_OS_WIN32
2930
2931 #define G_WIN32_MSG_HANDLE 19981206
2932
2933 /* Use this to get a GPollFD from a GIOChannel, so that you can call
2934  * g_io_channel_win32_poll(). After calling this you should only use
2935  * g_io_channel_read() to read from the GIOChannel, i.e. never read()
2936  * or recv() from the underlying file descriptor or SOCKET.
2937  */
2938 void        g_io_channel_win32_make_pollfd (GIOChannel   *channel,
2939                                             GIOCondition  condition,
2940                                             GPollFD      *fd);
2941
2942 /* This can be used to wait a until at least one of the channels is readable.
2943  * On Unix you would do a select() on the file descriptors of the channels.
2944  * This should probably be available for all platforms?
2945  */
2946 gint        g_io_channel_win32_poll   (GPollFD    *fds,
2947                                        gint        n_fds,
2948                                        gint        timeout);
2949
2950 /* This is used to add polling for Windows messages. GDK (GTk+) programs
2951  * should *not* use this.
2952  */
2953 void        g_main_poll_win32_msg_add (gint        priority,
2954                                        GPollFD    *fd,
2955                                        guint       hwnd);
2956
2957 /* An IO channel for Windows messages for window handle hwnd. */
2958 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
2959
2960 /* An IO channel for C runtime (emulated Unix-like) file
2961  * descriptors. Identical to g_io_channel_unix_new above.
2962  * After calling g_io_add_watch() on a IO channel returned
2963  * by this function, you shouldn't call read() on the file
2964  * descriptor.
2965  */
2966 GIOChannel* g_io_channel_win32_new_fd (int         fd);
2967
2968 /* Get the C runtime file descriptor of a channel. */
2969 gint        g_io_channel_win32_get_fd (GIOChannel *channel);
2970
2971 /* An IO channel for a SOCK_STREAM winsock socket. The parameter
2972  * should be a SOCKET. After calling g_io_add_watch() on a IO channel
2973  * returned by this function, you shouldn't call recv() on the SOCKET.
2974  */
2975 GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
2976
2977 #endif
2978
2979 /* Windows emulation stubs for common Unix functions
2980  */
2981 #ifdef G_OS_WIN32
2982 #  define MAXPATHLEN 1024
2983
2984 #ifdef _MSC_VER
2985 typedef int pid_t;
2986 #endif
2987
2988 /*
2989  * To get prototypes for the following POSIXish functions, you have to
2990  * include the indicated non-POSIX headers. The functions are defined
2991  * in OLDNAMES.LIB (MSVC) or -lmoldname-msvc (mingw32).
2992  *
2993  * getcwd: <direct.h> (MSVC), <io.h> (mingw32)
2994  * getpid: <process.h>
2995  * access: <io.h>
2996  * unlink: <stdio.h> or <io.h>
2997  * open, read, write, lseek, close: <io.h>
2998  * rmdir: <direct.h>
2999  * pipe: <direct.h>
3000  */
3001
3002 /* pipe is not in OLDNAMES.LIB or -lmoldname-msvc. */
3003 #define pipe(phandles)  _pipe (phandles, 4096, _O_BINARY)
3004
3005 /* For some POSIX functions that are not provided by the MS runtime,
3006  * we provide emulators in glib, which are prefixed with g_win32_.
3007  */
3008 #    define ftruncate(fd, size) g_win32_ftruncate (fd, size)
3009
3010 /* -lmingw32 also has emulations for these, but we need our own
3011  * for MSVC anyhow, so we might aswell use them always.
3012  */
3013 #    define opendir             g_win32_opendir
3014 #    define readdir             g_win32_readdir
3015 #    define rewinddir           g_win32_rewinddir
3016 #    define closedir            g_win32_closedir
3017 #    define NAME_MAX 255
3018
3019 struct DIR
3020 {
3021   gchar    *dir_name;
3022   gboolean  just_opened;
3023   guint     find_file_handle;
3024   gpointer  find_file_data;
3025 };
3026 typedef struct DIR DIR;
3027 struct dirent
3028 {
3029   gchar  d_name[NAME_MAX + 1];
3030 };
3031 /* emulation functions */
3032 extern int      g_win32_ftruncate       (gint            f,
3033                                          guint           size);
3034 DIR*            g_win32_opendir         (const gchar    *dirname);
3035 struct dirent*  g_win32_readdir         (DIR            *dir);
3036 void            g_win32_rewinddir       (DIR            *dir);
3037 gint            g_win32_closedir        (DIR            *dir);
3038
3039 /* The MS setlocale uses locale names of the form "English_United
3040  * States.1252" etc. We want the Unixish standard form "en", "zh_TW"
3041  * etc. This function gets the current thread locale from Windows and
3042  * returns it as a string of the above form for use in forming file
3043  * names etc. The returned string should be deallocated with g_free().
3044  */
3045 gchar *         g_win32_getlocale  (void);
3046
3047 /* Translate a Win32 error code (as returned by GetLastError()) into
3048  * the corresponding message. The returned string should be deallocated
3049  * with g_free().
3050  */
3051 gchar *         g_win32_error_message (gint error);
3052
3053 #endif   /* G_OS_WIN32 */
3054
3055
3056 /* GLib Thread support
3057  */
3058
3059 extern GQuark g_thread_error_quark();
3060 #define G_THREAD_ERROR g_thread_error_quark()
3061
3062 typedef enum
3063 {
3064   G_THREAD_ERROR_AGAIN /* Resource temporarily unavailable */
3065 } GThreadError;
3066
3067 typedef void            (*GThreadFunc)          (gpointer       value);
3068
3069 typedef enum
3070 {
3071     G_THREAD_PRIORITY_LOW,
3072     G_THREAD_PRIORITY_NORMAL,
3073     G_THREAD_PRIORITY_HIGH,
3074     G_THREAD_PRIORITY_URGENT
3075 } GThreadPriority;
3076
3077 typedef struct _GThread         GThread;
3078 struct  _GThread
3079 {
3080   GThreadPriority priority;
3081   gboolean bound;
3082   gboolean joinable;
3083 };
3084
3085 typedef struct _GMutex          GMutex;
3086 typedef struct _GCond           GCond;
3087 typedef struct _GPrivate        GPrivate;
3088 typedef struct _GStaticPrivate  GStaticPrivate;
3089 typedef struct _GAsyncQueue     GAsyncQueue;
3090 typedef struct _GThreadPool     GThreadPool;
3091
3092 typedef struct _GThreadFunctions GThreadFunctions;
3093 struct _GThreadFunctions
3094 {
3095   GMutex*  (*mutex_new)           (void);
3096   void     (*mutex_lock)          (GMutex               *mutex);
3097   gboolean (*mutex_trylock)       (GMutex               *mutex);
3098   void     (*mutex_unlock)        (GMutex               *mutex);
3099   void     (*mutex_free)          (GMutex               *mutex);
3100   GCond*   (*cond_new)            (void);
3101   void     (*cond_signal)         (GCond                *cond);
3102   void     (*cond_broadcast)      (GCond                *cond);
3103   void     (*cond_wait)           (GCond                *cond,
3104                                    GMutex               *mutex);
3105   gboolean (*cond_timed_wait)     (GCond                *cond,
3106                                    GMutex               *mutex, 
3107                                    GTimeVal             *end_time);
3108   void      (*cond_free)          (GCond                *cond);
3109   GPrivate* (*private_new)        (GDestroyNotify        destructor);
3110   gpointer  (*private_get)        (GPrivate             *private_key);
3111   void      (*private_set)        (GPrivate             *private_key,
3112                                    gpointer              data);
3113   void      (*thread_create)      (GThreadFunc           thread_func,
3114                                    gpointer              arg,
3115                                    gulong                stack_size,
3116                                    gboolean              joinable,
3117                                    gboolean              bound,
3118                                    GThreadPriority       priority,
3119                                    gpointer              thread,
3120                                    GError              **error);
3121   void      (*thread_yield)       (void);
3122   void      (*thread_join)        (gpointer              thread);
3123   void      (*thread_exit)        (void);
3124   void      (*thread_set_priority)(gpointer              thread, 
3125                                    GThreadPriority       priority);
3126   void      (*thread_self)        (gpointer              thread);
3127 };
3128
3129 GLIB_VAR GThreadFunctions       g_thread_functions_for_glib_use;
3130 GLIB_VAR gboolean               g_thread_use_default_impl;
3131 GLIB_VAR gboolean               g_threads_got_initialized;
3132
3133 /* initializes the mutex/cond/private implementation for glib, might
3134  * only be called once, and must not be called directly or indirectly
3135  * from another glib-function, e.g. as a callback.
3136  */
3137 void    g_thread_init   (GThreadFunctions       *vtable);
3138
3139 /* internal function for fallback static mutex implementation */
3140 GMutex* g_static_mutex_get_mutex_impl   (GMutex **mutex);
3141
3142 /* shorthands for conditional and unconditional function calls */
3143 #define G_THREAD_UF(name, arglist) \
3144     (*g_thread_functions_for_glib_use . name) arglist
3145 #define G_THREAD_CF(name, fail, arg) \
3146     (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
3147 /* keep in mind, all those mutexes and static mutexes are not 
3148  * recursive in general, don't rely on that
3149  */
3150 #define g_thread_supported()    (g_threads_got_initialized)
3151 #define g_mutex_new()            G_THREAD_UF (mutex_new,      ())
3152 #define g_mutex_lock(mutex)      G_THREAD_CF (mutex_lock,     (void)0, (mutex))
3153 #define g_mutex_trylock(mutex)   G_THREAD_CF (mutex_trylock,  TRUE,    (mutex))
3154 #define g_mutex_unlock(mutex)    G_THREAD_CF (mutex_unlock,   (void)0, (mutex))
3155 #define g_mutex_free(mutex)      G_THREAD_CF (mutex_free,     (void)0, (mutex))
3156 #define g_cond_new()             G_THREAD_UF (cond_new,       ())
3157 #define g_cond_signal(cond)      G_THREAD_CF (cond_signal,    (void)0, (cond))
3158 #define g_cond_broadcast(cond)   G_THREAD_CF (cond_broadcast, (void)0, (cond))
3159 #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait,      (void)0, (cond, \
3160                                                                         mutex))
3161 #define g_cond_free(cond)        G_THREAD_CF (cond_free,      (void)0, (cond))
3162 #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
3163                                                               TRUE, \
3164                                                               (cond, mutex, \
3165                                                                abs_time))
3166 #define g_private_new(destructor)         G_THREAD_UF (private_new, (destructor))
3167 #define g_private_get(private_key)        G_THREAD_CF (private_get, \
3168                                                        ((gpointer)private_key), \
3169                                                        (private_key))
3170 #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
3171                                                        (void) (private_key = \
3172                                                         (GPrivate*) (value)), \
3173                                                        (private_key, value))
3174 #define g_thread_yield()              G_THREAD_CF (thread_yield, (void)0, ())
3175 #define g_thread_exit()               G_THREAD_CF (thread_exit, (void)0, ())
3176
3177 GThread* g_thread_create (GThreadFunc            thread_func,
3178                           gpointer               arg,
3179                           gulong                 stack_size,
3180                           gboolean               joinable,
3181                           gboolean               bound,
3182                           GThreadPriority        priority,
3183                           GError               **error);
3184 GThread* g_thread_self ();
3185 void g_thread_join (GThread *thread);
3186 void g_thread_set_priority (GThread         *thread, 
3187                             GThreadPriority  priority);
3188
3189 /* GStaticMutexes can be statically initialized with the value
3190  * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
3191  * much easier, than having to explicitly allocate the mutex before
3192  * use
3193  */
3194 #define g_static_mutex_lock(mutex) \
3195     g_mutex_lock (g_static_mutex_get_mutex (mutex))
3196 #define g_static_mutex_trylock(mutex) \
3197     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
3198 #define g_static_mutex_unlock(mutex) \
3199     g_mutex_unlock (g_static_mutex_get_mutex (mutex)) 
3200
3201 struct _GStaticPrivate
3202 {
3203   guint index;
3204 };
3205 #define G_STATIC_PRIVATE_INIT { 0 }
3206 gpointer g_static_private_get (GStaticPrivate   *private_key);
3207 void     g_static_private_set (GStaticPrivate   *private_key, 
3208                                gpointer          data,
3209                                GDestroyNotify    notify);
3210 gpointer g_static_private_get_for_thread (GStaticPrivate *private_key,
3211                                           GThread        *thread);
3212 void g_static_private_set_for_thread (GStaticPrivate *private_key, 
3213                                       GThread        *thread,
3214                                       gpointer        data,
3215                                       GDestroyNotify  notify);
3216
3217 typedef struct _GStaticRecMutex GStaticRecMutex;
3218 struct _GStaticRecMutex
3219 {
3220   GStaticMutex mutex;
3221   unsigned int depth;
3222   GSystemThread owner;
3223 };
3224
3225 #define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT }
3226 void     g_static_rec_mutex_lock        (GStaticRecMutex *mutex);
3227 gboolean g_static_rec_mutex_trylock     (GStaticRecMutex *mutex);
3228 void     g_static_rec_mutex_unlock      (GStaticRecMutex *mutex);
3229 void     g_static_rec_mutex_lock_full   (GStaticRecMutex *mutex,
3230                                          guint            depth);
3231 guint    g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
3232
3233 typedef struct _GStaticRWLock GStaticRWLock;
3234 struct _GStaticRWLock
3235 {
3236   GStaticMutex mutex; 
3237   GCond *read_cond;
3238   GCond *write_cond;
3239   guint read_counter;
3240   gboolean write;
3241   guint want_to_write;
3242 };
3243
3244 #define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, FALSE }
3245
3246 void      g_static_rw_lock_reader_lock    (GStaticRWLock* lock);
3247 gboolean  g_static_rw_lock_reader_trylock (GStaticRWLock* lock);
3248 void      g_static_rw_lock_reader_unlock  (GStaticRWLock* lock);
3249 void      g_static_rw_lock_writer_lock    (GStaticRWLock* lock);
3250 gboolean  g_static_rw_lock_writer_trylock (GStaticRWLock* lock);
3251 void      g_static_rw_lock_writer_unlock  (GStaticRWLock* lock);
3252 void      g_static_rw_lock_free (GStaticRWLock* lock);
3253
3254 /* these are some convenience macros that expand to nothing if GLib
3255  * was configured with --disable-threads. for using StaticMutexes,
3256  * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
3257  * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
3258  * declare such an globally defined lock. name is a unique identifier
3259  * for the protected varibale or code portion. locking, testing and
3260  * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
3261  * G_TRYLOCK() respectively.  
3262  */
3263 extern void glib_dummy_decl (void);
3264 #define G_LOCK_NAME(name)               g__ ## name ## _lock
3265 #ifdef  G_THREADS_ENABLED
3266 #  define G_LOCK_DEFINE_STATIC(name)    static G_LOCK_DEFINE (name)
3267 #  define G_LOCK_DEFINE(name)           \
3268     GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT 
3269 #  define G_LOCK_EXTERN(name)           extern GStaticMutex G_LOCK_NAME (name)
3270
3271 #  ifdef G_DEBUG_LOCKS
3272 #    define G_LOCK(name)                G_STMT_START{             \
3273         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
3274                "file %s: line %d (%s): locking: %s ",             \
3275                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
3276                #name);                                            \
3277         g_static_mutex_lock (&G_LOCK_NAME (name));                \
3278      }G_STMT_END
3279 #    define G_UNLOCK(name)              G_STMT_START{             \
3280         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
3281                "file %s: line %d (%s): unlocking: %s ",           \
3282                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
3283                #name);                                            \
3284        g_static_mutex_unlock (&G_LOCK_NAME (name));               \
3285      }G_STMT_END
3286 #    define G_TRYLOCK(name)                                       \
3287         (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                  \
3288                "file %s: line %d (%s): try locking: %s ",         \
3289                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
3290                #name), g_static_mutex_trylock (&G_LOCK_NAME (name)))
3291 #  else  /* !G_DEBUG_LOCKS */
3292 #    define G_LOCK(name) g_static_mutex_lock       (&G_LOCK_NAME (name)) 
3293 #    define G_UNLOCK(name) g_static_mutex_unlock   (&G_LOCK_NAME (name))
3294 #    define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
3295 #  endif /* !G_DEBUG_LOCKS */
3296 #else   /* !G_THREADS_ENABLED */
3297 #  define G_LOCK_DEFINE_STATIC(name)    extern void glib_dummy_decl (void)
3298 #  define G_LOCK_DEFINE(name)           extern void glib_dummy_decl (void)
3299 #  define G_LOCK_EXTERN(name)           extern void glib_dummy_decl (void)
3300 #  define G_LOCK(name)
3301 #  define G_UNLOCK(name)
3302 #  define G_TRYLOCK(name)               (TRUE)
3303 #endif  /* !G_THREADS_ENABLED */
3304
3305 /* Asyncronous Queues, can be used to communicate between threads
3306  */
3307
3308 /* Get a new GAsyncQueue with the ref_count 1 */
3309 GAsyncQueue*  g_async_queue_new                (void);
3310
3311 /* Lock and unlock an GAsyncQueue, all functions lock the queue for
3312  * themselves, but in certain cirumstances you want to hold the lock longer,
3313  * thus you lock the queue, call the *_unlocked functions and unlock it again
3314  */
3315 void          g_async_queue_lock               (GAsyncQueue *queue);
3316 void          g_async_queue_unlock             (GAsyncQueue *queue);
3317
3318 /* Ref and unref the GAsyncQueue. g_async_queue_unref_unlocked makes
3319  * no sense, as after the unreffing the Queue might be gone and can't
3320  * be unlocked. So you have a function to call, if you don't hold the
3321  * lock (g_async_queue_unref) and one to call, when you already hold
3322  * the lock (g_async_queue_unref_and_unlock). After that however, you
3323  * don't hold the lock anymore and the Queue might in fact be
3324  * destroyed, if you unrefed to zero */
3325 void          g_async_queue_ref                (GAsyncQueue *queue);
3326 void          g_async_queue_ref_unlocked       (GAsyncQueue *queue);
3327 void          g_async_queue_unref              (GAsyncQueue *queue);
3328 void          g_async_queue_unref_and_unlock   (GAsyncQueue *queue);
3329
3330 /* Push data into the async queue. Must not be NULL */
3331 void          g_async_queue_push               (GAsyncQueue *queue,
3332                                                 gpointer     data);
3333 void          g_async_queue_push_unlocked      (GAsyncQueue *queue,
3334                                                 gpointer     data);
3335
3336 /* Pop data from the async queue, when no data is there, the thread is blocked
3337  * until data arrives */
3338 gpointer      g_async_queue_pop                (GAsyncQueue *queue);
3339 gpointer      g_async_queue_pop_unlocked       (GAsyncQueue *queue);
3340
3341 /* Try to pop data, NULL is returned in case of empty queue */
3342 gpointer      g_async_queue_try_pop            (GAsyncQueue *queue);
3343 gpointer      g_async_queue_try_pop_unlocked   (GAsyncQueue *queue);
3344
3345 /* Wait for data until at maximum until end_time is reached, NULL is returned
3346  * in case of empty queue*/
3347 gpointer      g_async_queue_timed_pop          (GAsyncQueue *queue, 
3348                                                 GTimeVal    *end_time);
3349 gpointer      g_async_queue_timed_pop_unlocked (GAsyncQueue *queue, 
3350                                                 GTimeVal    *end_time);
3351
3352 /* Return the length of the queue, negative values mean, that threads
3353  * are waiting, positve values mean, that there are entries in the
3354  * queue. Actually this function returns the length of the queue minus
3355  * the number of waiting threads, g_async_queue_length == 0 could also
3356  * mean 'n' entries in the queue and 'n' thread waiting, such can
3357  * happen due to locking of the queue or due to scheduling. */
3358 gint          g_async_queue_length             (GAsyncQueue *queue);
3359 gint          g_async_queue_length_unlocked    (GAsyncQueue *queue);
3360
3361 /* Thread Pools
3362  */
3363
3364 /* The real GThreadPool is bigger, so you may only create a thread
3365  * pool with the constructor function */
3366 struct _GThreadPool
3367 {
3368   GFunc thread_func;
3369   gulong stack_size;
3370   gboolean bound; 
3371   GThreadPriority priority;
3372   gboolean exclusive;
3373   gpointer user_data;
3374 };
3375
3376 /* Get a thread pool with the function thread_func, at most max_threads may
3377  * run at a time (max_threads == -1 means no limit), stack_size, bound,
3378  * priority like in g_thread_create, exclusive == TRUE means, that the threads
3379  * shouldn't be shared and that they will be prestarted (otherwise they are
3380  * started, as needed) user_data is the 2nd argument to the thread_func */
3381 GThreadPool*    g_thread_pool_new             (GFunc            thread_func,
3382                                                gint             max_threads,
3383                                                gulong           stack_size,
3384                                                gboolean         bound,
3385                                                GThreadPriority  priority,
3386                                                gboolean         exclusive,
3387                                                gpointer         user_data,
3388                                                GError         **error);
3389
3390 /* Push new data into the thread pool. This task is assigned to a thread later
3391  * (when the maximal number of threads is reached for that pool) or now
3392  * (otherwise). If necessary a new thread will be started. The function
3393  * returns immediatly */
3394 void            g_thread_pool_push            (GThreadPool     *pool,
3395                                                gpointer         data,
3396                                                GError         **error);
3397
3398 /* Set the number of threads, which can run concurrently for that pool, -1
3399  * means no limit. 0 means has the effect, that the pool won't process
3400  * requests until the limit is set higher again */
3401 void            g_thread_pool_set_max_threads (GThreadPool     *pool,
3402                                                gint             max_threads,
3403                                                GError         **error);
3404 gint            g_thread_pool_get_max_threads (GThreadPool     *pool);
3405
3406 /* Get the number of threads assigned to that pool. This number doesn't
3407  * necessarily represent the number of working threads in that pool */
3408 guint           g_thread_pool_get_num_threads (GThreadPool     *pool);
3409
3410 /* Get the number of unprocessed items in the pool */
3411 guint           g_thread_pool_unprocessed     (GThreadPool     *pool);
3412
3413 /* Free the pool, immediate means, that all unprocessed items in the queue
3414  * wont be processed, wait means, that the function doesn't return immediatly,
3415  * but after all threads in the pool are ready processing items. immediate
3416  * does however not mean, that threads are killed. */
3417 void            g_thread_pool_free            (GThreadPool     *pool,
3418                                                gboolean         immediate,
3419                                                gboolean         wait);
3420
3421 /* Set the maximal number of unused threads before threads will be stopped by
3422  * GLib, -1 means no limit */
3423 void            g_thread_pool_set_max_unused_threads (gint      max_threads);
3424 gint            g_thread_pool_get_max_unused_threads (void);
3425 guint           g_thread_pool_get_num_unused_threads (void);
3426
3427 /* Stop all currently unused threads, but leave the limit untouched */
3428 void            g_thread_pool_stop_unused_threads    (void);
3429
3430 #ifdef __cplusplus
3431 }
3432 #endif /* __cplusplus */
3433
3434 #include <gunicode.h>
3435
3436 #endif /* __G_LIB_H__ */