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