From 252df6c74c7be9b82aa89cdb4972f91c87b06184 Mon Sep 17 00:00:00 2001 From: Comrade Martin Miroslavovich Michalec Date: Mon, 27 Nov 2023 00:34:11 +0300 Subject: publish --- src/utils.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/utils.h (limited to 'src/utils.h') 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 @@ +#ifndef UTILS_H +#define UTILS_H + +#include +#include + +#define MAX(a, b) ({ \ + typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a > _b ? _a : _b; \ + }) + +#define MIN(a, b) ({ \ + typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a < _b ? _a : _b; \ + }) + +#define SWAP(a, b) ({ \ + typeof (a) tmp = (a); \ + (a) = (b); \ + (b) = tmp; \ + }) + +#define CLZ(X) __builtin_clz (X) +#define CTZ(X) __builtin_ctz (X) +#define POPCOUNT(X) __builtin_popcount (X) + +#define NEWLINE() putchar ('\n') +#define PAGEBREAK() putchar ('\n'); + +#define SUCCESS(MSG, ...) fprintf (stdout, "[+] SUCCESS: "MSG"\n", ##__VA_ARGS__) +#define INFO(MSG, ...) fprintf (stdout, "[*] INFO: " MSG"\n", ##__VA_ARGS__) +#define ERROR(MSG, ...) fprintf (stderr, "[-] ERROR: " MSG"\n", ##__VA_ARGS__) + +#define DIE(EXIT_CODE, MSG, ...) ({ ERROR (MSG, ##__VA_ARGS__); exit (EXIT_CODE); }) + +typedef unsigned int uint; +typedef uint8_t u8; +typedef int8_t s8; +typedef uint32_t u32; +typedef int32_t s32; +typedef uint64_t u64; + +int input (const char *message, const char *regex, const char *template, ...); +uint log10ui (uint ui); + +#endif -- cgit v1.3.1