mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-01-09 11:18:47 +08:00
Remove GLib dependency WIP
Add a shim implementing half-assed versions of most of the GLib functions used by MDB Tools. If GLib is detected at compile-time, use it, otherwise use the shim. This work is not complete, as the option-parsing code is not yet implemented - so most of the command-line tools crash.
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
include_HEADERS = mdbtools.h mdbsql.h mdbver.h
|
||||
if !HAVE_GLIB
|
||||
include_HEADERS += mdbfakeglib.h
|
||||
endif
|
||||
noinst_HEADERS = mdbprivate.h
|
||||
|
||||
147
include/mdbfakeglib.h
Normal file
147
include/mdbfakeglib.h
Normal file
@@ -0,0 +1,147 @@
|
||||
#ifndef _glib_shim_h_
|
||||
#define _glib_shim_h_
|
||||
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef uint16_t guint16;
|
||||
typedef uint32_t guint32;
|
||||
typedef uint64_t guint64;
|
||||
typedef int32_t gint32;
|
||||
typedef char gchar;
|
||||
typedef int gboolean;
|
||||
typedef int gint;
|
||||
typedef unsigned int guint;
|
||||
typedef void * gpointer;
|
||||
typedef const void * gconstpointer;
|
||||
typedef uint8_t guint8;
|
||||
|
||||
typedef guint (*GHashFunc)(gconstpointer);
|
||||
typedef int (*GCompareFunc)(gconstpointer, gconstpointer);
|
||||
typedef gboolean (*GEqualFunc)(gconstpointer, gconstpointer);
|
||||
typedef void (*GFunc) (gpointer data, gpointer user_data);
|
||||
typedef void (*GHFunc)(gpointer key, gpointer value, gpointer data);
|
||||
typedef gboolean (*GHRFunc)(gpointer key, gpointer value, gpointer data);
|
||||
|
||||
typedef struct GPtrArray {
|
||||
void **pdata;
|
||||
int len;
|
||||
} GPtrArray;
|
||||
|
||||
typedef struct GList {
|
||||
gpointer data;
|
||||
struct GList *next;
|
||||
struct GList *prev;
|
||||
} GList;
|
||||
|
||||
typedef struct GHashTable {
|
||||
GEqualFunc compare;
|
||||
GPtrArray *array;
|
||||
} GHashTable;
|
||||
|
||||
typedef struct GError {
|
||||
const char *message;
|
||||
} GError;
|
||||
|
||||
typedef enum GOptionArg {
|
||||
G_OPTION_ARG_NONE,
|
||||
G_OPTION_ARG_STRING,
|
||||
G_OPTION_ARG_INT
|
||||
} GOptionArg;
|
||||
|
||||
typedef enum GOptionFlags {
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_FLAG_REVERSE
|
||||
} GOptionFlags;
|
||||
|
||||
typedef struct GOptionEntry {
|
||||
const gchar *long_name;
|
||||
gchar short_name;
|
||||
gint flags;
|
||||
|
||||
GOptionArg arg;
|
||||
gpointer arg_data;
|
||||
|
||||
const gchar *description;
|
||||
const gchar *arg_description;
|
||||
} GOptionEntry;
|
||||
|
||||
typedef struct GOptionContext {
|
||||
const char *desc;
|
||||
const GOptionEntry *entries;
|
||||
} GOptionContext;
|
||||
|
||||
#define g_str_hash NULL
|
||||
|
||||
#define G_GUINT32_FORMAT PRIu32
|
||||
|
||||
#define g_return_val_if_fail(a, b) if (!a) { return b; }
|
||||
|
||||
#define g_ascii_strcasecmp strcasecmp
|
||||
#define g_malloc0(len) calloc(1, len)
|
||||
#define g_malloc malloc
|
||||
#define g_free free
|
||||
#define g_realloc realloc
|
||||
|
||||
#define g_strdup strdup
|
||||
|
||||
#define G_STR_DELIMITERS "_-|> <."
|
||||
|
||||
#define g_ptr_array_index(array, i) \
|
||||
((void **)array->pdata)[i]
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define GUINT16_FROM_LE(l) (uint16_t)l
|
||||
#define GUINT32_FROM_LE(l) (uint32_t)l
|
||||
#define GUINT64_FROM_LE(l) (uint64_t)l
|
||||
#define GINT32_FROM_LE(l) (uint32_t)l
|
||||
#define GINT32_FROM_BE(l) (int32_t)ntohl(l)
|
||||
#define GUINT32_SWAP_LE_BE(l) (uint32_t)ntohl(l)
|
||||
#define GINT32_TO_LE(l) (int32_t)l
|
||||
#define GINT32_TO_BE(l) (int32_t)ntohl(l)
|
||||
|
||||
/* string functions */
|
||||
void *g_memdup(const void *src, size_t len);
|
||||
int g_str_equal(const void *str1, const void *str2);
|
||||
char **g_strsplit(const char *haystack, const char *needle, int something);
|
||||
void g_strfreev(char **dir);
|
||||
char *g_strconcat(const char *first, ...);
|
||||
char *g_strdup_printf(const char *format, ...);
|
||||
gchar *g_strdelimit(gchar *string, const gchar *delimiters, gchar new_delimiter);
|
||||
|
||||
/* GHashTable */
|
||||
void *g_hash_table_lookup(GHashTable *tree, const void *key);
|
||||
void g_hash_table_insert(GHashTable *tree, void *key, void *value);
|
||||
GHashTable *g_hash_table_new(GHashFunc hashes, GEqualFunc equals);
|
||||
void g_hash_table_foreach(GHashTable *tree, GHFunc function, void *data);
|
||||
void g_hash_table_foreach_remove(GHashTable *tree, GHRFunc function, void *data);
|
||||
void g_hash_table_destroy(GHashTable *tree);
|
||||
|
||||
/* GPtrArray */
|
||||
void g_ptr_array_sort(GPtrArray *array, GCompareFunc func);
|
||||
void g_ptr_array_foreach(GPtrArray *array, GFunc function, gpointer user_data);
|
||||
GPtrArray *g_ptr_array_new(void);
|
||||
void g_ptr_array_add(GPtrArray *array, void *entry);
|
||||
void g_ptr_array_free(GPtrArray *array, gboolean something);
|
||||
|
||||
/* GList */
|
||||
GList *g_list_append(GList *list, void *data);
|
||||
GList *g_list_last(GList *list);
|
||||
GList *g_list_remove(GList *list, void *data);
|
||||
void g_list_free(GList *list);
|
||||
|
||||
/* GOption */
|
||||
GOptionContext *g_option_context_new(const char *description);
|
||||
void g_option_context_add_main_entries (GOptionContext *context,
|
||||
const GOptionEntry *entries,
|
||||
const gchar *translation_domain);
|
||||
gchar *g_option_context_get_help (GOptionContext *context,
|
||||
gboolean main_help, void *group);
|
||||
gboolean g_option_context_parse (GOptionContext *context,
|
||||
gint *argc, gchar ***argv, GError **error);
|
||||
void g_option_context_free (GOptionContext *context);
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_GLIB
|
||||
#include <glib.h>
|
||||
#else
|
||||
#include <mdbfakeglib.h>
|
||||
#endif
|
||||
#include <mdbtools.h>
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -30,7 +30,12 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_GLIB
|
||||
#include <glib.h>
|
||||
#else
|
||||
#include <mdbfakeglib.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
#include <iconv.h>
|
||||
@@ -284,8 +289,7 @@ typedef struct {
|
||||
int object_type;
|
||||
unsigned long table_pg; /* misnomer since object may not be a table */
|
||||
//int num_props; please use props->len
|
||||
GArray *props; /* GArray of MdbProperties */
|
||||
GArray *columns;
|
||||
GPtrArray *props; /* GPtrArray of MdbProperties */
|
||||
int flags;
|
||||
} MdbCatalogEntry;
|
||||
|
||||
@@ -575,7 +579,7 @@ extern gint32 mdb_map_find_next(MdbHandle *mdb, unsigned char *map, unsigned int
|
||||
/* props.c */
|
||||
extern void mdb_free_props(MdbProperties *props);
|
||||
extern void mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name);
|
||||
extern GArray* mdb_kkd_to_props(MdbHandle *mdb, void *kkd, size_t len);
|
||||
extern GPtrArray* mdb_kkd_to_props(MdbHandle *mdb, void *kkd, size_t len);
|
||||
|
||||
|
||||
/* worktable.c */
|
||||
|
||||
Reference in New Issue
Block a user