Format and document utility files (#246)

* Format and document utility files

* Add Doxyfile

* small updates for cleanup

* Final touches for util docs

* Replace `_` with `s_` for static functions

* update for clang-format changes

* Update include/audio_utils.h

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* Apply suggestions from code review

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* Update include/audio_utils.h

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* Update include/graphic_utils.h

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* Make clang-format happy :)

* Update gitignore for doxygen

* restor graphic_utils.c to main

* update graphics utils

* tmp

* tmp

* get it to compile

* fix some bad merge mistakes

* Fix clang format

* Apply suggestions from code review

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* make clang-format happy

---------

Co-authored-by: MeirGavish <meir.gavish@gmail.com>
This commit is contained in:
Rickey
2025-12-07 12:56:39 -08:00
committed by GitHub
co-authored by MeirGavish
parent 7bd510ee5f
commit 35ecbf33ae
14 changed files with 3765 additions and 317 deletions
+11 -8
View File
@@ -1,7 +1,8 @@
#include "util.h"
#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
int int_arr_max(int int_arr[], int size)
{
@@ -17,7 +18,11 @@ int int_arr_max(int int_arr[], int size)
return max;
}
void truncate_uint_to_suffixed_str(uint32_t num, int num_req_chars, char out_str_buff[UINT_MAX_DIGITS + 1])
void truncate_uint_to_suffixed_str(
uint32_t num,
int num_req_chars,
char out_str_buff[UINT_MAX_DIGITS + 1]
)
{
bool inevitable_overflow = num_req_chars < SUFFIXED_NUM_MIN_REQ_CHARS;
if (inevitable_overflow)
@@ -28,7 +33,7 @@ void truncate_uint_to_suffixed_str(uint32_t num, int num_req_chars, char out_str
int num_digits = u32_get_digits(num);
int overflow_size = num_digits - num_req_chars;
char* suffix = "";
/* If there is overflow, divide by the next suffixed power of 10
* to truncate the number back within num_req_chars.
* UINT32_MAX is in the billions so no need to check larger numbers
@@ -44,9 +49,8 @@ void truncate_uint_to_suffixed_str(uint32_t num, int num_req_chars, char out_str
num /= ONE_M;
suffix = "M";
}
else if (overflow_size > 0
|| (inevitable_overflow && num_digits == SUFFIXED_NUM_MIN_REQ_CHARS))
// Special case - alleviate inevitable overflow for 1000s and truncate them to "1K"s
else if (overflow_size > 0 || (inevitable_overflow && num_digits == SUFFIXED_NUM_MIN_REQ_CHARS))
// Special case - alleviate inevitable overflow for 1000s and truncate them to "1K"s
{
num /= ONE_K;
suffix = "K";
@@ -61,7 +65,7 @@ uint32_t u32_protected_add(uint32_t a, uint32_t b)
{
return (a > (UINT32_MAX - b)) ? UINT32_MAX : (a + b);
}
uint16_t u16_protected_add(uint16_t a, uint16_t b)
{
return (a > (UINT16_MAX - b)) ? UINT16_MAX : (a + b);
@@ -75,5 +79,4 @@ uint32_t u32_protected_mult(uint32_t a, uint32_t b)
uint16_t u16_protected_mult(uint16_t a, uint16_t b)
{
return (a == 0 || b == 0) ? 0 : (a > (UINT16_MAX / b) ? UINT16_MAX : a * b);
}