vessel/web/include/path-builtin.h
Arija A. bf87b89080
refact: Update macro formats.
Signed-off-by: Arija A. <ari@ari.lt>
2025-06-14 16:20:50 +03:00

133 lines
6.2 KiB
C

#ifndef VESSEL_WEB_PATH_BUILTIN_H_
#define VESSEL_WEB_PATH_BUILTIN_H_
#include "conf.h"
#include "path.h"
#include <vessel/def.h>
#include <vessel/hmap.h>
#define VW_INT_RANGE_NONE ((uint8_t)0x0)
#define VW_INT_RANGE_A ((uint8_t)0x1)
#define VW_INT_RANGE_B ((uint8_t)0x2)
#define VW_INT_RANGE_STEP ((uint8_t)0x4)
typedef struct {
intmax_t a, b;
intmax_t step;
uint8_t set;
} vw_IntRange;
typedef struct {
vs_HMap bools;
} vw_BoolList;
typedef enum {
vw_BoolStatus_false = 0,
vw_BoolStatus_true = 1,
vw_BoolStatus_not_bool = 2,
} vw_BoolStatus;
#define VW_DATE_TIME_SET_NONE ((uint16_t)0x0000)
#define VW_DATE_TIME_SET_YEAR ((uint16_t)0x8000) /* 1000 0000 => Year set */
#define VW_DATE_TIME_SET_MONTH ((uint16_t)0x4000) /* 0100 0000 => Month set */
#define VW_DATE_TIME_SET_DAY ((uint16_t)0x2000) /* 0010 0000 => Day set */
#define VW_DATE_TIME_SET_HOUR ((uint16_t)0x1000) /* 0001 0000 => Hour set */
#define VW_DATE_TIME_SET_MINUTE ((uint16_t)0x0800) /* 0000 1000 => Minute set */
#define VW_DATE_TIME_SET_SECOND ((uint16_t)0x0400) /* 0000 0100 => Second set */
#define VW_DATE_TIME_SET_WEEKDAY \
((uint16_t)0x0200) /* 0000 0010 => Weekday set \
*/
#define VW_DATE_TIME_SET_YEARWEEK ((uint16_t)0x0100) /* 0000 0001 0000 => Year week set */
#define VW_DATE_TIME_SET_YEARDAY ((uint16_t)0x0080) /* 0000 0000 1000 => Day of year set */
#define VW_DATE_TIME_SET_OFFSET ((uint16_t)0x0040) /* 0000 0000 0100 => Offset set */
typedef struct {
uint16_t year;
uint8_t month, day;
uint8_t hour, minute, second;
uint8_t weekday, yearweek;
uint16_t yearday;
float offset;
uint16_t set;
} vw_DateTime;
size_t vw_DateTime_matchn(
vw_DateTime *dt, const char *pat, size_t pat_len, const char *src, size_t src_len);
bool vw_DateTime_print(const vw_DateTime *dt);
bool vw_DateTime_adjust_offset(vw_DateTime *dt, float new_offset);
bool vw_BoolList_init(vw_BoolList *list);
bool vw_BoolList_parse(vw_BoolList *out, const char *list, size_t len);
vw_BoolStatus vw_BoolList_find(const vw_BoolList *list, const char *str, size_t len);
bool vw_BoolList_destroy(vw_BoolList *list);
bool vw_BoolList_print(const vw_BoolList *list);
bool vw_IntRange_parse(vw_IntRange *out, const char *range, size_t len);
bool vw_IntRange_inrange(const vw_IntRange *range, intmax_t n);
bool vw_IntRange_indrange(const vw_IntRange *range, double n);
bool vw_IntRange_print(const vw_IntRange *range);
bool vw_IntRange_expand(const vw_IntRange *range, intmax_t *min, intmax_t *max, intmax_t *step);
#define vw__VESSEL_WEB_PATH_TYPE_BUILTIN_DEFINE(name) \
bool vw_PathType_builtin_##name##_compile(const vw_ArgSource *arg, void **comp); \
bool vw_PathType_builtin_##name##_consume( \
const vw_PathSource *src, size_t *size, size_t *reqb); \
bool vw_PathType_builtin_##name##_convert(const vw_PathSource *src, size_t reqb, void *out); \
bool vw_PathType_builtin_##name##_cleanup(void *comp); \
bool vw_PathType_builtin_##name##_print(const void *comp)
#define vw__VESSEL_WEB_PATH_TYPE_BUILTIN_NOCONV_DEFINE(name) \
bool vw_PathType_builtin_##name##_compile(const vw_ArgSource *arg, void **comp); \
bool vw_PathType_builtin_##name##_consume( \
const vw_PathSource *src, size_t *size, size_t *reqb); \
bool vw_PathType_builtin_##name##_cleanup(void *comp); \
bool vw_PathType_builtin_##name##_print(const void *comp)
#define vw__VESSEL_WEB_PATH_TYPE_BUILTIN_STRLIKE_DEFINE(name) \
bool vw_PathType_builtin_##name##_consume(const vw_PathSource *src, size_t *size, size_t *reqb)
#define vw__VESSEL_WEB_PATH_TYPE_BUILTIN_INTLIKE_DEFINE(name) \
bool vw_PathType_builtin_##name##_consume( \
const vw_PathSource *src, size_t *size, size_t *reqb); \
bool vw_PathType_builtin_##name##_convert(const vw_PathSource *src, size_t reqb, void *out)
#define VW_PATH_TYPE_BUILTIN_ARGS(name) \
vw_PathType_builtin_##name##_compile, vw_PathType_builtin_##name##_consume, \
vw_PathType_builtin_##name##_convert, vw_PathType_builtin_##name##_cleanup, \
vw_PathType_builtin_##name##_print
#define VW_PATH_TYPE_BUILTIN_NOCONV_ARGS(name) \
vw_PathType_builtin_##name##_compile, vw_PathType_builtin_##name##_consume, NULL, \
vw_PathType_builtin_##name##_cleanup, vw_PathType_builtin_##name##_print
#define VW_PATH_TYPE_BUILTIN_STRLIKE_ARGS(name) \
vw_PathType_builtin_str_compile, vw_PathType_builtin_##name##_consume, NULL, \
vw_PathType_builtin_str_cleanup, vw_PathType_builtin_str_print
#define VW_PATH_TYPE_BUILTIN_INTLIKE_ARGS(name) \
vw_PathType_builtin_int_compile, vw_PathType_builtin_##name##_consume, \
vw_PathType_builtin_##name##_convert, vw_PathType_builtin_int_cleanup, \
vw_PathType_builtin_int_print
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_DEFINE(int);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_NOCONV_DEFINE(str);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_STRLIKE_DEFINE(path);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_INTLIKE_DEFINE(float);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_INTLIKE_DEFINE(double);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_DEFINE(bool);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_DEFINE(date);
bool vw_PathType_builtin_uuid_compile(const vw_ArgSource *arg, void **comp);
bool vw_PathType_builtin_uuid_consume(const vw_PathSource *src, size_t *size, size_t *reqb);
bool vw_PathType_builtin_uuid_print(const void *comp);
vw__VESSEL_WEB_PATH_TYPE_BUILTIN_STRLIKE_DEFINE(hex);
#undef vw__VESSEL_WEB_PATH_TYPE_BUILTIN_DEFINE
#undef vw__VESSEL_WEB_PATH_TYPE_BUILTIN_NOCONV_DEFINE
#undef vw__VESSEL_WEB_PATH_TYPE_BUILTIN_STRLIKE_DEFINE
#undef vw__VESSEL_WEB_PATH_TYPE_BUILTIN_INTLIKE_DEFINE
#endif /* VESSEL_WEB_PATH_BUILTIN_H_ */