72 lines
1.3 KiB
C
72 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <utils/utils.h>
|
|
|
|
const char*
|
|
vec_get_error_desc(ERROR_CODES err)
|
|
{
|
|
switch (err)
|
|
{
|
|
#define X(name, val, desc) \
|
|
case name: \
|
|
return desc;
|
|
ERROR_LIST(X)
|
|
#undef X
|
|
default:
|
|
return "Unknown";
|
|
}
|
|
}
|
|
|
|
void
|
|
vec_print_errs(const err_t err)
|
|
{
|
|
if (err.flags == SUCCESS)
|
|
{
|
|
printf("%s: %s\n", err.origin, vec_get_error_desc(SUCCESS));
|
|
return;
|
|
}
|
|
{
|
|
#define X(name, val, desc) \
|
|
if ((val) != 0 && ((err.flags) & (val))) \
|
|
{ \
|
|
printf("%s\n", vec_get_error_desc(name)); \
|
|
}
|
|
ERROR_LIST(X)
|
|
#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;
|
|
// }
|