Added correct formatting; started docstrings; added min size rel build

develop
Jef Roosens 2020-12-02 12:40:21 +01:00
parent 32184c498c
commit 1052dd6244
6 changed files with 1970 additions and 1909 deletions

1
.clang-format 100644
View File

@ -0,0 +1 @@
IndentWidth: 4

100
Makefile
View File

@ -1,17 +1,20 @@
SRC_DIR := src # =====CONFIG=====
BUILD_DIR := build SRC_DIR := src
RELEASE_DIR := $(BUILD_DIR)/release BUILD_DIR := build
DEBUG_DIR := $(BUILD_DIR)/debug RELEASE_DIR := $(BUILD_DIR)/release
BINARY := stj DEBUG_DIR := $(BUILD_DIR)/debug
CORES := $(shell nproc --all) MINSIZEREL_DIR := $(BUILD_DIR)/min_size_rel
PREFIX := /usr/local BINARY := stj
MANPREFIX := $(PREFIX)/share/man CORES := $(shell nproc --all)
PREFIX := /usr/local
MANPREFIX := $(PREFIX)/share/man
all: debug all: debug
.PHONY: all .PHONY: all
# Installation & removal # =====INSTALL & UNINSTALL=====
install: release install: release
mkdir -p $(DESTDIR)$(PREFIX)/bin mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f build/release/stj $(DESTDIR)$(PREFIX)/bin cp -f build/release/stj $(DESTDIR)$(PREFIX)/bin
@ -21,47 +24,16 @@ install: release
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stj.1 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stj.1
tic -sx data/stj.info tic -sx data/stj.info
cp -f data/stj.desktop $(DESTDIR)$(PREFIX)/share/applications cp -f data/stj.desktop $(DESTDIR)$(PREFIX)/share/applications
.PHONY: install
uninstall: uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/stj rm -f $(DESTDIR)$(PREFIX)/bin/stj
rm -f $(DESTDIR)$(MANPREFIX)/man1/stj.1 rm -f $(DESTDIR)$(MANPREFIX)/man1/stj.1
rm -f $(DESTDIR)$(PREFIX)/share/applications/stj.desktop rm -f $(DESTDIR)$(PREFIX)/share/applications/stj.desktop
.PHONY: uninstall
# Full clean # =====DEBUG=====
clean:
@ [ ! -e '$(BINARY)' ] || rm '$(BINARY)'
@ rm -rf '$(BUILD_DIR)'
.PHONY: clean
# Release
run-release: release
@ ./'$(RELEASE_DIR)/$(BINARY)'
.PHONY: run-release
release: $(RELEASE_DIR)/Makefile
@ 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 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
clean-release:
@ rm -rf '$(RELEASE_DIR)'
.PHONY: clean-release
# Debug
run-debug: debug
@ ./'$(DEBUG_DIR)/$(BINARY)'
.PHONY: run-debug
debug: $(DEBUG_DIR)/Makefile debug: $(DEBUG_DIR)/Makefile
@ make -C '$(DEBUG_DIR)' -j'$(CORES)' && \ @ make -C '$(DEBUG_DIR)' -j'$(CORES)' && \
ln -sf '$(DEBUG_DIR)/$(BINARY)' ./'$(BINARY)' ln -sf '$(DEBUG_DIR)/$(BINARY)' ./'$(BINARY)'
@ -74,6 +46,48 @@ $(DEBUG_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt
-DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# =====RELEASE=====
release: $(RELEASE_DIR)/Makefile
@ 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 \
# =====MINIMUM SIZE RELEASE=====
minsizerel: $(MINSIZEREL_DIR)/Makefile
@ make -C '$(MINSIZEREL_DIR)' -j'$(CORES)' && \
ln -sf '$(MINSIZEREL_DIR)'/'$(BINARY)' ./'$(BINARY)'
.PHONY: minsizerel
$(MINSIZEREL_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt
@ cmake \
-H'$(SRC_DIR)' \
-B'$(MINSIZEREL_DIR)' \
-DCMAKE_BUILD_TYPE=MinSizeRel \
# =====CLEANING=====
clean:
@ [ ! -e '$(BINARY)' ] || rm '$(BINARY)'
@ rm -rf '$(BUILD_DIR)'
.PHONY: clean
clean-release:
@ rm -rf '$(RELEASE_DIR)'
.PHONY: clean-release
clean-debug: clean-debug:
@ rm -rf '$(DEBUG_DIR)' @ rm -rf '$(DEBUG_DIR)'
.PHONY: clean-debug .PHONY: clean-debug
# =====FORMAT CODE=====
format:
@ clang-format -i --style=file src/**/*.c src/**/*.h

View File

@ -5,6 +5,8 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
endif() endif()
set(SYSTEM_TYPE x64)
# =====COMPILER===== # =====COMPILER=====
set(CMAKE_C_COMPILER "clang-11") set(CMAKE_C_COMPILER "clang-11")
@ -19,13 +21,21 @@ add_definitions(-DVERSION="${CMAKE_PROJECT_VERSION}" -D_XOPEN_SOURCE=600)
# Debug flags # Debug flags
# -g flag gets auto-added by CMake for the debug build # -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} -g -Weverything -O0 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -pedantic")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -pedantic")
# Arch doesn't use static libraries
if(NOT EXISTS "/etc/arch-release")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -static-libasan")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -static-libasan")
endif()
# Release flags # Release flags
# -O3 gets added automatically by CMake set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Werror -pedantic-errors")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror -march=native -pedantic-errors")
# MinSizeRel flags
# This one's just here for fun
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Oz -Werror -pedantic-errors")
# =====EXECUTABLE===== # =====EXECUTABLE=====
@ -39,8 +49,10 @@ add_executable(stj x.c "${st_SRC}" "${main_SRC}")
find_package(Freetype 2 REQUIRED) find_package(Freetype 2 REQUIRED)
target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}") target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}")
target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}") target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}")
target_link_libraries(stj PRIVATE Xft)
target_link_libraries(stj PRIVATE Xrender)
find_package(Fontconfig REQUIRED) find_package(Fontconfig 2 REQUIRED)
target_include_directories(stj PRIVATE "${Fontconfig_INCLUDE_DIRS}") target_include_directories(stj PRIVATE "${Fontconfig_INCLUDE_DIRS}")
target_link_libraries(stj PRIVATE "${Fontconfig_LIBRARIES}") target_link_libraries(stj PRIVATE "${Fontconfig_LIBRARIES}")
@ -48,8 +60,9 @@ find_package(X11 REQUIRED)
target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}") target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}")
target_link_libraries(stj PRIVATE "${X11_LIBRARIES}") target_link_libraries(stj PRIVATE "${X11_LIBRARIES}")
# Normally provided with clang
target_link_libraries(stj PRIVATE m) target_link_libraries(stj PRIVATE m)
target_link_libraries(stj PRIVATE rt) # I'm not sure if I actually need this, so keeping it here for reference
# target_link_libraries(stj PRIVATE rt)
target_link_libraries(stj PRIVATE util) target_link_libraries(stj PRIVATE util)
target_link_libraries(stj PRIVATE Xft)
target_link_libraries(stj PRIVATE Xrender)

View File

@ -9,9 +9,9 @@
#define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) \ #define ATTRCMP(a, b) \
((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define TIMEDIFF(t1, t2) \ #define TIMEDIFF(t1, t2) \
((t1.tv_sec - t2.tv_sec) * 1000 + (t1.tv_nsec - t2.tv_nsec) / 1E6) ((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 MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
#define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) #define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b))

File diff suppressed because it is too large Load Diff

View File

@ -3,41 +3,31 @@
#ifndef ST_H #ifndef ST_H
#define ST_H #define ST_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <stddef.h>
enum glyph_attribute { enum glyph_attribute {
ATTR_NULL = 0, ATTR_NULL = 0,
ATTR_BOLD = 1 << 0, ATTR_BOLD = 1 << 0,
ATTR_FAINT = 1 << 1, ATTR_FAINT = 1 << 1,
ATTR_ITALIC = 1 << 2, ATTR_ITALIC = 1 << 2,
ATTR_UNDERLINE = 1 << 3, ATTR_UNDERLINE = 1 << 3,
ATTR_BLINK = 1 << 4, ATTR_BLINK = 1 << 4,
ATTR_REVERSE = 1 << 5, ATTR_REVERSE = 1 << 5,
ATTR_INVISIBLE = 1 << 6, ATTR_INVISIBLE = 1 << 6,
ATTR_STRUCK = 1 << 7, ATTR_STRUCK = 1 << 7,
ATTR_WRAP = 1 << 8, ATTR_WRAP = 1 << 8,
ATTR_WIDE = 1 << 9, ATTR_WIDE = 1 << 9,
ATTR_WDUMMY = 1 << 10, ATTR_WDUMMY = 1 << 10,
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
}; };
enum selection_mode { enum selection_mode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 };
SEL_IDLE = 0,
SEL_EMPTY = 1,
SEL_READY = 2
};
enum selection_type { enum selection_type { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 };
SEL_REGULAR = 1,
SEL_RECTANGULAR = 2
};
enum selection_snap { enum selection_snap { SNAP_WORD = 1, SNAP_LINE = 2 };
SNAP_WORD = 1,
SNAP_LINE = 2
};
typedef unsigned char uchar; typedef unsigned char uchar;
typedef unsigned int uint; typedef unsigned int uint;
@ -48,20 +38,20 @@ typedef uint_least32_t Rune;
#define Glyph Glyph_ #define Glyph Glyph_
typedef struct { typedef struct {
Rune u; /* character code */ Rune u; /* character code */
ushort mode; /* attribute flags */ ushort mode; /* attribute flags */
uint32_t fg; /* foreground */ uint32_t fg; /* foreground */
uint32_t bg; /* background */ uint32_t bg; /* background */
} Glyph; } Glyph;
typedef Glyph *Line; typedef Glyph *Line;
typedef union { typedef union {
int i; int i;
uint ui; uint ui;
float f; float f;
const void *v; const void *v;
const char *s; const char *s;
} Arg; } Arg;
void die(const char *, ...); void die(const char *, ...);