[hackers] [lchat] minor cleanup and adjustments || Tom Schwindl

From: <git_AT_suckless.org>
Date: Sat, 8 Oct 2022 22:24:33 +0200 (CEST)

commit 1f48fc49963432855d340efd51abcc613bfcfd6c
Author: Tom Schwindl <schwindl_AT_posteo.de>
AuthorDate: Sat Oct 8 12:14:00 2022 +0200
Commit: Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Sat Oct 8 22:23:21 2022 +0200

    minor cleanup and adjustments

diff --git a/Makefile b/Makefile
index 24ef10c..bc4d363 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -7,11 +7,11 @@ clean:
         rm -f lchat *.o *.core sl_test filter/indent
 
 install: lchat
- cp lchat ${DESTDIR}${BINDIR}
- cp lchat.1 ${DESTDIR}${MAN1DIR}
+ cp lchat $(DESTDIR)$(BINDIR)
+ cp lchat.1 $(DESTDIR)$(MAN1DIR)
 
 uninstall:
- rm -f ${DESTDIR}${BINDIR}/lchat ${DESTDIR}${MAN1DIR}/lchat.1
+ rm -f $(DESTDIR)$(BINDIR)/lchat $(DESTDIR)$(MAN1DIR)/lchat.1
 
 test: sl_test
         ./sl_test
diff --git a/README.md b/README.md
index ca6554b..f1838ad 100644
--- a/README.md
+++ b/README.md
_AT_@ -1,9 +1,9 @@
 line chat
 =========
 
-lchat (line chat) is a line oriented front end for for ii-like chat programs.
+lchat (line chat) is a line oriented front end for ii-like chat programs.
 It handles the input from keyboard and output file in parallel. Thus, you are
-able to type new messages while new chat lines arriving. Its main focus is on
+able to type messages while new chat lines are arriving. Its main focus is on
 usability and simplicity.
 
 ![lchat](/lchat.png)
diff --git a/config.mk b/config.mk
index 15f86cc..c997f20 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -1,16 +1,10 @@
 # paths
 PREFIX = /usr/local
-BINDIR = ${PREFIX}/bin
-MANDIR = ${PREFIX}/share/man
-MAN1DIR = ${MANDIR}/man1
+BINDIR = $(PREFIX)/bin
+MANDIR = $(PREFIX)/share/man
+MAN1DIR = $(MANDIR)/man1
 
-CC ?= cc
-CFLAGS = -std=c99 -pedantic -Wall -Wextra -g
+CFLAGS = -std=c99 -pedantic -Wall -Wextra -I/usr/local/include
 
-# utf.h
-CFLAGS += -I/usr/local/include
+# grapheme.h
 LIBS = -L/usr/local/lib -lgrapheme
-
-# For sbase users:
-#CFLAGS += -I../sbase
-#LIBS = -L../sbase -lutf
diff --git a/lchat.c b/lchat.c
index cc279c9..d5d8faf 100644
--- a/lchat.c
+++ b/lchat.c
_AT_@ -35,8 +35,8 @@
 #define INFTIM -1
 #endif
 
-struct termios origin_term;
-struct winsize winsize;
+static struct termios origin_term;
+static struct winsize winsize;
 
 static void
 sigwinch(int sig)
_AT_@ -48,6 +48,14 @@ sigwinch(int sig)
 static void
 exit_handler(void)
 {
+ char *title = getenv("TERM");
+
+ /* reset terminal's window name */
+ if (strncmp(title, "screen", 6) == 0)
+ printf("\033k%s\033\\", title);
+ else
+ printf("\033]0;%s\a", title);
+
         if (tcsetattr(STDIN_FILENO, TCSANOW, &origin_term) == -1)
                 die("tcsetattr:");
 }
_AT_@ -139,9 +147,8 @@ fork_filter(int *read, int *write)
 static void
 usage(void)
 {
- fputs("lchat [-aeh] [-n lines] [-p prompt] [-t title] [-i in] [-o out]"
- " [directory]\n", stderr);
- exit(EXIT_FAILURE);
+ die("lchat [-aeh] [-n lines] [-p prompt] [-t title] [-i in] [-o out]"
+ " [directory]");
 }
 
 int
_AT_@ -164,6 +171,9 @@ main(int argc, char *argv[])
         char *prompt = read_file_line(".prompt");
         char *title = read_file_line(".title");
 
+ if (sl == NULL)
+ die("Failed to initialize slackline");
+
         if (prompt == NULL) /* set default prompt */
                 prompt = "> ";
 
_AT_@ -242,7 +252,7 @@ main(int argc, char *argv[])
                 if ((title = basename(path)) == NULL)
                         die("basename:");
         }
- if (strcmp(getenv("TERM"), "screen") == 0)
+ if (strncmp(getenv("TERM"), "screen", 6) == 0)
                 printf("\033k%s\033\\", title);
         else
                 printf("\033]0;%s\a", title);
_AT_@ -278,7 +288,7 @@ main(int argc, char *argv[])
                 FILE *fh;
 
                 /* open external source */
- snprintf(tail_cmd, sizeof tail_cmd, "exec tail -n %zd -f %s",
+ snprintf(tail_cmd, sizeof tail_cmd, "exec tail -n %zu -f %s",
                     history_len, out_file);
 
                 if ((fh = popen(tail_cmd, "r")) == NULL)
Received on Sat Oct 08 2022 - 22:24:33 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 08 2022 - 22:36:38 CEST