diff options
| author | 2023-11-26 21:34:11 +0000 | |
|---|---|---|
| committer | 2026-11-07 02:13:38 +0000 | |
| commit | 252df6c74c7be9b82aa89cdb4972f91c87b06184 (patch) | |
| tree | 988497c67eb3d8d8789aa9bdea47bafd300e25b2 /src/utils.h | |
| download | coursework-252df6c74c7be9b82aa89cdb4972f91c87b06184.tar.gz | |
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..c443b52 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | #ifndef UTILS_H | ||
| 2 | #define UTILS_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | |||
| 7 | #define MAX(a, b) ({ \ | ||
| 8 | typeof (a) _a = (a); \ | ||
| 9 | typeof (b) _b = (b); \ | ||
| 10 | _a > _b ? _a : _b; \ | ||
| 11 | }) | ||
| 12 | |||
| 13 | #define MIN(a, b) ({ \ | ||
| 14 | typeof (a) _a = (a); \ | ||
| 15 | typeof (b) _b = (b); \ | ||
| 16 | _a < _b ? _a : _b; \ | ||
| 17 | }) | ||
| 18 | |||
| 19 | #define SWAP(a, b) ({ \ | ||
| 20 | typeof (a) tmp = (a); \ | ||
| 21 | (a) = (b); \ | ||
| 22 | (b) = tmp; \ | ||
| 23 | }) | ||
| 24 | |||
| 25 | #define CLZ(X) __builtin_clz (X) | ||
| 26 | #define CTZ(X) __builtin_ctz (X) | ||
| 27 | #define POPCOUNT(X) __builtin_popcount (X) | ||
| 28 | |||
| 29 | #define NEWLINE() putchar ('\n') | ||
| 30 | #define PAGEBREAK() putchar ('\n'); | ||
| 31 | |||
| 32 | #define SUCCESS(MSG, ...) fprintf (stdout, "[+] SUCCESS: "MSG"\n", ##__VA_ARGS__) | ||
| 33 | #define INFO(MSG, ...) fprintf (stdout, "[*] INFO: " MSG"\n", ##__VA_ARGS__) | ||
| 34 | #define ERROR(MSG, ...) fprintf (stderr, "[-] ERROR: " MSG"\n", ##__VA_ARGS__) | ||
| 35 | |||
| 36 | #define DIE(EXIT_CODE, MSG, ...) ({ ERROR (MSG, ##__VA_ARGS__); exit (EXIT_CODE); }) | ||
| 37 | |||
| 38 | typedef unsigned int uint; | ||
| 39 | typedef uint8_t u8; | ||
| 40 | typedef int8_t s8; | ||
| 41 | typedef uint32_t u32; | ||
| 42 | typedef int32_t s32; | ||
| 43 | typedef uint64_t u64; | ||
| 44 | |||
| 45 | int input (const char *message, const char *regex, const char *template, ...); | ||
| 46 | uint log10ui (uint ui); | ||
| 47 | |||
| 48 | #endif | ||
