Added new help format to c plugins WIP

This commit is contained in:
James Booth
2016-02-18 01:20:17 +00:00
parent 2ac911618a
commit a14b7815ae
12 changed files with 108 additions and 15 deletions

View File

@@ -65,19 +65,39 @@ api_cons_show(const char * const message)
void
api_register_command(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void *callback,
const char **synopsis, const char *description, const char *arguments[][2], const char **examples, void *callback,
void(*callback_func)(PluginCommand *command, gchar **args))
{
PluginCommand *command = malloc(sizeof(PluginCommand));
command->command_name = command_name;
command->min_args = min_args;
command->max_args = max_args;
command->usage = usage;
command->short_help = short_help;
command->long_help = long_help;
command->callback = callback;
command->callback_func = callback_func;
CommandHelp *help = malloc(sizeof(CommandHelp));
int i = 0;
for (i = 0; synopsis[i] != NULL; i++) {
help->synopsis[i] = strdup(synopsis[i]);
}
help->synopsis[i] = NULL;
help->desc = strdup(description);
for (i = 0; arguments[i][0] != NULL; i++) {
help->args[i][0] = strdup(arguments[i][0]);
help->args[i][1] = strdup(arguments[i][1]);
}
help->args[i][0] = NULL;
help->args[i][1] = NULL;
for (i = 0; examples[i] != NULL; i++) {
help->examples[i] = strdup(examples[i]);
}
help->examples[i] = NULL;
command->help = help;
callbacks_add_command(command);
}

View File

@@ -45,7 +45,7 @@ char * api_get_current_recipient(void);
char * api_get_current_muc(void);
void api_register_command(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help,
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void *callback, void(*callback_func)(PluginCommand *command, gchar **args));
void api_register_timed(void *callback, int interval_seconds,
void (*callback_func)(PluginTimedFunction *timed_function));

View File

@@ -69,12 +69,13 @@ c_api_cons_show(const char * const message)
static void
c_api_register_command(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args))
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void(*callback)(char **args))
{
CommandWrapper *wrapper = malloc(sizeof(CommandWrapper));
wrapper->func = callback;
api_register_command(command_name, min_args, max_args, usage,
short_help, long_help, wrapper, c_command_callback);
api_register_command(command_name, min_args, max_args, synopsis,
description, arguments, examples, wrapper, c_command_callback);
}
static void

View File

@@ -91,7 +91,7 @@ plugins_run_command(const char * const input)
gboolean result;
gchar **args = parse_args(input, command->min_args, command->max_args, &result);
if (result == FALSE) {
ui_invalid_command_usage(command->usage, NULL);
ui_invalid_command_usage(command->command_name, NULL);
g_strfreev(split);
return TRUE;
} else {
@@ -107,6 +107,22 @@ plugins_run_command(const char * const input)
return FALSE;
}
CommandHelp*
plugins_get_help(const char *const cmd)
{
GSList *curr = p_commands;
while (curr) {
PluginCommand *command = curr->data;
if (g_strcmp0(cmd, command->command_name) == 0) {
return command->help;
}
curr = g_slist_next(curr);
}
return NULL;
}
void
plugins_run_timed(void)
{

View File

@@ -37,13 +37,13 @@
#include <glib.h>
#include "command/command.h"
typedef struct p_command {
const char *command_name;
int min_args;
int max_args;
const char *usage;
const char *short_help;
const char *long_help;
CommandHelp *help;
void *callback;
void (*callback_func)(struct p_command *command, gchar **args);
} PluginCommand;

View File

@@ -35,6 +35,8 @@
#ifndef PLUGINS_H
#define PLUGINS_H
#include "command/command.h"
typedef enum {
LANG_C
} lang_t;
@@ -100,6 +102,7 @@ void plugins_post_priv_message_send(const char * const jid, const char * const
gboolean plugins_run_command(const char * const cmd);
void plugins_run_timed(void);
gchar * plugins_get_dir(void);
CommandHelp* plugins_get_help(const char *const cmd);
void plugins_win_process_line(char *win, const char * const line);
#endif

View File

@@ -42,7 +42,8 @@ void (*prof_cons_alert)(void) = NULL;
void (*prof_cons_show)(const char * const message) = NULL;
void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args)) = NULL;
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void(*callback)(char **args)) = NULL;
void (*prof_register_timed)(void(*callback)(void), int interval_seconds) = NULL;

View File

@@ -42,7 +42,8 @@ void (*prof_cons_alert)(void);
void (*prof_cons_show)(const char * const message);
void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args));
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void(*callback)(char **args));
void (*prof_register_timed)(void(*callback)(void), int interval_seconds);