Skip to content

Commit 8590881

Browse files
committed
feat: merge tokens + error rail + progress bars branch
1 parent 9e62552 commit 8590881

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4480
-721
lines changed

.clang-tidy

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Clang-tidy configuration for mini-ccstatus
2+
# Focuses on type safety, readability, and modern C practices
3+
4+
Checks: >
5+
-*,
6+
bugprone-*,
7+
-bugprone-easily-swappable-parameters,
8+
cert-*,
9+
clang-analyzer-*,
10+
concurrency-*,
11+
modernize-*,
12+
-modernize-use-trailing-return-type,
13+
performance-*,
14+
portability-*,
15+
readability-*,
16+
-readability-identifier-length,
17+
-readability-magic-numbers,
18+
-readability-function-cognitive-complexity,
19+
misc-*,
20+
-misc-unused-parameters
21+
22+
CheckOptions:
23+
- key: readability-identifier-naming.FunctionCase
24+
value: lower_case
25+
- key: readability-identifier-naming.VariableCase
26+
value: lower_case
27+
- key: readability-identifier-naming.ParameterCase
28+
value: lower_case
29+
- key: readability-identifier-naming.MacroDefinitionCase
30+
value: UPPER_CASE
31+
- key: readability-identifier-naming.EnumConstantCase
32+
value: UPPER_CASE
33+
- key: readability-identifier-naming.ConstantCase
34+
value: UPPER_CASE
35+
- key: readability-identifier-naming.GlobalConstantCase
36+
value: UPPER_CASE
37+
- key: readability-identifier-naming.StaticConstantCase
38+
value: UPPER_CASE
39+
- key: readability-identifier-naming.StructCase
40+
value: lower_case
41+
- key: readability-identifier-naming.TypedefCase
42+
value: lower_case
43+
- key: bugprone-reserved-identifier.AllowedIdentifiers
44+
value: '_*'
45+
- key: cert-err33-c.CheckedFunctions
46+
value: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
47+
48+
WarningsAsErrors: ''
49+
HeaderFilterRegex: '(src|lib)/.*\.h$'
50+
AnalyzeTemporaryDtors: false
51+
FormatStyle: file

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
obj/
2-
obj-debug/
31
bin/
2+
obj/
3+
log/
44
benchmark/REPORT.md
5+
compile_commands.json
6+
.cache/
7+
tests/test_token_calculator

Makefile

Lines changed: 128 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,164 @@
55
CC ?= cc
66
CPPFLAGS ?=
77
CFLAGS ?= -O3 -pipe -march=native -flto -DNDEBUG
8-
WARNFLAGS ?= -Wall -Wextra -Wpedantic -Wno-sign-conversion
9-
LDFLAGS ?=
8+
# Type-safety warning flags (strict mode)
9+
WARNFLAGS ?= -Wall -Wextra -Wpedantic \
10+
-Wconversion -Wsign-conversion \
11+
-Wcast-qual -Wformat=2 \
12+
-Wstrict-overflow=5 -Wwrite-strings -Wundef \
13+
-Wshadow -Wpointer-arith \
14+
-Wcast-align -Wstrict-prototypes
15+
LDFLAGS ?= -lm
1016

1117
TARGET := mini-ccstatus
1218
OBJ_DIR := obj
1319
BIN_DIR := bin
14-
OBJECTS := $(OBJ_DIR)/mini-ccstatus.o $(OBJ_DIR)/cJSON.o
20+
SRC_DIR := src
21+
LIB_DIR := lib
22+
TST_DIR := tests
23+
LOG_DIR := log
24+
25+
# Source and object files
26+
SOURCES := main.c \
27+
$(SRC_DIR)/cache.c \
28+
$(SRC_DIR)/cli_parser.c \
29+
$(SRC_DIR)/json_parser.c \
30+
$(SRC_DIR)/token_calculator.c \
31+
$(SRC_DIR)/display.c \
32+
$(SRC_DIR)/safe_conv.c \
33+
$(LIB_DIR)/cjson/cJSON.c
34+
35+
# Release build configuration
36+
OBJ_DIR_RELEASE := $(OBJ_DIR)/release
37+
OBJECTS := $(addprefix $(OBJ_DIR_RELEASE)/, $(patsubst %.c,%.o,$(notdir $(SOURCES))))
38+
39+
# Common compilation settings
40+
COMPILE_FLAGS := $(CPPFLAGS) -I. -I$(LIB_DIR)
41+
COMMON_DEPS := $(SRC_DIR)/*.h $(LIB_DIR)/cjson/cJSON.h
1542

1643
# Debug build configuration (for valgrind and debugging)
17-
CFLAGS_DEBUG := -g -O0 $(WARNFLAGS)
18-
TARGET_DEBUG := mini-ccstatus-debug
19-
OBJ_DIR_DEBUG := obj-debug
20-
OBJECTS_DEBUG := $(OBJ_DIR_DEBUG)/mini-ccstatus.o $(OBJ_DIR_DEBUG)/cJSON.o
44+
CFLAGS_DEBUG_BASE := -g -O0 $(WARNFLAGS)
45+
CFLAGS_DEBUG := $(CFLAGS_DEBUG_BASE) -fanalyzer
46+
TARGET_DEBUG := mini-ccstatus-debug
47+
OBJ_DIR_DEBUG := $(OBJ_DIR)/debug
48+
OBJECTS_DEBUG := $(addprefix $(OBJ_DIR_DEBUG)/, $(patsubst %.c,%.o,$(notdir $(SOURCES))))
49+
50+
# Debug logging build configuration (debug + -DDEBUG for DEBUG_LOG macros)
51+
CFLAGS_DEBUG_LOG := $(CFLAGS_DEBUG_BASE) -DDEBUG
52+
TARGET_DEBUG_LOG := mini-ccstatus-debug-log
53+
OBJ_DIR_DEBUG_LOG := $(OBJ_DIR)/debug-log
54+
OBJECTS_DEBUG_LOG := $(addprefix $(OBJ_DIR_DEBUG_LOG)/, $(patsubst %.c,%.o,$(notdir $(SOURCES))))
2155

2256
# Test scripts
23-
DEMO_SCRIPT := tests/stdout.sh
24-
TEST_SCRIPT := tests/coverage.sh
25-
TEST_MEMORY := tests/memory.sh
26-
TEST_VALGRIND := tests/valgrind.sh
57+
DEMO_QUIET_SCRIPT := $(TST_DIR)/stdout_quiet.sh
58+
DEMO_VERBOSE_SCRIPT := $(TST_DIR)/stdout_verbose.sh
59+
UNIT_TEST_SCRIPT := $(TST_DIR)/run_unit_tests.sh
60+
TEST_SCRIPT := $(TST_DIR)/coverage.sh
61+
TEST_MEMORY := $(TST_DIR)/memory.sh
62+
TEST_VALGRIND := $(TST_DIR)/valgrind.sh
63+
64+
# Test fixtures
2765
FIXTURES := fixtures/*.json
2866

29-
default: $(BIN_DIR)/$(TARGET) demo
67+
default: $(BIN_DIR)/$(TARGET) demo-simple
3068

3169
.PHONY: all
32-
all: clean default test valgrind
70+
all: clean build-all demo-all test valgrind
3371

72+
.PHONY: build-all
73+
build-all: $(BIN_DIR)/$(TARGET) $(BIN_DIR)/$(TARGET_DEBUG) $(BIN_DIR)/$(TARGET_DEBUG_LOG)
74+
75+
.PHONY: demo-all
76+
demo-all: log-dir demo-simple demo-debug
77+
78+
.PHONY: log-dir
79+
log-dir:
80+
@mkdir -p $(LOG_DIR)
81+
82+
# Main target
3483
$(BIN_DIR)/$(TARGET): $(OBJECTS) | $(BIN_DIR)
3584
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
3685

37-
$(OBJ_DIR)/mini-ccstatus.o: mini-ccstatus.c lib/cjson/cJSON.h | $(OBJ_DIR)
38-
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARNFLAGS) -I. -Ilib -c $< -o $@
86+
# Tell Make where to find source files
87+
vpath %.c . $(SRC_DIR) $(LIB_DIR)/cjson
3988

40-
$(OBJ_DIR)/cJSON.o: lib/cjson/cJSON.c lib/cjson/cJSON.h | $(OBJ_DIR)
41-
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARNFLAGS) -I. -Ilib -c $< -o $@
89+
# Pattern rule for release build (VPATH handles source file lookup)
90+
$(OBJ_DIR_RELEASE)/%.o: %.c $(COMMON_DEPS) | $(OBJ_DIR_RELEASE)
91+
$(CC) $(COMPILE_FLAGS) $(CFLAGS) $(WARNFLAGS) -c $< -o $@
4292

43-
$(OBJ_DIR) $(BIN_DIR):
93+
$(OBJ_DIR_RELEASE) $(OBJ_DIR_DEBUG) $(OBJ_DIR_DEBUG_LOG) $(BIN_DIR):
4494
mkdir -p $@
4595

46-
# Debug build targets
96+
# Debug build target
4797
$(BIN_DIR)/$(TARGET_DEBUG): $(OBJECTS_DEBUG) | $(BIN_DIR)
4898
$(CC) $(OBJECTS_DEBUG) $(LDFLAGS) -o $@
4999

50-
$(OBJ_DIR_DEBUG)/mini-ccstatus.o: mini-ccstatus.c lib/cjson/cJSON.h | $(OBJ_DIR_DEBUG)
51-
$(CC) $(CPPFLAGS) $(CFLAGS_DEBUG) -I. -Ilib -c $< -o $@
52-
53-
$(OBJ_DIR_DEBUG)/cJSON.o: lib/cjson/cJSON.c lib/cjson/cJSON.h | $(OBJ_DIR_DEBUG)
54-
$(CC) $(CPPFLAGS) $(CFLAGS_DEBUG) -I. -Ilib -c $< -o $@
55-
56-
$(OBJ_DIR_DEBUG):
57-
mkdir -p $@
100+
# Pattern rule for debug build (VPATH handles source file lookup)
101+
$(OBJ_DIR_DEBUG)/%.o: %.c $(COMMON_DEPS) | $(OBJ_DIR_DEBUG)
102+
$(CC) $(COMPILE_FLAGS) $(CFLAGS_DEBUG) -c $< -o $@
58103

59104
.PHONY: debug
60105
debug: $(BIN_DIR)/$(TARGET_DEBUG)
61106

62-
.PHONY: test
63-
test: $(BIN_DIR)/$(TARGET) $(TEST_SCRIPT) $(TEST_MEMORY) $(FIXTURES)
64-
$(TEST_SCRIPT)
65-
$(TEST_MEMORY)
107+
# Debug logging build target (with -DDEBUG for DEBUG_LOG macros)
108+
$(BIN_DIR)/$(TARGET_DEBUG_LOG): $(OBJECTS_DEBUG_LOG) | $(BIN_DIR)
109+
$(CC) $(OBJECTS_DEBUG_LOG) $(LDFLAGS) -o $@
110+
111+
# Pattern rule for debug-log build (VPATH handles source file lookup)
112+
$(OBJ_DIR_DEBUG_LOG)/%.o: %.c $(COMMON_DEPS) | $(OBJ_DIR_DEBUG_LOG)
113+
$(CC) $(COMPILE_FLAGS) $(CFLAGS_DEBUG_LOG) -c $< -o $@
66114

67-
.PHONY: demo
68-
demo: $(BIN_DIR)/$(TARGET) $(DEMO_SCRIPT)
69-
$(DEMO_SCRIPT)
70-
VERBOSE=true $(DEMO_SCRIPT)
115+
.PHONY: debug-log
116+
debug-log: $(BIN_DIR)/$(TARGET_DEBUG_LOG)
117+
118+
.PHONY: test
119+
test: $(BIN_DIR)/$(TARGET) $(UNIT_TEST_SCRIPT) $(TEST_SCRIPT) $(TEST_MEMORY) $(FIXTURES) log-dir
120+
@echo "Running tests (logs: $(LOG_DIR)/test-*.log)..."
121+
$(UNIT_TEST_SCRIPT) 2>&1 | tee $(LOG_DIR)/test-unit.log
122+
$(TEST_SCRIPT) 2>&1 | tee $(LOG_DIR)/test-coverage.log
123+
$(TEST_MEMORY) 2>&1 | tee $(LOG_DIR)/test-memory.log
124+
125+
.PHONY: demo-simple
126+
demo-simple: $(BIN_DIR)/$(TARGET) $(DEMO_QUIET_SCRIPT) $(DEMO_VERBOSE_SCRIPT)
127+
$(DEMO_QUIET_SCRIPT)
128+
$(DEMO_VERBOSE_SCRIPT)
129+
130+
.PHONY: demo-debug
131+
demo-debug: $(BIN_DIR)/$(TARGET_DEBUG_LOG) log-dir
132+
@echo "Running with debug logging enabled..."
133+
@cat fixtures/status.json | $(BIN_DIR)/$(TARGET_DEBUG_LOG) > $(LOG_DIR)/demo-debug-basic.log 2>&1
134+
@cat $(LOG_DIR)/demo-debug-basic.log
135+
@echo ""
136+
@echo "Running with --all flag and debug logging..."
137+
@cat fixtures/test_status_with_transcript.json | $(BIN_DIR)/$(TARGET_DEBUG_LOG) --all > $(LOG_DIR)/demo-debug-all.log 2>&1
138+
@cat $(LOG_DIR)/demo-debug-all.log
139+
@echo ""
140+
@echo "Debug logs saved to $(LOG_DIR)/demo-debug-*.log"
71141

72142
.PHONY: valgrind
73-
valgrind: $(TEST_VALGRIND)
74-
$(TEST_VALGRIND)
143+
valgrind: $(TEST_VALGRIND) log-dir
144+
@echo "Running valgrind tests (logs: $(LOG_DIR)/test-valgrind.log)..."
145+
$(TEST_VALGRIND) 2>&1 | tee $(LOG_DIR)/test-valgrind.log
146+
147+
# Static analysis targets
148+
.PHONY: lint
149+
lint:
150+
@echo "Running clang-tidy static analysis..."
151+
@clang-tidy $(SOURCES) -- -I. -I$(LIB_DIR) $(CPPFLAGS) $(WARNFLAGS)
152+
153+
.PHONY: analyze
154+
analyze: debug
155+
@echo "Running GCC static analyzer..."
156+
@$(MAKE) clean
157+
@$(MAKE) debug 2>&1 | grep -E '(warning:|error:)' || echo "No analyzer warnings found"
158+
159+
.PHONY: clang
160+
clang:
161+
@echo "Generating compile_commands.json for clangd..."
162+
-@bear -- $(MAKE) clean
163+
-@bear -- $(MAKE)
164+
@echo "compile_commands.json generated successfully"
75165

76166
.PHONY: clean
77167
clean:
78-
rm -rfv $(BIN_DIR) $(OBJ_DIR) $(OBJ_DIR_DEBUG)
168+
rm -rfv $(BIN_DIR) $(OBJ_DIR) $(OBJ_DIR_DEBUG) $(OBJ_DIR_DEBUG_LOG) $(LOG_DIR) compile_commands.json

0 commit comments

Comments
 (0)