[hackers] [lchat] add special color for bellmatch in text part of chat msg || Jan Klemkow

From: <git_AT_suckless.org>
Date: Mon, 2 Apr 2018 00:29:28 +0200 (CEST)

commit 84eec82dccf223861142f19ca57b410ba414c98a
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
AuthorDate: Tue Mar 13 23:46:24 2018 +0100
Commit: Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Wed Mar 14 00:02:59 2018 +0100

    add special color for bellmatch in text part of chat msg

diff --git a/Makefile b/Makefile
index f153483..c739777 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -1,4 +1,4 @@
-include config.mk
+#include config.mk
 
 .PHONY: all install filter clean test
 
_AT_@ -21,8 +21,8 @@ lchat.o: lchat.c
             -o $_AT_ lchat.c
 
 filter: filter/indent
-filter/indent: filter/indent.c
- $(CC) $(CFLAGS) -o $_AT_ filter/indent.c
+filter/indent: filter/indent.c util.o util.h
+ $(CC) $(CFLAGS) -o $_AT_ filter/indent.c util.o
 
 sl_test.o: sl_test.c slackline.h
         $(CC) $(CFLAGS) -c -o $_AT_ sl_test.c
_AT_@ -32,3 +32,6 @@ sl_test: sl_test.o slackline.o slackline.h
 
 slackline.o: slackline.c slackline.h
         $(CC) -c $(CFLAGS) -o $_AT_ slackline.c
+
+util.o: util.c util.h
+ $(CC) -c $(CFLAGS) -o $_AT_ util.c
diff --git a/filter/indent.c b/filter/indent.c
index b45727c..24a3550 100644
--- a/filter/indent.c
+++ b/filter/indent.c
_AT_@ -6,8 +6,11 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "../util.h"
+
 #define color1 34
 #define color2 33
+#define color3 35
 
 int
 main(void)
_AT_@ -19,6 +22,7 @@ main(void)
         char *next, *nick, *word;
         int cols = 80; /* terminal width */
         int color = color1;
+ char *bell_file = ".bellmatch";
 
         while (fgets(buf, sizeof buf, stdin) != NULL) {
                 time_t time = strtol(buf, &next, 10);
_AT_@ -42,6 +46,9 @@ main(void)
                 if (strcmp(nick, old_nick) != 0)
                         color = color == color1 ? color2 : color1;
 
+ if (access(bell_file, R_OK) == 0 && bell_match(next, bell_file))
+ color = color3;
+
                 /* print prompt */
                 /* HH:MM nnnnnnnnnnnn ttttttttttttt */
                 // e[7;30;40m
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..bf6d9ca
--- /dev/null
+++ b/util.c
_AT_@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 Jan Klemkow <j.klemkow_AT_wemelug.de>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <err.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+bool
+bell_match(const char *str, const char *regex_file)
+{
+ FILE *fh = NULL;
+ char cmd[BUFSIZ];
+
+ if (access(regex_file, R_OK) == -1)
+ return true;
+
+ snprintf(cmd, sizeof cmd, "exec grep -qf %s", regex_file);
+
+ if ((fh = popen(cmd, "w")) == NULL)
+ err(EXIT_FAILURE, "popen");
+
+ if (fputs(str, fh) == EOF)
+ err(EXIT_FAILURE, "fputs");
+
+ if (pclose(fh) == 0)
+ return true;
+
+ return false;
+}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..c3851b0
--- /dev/null
+++ b/util.h
_AT_@ -0,0 +1,6 @@
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+bool bell_match(const char *str, const char *regex_file);
+
+#endif
Received on Mon Apr 02 2018 - 00:29:28 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 02 2018 - 00:36:30 CEST