slweb

Једноставни генератор статичких веб страна
git clone https://git.sr.ht/~strahinja/slweb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 9c5daccbf45b9d5aa21a474cf9b1f9d096783d1b
родитељ 7b80817d05997c1c2db48ef89ca571e6ad0c0c3c
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Mon, 22 Jul 2024 16:49:39 +0200

defs.h: Remove unused macros; add and document set macros; remove 
UBYTE, ULONG, ULLONG typedefs

Diffstat:
Mdefs.h | 147+++++++++++++++++++++++++++++++++++--------------------------------------------
измењених датотека: 1, додавања: 65(+), брисања: 82(-)

diff --git a/defs.h b/defs.h @@ -27,9 +27,24 @@ static const char* CMD_IDENTIFY = "identify %s | sed -e's/.* \\([0-9]\\{1,\\}\\)x\\([0-9]\\{1,\\}\\)" ".*/width=\"\\1\" height=\"\\2\"/g'"; -#define ALL(var, mask) (((var) & (mask)) == (mask)) -#define ANY(var, mask) (((var) & (mask)) != 0) -#define IN(var, mask) ALL(var, mask) +/* clang-format off */ +/* True iff all given "members" are present in the set */ +/* Usage: ALL(state, STATE1 | STATE2 | ...) */ +#define ALL(var, mask) (((var) & (mask)) == (mask)) +/* True if any of the given "members" are present in the set */ +/* Usage: ANY(state, STATE1 | STATE2 | ...) */ +#define ANY(var, mask) (((var) & (mask)) != 0) +/* Removes the given "members" from the set */ +/* Usage: CLEAR(state, STATE1 | STATE2 | ...) */ +#define CLEAR(v, c) do { (v) &= ~(c); } while(0) +#define IN(var, mask) ALL(var, mask) +/* Adds the given "members" to the set */ +/* Usage: SET(state, STATE1 | STATE2 | ...) */ +#define SET(v, c) do { (v) |= (c); } while(0) +/* Adds/removes the given "members" to/from the set */ +/* Usage: TOGGLE(state, STATE1 | STATE2 | ...) */ +#define TOGGLE(v, c) do { (v) ^= (c); } while(0) +/* clang-format on */ #define MIN(a, b) ((a < b) ? (a) : (b)) #define UNUSED(x) ((void)(x)) @@ -107,55 +122,23 @@ static const char* CMD_IDENTIFY ptoken = token; \ } while (0) -#define ENSURE_SIZE(to, temp, tosize, testsize, fromsize, label, type) \ - do \ - { \ - if (!to || tosize < testsize) \ - { \ - tosize = fromsize; \ - temp = realloc(to, tosize * sizeof(type)); \ - if (!temp) \ - { \ - perror("realloc"); \ - goto label; \ - } \ - to = temp; \ - } \ - } while (0) - -/* - * - Make sure the size of the destination string is large enough to copy, and - * copy - * - Sizes are in bytes - * - lval: to, temp, tosize - * - indexable: to - * - We explicitly use fromsize in MEMCCPY, because we ensured that tosize is - * at least as big, and to allow a subset of from to be copied - */ -#define U8_SAFE_COPY(to, temp, tosize, from, fromsize, label) \ - do \ - { \ - ENSURE_SIZE(to, temp, tosize, fromsize, fromsize, label, char); \ - MEMCCPY(to, from, fromsize, temp); \ - } while (0) -/* - * - Make sure the size of the destination string is large enough to copy, and - * copy - * - Sizes are in uint32_t units - * - We explicitly use fromsize in U32_MEMCCPY, because we ensured that tosize - * is at least as big, and to allow a subset of from to be copied - */ -#define U32_SAFE_COPY(to, temp, tosize, from, fromsize, label) \ +#define ENSURE_SIZE(to, temp, tosize, testsize, fromsize, label, type) \ do \ { \ - ENSURE_SIZE(to, temp, tosize, fromsize, fromsize, label, \ - uint32_t); \ - U32_MEMCCPY(to, from, fromsize, temp); \ + if (!(to) || (tosize) < (testsize)) \ + { \ + (tosize) = fromsize; \ + temp = realloc(to, (tosize) * sizeof(type)); \ + if (!temp) \ + { \ + perror(PROGRAMNAME ": realloc"); \ + goto label; \ + } \ + (to) = temp; \ + } \ } while (0) -typedef unsigned char UBYTE; typedef unsigned long ULONG; -typedef unsigned long long ULLONG; typedef enum { CMD_NONE, @@ -182,41 +165,41 @@ typedef int (*tsv_callback_t)(FILE* output, u8** tsv_header, u8** tsv_register); #define ST_NONE 0 #define ST_YAML 1 -#define ST_YAML_VAL ((ULLONG)1 << 1) -#define ST_PARA_OPEN ((ULLONG)1 << 2) -#define ST_TAG ((ULLONG)1 << 3) -#define ST_HEADING ((ULLONG)1 << 4) -#define ST_HEADING_TEXT ((ULLONG)1 << 5) -#define ST_BOLD ((ULLONG)1 << 6) -#define ST_ITALIC ((ULLONG)1 << 7) -#define ST_PRE ((ULLONG)1 << 8) -#define ST_CODE ((ULLONG)1 << 9) -#define ST_BLOCKQUOTE ((ULLONG)1 << 10) -#define ST_LINK ((ULLONG)1 << 11) -#define ST_LINK_SECOND_ARG ((ULLONG)1 << 12) -#define ST_LINK_SECOND_ARG_END ((ULLONG)1 << 13) -#define ST_LINK_SPAN ((ULLONG)1 << 14) -#define ST_LINK_MACRO ((ULLONG)1 << 15) -#define ST_IMAGE ((ULLONG)1 << 16) -#define ST_IMAGE_SECOND_ARG ((ULLONG)1 << 17) -#define ST_MACRO_BODY ((ULLONG)1 << 18) -#define ST_CSV_BODY ((ULLONG)1 << 19) -#define ST_TSV_BODY ((ULLONG)1 << 20) -#define ST_HTML_TAG ((ULLONG)1 << 21) -#define ST_KBD ((ULLONG)1 << 22) -#define ST_LIST ((ULLONG)1 << 23) -#define ST_NUMLIST ((ULLONG)1 << 24) -#define ST_FOOTNOTE ((ULLONG)1 << 25) -#define ST_FOOTNOTE_TEXT ((ULLONG)1 << 26) -#define ST_INLINE_FOOTNOTE ((ULLONG)1 << 27) -#define ST_FORMULA ((ULLONG)1 << 28) -#define ST_DISPLAY_FORMULA ((ULLONG)1 << 29) -#define ST_TABLE_HEADER ((ULLONG)1 << 30) -#define ST_TABLE_LINE ((ULLONG)1 << 31) -#define ST_TABLE ((ULLONG)1 << 32) -#define ST_STRIKE ((ULLONG)1 << 33) -#define ST_SUMMARY ((ULLONG)1 << 34) -#define ST_INCDIR ((ULLONG)1 << 35) +#define ST_YAML_VAL ((unsigned long long)1 << 1) +#define ST_PARA_OPEN ((unsigned long long)1 << 2) +#define ST_TAG ((unsigned long long)1 << 3) +#define ST_HEADING ((unsigned long long)1 << 4) +#define ST_HEADING_TEXT ((unsigned long long)1 << 5) +#define ST_BOLD ((unsigned long long)1 << 6) +#define ST_ITALIC ((unsigned long long)1 << 7) +#define ST_PRE ((unsigned long long)1 << 8) +#define ST_CODE ((unsigned long long)1 << 9) +#define ST_BLOCKQUOTE ((unsigned long long)1 << 10) +#define ST_LINK ((unsigned long long)1 << 11) +#define ST_LINK_SECOND_ARG ((unsigned long long)1 << 12) +#define ST_LINK_SECOND_ARG_END ((unsigned long long)1 << 13) +#define ST_LINK_SPAN ((unsigned long long)1 << 14) +#define ST_LINK_MACRO ((unsigned long long)1 << 15) +#define ST_IMAGE ((unsigned long long)1 << 16) +#define ST_IMAGE_SECOND_ARG ((unsigned long long)1 << 17) +#define ST_MACRO_BODY ((unsigned long long)1 << 18) +#define ST_CSV_BODY ((unsigned long long)1 << 19) +#define ST_TSV_BODY ((unsigned long long)1 << 20) +#define ST_HTML_TAG ((unsigned long long)1 << 21) +#define ST_KBD ((unsigned long long)1 << 22) +#define ST_LIST ((unsigned long long)1 << 23) +#define ST_NUMLIST ((unsigned long long)1 << 24) +#define ST_FOOTNOTE ((unsigned long long)1 << 25) +#define ST_FOOTNOTE_TEXT ((unsigned long long)1 << 26) +#define ST_INLINE_FOOTNOTE ((unsigned long long)1 << 27) +#define ST_FORMULA ((unsigned long long)1 << 28) +#define ST_DISPLAY_FORMULA ((unsigned long long)1 << 29) +#define ST_TABLE_HEADER ((unsigned long long)1 << 30) +#define ST_TABLE_LINE ((unsigned long long)1 << 31) +#define ST_TABLE ((unsigned long long)1 << 32) +#define ST_STRIKE ((unsigned long long)1 << 33) +#define ST_SUMMARY ((unsigned long long)1 << 34) +#define ST_INCDIR ((unsigned long long)1 << 35) #define ST_CS_NONE 0 #define ST_CS_HEADER 1