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