Cthulhu  0.2.10
Cthulhu compiler collection
common.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #pragma once
4 
5 #include "argparse/argparse.h"
6 
7 #include "config/config.h"
8 #include "core/analyze.h"
9 
10 #include <gmp.h>
11 
12 #define APLTYPE where_t
13 
14 typedef struct vector_t vector_t;
15 typedef struct map_t map_t;
16 typedef struct scan_t scan_t;
17 
18 typedef struct ap_callback_t
19 {
21  void *data;
23 
25 typedef struct ap_t
26 {
29 
32 
34  // map_t<const char*, cfg_field_t*>
36 
37  // param -> vector<ap_event_t> lookup
39 
40  // vector<ap_callback_t> for positional arguments
42 
45  // vector_t<const char*>
47 
50  // vector_t<const char*>
52 
56 
59  size_t count;
60 } ap_t;
61 
62 typedef struct ap_field_t
63 {
65  bool negate;
66 } ap_field_t;
67 
68 CT_ARGPARSE_API int ap_parse_common(ap_t *self, const char *text);
69 
70 CT_ARGPARSE_API void ap_on_string(scan_t *scan, cfg_field_t *param, char *value);
71 CT_ARGPARSE_API void ap_on_bool(scan_t *scan, cfg_field_t *param, bool value);
72 CT_ARGPARSE_API void ap_on_int(scan_t *scan, cfg_field_t *param, mpz_t value);
73 
74 CT_ARGPARSE_API void ap_on_posarg(scan_t *scan, char *value);
75 
76 STA_PRINTF(2, 3)
77 CT_ARGPARSE_API void ap_add_error(ap_t *self, const char *fmt, ...);
78 
79 CT_ARGPARSE_API void ap_on_invalid(scan_t *scan, char *value);
80 
81 CT_ARGPARSE_API int ap_get_opt(scan_t *scan, const char *name, ap_field_t *param, char **value);
#define STA_PRINTF(a, b)
mark a function as a printf style function
Definition: analyze.h:165
bool(* ap_event_t)(ap_t *ap, const cfg_field_t *param, const void *value, void *data)
callback for a parameter event called when a parameter is parsed return true to indicate the event wa...
Definition: argparse.h:44
CT_NODISCARD STA_FORMAT_STRING const char * fmt
Definition: str.h:68
void * data
Definition: common.h:21
ap_event_t callback
Definition: common.h:20
cfg_field_t * field
Definition: common.h:64
bool negate
Definition: common.h:65
argparse instance
Definition: common.h:26
vector_t * posarg_callbacks
Definition: common.h:41
arena_t * arena
allocation arena
Definition: common.h:28
size_t count
tracks the number of encountered arguments only counts arguments that are not positional or unknown
Definition: common.h:59
vector_t * unknown
all unknown arguments arguments that the config did not register at startup
Definition: common.h:51
map_t * name_lookup
a mapping of names to parameters
Definition: common.h:35
vector_t * posargs
all positional arguments ie arguments without a leading dash or slash
Definition: common.h:46
vector_t * errors
all errors errors other than unknown arguments
Definition: common.h:55
map_t * event_lookup
Definition: common.h:38
cfg_group_t * config
the root config group
Definition: common.h:31
an allocator object
Definition: arena.h:86
an unordered hash map
Definition: map.h:38
a source file scanner
Definition: scan.h:24
a generic vector of pointers
Definition: vector.c:16
CT_ARGPARSE_API void ap_add_error(ap_t *self, const char *fmt,...)
Definition: common.c:37
CT_ARGPARSE_API void ap_on_int(scan_t *scan, cfg_field_t *param, mpz_t value)
Definition: common.c:133
CT_ARGPARSE_API void ap_on_bool(scan_t *scan, cfg_field_t *param, bool value)
Definition: common.c:122
CT_ARGPARSE_API int ap_parse_common(ap_t *self, const char *text)
Definition: parse.c:86
CT_ARGPARSE_API void ap_on_string(scan_t *scan, cfg_field_t *param, char *value)
Definition: common.c:90
CT_ARGPARSE_API void ap_on_posarg(scan_t *scan, char *value)
Definition: common.c:150
CT_ARGPARSE_API void ap_on_invalid(scan_t *scan, char *value)
Definition: common.c:157
CT_ARGPARSE_API int ap_get_opt(scan_t *scan, const char *name, ap_field_t *param, char **value)
Definition: parse.c:153