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