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