From 9322b2315cdd3e9eb336da4ea116fa21a50765c2 Mon Sep 17 00:00:00 2001 From: Alnotz Date: Sun, 23 Jul 2023 19:27:19 +0200 Subject: [PATCH] Better plugin organization --- weechat-plugins/essai/Makefile | 27 ++++++++++ weechat-plugins/essai/build.sh | 5 ++ weechat-plugins/essai/essai.c | 43 ---------------- weechat-plugins/essai/src/essai-command.c | 63 +++++++++++++++++++++++ weechat-plugins/essai/src/essai-command.h | 6 +++ weechat-plugins/essai/src/essai.c | 47 +++++++++++++++++ weechat-plugins/essai/src/essai.h | 15 ++++++ 7 files changed, 163 insertions(+), 43 deletions(-) create mode 100644 weechat-plugins/essai/Makefile create mode 100644 weechat-plugins/essai/build.sh delete mode 100644 weechat-plugins/essai/essai.c create mode 100644 weechat-plugins/essai/src/essai-command.c create mode 100644 weechat-plugins/essai/src/essai-command.h create mode 100644 weechat-plugins/essai/src/essai.c create mode 100644 weechat-plugins/essai/src/essai.h diff --git a/weechat-plugins/essai/Makefile b/weechat-plugins/essai/Makefile new file mode 100644 index 0000000..e84077b --- /dev/null +++ b/weechat-plugins/essai/Makefile @@ -0,0 +1,27 @@ +# essai Makefile v4.3 + +WEECHAT_HEADER := /usr/include/weechat/weechat-plugin.h +PLUGIN =: ${XDG_DATA_HOME}/weechat/plugins/ +GCCFLAGS := $(pkg-config --cflags weechat) -fPIC -Wall -Wextra +LIBFLAGS := -shared +GCCLIBS := $(pkg-config --libs weechat) + +help : + @echo 'Pas d’aide.' + +build : essai.o essai-command.o + if [ ! -d lib ] ; then mkdir lib ; fi + gcc $(LIBFLAGS) $(GCCFLAGS) obj/essai.o obj/essai-command.o \ + -o lib/essai.so $(GCCLIBS) + +essai.o : essai.c essai.h essai-command.h $(WEECHAT_HEADER) + if [ ! -d obj ] ; then mkdir obj ; fi + gcc $(GCCFLAGS) -c essai.c -o obj/essai.o $(GCCLIBS) + +essai-command.o : essai-command.c essai.h essai-command.h $(WEECHAT_HEADER) + if [ ! -d obj ] ; then mkdir obj ; fi + gcc $(GCCFLAGS) -c essai-command.c -o obj/essai-command.o $(GCCLIBS) + +clean : + rm -r obj + rm -r lib diff --git a/weechat-plugins/essai/build.sh b/weechat-plugins/essai/build.sh new file mode 100644 index 0000000..12064a6 --- /dev/null +++ b/weechat-plugins/essai/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +gcc $(pkg-config --cflags weechat) \ + -shared -fPIC -Wall -Wextra src/essai.c src/essai-command.c -o lib/essai.so \ + $(pkg-config --libs weechat) && \ +mv -v lib/essai.so ${XDG_DATA_HOME}/weechat/plugins/ diff --git a/weechat-plugins/essai/essai.c b/weechat-plugins/essai/essai.c deleted file mode 100644 index fe458a3..0000000 --- a/weechat-plugins/essai/essai.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -gcc \$(pkg-config --cflags weechat) -shared -fPIC -Wall -Wextra essai.c -o essai.so $(pkg-config --libs weechat) -*/ -#include -#include - -WEECHAT_PLUGIN_NAME("essai"); -WEECHAT_PLUGIN_DESCRIPTION("Plugin just to test the library :-/"); -WEECHAT_PLUGIN_AUTHOR("Alnotz"); -WEECHAT_PLUGIN_VERSION("0.1.0"); -WEECHAT_PLUGIN_LICENSE("GPL-3.0-or-later"); -WEECHAT_PLUGIN_PRIORITY(999); - -struct t_weechat_plugin *weechat_plugin = NULL; - -int command_essai(const void *pointer, - void *data, - struct t_gui_buffer *buffer, - int argc, - char **argv, - char **argv_eol){ - /*Rien*/ - return WEECHAT_RC_OK; -} - -int weechat_plugin_init(struct t_weechat_plugin *plugin, - int argc, - char *argv[]){ - weechat_plugin = plugin; - weechat_hook_command("essai", - "Une commande d’essai", - "", - "Aucun paramètre", - NULL, - &command_essai, - NULL, - NULL); - return WEECHAT_RC_OK; -} - -int weechat_plugin_end(struct t_weechat_plugin *plugins){ - return WEECHAT_RC_OK; -} diff --git a/weechat-plugins/essai/src/essai-command.c b/weechat-plugins/essai/src/essai-command.c new file mode 100644 index 0000000..1fd1532 --- /dev/null +++ b/weechat-plugins/essai/src/essai-command.c @@ -0,0 +1,63 @@ +#include +#include +#include "essai.h" +#include "essai-command.h" + +int essai_command(const void *pointer, + void *data, + struct t_gui_buffer *buffer, + int argc, + char **argv, + char **argv_eol){ + int weechat_rc; + + if(weechat_buffer_match_list(buffer, + "core.weechat")){ + weechat_printf(NULL, + "Nombre d’arguments : %s%d%s\n" + "Commande 0 : %s%s%s\n" + "Commande 0 (fin de ligne) : %s%s%s", + weechat_color("blue"), + argc, + weechat_color("reset"), + weechat_color("green"), + argv[0], + weechat_color("reset"), + weechat_color("green"), + argv_eol[0], + weechat_color("reset")); + for(int i=1; i +#include +#include "essai.h" +#include "essai-command.h" + +WEECHAT_PLUGIN_NAME(ESSAI_PLUGIN_NAME); +WEECHAT_PLUGIN_DESCRIPTION(ESSAI_PLUGIN_DESCRIPTION); +WEECHAT_PLUGIN_AUTHOR(ESSAI_PLUGIN_AUTHOR); +WEECHAT_PLUGIN_VERSION(ESSAI_PLUGIN_VERSION); +WEECHAT_PLUGIN_LICENSE(ESSAI_PLUGIN_LICENCE); +WEECHAT_PLUGIN_PRIORITY(ESSAI_PLUGIN_PRIORITY); + +struct t_weechat_plugin *weechat_plugin = NULL; + +int weechat_plugin_init(struct t_weechat_plugin *plugin, + int argc, + char *argv[]){ + weechat_plugin = plugin; + + essai_command_init(); + + weechat_printf(NULL, + "%sGreffon %sessai%s connecté!%s", + weechat_color("green"), + weechat_color("/green"), + weechat_color("green"), + weechat_color("reset")); + + return WEECHAT_RC_OK; +} + +int weechat_plugin_end(struct t_weechat_plugin *plugin){ + weechat_printf(NULL, + "%sGreffon %sessai%s déconnecté!%s", + weechat_color("red"), + weechat_color("/red"), + weechat_color("red"), + weechat_color("reset")); + + return WEECHAT_RC_OK; +} + diff --git a/weechat-plugins/essai/src/essai.h b/weechat-plugins/essai/src/essai.h new file mode 100644 index 0000000..9a1fc0c --- /dev/null +++ b/weechat-plugins/essai/src/essai.h @@ -0,0 +1,15 @@ +#ifndef ESSAI_H +#define ESSAI_H + +#define weechat_plugin essai_plugin + +#define ESSAI_PLUGIN_NAME "essai" +#define ESSAI_PLUGIN_DESCRIPTION "Plugin just to test the library :-/" +#define ESSAI_PLUGIN_AUTHOR "Alnotz" +#define ESSAI_PLUGIN_VERSION "0.1.0" +#define ESSAI_PLUGIN_LICENCE "GPL-3.0-or-later" +#define ESSAI_PLUGIN_PRIORITY 999 + +extern struct t_weechat_plugin *essai_plugin; + +#endif//ESSAI_H