Implement 99% of what moonlight needs to run on eglib
[mono.git] / eglib / src / glib.h
index 45236fcfafb7c265882f32cb1e5a7de6dc3eac7c..0f8f8e74ec92388cd39fc9c149320b46df08e6c6 100644 (file)
@@ -72,18 +72,17 @@ typedef unsigned char  guchar;
 #if !G_TYPES_DEFINED
 /* VS 2010 and later have stdint.h */
 #if defined(_MSC_VER) && _MSC_VER < 1600
-typedef __int8                         gint8;
+typedef __int8                 gint8;
 typedef unsigned __int8                guint8;
-typedef __int16                                gint16;
+typedef __int16                        gint16;
 typedef unsigned __int16       guint16;
-typedef __int32                                gint32;
+typedef __int32                        gint32;
 typedef unsigned __int32       guint32;
-typedef __int64                                gint64;
+typedef __int64                        gint64;
 typedef unsigned __int64       guint64;
-typedef float                          gfloat;
-typedef double                         gdouble;
-typedef unsigned __int16       gunichar2;
-typedef int                 gboolean;
+typedef float                  gfloat;
+typedef double                 gdouble;
+typedef int                    gboolean;
 #else
 /* Types defined in terms of the stdint.h */
 typedef int8_t         gint8;
@@ -96,11 +95,13 @@ typedef int64_t        gint64;
 typedef uint64_t       guint64;
 typedef float          gfloat;
 typedef double         gdouble;
-typedef uint16_t       gunichar2;
 typedef int32_t        gboolean;
 #endif
 #endif
 
+typedef guint16 gunichar2;
+typedef guint32 gunichar;
+
 /*
  * Macros
  */
@@ -112,6 +113,7 @@ typedef int32_t        gboolean;
 #define G_MAXINT             INT_MAX
 #define G_MININT             INT_MIN
 #define G_MAXINT32           INT32_MAX
+#define G_MAXUINT32          UINT32_MAX
 #define G_MININT32           INT32_MIN
 #define G_MININT64           INT64_MIN
 #define G_MAXINT64          INT64_MAX
@@ -186,6 +188,7 @@ gchar*           g_win32_getlocale(void);
 /*
  * Precondition macros
  */
+#define g_warn_if_fail(x)  G_STMT_START { if (!(x)) { g_warning ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); } } G_STMT_END
 #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
 #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
 
@@ -221,6 +224,7 @@ gboolean        g_hash_table_lookup_extended (GHashTable *hash, gconstpointer ke
 void            g_hash_table_foreach         (GHashTable *hash, GHFunc func, gpointer user_data);
 gpointer        g_hash_table_find            (GHashTable *hash, GHRFunc predicate, gpointer user_data);
 gboolean        g_hash_table_remove          (GHashTable *hash, gconstpointer key);
+gboolean        g_hash_table_steal           (GHashTable *hash, gconstpointer key);
 void            g_hash_table_remove_all      (GHashTable *hash);
 guint           g_hash_table_foreach_remove  (GHashTable *hash, GHRFunc func, gpointer user_data);
 guint           g_hash_table_foreach_steal   (GHashTable *hash, GHRFunc func, gpointer user_data);
@@ -321,6 +325,7 @@ gint    g_ascii_xdigit_value (gchar c);
 #define g_strncasecmp strncasecmp
 #define g_strstrip(a) g_strchug (g_strchomp (a))
 #endif
+#define g_ascii_strdup strdup
 
 
 #define        G_STR_DELIMITERS "_-|> <."
@@ -341,11 +346,16 @@ gchar       *g_string_free          (GString *string, gboolean free_segment);
 GString     *g_string_append        (GString *string, const gchar *val);
 void         g_string_printf        (GString *string, const gchar *format, ...);
 void         g_string_append_printf (GString *string, const gchar *format, ...);
+void         g_string_append_vprintf (GString *string, const gchar *format, va_list args);
+GString     *g_string_append_unichar (GString *string, gunichar c);
 GString     *g_string_append_c      (GString *string, gchar c);
 GString     *g_string_append        (GString *string, const gchar *val);
 GString     *g_string_append_len    (GString *string, const gchar *val, gssize len);
 GString     *g_string_truncate      (GString *string, gsize len);
 GString     *g_string_prepend       (GString *string, const gchar *val);
+GString     *g_string_insert        (GString *string, gssize pos, const gchar *val);
+GString     *g_string_set_size      (GString *string, gsize len);
+GString     *g_string_erase         (GString *string, gssize pos, gssize len);
 
 #define g_string_sprintfa g_string_append_printf
 
@@ -444,6 +454,8 @@ GList *g_list_find_custom   (GList     *list,
                             GCompareFunc   func);
 GList *g_list_remove        (GList         *list,
                             gconstpointer  data);
+GList *g_list_remove_all    (GList         *list,
+                            gconstpointer  data);
 GList *g_list_reverse       (GList         *list);
 GList *g_list_remove_link   (GList         *list,
                             GList         *link);
@@ -483,16 +495,24 @@ struct _GArray {
 };
 
 GArray *g_array_new               (gboolean zero_terminated, gboolean clear_, guint element_size);
+GArray *g_array_sized_new         (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size);
 gchar*  g_array_free              (GArray *array, gboolean free_segment);
 GArray *g_array_append_vals       (GArray *array, gconstpointer data, guint len);
 GArray* g_array_insert_vals       (GArray *array, guint index_, gconstpointer data, guint len);
 GArray* g_array_remove_index      (GArray *array, guint index_);
 GArray* g_array_remove_index_fast (GArray *array, guint index_);
+void    g_array_set_size          (GArray *array, gint length);
 
 #define g_array_append_val(a,v)   (g_array_append_vals((a),&(v),1))
 #define g_array_insert_val(a,i,v) (g_array_insert_vals((a),(i),&(v),1))
 #define g_array_index(a,t,i)      *(t*)(((a)->data) + sizeof(t) * (i))
 
+/*
+ * QSort
+*/
+
+void g_qsort_with_data (gpointer base, size_t nmemb, size_t size, GCompareDataFunc compare, gpointer user_data);
+
 /*
  * Pointer Array
  */
@@ -595,7 +615,6 @@ gpointer g_convert_error_quark(void);
  * only used if the old collation code is activated, so this is only the
  * bare minimum to build.
  */
-typedef guint32 gunichar;
 
 typedef enum {
        G_UNICODE_CONTROL,
@@ -630,12 +649,53 @@ typedef enum {
        G_UNICODE_SPACE_SEPARATOR
 } GUnicodeType;
 
+typedef enum {
+       G_UNICODE_BREAK_MANDATORY,
+       G_UNICODE_BREAK_CARRIAGE_RETURN,
+       G_UNICODE_BREAK_LINE_FEED,
+       G_UNICODE_BREAK_COMBINING_MARK,
+       G_UNICODE_BREAK_SURROGATE,
+       G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
+       G_UNICODE_BREAK_INSEPARABLE,
+       G_UNICODE_BREAK_NON_BREAKING_GLUE,
+       G_UNICODE_BREAK_CONTINGENT,
+       G_UNICODE_BREAK_SPACE,
+       G_UNICODE_BREAK_AFTER,
+       G_UNICODE_BREAK_BEFORE,
+       G_UNICODE_BREAK_BEFORE_AND_AFTER,
+       G_UNICODE_BREAK_HYPHEN,
+       G_UNICODE_BREAK_NON_STARTER,
+       G_UNICODE_BREAK_OPEN_PUNCTUATION,
+       G_UNICODE_BREAK_CLOSE_PUNCTUATION,
+       G_UNICODE_BREAK_QUOTATION,
+       G_UNICODE_BREAK_EXCLAMATION,
+       G_UNICODE_BREAK_IDEOGRAPHIC,
+       G_UNICODE_BREAK_NUMERIC,
+       G_UNICODE_BREAK_INFIX_SEPARATOR,
+       G_UNICODE_BREAK_SYMBOL,
+       G_UNICODE_BREAK_ALPHABETIC,
+       G_UNICODE_BREAK_PREFIX,
+       G_UNICODE_BREAK_POSTFIX,
+       G_UNICODE_BREAK_COMPLEX_CONTEXT,
+       G_UNICODE_BREAK_AMBIGUOUS,
+       G_UNICODE_BREAK_UNKNOWN,
+       G_UNICODE_BREAK_NEXT_LINE,
+       G_UNICODE_BREAK_WORD_JOINER,
+       G_UNICODE_BREAK_HANGUL_L_JAMO,
+       G_UNICODE_BREAK_HANGUL_V_JAMO,
+       G_UNICODE_BREAK_HANGUL_T_JAMO,
+       G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
+       G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE
+} GUnicodeBreakType;
+
 gunichar       g_unichar_toupper (gunichar c);
 gunichar       g_unichar_tolower (gunichar c);
 gunichar       g_unichar_totitle (gunichar c);
 GUnicodeType   g_unichar_type    (gunichar c);
+gboolean       g_unichar_isspace (gunichar c);
 gboolean       g_unichar_isxdigit (gunichar c);
 gint           g_unichar_xdigit_value (gunichar c);
+GUnicodeBreakType   g_unichar_break_type (gunichar c);
 
 #ifndef MAX
 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
@@ -675,12 +735,15 @@ typedef enum {
        G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
 } GConvertError;
 
-gchar* g_utf8_strup (const gchar *str, gssize len);
-gchar* g_utf8_strdown (const gchar *str, gssize len);
+gchar     *g_utf8_strup (const gchar *str, gssize len);
+gchar     *g_utf8_strdown (const gchar *str, gssize len);
+gint       g_unichar_to_utf8 (gunichar c, gchar *outbuf);
+gunichar*  g_utf8_to_ucs4_fast (const gchar *str, glong len, glong *items_written);
 gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
 gchar     *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
-gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
 gunichar  *g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
+gchar     *g_ucs4_to_utf8  (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
+gunichar2 *g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items_written, GError **error);
 
 #define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
 
@@ -803,6 +866,18 @@ GFileError g_file_error_from_errno (gint err_no);
 gint       g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error);
 gboolean   g_file_test (const gchar *filename, GFileTest test);
 
+#define g_open open
+#define g_rename rename
+#define g_stat stat
+#define g_unlink unlink
+#define g_fopen fopen
+#define g_lstat lstat
+#define g_rmdir rmdir
+#define g_mkstemp mkstemp
+#define g_ascii_isdigit isdigit
+#define g_ascii_strtod strtod
+#define g_ascii_isalnum isalnum
+
 /*
  * Pattern matching
  */
@@ -819,6 +894,8 @@ GDir        *g_dir_open (const gchar *path, guint flags, GError **error);
 const gchar *g_dir_read_name (GDir *dir);
 void         g_dir_rewind (GDir *dir);
 void         g_dir_close (GDir *dir);
+
+int          g_mkdir_with_parents (const gchar *pathname, int mode);
 #define g_mkdir mkdir
 
 /*
@@ -899,6 +976,14 @@ gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **
 gunichar  g_utf8_get_char      (const gchar *src);
 glong     g_utf8_strlen        (const gchar *str, gssize max);
 #define   g_utf8_next_char(p) p + (g_trailingBytesForUTF8[(guchar)(*p)] + 1)
+gchar *   g_utf8_offset_to_pointer (const gchar *str, glong offset);
+glong     g_utf8_pointer_to_offset (const gchar *str, const gchar *pos);
+
+/*
+ * priorities
+ */
+#define G_PRIORITY_DEFAULT 0
+#define G_PRIORITY_DEFAULT_IDLE 200
 
 /*
  * Empty thread functions, not used by eglib