1 /* 2 * Copyright (C) 2018-2023 Alexander Borisov 3 * 4 * Author: Alexander Borisov <borisov@lexbor.com> 5 */ 6 7 #ifndef LEXBOR_BASE_H 8 #define LEXBOR_BASE_H 9 10 #ifdef __cplusplus 11 #define __STDC_LIMIT_MACROS 12 #define __STDC_CONSTANT_MACROS 13 14 extern "C" { 15 #endif 16 17 #include <stdlib.h> 18 #include <stddef.h> 19 #include <stdio.h> 20 #include <stdarg.h> 21 #include <memory.h> 22 #include <limits.h> 23 #include <string.h> 24 25 #include "lexbor/core/def.h" 26 #include "lexbor/core/types.h" 27 #include "lexbor/core/lexbor.h" 28 29 #define LEXBOR_VERSION_MAJOR 1 30 #define LEXBOR_VERSION_MINOR 7 31 #define LEXBOR_VERSION_PATCH 0 32 33 #define LEXBOR_VERSION_STRING LEXBOR_STRINGIZE(LEXBOR_VERSION_MAJOR) "." \ 34 LEXBOR_STRINGIZE(LEXBOR_VERSION_MINOR) "." \ 35 LEXBOR_STRINGIZE(LEXBOR_VERSION_PATCH) 36 37 #define lexbor_assert(val) 38 39 #define lexbor_max(val1, val2) ((val1) > (val2) ? (val1) : (val2)) 40 #define lexbor_min(val1, val2) ((val1) < (val2) ? (val1) : (val2)) 41 42 43 /* 44 * Very important!!! 45 * 46 * for lexbor 0..00AFFF; LXB_STATUS_OK == 0x000000 47 */ 48 typedef enum { 49 LXB_STATUS_OK = 0x0000, 50 LXB_STATUS_ERROR = 0x0001, 51 LXB_STATUS_ERROR_MEMORY_ALLOCATION, 52 LXB_STATUS_ERROR_OBJECT_IS_NULL, 53 LXB_STATUS_ERROR_SMALL_BUFFER, 54 LXB_STATUS_ERROR_INCOMPLETE_OBJECT, 55 LXB_STATUS_ERROR_NO_FREE_SLOT, 56 LXB_STATUS_ERROR_TOO_SMALL_SIZE, 57 LXB_STATUS_ERROR_NOT_EXISTS, 58 LXB_STATUS_ERROR_WRONG_ARGS, 59 LXB_STATUS_ERROR_WRONG_STAGE, 60 LXB_STATUS_ERROR_UNEXPECTED_RESULT, 61 LXB_STATUS_ERROR_UNEXPECTED_DATA, 62 LXB_STATUS_ERROR_OVERFLOW, 63 LXB_STATUS_CONTINUE, 64 LXB_STATUS_SMALL_BUFFER, 65 LXB_STATUS_ABORTED, 66 LXB_STATUS_STOPPED, 67 LXB_STATUS_NEXT, 68 LXB_STATUS_STOP, 69 LXB_STATUS_WARNING 70 } 71 lexbor_status_t; 72 73 typedef enum { 74 LEXBOR_ACTION_OK = 0x00, 75 LEXBOR_ACTION_STOP = 0x01, 76 LEXBOR_ACTION_NEXT = 0x02 77 } 78 lexbor_action_t; 79 80 81 typedef lxb_status_t 82 (*lexbor_serialize_cb_f)(const lxb_char_t *data, size_t len, void *ctx); 83 84 typedef lxb_status_t 85 (*lexbor_serialize_cb_cp_f)(const lxb_codepoint_t *cps, size_t len, void *ctx); 86 87 88 typedef struct { 89 lexbor_serialize_cb_f cb; 90 void *ctx; 91 92 intptr_t opt; 93 size_t count; 94 } 95 lexbor_serialize_ctx_t; 96 97 98 #ifdef __cplusplus 99 } /* extern "C" */ 100 #endif 101 102 #endif /* LEXBOR_BASE_H */ 103 104