mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-01-02 20:42:14 +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,5 +1,8 @@
|
||||
lib_LTLIBRARIES = libmdb.la
|
||||
libmdb_la_SOURCES= catalog.c mem.c file.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c map.c props.c worktable.c options.c iconv.c
|
||||
if !HAVE_GLIB
|
||||
libmdb_la_SOURCES += fakeglib.c
|
||||
endif
|
||||
libmdb_la_LDFLAGS = -version-info 2:1:0 -export-symbols-regex '^(mdb_|_mdb_put_int16$$|_mdb_put_int32$$)'
|
||||
AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
LIBS = $(GLIB_LIBS) @LIBS@ @LIBICONV@
|
||||
|
||||
@@ -184,7 +184,7 @@ enum {
|
||||
MDB_BACKEND_SQLITE,
|
||||
};
|
||||
|
||||
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data);
|
||||
static void mdb_drop_backend(gpointer key, gpointer value, gpointer data);
|
||||
|
||||
static gchar*
|
||||
quote_generic(const gchar *value, gchar quote_char, gchar escape_char) {
|
||||
@@ -448,14 +448,13 @@ mdb_remove_backends())
|
||||
void
|
||||
_mdb_remove_backends()
|
||||
{
|
||||
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
|
||||
g_hash_table_foreach(mdb_backends, mdb_drop_backend, NULL);
|
||||
g_hash_table_destroy(mdb_backends);
|
||||
}
|
||||
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data)
|
||||
static void mdb_drop_backend(gpointer key, gpointer value, gpointer data)
|
||||
{
|
||||
MdbBackend *backend = (MdbBackend *)value;
|
||||
g_free (backend);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,8 +57,8 @@ void mdb_free_catalog(MdbHandle *mdb)
|
||||
if (entry) {
|
||||
if (entry->props) {
|
||||
for (j=0; j<entry->props->len; j++)
|
||||
mdb_free_props(g_array_index(entry->props, MdbProperties*, j));
|
||||
g_array_free(entry->props, TRUE);
|
||||
mdb_free_props(g_ptr_array_index(entry->props, j));
|
||||
g_ptr_array_free(entry->props, TRUE);
|
||||
}
|
||||
g_free(entry);
|
||||
}
|
||||
|
||||
263
src/libmdb/fakeglib.c
Normal file
263
src/libmdb/fakeglib.c
Normal file
@@ -0,0 +1,263 @@
|
||||
|
||||
#include "mdbfakeglib.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* string functions */
|
||||
|
||||
void *g_memdup(const void *src, size_t len) {
|
||||
void *dst = malloc(len);
|
||||
memcpy(dst, src, len);
|
||||
return dst;
|
||||
}
|
||||
|
||||
int g_str_equal(const void *str1, const void *str2) {
|
||||
return strcmp(str1, str2) == 0;
|
||||
}
|
||||
|
||||
char **g_strsplit(const char *haystack, const char *needle, int something) {
|
||||
char **ret = NULL;
|
||||
char *found = NULL;
|
||||
size_t components = 1;
|
||||
|
||||
while ((found = strstr(haystack, needle))) {
|
||||
components++;
|
||||
haystack = found + strlen(needle);
|
||||
}
|
||||
|
||||
ret = malloc(components * sizeof(char *));
|
||||
|
||||
int i = 0;
|
||||
while ((found = strstr(haystack, needle))) {
|
||||
ret[i++] = strndup(haystack, found - haystack);
|
||||
haystack = found + strlen(needle);
|
||||
}
|
||||
ret[i] = strdup(haystack);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void g_strfreev(char **dir) {
|
||||
int i=0;
|
||||
while (dir[i]) {
|
||||
free(dir[i]);
|
||||
i++;
|
||||
}
|
||||
free(dir);
|
||||
}
|
||||
|
||||
char *g_strconcat(const char *first, ...) {
|
||||
char *ret = NULL;
|
||||
size_t len = strlen(first);
|
||||
char *arg = NULL;
|
||||
va_list argp;
|
||||
|
||||
va_start(argp, first);
|
||||
while ((arg = va_arg(argp, char *))) {
|
||||
len += strlen(arg);
|
||||
}
|
||||
va_end(argp);
|
||||
|
||||
ret = malloc(len+1);
|
||||
|
||||
char *pos = stpcpy(ret, first);
|
||||
|
||||
va_start(argp, first);
|
||||
while ((arg = va_arg(argp, char *))) {
|
||||
pos = stpcpy(pos, arg);
|
||||
}
|
||||
va_end(argp);
|
||||
|
||||
ret[len] = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *g_strdup_printf(const char *format, ...) {
|
||||
char *ret = NULL;
|
||||
va_list argp;
|
||||
|
||||
va_start(argp, format);
|
||||
vasprintf(&ret, format, argp);
|
||||
va_end(argp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar *g_strdelimit(gchar *string, const gchar *delimiters, gchar new_delimiter) {
|
||||
char *orig = string;
|
||||
if (delimiters == NULL)
|
||||
delimiters = G_STR_DELIMITERS;
|
||||
size_t n = strlen(delimiters);
|
||||
while (*string) {
|
||||
size_t i;
|
||||
for (i=0; i<n; i++) {
|
||||
if (*string == delimiters[i]) {
|
||||
*string = new_delimiter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
}
|
||||
|
||||
return orig;
|
||||
}
|
||||
|
||||
/* GHashTable */
|
||||
|
||||
typedef struct MyNode {
|
||||
char *key;
|
||||
void *value;
|
||||
} MyNode;
|
||||
|
||||
void *g_hash_table_lookup(GHashTable *table, const void *key) {
|
||||
int i;
|
||||
for (i=0; i<table->array->len; i++) {
|
||||
MyNode *node = g_ptr_array_index(table->array, i);
|
||||
if (table->compare(key, node->key))
|
||||
return node->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void g_hash_table_insert(GHashTable *table, void *key, void *value) {
|
||||
MyNode *node = calloc(1, sizeof(MyNode));
|
||||
node->value = value;
|
||||
node->key = key;
|
||||
g_ptr_array_add(table->array, node);
|
||||
}
|
||||
|
||||
GHashTable *g_hash_table_new(GHashFunc hashes, GEqualFunc equals) {
|
||||
GHashTable *table = calloc(1, sizeof(GHashTable));
|
||||
table->array = g_ptr_array_new();
|
||||
table->compare = equals;
|
||||
return table;
|
||||
}
|
||||
|
||||
void g_hash_table_foreach(GHashTable *table, GHFunc function, void *data) {
|
||||
int i;
|
||||
for (i=0; i<table->array->len; i++) {
|
||||
MyNode *node = g_ptr_array_index(table->array, i);
|
||||
function(node->key, node->value, data);
|
||||
}
|
||||
}
|
||||
|
||||
void g_hash_table_destroy(GHashTable *table) {
|
||||
int i;
|
||||
for (i=0; i<table->array->len; i++) {
|
||||
MyNode *node = g_ptr_array_index(table->array, i);
|
||||
free(node);
|
||||
}
|
||||
g_ptr_array_free(table->array, TRUE);
|
||||
free(table);
|
||||
}
|
||||
|
||||
/* GPtrArray */
|
||||
|
||||
void g_ptr_array_sort(GPtrArray *array, GCompareFunc func) {
|
||||
qsort(array->pdata, array->len, sizeof(void *), func);
|
||||
}
|
||||
|
||||
void g_ptr_array_foreach(GPtrArray *array, GFunc function, gpointer user_data) {
|
||||
int i;
|
||||
for (i=0; i<array->len; i++) {
|
||||
function(g_ptr_array_index(array, i), user_data);
|
||||
}
|
||||
}
|
||||
|
||||
GPtrArray *g_ptr_array_new() {
|
||||
GPtrArray *array = malloc(sizeof(GPtrArray));
|
||||
array->len = 0;
|
||||
array->pdata = NULL;
|
||||
return array;
|
||||
}
|
||||
|
||||
void g_ptr_array_add(GPtrArray *array, void *entry) {
|
||||
array->pdata = realloc(array->pdata, (array->len+1) * sizeof(void *));
|
||||
array->pdata[array->len++] = entry;
|
||||
}
|
||||
|
||||
void g_ptr_array_free(GPtrArray *array, gboolean something) {
|
||||
free(array->pdata);
|
||||
free(array);
|
||||
}
|
||||
|
||||
/* GList */
|
||||
|
||||
GList *g_list_append(GList *list, void *data) {
|
||||
GList *new_list = calloc(1, sizeof(GList));
|
||||
new_list->data = data;
|
||||
new_list->next = list;
|
||||
if (list)
|
||||
list->prev = new_list;
|
||||
return new_list;
|
||||
}
|
||||
|
||||
GList *g_list_last(GList *list) {
|
||||
while (list && list->next) {
|
||||
list = list->next;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
GList *g_list_remove(GList *list, void *data) {
|
||||
GList *link = list;
|
||||
while (link) {
|
||||
if (link->data == data) {
|
||||
GList *return_list = list;
|
||||
if (link->prev)
|
||||
link->prev->next = link->next;
|
||||
if (link->next)
|
||||
link->next->prev = link->prev;
|
||||
if (link == list)
|
||||
return_list = link->next;
|
||||
free(link);
|
||||
return list;
|
||||
}
|
||||
link = link->next;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void g_list_free(GList *list) {
|
||||
GList *next = NULL;
|
||||
while (list) {
|
||||
next = list->next;
|
||||
free(list);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* GOption */
|
||||
|
||||
void g_option_context_add_main_entries (GOptionContext *context,
|
||||
const GOptionEntry *entries,
|
||||
const gchar *translation_domain) {
|
||||
context->entries = entries;
|
||||
}
|
||||
|
||||
gchar *g_option_context_get_help (GOptionContext *context,
|
||||
gboolean main_help, void *group) {
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GOptionContext *g_option_context_new(const char *description) {
|
||||
GOptionContext *ctx = calloc(1, sizeof(GOptionContext));
|
||||
ctx->desc = description;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
gboolean g_option_context_parse(GOptionContext *context,
|
||||
gint *argc, gchar ***argv, GError **error) {
|
||||
/* TODO */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void g_option_context_free(GOptionContext *context) {
|
||||
free(context);
|
||||
}
|
||||
@@ -159,16 +159,16 @@ mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name) {
|
||||
/*
|
||||
* That function takes a raw KKD/MR2 binary buffer,
|
||||
* typically read from LvProp in table MSysbjects
|
||||
* and returns a GArray of MdbProps*
|
||||
* and returns a GPtrArray of MdbProps*
|
||||
*/
|
||||
GArray*
|
||||
GPtrArray*
|
||||
mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
||||
guint32 record_len;
|
||||
guint16 record_type;
|
||||
size_t pos;
|
||||
GPtrArray *names = NULL;
|
||||
MdbProperties *props;
|
||||
GArray *result;
|
||||
GPtrArray *result;
|
||||
|
||||
#if MDB_DEBUG
|
||||
mdb_buffer_dump(buffer, 0, len);
|
||||
@@ -181,7 +181,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = g_array_new(0, 0, sizeof(MdbProperties*));
|
||||
result = g_ptr_array_new();
|
||||
|
||||
pos = 4;
|
||||
while (pos < len) {
|
||||
@@ -201,7 +201,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
||||
break;
|
||||
}
|
||||
props = mdb_read_props(mdb, names, (char*)buffer+pos+6, record_len - 6);
|
||||
g_array_append_val(result, props);
|
||||
g_ptr_array_add(result, props);
|
||||
//mdb_dump_props(props, stderr, 1);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -112,7 +112,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
|
||||
|
||||
if (entry->props)
|
||||
for (i=0; i<entry->props->len; ++i) {
|
||||
MdbProperties *props = g_array_index(entry->props, MdbProperties*, i);
|
||||
MdbProperties *props = g_ptr_array_index(entry->props, i);
|
||||
if (!props->name)
|
||||
table->props = props;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
||||
unsigned int i, j;
|
||||
int cur_pos;
|
||||
size_t name_sz;
|
||||
GArray *allprops;
|
||||
GPtrArray *allprops;
|
||||
|
||||
table->columns = g_ptr_array_new();
|
||||
|
||||
@@ -319,8 +319,8 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
||||
for (i=0;i<table->num_cols;i++) {
|
||||
pcol = g_ptr_array_index(table->columns, i);
|
||||
for (j=0; j<allprops->len; ++j) {
|
||||
MdbProperties *props = g_array_index(allprops, MdbProperties*, j);
|
||||
if (props->name && pcol->name && !strcmp(props->name, pcol->name)) {
|
||||
MdbProperties *props = g_ptr_array_index(allprops, j);
|
||||
if (props->name && !strcmp(props->name, pcol->name)) {
|
||||
pcol->props = props;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ static int GetNextItem (FILE* stream, char** name, char** value);
|
||||
#endif //HAVE_SQLGETPRIVATEPROFILESTRING
|
||||
|
||||
static void visit (gpointer key, gpointer value, gpointer user_data);
|
||||
static gboolean cleanup (gpointer key, gpointer value, gpointer user_data);
|
||||
static void cleanup (gpointer key, gpointer value, gpointer user_data);
|
||||
|
||||
/*
|
||||
* Allocate create a ConnectParams object
|
||||
@@ -91,7 +91,7 @@ void FreeConnectParams (ConnectParams* params)
|
||||
g_string_free (params->iniFileName, TRUE);
|
||||
if (params->table)
|
||||
{
|
||||
g_hash_table_foreach_remove (params->table, cleanup, NULL);
|
||||
g_hash_table_foreach (params->table, cleanup, NULL);
|
||||
g_hash_table_destroy (params->table);
|
||||
}
|
||||
g_free(params);
|
||||
@@ -514,12 +514,10 @@ static void visit (gpointer key, gpointer value, gpointer user_data)
|
||||
fprintf(output, "Parameter: %s, Value: %s\n", (char*)key, (char*)value);
|
||||
}
|
||||
|
||||
static gboolean cleanup (gpointer key, gpointer value, gpointer user_data)
|
||||
static void cleanup (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
g_free (key);
|
||||
g_free (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
SUBDIRS = bash-completion
|
||||
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver mdb-prop mdb-count
|
||||
noinst_PROGRAMS = mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
||||
LIBS = $(GLIB_LIBS) @LIBS@
|
||||
if !HAVE_GLIB
|
||||
mdb_export_SOURCES = mdb-export.c ../libmdb/fakeglib.c
|
||||
mdb_schema_SOURCES = mdb-schema.c ../libmdb/fakeglib.c
|
||||
mdb_tables_SOURCES = mdb-tables.c ../libmdb/fakeglib.c
|
||||
mdb_sql_SOURCES = mdb-sql.c ../libmdb/fakeglib.c
|
||||
mdb_ver_SOURCES = mdb-ver.c ../libmdb/fakeglib.c
|
||||
mdb_import_SOURCES = mdb-import.c ../libmdb/fakeglib.c
|
||||
endif
|
||||
LIBS = $(GLIB_LIBS) @LIBS@
|
||||
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
||||
AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
LDADD = ../libmdb/libmdb.la
|
||||
|
||||
@@ -91,12 +91,12 @@ main(int argc, char **argv)
|
||||
}
|
||||
void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
|
||||
{
|
||||
GArray *aprops = mdb_kkd_to_props(mdb, kkd, len);
|
||||
GPtrArray *aprops = mdb_kkd_to_props(mdb, kkd, len);
|
||||
int i;
|
||||
if (!aprops)
|
||||
return;
|
||||
for (i=0; i<aprops->len; ++i) {
|
||||
MdbProperties *props = g_array_index(aprops, MdbProperties*, i);
|
||||
MdbProperties *props = g_ptr_array_index(aprops, i);
|
||||
mdb_dump_props(props, stdout, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user