2007-10-19 Nagappan A <anagappan@novell.com>
[mono.git] / eglib / src / glib.h
index 51393b3cbfad3667777bf5d8e35ad9d34e7b30e5..935c5c46d5b58da5eb757a9cd25d1e2bdbd2c933 100644 (file)
@@ -5,9 +5,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include <stdint.h>
 #include <stddef.h>
 #include <ctype.h>
+
+#ifdef _MSC_VER
+#pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
+#else
+#include <stdint.h>
+#endif
+
 #include <eglib-config.h>
 
 #ifndef offsetof
@@ -15,6 +21,7 @@
 #endif
 
 #define __EGLIB_X11 1
+
 /*
  * Basic data types
  */
@@ -30,6 +37,19 @@ typedef const void *   gconstpointer;
 typedef char           gchar;
 typedef unsigned char  guchar;
 
+#ifdef _MSC_VER
+typedef __int8                         gint8;
+typedef unsigned __int8                guint8;
+typedef __int16                                gint16;
+typedef unsigned __int16       guint16;
+typedef __int32                                gint32;
+typedef unsigned __int32       guint32;
+typedef __int64                                gint64;
+typedef unsigned __int64       guint64;
+typedef float                          gfloat;
+typedef double                         gdouble;
+typedef unsigned __int16       gunichar2;
+#else
 /* Types defined in terms of the stdint.h */
 typedef int8_t         gint8;
 typedef uint8_t        guint8;
@@ -42,6 +62,8 @@ typedef uint64_t       guint64;
 typedef float          gfloat;
 typedef double         gdouble;
 typedef uint16_t       gunichar2;
+#endif
+
 /*
  * Macros
  */
@@ -62,7 +84,7 @@ typedef uint16_t       gunichar2;
 
 #define G_USEC_PER_SEC  1000000
 
-#define ABS(a,b)        (((a)>(b)) ? ((a)-(b)) : ((b)-(a)))
+#define ABS(a)         ((a) > 0 ? (a) : -(a))
 
 #define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
 
@@ -113,6 +135,8 @@ const gchar *    g_getenv(const gchar *variable);
 gboolean         g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
 void             g_unsetenv(const gchar *variable);
 
+gchar*           g_win32_getlocale(void);
+
 /*
  * Precondition macros
  */
@@ -131,6 +155,7 @@ typedef gboolean (*GHRFunc)        (gpointer key, gpointer value, gpointer user_
 typedef void     (*GDestroyNotify) (gpointer data);
 typedef guint    (*GHashFunc)      (gconstpointer key);
 typedef gboolean (*GEqualFunc)     (gconstpointer a, gconstpointer b);
+typedef void     (*GFreeFunc)      (gpointer       data);
 
 GHashTable     *g_hash_table_new             (GHashFunc hash_func, GEqualFunc key_equal_func);
 GHashTable     *g_hash_table_new_full        (GHashFunc hash_func, GEqualFunc key_equal_func,
@@ -212,12 +237,9 @@ gint         g_snprintf        (gchar *string, gulong n, gchar const *format, ..
 #define g_vsnprintf vsnprintf
 #define g_vasprintf vasprintf
 
-#ifdef HAVE_STRLCPY
-#define g_strlcpy      strlcpy
-#else
 gsize       g_strlcpy          (gchar *dest, const gchar *src, gsize dest_size);
-#endif
 
+gchar   g_ascii_tolower      (gchar c);
 gchar  *g_ascii_strdown      (const gchar *str, gssize len);
 gint    g_ascii_strncasecmp  (const gchar *s1, const gchar *s2, gsize n);
 gint    g_ascii_xdigit_value (gchar c);
@@ -227,10 +249,18 @@ gint    g_ascii_xdigit_value (gchar c);
 #define g_ascii_isxdigit(c)  (isxdigit (c) != 0)
 
 /* FIXME: g_strcasecmp supports utf8 unicode stuff */
+#ifdef _MSC_VER
+#define g_strcasecmp stricmp
+#define g_ascii_strcasecmp stricmp
+#define g_strncasecmp strnicmp
+#define g_strstrip(a) g_strchug (g_strchomp (a))
+#else
 #define g_strcasecmp strcasecmp
 #define g_ascii_strcasecmp strcasecmp
 #define g_strncasecmp strncasecmp
 #define g_strstrip(a) g_strchug (g_strchomp (a))
+#endif
+
 
 #define        G_STR_DELIMITERS "_-|> <."
 
@@ -439,14 +469,14 @@ GLogLevelFlags g_log_set_fatal_mask   (const gchar *log_domain, GLogLevelFlags f
 void           g_logv                 (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
 void           g_log                  (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
 
-#define g_error(format...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format)
-#define g_critical(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format)
-#define g_warning(format...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format)
-#define g_message(format...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format)
-#define g_debug(format...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
+#define g_error(format, ...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__)
+#define g_critical(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, __VA_ARGS__)
+#define g_warning(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__)
+#define g_message(format, ...)  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__)
+#define g_debug(format, ...)    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__)
 
 #define g_log_set_handler(a,b,c,d)
-#define g_printerr(format...) fprintf (stderr, format)
+#define g_printerr(format, ...) fprintf (stderr, format, __VA_ARGS__)
 /*
  * Conversions
  */
@@ -467,6 +497,8 @@ typedef enum {
 
 gunichar       g_unichar_tolower (gunichar c);
 GUnicodeType   g_unichar_type    (gunichar c);
+gboolean       g_unichar_isxdigit (gunichar c);
+gint           g_unichar_xdigit_value (gunichar c);
 
 #ifndef MAX
 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
@@ -476,6 +508,10 @@ GUnicodeType   g_unichar_type    (gunichar c);
 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
 #endif
 
+#ifndef CLAMP
+#define CLAMP(a,low,high) (((a) < (low)) ? (low) : (((a) > (high)) ? (high) : (a)))
+#endif
+
 /* FIXME: Implement these two for gcc */
 #define G_LIKELY(x) (x)
 #define G_UNLIKELY(x) (x)
@@ -498,11 +534,19 @@ typedef enum {
 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);
 
+#define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
+
+#ifdef G_OS_WIN32
+#define u16to8(str) g_utf16_to_utf8(str, (glong)wcslen(str), NULL, NULL, NULL)
+#else
+#define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
+#endif
+
 /*
  * Path
  */
 gchar  *g_build_path           (const gchar *separator, const gchar *first_element, ...);
-#define g_build_filename(x...) g_build_path(G_DIR_SEPARATOR_S, x)
+#define g_build_filename(x, ...) g_build_path(G_DIR_SEPARATOR_S, x, __VA_ARGS__)
 gchar  *g_path_get_dirname     (const gchar *filename);
 gchar  *g_path_get_basename    (const char *filename);
 gchar  *g_find_program_in_path (const gchar *program);
@@ -702,6 +746,13 @@ gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **
 #define g_thread_supported()   TRUE
 #define g_thread_init(x)       G_STMT_START { if (x != NULL) { g_error ("No vtable supported in g_thread_init"); } } G_STMT_END
 
+#define G_LOCK_DEFINE(name)
+#define G_LOCK_DEFINE_STATIC(name)
+#define G_LOCK_EXTERN(name)
+#define G_LOCK(name)
+#define G_TRYLOCK(name)
+#define G_UNLOCK(name)
+
 #define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
 #define GUINT32_SWAP_LE_BE(x) ((guint32) \
                               ( (((guint32) (x)) << 24)| \
@@ -718,15 +769,18 @@ gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **
 #   define GUINT32_TO_LE(x) (x)
 #   define GUINT64_TO_LE(x) (x)
 #   define GUINT16_TO_LE(x) (x)
+#   define GUINT_TO_LE(x)   (x)
 #else
 #   define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
 #   define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
 #   define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
+#   define GUINT_TO_LE(x)   GUINT32_SWAP_LE_BE(x)
 #endif
 
 #define GUINT32_FROM_LE(x)  (GUINT32_TO_LE (x))
 #define GUINT64_FROM_LE(x)  (GUINT64_TO_LE (x))
 #define GUINT16_FROM_LE(x)  (GUINT16_TO_LE (x))
+#define GUINT_FROM_LE(x)    (GUINT_TO_LE (x))
 
 #define _EGLIB_MAJOR  2
 #define _EGLIB_MIDDLE 4
@@ -736,3 +790,4 @@ gboolean  g_utf8_validate      (const gchar *str, gssize max_len, const gchar **
  
 #endif
 
+