diff options
-rw-r--r-- | src/plugins/api.c | 130 | ||||
-rw-r--r-- | src/plugins/api.h | 16 | ||||
-rw-r--r-- | src/plugins/c_api.c | 36 | ||||
-rw-r--r-- | src/plugins/c_plugins.c | 2 | ||||
-rw-r--r-- | src/plugins/profapi.c | 16 | ||||
-rw-r--r-- | src/plugins/profapi.h | 16 |
6 files changed, 157 insertions, 59 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c index 8db53091..9855165f 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -53,22 +53,32 @@ api_cons_alert(void) cons_alert(); } -void +int api_cons_show(const char * const message) { - if (message) { - char *parsed = str_replace(message, "\r\n", "\n"); - cons_show("%s", parsed); - free(parsed); + if (message == NULL) { + log_warning("%s", "prof_cons_show failed, message is NULL"); + return 0; } + + char *parsed = str_replace(message, "\r\n", "\n"); + cons_show("%s", parsed); + free(parsed); + + return 1; } -void +int api_cons_bad_cmd_usage(const char *const cmd) { - if (cmd) { - cons_bad_cmd_usage(cmd); + if (cmd == NULL) { + log_warning("%s", "prof_cons_bad_cmd_usage failed, cmd is NULL"); + return 0; } + + cons_bad_cmd_usage(cmd); + + return 1; } void @@ -213,49 +223,141 @@ api_win_create(const char *tag, void *callback, status_bar_active(num); } -void +int api_win_focus(const char *tag) { + if (tag == NULL) { + log_warning("%s", "prof_win_focus failed, tag is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_focus failed, no window with tag: %s", tag); + return 0; + } + ui_focus_win((ProfWin*)pluginwin); + + return 1; } -void +int api_win_show(const char *tag, const char *line) { + if (tag == NULL) { + log_warning("%s", "prof_win_show failed, tag is NULL"); + return 0; + } + if (line == NULL) { + log_warning("%s", "prof_win_show failed, line is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_show failed, no window with tag: %s", tag); + return 0; + } + ProfWin *window = (ProfWin*)pluginwin; win_print(window, '!', 0, NULL, 0, 0, "", line); + + return 1; } -void +int api_win_show_green(const char *tag, const char *line) { + if (tag == NULL) { + log_warning("%s", "prof_win_show_green failed, tag is NULL"); + return 0; + } + if (line == NULL) { + log_warning("%s", "prof_win_show_green failed, line is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_show_green failed, no window with tag: %s", tag); + return 0; + } + ProfWin *window = (ProfWin*)pluginwin; win_print(window, '!', 0, NULL, 0, THEME_GREEN, "", line); + + return 1; } -void +int api_win_show_red(const char *tag, const char *line) { + if (tag == NULL) { + log_warning("%s", "prof_win_show_red failed, tag is NULL"); + return 0; + } + if (line == NULL) { + log_warning("%s", "prof_win_show_red failed, line is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_show_red failed, no window with tag: %s", tag); + return 0; + } + ProfWin *window = (ProfWin*)pluginwin; win_print(window, '!', 0, NULL, 0, THEME_RED, "", line); + + return 1; } -void +int api_win_show_cyan(const char *tag, const char *line) { + if (tag == NULL) { + log_warning("%s", "prof_win_show_cyan failed, tag is NULL"); + return 0; + } + if (line == NULL) { + log_warning("%s", "prof_win_show_cyan failed, line is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_show_cyan failed, no window with tag: %s", tag); + return 0; + } + ProfWin *window = (ProfWin*)pluginwin; win_print(window, '!', 0, NULL, 0, THEME_CYAN, "", line); + + return 1; } -void +int api_win_show_yellow(const char *tag, const char *line) { + if (tag == NULL) { + log_warning("%s", "prof_win_show_yellow failed, tag is NULL"); + return 0; + } + if (line == NULL) { + log_warning("%s", "prof_win_show_yellow failed, line is NULL"); + return 0; + } + ProfPluginWin *pluginwin = wins_get_plugin(tag); + if (pluginwin == NULL) { + log_warning("prof_win_show_yellow failed, no window with tag: %s", tag); + return 0; + } + ProfWin *window = (ProfWin*)pluginwin; win_print(window, '!', 0, NULL, 0, THEME_YELLOW, "", line); + + return 1; } diff --git a/src/plugins/api.h b/src/plugins/api.h index b156c7e6..baf7c132 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -38,8 +38,8 @@ #include "plugins/callbacks.h" void api_cons_alert(void); -void api_cons_show(const char * const message); -void api_cons_bad_cmd_usage(const char *const cmd); +int api_cons_show(const char * const message); +int api_cons_bad_cmd_usage(const char *const cmd); void api_notify(const char *message, const char *category, int timeout_ms); void api_send_line(char *line); char * api_get_current_recipient(void); @@ -60,11 +60,11 @@ void api_log_error(const char *message); int api_win_exists(const char *tag); void api_win_create(const char *tag, void *callback, void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line)); -void api_win_focus(const char *tag); -void api_win_show(const char *tag, const char *line); -void api_win_show_green(const char *tag, const char *line); -void api_win_show_red(const char *tag, const char *line); -void api_win_show_cyan(const char *tag, const char *line); -void api_win_show_yellow(const char *tag, const char *line); +int api_win_focus(const char *tag); +int api_win_show(const char *tag, const char *line); +int api_win_show_green(const char *tag, const char *line); +int api_win_show_red(const char *tag, const char *line); +int api_win_show_cyan(const char *tag, const char *line); +int api_win_show_yellow(const char *tag, const char *line); #endif diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index c058645e..c4b24561 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -59,20 +59,16 @@ c_api_cons_alert(void) api_cons_alert(); } -static void +static int c_api_cons_show(const char * const message) { - if (message) { - api_cons_show(message); - } + return api_cons_show(message); } -static void +static int c_api_cons_bad_cmd_usage(const char *const cmd) { - if (cmd) { - api_cons_bad_cmd_usage(cmd); - } + return api_cons_bad_cmd_usage(cmd); } static void @@ -162,40 +158,40 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line)) api_win_create(tag, wrapper, c_window_callback); } -void +int c_api_win_focus(char *tag) { - api_win_focus(tag); + return api_win_focus(tag); } -void +int c_api_win_show(char *tag, char *line) { - api_win_show(tag, line); + return api_win_show(tag, line); } -void +int c_api_win_show_green(char *tag, char *line) { - api_win_show_green(tag, line); + return api_win_show_green(tag, line); } -void +int c_api_win_show_red(char *tag, char *line) { - api_win_show_red(tag, line); + return api_win_show_red(tag, line); } -void +int c_api_win_show_cyan(char *tag, char *line) { - api_win_show_cyan(tag, line); + return api_win_show_cyan(tag, line); } -void +int c_api_win_show_yellow(char *tag, char *line) { - api_win_show_yellow(tag, line); + return api_win_show_yellow(tag, line); } void diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index dcf2a0ff..fbced688 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -69,7 +69,7 @@ c_plugin_create(const char * const filename) handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL); if (!handle) { - log_warning ("dlopen failed to open `%s', %s", filename, dlerror ()); + log_warning("dlopen failed to open `%s', %s", filename, dlerror ()); g_string_free(path, TRUE); return NULL; } diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index a787a7a5..b8046373 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -38,8 +38,8 @@ #include "plugins/callbacks.h" void (*prof_cons_alert)(void) = NULL; -void (*prof_cons_show)(const char * const message) = NULL; -void (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL; +int (*prof_cons_show)(const char * const message) = NULL; +int (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL; void (*prof_register_command)(const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, @@ -63,9 +63,9 @@ void (*prof_log_error)(const char *message) = NULL; int (*prof_win_exists)(PROF_WIN_TAG win) = NULL; void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line)) = NULL; -void (*prof_win_focus)(PROF_WIN_TAG win) = NULL; -void (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL; -void (*prof_win_show_green)(PROF_WIN_TAG win, char *line) = NULL; -void (*prof_win_show_red)(PROF_WIN_TAG win, char *line) = NULL; -void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line) = NULL; -void (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line) = NULL; +int (*prof_win_focus)(PROF_WIN_TAG win) = NULL; +int (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL; +int (*prof_win_show_green)(PROF_WIN_TAG win, char *line) = NULL; +int (*prof_win_show_red)(PROF_WIN_TAG win, char *line) = NULL; +int (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line) = NULL; +int (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index b7a5305d..834a7210 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -38,8 +38,8 @@ typedef char* PROF_WIN_TAG; void (*prof_cons_alert)(void); -void (*prof_cons_show)(const char * const message); -void (*prof_cons_bad_cmd_usage)(const char *const cmd); +int (*prof_cons_show)(const char * const message); +int (*prof_cons_bad_cmd_usage)(const char *const cmd); void (*prof_register_command)(const char *command_name, int min_args, int max_args, const char **synopsis, const char *description, const char *arguments[][2], const char **examples, @@ -63,11 +63,11 @@ void (*prof_log_error)(const char *message); int (*prof_win_exists)(PROF_WIN_TAG win); void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line)); -void (*prof_win_focus)(PROF_WIN_TAG win); -void (*prof_win_show)(PROF_WIN_TAG win, char *line); -void (*prof_win_show_green)(PROF_WIN_TAG win, char *line); -void (*prof_win_show_red)(PROF_WIN_TAG win, char *line); -void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line); -void (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line); +int (*prof_win_focus)(PROF_WIN_TAG win); +int (*prof_win_show)(PROF_WIN_TAG win, char *line); +int (*prof_win_show_green)(PROF_WIN_TAG win, char *line); +int (*prof_win_show_red)(PROF_WIN_TAG win, char *line); +int (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line); +int (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line); #endif |