#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
+# define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
+#endif
+
#define __EGLIB_X11 1
+
/*
* Basic data types
*/
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;
typedef float gfloat;
typedef double gdouble;
typedef uint16_t gunichar2;
+#endif
+
/*
* Macros
*/
#define G_MAXINT32 INT32_MAX
#define G_MININT32 INT32_MIN
+#define G_MININT64 INT64_MIN
+#define G_MAXINT64 INT64_MAX
#define G_LITTLE_ENDIAN 1234
#define G_BIG_ENDIAN 4321
#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) \
- ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
+#define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
#define EGLIB_STRINGIFY(x) #x
#define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
void g_unsetenv(const gchar *variable);
+gchar* g_win32_getlocale(void);
+
/*
* Precondition macros
*/
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,
void g_error_free (GError *error);
GError *g_error_new (gpointer domain, gint code, const char *format, ...);
void g_set_error (GError **err, gpointer domain, gint code, const gchar *format, ...);
+void g_propagate_error (GError **dest, GError *src);
/*
* Strings utility
gboolean g_str_has_suffix (const gchar *str, const gchar *suffix);
guint g_strv_length (gchar **str_array);
gchar *g_strjoin (const gchar *separator, ...);
+gchar *g_strjoinv (const gchar *separator, gchar **str_array);
gchar *g_strchug (gchar *str);
gchar *g_strchomp (gchar *str);
+void g_strdown (gchar *string);
+
gchar *g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter);
gchar *g_strescape (const gchar *source, const gchar *exceptions);
#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_strdown (const gchar *str, gssize len);
-#define g_ascii_isspace(c) (isspace (c) != 0)
-#define g_ascii_isalpha(c) (isalpha (c) != 0)
-#define g_ascii_isprint(c) (isprint (c) != 0)
-#define g_ascii_isxdigit(c) (isxdigit (c) != 0)
-#define g_ascii_xdigit_value(c) ((isxdigit (c) == 0) ? -1 : \
- ((c >= '0' && c <= '9') ? (c - '0') : \
- ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : \
- (c - 'A' + 10))))
+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);
+#define g_ascii_isspace(c) (isspace (c) != 0)
+#define g_ascii_isalpha(c) (isalpha (c) != 0)
+#define g_ascii_isprint(c) (isprint (c) != 0)
+#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 "_-|> <."
gpointer data);
GSList *g_slist_sort (GSList *list,
GCompareFunc func);
-
#define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
typedef struct _GList GList;
GList *prev;
};
-#define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL);
+#define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
GList *g_list_alloc (void);
GList *g_list_append (GList *list,
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
*/
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))
#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)
} GConvertError;
gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
-glong utf8_to_utf16_len (const gchar *str, glong len, glong *items_read, GError **error);
gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
-glong utf16_to_utf8_len (const gunichar2 *str, glong len, glong *items_read, 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);
* Shell
*/
-gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
+gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error);
+gchar *g_shell_unquote (const gchar *quoted_string, GError **error);
+gchar *g_shell_quote (const gchar *unquoted_string);
/*
* Spawn
gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
GError **error);
-/*
- * GModule support
- */
-
-typedef struct _GModule GModule;
-
-typedef enum {
- G_MODULE_BIND_LAZY = 1,
- G_MODULE_BIND_LOCAL = 2,
- G_MODULE_BIND_MASK = 3
-} GModuleFlags;
-
-GModule *g_module_open (const gchar *file, GModuleFlags flags);
-gboolean g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol);
-const gchar *g_module_error (void);
-gboolean g_module_close (GModule *module);
-
/*
* Character set conversion
*/
-gboolean g_get_charset (char **charset);
+gboolean g_get_charset (G_CONST_RETURN char **charset);
gchar *g_locale_to_utf8 (const gchar *opsysstring, gssize len,
gsize *bytes_read, gsize *bytes_written,
GError **error);
* Empty thread functions, not used by eglib
*/
#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_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)| \
+ ((((guint32) (x)) & 0xff0000) >> 8) | \
+ ((((guint32) (x)) & 0xff00) << 8) | \
+ (((guint32) (x)) >> 24)) )
+
+#define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
+ GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
+
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+# 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
+#define _EGLIB_MINOR 0
+
+#define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
+
+#endif
+
+