diff options
author | midipix <writeonce@midipix.org> | 2024-04-29 02:39:30 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2024-05-07 20:07:25 +0000 |
commit | 02e59c946d51faf976a85610e44d7b0ccf4a6e59 (patch) | |
tree | 660056e01b242e947e27c470b9989c7b1ae6b2b7 /include | |
parent | e9098c5591f439cdf8a923c9298b8fc7ff28a3ac (diff) | |
download | treebnf-02e59c946d51faf976a85610e44d7b0ccf4a6e59.tar.bz2 treebnf-02e59c946d51faf976a85610e44d7b0ccf4a6e59.tar.xz |
driver: created program skeleton.
Diffstat (limited to 'include')
-rw-r--r-- | include/treebnf/treebnf.h | 142 | ||||
-rw-r--r-- | include/treebnf/treebnf_api.h | 35 |
2 files changed, 177 insertions, 0 deletions
diff --git a/include/treebnf/treebnf.h b/include/treebnf/treebnf.h new file mode 100644 index 0000000..c10f115 --- /dev/null +++ b/include/treebnf/treebnf.h @@ -0,0 +1,142 @@ +#ifndef TREEBNF_H +#define TREEBNF_H + +#include <fcntl.h> +#include <stdint.h> +#include <stddef.h> + +#include "treebnf_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* pre-alpha */ +#ifndef TBNF_APP +#ifndef TBNF_PRE_ALPHA +#error libtreebnf: pre-alpha: ABI is not final! +#error to use the library, please pass -DTBNF_PRE_ALPHA to the compiler. +#endif +#endif + +/* status codes */ +#define TBNF_OK 0x00 +#define TBNF_USAGE 0x01 +#define TBNF_ERROR 0x02 + +/* driver flags */ +#define TBNF_DRIVER_XFLAG(x) ((uint64_t)(x) << 32) + +#define TBNF_DRIVER_VERBOSITY_NONE 0x0000 +#define TBNF_DRIVER_VERBOSITY_ERRORS 0x0001 +#define TBNF_DRIVER_VERBOSITY_STATUS 0x0002 +#define TBNF_DRIVER_VERBOSITY_USAGE 0x0004 +#define TBNF_DRIVER_CLONE_VECTOR 0x0008 + +#define TBNF_DRIVER_VERSION 0x0010 + +#define TBNF_DRIVER_ANNOTATE_ALWAYS 0x10000000 +#define TBNF_DRIVER_ANNOTATE_NEVER 0x20000000 +#define TBNF_DRIVER_ANNOTATE_FULL 0x40000000 + +/* error flags */ +#define TBNF_ERROR_TOP_LEVEL 0x0001 +#define TBNF_ERROR_NESTED 0x0002 +#define TBNF_ERROR_CHILD 0x0004 +#define TBNF_ERROR_CUSTOM 0x0008 + +enum tbnf_custom_error { + TBNF_ERR_FLOW_ERROR, + TBNF_ERR_NULL_CONTEXT, + TBNF_ERR_IMAGE_SIZE_ZERO, +}; + +struct tbnf_raw_input { + void * map_addr; + size_t map_size; +}; + +struct tbnf_source_version { + int major; + int minor; + int revision; + const char * commit; +}; + +struct tbnf_fd_ctx { + int fdin; + int fdout; + int fderr; + int fdlog; + int fdcwd; + int fddst; +}; + +struct tbnf_error_info { + const struct tbnf_driver_ctx * edctx; + int esyscode; + int elibcode; + const char * efunction; + int eline; + unsigned eflags; + void * eany; +}; + +struct tbnf_common_ctx { + uint64_t drvflags; + uint64_t actflags; + uint64_t fmtflags; +}; + +struct tbnf_driver_ctx { + const char * program; + const char * module; + const char ** units; + const struct tbnf_common_ctx * cctx; + struct tbnf_error_info ** errv; + void * any; +}; + +struct tbnf_unit_ctx { + const char * const * path; + const struct tbnf_raw_input * map; + void * any; +}; + +/* driver api */ +tbnf_api int tbnf_lib_get_driver_ctx (char ** argv, char ** envp, uint64_t flags, + const struct tbnf_fd_ctx *, + struct tbnf_driver_ctx **); + +tbnf_api void tbnf_lib_free_driver_ctx (struct tbnf_driver_ctx *); + +tbnf_api int tbnf_lib_get_unit_ctx (const struct tbnf_driver_ctx *, const char * path, + struct tbnf_unit_ctx **); + +tbnf_api void tbnf_lib_free_unit_ctx (struct tbnf_unit_ctx *); + +tbnf_api int tbnf_lib_get_driver_fdctx (const struct tbnf_driver_ctx *, struct tbnf_fd_ctx *); + +tbnf_api int tbnf_lib_set_driver_fdctx (struct tbnf_driver_ctx *, const struct tbnf_fd_ctx *); + +tbnf_api int tbnf_lib_map_raw_input (const struct tbnf_driver_ctx *, + int fd, const char * path, int prot, + struct tbnf_raw_input *); + +tbnf_api int tbnf_lib_unmap_raw_input (struct tbnf_raw_input *); + +/* utility api */ +tbnf_api int tbnf_main (char **, char **, + const struct tbnf_fd_ctx *); + +tbnf_api int tbnf_output_error_vector (const struct tbnf_driver_ctx *); +tbnf_api int tbnf_output_error_record (const struct tbnf_driver_ctx *, const struct tbnf_error_info *); + +/* package info */ +tbnf_api const struct tbnf_source_version * tbnf_api_source_version(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/treebnf/treebnf_api.h b/include/treebnf/treebnf_api.h new file mode 100644 index 0000000..ca55079 --- /dev/null +++ b/include/treebnf/treebnf_api.h @@ -0,0 +1,35 @@ +#ifndef TREEBNF_API_H +#define TREEBNF_API_H + +#include <limits.h> + +/* tbnf_export */ +#if defined(__dllexport) +#define tbnf_export __dllexport +#else +#define tbnf_export +#endif + +/* tbnf_import */ +#if defined(__dllimport) +#define tbnf_import __dllimport +#else +#define tbnf_import +#endif + +/* tbnf_api */ +#ifndef TBNF_APP +#if defined (TBNF_EXPORT) +#define tbnf_api tbnf_export +#elif defined (TBNF_IMPORT) +#define tbnf_api tbnf_import +#elif defined (TBNF_STATIC) +#define tbnf_api +#else +#define tbnf_api +#endif +#else +#define tbnf_api +#endif + +#endif |