From 6182c1ff04f442086d7ce44538d357b863422295 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl <0x6A73@pm.me> Date: Thu, 25 Apr 2024 13:21:10 -0600 Subject: align makefile & tidy code --- .gitignore | 1 + Makefile | 29 ++++++++++++----------------- arg.h | 13 +++---------- boxdraw.c | 7 ++----- boxdraw_data.h | 7 +++---- config.h | 2 ++ config.mk | 31 ------------------------------- hb.c | 3 ++- hb.h | 4 ++++ readme.md | 2 +- st.c | 5 +++-- st.h | 26 ++++++++++++++++++++------ win.h | 4 +++- x.c | 3 ++- 14 files changed, 58 insertions(+), 79 deletions(-) delete mode 100644 config.mk 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) avihpit@yahoo.com https://github.com/avih - * MIT/X Consortium License - */ - +// Copyright 2024 @waffle87 +// SPDX-License-Identifier: MIT/X #include #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) avihpit@yahoo.com 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 #include #include -#include #include #include 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 #include #include 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 #include #include @@ -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 #include -// #include -#include - /* 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 #include #include -- cgit v1.2.3