Преглед на файлове

vcc: add plugin beep which uses notice-send

intirain преди 4 години
родител
ревизия
5d5244dd66
променени са 6 файла, в които са добавени 104 реда и са изтрити 6 реда
  1. 1 1
      Makefile
  2. 2 2
      include/vcc/version.h
  3. 2 2
      plugins.c
  4. 1 1
      plugins/Makefile
  5. 14 0
      plugins/beep/Makefile
  6. 84 0
      plugins/beep/beep.c

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 31
+VCC_MINOR 		= 32
 VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.31.0 Mon Jun 13 01:23:55 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.31.0-rc "
+#define VCC_VERSION "VCC 1.32.0 Fri Jun 17 10:05:46 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.32.0-rc "

+ 2 - 2
plugins.c

@@ -43,10 +43,10 @@
 #include <vcc/interfaces.h>
 
 
-extern struct plugin plg_hello, plg_robot, plg_m4, plg_script, plg_hist, plg_cqd;
+extern struct plugin plg_hello, plg_robot, plg_m4, plg_script, plg_hist, plg_cqd, plg_beep;
 
 struct plugin *plugins[] = {
-	&plg_hello, &plg_robot, &plg_m4, &plg_script, &plg_hist, &plg_cqd, 
+	&plg_hello, &plg_robot, &plg_m4, &plg_script, &plg_hist, &plg_cqd, &plg_beep, 
 	(struct plugin *) NULL
 };
 

+ 1 - 1
plugins/Makefile

@@ -1,4 +1,4 @@
-plugins 	= hello robot m4 script hist cqd 
+plugins 	= hello robot m4 script hist cqd beep 
 target 		= libplugins.a 
 
 all: 

+ 14 - 0
plugins/beep/Makefile

@@ -0,0 +1,14 @@
+objs 	= beep.o 
+target 	= ../plg_beep.o 
+CFLAGS 	= -std=gnu11 -Wall -Wextra -Werror -I../../include -g 
+
+$(target): $(objs)
+	@cp $(objs) $(target)
+
+%.o: %.c
+	@$(CC) -c $*.c $(CFLAGS)
+	@echo -e "CC\t\t\t$*.c"
+
+.PHONY clean: 
+	rm -f $(target) $(objs)
+

+ 84 - 0
plugins/beep/beep.c

@@ -0,0 +1,84 @@
+/* vcc/plugins/beep/beep.c 
+ * 
+ * This file is part of vcc. 
+ * 
+ * vcc is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * vcc is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <vcc/vcc.h>
+#include <vcc/pretty.h>
+#include <vcc/plugin.h>
+#include <vcc/version.h>
+
+
+int beep_init(void);
+
+struct cmdtable beep_cmdtab[] = {
+	{ NULL, NULL, NULL }
+};
+
+struct plugin plg_beep = {
+	.state = 0, 
+	.name = "beep", 
+	.descr = "Beep when you have a new message. ", 
+	.init = beep_init, 
+	.cmdtab = beep_cmdtab
+};
+
+#define this_plg (&plg_beep)
+
+char *beep_hook(struct hook_info *hi) {
+	char buf[128];
+	char *p;
+	int len;
+
+	if (unlikely(!(p = strdup(hi->msg)))) {
+		fprintf(stderr, "*** malloc() failed\n");
+
+		return HOOK_FAILED;
+	}
+
+	/* '\n' */
+	len = strlen(p);
+	p[len - 1] = 0;
+
+	printf("%d\n", len);
+
+	if (len > 10) {
+		p[10] = 0;
+		strcat(p, "...");
+	}
+
+	sprintf(buf, "notify-send \"vcc\" \"vcc: %s: %s\"", hi->usr, p);
+
+	fprintf(stderr, "\a");
+	system(buf);
+	free(p);
+
+	return HOOK_IGNORE;
+}
+
+int beep_init(void) {
+	register_hook(HOOK_RECV, beep_hook);
+	return 0;
+}
+
+