mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-06-28 15:39:02 +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:
parent
a2fa34c0cb
commit
e9f4c6c786
@ -146,11 +146,10 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
dnl check for glib/gtk/gnome
|
dnl check for glib/gtk/gnome
|
||||||
PKG_CHECK_MODULES([GLIB], [glib-2.0], ,
|
PKG_CHECK_MODULES([GLIB], [glib-2.0], AM_CONDITIONAL([HAVE_GLIB], true), AM_CONDITIONAL([HAVE_GLIB], false))
|
||||||
AC_MSG_ERROR([
|
if test "x$HAVE_GLIB" = "xtrue"; then
|
||||||
glib 2.0 is required by MDB Tools (runtime and devel).
|
GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1"
|
||||||
It can be downloaded at www.gtk.org.
|
fi
|
||||||
]))
|
|
||||||
|
|
||||||
PKG_CHECK_MODULES([GNOME], [gtk+-2.0 >= 2.14 libglade-2.0 libgnomeui-2.0], HAVE_GNOME=true, HAVE_GNOME=false)
|
PKG_CHECK_MODULES([GNOME], [gtk+-2.0 >= 2.14 libglade-2.0 libgnomeui-2.0], HAVE_GNOME=true, HAVE_GNOME=false)
|
||||||
|
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
include_HEADERS = mdbtools.h mdbsql.h mdbver.h
|
include_HEADERS = mdbtools.h mdbsql.h mdbver.h
|
||||||
|
if !HAVE_GLIB
|
||||||
|
include_HEADERS += mdbfakeglib.h
|
||||||
|
endif
|
||||||
noinst_HEADERS = mdbprivate.h
|
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 <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifdef HAVE_GLIB
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#else
|
||||||
|
#include <mdbfakeglib.h>
|
||||||
|
#endif
|
||||||
#include <mdbtools.h>
|
#include <mdbtools.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -30,7 +30,12 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_GLIB
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#else
|
||||||
|
#include <mdbfakeglib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
@ -284,8 +289,7 @@ typedef struct {
|
|||||||
int object_type;
|
int object_type;
|
||||||
unsigned long table_pg; /* misnomer since object may not be a table */
|
unsigned long table_pg; /* misnomer since object may not be a table */
|
||||||
//int num_props; please use props->len
|
//int num_props; please use props->len
|
||||||
GArray *props; /* GArray of MdbProperties */
|
GPtrArray *props; /* GPtrArray of MdbProperties */
|
||||||
GArray *columns;
|
|
||||||
int flags;
|
int flags;
|
||||||
} MdbCatalogEntry;
|
} MdbCatalogEntry;
|
||||||
|
|
||||||
@ -575,7 +579,7 @@ extern gint32 mdb_map_find_next(MdbHandle *mdb, unsigned char *map, unsigned int
|
|||||||
/* props.c */
|
/* props.c */
|
||||||
extern void mdb_free_props(MdbProperties *props);
|
extern void mdb_free_props(MdbProperties *props);
|
||||||
extern void mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name);
|
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 */
|
/* worktable.c */
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
lib_LTLIBRARIES = libmdb.la
|
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
|
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$$)'
|
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)
|
AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||||
LIBS = $(GLIB_LIBS) @LIBS@ @LIBICONV@
|
LIBS = $(GLIB_LIBS) @LIBS@ @LIBICONV@
|
||||||
|
@ -184,7 +184,7 @@ enum {
|
|||||||
MDB_BACKEND_SQLITE,
|
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*
|
static gchar*
|
||||||
quote_generic(const gchar *value, gchar quote_char, gchar escape_char) {
|
quote_generic(const gchar *value, gchar quote_char, gchar escape_char) {
|
||||||
@ -448,14 +448,13 @@ mdb_remove_backends())
|
|||||||
void
|
void
|
||||||
_mdb_remove_backends()
|
_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);
|
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;
|
MdbBackend *backend = (MdbBackend *)value;
|
||||||
g_free (backend);
|
g_free (backend);
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,8 +57,8 @@ void mdb_free_catalog(MdbHandle *mdb)
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
if (entry->props) {
|
if (entry->props) {
|
||||||
for (j=0; j<entry->props->len; j++)
|
for (j=0; j<entry->props->len; j++)
|
||||||
mdb_free_props(g_array_index(entry->props, MdbProperties*, j));
|
mdb_free_props(g_ptr_array_index(entry->props, j));
|
||||||
g_array_free(entry->props, TRUE);
|
g_ptr_array_free(entry->props, TRUE);
|
||||||
}
|
}
|
||||||
g_free(entry);
|
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,
|
* That function takes a raw KKD/MR2 binary buffer,
|
||||||
* typically read from LvProp in table MSysbjects
|
* 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) {
|
mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
||||||
guint32 record_len;
|
guint32 record_len;
|
||||||
guint16 record_type;
|
guint16 record_type;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
GPtrArray *names = NULL;
|
GPtrArray *names = NULL;
|
||||||
MdbProperties *props;
|
MdbProperties *props;
|
||||||
GArray *result;
|
GPtrArray *result;
|
||||||
|
|
||||||
#if MDB_DEBUG
|
#if MDB_DEBUG
|
||||||
mdb_buffer_dump(buffer, 0, len);
|
mdb_buffer_dump(buffer, 0, len);
|
||||||
@ -181,7 +181,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = g_array_new(0, 0, sizeof(MdbProperties*));
|
result = g_ptr_array_new();
|
||||||
|
|
||||||
pos = 4;
|
pos = 4;
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
@ -201,7 +201,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
props = mdb_read_props(mdb, names, (char*)buffer+pos+6, record_len - 6);
|
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);
|
//mdb_dump_props(props, stderr, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -112,7 +112,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
|
|||||||
|
|
||||||
if (entry->props)
|
if (entry->props)
|
||||||
for (i=0; i<entry->props->len; ++i) {
|
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)
|
if (!props->name)
|
||||||
table->props = props;
|
table->props = props;
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
|||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
int cur_pos;
|
int cur_pos;
|
||||||
size_t name_sz;
|
size_t name_sz;
|
||||||
GArray *allprops;
|
GPtrArray *allprops;
|
||||||
|
|
||||||
table->columns = g_ptr_array_new();
|
table->columns = g_ptr_array_new();
|
||||||
|
|
||||||
@ -319,8 +319,8 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
|||||||
for (i=0;i<table->num_cols;i++) {
|
for (i=0;i<table->num_cols;i++) {
|
||||||
pcol = g_ptr_array_index(table->columns, i);
|
pcol = g_ptr_array_index(table->columns, i);
|
||||||
for (j=0; j<allprops->len; ++j) {
|
for (j=0; j<allprops->len; ++j) {
|
||||||
MdbProperties *props = g_array_index(allprops, MdbProperties*, j);
|
MdbProperties *props = g_ptr_array_index(allprops, j);
|
||||||
if (props->name && pcol->name && !strcmp(props->name, pcol->name)) {
|
if (props->name && !strcmp(props->name, pcol->name)) {
|
||||||
pcol->props = props;
|
pcol->props = props;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ static int GetNextItem (FILE* stream, char** name, char** value);
|
|||||||
#endif //HAVE_SQLGETPRIVATEPROFILESTRING
|
#endif //HAVE_SQLGETPRIVATEPROFILESTRING
|
||||||
|
|
||||||
static void visit (gpointer key, gpointer value, gpointer user_data);
|
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
|
* Allocate create a ConnectParams object
|
||||||
@ -91,7 +91,7 @@ void FreeConnectParams (ConnectParams* params)
|
|||||||
g_string_free (params->iniFileName, TRUE);
|
g_string_free (params->iniFileName, TRUE);
|
||||||
if (params->table)
|
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_hash_table_destroy (params->table);
|
||||||
}
|
}
|
||||||
g_free(params);
|
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);
|
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 (key);
|
||||||
g_free (value);
|
g_free (value);
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
|
AUTOMAKE_OPTIONS = subdir-objects
|
||||||
SUBDIRS = bash-completion
|
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
|
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
|
noinst_PROGRAMS = mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
||||||
|
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@
|
LIBS = $(GLIB_LIBS) @LIBS@
|
||||||
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
||||||
AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||||
|
@ -91,12 +91,12 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
|
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;
|
int i;
|
||||||
if (!aprops)
|
if (!aprops)
|
||||||
return;
|
return;
|
||||||
for (i=0; i<aprops->len; ++i) {
|
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);
|
mdb_dump_props(props, stdout, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user