Skip to content

Commit

Permalink
removed fread fixes and added windows visual studio clang support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed Jun 24, 2024
1 parent 4361760 commit c8f6f3e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ Testing/

# vscode
.VSCodeCounter
.vs
.vs/
.vscode/
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ project(SLNOSLAV
LANGUAGES C
)

set(CMAKE_C_FLAGS "-std=c17 -pg -Wall -Werror -ftest-coverage")
if (WIN32)
add_compile_options(/W4)
else()
add_compile_options(-std=c17 -pg -Wall -Wextra -Wpedantic)
endif()

add_subdirectory(external)
add_subdirectory(program)
Expand Down
15 changes: 15 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "clang_cl_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
10 changes: 6 additions & 4 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ set_target_properties(NUKLEAR_LIB PROPERTIES LINKER_LANGUAGE C)

target_include_directories(NUKLEAR_LIB INTERFACE nuklear/src)

find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND REQUIRED wayland-client wayland-cursor wayland-egl xkbcommon)
find_package(X11 REQUIRED)
find_package(Doxygen)
if (!WIN32)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND REQUIRED wayland-client wayland-cursor wayland-egl xkbcommon)
find_package(X11 REQUIRED)
find_package(Doxygen)
endif()

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
Expand Down
4 changes: 2 additions & 2 deletions program/include/structures/abstract/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static inline Stack copy_stack(Stack stack, STACK_DATA_TYPE (*copy_element)(STAC
Stack copy = create_stack();

SLArray * current_array = stack.head;
for (size_t i = stack.size - 1; i >= 0 && current_array;) {
for (size_t i = stack.size - 1; current_array;) {
SLArray * temp = malloc(sizeof(SLArray));

assert(temp && "MEMORY ALLOCATION FAILED");
Expand All @@ -166,7 +166,7 @@ static inline Stack copy_stack(Stack stack, STACK_DATA_TYPE (*copy_element)(STAC
temp->next = copy.head;
copy.head = temp;

for (size_t j = i % STACK_LIST_ARRAY_SIZE; j >= 0; i--, j--) {
for (size_t j = i % STACK_LIST_ARRAY_SIZE;; i--, j--) {
copy.head->elements[j] = copy_element ? copy_element(current_array->elements[j]) : current_array->elements[j];
copy.size++;
}
Expand Down
12 changes: 6 additions & 6 deletions program/source/algorithms/arc_consistency.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void _reduce_col_one_values(Kakuro board, Stack * ones, SArray * current_state,
Valid _create_valid(Kakuro board, SArray * current_state, ksize_t index, KGSizes type);
void _destroy_valid(Valid * combinations);
bool _reduce_no_combination(Kakuro board, SArray * current_state, Check * checks);
bool _reduce_no_col_combination(Kakuro board, SArray * current_state, Check * checks, ksize_t index);
bool _reduce_no_row_combination(Kakuro board, SArray * current_state, Check * checks, ksize_t index);
bool _reduce_no_col_combination(Kakuro board, SArray * current_state, ksize_t index);
bool _reduce_no_row_combination(Kakuro board, SArray * current_state, ksize_t index);

bool look_ahead(Kakuro board, SArray * current_state) {
assert(current_state && "CURRENT STATE ARRAY IS NULL");
Expand Down Expand Up @@ -161,15 +161,15 @@ void _destroy_valid(Valid * combinations) {
bool _reduce_no_combination(Kakuro board, SArray * current_state, Check * checks) {
bool is_reduced = false;
for (size_t i = 0; i < board.game.empty_count; i++) {
if (!(checks[i] & ROWCHECK)) is_reduced |= _reduce_no_row_combination(board, current_state, checks, i);
if (!(checks[i] & COLCHECK)) is_reduced |= _reduce_no_col_combination(board, current_state, checks, i);
if (!(checks[i] & ROWCHECK)) is_reduced |= _reduce_no_row_combination(board, current_state, i);
if (!(checks[i] & COLCHECK)) is_reduced |= _reduce_no_col_combination(board, current_state, i);
add_check(board, checks, i);
}

return is_reduced;
}

bool _reduce_no_row_combination(Kakuro board, SArray * current_state, Check * checks, ksize_t index) {
bool _reduce_no_row_combination(Kakuro board, SArray * current_state, ksize_t index) {
ksize_t row = board.coords[ROW][index], col = board.coords[COLUMN][index];
for (ksize_t i = 0; i < board.blocks[ROW][index]; i++) {
if (!current_state->elements[board.grid[row][col + i]]) return false;
Expand All @@ -192,7 +192,7 @@ bool _reduce_no_row_combination(Kakuro board, SArray * current_state, Check * ch
return is_reduced;
}

bool _reduce_no_col_combination(Kakuro board, SArray * current_state, Check * checks, ksize_t index) {
bool _reduce_no_col_combination(Kakuro board, SArray * current_state, ksize_t index) {
ksize_t row = board.coords[ROW][index], col = board.coords[COLUMN][index];
for (ksize_t i = 0; i < board.blocks[COLUMN][index]; i++) {
if (current_state->elements[board.grid[row + i][col]] == INVALID_STATE) return false;
Expand Down
12 changes: 6 additions & 6 deletions program/source/algorithms/reduce.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ state_t _check_even_two_blocks(ksize_t block, ksize_t sum);
state_t _check_high_end(ksize_t block, ksize_t sum);
state_t _check_low_end(ksize_t block, ksize_t sum);
void _reduce_multi_values(Kakuro board, SArray * initial_state);
void _reduce_row_multi_values(Kakuro board, SArray * initial_state, Check * checks, ksize_t index);
void _reduce_col_multi_values(Kakuro board, SArray * initial_state, Check * checks, ksize_t index);
void _reduce_row_multi_values(Kakuro board, SArray * initial_state, ksize_t index);
void _reduce_col_multi_values(Kakuro board, SArray * initial_state, ksize_t index);

void reduce(Kakuro board, SArray * initial_state) {
assert(initial_state && "INITIAL STATE ARRAY IS NULL");
Expand Down Expand Up @@ -87,13 +87,13 @@ void _reduce_multi_values(Kakuro board, SArray * current_state) {
Check checks[KAKURO_SIZE_MAX] = { 0 };

for (size_t i = 0; i < board.game.empty_count; i++) {
if (!(checks[i] & ROWCHECK)) _reduce_row_multi_values(board, current_state, checks, i);
if (!(checks[i] & COLCHECK)) _reduce_col_multi_values(board, current_state, checks, i);
if (!(checks[i] & ROWCHECK)) _reduce_row_multi_values(board, current_state, i);
if (!(checks[i] & COLCHECK)) _reduce_col_multi_values(board, current_state, i);
add_check(board, checks, i);
}
}

void _reduce_row_multi_values(Kakuro board, SArray * current_state, Check * checks, ksize_t index) {
void _reduce_row_multi_values(Kakuro board, SArray * current_state, ksize_t index) {
ksize_t row = board.coords[ROW][index], col = board.coords[COLUMN][index];
ksize_t block = board.blocks[ROW][index], sums = board.sums[ROW][index];
ksize_t empty_blocks = block, empty_sums = sums;
Expand All @@ -118,7 +118,7 @@ void _reduce_row_multi_values(Kakuro board, SArray * current_state, Check * chec
destroy_stack(&multi, NULL);
}

void _reduce_col_multi_values(Kakuro board, SArray * current_state, Check * checks, ksize_t index) {
void _reduce_col_multi_values(Kakuro board, SArray * current_state, ksize_t index) {
ksize_t row = board.coords[ROW][index], col = board.coords[COLUMN][index];
ksize_t block = board.blocks[COLUMN][index], sums = board.sums[COLUMN][index];
ksize_t empty_blocks = block, empty_sums = sums;
Expand Down
8 changes: 0 additions & 8 deletions program/source/structures/concrete/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ ksize_t _empty_cell_count(KGrid from);

Kakuro init_kakuro(FILE * kakuro_file) {
assert(kakuro_file && "KAKURO FILE POINTER IS NULL");
ksize_t c = 0;
do {
assert(fread(&c, sizeof(ksize_t), 1, kakuro_file));
printf ("%02x ", c);
} while (!feof(kakuro_file));
fflush(stdout);

rewind(kakuro_file);

Kakuro k = { 0 };
_kakuro_alloc(&k, kakuro_file);
Expand Down

0 comments on commit c8f6f3e

Please sign in to comment.