Added correct formatting; started docstrings; added min size rel build
parent
32184c498c
commit
1052dd6244
|
@ -0,0 +1 @@
|
|||
IndentWidth: 4
|
100
Makefile
100
Makefile
|
@ -1,17 +1,20 @@
|
|||
SRC_DIR := src
|
||||
BUILD_DIR := build
|
||||
RELEASE_DIR := $(BUILD_DIR)/release
|
||||
DEBUG_DIR := $(BUILD_DIR)/debug
|
||||
BINARY := stj
|
||||
CORES := $(shell nproc --all)
|
||||
PREFIX := /usr/local
|
||||
MANPREFIX := $(PREFIX)/share/man
|
||||
# =====CONFIG=====
|
||||
SRC_DIR := src
|
||||
BUILD_DIR := build
|
||||
RELEASE_DIR := $(BUILD_DIR)/release
|
||||
DEBUG_DIR := $(BUILD_DIR)/debug
|
||||
MINSIZEREL_DIR := $(BUILD_DIR)/min_size_rel
|
||||
BINARY := stj
|
||||
CORES := $(shell nproc --all)
|
||||
PREFIX := /usr/local
|
||||
MANPREFIX := $(PREFIX)/share/man
|
||||
|
||||
|
||||
all: debug
|
||||
.PHONY: all
|
||||
|
||||
|
||||
# Installation & removal
|
||||
# =====INSTALL & UNINSTALL=====
|
||||
install: release
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f build/release/stj $(DESTDIR)$(PREFIX)/bin
|
||||
|
@ -21,47 +24,16 @@ install: release
|
|||
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stj.1
|
||||
tic -sx data/stj.info
|
||||
cp -f data/stj.desktop $(DESTDIR)$(PREFIX)/share/applications
|
||||
.PHONY: install
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/stj
|
||||
rm -f $(DESTDIR)$(MANPREFIX)/man1/stj.1
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/applications/stj.desktop
|
||||
.PHONY: uninstall
|
||||
|
||||
|
||||
# Full clean
|
||||
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: $(DEBUG_DIR)/Makefile
|
||||
@ make -C '$(DEBUG_DIR)' -j'$(CORES)' && \
|
||||
ln -sf '$(DEBUG_DIR)/$(BINARY)' ./'$(BINARY)'
|
||||
|
@ -74,6 +46,48 @@ $(DEBUG_DIR)/Makefile: $(SRC_DIR)/CMakeLists.txt
|
|||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-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:
|
||||
@ rm -rf '$(DEBUG_DIR)'
|
||||
.PHONY: clean-debug
|
||||
|
||||
|
||||
# =====FORMAT CODE=====
|
||||
format:
|
||||
@ clang-format -i --style=file src/**/*.c src/**/*.h
|
||||
|
|
|
@ -5,6 +5,8 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
set(SYSTEM_TYPE x64)
|
||||
|
||||
|
||||
# =====COMPILER=====
|
||||
set(CMAKE_C_COMPILER "clang-11")
|
||||
|
@ -19,13 +21,21 @@ add_definitions(-DVERSION="${CMAKE_PROJECT_VERSION}" -D_XOPEN_SOURCE=600)
|
|||
|
||||
# Debug flags
|
||||
# -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 -pedantic")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Weverything -O0 -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_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
|
||||
# -O3 gets added automatically by CMake
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror -march=native -pedantic-errors")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Werror -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=====
|
||||
|
@ -39,8 +49,10 @@ add_executable(stj x.c "${st_SRC}" "${main_SRC}")
|
|||
find_package(Freetype 2 REQUIRED)
|
||||
target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}")
|
||||
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_link_libraries(stj PRIVATE "${Fontconfig_LIBRARIES}")
|
||||
|
||||
|
@ -48,8 +60,9 @@ find_package(X11 REQUIRED)
|
|||
target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}")
|
||||
target_link_libraries(stj PRIVATE "${X11_LIBRARIES}")
|
||||
|
||||
# Normally provided with clang
|
||||
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 Xft)
|
||||
target_link_libraries(stj PRIVATE Xrender)
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
#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)
|
||||
((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)
|
||||
((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))
|
||||
|
|
3681
src/st/st.c
3681
src/st/st.c
File diff suppressed because it is too large
Load Diff
62
src/st/st.h
62
src/st/st.h
|
@ -3,41 +3,31 @@
|
|||
#ifndef ST_H
|
||||
#define ST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum glyph_attribute {
|
||||
ATTR_NULL = 0,
|
||||
ATTR_BOLD = 1 << 0,
|
||||
ATTR_FAINT = 1 << 1,
|
||||
ATTR_ITALIC = 1 << 2,
|
||||
ATTR_UNDERLINE = 1 << 3,
|
||||
ATTR_BLINK = 1 << 4,
|
||||
ATTR_REVERSE = 1 << 5,
|
||||
ATTR_INVISIBLE = 1 << 6,
|
||||
ATTR_STRUCK = 1 << 7,
|
||||
ATTR_WRAP = 1 << 8,
|
||||
ATTR_WIDE = 1 << 9,
|
||||
ATTR_WDUMMY = 1 << 10,
|
||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||
ATTR_NULL = 0,
|
||||
ATTR_BOLD = 1 << 0,
|
||||
ATTR_FAINT = 1 << 1,
|
||||
ATTR_ITALIC = 1 << 2,
|
||||
ATTR_UNDERLINE = 1 << 3,
|
||||
ATTR_BLINK = 1 << 4,
|
||||
ATTR_REVERSE = 1 << 5,
|
||||
ATTR_INVISIBLE = 1 << 6,
|
||||
ATTR_STRUCK = 1 << 7,
|
||||
ATTR_WRAP = 1 << 8,
|
||||
ATTR_WIDE = 1 << 9,
|
||||
ATTR_WDUMMY = 1 << 10,
|
||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||
};
|
||||
|
||||
enum selection_mode {
|
||||
SEL_IDLE = 0,
|
||||
SEL_EMPTY = 1,
|
||||
SEL_READY = 2
|
||||
};
|
||||
enum selection_mode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 };
|
||||
|
||||
enum selection_type {
|
||||
SEL_REGULAR = 1,
|
||||
SEL_RECTANGULAR = 2
|
||||
};
|
||||
enum selection_type { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 };
|
||||
|
||||
enum selection_snap {
|
||||
SNAP_WORD = 1,
|
||||
SNAP_LINE = 2
|
||||
};
|
||||
enum selection_snap { SNAP_WORD = 1, SNAP_LINE = 2 };
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned int uint;
|
||||
|
@ -48,20 +38,20 @@ typedef uint_least32_t Rune;
|
|||
|
||||
#define Glyph Glyph_
|
||||
typedef struct {
|
||||
Rune u; /* character code */
|
||||
ushort mode; /* attribute flags */
|
||||
uint32_t fg; /* foreground */
|
||||
uint32_t bg; /* background */
|
||||
Rune u; /* character code */
|
||||
ushort mode; /* attribute flags */
|
||||
uint32_t fg; /* foreground */
|
||||
uint32_t bg; /* background */
|
||||
} Glyph;
|
||||
|
||||
typedef Glyph *Line;
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
uint ui;
|
||||
float f;
|
||||
const void *v;
|
||||
const char *s;
|
||||
int i;
|
||||
uint ui;
|
||||
float f;
|
||||
const void *v;
|
||||
const char *s;
|
||||
} Arg;
|
||||
|
||||
void die(const char *, ...);
|
||||
|
|
Reference in New Issue