pruned clang-tidy, added splint and cppcheck
This commit is contained in:
parent
83b2988509
commit
f3e286e787
22
.clang-tidy
22
.clang-tidy
@ -1,25 +1,15 @@
|
|||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
clang-diagnostic-*,
|
clang-diagnostic-*,
|
||||||
clang-analyzer-*,
|
bugprone-macro-parentheses,
|
||||||
readability-*,
|
bugprone-suspicious-string-compare,
|
||||||
-readability-identifier-length,
|
bugprone-sizeof-expression,
|
||||||
-readability-magic-numbers,
|
bugprone-signed-char-misuse,
|
||||||
-readability-function-cognitive-complexity,
|
cert-dcl37-c,
|
||||||
bugprone-*,
|
readability-misleading-indentation
|
||||||
-bugprone-easily-swappable-parameters,
|
|
||||||
misc-*,
|
|
||||||
-misc-unused-parameters,
|
|
||||||
portability-*
|
|
||||||
|
|
||||||
WarningsAsErrors: ''
|
WarningsAsErrors: ''
|
||||||
|
|
||||||
HeaderFilterRegex: '.*'
|
HeaderFilterRegex: '.*'
|
||||||
|
|
||||||
CheckOptions:
|
|
||||||
- key: readability-function-size.LineThreshold
|
|
||||||
value: '100'
|
|
||||||
- key: readability-function-size.StatementThreshold
|
|
||||||
value: '50'
|
|
||||||
|
|
||||||
FormatStyle: none
|
FormatStyle: none
|
||||||
25
Makefile
25
Makefile
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# Compiler and flags
|
# Compiler and flags
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -std=c90 -pedantic -Wpedantic -Wall -Wextra
|
CFLAGS = -std=c90 -pedantic -Wpedantic -Wall -Wextra -Wstrict-prototypes -Wold-style-definition
|
||||||
|
|
||||||
# Platform detection
|
# Platform detection
|
||||||
ifdef COMSPEC
|
ifdef COMSPEC
|
||||||
@ -95,3 +95,26 @@ help:
|
|||||||
@echo " - GNU Make"
|
@echo " - GNU Make"
|
||||||
|
|
||||||
.PHONY: all clean install uninstall rebuild wordlists help
|
.PHONY: all clean install uninstall rebuild wordlists help
|
||||||
|
|
||||||
|
# Static analysis targets
|
||||||
|
analyze: cppcheck
|
||||||
|
|
||||||
|
# Relaxed splint (too noisy with +standard)
|
||||||
|
splint:
|
||||||
|
@echo "Running splint with relaxed checks..."
|
||||||
|
@splint -weak +posixlib -I./include src/*.c 2>&1 | grep -v "Definition of" || true
|
||||||
|
|
||||||
|
# Strict splint (very verbose, use with caution)
|
||||||
|
splint-strict:
|
||||||
|
splint +standard -I./include src/*.c
|
||||||
|
|
||||||
|
cppcheck:
|
||||||
|
@echo "Running cppcheck..."
|
||||||
|
@cppcheck --std=c90 --enable=warning,style,performance,portability \
|
||||||
|
--suppress=missingIncludeSystem --quiet -I./include src/
|
||||||
|
|
||||||
|
strict-compile:
|
||||||
|
gcc -std=c90 -pedantic -Wpedantic -Wall -Wextra \
|
||||||
|
-Wstrict-prototypes -Wold-style-definition \
|
||||||
|
-Wmissing-prototypes -Wdeclaration-after-statement \
|
||||||
|
-Iinclude -c src/*.c
|
||||||
|
|||||||
2
build.sh
2
build.sh
@ -4,7 +4,7 @@
|
|||||||
mkdir -p build/cordle
|
mkdir -p build/cordle
|
||||||
|
|
||||||
echo "Building application."
|
echo "Building application."
|
||||||
gcc -v -std=c90 -pedantic -Wpedantic -o build/cordle/cordle src/*.c -Iinclude -lncurses > build/cordle-build.log 2>&1
|
gcc -std=c90 -pedantic -Wpedantic -Wall -Wextra -Wstrict-prototypes -Wold-style-definition
|
||||||
export RESULT=$?
|
export RESULT=$?
|
||||||
|
|
||||||
if (( RESULT == 0 )); then
|
if (( RESULT == 0 )); then
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
int load_words(GameState* game, const char* filename);
|
int load_words(GameState* game, const char* filename);
|
||||||
int is_valid_word(GameState* game, const char* word);
|
int is_valid_word(const GameState* game, const char* word);
|
||||||
void to_upper(char* str);
|
void to_upper(char* str);
|
||||||
|
|
||||||
#endif /* WORDS_H */
|
#endif /* WORDS_H */
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include "../include/ui.h"
|
#include "../include/ui.h"
|
||||||
|
|
||||||
/* Parse command line arguments */
|
/* Parse command line arguments */
|
||||||
void parse_arguments(int argc, char *argv[], char *filename, char *difficulty) {
|
static void parse_arguments(int argc, char **argv, char *filename, char *difficulty) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Default values */
|
/* Default values */
|
||||||
@ -53,7 +53,7 @@ void parse_arguments(int argc, char *argv[], char *filename, char *difficulty) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Main game loop */
|
/* Main game loop */
|
||||||
int main_game_loop(int argc, char *argv[]) {
|
static int main_game_loop(int argc, char *argv[]) {
|
||||||
WINDOW *stdscr;
|
WINDOW *stdscr;
|
||||||
GameState game;
|
GameState game;
|
||||||
char filename[MAX_FILENAME];
|
char filename[MAX_FILENAME];
|
||||||
|
|||||||
7
src/ui.c
7
src/ui.c
@ -31,14 +31,14 @@ void draw_title(WINDOW *win, int y, const char *difficulty) {
|
|||||||
/* Draw the game board */
|
/* Draw the game board */
|
||||||
void draw_board(WINDOW *win, GameState *game, int y) {
|
void draw_board(WINDOW *win, GameState *game, int y) {
|
||||||
int width, board_x;
|
int width, board_x;
|
||||||
int row, col, x_pos, y_pos;
|
int row, col, x_pos;
|
||||||
char cell[4];
|
char cell[4];
|
||||||
|
|
||||||
width = getmaxx(win);
|
width = getmaxx(win);
|
||||||
board_x = (width - (WORD_LENGTH * 4 - 1)) / 2;
|
board_x = (width - (WORD_LENGTH * 4 - 1)) / 2;
|
||||||
|
|
||||||
for (row = 0; row < MAX_GUESSES; row++) {
|
for (row = 0; row < MAX_GUESSES; row++) {
|
||||||
y_pos = y + row * 2;
|
int y_pos = y + row * 2;
|
||||||
|
|
||||||
if (row < game->guess_count) {
|
if (row < game->guess_count) {
|
||||||
/* Draw a completed guess */
|
/* Draw a completed guess */
|
||||||
@ -77,7 +77,7 @@ void draw_board(WINDOW *win, GameState *game, int y) {
|
|||||||
/* Draw visual keyboard */
|
/* Draw visual keyboard */
|
||||||
void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
||||||
int width;
|
int width;
|
||||||
int row_idx, x, y_pos, i;
|
int row_idx, i;
|
||||||
const char *row;
|
const char *row;
|
||||||
char letter;
|
char letter;
|
||||||
int status, color;
|
int status, color;
|
||||||
@ -85,6 +85,7 @@ void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
|||||||
width = getmaxx(win);
|
width = getmaxx(win);
|
||||||
|
|
||||||
for (row_idx = 0; row_idx < 3; row_idx++) {
|
for (row_idx = 0; row_idx < 3; row_idx++) {
|
||||||
|
int x, y_pos;
|
||||||
row = keyboard_rows[row_idx];
|
row = keyboard_rows[row_idx];
|
||||||
x = (width - strlen(row) * 2 + 1) / 2;
|
x = (width - strlen(row) * 2 + 1) / 2;
|
||||||
y_pos = y + row_idx;
|
y_pos = y + row_idx;
|
||||||
|
|||||||
@ -56,7 +56,6 @@ int load_words(GameState *game, const char *filename) {
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
char line[32];
|
char line[32];
|
||||||
char word[WORD_LENGTH + 1];
|
char word[WORD_LENGTH + 1];
|
||||||
int len;
|
|
||||||
|
|
||||||
/* Try to open the file */
|
/* Try to open the file */
|
||||||
file = open_wordlist(filename);
|
file = open_wordlist(filename);
|
||||||
@ -67,7 +66,7 @@ int load_words(GameState *game, const char *filename) {
|
|||||||
game->word_count = 0;
|
game->word_count = 0;
|
||||||
while (fgets(line, sizeof(line), file) && game->word_count < MAX_WORDS) {
|
while (fgets(line, sizeof(line), file) && game->word_count < MAX_WORDS) {
|
||||||
/* Remove newline and whitespace */
|
/* Remove newline and whitespace */
|
||||||
len = strlen(line);
|
int len = strlen(line);
|
||||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r' || line[len - 1] == ' ')) {
|
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r' || line[len - 1] == ' ')) {
|
||||||
line[--len] = '\0';
|
line[--len] = '\0';
|
||||||
}
|
}
|
||||||
@ -94,7 +93,7 @@ int load_words(GameState *game, const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if word exists in a word list */
|
/* Check if word exists in a word list */
|
||||||
int is_valid_word(GameState *game, const char *word) {
|
int is_valid_word(const GameState *game, const char *word) {
|
||||||
int i;
|
int i;
|
||||||
char upper_word[WORD_LENGTH + 1];
|
char upper_word[WORD_LENGTH + 1];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user