REFACTOR: Completely refactored and fixed the error handling

This commit is contained in:
2026-10-08 13:25:26 -04:00
parent 4bc6efd89e
commit b39911f57e
10 changed files with 1041 additions and 973 deletions
+39 -4
View File
@@ -17,16 +17,16 @@ vec_get_error_desc(ERROR_CODES err)
}
void
vec_print_errs(const unsigned int err)
vec_print_errs(const err_t err)
{
if (err == SUCCESS)
if (err.flags == SUCCESS)
{
printf("%s", vec_get_error_desc(SUCCESS));
printf("%s: %s\n", err.origin, vec_get_error_desc(SUCCESS));
return;
}
{
#define X(name, val, desc) \
if ((val) != 0 && ((err) & (val))) \
if ((val) != 0 && ((err.flags) & (val))) \
{ \
printf("%s\n", vec_get_error_desc(name)); \
}
@@ -34,3 +34,38 @@ vec_print_errs(const unsigned int err)
#undef X
}
}
void
print_bits(unsigned int num)
{
// Determine the number of bits in an unsigned int (usually 32)
int total_bits = sizeof(num) * 8;
// Loop from the most significant bit (MSB) down to the least
// significant bit (LSB)
for (int i = total_bits - 1; i >= 0; i--)
{
// Shift a 1 to the i-th position and check if that bit is set
int bit = (num >> i) & 1;
printf("%d", bit);
// Optional: Add a space every 4 or 8 bits for readability
if (i % 8 == 0)
{
printf(" ");
}
}
printf("\n");
}
// void
// _vec_update_origin(err_t* err, char* str)
// {
// err_t res;
// if (err == nullptr)
// {
// res.err = 0;
// res.value = 0;
// }
// if (!err->origin) err->origin = str;
// }