From 80cded6ecf649a1ab2202eff43b58fc2ef5300a0 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 5 Nov 2020 13:53:13 +0100 Subject: [PATCH 01/14] Added .gitignore (#1) --- .gitignore | 8 + Makefile | 57 ------- config.h | 472 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 480 insertions(+), 57 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 config.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75af8f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# IDE Directories +.vim/ +.vscode/ + +# CMake files +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake diff --git a/Makefile b/Makefile deleted file mode 100644 index 470ac86..0000000 --- a/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# st - simple terminal -# See LICENSE file for copyright and license details. -.POSIX: - -include config.mk - -SRC = st.c x.c -OBJ = $(SRC:.c=.o) - -all: options st - -options: - @echo st build options: - @echo "CFLAGS = $(STCFLAGS)" - @echo "LDFLAGS = $(STLDFLAGS)" - @echo "CC = $(CC)" - -config.h: - cp config.def.h config.h - -.c.o: - $(CC) $(STCFLAGS) -c $< - -st.o: config.h st.h win.h -x.o: arg.h config.h st.h win.h - -$(OBJ): config.h config.mk - -st: $(OBJ) - $(CC) -o $@ $(OBJ) $(STLDFLAGS) - -clean: - rm -f st $(OBJ) st-$(VERSION).tar.gz - -dist: clean - mkdir -p st-$(VERSION) - cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\ - config.def.h st.info st.1 arg.h st.h win.h $(SRC)\ - st-$(VERSION) - tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz - rm -rf st-$(VERSION) - -install: st - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f st $(DESTDIR)$(PREFIX)/bin - chmod 755 $(DESTDIR)$(PREFIX)/bin/st - mkdir -p $(DESTDIR)$(MANPREFIX)/man1 - sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1 - chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1 - tic -sx st.info - @echo Please see the README file regarding the terminfo entry of st. - -uninstall: - rm -f $(DESTDIR)$(PREFIX)/bin/st - rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 - -.PHONY: all options clean dist install uninstall diff --git a/config.h b/config.h new file mode 100644 index 0000000..6f05dce --- /dev/null +++ b/config.h @@ -0,0 +1,472 @@ +/* See LICENSE file for copyright and license details. */ + +/* + * appearance + * + * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html + */ +static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; +static int borderpx = 2; + +/* + * What program is execed by st depends of these precedence rules: + * 1: program passed with -e + * 2: scroll and/or utmp + * 3: SHELL environment variable + * 4: value of shell in /etc/passwd + * 5: value of shell in config.h + */ +static char *shell = "/bin/sh"; +char *utmp = NULL; +/* scroll program: to enable use a string like "scroll" */ +char *scroll = NULL; +char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; + +/* identification sequence returned in DA and DECID */ +char *vtiden = "\033[?6c"; + +/* Kerning / character bounding-box multipliers */ +static float cwscale = 1.0; +static float chscale = 1.0; + +/* + * word delimiter string + * + * More advanced example: L" `'\"()[]{}" + */ +wchar_t *worddelimiters = L" "; + +/* selection timeouts (in milliseconds) */ +static unsigned int doubleclicktimeout = 300; +static unsigned int tripleclicktimeout = 600; + +/* alt screens */ +int allowaltscreen = 1; + +/* allow certain non-interactive (insecure) window operations such as: + setting the clipboard text */ +int allowwindowops = 0; + +/* + * draw latency range in ms - from new content/keypress/etc until drawing. + * within this range, st draws when content stops arriving (idle). mostly it's + * near minlatency, but it waits longer for slow updates to avoid partial draw. + * low minlatency will tear/flicker more, as it can "detect" idle too early. + */ +static double minlatency = 8; +static double maxlatency = 33; + +/* + * blinking timeout (set to 0 to disable blinking) for the terminal blinking + * attribute. + */ +static unsigned int blinktimeout = 800; + +/* + * thickness of underline and bar cursors + */ +static unsigned int cursorthickness = 2; + +/* + * bell volume. It must be a value between -100 and 100. Use 0 for disabling + * it + */ +static int bellvolume = 0; + +/* default TERM value */ +char *termname = "st-256color"; + +/* + * spaces per tab + * + * When you are changing this value, don't forget to adapt the »it« value in + * the st.info and appropriately install the st.info in the environment where + * you use this st version. + * + * it#$tabspaces, + * + * Secondly make sure your kernel is not expanding tabs. When running `stty + * -a` »tab0« should appear. You can tell the terminal to not expand tabs by + * running following command: + * + * stty tabs + */ +unsigned int tabspaces = 8; + +/* Terminal colors (16 first used in escape sequence) */ +static const char *colorname[] = { + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", +}; + + +/* + * Default colors (colorname index) + * foreground, background, cursor, reverse cursor + */ +unsigned int defaultfg = 7; +unsigned int defaultbg = 0; +static unsigned int defaultcs = 256; +static unsigned int defaultrcs = 257; + +/* + * Default shape of cursor + * 2: Block ("█") + * 4: Underline ("_") + * 6: Bar ("|") + * 7: Snowman ("☃") + */ +static unsigned int cursorshape = 2; + +/* + * Default columns and rows numbers + */ + +static unsigned int cols = 80; +static unsigned int rows = 24; + +/* + * Default colour and shape of the mouse cursor + */ +static unsigned int mouseshape = XC_xterm; +static unsigned int mousefg = 7; +static unsigned int mousebg = 0; + +/* + * Color used to display font attributes when fontconfig selected a font which + * doesn't match the ones requested. + */ +static unsigned int defaultattr = 11; + +/* + * Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set). + * Note that if you want to use ShiftMask with selmasks, set this to an other + * modifier, set to 0 to not use it. + */ +static uint forcemousemod = ShiftMask; + +/* + * Internal mouse shortcuts. + * Beware that overloading Button1 will disable the selection. + */ +static MouseShortcut mshortcuts[] = { + /* mask button function argument release */ + { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, + { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, + { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, + { ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} }, + { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, +}; + +/* Internal keyboard shortcuts. */ +#define MODKEY Mod1Mask +#define TERMMOD (ControlMask|ShiftMask) + +static Shortcut shortcuts[] = { + /* mask keysym function argument */ + { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, + { ControlMask, XK_Print, toggleprinter, {.i = 0} }, + { ShiftMask, XK_Print, printscreen, {.i = 0} }, + { XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, + { TERMMOD, XK_Prior, zoom, {.f = +1} }, + { TERMMOD, XK_Next, zoom, {.f = -1} }, + { TERMMOD, XK_Home, zoomreset, {.f = 0} }, + { TERMMOD, XK_C, clipcopy, {.i = 0} }, + { TERMMOD, XK_V, clippaste, {.i = 0} }, + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { ShiftMask, XK_Insert, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, +}; + +/* + * Special keys (change & recompile st.info accordingly) + * + * Mask value: + * * Use XK_ANY_MOD to match the key no matter modifiers state + * * Use XK_NO_MOD to match the key alone (no modifiers) + * appkey value: + * * 0: no value + * * > 0: keypad application mode enabled + * * = 2: term.numlock = 1 + * * < 0: keypad application mode disabled + * appcursor value: + * * 0: no value + * * > 0: cursor application mode enabled + * * < 0: cursor application mode disabled + * + * Be careful with the order of the definitions because st searches in + * this table sequentially, so any XK_ANY_MOD must be in the last + * position for a key. + */ + +/* + * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF) + * to be mapped below, add them to this array. + */ +static KeySym mappedkeys[] = { -1 }; + +/* + * State bits to ignore when matching key or button events. By default, + * numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored. + */ +static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; + +/* + * This is the huge key array which defines all compatibility to the Linux + * world. Please decide about changes wisely. + */ +static Key key[] = { + /* keysym mask string appkey appcursor */ + { XK_KP_Home, ShiftMask, "\033[2J", 0, -1}, + { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1}, + { XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1}, + { XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1}, + { XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0}, + { XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1}, + { XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1}, + { XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0}, + { XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1}, + { XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1}, + { XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0}, + { XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1}, + { XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1}, + { XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0}, + { XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1}, + { XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1}, + { XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0}, + { XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0}, + { XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0}, + { XK_KP_End, ControlMask, "\033[J", -1, 0}, + { XK_KP_End, ControlMask, "\033[1;5F", +1, 0}, + { XK_KP_End, ShiftMask, "\033[K", -1, 0}, + { XK_KP_End, ShiftMask, "\033[1;2F", +1, 0}, + { XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0}, + { XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0}, + { XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0}, + { XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0}, + { XK_KP_Insert, ShiftMask, "\033[4l", -1, 0}, + { XK_KP_Insert, ControlMask, "\033[L", -1, 0}, + { XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0}, + { XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0}, + { XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0}, + { XK_KP_Delete, ControlMask, "\033[M", -1, 0}, + { XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0}, + { XK_KP_Delete, ShiftMask, "\033[2K", -1, 0}, + { XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0}, + { XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0}, + { XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, + { XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0}, + { XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0}, + { XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0}, + { XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0}, + { XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0}, + { XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0}, + { XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0}, + { XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0}, + { XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0}, + { XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0}, + { XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0}, + { XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0}, + { XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0}, + { XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0}, + { XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0}, + { XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0}, + { XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0}, + { XK_Up, ShiftMask, "\033[1;2A", 0, 0}, + { XK_Up, Mod1Mask, "\033[1;3A", 0, 0}, + { XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0}, + { XK_Up, ControlMask, "\033[1;5A", 0, 0}, + { XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0}, + { XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0}, + { XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0}, + { XK_Up, XK_ANY_MOD, "\033[A", 0, -1}, + { XK_Up, XK_ANY_MOD, "\033OA", 0, +1}, + { XK_Down, ShiftMask, "\033[1;2B", 0, 0}, + { XK_Down, Mod1Mask, "\033[1;3B", 0, 0}, + { XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0}, + { XK_Down, ControlMask, "\033[1;5B", 0, 0}, + { XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0}, + { XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0}, + { XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0}, + { XK_Down, XK_ANY_MOD, "\033[B", 0, -1}, + { XK_Down, XK_ANY_MOD, "\033OB", 0, +1}, + { XK_Left, ShiftMask, "\033[1;2D", 0, 0}, + { XK_Left, Mod1Mask, "\033[1;3D", 0, 0}, + { XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0}, + { XK_Left, ControlMask, "\033[1;5D", 0, 0}, + { XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0}, + { XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0}, + { XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0}, + { XK_Left, XK_ANY_MOD, "\033[D", 0, -1}, + { XK_Left, XK_ANY_MOD, "\033OD", 0, +1}, + { XK_Right, ShiftMask, "\033[1;2C", 0, 0}, + { XK_Right, Mod1Mask, "\033[1;3C", 0, 0}, + { XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0}, + { XK_Right, ControlMask, "\033[1;5C", 0, 0}, + { XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0}, + { XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0}, + { XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0}, + { XK_Right, XK_ANY_MOD, "\033[C", 0, -1}, + { XK_Right, XK_ANY_MOD, "\033OC", 0, +1}, + { XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0}, + { XK_Return, Mod1Mask, "\033\r", 0, 0}, + { XK_Return, XK_ANY_MOD, "\r", 0, 0}, + { XK_Insert, ShiftMask, "\033[4l", -1, 0}, + { XK_Insert, ShiftMask, "\033[2;2~", +1, 0}, + { XK_Insert, ControlMask, "\033[L", -1, 0}, + { XK_Insert, ControlMask, "\033[2;5~", +1, 0}, + { XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0}, + { XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0}, + { XK_Delete, ControlMask, "\033[M", -1, 0}, + { XK_Delete, ControlMask, "\033[3;5~", +1, 0}, + { XK_Delete, ShiftMask, "\033[2K", -1, 0}, + { XK_Delete, ShiftMask, "\033[3;2~", +1, 0}, + { XK_Delete, XK_ANY_MOD, "\033[P", -1, 0}, + { XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, + { XK_BackSpace, XK_NO_MOD, "\177", 0, 0}, + { XK_BackSpace, Mod1Mask, "\033\177", 0, 0}, + { XK_Home, ShiftMask, "\033[2J", 0, -1}, + { XK_Home, ShiftMask, "\033[1;2H", 0, +1}, + { XK_Home, XK_ANY_MOD, "\033[H", 0, -1}, + { XK_Home, XK_ANY_MOD, "\033[1~", 0, +1}, + { XK_End, ControlMask, "\033[J", -1, 0}, + { XK_End, ControlMask, "\033[1;5F", +1, 0}, + { XK_End, ShiftMask, "\033[K", -1, 0}, + { XK_End, ShiftMask, "\033[1;2F", +1, 0}, + { XK_End, XK_ANY_MOD, "\033[4~", 0, 0}, + { XK_Prior, ControlMask, "\033[5;5~", 0, 0}, + { XK_Prior, ShiftMask, "\033[5;2~", 0, 0}, + { XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0}, + { XK_Next, ControlMask, "\033[6;5~", 0, 0}, + { XK_Next, ShiftMask, "\033[6;2~", 0, 0}, + { XK_Next, XK_ANY_MOD, "\033[6~", 0, 0}, + { XK_F1, XK_NO_MOD, "\033OP" , 0, 0}, + { XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0}, + { XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0}, + { XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0}, + { XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0}, + { XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0}, + { XK_F2, XK_NO_MOD, "\033OQ" , 0, 0}, + { XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0}, + { XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0}, + { XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0}, + { XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0}, + { XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0}, + { XK_F3, XK_NO_MOD, "\033OR" , 0, 0}, + { XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0}, + { XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0}, + { XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0}, + { XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0}, + { XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0}, + { XK_F4, XK_NO_MOD, "\033OS" , 0, 0}, + { XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0}, + { XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0}, + { XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0}, + { XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0}, + { XK_F5, XK_NO_MOD, "\033[15~", 0, 0}, + { XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0}, + { XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0}, + { XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0}, + { XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0}, + { XK_F6, XK_NO_MOD, "\033[17~", 0, 0}, + { XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0}, + { XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0}, + { XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0}, + { XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0}, + { XK_F7, XK_NO_MOD, "\033[18~", 0, 0}, + { XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0}, + { XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0}, + { XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0}, + { XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0}, + { XK_F8, XK_NO_MOD, "\033[19~", 0, 0}, + { XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0}, + { XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0}, + { XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0}, + { XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0}, + { XK_F9, XK_NO_MOD, "\033[20~", 0, 0}, + { XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0}, + { XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0}, + { XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0}, + { XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0}, + { XK_F10, XK_NO_MOD, "\033[21~", 0, 0}, + { XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0}, + { XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0}, + { XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0}, + { XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0}, + { XK_F11, XK_NO_MOD, "\033[23~", 0, 0}, + { XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0}, + { XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0}, + { XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0}, + { XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0}, + { XK_F12, XK_NO_MOD, "\033[24~", 0, 0}, + { XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0}, + { XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0}, + { XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0}, + { XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0}, + { XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0}, + { XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0}, + { XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0}, + { XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0}, + { XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0}, + { XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0}, + { XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0}, + { XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0}, + { XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0}, + { XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0}, + { XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0}, + { XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0}, + { XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0}, + { XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0}, + { XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0}, + { XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0}, + { XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0}, + { XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0}, + { XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0}, + { XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0}, + { XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0}, + { XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0}, + { XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0}, +}; + +/* + * Selection types' masks. + * Use the same masks as usual. + * Button1Mask is always unset, to make masks match between ButtonPress. + * ButtonRelease and MotionNotify. + * If no match is found, regular selection is used. + */ +static uint selmasks[] = { + [SEL_RECTANGULAR] = Mod1Mask, +}; + +/* + * Printable characters in ASCII, used to estimate the advance width + * of single wide characters. + */ +static char ascii_printable[] = + " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "`abcdefghijklmnopqrstuvwxyz{|}~"; From 8a611a85f49e5148fb3e2e83f4ea80b358e2f023 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 5 Nov 2020 13:56:01 +0100 Subject: [PATCH 02/14] Some re-organizing (#1) --- FAQ | 250 ---------------------------------------- LEGACY | 17 --- TODO | 28 ----- st.1 => data/st.1 | 0 st.info => data/st.info | 0 st.c => st/st.c | 0 st.h => st/st.h | 0 7 files changed, 295 deletions(-) delete mode 100644 FAQ delete mode 100644 LEGACY delete mode 100644 TODO rename st.1 => data/st.1 (100%) rename st.info => data/st.info (100%) rename st.c => st/st.c (100%) rename st.h => st/st.h (100%) diff --git a/FAQ b/FAQ deleted file mode 100644 index 0f9609d..0000000 --- a/FAQ +++ /dev/null @@ -1,250 +0,0 @@ -## Why does st not handle utmp entries? - -Use the excellent tool of [utmp](https://git.suckless.org/utmp/) for this task. - - -## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever! - -It means that st doesn’t have any terminfo entry on your system. Chances are -you did not `make install`. If you just want to test it without installing it, -you can manually run `tic -sx st.info`. - - -## Nothing works, and nothing is said about an unknown terminal! - -* Some programs just assume they’re running in xterm i.e. they don’t rely on - terminfo. What you see is the current state of the “xterm compliance”. -* Some programs don’t complain about the lacking st description and default to - another terminal. In that case see the question about terminfo. - - -## How do I scroll back up? - -* Using a terminal multiplexer. - * `st -e tmux` using C-b [ - * `st -e screen` using C-a ESC -* Using the excellent tool of [scroll](https://git.suckless.org/scroll/). -* Using the scrollback [patch](https://st.suckless.org/patches/scrollback/). - - -## I would like to have utmp and/or scroll functionality by default - -You can add the absolute patch of both programs in your config.h -file. You only have to modify the value of utmp and scroll variables. - - -## Why doesn't the Del key work in some programs? - -Taken from the terminfo manpage: - - If the terminal has a keypad that transmits codes when the keys - are pressed, this information can be given. Note that it is not - possible to handle terminals where the keypad only works in - local (this applies, for example, to the unshifted HP 2621 keys). - If the keypad can be set to transmit or not transmit, give these - codes as smkx and rmkx. Otherwise the keypad is assumed to - always transmit. - -In the st case smkx=E[?1hE= and rmkx=E[?1lE>, so it is mandatory that -applications which want to test against keypad keys send these -sequences. - -But buggy applications (like bash and irssi, for example) don't do this. A fast -solution for them is to use the following command: - - $ printf '\033[?1h\033=' >/dev/tty - -or - $ tput smkx - -In the case of bash, readline is used. Readline has a different note in its -manpage about this issue: - - enable-keypad (Off) - When set to On, readline will try to enable the - application keypad when it is called. Some systems - need this to enable arrow keys. - -Adding this option to your .inputrc will fix the keypad problem for all -applications using readline. - -If you are using zsh, then read the zsh FAQ -: - - It should be noted that the O / [ confusion can occur with other keys - such as Home and End. Some systems let you query the key sequences - sent by these keys from the system's terminal database, terminfo. - Unfortunately, the key sequences given there typically apply to the - mode that is not the one zsh uses by default (it's the "application" - mode rather than the "raw" mode). Explaining the use of terminfo is - outside of the scope of this FAQ, but if you wish to use the key - sequences given there you can tell the line editor to turn on - "application" mode when it starts and turn it off when it stops: - - function zle-line-init () { echoti smkx } - function zle-line-finish () { echoti rmkx } - zle -N zle-line-init - zle -N zle-line-finish - -Putting these lines into your .zshrc will fix the problems. - - -## How can I use meta in 8bit mode? - -St supports meta in 8bit mode, but the default terminfo entry doesn't -use this capability. If you want it, you have to use the 'st-meta' value -in TERM. - - -## I cannot compile st in OpenBSD - -OpenBSD lacks librt, despite it being mandatory in POSIX -. -If you want to compile st for OpenBSD you have to remove -lrt from config.mk, and -st will compile without any loss of functionality, because all the functions are -included in libc on this platform. - - -## The Backspace Case - -St is emulating the Linux way of handling backspace being delete and delete being -backspace. - -This is an issue that was discussed in suckless mailing list -. Here is why some old grumpy -terminal users wants its backspace to be how he feels it: - - Well, I am going to comment why I want to change the behaviour - of this key. When ASCII was defined in 1968, communication - with computers was done using punched cards, or hardcopy - terminals (basically a typewriter machine connected with the - computer using a serial port). ASCII defines DELETE as 7F, - because, in punched-card terms, it means all the holes of the - card punched; it is thus a kind of 'physical delete'. In the - same way, the BACKSPACE key was a non-destructive backspace, - as on a typewriter. So, if you wanted to delete a character, - you had to BACKSPACE and then DELETE. Another use of BACKSPACE - was to type accented characters, for example 'a BACKSPACE `'. - The VT100 had no BACKSPACE key; it was generated using the - CONTROL key as another control character (CONTROL key sets to - 0 b7 b6 b5, so it converts H (code 0x48) into BACKSPACE (code - 0x08)), but it had a DELETE key in a similar position where - the BACKSPACE key is located today on common PC keyboards. - All the terminal emulators emulated the difference between - these keys correctly: the backspace key generated a BACKSPACE - (^H) and delete key generated a DELETE (^?). - - But a problem arose when Linus Torvalds wrote Linux. Unlike - earlier terminals, the Linux virtual terminal (the terminal - emulator integrated in the kernel) returned a DELETE when - backspace was pressed, due to the VT100 having a DELETE key in - the same position. This created a lot of problems (see [1] - and [2]). Since Linux has become the king, a lot of terminal - emulators today generate a DELETE when the backspace key is - pressed in order to avoid problems with Linux. The result is - that the only way of generating a BACKSPACE on these systems - is by using CONTROL + H. (I also think that emacs had an - important point here because the CONTROL + H prefix is used - in emacs in some commands (help commands).) - - From point of view of the kernel, you can change the key - for deleting a previous character with stty erase. When you - connect a real terminal into a machine you describe the type - of terminal, so getty configures the correct value of stty - erase for this terminal. In the case of terminal emulators, - however, you don't have any getty that can set the correct - value of stty erase, so you always get the default value. - For this reason, it is necessary to add 'stty erase ^H' to your - profile if you have changed the value of the backspace key. - Of course, another solution is for st itself to modify the - value of stty erase. I usually have the inverse problem: - when I connect to non-Unix machines, I have to press CONTROL + - h to get a BACKSPACE. The inverse problem occurs when a user - connects to my Unix machines from a different system with a - correct backspace key. - - [1] http://www.ibb.net/~anne/keyboard.html - [2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html - - -## But I really want the old grumpy behaviour of my terminal - -Apply [1]. - -[1] https://st.suckless.org/patches/delkey - - -## Why do images not work in st using the w3m image hack? - -w3mimg uses a hack that draws an image on top of the terminal emulator Drawable -window. The hack relies on the terminal to use a single buffer to draw its -contents directly. - -st uses double-buffered drawing so the image is quickly replaced and may show a -short flicker effect. - -Below is a patch example to change st double-buffering to a single Drawable -buffer. - -diff --git a/x.c b/x.c ---- a/x.c -+++ b/x.c -@@ -732,10 +732,6 @@ xresize(int col, int row) - win.tw = col * win.cw; - win.th = row * win.ch; - -- XFreePixmap(xw.dpy, xw.buf); -- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, -- DefaultDepth(xw.dpy, xw.scr)); -- XftDrawChange(xw.draw, xw.buf); - xclear(0, 0, win.w, win.h); - - /* resize to new width */ -@@ -1148,8 +1144,7 @@ xinit(int cols, int rows) - gcvalues.graphics_exposures = False; - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures, - &gcvalues); -- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, -- DefaultDepth(xw.dpy, xw.scr)); -+ xw.buf = xw.win; - XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); - XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); - -@@ -1632,8 +1627,6 @@ xdrawline(Line line, int x1, int y1, int x2) - void - xfinishdraw(void) - { -- XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, -- win.h, 0, 0); - XSetForeground(xw.dpy, dc.gc, - dc.col[IS_SET(MODE_REVERSE)? - defaultfg : defaultbg].pixel); - - -## BadLength X error in Xft when trying to render emoji - -Xft makes st crash when rendering color emojis with the following error: - -"X Error of failed request: BadLength (poly request too large or internal Xlib length error)" - Major opcode of failed request: 139 (RENDER) - Minor opcode of failed request: 20 (RenderAddGlyphs) - Serial number of failed request: 1595 - Current serial number in output stream: 1818" - -This is a known bug in Xft (not st) which happens on some platforms and -combination of particular fonts and fontconfig settings. - -See also: -https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6 -https://bugs.freedesktop.org/show_bug.cgi?id=107534 -https://bugzilla.redhat.com/show_bug.cgi?id=1498269 - -The solution is to remove color emoji fonts or disable this in the fontconfig -XML configuration. As an ugly workaround (which may work only on newer -fontconfig versions (FC_COLOR)), the following code can be used to mask color -fonts: - - FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); - -Please don't bother reporting this bug to st, but notify the upstream Xft -developers about fixing this bug. diff --git a/LEGACY b/LEGACY deleted file mode 100644 index bf28b1e..0000000 --- a/LEGACY +++ /dev/null @@ -1,17 +0,0 @@ -A STATEMENT ON LEGACY SUPPORT - -In the terminal world there is much cruft that comes from old and unsup‐ -ported terminals that inherit incompatible modes and escape sequences -which noone is able to know, except when he/she comes from that time and -developed a graphical vt100 emulator at that time. - -One goal of st is to only support what is really needed. When you en‐ -counter a sequence which you really need, implement it. But while you -are at it, do not add the other cruft you might encounter while sneek‐ -ing at other terminal emulators. History has bloated them and there is -no real evidence that most of the sequences are used today. - - -Christoph Lohmann <20h@r-36.net> -2012-09-13T07:00:36.081271045+02:00 - diff --git a/TODO b/TODO deleted file mode 100644 index 5f74cd5..0000000 --- a/TODO +++ /dev/null @@ -1,28 +0,0 @@ -vt emulation ------------- - -* double-height support - -code & interface ----------------- - -* add a simple way to do multiplexing - -drawing -------- -* add diacritics support to xdraws() - * switch to a suckless font drawing library -* make the font cache simpler -* add better support for brightening of the upper colors - -bugs ----- - -* fix shift up/down (shift selection in emacs) -* remove DEC test sequence when appropriate - -misc ----- - - $ grep -nE 'XXX|TODO' st.c - diff --git a/st.1 b/data/st.1 similarity index 100% rename from st.1 rename to data/st.1 diff --git a/st.info b/data/st.info similarity index 100% rename from st.info rename to data/st.info diff --git a/st.c b/st/st.c similarity index 100% rename from st.c rename to st/st.c diff --git a/st.h b/st/st.h similarity index 100% rename from st.h rename to st/st.h From bbca7d0a0f5f4a220fc80d02bc8a482d5b766b2a Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 5 Nov 2020 14:00:55 +0100 Subject: [PATCH 03/14] Moved everything to src dir (#1) --- arg.h => src/arg.h | 0 config.def.h => src/config.def.h | 0 config.h => src/config.h | 0 src/st/CMakeLists.txt | 0 {st => src/st}/st.c | 0 {st => src/st}/st.h | 0 win.h => src/win.h | 0 x.c => src/x.c | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename arg.h => src/arg.h (100%) rename config.def.h => src/config.def.h (100%) rename config.h => src/config.h (100%) create mode 100644 src/st/CMakeLists.txt rename {st => src/st}/st.c (100%) rename {st => src/st}/st.h (100%) rename win.h => src/win.h (100%) rename x.c => src/x.c (100%) diff --git a/arg.h b/src/arg.h similarity index 100% rename from arg.h rename to src/arg.h diff --git a/config.def.h b/src/config.def.h similarity index 100% rename from config.def.h rename to src/config.def.h diff --git a/config.h b/src/config.h similarity index 100% rename from config.h rename to src/config.h diff --git a/src/st/CMakeLists.txt b/src/st/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/st/st.c b/src/st/st.c similarity index 100% rename from st/st.c rename to src/st/st.c diff --git a/st/st.h b/src/st/st.h similarity index 100% rename from st/st.h rename to src/st/st.h diff --git a/win.h b/src/win.h similarity index 100% rename from win.h rename to src/win.h diff --git a/x.c b/src/x.c similarity index 100% rename from x.c rename to src/x.c From 4e5a59b34d9021aab09001c7ad37008acb606c08 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 5 Nov 2020 17:02:06 +0100 Subject: [PATCH 04/14] Added working CMake build (#1) --- .gitignore | 5 +++++ src/CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++ src/st/CMakeLists.txt | 0 src/st/st.c | 2 +- src/x.c | 4 ++-- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/CMakeLists.txt delete mode 100644 src/st/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 75af8f0..d4b250e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ CMakeCache.txt CMakeFiles/ cmake_install.cmake +compile_commands.json +Makefile + +# Final binary +stj diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f5703c7 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.0) + +set(CMAKE_C_COMPILER "clang") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project(stj VERSION 0.1) + +file(GLOB st_SRC "st/*.c" "st/*.h") +file(GLOB main_SRC "*.c" "*.h") + +add_executable(stj x.c "${st_SRC}" "${main_SRC}") + +# Find required packages +# Store Find*.cmake files in ./cmake +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/") + +find_package(Freetype 2 REQUIRED) +target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}") +target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}") + +find_package(Fontconfig REQUIRED) +target_include_directories(stj PRIVATE "${Fontconfig_INCLUDE_DIRS}") +target_link_libraries(stj PRIVATE "${Fontconfig_LIBRARIES}") + +find_package(X11 REQUIRED) +target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}") +target_link_libraries(stj PRIVATE "${X11_LIBRARIES}") + +# Needed to work; copied from original Makefile +target_link_libraries(stj PRIVATE m) +target_link_libraries(stj PRIVATE rt) +target_link_libraries(stj PRIVATE util) +target_link_libraries(stj PRIVATE Xft) +target_link_libraries(stj PRIVATE Xrender) + +# Add version as flag +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVERSION=\"${CMAKE_PROJECT_VERSION}\"") diff --git a/src/st/CMakeLists.txt b/src/st/CMakeLists.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/st/st.c b/src/st/st.c index abbbe4b..5758702 100644 --- a/src/st/st.c +++ b/src/st/st.c @@ -18,7 +18,7 @@ #include #include "st.h" -#include "win.h" +#include "../win.h" #if defined(__linux) #include diff --git a/src/x.c b/src/x.c index 120e495..f973a1d 100644 --- a/src/x.c +++ b/src/x.c @@ -17,7 +17,7 @@ char *argv0; #include "arg.h" -#include "st.h" +#include "st/st.h" #include "win.h" /* types used in config.h */ @@ -2036,7 +2036,7 @@ main(int argc, char *argv[]) opt_embed = EARGF(usage()); break; case 'v': - die("%s " VERSION "\n", argv0); + die("%s %s \n", argv0, VERSION); break; default: usage(); From 9fca78f0dd5c80ae7f7f960c3c898c2a9b1b0a78 Mon Sep 17 00:00:00 2001 From: --unset <--unset> Date: Thu, 5 Nov 2020 17:49:05 +0100 Subject: [PATCH 05/14] Changed compiler to clang-10 --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5703c7..fe81d48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -set(CMAKE_C_COMPILER "clang") +set(CMAKE_C_COMPILER "clang-10") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project(stj VERSION 0.1) From 68ce8a39144e339648ac30816e855d2c1f2cd63b Mon Sep 17 00:00:00 2001 From: --unset <--unset> Date: Thu, 5 Nov 2020 18:00:50 +0100 Subject: [PATCH 06/14] Added header guards; fixed linter errors --- src/arg.h | 4 ++-- src/st/st.h | 6 ++++++ src/win.h | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/arg.h b/src/arg.h index a22e019..dbdef84 100644 --- a/src/arg.h +++ b/src/arg.h @@ -3,8 +3,8 @@ * by 20h */ -#ifndef ARG_H__ -#define ARG_H__ +#ifndef ARG_H +#define ARG_H extern char *argv0; diff --git a/src/st/st.h b/src/st/st.h index 3d351b6..1750b14 100644 --- a/src/st/st.h +++ b/src/st/st.h @@ -1,7 +1,11 @@ /* See LICENSE for license details. */ +#ifndef ST_H +#define ST_H + #include #include +#include /* macros */ #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -123,3 +127,5 @@ extern char *termname; extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; + +#endif diff --git a/src/win.h b/src/win.h index e6e4369..1d6e355 100644 --- a/src/win.h +++ b/src/win.h @@ -1,5 +1,10 @@ /* See LICENSE for license details. */ +#ifndef WIN_H +#define WIN_H + +#include "st/st.h" + enum win_mode { MODE_VISIBLE = 1 << 0, MODE_FOCUSED = 1 << 1, @@ -38,3 +43,5 @@ void xsetpointermotion(int); void xsetsel(char *); int xstartdraw(void); void xximspot(int, int); + +#endif From 6a203b3fe575c731a7b805977f96a9ddee08fff6 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 5 Nov 2020 18:21:52 +0100 Subject: [PATCH 07/14] Switched to C11; added release types --- src/CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe81d48..5b0c49a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,26 @@ cmake_minimum_required(VERSION 3.0) +# Use Release as default type +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +# Set Compiler set(CMAKE_C_COMPILER "clang-10") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project(stj VERSION 0.1) +# List all files needed in final binary file(GLOB st_SRC "st/*.c" "st/*.h") file(GLOB main_SRC "*.c" "*.h") add_executable(stj x.c "${st_SRC}" "${main_SRC}") -# Find required packages -# Store Find*.cmake files in ./cmake -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/") +# Set the standard to C11 +set_property(TARGET stj PROPERTY C_STANDARD 11) +# Find required packages find_package(Freetype 2 REQUIRED) target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}") target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}") From d83fb29d6be5672cbfdaa4998fc1e9bf14768dbf Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 6 Nov 2020 13:03:16 +0100 Subject: [PATCH 08/14] Added Makefile cmake wrapper --- .gitignore | 12 +++--------- Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++++ config.mk | 35 ----------------------------------- src/CMakeLists.txt | 13 +++++++++---- 4 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 Makefile delete mode 100644 config.mk diff --git a/.gitignore b/.gitignore index d4b250e..87ca7d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,7 @@ # IDE Directories .vim/ -.vscode/ -# CMake files -CMakeCache.txt -CMakeFiles/ -cmake_install.cmake -compile_commands.json -Makefile +# CMake build dir +build/ -# Final binary -stj +# compile_commands.json symlink diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e9a9b9 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +SRC_DIR=src +RELEASE_DIR=build/release +DEBUG_DIR=build/debug + +all: debug +.PHONY: all + + +clean: + @ rm -rf build +.PHONY: clean + + +# Release +run-release: release + @ ./$(RELEASE_DIR) +.PHONY: run-release + +release: $(RELEASE_DIR)/Makefile + @ make -C $(RELEASE_DIR) +.PHONY: release + +$(RELEASE_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt + @ cmake -H$(SRC_DIR) -B$(RELEASE_DIR) -DCMAKE_BUILD_TYPE=Release + +clean-release: + @ rm -rf build/release +.PHONY: clean-release + + +# Debug +run-debug: debug + @ ./$(DEBUG_DIR) +.PHONY: run-debug + +debug: $(DEBUG_DIR)/Makefile + @ make -C $(DEBUG_DIR) +.PHONY: debug + +$(DEBUG_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt + @ cmake -H$(SRC_DIR) -B$(DEBUG_DIR) -DCMAKE_BUILD_TYPE=Debug + +clean-debug: + @ rm -rf build/debug +.PHONY: clean-debug diff --git a/config.mk b/config.mk deleted file mode 100644 index c070a4a..0000000 --- a/config.mk +++ /dev/null @@ -1,35 +0,0 @@ -# st version -VERSION = 0.8.4 - -# Customize below to fit your system - -# 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 fontconfig` \ - `$(PKG_CONFIG) --cflags freetype2` -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ - `$(PKG_CONFIG) --libs fontconfig` \ - `$(PKG_CONFIG) --libs freetype2` - -# flags -STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS) -STLDFLAGS = $(LIBS) $(LDFLAGS) - -# OpenBSD: -#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \ -# `$(PKG_CONFIG) --libs fontconfig` \ -# `$(PKG_CONFIG) --libs freetype2` - -# compiler and linker -# CC = c99 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b0c49a..5f96dec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,9 +5,17 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +# Set build dirs (keeps things clean) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # TODO add adress sanitizer flags n stuff +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + # TODO add optimization flags +endif() + # Set Compiler set(CMAKE_C_COMPILER "clang-10") -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_STANDARD 11) project(stj VERSION 0.1) @@ -17,9 +25,6 @@ file(GLOB main_SRC "*.c" "*.h") add_executable(stj x.c "${st_SRC}" "${main_SRC}") -# Set the standard to C11 -set_property(TARGET stj PROPERTY C_STANDARD 11) - # Find required packages find_package(Freetype 2 REQUIRED) target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}") From 209f27d1145cf18e6462a53381891f35404694d9 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 6 Nov 2020 13:33:21 +0100 Subject: [PATCH 09/14] Split macros into own header file --- .gitignore | 1 + src/st/macros.h | 20 ++++++++++++++++++++ src/st/st.c | 1 + src/st/st.h | 17 ----------------- src/x.c | 1 + 5 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 src/st/macros.h diff --git a/.gitignore b/.gitignore index 87ca7d5..497082c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/ # compile_commands.json symlink +compile_commands.json diff --git a/src/st/macros.h b/src/st/macros.h new file mode 100644 index 0000000..a272a2f --- /dev/null +++ b/src/st/macros.h @@ -0,0 +1,20 @@ +#ifndef MACROS_H +#define MACROS_H + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) < (b) ? (b) : (a)) +#define LEN(a) (sizeof(a) / sizeof(a)[0]) +#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) +#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) ((a).mode != (b).mode || (a).fg != (b).fg || \ + (a).bg != (b).bg) +#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ + (t1.tv_nsec-t2.tv_nsec)/1E6) +#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) + +#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) +#define IS_TRUECOL(x) (1 << 24 & (x)) + +#endif diff --git a/src/st/st.c b/src/st/st.c index 5758702..44bfd1d 100644 --- a/src/st/st.c +++ b/src/st/st.c @@ -18,6 +18,7 @@ #include #include "st.h" +#include "macros.h" #include "../win.h" #if defined(__linux) diff --git a/src/st/st.h b/src/st/st.h index 1750b14..19924bd 100644 --- a/src/st/st.h +++ b/src/st/st.h @@ -7,23 +7,6 @@ #include #include -/* macros */ -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a) / sizeof(a)[0]) -#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) -#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) ((a).mode != (b).mode || (a).fg != (b).fg || \ - (a).bg != (b).bg) -#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ - (t1.tv_nsec-t2.tv_nsec)/1E6) -#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) - -#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) -#define IS_TRUECOL(x) (1 << 24 & (x)) - enum glyph_attribute { ATTR_NULL = 0, ATTR_BOLD = 1 << 0, diff --git a/src/x.c b/src/x.c index f973a1d..c93f126 100644 --- a/src/x.c +++ b/src/x.c @@ -18,6 +18,7 @@ char *argv0; #include "arg.h" #include "st/st.h" +#include "st/macros.h" #include "win.h" /* types used in config.h */ From 66093b4858ae60521de1c1779cb0168476b88f5b Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 6 Nov 2020 15:45:41 +0100 Subject: [PATCH 10/14] Added extra compiler flags --- Makefile | 11 ++++++----- src/CMakeLists.txt | 36 ++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 0e9a9b9..a3d2a4c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ -SRC_DIR=src -RELEASE_DIR=build/release -DEBUG_DIR=build/debug +SRC_DIR = src +RELEASE_DIR = build/release +DEBUG_DIR = build/debug +BINARY = stj all: debug .PHONY: all @@ -13,7 +14,7 @@ clean: # Release run-release: release - @ ./$(RELEASE_DIR) + @ ./$(RELEASE_DIR)/$(BINARY) .PHONY: run-release release: $(RELEASE_DIR)/Makefile @@ -30,7 +31,7 @@ clean-release: # Debug run-debug: debug - @ ./$(DEBUG_DIR) + @ ./$(DEBUG_DIR)/$(BINARY) .PHONY: run-debug debug: $(DEBUG_DIR)/Makefile diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f96dec..820e61d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,27 +5,39 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Set build dirs (keeps things clean) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - # TODO add adress sanitizer flags n stuff -elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - # TODO add optimization flags -endif() +# Create compile_commands.json +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# Set Compiler + +# =====COMPILER===== set(CMAKE_C_COMPILER "clang-10") set(CMAKE_C_STANDARD 11) + project(stj VERSION 0.1) -# List all files needed in final binary + +# =====COMPILE FLAGS===== +# General flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVERSION=\"${CMAKE_PROJECT_VERSION}\"") + +# Debug flags +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -O0 -march=native") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + +# Release flags +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Werror -march=native") + + +# =====EXECUTABLE===== file(GLOB st_SRC "st/*.c" "st/*.h") file(GLOB main_SRC "*.c" "*.h") add_executable(stj x.c "${st_SRC}" "${main_SRC}") -# Find required packages + +# =====PACKAGES & LIBRARIES===== find_package(Freetype 2 REQUIRED) target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}") target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}") @@ -38,12 +50,8 @@ find_package(X11 REQUIRED) target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}") target_link_libraries(stj PRIVATE "${X11_LIBRARIES}") -# Needed to work; copied from original Makefile target_link_libraries(stj PRIVATE m) target_link_libraries(stj PRIVATE rt) target_link_libraries(stj PRIVATE util) target_link_libraries(stj PRIVATE Xft) target_link_libraries(stj PRIVATE Xrender) - -# Add version as flag -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVERSION=\"${CMAKE_PROJECT_VERSION}\"") From 584bcb94d152ebe1e582c6dc872d3657a295c423 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 7 Nov 2020 14:49:29 +0100 Subject: [PATCH 11/14] Fixed implicit method; some refactoring --- Makefile | 20 +++++---- src/CMakeLists.txt | 11 ++--- src/st/st.c | 104 +++++++++++++++++++++++---------------------- src/st/st.h | 6 +-- src/x.c | 12 +++--- 5 files changed, 80 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index a3d2a4c..71b7545 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ -SRC_DIR = src -RELEASE_DIR = build/release -DEBUG_DIR = build/debug -BINARY = stj +SRC_DIR := src +BUILD_DIR := build +RELEASE_DIR := $(BUILD_DIR)/release +DEBUG_DIR := $(BUILD_DIR)/debug +BINARY := stj +CORES := $(shell nproc --all) all: debug .PHONY: all clean: - @ rm -rf build + @ rm -rf $(BUILD_DIR) .PHONY: clean @@ -18,14 +20,14 @@ run-release: release .PHONY: run-release release: $(RELEASE_DIR)/Makefile - @ make -C $(RELEASE_DIR) + @ make -C $(RELEASE_DIR) -j$(CORES) .PHONY: release $(RELEASE_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt @ cmake -H$(SRC_DIR) -B$(RELEASE_DIR) -DCMAKE_BUILD_TYPE=Release clean-release: - @ rm -rf build/release + @ rm -rf $(RELEASE_DIR) .PHONY: clean-release @@ -35,12 +37,12 @@ run-debug: debug .PHONY: run-debug debug: $(DEBUG_DIR)/Makefile - @ make -C $(DEBUG_DIR) + @ make -C $(DEBUG_DIR) -j$(CORES) .PHONY: debug $(DEBUG_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt @ cmake -H$(SRC_DIR) -B$(DEBUG_DIR) -DCMAKE_BUILD_TYPE=Debug clean-debug: - @ rm -rf build/debug + @ rm -rf $(DEBUG_DIR) .PHONY: clean-debug diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 820e61d..adca3d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,16 +18,17 @@ project(stj VERSION 0.1) # =====COMPILE FLAGS===== -# General flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVERSION=\"${CMAKE_PROJECT_VERSION}\"") +add_definitions(-DVERSION="${CMAKE_PROJECT_VERSION}" -D_XOPEN_SOURCE=600) # Debug flags -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -O0 -march=native") +# -g flag gets auto-added by CMake for the debug build +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0 -march=native") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") -set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -pedantic") # Release flags -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Werror -march=native") +# -O3 gets added automatically by CMake +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror -march=native -pedantic-errors") # =====EXECUTABLE===== diff --git a/src/st/st.c b/src/st/st.c index 44bfd1d..3db43fe 100644 --- a/src/st/st.c +++ b/src/st/st.c @@ -31,8 +31,8 @@ /* Arbitrary sizes */ #define UTF_INVALID 0xFFFD -#define UTF_SIZ 4 -#define ESC_BUF_SIZ (128*UTF_SIZ) +#define UTF_SIZE 4 +#define ESC_BUF_SIZ (128*UTF_SIZE) #define ESC_ARG_SIZ 16 #define STR_BUF_SIZ ESC_BUF_SIZ #define STR_ARG_SIZ ESC_ARG_SIZ @@ -227,50 +227,51 @@ static int iofd = 1; static int cmdfd; static pid_t pid; -static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; -static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; -static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; -static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +static uchar utfbyte[UTF_SIZE + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; +static uchar utfmask[UTF_SIZE + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; +static Rune utfmin[UTF_SIZE + 1] = { 0, 0, 0x80, 0x800, 0x10000}; +static Rune utfmax[UTF_SIZE + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; -ssize_t -xwrite(int fd, const char *s, size_t len) +ssize_t xwrite(int fd, const char* s, size_t len) { size_t aux = len; - ssize_t r; + ssize_t result; while (len > 0) { - r = write(fd, s, len); - if (r < 0) - return r; - len -= r; - s += r; + result = write(fd, s, len); + + // This means an error occured in write, so it passes the error along + if (result < 0) + return result; + + len -= result; + s += result; } return aux; } -void * -xmalloc(size_t len) +// Same as malloc, but stops entire program if malloc fails +void* safe_malloc(size_t len) { - void *p; + void *ptr; - if (!(p = malloc(len))) + if (!(ptr = malloc(len))) die("malloc: %s\n", strerror(errno)); - return p; + return ptr; } -void * -xrealloc(void *p, size_t len) +// Same as realloc, but stops entire program if malloc fails +void* safe_realloc(void* ptr, size_t len) { - if ((p = realloc(p, len)) == NULL) + if ((ptr = realloc(ptr, len)) == NULL) die("realloc: %s\n", strerror(errno)); - return p; + return ptr; } -char * -xstrdup(char *s) +char * safe_strdup(char* s) { if ((s = strdup(s)) == NULL) die("strdup: %s\n", strerror(errno)); @@ -278,25 +279,28 @@ xstrdup(char *s) return s; } -size_t -utf8decode(const char *c, Rune *u, size_t clen) +size_t utf8decode(const char* chr, Rune* u, size_t chr_len) { size_t i, j, len, type; Rune udecoded; *u = UTF_INVALID; - if (!clen) + if (!chr_len) // chr_len is 0, so just return 0 return 0; - udecoded = utf8decodebyte(c[0], &len); - if (!BETWEEN(len, 1, UTF_SIZ)) + + udecoded = utf8decodebyte(chr[0], &len); + if (!BETWEEN(len, 1, UTF_SIZE)) return 1; - for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { - udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); + + for (i = 1, j = 1; i < chr_len && j < len; ++i, ++j) { + udecoded = (udecoded << 6) | utf8decodebyte(chr[i], &type); if (type != 0) return j; } + if (j < len) return 0; + *u = udecoded; utf8validate(u, len); @@ -319,7 +323,7 @@ utf8encode(Rune u, char *c) size_t len, i; len = utf8validate(&u, 0); - if (len > UTF_SIZ) + if (len > UTF_SIZE) return 0; for (i = len - 1; i != 0; --i) { @@ -379,7 +383,7 @@ base64dec(const char *src) if (in_len % 4) in_len += 4 - (in_len % 4); - result = dst = xmalloc(in_len / 4 * 3 + 1); + result = dst = safe_malloc(in_len / 4 * 3 + 1); while (*src) { int a = base64_digits[(unsigned char) base64dec_getc(&src)]; int b = base64_digits[(unsigned char) base64dec_getc(&src)]; @@ -597,8 +601,8 @@ getsel(void) if (sel.ob.x == -1) return NULL; - bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ; - ptr = str = xmalloc(bufsize); + bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZE; + ptr = str = safe_malloc(bufsize); /* append every set & selected glyph to the selection */ for (y = sel.nb.y; y <= sel.ne.y; y++) { @@ -1205,7 +1209,7 @@ tsetchar(Rune u, Glyph *attr, int x, int y) */ if (term.trantbl[term.charset] == CS_GRAPHIC0 && BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41]) - utf8decode(vt100_0[u - 0x41], &u, UTF_SIZ); + utf8decode(vt100_0[u - 0x41], &u, UTF_SIZE); if (term.line[y][x].mode & ATTR_WIDE) { if (x+1 < term.col) { @@ -1966,7 +1970,7 @@ void strreset(void) { strescseq = (STREscape){ - .buf = xrealloc(strescseq.buf, STR_BUF_SIZ), + .buf = safe_realloc(strescseq.buf, STR_BUF_SIZ), .siz = STR_BUF_SIZ, }; } @@ -2020,7 +2024,7 @@ tdumpsel(void) void tdumpline(int n) { - char buf[UTF_SIZ]; + char buf[UTF_SIZE]; Glyph *bp, *end; bp = &term.line[n][0]; @@ -2303,7 +2307,7 @@ eschandle(uchar ascii) void tputc(Rune u) { - char c[UTF_SIZ]; + char c[UTF_SIZE]; int control; int width, len; Glyph *gp; @@ -2349,10 +2353,10 @@ tputc(Rune u) * term.esc = 0; * strhandle(); */ - if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2) + if (strescseq.siz > (SIZE_MAX - UTF_SIZE) / 2) return; strescseq.siz *= 2; - strescseq.buf = xrealloc(strescseq.buf, strescseq.siz); + strescseq.buf = safe_realloc(strescseq.buf, strescseq.siz); } memmove(&strescseq.buf[strescseq.len], c, len); @@ -2505,21 +2509,21 @@ tresize(int col, int row) } /* resize to new height */ - term.line = xrealloc(term.line, row * sizeof(Line)); - term.alt = xrealloc(term.alt, row * sizeof(Line)); - term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty)); - term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs)); + term.line = safe_realloc(term.line, row * sizeof(Line)); + term.alt = safe_realloc(term.alt, row * sizeof(Line)); + term.dirty = safe_realloc(term.dirty, row * sizeof(*term.dirty)); + term.tabs = safe_realloc(term.tabs, col * sizeof(*term.tabs)); /* resize each row to new width, zero-pad if needed */ for (i = 0; i < minrow; i++) { - term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); - term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph)); + term.line[i] = safe_realloc(term.line[i], col * sizeof(Glyph)); + term.alt[i] = safe_realloc(term.alt[i], col * sizeof(Glyph)); } /* allocate any new rows */ for (/* i = minrow */; i < row; i++) { - term.line[i] = xmalloc(col * sizeof(Glyph)); - term.alt[i] = xmalloc(col * sizeof(Glyph)); + term.line[i] = safe_malloc(col * sizeof(Glyph)); + term.alt[i] = safe_malloc(col * sizeof(Glyph)); } if (col > term.col) { bp = term.tabs + term.col; diff --git a/src/st/st.h b/src/st/st.h index 19924bd..aca352c 100644 --- a/src/st/st.h +++ b/src/st/st.h @@ -94,9 +94,9 @@ char *getsel(void); size_t utf8encode(Rune, char *); -void *xmalloc(size_t); -void *xrealloc(void *, size_t); -char *xstrdup(char *); +void *safe_malloc(size_t); +void *safe_realloc(void *, size_t); +char *safe_strdup(char *); /* config.h globals */ extern char *utmp; diff --git a/src/x.c b/src/x.c index c93f126..635cfbd 100644 --- a/src/x.c +++ b/src/x.c @@ -264,7 +264,7 @@ clipcopy(const Arg *dummy) xsel.clipboard = NULL; if (xsel.primary != NULL) { - xsel.clipboard = xstrdup(xsel.primary); + xsel.clipboard = safe_strdup(xsel.primary); clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime); } @@ -740,7 +740,7 @@ xresize(int col, int row) xclear(0, 0, win.w, win.h); /* resize to new width */ - xw.specbuf = xrealloc(xw.specbuf, col * sizeof(GlyphFontSpec)); + xw.specbuf = safe_realloc(xw.specbuf, col * sizeof(GlyphFontSpec)); } ushort @@ -785,7 +785,7 @@ xloadcols(void) XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); } else { dc.collen = MAX(LEN(colorname), 256); - dc.col = xmalloc(dc.collen * sizeof(Color)); + dc.col = safe_malloc(dc.collen * sizeof(Color)); } for (i = 0; i < dc.collen; i++) @@ -1155,7 +1155,7 @@ xinit(int cols, int rows) XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); /* font spec buffer */ - xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec)); + xw.specbuf = safe_malloc(cols * sizeof(GlyphFontSpec)); /* Xft rendering context */ xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); @@ -1310,7 +1310,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x /* Allocate memory for the new cache entry. */ if (frclen >= frccap) { frccap += 16; - frc = xrealloc(frc, frccap * sizeof(Fontcache)); + frc = safe_realloc(frc, frccap * sizeof(Fontcache)); } frc[frclen].font = XftFontOpenPattern(xw.dpy, @@ -2037,7 +2037,7 @@ main(int argc, char *argv[]) opt_embed = EARGF(usage()); break; case 'v': - die("%s %s \n", argv0, VERSION); + die("%s\n", VERSION); break; default: usage(); From 7c43bcb2d869b3d59b31a88854a66749010fc28f Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 7 Nov 2020 15:29:13 +0100 Subject: [PATCH 12/14] Tidied up Makefile; fixed compile commands not generating --- Makefile | 29 ++++++++++++++++++++--------- src/CMakeLists.txt | 3 --- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 71b7545..ff79c54 100644 --- a/Makefile +++ b/Makefile @@ -10,39 +10,50 @@ all: debug clean: - @ rm -rf $(BUILD_DIR) + @ [ ! -e '$(BINARY)' ] || rm '$(BINARY)' + @ rm -rf '$(BUILD_DIR)' .PHONY: clean # Release run-release: release - @ ./$(RELEASE_DIR)/$(BINARY) + @ ./'$(RELEASE_DIR)/$(BINARY)' .PHONY: run-release release: $(RELEASE_DIR)/Makefile - @ make -C $(RELEASE_DIR) -j$(CORES) + @ make -C '$(RELEASE_DIR)' -j'$(CORES)' && \ + ln -sf '$(RELEASE_DIR)'/'$(BINARY)' ./'$(BINARY)' .PHONY: release $(RELEASE_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt - @ cmake -H$(SRC_DIR) -B$(RELEASE_DIR) -DCMAKE_BUILD_TYPE=Release + @ cmake \ + -H'$(SRC_DIR)' \ + -B'$(RELEASE_DIR)' \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON clean-release: - @ rm -rf $(RELEASE_DIR) + @ rm -rf '$(RELEASE_DIR)' .PHONY: clean-release # Debug run-debug: debug - @ ./$(DEBUG_DIR)/$(BINARY) + @ ./'$(DEBUG_DIR)/$(BINARY)' .PHONY: run-debug debug: $(DEBUG_DIR)/Makefile - @ make -C $(DEBUG_DIR) -j$(CORES) + @ make -C '$(DEBUG_DIR)' -j'$(CORES)' && \ + ln -sf '$(DEBUG_DIR)/$(BINARY)' ./'$(BINARY)' .PHONY: debug $(DEBUG_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt - @ cmake -H$(SRC_DIR) -B$(DEBUG_DIR) -DCMAKE_BUILD_TYPE=Debug + @ cmake \ + -H'$(SRC_DIR)' \ + -B'$(DEBUG_DIR)' \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON clean-debug: - @ rm -rf $(DEBUG_DIR) + @ rm -rf '$(DEBUG_DIR)' .PHONY: clean-debug diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index adca3d1..b26713d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,9 +5,6 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Create compile_commands.json -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - # =====COMPILER===== set(CMAKE_C_COMPILER "clang-10") From fad6ca04a90d4335a1e50bb70fc9ea31f07de013 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 14 Nov 2020 16:38:09 +0100 Subject: [PATCH 13/14] Updated gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 497082c..5dbe8e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,8 @@ # CMake build dir build/ +# Final executable symlink +stj + # compile_commands.json symlink compile_commands.json From cbefc58bb08f54fd6c46636caaa38e5f29e533cf Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 14 Nov 2020 17:30:54 +0100 Subject: [PATCH 14/14] Added install & uninstall; added desktop entry --- Makefile | 20 ++++++++++++++++++++ data/{st.1 => stj.1} | 0 data/stj.desktop | 7 +++++++ data/{st.info => stj.info} | 0 4 files changed, 27 insertions(+) rename data/{st.1 => stj.1} (100%) create mode 100644 data/stj.desktop rename data/{st.info => stj.info} (100%) diff --git a/Makefile b/Makefile index ff79c54..0e49af7 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,31 @@ RELEASE_DIR := $(BUILD_DIR)/release DEBUG_DIR := $(BUILD_DIR)/debug BINARY := stj CORES := $(shell nproc --all) +PREFIX := /usr/local +MANPREFIX := $(PREFIX)/share/man all: debug .PHONY: all +# Installation & removal +install: release + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f build/release/stj $(DESTDIR)$(PREFIX)/bin + chmod 755 $(DESTDIR)$(PREFIX)/bin/stj + mkdir -p $(DESTDIR)$(MANPREFIX)/man1 + sed "s/VERSION/$(VERSION)/g" < data/stj.1 > $(DESTDIR)$(MANPREFIX)/man1/stj.1 + chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stj.1 + tic -sx data/stj.info + cp -f data/stj.desktop $(DESTDIR)$(PREFIX)/share/applications + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/stj + rm -f $(DESTDIR)$(MANPREFIX)/man1/stj.1 + rm -f $(DESTDIR)$(PREFIX)/share/applications/stj.desktop + + +# Full clean clean: @ [ ! -e '$(BINARY)' ] || rm '$(BINARY)' @ rm -rf '$(BUILD_DIR)' diff --git a/data/st.1 b/data/stj.1 similarity index 100% rename from data/st.1 rename to data/stj.1 diff --git a/data/stj.desktop b/data/stj.desktop new file mode 100644 index 0000000..db543c9 --- /dev/null +++ b/data/stj.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=stj +Comment=Jef's build of the st terminal +Icon=utilities-terminal +Exec=stj +Categories=System;TerminalEmulator diff --git a/data/st.info b/data/stj.info similarity index 100% rename from data/st.info rename to data/stj.info