mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
Implement g_option_context_get_help (fake GLib)
This fixes the crashing issues, but the command-line tools are still useless.
This commit is contained in:
parent
cb7b694d4b
commit
fa01a6fe27
@ -16,6 +16,7 @@ typedef unsigned int guint;
|
|||||||
typedef void * gpointer;
|
typedef void * gpointer;
|
||||||
typedef const void * gconstpointer;
|
typedef const void * gconstpointer;
|
||||||
typedef uint8_t guint8;
|
typedef uint8_t guint8;
|
||||||
|
typedef guint32 GQuark;
|
||||||
|
|
||||||
typedef guint (*GHashFunc)(gconstpointer);
|
typedef guint (*GHashFunc)(gconstpointer);
|
||||||
typedef int (*GCompareFunc)(gconstpointer, gconstpointer);
|
typedef int (*GCompareFunc)(gconstpointer, gconstpointer);
|
||||||
@ -41,7 +42,9 @@ typedef struct GHashTable {
|
|||||||
} GHashTable;
|
} GHashTable;
|
||||||
|
|
||||||
typedef struct GError {
|
typedef struct GError {
|
||||||
const char *message;
|
GQuark domain;
|
||||||
|
gint code;
|
||||||
|
gchar *message;
|
||||||
} GError;
|
} GError;
|
||||||
|
|
||||||
typedef enum GOptionArg {
|
typedef enum GOptionArg {
|
||||||
|
@ -242,8 +242,39 @@ void g_option_context_add_main_entries (GOptionContext *context,
|
|||||||
|
|
||||||
gchar *g_option_context_get_help (GOptionContext *context,
|
gchar *g_option_context_get_help (GOptionContext *context,
|
||||||
gboolean main_help, void *group) {
|
gboolean main_help, void *group) {
|
||||||
/* TODO */
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
return NULL;
|
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) {
|
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,
|
gboolean g_option_context_parse(GOptionContext *context,
|
||||||
gint *argc, gchar ***argv, GError **error) {
|
gint *argc, gchar ***argv, GError **error) {
|
||||||
|
*error = malloc(sizeof(GError));
|
||||||
|
(*error)->message = "Not implemented";
|
||||||
/* TODO */
|
/* TODO */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user