#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <stdint.h>
#include <stddef.h>
#include <ctype.h>
+#include <limits.h>
+
+#ifdef _MSC_VER
+#pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
+#else
+#include <stdint.h>
+/* For pid_t */
+#ifndef WIN32
+#include <unistd.h>
+#endif
+#endif
+
#include <eglib-config.h>
+#ifndef EGLIB_NO_REMAP
+#include <eglib-remap.h>
+#endif
#ifndef offsetof
# define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
#endif
#define __EGLIB_X11 1
+
+#ifdef __cplusplus
+#define G_BEGIN_DECLS extern "C" {
+#define G_END_DECLS }
+#else
+#define G_BEGIN_DECLS
+#define G_END_DECLS
+#endif
+
+G_BEGIN_DECLS
+
/*
* Basic data types
*/
typedef char gchar;
typedef unsigned char guchar;
+#if !G_TYPES_DEFINED
+#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
+#endif
+
+
/*
* Macros
*/
#define FALSE 0
#define TRUE 1
+#define G_MAXINT INT_MAX
+#define G_MININT INT_MIN
#define G_MAXINT32 INT32_MAX
#define G_MININT32 INT32_MIN
#define G_MININT64 INT64_MIN
#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)
#define EGLIB_TOSTRING(x) EGLIB_STRINGIFY(x)
#define G_STRLOC __FILE__ ":" EGLIB_TOSTRING(__LINE__) ":"
-#define G_BEGIN_DECLS
-#define G_END_DECLS
-
#define G_CONST_RETURN const
/*
* Allocation
*/
-#define g_new(type,size) ((type *) malloc (sizeof (type) * (size)))
-#define g_new0(type,size) ((type *) calloc (sizeof (type), (size)))
+void g_free (void *ptr);
+static inline gpointer g_realloc (gpointer obj, gsize size) { if (!size) {g_free (obj); return 0;} return realloc (obj, size);}
+static inline gpointer g_malloc (gsize x) {if (x) return malloc (x); else return 0;}
+static inline gpointer g_malloc0 (gsize x) {if (x) return calloc(1,x); else return 0;}
+#define g_try_malloc(x) g_malloc(x)
+#define g_try_realloc(obj,size) g_realloc((obj),(size))
+
+#define g_new(type,size) ((type *) g_malloc (sizeof (type) * (size)))
+#define g_new0(type,size) ((type *) g_malloc0 (sizeof (type)* (size)))
#define g_newa(type,size) ((type *) alloca (sizeof (type) * (size)))
-#define g_realloc(obj,size) realloc((obj), (size))
-#define g_malloc(x) malloc(x)
-#define g_try_malloc(x) malloc(x)
-#define g_try_realloc(obj,size) realloc((obj),(size))
-#define g_malloc0(x) calloc(1,x)
+
#define g_memmove(dest,src,len) memmove (dest, src, len)
-#define g_renew(struct_type, mem, n_structs) realloc (mem, sizeof (struct_type) * n_structs)
+#define g_renew(struct_type, mem, n_structs) g_realloc (mem, sizeof (struct_type) * n_structs)
#define g_alloca(size) alloca (size)
-#define g_free free
gpointer g_memdup (gconstpointer mem, guint byte_size);
-gchar *g_strdup (const gchar *str);
+static inline gchar *g_strdup (const gchar *str) { if (str) {return strdup (str);} return NULL; }
typedef struct {
gpointer (*malloc) (gsize n_bytes);
} GMemVTable;
#define g_mem_set_vtable(x)
+
+struct _GMemChunk {
+ guint alloc_size;
+};
+
+typedef struct _GMemChunk GMemChunk;
/*
* Misc.
*/
gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);
void g_unsetenv(const gchar *variable);
+gchar* g_win32_getlocale(void);
+
/*
* Precondition macros
*/
-#define g_return_if_fail(x) G_STMT_START { if (!(x)) { printf ("%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)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } 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
/*
* Hashtables
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,
gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data);
gboolean g_hash_table_remove (GHashTable *hash, gconstpointer key);
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);
void g_hash_table_destroy (GHashTable *hash);
guint g_spaced_primes_closest (guint x);
gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
guint g_str_hash (gconstpointer v1);
-#define g_assert(x) G_STMT_START { if (!(x)) g_error ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x); } G_STMT_END
-#define g_assert_not_reached() G_STMT_START { g_error ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); } G_STMT_END
+#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
+#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
/*
* Errors
gchar *message;
} GError;
+void g_clear_error (GError **error);
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_strfreev (gchar **str_array);
gchar *g_strconcat (const gchar *first, ...);
gchar **g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens);
+gchar **g_strsplit_set (const gchar *string, const gchar *delimiter, gint max_tokens);
gchar *g_strreverse (gchar *str);
gboolean g_str_has_prefix (const gchar *str, const gchar *prefix);
gboolean g_str_has_suffix (const gchar *str, const gchar *suffix);
gchar *g_strchug (gchar *str);
gchar *g_strchomp (gchar *str);
void g_strdown (gchar *string);
+gchar *g_strnfill (gsize length, gchar fill_char);
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_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_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 "_-|> <."
GSList *g_slist_last (GSList *list);
GSList *g_slist_find (GSList *list,
gconstpointer data);
+GSList *g_slist_find_custom (GSList *list,
+ gconstpointer data,
+ GCompareFunc func);
GSList *g_slist_remove (GSList *list,
gconstpointer data);
GSList *g_slist_remove_all (GSList *list,
gpointer data);
GSList *g_slist_sort (GSList *list,
GCompareFunc func);
+gint g_slist_index (GSList *list,
+ gconstpointer data);
+GSList *g_slist_nth (GSList *list,
+ guint n);
+gpointer g_slist_nth_data (GSList *list,
+ guint n);
+
#define g_slist_next(slist) ((slist) ? (((GSList *) (slist))->next) : NULL)
+
typedef struct _GList GList;
struct _GList {
gpointer data;
};
#define g_list_next(list) ((list) ? (((GList *) (list))->next) : NULL)
+#define g_list_previous(list) ((list) ? (((GList *) (list))->prev) : NULL)
GList *g_list_alloc (void);
GList *g_list_append (GList *list,
GList *g_list_first (GList *list);
GList *g_list_find (GList *list,
gconstpointer data);
+GList *g_list_find_custom (GList *list,
+ gconstpointer data,
+ GCompareFunc func);
GList *g_list_remove (GList *list,
gconstpointer data);
GList *g_list_reverse (GList *list);
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_);
#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))
gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
gpointer g_ptr_array_remove_index (GPtrArray *array, guint index);
gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data);
-gpointer g_ptr_array_remove_index_fast (GPtrArray *array, gpointer data);
+gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index);
void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func);
void g_ptr_array_sort_with_data (GPtrArray *array, GCompareDataFunc compare_func, gpointer user_data);
void g_ptr_array_set_size (GPtrArray *array, gint length);
gpointer g_queue_pop_head (GQueue *queue);
void g_queue_push_head (GQueue *queue,
gpointer data);
+void g_queue_push_tail (GQueue *queue,
+ gpointer data);
gboolean g_queue_is_empty (GQueue *queue);
GQueue *g_queue_new (void);
void g_queue_free (GQueue *queue);
} GLogLevelFlags;
void g_print (const gchar *format, ...);
+void g_printerr (const gchar *format, ...);
GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask);
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)
-
+void g_assertion_message (const gchar *format, ...) G_GNUC_NORETURN;
+
+#ifdef HAVE_C99_SUPPORT
+/* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
+#define g_error(format, ...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
+#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__)
+#else /* HAVE_C99_SUPPORT */
+#define g_error(...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__); for (;;); } while (0)
+#define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
+#define g_warning(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
+#define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
+#define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
+#endif /* ndef HAVE_C99_SUPPORT */
#define g_log_set_handler(a,b,c,d)
-#define g_printerr(format...) fprintf (stderr, format)
+
/*
* Conversions
*/
typedef guint32 gunichar;
typedef enum {
+ G_UNICODE_CONTROL,
+ G_UNICODE_FORMAT,
+ G_UNICODE_UNASSIGNED,
+ G_UNICODE_PRIVATE_USE,
+ G_UNICODE_SURROGATE,
G_UNICODE_LOWERCASE_LETTER,
+ G_UNICODE_MODIFIER_LETTER,
+ G_UNICODE_OTHER_LETTER,
+ G_UNICODE_TITLECASE_LETTER,
+ G_UNICODE_UPPERCASE_LETTER,
+ G_UNICODE_COMBINING_MARK,
+ G_UNICODE_ENCLOSING_MARK,
+ G_UNICODE_NON_SPACING_MARK,
+ G_UNICODE_DECIMAL_NUMBER,
+ G_UNICODE_LETTER_NUMBER,
+ G_UNICODE_OTHER_NUMBER,
+ G_UNICODE_CONNECT_PUNCTUATION,
+ G_UNICODE_DASH_PUNCTUATION,
+ G_UNICODE_CLOSE_PUNCTUATION,
+ G_UNICODE_FINAL_PUNCTUATION,
+ G_UNICODE_INITIAL_PUNCTUATION,
+ G_UNICODE_OTHER_PUNCTUATION,
+ G_UNICODE_OPEN_PUNCTUATION,
+ G_UNICODE_CURRENCY_SYMBOL,
+ G_UNICODE_MODIFIER_SYMBOL,
+ G_UNICODE_MATH_SYMBOL,
+ G_UNICODE_OTHER_SYMBOL,
+ G_UNICODE_LINE_SEPARATOR,
+ G_UNICODE_PARAGRAPH_SEPARATOR,
+ G_UNICODE_SPACE_SEPARATOR
} GUnicodeType;
+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_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)
G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
} GConvertError;
-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);
+gchar* g_utf8_strup (const gchar *str, gssize len);
+gchar* g_utf8_strdown (const gchar *str, gssize len);
+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);
+
+#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);
} GTimeVal;
void g_get_current_time (GTimeVal *result);
+void g_usleep (gulong microseconds);
/*
* File
/*
* Character set conversion
*/
+/*
+* Index into the table below with the first byte of a UTF-8 sequence to
+* get the number of trailing bytes that are supposed to follow it.
+* Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
+* left as-is for anyone who may want to do such conversion, which was
+* allowed in earlier algorithms.
+*/
+extern const gchar g_trailingBytesForUTF8[256];
+
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,
const gchar *to_codeset, const gchar *from_codeset,
gsize *bytes_read, gsize *bytes_written, GError **error);
gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **end);
+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)
/*
* 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_LOCK_DEFINE(name) int name;
+#define G_LOCK_DEFINE_STATIC(name) static int name;
+#define G_LOCK_EXTERN(name)
+#define G_LOCK(name)
+#define G_TRYLOCK(name)
+#define G_UNLOCK(name)
+
+#define GUINT16_SWAP_LE_BE_CONSTANT(x) ((((guint16) x) >> 8) | ((((guint16) x) << 8)))
+
#define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
#define GUINT32_SWAP_LE_BE(x) ((guint32) \
( (((guint32) (x)) << 24)| \
# define GUINT32_TO_LE(x) (x)
# define GUINT64_TO_LE(x) (x)
# define GUINT16_TO_LE(x) (x)
+# define GUINT_TO_LE(x) (x)
+# define GUINT32_TO_BE(x) GUINT32_SWAP_LE_BE(x)
+# define GUINT32_FROM_BE(x) GUINT32_SWAP_LE_BE(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)
+# define GUINT32_TO_BE(x) (x)
+# define GUINT32_FROM_BE(x) (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 GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
+G_END_DECLS
+
#endif
+
+