From e9f4c6c7865ff18c085c7752f97ac09832a0c678 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Aug 2020 17:19:40 -0400 Subject: [PATCH 01/30] 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. --- configure.ac | 9 +- include/Makefile.am | 3 + include/mdbfakeglib.h | 147 ++++++++++++++++++++++ include/mdbsql.h | 4 + include/mdbtools.h | 10 +- src/libmdb/Makefile.am | 3 + src/libmdb/backend.c | 7 +- src/libmdb/catalog.c | 4 +- src/libmdb/fakeglib.c | 263 +++++++++++++++++++++++++++++++++++++++ src/libmdb/props.c | 10 +- src/libmdb/table.c | 8 +- src/odbc/connectparams.c | 8 +- src/util/Makefile.am | 11 +- src/util/mdb-prop.c | 4 +- 14 files changed, 460 insertions(+), 31 deletions(-) create mode 100644 include/mdbfakeglib.h create mode 100644 src/libmdb/fakeglib.c diff --git a/configure.ac b/configure.ac index fd56e68..5c73ad9 100644 --- a/configure.ac +++ b/configure.ac @@ -146,11 +146,10 @@ fi dnl check for glib/gtk/gnome -PKG_CHECK_MODULES([GLIB], [glib-2.0], , - AC_MSG_ERROR([ -glib 2.0 is required by MDB Tools (runtime and devel). -It can be downloaded at www.gtk.org. -])) +PKG_CHECK_MODULES([GLIB], [glib-2.0], AM_CONDITIONAL([HAVE_GLIB], true), AM_CONDITIONAL([HAVE_GLIB], false)) +if test "x$HAVE_GLIB" = "xtrue"; then + GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1" +fi PKG_CHECK_MODULES([GNOME], [gtk+-2.0 >= 2.14 libglade-2.0 libgnomeui-2.0], HAVE_GNOME=true, HAVE_GNOME=false) diff --git a/include/Makefile.am b/include/Makefile.am index 073b09c..c19d930 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,2 +1,5 @@ include_HEADERS = mdbtools.h mdbsql.h mdbver.h +if !HAVE_GLIB +include_HEADERS += mdbfakeglib.h +endif noinst_HEADERS = mdbprivate.h diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h new file mode 100644 index 0000000..beb8ee4 --- /dev/null +++ b/include/mdbfakeglib.h @@ -0,0 +1,147 @@ +#ifndef _glib_shim_h_ +#define _glib_shim_h_ + +#include +#include +#include + +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 diff --git a/include/mdbsql.h b/include/mdbsql.h index 951a340..e39d736 100644 --- a/include/mdbsql.h +++ b/include/mdbsql.h @@ -25,7 +25,11 @@ #include #include +#ifdef HAVE_GLIB #include +#else +#include +#endif #include typedef struct { diff --git a/include/mdbtools.h b/include/mdbtools.h index e5f5baa..c553c95 100644 --- a/include/mdbtools.h +++ b/include/mdbtools.h @@ -30,7 +30,12 @@ #include #include #include + +#ifdef HAVE_GLIB #include +#else +#include +#endif #ifdef HAVE_ICONV #include @@ -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 */ diff --git a/src/libmdb/Makefile.am b/src/libmdb/Makefile.am index aa823ba..aa3742e 100644 --- a/src/libmdb/Makefile.am +++ b/src/libmdb/Makefile.am @@ -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@ diff --git a/src/libmdb/backend.c b/src/libmdb/backend.c index c67c0ba..12ffe3e 100644 --- a/src/libmdb/backend.c +++ b/src/libmdb/backend.c @@ -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; } /** diff --git a/src/libmdb/catalog.c b/src/libmdb/catalog.c index 2093ad5..e4d93b4 100644 --- a/src/libmdb/catalog.c +++ b/src/libmdb/catalog.c @@ -57,8 +57,8 @@ void mdb_free_catalog(MdbHandle *mdb) if (entry) { if (entry->props) { for (j=0; jprops->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); } diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c new file mode 100644 index 0000000..b659090 --- /dev/null +++ b/src/libmdb/fakeglib.c @@ -0,0 +1,263 @@ + +#include "mdbfakeglib.h" + +#include +#include +#include +#include +#include + +/* 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; iarray->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; iarray->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; iarray->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; ilen; 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); +} diff --git a/src/libmdb/props.c b/src/libmdb/props.c index 801fd5b..b647d87 100644 --- a/src/libmdb/props.c +++ b/src/libmdb/props.c @@ -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: diff --git a/src/libmdb/table.c b/src/libmdb/table.c index 8f8ed55..da64e50 100644 --- a/src/libmdb/table.c +++ b/src/libmdb/table.c @@ -112,7 +112,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry) if (entry->props) for (i=0; iprops->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;inum_cols;i++) { pcol = g_ptr_array_index(table->columns, i); for (j=0; jlen; ++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; } diff --git a/src/odbc/connectparams.c b/src/odbc/connectparams.c index 76546b4..ad30d88 100644 --- a/src/odbc/connectparams.c +++ b/src/odbc/connectparams.c @@ -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; } diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 477fb2c..513a156 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -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 diff --git a/src/util/mdb-prop.c b/src/util/mdb-prop.c index e9cfa06..a0a88bb 100644 --- a/src/util/mdb-prop.c +++ b/src/util/mdb-prop.c @@ -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; ilen; ++i) { - MdbProperties *props = g_array_index(aprops, MdbProperties*, i); + MdbProperties *props = g_ptr_array_index(aprops, i); mdb_dump_props(props, stdout, 1); } } From fa01a6fe27a6ddd0eb864dd8e4bfcf0aa1fbaa5f Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Aug 2020 19:53:58 -0400 Subject: [PATCH 02/30] Implement g_option_context_get_help (fake GLib) This fixes the crashing issues, but the command-line tools are still useless. --- include/mdbfakeglib.h | 5 ++++- src/libmdb/fakeglib.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index beb8ee4..9bfd942 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -16,6 +16,7 @@ typedef unsigned int guint; typedef void * gpointer; typedef const void * gconstpointer; typedef uint8_t guint8; +typedef guint32 GQuark; typedef guint (*GHashFunc)(gconstpointer); typedef int (*GCompareFunc)(gconstpointer, gconstpointer); @@ -41,7 +42,9 @@ typedef struct GHashTable { } GHashTable; typedef struct GError { - const char *message; + GQuark domain; + gint code; + gchar *message; } GError; typedef enum GOptionArg { diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index b659090..27244d3 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -242,8 +242,39 @@ void g_option_context_add_main_entries (GOptionContext *context, gchar *g_option_context_get_help (GOptionContext *context, gboolean main_help, void *group) { - /* TODO */ - return NULL; +#if defined(__APPLE__) || defined(__FreeBSD__) + const char * appname = getprogname(); +#elif defined(_GNU_SOURCE) + const char * appname = program_invocation_name; +#else + const char * appname = "mdb-util"; +#endif + + char *help = malloc(4096); + char *end = help + 4096; + char *p = help; + p += snprintf(p, end - p, + "Usage:\n %s [OPTION\xE2\x80\xA6] %s\n\n", appname, context->desc); + p += snprintf(p, end - p, + "Help Options:\n -h, --%-20s%s\n\n", "help", "Show help options"); + p += snprintf(p, end - p, + "Application Options:\n"); + int i=0; + for (i=0; context->entries[i].long_name; i++) { + p += snprintf(p, end - p, " -%c, --", context->entries[i].short_name); + if (context->entries[i].arg_description) { + char *long_name = g_strconcat( + context->entries[i].long_name, "=", + context->entries[i].arg_description, NULL); + p += snprintf(p, end - p, "%-20s", long_name); + free(long_name); + } else { + p += snprintf(p, end - p, "%-20s", context->entries[i].long_name); + } + p += snprintf(p, end - p, "%s\n", context->entries[i].description); + } + p += snprintf(p, end - p, "\n"); + return help; } GOptionContext *g_option_context_new(const char *description) { @@ -254,6 +285,8 @@ GOptionContext *g_option_context_new(const char *description) { gboolean g_option_context_parse(GOptionContext *context, gint *argc, gchar ***argv, GError **error) { + *error = malloc(sizeof(GError)); + (*error)->message = "Not implemented"; /* TODO */ return FALSE; } From 255b38d7fda24f7b9383dfc080690b19f76753cf Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Aug 2020 22:13:13 -0400 Subject: [PATCH 03/30] Implement g_option_context_parse for short options Use getopt under the hood for old-fashioned argument parsing. Still need to add support for --long-style-options. --- src/libmdb/fakeglib.c | 74 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 27244d3..0fd58e8 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -6,6 +6,7 @@ #include #include #include +#include /* string functions */ @@ -261,7 +262,11 @@ gchar *g_option_context_get_help (GOptionContext *context, "Application Options:\n"); int i=0; for (i=0; context->entries[i].long_name; i++) { - p += snprintf(p, end - p, " -%c, --", context->entries[i].short_name); + p += snprintf(p, end - p, " "); + if (context->entries[i].short_name) { + p += snprintf(p, end - p, "-%c, ", context->entries[i].short_name); + } + p += snprintf(p, end - p, "--"); if (context->entries[i].arg_description) { char *long_name = g_strconcat( context->entries[i].long_name, "=", @@ -271,6 +276,9 @@ gchar *g_option_context_get_help (GOptionContext *context, } else { p += snprintf(p, end - p, "%-20s", context->entries[i].long_name); } + if (!context->entries[i].short_name) { + p += snprintf(p, end - p, " "); + } p += snprintf(p, end - p, "%s\n", context->entries[i].description); } p += snprintf(p, end - p, "\n"); @@ -285,10 +293,66 @@ GOptionContext *g_option_context_new(const char *description) { gboolean g_option_context_parse(GOptionContext *context, gint *argc, gchar ***argv, GError **error) { - *error = malloc(sizeof(GError)); - (*error)->message = "Not implemented"; - /* TODO */ - return FALSE; + int i; + int count = 0; + int len = 0; + if (*argc == 2 && + (strcmp((*argv)[1], "-h") == 0 || strcmp((*argv)[1], "--help") == 0)) { + fprintf(stderr, "%s", g_option_context_get_help(context, TRUE, NULL)); + exit(0); + } + for (i=0; context->entries[i].long_name; i++) { + GOptionArg arg = context->entries[i].arg; + count++; + len++; + if (arg == G_OPTION_ARG_STRING || arg == G_OPTION_ARG_INT) { + len++; + } + } + char *short_opts = calloc(1, len+1); + for (i=0; ientries[i].arg; + short_opts[i] = context->entries[i].short_name; + if (arg == G_OPTION_ARG_STRING || arg == G_OPTION_ARG_INT) { + short_opts[++i] = ':'; + } + } + int c; + opterr = 0; + while ((c = getopt(*argc, *argv, short_opts)) != -1) { + if (c == '?') { + *error = malloc(sizeof(GError)); + (*error)->message = malloc(100); + snprintf((*error)->message, 100, "Unrecognized option: %c", optopt); + free(short_opts); + return FALSE; + } + for (i=0; ientries[i].short_name == c) { + GOptionArg arg = context->entries[i].arg; + if (arg == G_OPTION_ARG_NONE) { + *(int *)context->entries[i].arg_data = !(context->entries[i].flags & G_OPTION_FLAG_REVERSE); + } else if (arg == G_OPTION_ARG_INT) { + char *endptr = NULL; + *(int *)context->entries[i].arg_data = strtol(optarg, &endptr, 10); + if (*endptr) { + *error = malloc(sizeof(GError)); + (*error)->message = malloc(100); + snprintf((*error)->message, 100, "Argument to -%c must be an integer", c); + free(short_opts); + return FALSE; + } + } else if (arg == G_OPTION_ARG_STRING) { + *(char **)context->entries[i].arg_data = strdup(optarg); + } + } + } + } + *argc -= (optind - 1); + *argv += (optind - 1); + free(short_opts); + + return TRUE; } void g_option_context_free(GOptionContext *context) { From f9a0234cf477ce1218a0eac24444d349d1112ffb Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Mon, 3 Aug 2020 23:58:33 -0400 Subject: [PATCH 04/30] Support long-style options (fake GLib) --- src/libmdb/fakeglib.c | 67 +++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 0fd58e8..eed36a0 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include /* string functions */ @@ -309,48 +309,67 @@ gboolean g_option_context_parse(GOptionContext *context, len++; } } + struct option *long_opts = calloc(count+1, sizeof(struct option)); char *short_opts = calloc(1, len+1); - for (i=0; ientries[i].arg; - short_opts[i] = context->entries[i].short_name; + int j=0; + for (i=0; ientries[i]; + GOptionArg arg = entry->arg; + short_opts[j++] = entry->short_name; if (arg == G_OPTION_ARG_STRING || arg == G_OPTION_ARG_INT) { - short_opts[++i] = ':'; + short_opts[j++] = ':'; } + long_opts[i].name = entry->long_name; + long_opts[i].has_arg = entry->arg == G_OPTION_ARG_NONE ? no_argument : required_argument; } int c; + int longindex = 0; opterr = 0; - while ((c = getopt(*argc, *argv, short_opts)) != -1) { + while ((c = getopt_long(*argc, *argv, short_opts, long_opts, &longindex)) != -1) { if (c == '?') { *error = malloc(sizeof(GError)); (*error)->message = malloc(100); - snprintf((*error)->message, 100, "Unrecognized option: %c", optopt); + if (optopt) { + snprintf((*error)->message, 100, "Unrecognized option: -%c", optopt); + } else { + snprintf((*error)->message, 100, "Unrecognized option: %s", (*argv)[optind-1]); + } free(short_opts); + free(long_opts); return FALSE; } - for (i=0; ientries[i].short_name == c) { - GOptionArg arg = context->entries[i].arg; - if (arg == G_OPTION_ARG_NONE) { - *(int *)context->entries[i].arg_data = !(context->entries[i].flags & G_OPTION_FLAG_REVERSE); - } else if (arg == G_OPTION_ARG_INT) { - char *endptr = NULL; - *(int *)context->entries[i].arg_data = strtol(optarg, &endptr, 10); - if (*endptr) { - *error = malloc(sizeof(GError)); - (*error)->message = malloc(100); - snprintf((*error)->message, 100, "Argument to -%c must be an integer", c); - free(short_opts); - return FALSE; - } - } else if (arg == G_OPTION_ARG_STRING) { - *(char **)context->entries[i].arg_data = strdup(optarg); + const GOptionEntry *entry = NULL; + if (c == 0) { + entry = &context->entries[longindex]; + } else { + for (i=0; ientries[i].short_name == c) { + entry = &context->entries[i]; + break; } } } + if (entry->arg == G_OPTION_ARG_NONE) { + *(int *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE); + } else if (entry->arg == G_OPTION_ARG_INT) { + char *endptr = NULL; + *(int *)entry->arg_data = strtol(optarg, &endptr, 10); + if (*endptr) { + *error = malloc(sizeof(GError)); + (*error)->message = malloc(100); + snprintf((*error)->message, 100, "Argument to --%s must be an integer", entry->long_name); + free(short_opts); + free(long_opts); + return FALSE; + } + } else if (entry->arg == G_OPTION_ARG_STRING) { + *(char **)entry->arg_data = strdup(optarg); + } } *argc -= (optind - 1); *argv += (optind - 1); free(short_opts); + free(long_opts); return TRUE; } From 65b3701d67f94bbfa3c25be2c7ae3a9588e3a20f Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Tue, 4 Aug 2020 08:02:10 -0400 Subject: [PATCH 05/30] Fix building utilities with GLib present --- src/util/Makefile.am | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 513a156..9460beb 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -2,13 +2,19 @@ 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 +mdb_export_SOURCES = mdb-export.c +mdb_schema_SOURCES = mdb-schema.c +mdb_tables_SOURCES = mdb-tables.c +mdb_sql_SOURCES = mdb-sql.c +mdb_ver_SOURCES = mdb-ver.c +mdb_import_SOURCES = mdb-import.c 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 +mdb_export_SOURCES += ../libmdb/fakeglib.c +mdb_schema_SOURCES += ../libmdb/fakeglib.c +mdb_tables_SOURCES += ../libmdb/fakeglib.c +mdb_sql_SOURCES += ../libmdb/fakeglib.c +mdb_ver_SOURCES += ../libmdb/fakeglib.c +mdb_import_SOURCES += ../libmdb/fakeglib.c endif LIBS = $(GLIB_LIBS) @LIBS@ DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\" From 6771014c490aa4931f2591ed548a332c0ecc0433 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 00:20:59 -0400 Subject: [PATCH 06/30] Windows portability fixes --- include/mdbfakeglib.h | 7 +++++++ src/libmdb/fakeglib.c | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 9bfd942..614dc68 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -5,6 +5,13 @@ #include #include +// for ntohl +#ifdef _WIN32 +#include +#else +#include +#endif + typedef uint16_t guint16; typedef uint32_t guint32; typedef uint64_t guint64; diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index eed36a0..5e56bd8 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -34,7 +34,13 @@ char **g_strsplit(const char *haystack, const char *needle, int something) { int i = 0; while ((found = strstr(haystack, needle))) { - ret[i++] = strndup(haystack, found - haystack); + // Windows lacks strndup + size_t chunk_len = found - haystack; + char *chunk = malloc(chunk_len + 1); + memcpy(chunk, haystack, chunk_len); + chunk[chunk_len] = 0; + + ret[i++] = chunk; haystack = found + strlen(needle); } ret[i] = strdup(haystack); @@ -65,11 +71,11 @@ char *g_strconcat(const char *first, ...) { ret = malloc(len+1); - char *pos = stpcpy(ret, first); + char *pos = strcpy(ret, first) + strlen(first); va_start(argp, first); while ((arg = va_arg(argp, char *))) { - pos = stpcpy(pos, arg); + pos = strcpy(pos, arg) + strlen(arg); } va_end(argp); From 4f481000a80d9c5c1a87655fcbbd4c489de3e8e9 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 00:27:03 -0400 Subject: [PATCH 07/30] Fix logic error / warning in fake g_list_remove --- src/libmdb/fakeglib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 5e56bd8..c9e1548 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -223,7 +223,7 @@ GList *g_list_remove(GList *list, void *data) { if (link == list) return_list = link->next; free(link); - return list; + return return_list; } link = link->next; } From 71969c29df467076d3c0097d4ba900bb29ddb88a Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 00:33:29 -0400 Subject: [PATCH 08/30] Remove GLib from Appveyor --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8344a33..1d446c8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,14 +22,12 @@ build_script: if ($env:TOOLCHAIN -eq "msys2") { $env:MSYSTEM="MINGW64" - C:\msys64\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-glib2" C:\msys64\usr\bin\bash -l -c "cd /c/projects/mdbtools && autoreconf -i -f" C:\msys64\usr\bin\bash -l -c "cd /c/projects/mdbtools && ./configure --disable-man --disable-silent-rules" C:\msys64\usr\bin\bash -l -c "cd /c/projects/mdbtools && make" } else { - C:\cygwin64\setup-x86_64.exe -qP libglib2.0-devel C:\cygwin64\bin\sh -lc "cd /cygdrive/c/projects/mdbtools && autoreconf -i -f" C:\cygwin64\bin\sh -lc "cd /cygdrive/c/projects/mdbtools && ./configure --disable-man --disable-silent-rules" C:\cygwin64\bin\sh -lc "cd /cygdrive/c/projects/mdbtools && make" From 36ba51db7ad96f80aeaa9014a19951768fb3c1df Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 00:45:14 -0400 Subject: [PATCH 09/30] More Windows fixes --- configure.ac | 2 +- include/mdbfakeglib.h | 1 + src/libmdb/fakeglib.c | 1 - src/libmdb/iconv.c | 4 ++++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 3a2c6b8..7b3845c 100644 --- a/configure.ac +++ b/configure.ac @@ -63,7 +63,7 @@ AC_SUBST(LFLAGS) CFLAGS="$CFLAGS -Wall -Wstrict-prototypes" AS_CASE([$host], - [*mingw*|*cygwin*], [LDFLAGS="$LDFLAGS -no-undefined"], []) + [*mingw*|*cygwin*], [LDFLAGS="$LDFLAGS -no-undefined -lWs2_32"], []) dnl Enable -Wl,--as-needed by default to prevent overlinking AC_ARG_ENABLE([as-needed], diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 614dc68..751ae0c 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -4,6 +4,7 @@ #include #include #include +#include // for ntohl #ifdef _WIN32 diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index c9e1548..525ddfc 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -1,7 +1,6 @@ #include "mdbfakeglib.h" -#include #include #include #include diff --git a/src/libmdb/iconv.c b/src/libmdb/iconv.c index 25c1fa3..34dbd17 100644 --- a/src/libmdb/iconv.c +++ b/src/libmdb/iconv.c @@ -23,6 +23,10 @@ #include "dmalloc.h" #endif +#ifndef MIN +#define MIN(a,b) (a>b ? b : a) +#endif + /* * This function is used in reading text data from an MDB table. */ From 40433e3a11dbd9a2a104acff6b6cafb670977ba0 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 00:55:49 -0400 Subject: [PATCH 10/30] Compile fakeglib into libmdbsql Fixes build error --- src/sql/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sql/Makefile.am b/src/sql/Makefile.am index 94b0838..02cf042 100644 --- a/src/sql/Makefile.am +++ b/src/sql/Makefile.am @@ -2,6 +2,9 @@ BUILT_SOURCES = parser.h AM_YFLAGS = -d lib_LTLIBRARIES = libmdbsql.la libmdbsql_la_SOURCES= mdbsql.c parser.y lexer.l +if !HAVE_GLIB +libmdbsql_la_SOURCES += fakeglib.c +endif libmdbsql_la_LDFLAGS = -version-info 2:0:0 -export-symbols-regex '^mdb_sql_' CLEANFILES = parser.c parser.h lexer.c AM_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) From 32ec8081b07eb7a5528cebcb6907694a40d6513d Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 08:04:46 -0400 Subject: [PATCH 11/30] Fix build --- src/sql/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sql/Makefile.am b/src/sql/Makefile.am index 02cf042..7a353f2 100644 --- a/src/sql/Makefile.am +++ b/src/sql/Makefile.am @@ -1,9 +1,10 @@ +AUTOMAKE_OPTIONS = subdir-objects BUILT_SOURCES = parser.h AM_YFLAGS = -d lib_LTLIBRARIES = libmdbsql.la libmdbsql_la_SOURCES= mdbsql.c parser.y lexer.l if !HAVE_GLIB -libmdbsql_la_SOURCES += fakeglib.c +libmdbsql_la_SOURCES += ../libmdb/fakeglib.c endif libmdbsql_la_LDFLAGS = -version-info 2:0:0 -export-symbols-regex '^mdb_sql_' CLEANFILES = parser.c parser.h lexer.c From 7ecd132e572e4a6fd0f22767636dbd6478401074 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 08:17:49 -0400 Subject: [PATCH 12/30] Cygwin fix --- configure.ac | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7b3845c..a5f7254 100644 --- a/configure.ac +++ b/configure.ac @@ -63,7 +63,9 @@ AC_SUBST(LFLAGS) CFLAGS="$CFLAGS -Wall -Wstrict-prototypes" AS_CASE([$host], - [*mingw*|*cygwin*], [LDFLAGS="$LDFLAGS -no-undefined -lWs2_32"], []) + [*mingw*|*cygwin*], [LDFLAGS="$LDFLAGS -no-undefined"], []) +AS_CASE([$host], + [*mingw*], [LDFLAGS="$LDFLAGS -lWs2_32"], []) dnl Enable -Wl,--as-needed by default to prevent overlinking AC_ARG_ENABLE([as-needed], From 8ef1c6e1c3e0f22d8af072fbae912dd244157a72 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 08:26:40 -0400 Subject: [PATCH 13/30] Provide vasprintf on Windows --- include/mdbfakeglib.h | 1 + src/libmdb/fakeglib.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 751ae0c..663a76b 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -5,6 +5,7 @@ #include #include #include +#include // for ntohl #ifdef _WIN32 diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 525ddfc..ebe61dc 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -83,6 +83,24 @@ char *g_strconcat(const char *first, ...) { return ret; } +#ifdef _MSC_VER +int vasprintf(char **ret, const char *format, va_list ap) { + int len; + int retval; + char *result; + if ((len = _vscprintf(format, ap)) < 0) + return -1; + if ((result = malloc(len+1)) == NULL) + return -1; + if ((retval = _vsprintf_s(result, len+1, format, ap)) == -1) { + free(result); + return -1; + } + *ret = result; + return retval; +} +#endif + char *g_strdup_printf(const char *format, ...) { char *ret = NULL; va_list argp; From 1d7d3c39d2b9ee17c749ccb01bf742e97e25dc1a Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 08:32:48 -0400 Subject: [PATCH 14/30] Maybe finally fix Windows builds --- src/libmdb/fakeglib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index ebe61dc..a0569d9 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -83,7 +83,7 @@ char *g_strconcat(const char *first, ...) { return ret; } -#ifdef _MSC_VER +#ifdef _WIN32 int vasprintf(char **ret, const char *format, va_list ap) { int len; int retval; From 41c7e01ec738a4b05bfb217485b73ce83f359a4b Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 08:41:33 -0400 Subject: [PATCH 15/30] Even more Windows fixes --- include/mdbfakeglib.h | 4 ++++ src/libmdb/fakeglib.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 663a76b..73541d6 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -96,7 +96,11 @@ typedef struct GOptionContext { #define g_free free #define g_realloc realloc +#ifdef _WIN32 +#define g_strdup _strdup +#else #define g_strdup strdup +#endif #define G_STR_DELIMITERS "_-|> <." diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index a0569d9..da884a5 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -92,7 +92,7 @@ int vasprintf(char **ret, const char *format, va_list ap) { return -1; if ((result = malloc(len+1)) == NULL) return -1; - if ((retval = _vsprintf_s(result, len+1, format, ap)) == -1) { + if ((retval = vsprintf_s(result, len+1, format, ap)) == -1) { free(result); return -1; } From 7dcb42eae3d79bbbbe9613ad5c077ca1364e66bd Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 09:00:38 -0400 Subject: [PATCH 16/30] Try fixing Cygwin --- include/mdbfakeglib.h | 2 +- src/libmdb/fakeglib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 73541d6..185a10c 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -96,7 +96,7 @@ typedef struct GOptionContext { #define g_free free #define g_realloc realloc -#ifdef _WIN32 +#if defined _WIN32 || defined __CYGWIN__ #define g_strdup _strdup #else #define g_strdup strdup diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index da884a5..143a07b 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -83,7 +83,7 @@ char *g_strconcat(const char *first, ...) { return ret; } -#ifdef _WIN32 +#if defined _WIN32 || defined __CYGWIN__ int vasprintf(char **ret, const char *format, va_list ap) { int len; int retval; From f1af742ecf8e4ee547de8531b36f46271d653ef5 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 09:22:26 -0400 Subject: [PATCH 17/30] Another attempted Cygwin fix --- include/mdbfakeglib.h | 2 +- src/libmdb/fakeglib.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 185a10c..5a0262d 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -96,7 +96,7 @@ typedef struct GOptionContext { #define g_free free #define g_realloc realloc -#if defined _WIN32 || defined __CYGWIN__ +#if defined _WIN32 #define g_strdup _strdup #else #define g_strdup strdup diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 143a07b..199308b 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -83,7 +83,7 @@ char *g_strconcat(const char *first, ...) { return ret; } -#if defined _WIN32 || defined __CYGWIN__ +#if defined _WIN32 int vasprintf(char **ret, const char *format, va_list ap) { int len; int retval; @@ -106,7 +106,12 @@ char *g_strdup_printf(const char *format, ...) { va_list argp; va_start(argp, format); +#ifdef ___CYGWIN__ + size_t len = 0; + vasnprintf(&ret, &len, format, argp); +#else vasprintf(&ret, format, argp); +#endif va_end(argp); return ret; From 05092351dfcca1b5e1981724efe1be69ea75d322 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 09:35:19 -0400 Subject: [PATCH 18/30] Don't rely on strdup / cygwin fix --- include/mdbfakeglib.h | 8 +------- src/libmdb/fakeglib.c | 8 +++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 5a0262d..2b5766d 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -4,7 +4,6 @@ #include #include #include -#include #include // for ntohl @@ -96,12 +95,6 @@ typedef struct GOptionContext { #define g_free free #define g_realloc realloc -#if defined _WIN32 -#define g_strdup _strdup -#else -#define g_strdup strdup -#endif - #define G_STR_DELIMITERS "_-|> <." #define g_ptr_array_index(array, i) \ @@ -125,6 +118,7 @@ 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(const char *src); char *g_strdup_printf(const char *format, ...); gchar *g_strdelimit(gchar *string, const gchar *delimiters, gchar new_delimiter); diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 199308b..c799c6d 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -5,6 +5,7 @@ #include #include #include +#include #include /* string functions */ @@ -101,12 +102,17 @@ int vasprintf(char **ret, const char *format, va_list ap) { } #endif +char *g_strdup(const char *input) { + size_t len = strlen(input); + return g_memdup(input, len+1); +} + char *g_strdup_printf(const char *format, ...) { char *ret = NULL; va_list argp; va_start(argp, format); -#ifdef ___CYGWIN__ +#ifdef __CYGWIN__ size_t len = 0; vasnprintf(&ret, &len, format, argp); #else From 7436fa0e0eb8aedaf2f20baf061b18809bb310d7 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 09:53:41 -0400 Subject: [PATCH 19/30] Yet another attempted cygwin fix --- src/libmdb/fakeglib.c | 2 +- src/util/Makefile.am | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index c799c6d..f0f51f8 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -114,7 +114,7 @@ char *g_strdup_printf(const char *format, ...) { va_start(argp, format); #ifdef __CYGWIN__ size_t len = 0; - vasnprintf(&ret, &len, format, argp); + ret = vasnprintf(ret, &len, format, argp); #else vasprintf(&ret, format, argp); #endif diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 9460beb..470e6c5 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -8,6 +8,7 @@ mdb_tables_SOURCES = mdb-tables.c mdb_sql_SOURCES = mdb-sql.c mdb_ver_SOURCES = mdb-ver.c mdb_import_SOURCES = mdb-import.c +updrow_SOURCES = updrow.c if !HAVE_GLIB mdb_export_SOURCES += ../libmdb/fakeglib.c mdb_schema_SOURCES += ../libmdb/fakeglib.c @@ -15,6 +16,7 @@ mdb_tables_SOURCES += ../libmdb/fakeglib.c mdb_sql_SOURCES += ../libmdb/fakeglib.c mdb_ver_SOURCES += ../libmdb/fakeglib.c mdb_import_SOURCES += ../libmdb/fakeglib.c +updrow_SOURCES += ../libmdb/fakeglib.c endif LIBS = $(GLIB_LIBS) @LIBS@ DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\" From b8181fa65f5b5f102a7b1c0bf29a70d20665119a Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 10:08:11 -0400 Subject: [PATCH 20/30] Add -Wno-conflicts-sr to yacc flags --- configure.ac | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a5f7254..e5aa945 100644 --- a/configure.ac +++ b/configure.ac @@ -46,7 +46,11 @@ AC_MSG_RESULT( no - SQL engine disable); sql=false fi -if ! $YACC -V >/dev/null 2>&1; then +if $YACC -V >/dev/null 2>&1; then + if $YACC -Wno-conflicts-sr -V >/dev/null 2>&1; then + YFLAGS="$YFLAGS -Wno-conflicts-sr" + fi +else sql=false fi From 18de0070af255ba420ddc70f94307f449d962eaf Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 20:36:20 -0400 Subject: [PATCH 21/30] New --disable-glib configure option This option uses the fake GLib shim even when GLib is present on the system. --- .travis.yml | 2 +- configure.ac | 19 +++++++++++++++---- include/Makefile.am | 2 +- src/libmdb/Makefile.am | 2 +- src/sql/Makefile.am | 2 +- src/util/Makefile.am | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2216bb7..3a9553f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: - autoreconf -i -f -Wno-portability script: - - ./configure --disable-man --disable-silent-rules + - ./configure --disable-man --disable-silent-rules --disable-glib - make - ./src/util/mdb-array test/data/ASampleDatabase.accdb "Asset Items" - ./src/util/mdb-array test/data/nwind.mdb "Customers" diff --git a/configure.ac b/configure.ac index e5aa945..3a54164 100644 --- a/configure.ac +++ b/configure.ac @@ -152,13 +152,22 @@ pkg-config is required. See pkg-config.freedesktop.org]) fi +dnl See if GLib is present and wanted +AC_ARG_ENABLE(glib, + AS_HELP_STRING([--disable-glib], [do not link with GLib]), + [enable_glib=$enableval], [enable_glib=yes]) -dnl check for glib/gtk/gnome -PKG_CHECK_MODULES([GLIB], [glib-2.0], AM_CONDITIONAL([HAVE_GLIB], true), AM_CONDITIONAL([HAVE_GLIB], false)) -if test "x$HAVE_GLIB" = "xtrue"; then - GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1" +if test "$enable_glib" = "yes"; then + PKG_CHECK_MODULES([GLIB], [glib-2.0], HAVE_GLIB=true, HAVE_GLIB=false) + if test "x$HAVE_GLIB" = "xtrue"; then + GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1" + else + enable_glib=no + fi fi +AM_CONDITIONAL(FAKE_GLIB, test "x$enable_glib" != "xyes") +dnl check for gtk/gnome PKG_CHECK_MODULES([GNOME], [gtk+-2.0 >= 2.14 libglade-2.0 libgnomeui-2.0], HAVE_GNOME=true, HAVE_GNOME=false) GNOME_DOC_INIT @@ -282,6 +291,8 @@ if test x$sql = xtrue; then summary=${bold_green}enabled; else summary=${bold_re AC_MSG_NOTICE([ SQL : ${summary}${reset}]) if test x$HAVE_ODBC = xtrue; then summary=${bold_green}enabled; else summary=${bold_red}disabled; fi AC_MSG_NOTICE([ ODBC : ${summary}${reset}]) +if test x$enable_glib = xyes; then summary=${bold_green}enabled; else summary=${bold_red}disabled; fi +AC_MSG_NOTICE([ GLib : ${summary}${reset}]) if test x$build_gmdb2 = xyes; then summary=${bold_green}enabled; else summary=${bold_red}disabled; fi AC_MSG_NOTICE([ UI : ${summary}${reset}]) if test x$enable_gtk_doc = xyes; then summary=${bold_green}enabled; else summary=${bold_red}disabled; fi diff --git a/include/Makefile.am b/include/Makefile.am index c19d930..bc5aa3f 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,5 +1,5 @@ include_HEADERS = mdbtools.h mdbsql.h mdbver.h -if !HAVE_GLIB +if FAKE_GLIB include_HEADERS += mdbfakeglib.h endif noinst_HEADERS = mdbprivate.h diff --git a/src/libmdb/Makefile.am b/src/libmdb/Makefile.am index aa3742e..2e74a19 100644 --- a/src/libmdb/Makefile.am +++ b/src/libmdb/Makefile.am @@ -1,6 +1,6 @@ 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 +if FAKE_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$$)' diff --git a/src/sql/Makefile.am b/src/sql/Makefile.am index 7a353f2..5c2a7a7 100644 --- a/src/sql/Makefile.am +++ b/src/sql/Makefile.am @@ -3,7 +3,7 @@ BUILT_SOURCES = parser.h AM_YFLAGS = -d lib_LTLIBRARIES = libmdbsql.la libmdbsql_la_SOURCES= mdbsql.c parser.y lexer.l -if !HAVE_GLIB +if FAKE_GLIB libmdbsql_la_SOURCES += ../libmdb/fakeglib.c endif libmdbsql_la_LDFLAGS = -version-info 2:0:0 -export-symbols-regex '^mdb_sql_' diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 470e6c5..a03c75b 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -9,7 +9,7 @@ mdb_sql_SOURCES = mdb-sql.c mdb_ver_SOURCES = mdb-ver.c mdb_import_SOURCES = mdb-import.c updrow_SOURCES = updrow.c -if !HAVE_GLIB +if FAKE_GLIB mdb_export_SOURCES += ../libmdb/fakeglib.c mdb_schema_SOURCES += ../libmdb/fakeglib.c mdb_tables_SOURCES += ../libmdb/fakeglib.c From fe28ce8d259eebdcb4e0b0b548ee7f9d65ee368b Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:07:13 -0400 Subject: [PATCH 22/30] Fix vasprintf warning with GCC --- src/libmdb/fakeglib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index f0f51f8..d980cf9 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -1,6 +1,7 @@ #include "mdbfakeglib.h" +#define _GNU_SOURCE /* vasprintf */ #include #include #include From 783304c164708a1a8b0c03eb528eaefc7b847e20 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:07:48 -0400 Subject: [PATCH 23/30] Turn on -Werror --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3a54164..5605ecc 100644 --- a/configure.ac +++ b/configure.ac @@ -65,7 +65,7 @@ AM_CONDITIONAL(SQL, test x$sql = xtrue) AC_SUBST(SQL) AC_SUBST(LFLAGS) -CFLAGS="$CFLAGS -Wall -Wstrict-prototypes" +CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Werror" AS_CASE([$host], [*mingw*|*cygwin*], [LDFLAGS="$LDFLAGS -no-undefined"], []) AS_CASE([$host], From 514b74744b0283faadeafe3f9082c99298c70205 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:17:22 -0400 Subject: [PATCH 24/30] Try fixing Linux warnings --- include/mdbfakeglib.h | 4 ++-- src/libmdb/fakeglib.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/mdbfakeglib.h b/include/mdbfakeglib.h index 2b5766d..1fbc683 100644 --- a/include/mdbfakeglib.h +++ b/include/mdbfakeglib.h @@ -1,5 +1,5 @@ -#ifndef _glib_shim_h_ -#define _glib_shim_h_ +#ifndef _mdbfakeglib_h_ +#define _mdbfakeglib_h_ #include #include diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index d980cf9..0d3e6d1 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -1,13 +1,14 @@ +#define _GNU_SOURCE #include "mdbfakeglib.h" -#define _GNU_SOURCE /* vasprintf */ #include #include #include #include #include #include +#include /* string functions */ From 04b736c9ff8f73d2c55625b861375c1c0b1849dc Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:22:08 -0400 Subject: [PATCH 25/30] Fix indentation warnings --- src/libmdb/data.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libmdb/data.c b/src/libmdb/data.c index 883294c..2b14d59 100644 --- a/src/libmdb/data.c +++ b/src/libmdb/data.c @@ -140,9 +140,9 @@ int mdb_find_row(MdbHandle *mdb, int row, int *start, size_t *len) mdb_get_int16(mdb->pg_buf, rco + row*2) & OFFSET_MASK; *len = next_start - (*start & OFFSET_MASK); - if ((*start & OFFSET_MASK) >= mdb->fmt->pg_size || - next_start > mdb->fmt->pg_size) - return -1; + if ((*start & OFFSET_MASK) >= mdb->fmt->pg_size || + next_start > mdb->fmt->pg_size) + return -1; return 0; } @@ -304,8 +304,8 @@ int mdb_read_row(MdbTableDef *table, unsigned int row) num_fields = mdb_crack_row(table, row_start, row_start + row_size - 1, fields); - if (num_fields < 0) - return 0; + if (num_fields < 0) + return 0; if (!mdb_test_sargs(table, fields, num_fields)) return 0; #if MDB_DEBUG From 8bacbf1678cd2e834d3bb19b7ec4d36eae04d94f Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:27:19 -0400 Subject: [PATCH 26/30] Fix unused result warning --- src/libmdb/fakeglib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 0d3e6d1..6a14d2d 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -118,7 +118,7 @@ char *g_strdup_printf(const char *format, ...) { size_t len = 0; ret = vasnprintf(ret, &len, format, argp); #else - vasprintf(&ret, format, argp); + (void)vasprintf(&ret, format, argp); #endif va_end(argp); From 7c324a9cb49338cca6fd093cc70d2ba291666e76 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:48:49 -0400 Subject: [PATCH 27/30] Fix warnings --- configure.ac | 1 + src/libmdb/fakeglib.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 5605ecc..fdf6a8c 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,7 @@ AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h limits.h unistd.h) AC_CHECK_HEADERS(wordexp.h) AC_CHECK_LIB(mswstr, DBLCMapStringW) +AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include ]]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index 6a14d2d..e0e3399 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -10,6 +10,10 @@ #include #include +#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME +extern char *program_invocation_short_name; +#endif + /* string functions */ void *g_memdup(const void *src, size_t len) { @@ -118,7 +122,8 @@ char *g_strdup_printf(const char *format, ...) { size_t len = 0; ret = vasnprintf(ret, &len, format, argp); #else - (void)vasprintf(&ret, format, argp); + int gcc_is_dumb = vasprintf(&ret, format, argp); + (void)gcc_is_dumb; #endif va_end(argp); @@ -281,8 +286,8 @@ gchar *g_option_context_get_help (GOptionContext *context, gboolean main_help, void *group) { #if defined(__APPLE__) || defined(__FreeBSD__) const char * appname = getprogname(); -#elif defined(_GNU_SOURCE) - const char * appname = program_invocation_name; +#elif HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + const char * appname = program_invocation_short_name; #else const char * appname = "mdb-util"; #endif From 0b6809be82246a635ff17f858b29bf944d353657 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:54:25 -0400 Subject: [PATCH 28/30] Fix program_invocation_short_name on Linux --- configure.ac | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index fdf6a8c..a82e721 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,9 @@ AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h limits.h unistd.h) AC_CHECK_HEADERS(wordexp.h) AC_CHECK_LIB(mswstr, DBLCMapStringW) -AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include ]]) +AC_CHECK_DECLS([program_invocation_short_name], [], [], [[ + #define _GNU_SOURCE + #include ]]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST From d0d30602236f7160360c740290c0906906a7f259 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Wed, 5 Aug 2020 23:59:58 -0400 Subject: [PATCH 29/30] Fix program_invocation_short_name on Cygwin --- src/libmdb/fakeglib.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libmdb/fakeglib.c b/src/libmdb/fakeglib.c index e0e3399..8d7ba35 100644 --- a/src/libmdb/fakeglib.c +++ b/src/libmdb/fakeglib.c @@ -10,10 +10,6 @@ #include #include -#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME -extern char *program_invocation_short_name; -#endif - /* string functions */ void *g_memdup(const void *src, size_t len) { From 2117195fac5904ed16987a1a3baed81cdcde8ec4 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Thu, 6 Aug 2020 12:51:45 -0400 Subject: [PATCH 30/30] Update README --- README.md | 90 ++++++++++++++++--------------------------------------- 1 file changed, 26 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 65a9a22..616e8d7 100644 --- a/README.md +++ b/README.md @@ -51,69 +51,24 @@ Builds on libmdb to provide a SQL engine (aka Jet) Provids command line utilities, including: -### mdb-ver - -Prints the version (JET 3 or 4) of an mdb file. - -### mdb-schema - -Prints DDL for the specified table. - -### mdb-export - -Export table to CSV format. - -### mdb-tables - -A simple dump of table names to be used with shell scripts. - -### mdb-count - -A simple count of number of rows in a table, to be used in shell scripts and ETL pipelines. - -### mdb-header - -Generates a C header to be used in exporting mdb data to a C prog. - -### mdb-parsecsv - -Generates a C program given a CSV file made with mdb-export. - -### mdb-sql - -A simple SQL engine (also used by ODBC and gmdb). - -### prcat - -Prints the catalog table from an mdb file. - -### prkkd - -Dump of information about design view data given the offset to it. - -### prtable - -Dump of a table definition. - -### prdata - -Dump of the data given a table name. - -### prole - -Dump of ole columns given a table name and sargs. - -## odbc - -An ODBC driver for use with unixODBC or iODBC driver manager. Allows one to use MDB files with PHP for example. - -## gmdb2 - -The Gnome MDB File Viewer and debugger. Still alpha, but making great progress. - -## src/extras/mdb-hexdump - -Simple hex dump utility that I've been using to look at mdb files. +| Command | Description | +| ------- | ----------- | +| mdb-ver | Prints the version (JET 3 or 4) of an mdb file. | +| mdb-schema | Prints DDL for the specified table. | +| mdb-export | Export table to CSV format. | +| mdb-tables | A simple dump of table names to be used with shell scripts. | +| mdb-count | A simple count of number of rows in a table, to be used in shell scripts and ETL pipelines. | +| mdb-header | Generates a C header to be used in exporting mdb data to a C prog. | +| mdb-parsecsv | Generates a C program given a CSV file made with mdb-export. | +| mdb-sql | A simple SQL engine (also used by ODBC and gmdb). | +| prcat | Prints the catalog table from an mdb file. | +| prkkd | Dump of information about design view data given the offset to it. | +| prtable | Dump of a table definition. | +| prdata | Dump of the data given a table name. | +| prole | Dump of ole columns given a table name and sargs. | +| odbc | An ODBC driver for use with unixODBC or iODBC driver manager. Allows one to use MDB files with PHP for example. | +| gmdb2 | The Gnome MDB File Viewer and debugger. Still alpha. | +| mdb-hexdump | (in src/extras) Simple hex dump utility that I've been using to look at mdb files. | # License @@ -150,7 +105,7 @@ If you want to generate the html version of the docbook, you'll need Last version is available at https://github.com/evanmiller/mdbtools ```bash -$ autoreconf -i -f +$ autoreconf -i -f -Wno-portability ``` If you want to build the html version of the docbook documentation, you need to @@ -169,6 +124,13 @@ OR for a complete install (requires bison, flex, and unixODBC): $ ./configure --with-unixodbc=/usr/local ``` +By default, MDB Tools is linked against the copy of +[GLib](https://developer.gnome.org/glib/) returned by pkg-config. You can +point to a different GLib installation using the `GLIB_CFLAGS` and `GLIB_LIBS` +enivornment variables. Or, you can disable GLib entirely with the +`--disable-glib` flag, in which case MDB Tools will use an internal +implementation of GLib's functions. + configure can be passed any of the following flags to turn on other capabilities. Note that the options `--with-unixodbc` and `--with-iodbc` are mutually exclusive.