ae931dd14007b6fd78d57804b7f0d106739ac55f
[mono.git] / eglib / src / glib.h
1 #ifndef __GLIB_H
2 #define __GLIB_H
3
4 #include <stdarg.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <stddef.h>
9 #include <ctype.h>
10 #include <limits.h>
11
12 #ifdef _MSC_VER
13 #pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
14 #else
15 #include <stdint.h>
16 /* For pid_t */
17 #ifndef WIN32
18 #include <unistd.h>
19 #endif
20 #endif
21
22 #include <eglib-config.h>
23 #ifndef EGLIB_NO_REMAP
24 #include <eglib-remap.h>
25 #endif
26
27 #ifndef offsetof
28 #   define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
29 #endif
30
31 #define __EGLIB_X11 1
32
33 #ifdef  __cplusplus
34 #define G_BEGIN_DECLS  extern "C" {
35 #define G_END_DECLS    }
36 #else
37 #define G_BEGIN_DECLS
38 #define G_END_DECLS
39 #endif
40
41 G_BEGIN_DECLS
42
43 /*
44  * Basic data types
45  */
46 typedef int            gint;
47 typedef unsigned int   guint;
48 typedef short          gshort;
49 typedef unsigned short gushort;
50 typedef long           glong;
51 typedef unsigned long  gulong;
52 typedef void *         gpointer;
53 typedef const void *   gconstpointer;
54 typedef char           gchar;
55 typedef unsigned char  guchar;
56
57 #if !G_TYPES_DEFINED
58 #ifdef _MSC_VER
59 typedef __int8                          gint8;
60 typedef unsigned __int8         guint8;
61 typedef __int16                         gint16;
62 typedef unsigned __int16        guint16;
63 typedef __int32                         gint32;
64 typedef unsigned __int32        guint32;
65 typedef __int64                         gint64;
66 typedef unsigned __int64        guint64;
67 typedef float                           gfloat;
68 typedef double                          gdouble;
69 typedef unsigned __int16        gunichar2;
70 typedef int                 gboolean;
71 #else
72 /* Types defined in terms of the stdint.h */
73 typedef int8_t         gint8;
74 typedef uint8_t        guint8;
75 typedef int16_t        gint16;
76 typedef uint16_t       guint16;
77 typedef int32_t        gint32;
78 typedef uint32_t       guint32;
79 typedef int64_t        gint64;
80 typedef uint64_t       guint64;
81 typedef float          gfloat;
82 typedef double         gdouble;
83 typedef uint16_t       gunichar2;
84 typedef int32_t        gboolean;
85 #endif
86 #endif
87
88
89 /*
90  * Macros
91  */
92 #define G_N_ELEMENTS(s)      (sizeof(s) / sizeof ((s) [0]))
93
94 #define FALSE                0
95 #define TRUE                 1
96
97 #define G_MAXINT             INT_MAX
98 #define G_MININT             INT_MIN
99 #define G_MAXINT32           INT32_MAX
100 #define G_MININT32           INT32_MIN
101 #define G_MININT64           INT64_MIN
102 #define G_MAXINT64           INT64_MAX
103 #define G_MAXUINT64          UINT64_MAX
104
105 #define G_LITTLE_ENDIAN 1234
106 #define G_BIG_ENDIAN    4321
107 #define G_STMT_START    do 
108 #define G_STMT_END      while (0)
109
110 #define G_USEC_PER_SEC  1000000
111
112 #define ABS(a)         ((a) > 0 ? (a) : -(a))
113
114 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
115
116 #define EGLIB_STRINGIFY(x) #x
117 #define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
118 #define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
119
120 #define G_CONST_RETURN const
121
122 /*
123  * Allocation
124  */
125 void g_free (void *ptr);
126 static inline gpointer g_realloc (gpointer obj, gsize size) { if (!size) {g_free (obj); return 0;} return  realloc (obj, size);}
127 static inline gpointer g_malloc (gsize x) {if (x) return malloc (x); else return 0;}
128 static inline gpointer g_malloc0 (gsize x) {if (x) return calloc(1,x); else return 0;}
129 #define g_try_malloc(x)         g_malloc(x)
130 #define g_try_realloc(obj,size) g_realloc((obj),(size))
131
132 #define g_new(type,size)        ((type *) g_malloc (sizeof (type) * (size)))
133 #define g_new0(type,size)       ((type *) g_malloc0 (sizeof (type)* (size)))
134 #define g_newa(type,size)       ((type *) alloca (sizeof (type) * (size)))
135
136 #define g_memmove(dest,src,len) memmove (dest, src, len)
137 #define g_renew(struct_type, mem, n_structs) g_realloc (mem, sizeof (struct_type) * n_structs)
138 #define g_alloca(size)          alloca (size)
139
140 gpointer g_memdup (gconstpointer mem, guint byte_size);
141 static inline gchar   *g_strdup (const gchar *str) { if (str) {return strdup (str);} return NULL; }
142 gchar **g_strdupv (gchar **str_array);
143
144 typedef struct {
145         gpointer (*malloc)      (gsize    n_bytes);
146         gpointer (*realloc)     (gpointer mem, gsize n_bytes);
147         void     (*free)        (gpointer mem);
148         gpointer (*calloc)      (gsize    n_blocks, gsize n_block_bytes);
149         gpointer (*try_malloc)  (gsize    n_bytes);
150         gpointer (*try_realloc) (gpointer mem, gsize n_bytes);
151 } GMemVTable;
152
153 #define g_mem_set_vtable(x)
154
155 struct _GMemChunk {
156         guint alloc_size;
157 };
158
159 typedef struct _GMemChunk GMemChunk;
160 /*
161  * Misc.
162  */
163 #define g_atexit(func)  ((void) atexit (func))
164
165 const gchar *    g_getenv(const gchar *variable);
166 gboolean         g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
167 void             g_unsetenv(const gchar *variable);
168
169 gchar*           g_win32_getlocale(void);
170
171 /*
172  * Precondition macros
173  */
174 #define g_return_if_fail(x)  G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END
175 #define g_return_val_if_fail(x,e)  G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END
176
177 /*
178  * Hashtables
179  */
180 typedef struct _GHashTable GHashTable;
181 typedef void     (*GFunc)          (gpointer data, gpointer user_data);
182 typedef gint     (*GCompareFunc)   (gconstpointer a, gconstpointer b);
183 typedef gint     (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
184 typedef void     (*GHFunc)         (gpointer key, gpointer value, gpointer user_data);
185 typedef gboolean (*GHRFunc)        (gpointer key, gpointer value, gpointer user_data);
186 typedef void     (*GDestroyNotify) (gpointer data);
187 typedef guint    (*GHashFunc)      (gconstpointer key);
188 typedef gboolean (*GEqualFunc)     (gconstpointer a, gconstpointer b);
189 typedef void     (*GFreeFunc)      (gpointer       data);
190
191 GHashTable     *g_hash_table_new             (GHashFunc hash_func, GEqualFunc key_equal_func);
192 GHashTable     *g_hash_table_new_full        (GHashFunc hash_func, GEqualFunc key_equal_func,
193                                               GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
194 void            g_hash_table_insert_replace  (GHashTable *hash, gpointer key, gpointer value, gboolean replace);
195 guint           g_hash_table_size            (GHashTable *hash);
196 gpointer        g_hash_table_lookup          (GHashTable *hash, gconstpointer key);
197 gboolean        g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
198 void            g_hash_table_foreach         (GHashTable *hash, GHFunc func, gpointer user_data);
199 gpointer        g_hash_table_find            (GHashTable *hash, GHRFunc predicate, gpointer user_data);
200 gboolean        g_hash_table_remove          (GHashTable *hash, gconstpointer key);
201 guint           g_hash_table_foreach_remove  (GHashTable *hash, GHRFunc func, gpointer user_data);
202 guint           g_hash_table_foreach_steal   (GHashTable *hash, GHRFunc func, gpointer user_data);
203 void            g_hash_table_destroy         (GHashTable *hash);
204
205 guint           g_spaced_primes_closest      (guint x);
206
207 #define g_hash_table_insert(h,k,v)    g_hash_table_insert_replace ((h),(k),(v),FALSE)
208 #define g_hash_table_replace(h,k,v)   g_hash_table_insert_replace ((h),(k),(v),TRUE)
209
210 gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
211 guint    g_direct_hash  (gconstpointer v1);
212 gboolean g_int_equal    (gconstpointer v1, gconstpointer v2);
213 guint    g_int_hash     (gconstpointer v1);
214 gboolean g_str_equal    (gconstpointer v1, gconstpointer v2);
215 guint    g_str_hash     (gconstpointer v1);
216
217 #define  g_assert(x)     G_STMT_START { if (!(x)) g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x);  } G_STMT_END
218 #define  g_assert_not_reached() G_STMT_START { g_assertion_message ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); } G_STMT_END
219
220 /*
221  * Errors
222  */
223 typedef struct {
224         /* In the real glib, this is a GQuark, but we dont use/need that */
225         gpointer domain;
226         gint     code;
227         gchar   *message;
228 } GError;
229
230 void    g_clear_error (GError **error);
231 void    g_error_free (GError *error);
232 GError *g_error_new  (gpointer domain, gint code, const char *format, ...);
233 void    g_set_error  (GError **err, gpointer domain, gint code, const gchar *format, ...);
234 void    g_propagate_error (GError **dest, GError *src);
235
236 /*
237  * Strings utility
238  */
239 gchar       *g_strdup_printf  (const gchar *format, ...);
240 gchar       *g_strdup_vprintf (const gchar *format, va_list args);
241 gchar       *g_strndup        (const gchar *str, gsize n);
242 const gchar *g_strerror       (gint errnum);
243 gchar       *g_strndup        (const gchar *str, gsize n);
244 void         g_strfreev       (gchar **str_array);
245 gchar       *g_strconcat      (const gchar *first, ...);
246 gchar      **g_strsplit       (const gchar *string, const gchar *delimiter, gint max_tokens);
247 gchar      **g_strsplit_set   (const gchar *string, const gchar *delimiter, gint max_tokens);
248 gchar       *g_strreverse     (gchar *str);
249 gboolean     g_str_has_prefix (const gchar *str, const gchar *prefix);
250 gboolean     g_str_has_suffix (const gchar *str, const gchar *suffix);
251 guint        g_strv_length    (gchar **str_array);
252 gchar       *g_strjoin        (const gchar *separator, ...);
253 gchar       *g_strjoinv       (const gchar *separator, gchar **str_array);
254 gchar       *g_strchug        (gchar *str);
255 gchar       *g_strchomp       (gchar *str);
256 void         g_strdown        (gchar *string);
257 gchar       *g_strnfill       (gsize length, gchar fill_char);
258
259 gchar       *g_strdelimit     (gchar *string, const gchar *delimiters, gchar new_delimiter);
260 gchar       *g_strescape      (const gchar *source, const gchar *exceptions);
261
262 gchar       *g_filename_to_uri   (const gchar *filename, const gchar *hostname, GError **error);
263 gchar       *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
264
265 gint         g_printf          (gchar const *format, ...);
266 gint         g_fprintf         (FILE *file, gchar const *format, ...);
267 gint         g_sprintf         (gchar *string, gchar const *format, ...);
268 gint         g_snprintf        (gchar *string, gulong n, gchar const *format, ...);
269 #define g_vprintf vprintf
270 #define g_vfprintf vfprintf
271 #define g_vsprintf vsprintf
272 #define g_vsnprintf vsnprintf
273 #define g_vasprintf vasprintf
274
275 gsize       g_strlcpy          (gchar *dest, const gchar *src, gsize dest_size);
276
277 gchar   g_ascii_tolower      (gchar c);
278 gchar  *g_ascii_strdown      (const gchar *str, gssize len);
279 gint    g_ascii_strncasecmp  (const gchar *s1, const gchar *s2, gsize n);
280 gint    g_ascii_xdigit_value (gchar c);
281 #define g_ascii_isspace(c)   (isspace (c) != 0)
282 #define g_ascii_isalpha(c)   (isalpha (c) != 0)
283 #define g_ascii_isprint(c)   (isprint (c) != 0)
284 #define g_ascii_isxdigit(c)  (isxdigit (c) != 0)
285
286 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
287 #ifdef _MSC_VER
288 #define g_strcasecmp stricmp
289 #define g_ascii_strcasecmp stricmp
290 #define g_strncasecmp strnicmp
291 #define g_strstrip(a) g_strchug (g_strchomp (a))
292 #else
293 #define g_strcasecmp strcasecmp
294 #define g_ascii_strcasecmp strcasecmp
295 #define g_ascii_strtoull strtoull
296 #define g_strncasecmp strncasecmp
297 #define g_strstrip(a) g_strchug (g_strchomp (a))
298 #endif
299
300
301 #define G_STR_DELIMITERS "_-|> <."
302
303 /*
304  * String type
305  */
306 typedef struct {
307         char *str;
308         gsize len;
309         gsize allocated_len;
310 } GString;
311
312 GString     *g_string_new           (const gchar *init);
313 GString     *g_string_new_len       (const gchar *init, gssize len);
314 GString     *g_string_sized_new     (gsize default_size);
315 gchar       *g_string_free          (GString *string, gboolean free_segment);
316 GString     *g_string_append        (GString *string, const gchar *val);
317 void         g_string_printf        (GString *string, const gchar *format, ...);
318 void         g_string_append_printf (GString *string, const gchar *format, ...);
319 GString     *g_string_append_c      (GString *string, gchar c);
320 GString     *g_string_append        (GString *string, const gchar *val);
321 GString     *g_string_append_len    (GString *string, const gchar *val, gssize len);
322 GString     *g_string_truncate      (GString *string, gsize len);
323 GString     *g_string_prepend       (GString *string, const gchar *val);
324
325 #define g_string_sprintfa g_string_append_printf
326
327 /*
328  * Lists
329  */
330 typedef struct _GSList GSList;
331 struct _GSList {
332         gpointer data;
333         GSList *next;
334 };
335
336 GSList *g_slist_alloc         (void);
337 GSList *g_slist_append        (GSList        *list,
338                                gpointer       data);
339 GSList *g_slist_prepend       (GSList        *list,
340                                gpointer       data);
341 void    g_slist_free          (GSList        *list);
342 void    g_slist_free_1        (GSList        *list);
343 GSList *g_slist_copy          (GSList        *list);
344 GSList *g_slist_concat        (GSList        *list1,
345                                GSList        *list2);
346 void    g_slist_foreach       (GSList        *list,
347                                GFunc          func,
348                                gpointer       user_data);
349 GSList *g_slist_last          (GSList        *list);
350 GSList *g_slist_find          (GSList        *list,
351                                gconstpointer  data);
352 GSList *g_slist_find_custom   (GSList        *list,
353                                gconstpointer  data,
354                                GCompareFunc   func);
355 GSList *g_slist_remove        (GSList        *list,
356                                gconstpointer  data);
357 GSList *g_slist_remove_all    (GSList        *list,
358                                gconstpointer  data);
359 GSList *g_slist_reverse       (GSList        *list);
360 guint   g_slist_length        (GSList        *list);
361 GSList *g_slist_remove_link   (GSList        *list,
362                                GSList        *link);
363 GSList *g_slist_delete_link   (GSList        *list,
364                                GSList        *link);
365 GSList *g_slist_insert_sorted (GSList        *list,
366                                gpointer       data,
367                                GCompareFunc   func);
368 GSList *g_slist_insert_before (GSList        *list,
369                                GSList        *sibling,
370                                gpointer       data);
371 GSList *g_slist_sort          (GSList        *list,
372                                GCompareFunc   func);
373 gint    g_slist_index         (GSList        *list,
374                                gconstpointer  data);
375 GSList *g_slist_nth           (GSList        *list,
376                                guint          n);
377 gpointer g_slist_nth_data     (GSList        *list,
378                                guint          n);
379
380 #define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
381
382
383 typedef struct _GList GList;
384 struct _GList {
385   gpointer data;
386   GList *next;
387   GList *prev;
388 };
389
390 #define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
391 #define g_list_previous(list) ((list) ? (((GList *) (list))->prev) : NULL)
392
393 GList *g_list_alloc         (void);
394 GList *g_list_append        (GList         *list,
395                              gpointer       data);
396 GList *g_list_prepend       (GList         *list,
397                              gpointer       data);
398 void   g_list_free          (GList         *list);
399 void   g_list_free_1        (GList         *list);
400 GList *g_list_copy          (GList         *list);
401 guint  g_list_length        (GList         *list);
402 gint   g_list_index         (GList         *list,
403                              gconstpointer  data);
404 GList *g_list_nth           (GList         *list,
405                              guint          n);
406 gpointer g_list_nth_data      (GList         *list,
407                              guint          n);
408 GList *g_list_last          (GList         *list);
409 GList *g_list_concat        (GList         *list1,
410                              GList         *list2);
411 void   g_list_foreach       (GList         *list,
412                              GFunc          func,
413                              gpointer       user_data);
414 GList *g_list_first         (GList         *list);
415 GList *g_list_find          (GList         *list,
416                              gconstpointer  data);
417 GList *g_list_find_custom   (GList         *list,
418                              gconstpointer  data,
419                              GCompareFunc   func);
420 GList *g_list_remove        (GList         *list,
421                              gconstpointer  data);
422 GList *g_list_reverse       (GList         *list);
423 GList *g_list_remove_link   (GList         *list,
424                              GList         *link);
425 GList *g_list_delete_link   (GList         *list,
426                              GList         *link);
427 GList *g_list_insert_sorted (GList         *list,
428                              gpointer       data,
429                              GCompareFunc   func);
430 GList *g_list_insert_before (GList         *list,
431                              GList         *sibling,
432                              gpointer       data);
433 GList *g_list_sort          (GList         *sort,
434                              GCompareFunc   func);
435
436 /*
437  * Array
438  */
439
440 typedef struct _GArray GArray;
441 struct _GArray {
442         gchar *data;
443         gint len;
444 };
445
446 GArray *g_array_new               (gboolean zero_terminated, gboolean clear_, guint element_size);
447 gchar*  g_array_free              (GArray *array, gboolean free_segment);
448 GArray *g_array_append_vals       (GArray *array, gconstpointer data, guint len);
449 GArray* g_array_insert_vals       (GArray *array, guint index_, gconstpointer data, guint len);
450 GArray* g_array_remove_index      (GArray *array, guint index_);
451 GArray* g_array_remove_index_fast (GArray *array, guint index_);
452
453 #define g_array_append_val(a,v)   (g_array_append_vals((a),&(v),1))
454 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
455 #define g_array_index(a,t,i)      *(t*)(((a)->data) + sizeof(t) * (i))
456
457 /*
458  * Pointer Array
459  */
460
461 typedef struct _GPtrArray GPtrArray;
462 struct _GPtrArray {
463         gpointer *pdata;
464         guint len;
465 };
466
467 GPtrArray *g_ptr_array_new                (void);
468 GPtrArray *g_ptr_array_sized_new          (guint reserved_size);
469 void       g_ptr_array_add                (GPtrArray *array, gpointer data);
470 gboolean   g_ptr_array_remove             (GPtrArray *array, gpointer data);
471 gpointer   g_ptr_array_remove_index       (GPtrArray *array, guint index);
472 gboolean   g_ptr_array_remove_fast        (GPtrArray *array, gpointer data);
473 gpointer   g_ptr_array_remove_index_fast  (GPtrArray *array, guint index);
474 void       g_ptr_array_sort               (GPtrArray *array, GCompareFunc compare_func);
475 void       g_ptr_array_sort_with_data     (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
476 void       g_ptr_array_set_size           (GPtrArray *array, gint length);
477 gpointer  *g_ptr_array_free               (GPtrArray *array, gboolean free_seg);
478 void       g_ptr_array_foreach            (GPtrArray *array, GFunc func, gpointer user_data);
479 #define    g_ptr_array_index(array,index) (array)->pdata[(index)]
480
481 /*
482  * Queues
483  */
484 typedef struct {
485         GList *head;
486         GList *tail;
487         guint length;
488 } GQueue;
489
490 gpointer g_queue_pop_head  (GQueue   *queue);
491 void     g_queue_push_head (GQueue   *queue,
492                             gpointer  data);
493 void     g_queue_push_tail (GQueue   *queue,
494                             gpointer  data);
495 gboolean g_queue_is_empty  (GQueue   *queue);
496 GQueue  *g_queue_new       (void);
497 void     g_queue_free      (GQueue   *queue);
498
499 /*
500  * Messages
501  */
502 #ifndef G_LOG_DOMAIN
503 #define G_LOG_DOMAIN ((gchar*) 0)
504 #endif
505
506 typedef enum {
507         G_LOG_FLAG_RECURSION          = 1 << 0,
508         G_LOG_FLAG_FATAL              = 1 << 1,
509         
510         G_LOG_LEVEL_ERROR             = 1 << 2,
511         G_LOG_LEVEL_CRITICAL          = 1 << 3,
512         G_LOG_LEVEL_WARNING           = 1 << 4,
513         G_LOG_LEVEL_MESSAGE           = 1 << 5,
514         G_LOG_LEVEL_INFO              = 1 << 6,
515         G_LOG_LEVEL_DEBUG             = 1 << 7,
516         
517         G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
518 } GLogLevelFlags;
519
520 void           g_print                (const gchar *format, ...);
521 void           g_printerr             (const gchar *format, ...);
522 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
523 GLogLevelFlags g_log_set_fatal_mask   (const gchar *log_domain, GLogLevelFlags fatal_mask);
524 void           g_logv                 (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
525 void           g_log                  (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
526 void           g_assertion_message    (const gchar *format, ...) G_GNUC_NORETURN;
527
528 #ifdef HAVE_C99_SUPPORT
529 /* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
530 #define g_error(format, ...)    do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
531 #define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
532 #define g_warning(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
533 #define g_message(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
534 #define g_debug(format, ...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
535 #else   /* HAVE_C99_SUPPORT */
536 #define g_error(...)    do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;); } while (0)
537 #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
538 #define g_warning(...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
539 #define g_message(...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
540 #define g_debug(...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
541 #endif  /* ndef HAVE_C99_SUPPORT */
542 #define g_log_set_handler(a,b,c,d)
543
544 /*
545  * Conversions
546  */
547
548 gpointer g_convert_error_quark(void);
549
550
551 /*
552  * Unicode Manipulation: most of this is not used by Mono by default, it is
553  * only used if the old collation code is activated, so this is only the
554  * bare minimum to build.
555  */
556 typedef guint32 gunichar;
557
558 typedef enum {
559         G_UNICODE_CONTROL,
560         G_UNICODE_FORMAT,
561         G_UNICODE_UNASSIGNED,
562         G_UNICODE_PRIVATE_USE,
563         G_UNICODE_SURROGATE,
564         G_UNICODE_LOWERCASE_LETTER,
565         G_UNICODE_MODIFIER_LETTER,
566         G_UNICODE_OTHER_LETTER,
567         G_UNICODE_TITLECASE_LETTER,
568         G_UNICODE_UPPERCASE_LETTER,
569         G_UNICODE_COMBINING_MARK,
570         G_UNICODE_ENCLOSING_MARK,
571         G_UNICODE_NON_SPACING_MARK,
572         G_UNICODE_DECIMAL_NUMBER,
573         G_UNICODE_LETTER_NUMBER,
574         G_UNICODE_OTHER_NUMBER,
575         G_UNICODE_CONNECT_PUNCTUATION,
576         G_UNICODE_DASH_PUNCTUATION,
577         G_UNICODE_CLOSE_PUNCTUATION,
578         G_UNICODE_FINAL_PUNCTUATION,
579         G_UNICODE_INITIAL_PUNCTUATION,
580         G_UNICODE_OTHER_PUNCTUATION,
581         G_UNICODE_OPEN_PUNCTUATION,
582         G_UNICODE_CURRENCY_SYMBOL,
583         G_UNICODE_MODIFIER_SYMBOL,
584         G_UNICODE_MATH_SYMBOL,
585         G_UNICODE_OTHER_SYMBOL,
586         G_UNICODE_LINE_SEPARATOR,
587         G_UNICODE_PARAGRAPH_SEPARATOR,
588         G_UNICODE_SPACE_SEPARATOR
589 } GUnicodeType;
590
591 gunichar       g_unichar_toupper (gunichar c);
592 gunichar       g_unichar_tolower (gunichar c);
593 gunichar       g_unichar_totitle (gunichar c);
594 GUnicodeType   g_unichar_type    (gunichar c);
595 gboolean       g_unichar_isxdigit (gunichar c);
596 gint           g_unichar_xdigit_value (gunichar c);
597
598 #ifndef MAX
599 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
600 #endif
601
602 #ifndef MIN
603 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
604 #endif
605
606 #ifndef CLAMP
607 #define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
608 #endif
609
610 /* FIXME: Implement these two for gcc */
611 #define G_LIKELY(x) (x)
612 #define G_UNLIKELY(x) (x)
613
614 /*
615  * Unicode conversion
616  */
617
618 #define G_CONVERT_ERROR g_convert_error_quark()
619
620 typedef enum {
621         G_CONVERT_ERROR_NO_CONVERSION,
622         G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
623         G_CONVERT_ERROR_FAILED,
624         G_CONVERT_ERROR_PARTIAL_INPUT,
625         G_CONVERT_ERROR_BAD_URI,
626         G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
627 } GConvertError;
628
629 gchar* g_utf8_strup (const gchar *str, gssize len);
630 gchar* g_utf8_strdown (const gchar *str, gssize len);
631 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
632 gchar     *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
633 gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
634 gunichar  *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
635
636 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
637
638 #ifdef G_OS_WIN32
639 #define u16to8(str) g_utf16_to_utf8(str, (glong)wcslen(str), NULL, NULL, NULL)
640 #else
641 #define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
642 #endif
643
644 /*
645  * Path
646  */
647 gchar  *g_build_path           (const gchar *separator, const gchar *first_element, ...);
648 #define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
649 gchar  *g_path_get_dirname     (const gchar *filename);
650 gchar  *g_path_get_basename    (const char *filename);
651 gchar  *g_find_program_in_path (const gchar *program);
652 gchar  *g_get_current_dir      (void);
653 gboolean g_path_is_absolute    (const char *filename);
654
655 const gchar *g_get_home_dir    (void);
656 const gchar *g_get_tmp_dir     (void);
657 const gchar *g_get_user_name   (void);
658 gchar *g_get_prgname           (void);
659 void  g_set_prgname            (const gchar *prgname);
660
661 /*
662  * Shell
663  */
664
665 gboolean  g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
666 gchar    *g_shell_unquote    (const gchar *quoted_string, GError **error);
667 gchar    *g_shell_quote      (const gchar *unquoted_string);
668
669 /*
670  * Spawn
671  */
672 typedef enum {
673         G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
674         G_SPAWN_DO_NOT_REAP_CHILD      = 1 << 1,
675         G_SPAWN_SEARCH_PATH            = 1 << 2,
676         G_SPAWN_STDOUT_TO_DEV_NULL     = 1 << 3,
677         G_SPAWN_STDERR_TO_DEV_NULL     = 1 << 4,
678         G_SPAWN_CHILD_INHERITS_STDIN   = 1 << 5,
679         G_SPAWN_FILE_AND_ARGV_ZERO     = 1 << 6
680 } GSpawnFlags;
681
682 typedef pid_t GPid;
683
684 typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
685
686 gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
687 gboolean g_spawn_async_with_pipes  (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
688                                 gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
689
690
691 /*
692  * Timer
693  */
694 typedef struct _GTimer GTimer;
695
696 GTimer *g_timer_new (void);
697 void g_timer_destroy (GTimer *timer);
698 gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds);
699 void g_timer_stop (GTimer *timer);
700 void g_timer_start (GTimer *timer);
701
702 /*
703  * Date and time
704  */
705 typedef struct {
706         glong tv_sec;
707         glong tv_usec;
708 } GTimeVal;
709
710 void g_get_current_time (GTimeVal *result);
711 void g_usleep (gulong microseconds);
712
713 /*
714  * File
715  */
716
717 typedef enum {
718         G_FILE_ERROR_EXIST,
719         G_FILE_ERROR_ISDIR,
720         G_FILE_ERROR_ACCES,
721         G_FILE_ERROR_NAMETOOLONG,
722         G_FILE_ERROR_NOENT,
723         G_FILE_ERROR_NOTDIR,
724         G_FILE_ERROR_NXIO,
725         G_FILE_ERROR_NODEV,
726         G_FILE_ERROR_ROFS,
727         G_FILE_ERROR_TXTBSY,
728         G_FILE_ERROR_FAULT,
729         G_FILE_ERROR_LOOP,
730         G_FILE_ERROR_NOSPC,
731         G_FILE_ERROR_NOMEM,
732         G_FILE_ERROR_MFILE,
733         G_FILE_ERROR_NFILE,
734         G_FILE_ERROR_BADF,
735         G_FILE_ERROR_INVAL,
736         G_FILE_ERROR_PIPE,
737         G_FILE_ERROR_AGAIN,
738         G_FILE_ERROR_INTR,
739         G_FILE_ERROR_IO,
740         G_FILE_ERROR_PERM,
741         G_FILE_ERROR_NOSYS,
742         G_FILE_ERROR_FAILED
743 } GFileError;
744
745 typedef enum {
746         G_FILE_TEST_IS_REGULAR = 1 << 0,
747         G_FILE_TEST_IS_SYMLINK = 1 << 1,
748         G_FILE_TEST_IS_DIR = 1 << 2,
749         G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
750         G_FILE_TEST_EXISTS = 1 << 4
751 } GFileTest;
752
753
754 gboolean   g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
755 GFileError g_file_error_from_errno (gint err_no);
756 gint       g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
757 gboolean   g_file_test (const gchar *filename, GFileTest test);
758
759 /*
760  * Pattern matching
761  */
762 typedef struct _GPatternSpec GPatternSpec;
763 GPatternSpec * g_pattern_spec_new (const gchar *pattern);
764 void           g_pattern_spec_free (GPatternSpec *pspec);
765 gboolean       g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
766
767 /*
768  * Directory
769  */
770 typedef struct _GDir GDir;
771 GDir        *g_dir_open (const gchar *path, guint flags, GError **error);
772 const gchar *g_dir_read_name (GDir *dir);
773 void         g_dir_rewind (GDir *dir);
774 void         g_dir_close (GDir *dir);
775 #define g_mkdir mkdir
776
777 /*
778  * GMarkup
779  */
780 typedef struct _GMarkupParseContext GMarkupParseContext;
781
782 typedef enum
783 {
784         G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
785         G_MARKUP_TREAT_CDATA_AS_TEXT              = 1 << 1
786 } GMarkupParseFlags;
787
788 typedef struct {
789         void (*start_element)  (GMarkupParseContext *context,
790                                 const gchar *element_name,
791                                 const gchar **attribute_names,
792                                 const gchar **attribute_values,
793                                 gpointer user_data,
794                                 GError **error);
795
796         void (*end_element)    (GMarkupParseContext *context,
797                                 const gchar         *element_name,
798                                 gpointer             user_data,
799                                 GError             **error);
800         
801         void (*text)           (GMarkupParseContext *context,
802                                 const gchar         *text,
803                                 gsize                text_len,  
804                                 gpointer             user_data,
805                                 GError             **error);
806         
807         void (*passthrough)    (GMarkupParseContext *context,
808                                 const gchar         *passthrough_text,
809                                 gsize                text_len,  
810                                 gpointer             user_data,
811                                 GError             **error);
812         void (*error)          (GMarkupParseContext *context,
813                                 GError              *error,
814                                 gpointer             user_data);
815 } GMarkupParser;
816
817 GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
818                                                    GMarkupParseFlags flags,
819                                                    gpointer user_data,
820                                                    GDestroyNotify user_data_dnotify);
821 void                 g_markup_parse_context_free  (GMarkupParseContext *context);
822 gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
823                                                    const gchar *text, gssize text_len,
824                                                    GError **error);
825 gboolean         g_markup_parse_context_end_parse (GMarkupParseContext *context,
826                                                    GError **error);
827
828 /*
829  * Character set conversion
830  */
831 /*
832 * Index into the table below with the first byte of a UTF-8 sequence to
833 * get the number of trailing bytes that are supposed to follow it.
834 * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
835 * left as-is for anyone who may want to do such conversion, which was
836 * allowed in earlier algorithms.
837 */
838 extern const gchar g_trailingBytesForUTF8[256];
839
840 gboolean  g_get_charset        (G_CONST_RETURN char **charset);
841 gchar    *g_locale_to_utf8     (const gchar *opsysstring, gssize len,
842                                 gsize *bytes_read, gsize *bytes_written,
843                                 GError **error);
844 gchar    *g_locale_from_utf8   (const gchar *utf8string, gssize len, gsize *bytes_read,
845                                 gsize *bytes_written, GError **error);
846 gchar    *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
847                                 gsize *bytes_written, GError **error);
848 gchar    *g_convert            (const gchar *str, gssize len,
849                                 const gchar *to_codeset, const gchar *from_codeset,
850                                 gsize *bytes_read, gsize *bytes_written, GError **error);
851 gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **end);
852 gunichar  g_utf8_get_char      (const gchar *src);
853 glong     g_utf8_strlen        (const gchar *str, gssize max);
854 #define   g_utf8_next_char(p) p + (g_trailingBytesForUTF8[(guchar)(*p)] + 1)
855
856 /*
857  * Empty thread functions, not used by eglib
858  */
859 #define g_thread_supported()   TRUE
860 #define g_thread_init(x)       G_STMT_START { if (x != NULL) { g_error ("No vtable supported in g_thread_init"); } } G_STMT_END
861
862 #define G_LOCK_DEFINE(name)        int name;
863 #define G_LOCK_DEFINE_STATIC(name) static int name;
864 #define G_LOCK_EXTERN(name)
865 #define G_LOCK(name)
866 #define G_TRYLOCK(name)
867 #define G_UNLOCK(name)
868
869 #define GUINT16_SWAP_LE_BE_CONSTANT(x) ((((guint16) x) >> 8) | ((((guint16) x) << 8)))
870
871 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
872 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
873                                ( (((guint32) (x)) << 24)| \
874                                  ((((guint32) (x)) & 0xff0000) >> 8) | \
875                                  ((((guint32) (x)) & 0xff00) << 8) | \
876                                  (((guint32) (x)) >> 24)) )
877  
878 #define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
879                                GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
880
881                                   
882  
883 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
884 #   define GUINT32_TO_LE(x) (x)
885 #   define GUINT64_TO_LE(x) (x)
886 #   define GUINT16_TO_LE(x) (x)
887 #   define GUINT_TO_LE(x)   (x)
888 #   define GUINT32_TO_BE(x) GUINT32_SWAP_LE_BE(x)
889 #   define GUINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(x)
890 #else
891 #   define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
892 #   define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
893 #   define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
894 #   define GUINT_TO_LE(x)   GUINT32_SWAP_LE_BE(x)
895 #   define GUINT32_TO_BE(x) (x)
896 #   define GUINT32_FROM_BE(x) (x)
897 #endif
898
899 #define GUINT32_FROM_LE(x)  (GUINT32_TO_LE (x))
900 #define GUINT64_FROM_LE(x)  (GUINT64_TO_LE (x))
901 #define GUINT16_FROM_LE(x)  (GUINT16_TO_LE (x))
902 #define GUINT_FROM_LE(x)    (GUINT_TO_LE (x))
903
904 #define _EGLIB_MAJOR  2
905 #define _EGLIB_MIDDLE 4
906 #define _EGLIB_MINOR  0
907  
908 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
909  
910 G_END_DECLS
911
912 #endif
913
914
915