#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 uint64_t guint64;
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_STMT_START do
#define G_STMT_END while (0)
-#define ABS(a,b) (((a)>(b)) ? ((a)-(b)) : ((b)-(a)))
+#define G_USEC_PER_SEC 1000000
+
+#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)
+#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)))
+#define g_new0(type,size) ((type *) calloc (sizeof (type), (size)))
+#define g_newa(type,size) ((type *) alloca (sizeof (type) * (size)))
#define g_realloc(obj,size) realloc((obj), (size))
-#define g_strdup(x) strdup(x)
#define g_malloc(x) malloc(x)
#define g_try_malloc(x) malloc(x)
#define g_try_realloc(obj,size) realloc((obj),(size))
#define g_free free
gpointer g_memdup (gconstpointer mem, guint byte_size);
+gchar *g_strdup (const gchar *str);
+typedef struct {
+ gpointer (*malloc) (gsize n_bytes);
+ gpointer (*realloc) (gpointer mem, gsize n_bytes);
+ void (*free) (gpointer mem);
+ gpointer (*calloc) (gsize n_blocks, gsize n_block_bytes);
+ gpointer (*try_malloc) (gsize n_bytes);
+ gpointer (*try_realloc) (gpointer mem, gsize n_bytes);
+} GMemVTable;
+
+#define g_mem_set_vtable(x)
/*
* 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
*/
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,
guint g_hash_table_foreach_remove (GHashTable *hash, GHRFunc func, gpointer user_data);
void g_hash_table_destroy (GHashTable *hash);
+guint g_spaced_primes_closest (guint x);
+
#define g_hash_table_insert(h,k,v) g_hash_table_insert_replace ((h),(k),(v),FALSE)
#define g_hash_table_replace(h,k,v) g_hash_table_insert_replace ((h),(k),(v),TRUE)
#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
+/*
+ * Errors
+ */
+typedef struct {
+ /* In the real glib, this is a GQuark, but we dont use/need that */
+ gpointer domain;
+ gint code;
+ gchar *message;
+} GError;
+
+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);
+
+gchar *g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error);
+gchar *g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error);
gint g_printf (gchar const *format, ...);
gint g_fprintf (FILE *file, gchar const *format, ...);
#define g_vsnprintf vsnprintf
#define g_vasprintf vasprintf
-#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)
+gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
+
+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 "_-|> <."
/*
* String type
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,
guint len;
};
-GPtrArray *g_ptr_array_new ();
+GPtrArray *g_ptr_array_new (void);
GPtrArray *g_ptr_array_sized_new (guint reserved_size);
void g_ptr_array_add (GPtrArray *array, gpointer data);
gboolean g_ptr_array_remove (GPtrArray *array, gpointer data);
GQueue *g_queue_new (void);
void g_queue_free (GQueue *queue);
-
-/*
- * Modules
- */
-typedef enum {
- G_MODULE_BIND_LAZY = 0x01,
- G_MODULE_BIND_LOCAL = 0x02,
- G_MODULE_BIND_MASK = 0x03
-} GModuleFlags;
-typedef struct _GModule GModule;
-
-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);
-gchar * g_module_build_path (const gchar *directory, const gchar *module_name);
/*
* Messages
*/
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, __VA_ARGS__)
+/*
+ * Conversions
+ */
+
+gpointer g_convert_error_quark(void);
+
/*
* Unicode Manipulation: most of this is not used by Mono by default, it is
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))
#endif
+#ifndef MIN
+#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)
/*
- * Errors
+ * Unicode conversion
*/
-typedef struct {
- /* In the real glib, this is a GQuark, but we dont use/need that */
- gpointer domain;
- gint code;
- gchar *message;
-} GError;
-void g_error_free (GError *error);
-GError *g_error_new (gpointer domain, gint code, const char *format, ...);
+#define G_CONVERT_ERROR g_convert_error_quark()
+
+typedef enum {
+ G_CONVERT_ERROR_NO_CONVERSION,
+ G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
+ G_CONVERT_ERROR_FAILED,
+ G_CONVERT_ERROR_PARTIAL_INPUT,
+ G_CONVERT_ERROR_BAD_URI,
+ 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);
+
+#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);
gchar *g_get_current_dir (void);
+gboolean g_path_is_absolute (const char *filename);
const gchar *g_get_home_dir (void);
const gchar *g_get_tmp_dir (void);
const gchar *g_get_user_name (void);
+gchar *g_get_prgname (void);
+void g_set_prgname (const gchar *prgname);
/*
* 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
*/
+typedef enum {
+ G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1,
+ G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
+ G_SPAWN_SEARCH_PATH = 1 << 2,
+ G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
+ G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
+ G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
+ G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
+} GSpawnFlags;
+
+typedef pid_t GPid;
+
+typedef void (*GSpawnChildSetupFunc) (gpointer user_data);
gboolean g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error);
+gboolean g_spawn_async_with_pipes (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup,
+ gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output, gint *standard_error, GError **error);
/*
G_FILE_ERROR_FAILED
} GFileError;
+typedef enum {
+ G_FILE_TEST_IS_REGULAR = 1 << 0,
+ G_FILE_TEST_IS_SYMLINK = 1 << 1,
+ G_FILE_TEST_IS_DIR = 1 << 2,
+ G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
+ G_FILE_TEST_EXISTS = 1 << 4
+} GFileTest;
+
+
gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **error);
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);
+
+/*
+ * Pattern matching
+ */
+typedef struct _GPatternSpec GPatternSpec;
+GPatternSpec * g_pattern_spec_new (const gchar *pattern);
+void g_pattern_spec_free (GPatternSpec *pspec);
+gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string);
+
+/*
+ * Directory
+ */
+typedef struct _GDir GDir;
+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);
+
+/*
+ * GMarkup
+ */
+typedef struct _GMarkupParseContext GMarkupParseContext;
+
+typedef enum
+{
+ G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
+ G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1
+} GMarkupParseFlags;
+
+typedef struct {
+ void (*start_element) (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error);
+
+ void (*end_element) (GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error);
+
+ void (*text) (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error);
+
+ void (*passthrough) (GMarkupParseContext *context,
+ const gchar *passthrough_text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error);
+ void (*error) (GMarkupParseContext *context,
+ GError *error,
+ gpointer user_data);
+} GMarkupParser;
+
+GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
+ GMarkupParseFlags flags,
+ gpointer user_data,
+ GDestroyNotify user_data_dnotify);
+void g_markup_parse_context_free (GMarkupParseContext *context);
+gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
+ const gchar *text, gssize text_len,
+ GError **error);
+gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
+ GError **error);
+
+/*
+ * Character set conversion
+ */
+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);
+gchar *g_locale_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
+ gsize *bytes_written, GError **error);
+gchar *g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read,
+ gsize *bytes_written, GError **error);
+gchar *g_convert (const gchar *str, gssize len,
+ 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);
+
+/*
+ * 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)
+#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
+
+