7 #include "headers/utils.h"
12 return (a < b) ? a : b;
16 clamp(int v, int min, int max)
18 if (v > max) return max;
19 if (v < min) return min;
26 return (v >= 0) ? v : 0;
31 wrap_text(char* str, int max_width, int* lines)
38 wrapped_str = malloc(sizeof(char));
44 for (int i = 0; i < floor(strlen(str)/max_width)+1; i++) {
48 curlen = min(strlen(str_read), max_width);
49 totlen += (curlen+1); // account for new line
51 wrapped_str = realloc(wrapped_str, sizeof(char)*totlen+1); // account for null
52 strncat(wrapped_str, str_read, curlen);
53 strcat(wrapped_str, "\n");
55 str_read += max_width;
67 ar_swap_item(void** arr, int src_index, int dest_index)
71 temp = arr[dest_index];
72 arr[dest_index] = arr[src_index];
73 arr[src_index] = temp;