X-Git-Url: https://git.danieliu.xyz/?p=taskasaur.git;a=blobdiff_plain;f=utils.c;h=9b374046efaeef15cc4b14b4b7c8870bb31b7111;hp=ecf4b70ce604ba51a0ed5332f24771fc6fca7c16;hb=HEAD;hpb=303071d6e0488d7da4dc810897948b8ed97354d2 diff --git a/utils.c b/utils.c index ecf4b70..9b37404 100644 --- a/utils.c +++ b/utils.c @@ -12,6 +12,21 @@ min(int a, int b) return (a < b) ? a : b; } +int +clamp(int v, int min, int max) +{ + if (v > max) return max; + if (v < min) return min; + return v; +} + +int +floorzero(int v) +{ + return (v >= 0) ? v : 0; +} + + char* wrap_text(char* str, int max_width, int* lines) { @@ -39,7 +54,6 @@ wrap_text(char* str, int max_width, int* lines) str_read += max_width; line_count += 1; - } *lines = line_count; @@ -48,4 +62,17 @@ wrap_text(char* str, int max_width, int* lines) } +/* array stuff */ +int +ar_swap_item(void** arr, int src_index, int dest_index) +{ + void* temp; + + temp = arr[dest_index]; + arr[dest_index] = arr[src_index]; + arr[src_index] = temp; + + return 0; +} +