aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-04-25 13:21:10 -0600
committerJack Sangdahl <[email protected]>2024-04-25 13:21:10 -0600
commit6182c1ff04f442086d7ce44538d357b863422295 (patch)
treeb0fdc9c0f1287408c933f2df5ea4c5aa3e25acdc
parenta9c2d5b0084857f572e08ba1413cb7916cf2409f (diff)
downloadst-6182c1ff04f442086d7ce44538d357b863422295.tar.gz
st-6182c1ff04f442086d7ce44538d357b863422295.zip
align makefile & tidy code
-rw-r--r--.gitignore1
-rw-r--r--Makefile29
-rw-r--r--arg.h13
-rw-r--r--boxdraw.c7
-rw-r--r--boxdraw_data.h7
-rw-r--r--config.h2
-rw-r--r--config.mk31
-rw-r--r--hb.c3
-rw-r--r--hb.h4
-rw-r--r--readme.md2
-rw-r--r--st.c5
-rw-r--r--st.h26
-rw-r--r--win.h4
-rw-r--r--x.c3
14 files changed, 58 insertions, 79 deletions
diff --git a/.gitignore b/.gitignore
index 6e792d7..142cced 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ st
*.o
*.orig
*.rej
+.gdb_history
diff --git a/Makefile b/Makefile
index 413fdf9..3561f6b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,12 @@
-# st - simple terminal
-# See LICENSE file for copyright and license details.
-.POSIX:
+PREFIX = /usr
-include config.mk
+DEPS = fontconfig harfbuzz
+
+CFLAGS = -I/usr/X11R6/include `pkg-config --cflags ${DEPS}` \
+ -DVERSION=\"0.9\" -D_XOPEN_SOURCE=600
+
+LDFLAGS = -L/usr/X11R6/lib -lm -lX11 -lXft \
+ `pkg-config --libs ${DEPS}`
SRC = st.c x.c boxdraw.c hb.c
OBJ = $(SRC:.c=.o)
@@ -10,27 +14,20 @@ OBJ = $(SRC:.c=.o)
all: st
.c.o:
- $(CC) $(STCFLAGS) -c $<
+ cc $(CFLAGS) -c $<
st.o: config.h st.h win.h
x.o: arg.h config.h st.h win.h hb.h
hb.o: st.h
boxdraw.o: config.h st.h boxdraw_data.h
-$(OBJ): config.h config.mk
+$(OBJ): config.h
st: $(OBJ)
- $(CC) -o $@ $(OBJ) $(STLDFLAGS)
+ cc -o $@ $(OBJ) $(LDFLAGS)
clean:
- rm -f st *.o *.orig *.rej
-
-dist: clean
- mkdir -p st-$(VERSION)
- cp -r Makefile readme.md config.mk arg.h hb.h win.h \
- config.h boxdraw_data.h st.h $(SRC) st-$(VERSION)
- tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz
- rm -rf st-$(VERSION)
+ rm -f st $(OBJ) *.orig *.rej
install: st
mkdir -p $(DESTDIR)$(PREFIX)/bin
@@ -39,5 +36,3 @@ install: st
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st
-
-.PHONY: all clean dist install uninstall
diff --git a/arg.h b/arg.h
index 2f8bd07..039a187 100644
--- a/arg.h
+++ b/arg.h
@@ -1,14 +1,9 @@
-/*
- * Copy me if you can.
- * by 20h
- */
-
-#ifndef ARG_H__
-#define ARG_H__
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
+#pragma once
extern char *argv0;
-/* use main(int argc, char *argv[]) */
#define ARGBEGIN \
for (argv0 = *argv, argv++, argc--; \
argv[0] && argv[0][0] == '-' && argv[0][1]; argc--, argv++) { \
@@ -44,5 +39,3 @@ extern char *argv0;
? (char *)0 \
: (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \
: (argc--, argv++, argv[0])))
-
-#endif
diff --git a/boxdraw.c b/boxdraw.c
index 28a92d0..38103b0 100644
--- a/boxdraw.c
+++ b/boxdraw.c
@@ -1,8 +1,5 @@
-/*
- * Copyright 2018 Avi Halachmi (:avih) [email protected] https://github.com/avih
- * MIT/X Consortium License
- */
-
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#include <X11/Xft/Xft.h>
#include "st.h"
#include "boxdraw_data.h"
diff --git a/boxdraw_data.h b/boxdraw_data.h
index 37a7e8a..bb7b00f 100644
--- a/boxdraw_data.h
+++ b/boxdraw_data.h
@@ -1,7 +1,6 @@
-/*
- * Copyright 2018 Avi Halachmi (:avih) [email protected] https://github.com/avih
- * MIT/X Consortium License
- */
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
+#pragma once
/*
* U+25XX codepoints data
diff --git a/config.h b/config.h
index d85ee7e..3254169 100644
--- a/config.h
+++ b/config.h
@@ -1,3 +1,5 @@
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#pragma once
static char *font =
diff --git a/config.mk b/config.mk
deleted file mode 100644
index 810ffa4..0000000
--- a/config.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# st version
-VERSION = 0.9
-
-# paths
-PREFIX = /usr/local
-MANPREFIX = $(PREFIX)/share/man
-
-X11INC = /usr/X11R6/include
-X11LIB = /usr/X11R6/lib
-
-PKG_CONFIG = pkg-config
-
-# includes and libs
-INCS = -I$(X11INC) \
- `$(PKG_CONFIG) --cflags glib-2.0` \
- `$(PKG_CONFIG) --cflags fontconfig` \
- `$(PKG_CONFIG) --cflags freetype2` \
- `$(PKG_CONFIG) --cflags harfbuzz`
-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
- `$(PKG_CONFIG) --libs glib-2.0` \
- `$(PKG_CONFIG) --libs fontconfig` \
- `$(PKG_CONFIG) --libs freetype2` \
- `$(PKG_CONFIG) --libs harfbuzz`
-
-# flags
-STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
-STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
-STLDFLAGS = $(LIBS) $(LDFLAGS)
-
-# compiler and linker
-CC = gcc
diff --git a/hb.c b/hb.c
index 6382b5d..29d7664 100644
--- a/hb.c
+++ b/hb.c
@@ -1,7 +1,8 @@
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#include <X11/Xft/Xft.h>
#include <hb-ft.h>
#include <hb.h>
-#include <math.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/hb.h b/hb.h
index 2dbcdc3..65a275c 100644
--- a/hb.h
+++ b/hb.h
@@ -1,3 +1,7 @@
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
+#pragma once
+
#include <X11/Xft/Xft.h>
#include <hb-ft.h>
#include <hb.h>
diff --git a/readme.md b/readme.md
index 297164f..bb33db6 100644
--- a/readme.md
+++ b/readme.md
@@ -3,4 +3,4 @@
![image](nord_image.png)
### dependencies
-libXft, libXext, harfbuzz, glib, freetype, fontconfig, JetBrainsMono Nerd Font
+harfbuzz, fontconfig, JetBrainsMono Nerd Font
diff --git a/st.c b/st.c
index 876e625..70d1c6b 100644
--- a/st.c
+++ b/st.c
@@ -1,4 +1,5 @@
-/* See LICENSE for license details. */
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -48,7 +49,7 @@
#define TLINE(y) \
((y) < term.scr \
? term.hist[((y) + term.histi - term.scr + HISTSIZE + 1) % HISTSIZE] \
- : term.line[(y)-term.scr])
+ : term.line[(y) - term.scr])
#define TLINE_HIST(y) \
((y) <= HISTSIZE - term.row + 2 ? term.hist[(y)] \
diff --git a/st.h b/st.h
index c30a0d4..b637374 100644
--- a/st.h
+++ b/st.h
@@ -1,15 +1,29 @@
-/* See LICENSE for license details. */
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
+#pragma once
#include <stdint.h>
#include <sys/types.h>
-// #include <gd.h>
-#include <glib.h>
-
/* macros */
-#define LEN(a) (sizeof(a) / sizeof(a)[0])
+#define MIN(a, b) \
+ ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a < _b ? _a : _b; \
+ })
+#define MAX(a, b) \
+ ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a > _b ? _a : _b; \
+ })
+#define CHECK(value) \
+ (!__builtin_types_compatible_p(typeof((value)), typeof(&(value)[0])))
+#define LEN(a) \
+ (__builtin_choose_expr(CHECK((a)), sizeof((a)) / sizeof((a)[0]), (void)0))
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
-#define DIVCEIL(n, d) (((n) + ((d)-1)) / (d))
+#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) \
diff --git a/win.h b/win.h
index df103f1..191d1d4 100644
--- a/win.h
+++ b/win.h
@@ -1,4 +1,6 @@
-/* See LICENSE for license details. */
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
+#pragma once
enum win_mode {
MODE_VISIBLE = 1 << 0,
diff --git a/x.c b/x.c
index 57cbc90..2eacd06 100644
--- a/x.c
+++ b/x.c
@@ -1,4 +1,5 @@
-/* See LICENSE for license details. */
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#include <errno.h>
#include <math.h>
#include <limits.h>