From 22e1f638bd14b6f379fbd0e2c9c2a05c65c25783 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Thu, 27 Oct 2011 22:26:47 +0200 Subject: [PATCH] Fonctionne --- C_Language/weechat_plugins/currentsong.c | 57 ++++++++++++++++++++---- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/C_Language/weechat_plugins/currentsong.c b/C_Language/weechat_plugins/currentsong.c index 46843d9..435cfd1 100644 --- a/C_Language/weechat_plugins/currentsong.c +++ b/C_Language/weechat_plugins/currentsong.c @@ -1,3 +1,14 @@ +/* Karchnu : + * + * currentsong : affiche le morceau que vous écoutez dans le buffer courant + * + * Pour l'ajouter : make ; cp libcurrentsong.so ~/.weechat/plugins/ + * Puis dans weechat : /plugin load libcurrentsong.so + * + */ + +#include +#include #include #include #include @@ -5,6 +16,8 @@ #include #define TAILLE_BUFFER_CURRENT_SONG 100 +#define TAILLE_OPTIONS 15 + WEECHAT_PLUGIN_NAME("currentsong"); WEECHAT_PLUGIN_DESCRIPTION("Affiche la musique en cours en utilisant mpc"); WEECHAT_PLUGIN_AUTHOR("Karchnu "); @@ -20,14 +33,29 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha (void) buffer; (void) argv; + argc = (argc >= 3) ? 4 : 2; + + int i,status; int p[2]; - //char local_buffer[100]; - char * song; - char affichage[TAILLE_BUFFER_CURRENT_SONG + 10]; - int i; - char * cmd[] = { "mpc", "-h" , "192.168.0.100","current", (char *)0 }; - song = malloc(TAILLE_BUFFER_CURRENT_SONG*sizeof(char)); - if(song == NULL) return WEECHAT_RC_ERROR; + char **cmd; + char *song; + char *affichage; + + cmd = (char **) malloc(sizeof(char*) * argc+1); + for(i = 0 ; i < argc ; i++) + cmd[i] = malloc(sizeof(char) * TAILLE_OPTIONS); + cmd[i] = NULL; + + strcpy(cmd[0],"mpc"); + strcpy(cmd[i-1],"current"); + if(argc == 4) + { + strcpy(cmd[1],argv[1]); + strcpy(cmd[2],argv[2]); + } + + song = malloc(TAILLE_BUFFER_CURRENT_SONG * sizeof(char)); + affichage = malloc((TAILLE_BUFFER_CURRENT_SONG + 10) * sizeof(char)); for(i = 0 ; i < TAILLE_BUFFER_CURRENT_SONG ; i++) song[i] = '\0'; @@ -45,11 +73,22 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha close(p[1]); read(p[0], song, TAILLE_BUFFER_CURRENT_SONG); close(p[0]); + + wait(&status); + if(WEXITSTATUS(status) != 0) + sprintf(song,"didn't worked !!!"); sprintf(affichage,"/me ♪ %s", song); + //sprintf(affichage,"/me ♪ %s%s", weechat_color ("_red"), song); // Ne s'affiche pas correctement chez les autres - weechat_utf8_normalize(affichage, '?'); // Pour ne pas avoir de caractères non-lisibles + //weechat_utf8_normalize(affichage, '?'); // Pour ne pas avoir de caractères non-lisibles + weechat_command(buffer,affichage); - free(song); + + free(song); // :') + for(i = 0 ; i < argc ; i++) + free(cmd[i]); + free(cmd); + free(affichage); return WEECHAT_RC_OK; }