Skip to content

Commit 0e6973a

Browse files
committed
feat: Working on debugging for windows. WILL NOT debug any further 'til this pr has been merged. @Intancote
1 parent 073404c commit 0e6973a

13 files changed

+164
-64
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
/hamon
66
/tests/unity
77
/vgcore
8-
/compile_commands.json
98
/.cache
9+
/compile_commands.json

build/build.sh

+36-28
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ TESTS_BIN="${BUILD}/tests/bin"
5757

5858
UNITY_TAG="v2.6.0"
5959

60-
#INCLUDE="$(pwd)/include"
60+
EXCLUDE=("file.c" "config.c" "prompt.c" "exec.c" "error.c" "builtins.c" "escape.c")
61+
62+
#LIB="$(pwd)/lib"
6163
COLOR=true
6264

6365
CC="clang"
@@ -74,12 +76,12 @@ fi
7476

7577
CFLAGS="-O3 -Wall -Wextra -I./include/"
7678

77-
LINKER_FLAGS="-Wall -Wextra"
79+
LINKER_FLAGS=""
7880

7981
if [[ ${OSTYPE} != "msys" ]]; then
8082
LINKER_FLAGS+=" -fuse-ld=mold"
8183
else
82-
CFLAGS+=" -I/usr/include"
84+
CFLAGS+=" -I/usr/include -fsanitize=address"
8385
LINKER_FLAGS+=" -lbsd -L/usr/lib"
8486
fi
8587

@@ -142,34 +144,40 @@ EOF
142144

143145
compile() {
144146
local -a C_FILES
147+
local -a C_FILES_RL
145148

146-
local -a TRIMMED_C_FILES
147-
local -a TRIMMED_C_FILENAMES
149+
local -a TRIMMED_FILES
150+
local -a CFILE_DIFF
148151

149152
local RECOMPILE
150-
local TRIMMED_C_FILE
151-
local TRIMMED_C_FILENAME
153+
local TRIMMED_FILE
154+
155+
if ! [[ ${#EXCLUDE[@]} -eq 0 ]]; then
156+
echo -e "Housekeeping!!!"
157+
clean "${OUT}" "${BIN}" "y"
158+
fi
152159

153160
mapfile -t C_FILES < <(find "${DIR}" -type f -name "*.c")
161+
for i in "${!C_FILES[@]}"; do C_FILES_RL[i]="$(basename "${C_FILES[i]}")"; done
162+
163+
CFILE_DIFF=($(comm -23 <(printf "%s\n" "${C_FILES_RL[@]}" | sort) <(printf "%s\n" "${EXCLUDE[@]}" | sort)))
154164

155-
for ((i = 0; i < ${#C_FILES[@]}; i++)); do
156-
TRIMMED_C_FILE="${C_FILES[${i}]%.*}"
157-
TRIMMED_C_FILENAME="${TRIMMED_C_FILE##*/}"
158-
TRIMMED_C_FILES+=("${TRIMMED_C_FILE}")
159-
TRIMMED_C_FILENAMES+=("${TRIMMED_C_FILENAME}")
160-
echo -e "${BLUE}>${CLEAR} Compiling: ${CYAN}${C_FILES[${i}]}${CLEAR}"
161-
if [[ -f "${OUT}/${TRIMMED_C_FILENAME}.o" ]]; then
162-
echo -ne "${YELLOW}!${CLEAR} ${CYAN}${TRIMMED_C_FILENAME}.o${CLEAR} seems to already exist, you wanna recompile it? [${GREEN}Y${CLEAR}/${RED}n${CLEAR}]: "
165+
for ((i = 0; i < ${#CFILE_DIFF[@]}; i++)); do
166+
TRIMMED_FILE="${CFILE_DIFF[${i}]%.*}"
167+
TRIMMED_FILES+=("${TRIMMED_FILE}")
168+
echo -e "${BLUE}>${CLEAR} Compiling: ${CYAN}${TRIMMED_FILE}.c${CLEAR}"
169+
if [[ -f "${OUT}/${TRIMMED_FILE}.o" ]]; then
170+
echo -ne "${YELLOW}!${CLEAR} ${CYAN}${TRIMMED_FILE}.o${CLEAR} seems to already exist, you wanna recompile it? [${GREEN}Y${CLEAR}/${RED}n${CLEAR}]: "
163171
read -r RECOMPILE
164172
if [[ ! ${RECOMPILE} =~ [Nn] ]]; then
165-
echo -e "Running: ${CC} ${CFLAGS} -c ${C_FILES[${i}]} -o ${OUT}/${TRIMMED_C_FILENAME}.o"
173+
echo -e "Running: ${CC} ${CFLAGS} -c ${DIR}/${TRIMMED_FILE}.c -o ${OUT}/${TRIMMED_FILE}.o"
166174
# shellcheck disable=SC2086
167-
"${CC}" ${CFLAGS} -c "${C_FILES[${i}]}" -o "${OUT}/${TRIMMED_C_FILENAME}.o"
175+
"${CC}" ${CFLAGS} -c "${DIR}/${TRIMMED_FILE}.c" -o "${OUT}/${TRIMMED_FILE}.o"
168176
fi
169177
else
170-
echo -e "Running: ${CC} ${CFLAGS} -c ${C_FILES[${i}]} -o ${OUT}/${TRIMMED_C_FILENAME}.o"
178+
echo -e "Running: ${CC} ${CFLAGS} -c ${DIR}/${TRIMMED_FILE}.c -o ${OUT}/${TRIMMED_FILE}.o"
171179
# shellcheck disable=SC2086
172-
"${CC}" ${CFLAGS} -c "${C_FILES[${i}]}" -o "${OUT}/${TRIMMED_C_FILENAME}.o"
180+
"${CC}" ${CFLAGS} -c "${DIR}/${TRIMMED_FILE}.c" -o "${OUT}/${TRIMMED_FILE}.o"
173181
fi
174182
done
175183

@@ -178,8 +186,8 @@ compile() {
178186
# shellcheck disable=SC2086
179187
"${CC}" ${CFLAGS} -c "${SRC}/main.c" -o "${OUT}/main.o"
180188

181-
for i in "${!TRIMMED_C_FILENAMES[@]}"; do TRIMMED_C_FILENAMES[i]="${TRIMMED_C_FILENAMES[i]}.c"; done
182-
echo -e "${GREEN}${CLEAR} Compiled ${CYAN}${TRIMMED_C_FILENAMES[*]}${CLEAR} & ${CYAN}main.c${CLEAR} successfully"
189+
for i in "${!TRIMMED_FILES[@]}"; do TRIMMED_FILES[i]="${TRIMMED_FILES[i]}.c"; done
190+
echo -e "${GREEN}${CLEAR} Compiled ${CYAN}${TRIMMED_FILES[*]}${CLEAR} & ${CYAN}main.c${CLEAR} successfully"
183191
}
184192

185193
# links all object files in out/ to an executable in /bin
@@ -207,7 +215,7 @@ link() {
207215
pushd "${OUT}" >/dev/null || handle_failure "Failed to pushd" #|| echo "Failed to pushd" && exit 1
208216

209217
echo -e "${BLUE}>${CLEAR} Linking: ${CYAN}${TRIMMED_FILES[*]}${CLEAR}"
210-
218+
for i in "${!TRIMMED_FILES[@]}"; do TRIMMED_FILES[i]="${OUT}/${TRIMMED_FILES[i]}"; done
211219
if [[ -f "${BIN}/${EXECUTABLE_NAME}" ]]; then
212220
echo -ne "${YELLOW}!${CLEAR} ${CYAN}${EXECUTABLE_NAME}${CLEAR} seems to already exist, you wanna relink it? [${GREEN}Y${CLEAR}/${RED}n${CLEAR}]: "
213221
read -r RELINK
@@ -348,7 +356,7 @@ unit_test() {
348356

349357
popd >/dev/null || handle_failure "Failed to popd" # || echo "Failed to popd" && exit 1
350358

351-
#rm -fr "${TESTS_OUT}" "${TESTS_BIN}"
359+
# rm -fr "${TESTS_OUT}" "${TESTS_BIN}"
352360
}
353361

354362
# removes dangling object files that shouldn't be there, used to be required, not that much as of lately though.
@@ -386,8 +394,8 @@ clean() {
386394
local LOCALBIN
387395
local LOG
388396

389-
LOCALOUT=${1}
390-
LOCALBIN=${2}
397+
LOCALOUT=${1:?}
398+
LOCALBIN=${2:?}
391399
CONFIRMATION=${3}
392400
LOG=${4:true}
393401

@@ -401,10 +409,10 @@ clean() {
401409
CLEAN="y"
402410
fi
403411
if [[ ${CLEAN} =~ [Yy] ]]; then
404-
rm -fr "${LOCALOUT:?}/*"
405-
rm -fr "${LOCALBIN:?}/*"
412+
rm -fr "${LOCALOUT}"/*
413+
rm -fr "${LOCALBIN}"/*
406414
if ${LOG}; then
407-
echo -e "${GREEN}${CLEAR} Cleaned ${CYAN}${LOCALOUT}${CLEAR} & ${CYAN}${LOCALBIN}${CLEAR} successfully."
415+
echo -e "${GREEN}${CLEAR} Cleaned ${CYAN}${LOCALOUT}/*${CLEAR} & ${CYAN}${LOCALBIN}/*${CLEAR} successfully."
408416
fi
409417
else
410418
echo -e "${GREEN}${CLEAR} Cancelled."

include/hamon_file.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#include <stdio.h>
55

6-
int write_file(const char *filename, const char *content, const size_t size);
6+
int write_file(const char *filename, const char *content);
77
int check_if_folder_exists(const char *folder_path);
88
int compare_file_contents(const char *file_path, char *contents,
99
size_t content_len);
10+
int remove_file(const char *file_path);
1011
int create_folder(const char *folder_path);
1112
int remove_folder(const char *path);
1213
char *read_file(const char *file_path);

justfile

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ default:
3838
just link {{name}}
3939
lldb ./build/bin/{{name}}.exe {{args}}
4040

41+
@debug-no-debugger args="" name="hsh": fix_perms
42+
just compile --debug
43+
just link {{name}}
44+
./build/bin/{{name}} {{args}}
45+
4146
@clear_cores: fix_perms
4247
build/build.sh -vg
4348

src/hamon/cli.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ int info_for_flag(Info *info) {
4747
int first_arg_len = info->first_arg_len;
4848
const char *use = info->use;
4949

50+
printf("%s\n", use);
51+
printf("%zu\n", strlen(use));
52+
5053
char *buffer = {0};
5154
buffer = (char *)malloc((first_arg_len + strlen(use)) * sizeof(char));
5255
if (!buffer) {
5356
perror("buffer malloc");
5457
return 1;
5558
}
5659

57-
snprintf(buffer, ((first_arg_len * 2 + strlen(use)) - 3), use, first_arg,
60+
snprintf(buffer, first_arg_len * 2 + strlen(use) + 1, use, first_arg,
5861
first_arg);
5962

6063
printf("%s", flags[0]);

src/hamon/config.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ const char *default_config =
155155

156156
int gen_default_config(void) {
157157
size_t config_buffer_size = strlen(default_config);
158+
printf("Config buffer size: %zu\n", config_buffer_size);
159+
158160
char *config_buffer = {0};
159161

160162
config_buffer = (char *)malloc(config_buffer_size);
@@ -169,6 +171,8 @@ int gen_default_config(void) {
169171
return -1;
170172
}
171173

174+
printf("Config buffer: %s\n", config_buffer);
175+
172176
#ifdef _WIN32
173177
char folder_buffer[MAX_PATH] = {0};
174178
char absolute_path_buffer[MAX_PATH] = {0};
@@ -186,6 +190,9 @@ int gen_default_config(void) {
186190
win_perror("snprintf");
187191
return -1;
188192
}
193+
printf("Folder: %s\n", folder_buffer);
194+
printf("Path: %s\n", absolute_path_buffer);
195+
189196
#elif __linux__
190197
char folder_buffer[1024] = {0};
191198
char absolute_path_buffer[1024] = {0};
@@ -214,8 +221,7 @@ int gen_default_config(void) {
214221
}
215222

216223
if (read_file(absolute_path_buffer)) {
217-
int status =
218-
write_file(absolute_path_buffer, config_buffer, config_buffer_size);
224+
int status = write_file(absolute_path_buffer, config_buffer);
219225

220226
if (!status) {
221227
free(config_buffer);

0 commit comments

Comments
 (0)