libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_auto_resolver.c File Reference
#include "amxo_parser_priv.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

static void amxo_resolver_auto_defaults (amxo_parser_t *parser, UNUSED void *priv)
 
static amxo_fn_ptr_t amxo_resolver_auto (amxo_parser_t *parser, const char *fn_name, amxo_fn_type_t type, UNUSED const char *data, UNUSED void *priv)
 
 CONSTRUCTOR_LVL (110)
 
 DESTRUCTOR_LVL (110)
 

Variables

static amxo_resolver_t res_auto
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxo_auto_resolver.c.

Function Documentation

◆ amxo_resolver_auto()

static amxo_fn_ptr_t amxo_resolver_auto ( amxo_parser_t parser,
const char *  fn_name,
amxo_fn_type_t  type,
UNUSED const char *  data,
UNUSED void *  priv 
)
static

Definition at line 73 of file amxo_auto_resolver.c.

77  {
78  int retval = -1;
79  amxc_var_t* config = amxo_parser_claim_config(parser, "auto-resolver-order");
80  const amxc_llist_t* order = amxc_var_constcast(amxc_llist_t, config);
81  amxc_htable_t* resolvers = amxo_parser_get_resolvers();
82  amxc_var_t used_resolvers;
83  const char* name = NULL;
84 
85  amxc_var_init(&used_resolvers);
86  amxc_var_set_type(&used_resolvers, AMXC_VAR_ID_HTABLE);
87  amxc_var_add_key(bool, &used_resolvers, "auto", true);
88  amxc_llist_for_each(it, order) {
89  name = amxc_var_constcast(cstring_t, amxc_var_from_llist_it(it));
90  if(name[0] == '*') {
91  break;
92  }
93  retval = amxo_parser_resolve(parser, name, fn_name, type, NULL);
94  when_true(retval == 0, exit);
95  amxc_var_add_key(bool, &used_resolvers, name, true);
96  }
97 
98  when_true((name != NULL && name[0] != '*'), exit);
99 
100  amxc_htable_for_each(hit, resolvers) {
101  name = amxc_htable_it_get_key(hit);
102  if(amxc_var_get_key(&used_resolvers, name, AMXC_VAR_FLAG_DEFAULT)) {
103  continue;
104  }
105  retval = amxo_parser_resolve(parser, name, fn_name, type, NULL);
106  when_true(retval == 0, exit);
107  }
108 
109 exit:
110  amxc_var_clean(&used_resolvers);
111  if(retval == 0) {
112  return parser->resolved_fn;
113  } else {
114  return NULL;
115  }
116 }
PRIVATE amxc_htable_t * amxo_parser_get_resolvers(void)
PRIVATE int amxo_parser_resolve(amxo_parser_t *parser, const char *resolver_name, const char *func_name, amxo_fn_type_t type, const char *data)
static amxc_htable_t resolvers
config
amxc_var_t * amxo_parser_claim_config(amxo_parser_t *parser, const char *path)
Gets or creates a configuration option.
amxo_fn_ptr_t resolved_fn
Definition: amxo_types.h:266

◆ amxo_resolver_auto_defaults()

static void amxo_resolver_auto_defaults ( amxo_parser_t parser,
UNUSED void *  priv 
)
static

Definition at line 61 of file amxo_auto_resolver.c.

62  {
63  amxc_var_t* config = amxo_parser_claim_config(parser, "auto-resolver-order");
64  amxc_var_set_type(config, AMXC_VAR_ID_LIST);
65 
66  amxc_var_add(cstring_t, config, "ftab");
67  amxc_var_add(cstring_t, config, "import");
68  amxc_var_add(cstring_t, config, "*");
69 
70  return;
71 }

◆ CONSTRUCTOR_LVL()

CONSTRUCTOR_LVL ( 110  )

Definition at line 126 of file amxo_auto_resolver.c.

126  {
128 }
static amxo_resolver_t res_auto
int amxo_register_resolver(const char *name, amxo_resolver_t *resolver)
Registers a function resolver.

◆ DESTRUCTOR_LVL()

DESTRUCTOR_LVL ( 110  )

Definition at line 130 of file amxo_auto_resolver.c.

130  {
131  amxo_unregister_resolver("auto");
132 }
int amxo_unregister_resolver(const char *name)
Unregisters a function resolver.

Variable Documentation

◆ res_auto

amxo_resolver_t res_auto
static
Initial value:
= {
.hit = { .ait = NULL, .key = NULL, .next = NULL },
.resolve = amxo_resolver_auto,
.clean = NULL,
.priv = NULL
}
static amxo_fn_ptr_t amxo_resolver_auto(amxo_parser_t *parser, const char *fn_name, amxo_fn_type_t type, UNUSED const char *data, UNUSED void *priv)
static void amxo_resolver_auto_defaults(amxo_parser_t *parser, UNUSED void *priv)

Definition at line 118 of file amxo_auto_resolver.c.