Better plugin organization

This commit is contained in:
F. Y. H. 2023-07-23 19:27:19 +02:00
parent 4f8393cd12
commit 9322b2315c
Signed by: Alnotz
GPG key ID: B808CA1113935C00
7 changed files with 163 additions and 43 deletions

View file

@ -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 daide.'
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

View file

@ -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/

View file

@ -1,43 +0,0 @@
/*
gcc \$(pkg-config --cflags weechat) -shared -fPIC -Wall -Wextra essai.c -o essai.so $(pkg-config --libs weechat)
*/
#include <stdlib.h>
#include <weechat/weechat-plugin.h>
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 dessai",
"",
"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;
}

View file

@ -0,0 +1,63 @@
#include <stdlib.h>
#include <weechat/weechat-plugin.h>
#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 darguments : %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<argc; i++){
weechat_printf(NULL,
"Commande %d : %s%s%s\n"
"Commande %d (fin de ligne) : %s%s%s",
i,
weechat_color("green"),
argv[i],
weechat_color("reset"),
i,
weechat_color("green"),
argv_eol[i],
weechat_color("reset"));
}
weechat_rc = WEECHAT_RC_OK;
} else {
weechat_printf(NULL,
"Il ny a que dans ce tampon que la commande %s/essai%s est possible.",
weechat_color("italic"),
weechat_color("-italic"));
weechat_rc = WEECHAT_RC_ERROR;
}
return weechat_rc;
}
void essai_command_init(){
weechat_hook_command("1000|essai",
"Une commande dessai",
"[version]",
"version : description du greffon",
"version %-",
&essai_command,
NULL,
NULL);
}

View file

@ -0,0 +1,6 @@
#ifndef ESSAI_COMMAND_H
#define ESSAI_COMMAND_H
extern void essai_command_init();
#endif//ESSAI_COMMAND_H

View file

@ -0,0 +1,47 @@
/*
gcc $(pkg-config --cflags weechat) \
-shared -fPIC -Wall -Wextra essai.c essai-command.c -o ./essai.so \
$(pkg-config --libs weechat)
*/
#include <stdlib.h>
#include <weechat/weechat-plugin.h>
#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;
}

View file

@ -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