102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
schema.c File Reference
#include "config_internal.h"
#include <dttr_log.h>
#include <dttr_path.h>
#include <khash.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define CONFIG_LOOKUP_KEY_CAPACITY   64
#define FIELD(_section, _key, _field, _type)
#define FIELD_TOP(_key, _field, _type)
#define FIELD_GAMEPAD_AXIS(_key, _index)
#define FIELD_GAMEPAD_DEADZONE(_key, _index)
#define CONFIG_SCHEMA_COUNT   ((int)SDL_arraysize(config_schema))
#define CONFIG_ASSIGN_TYPES(X)
#define CONFIG_ASSIGN_FN(value_type, type, default_val, parse_fn, fn_name)
#define CONFIG_ASSIGN_CASE(value_type, type, default_val, parse_fn, fn_name)

Functions

static khash_t (dttr_config_lookup)
int DTTR_Config_SchemaCount ()
const DTTR_ConfigFieldSpecDTTR_Config_SchemaGet (int index)
static const char * config_field_bytes (const DTTR_Config *config, const DTTR_ConfigFieldSpec *spec)
bool DTTR_Config_FieldChanged (const DTTR_Config *current, const DTTR_Config *base, const DTTR_ConfigFieldSpec *spec)
bool DTTR_Config_SchemaChanged (const DTTR_Config *current, const DTTR_Config *base)
static void config_schema_init ()
const DTTR_ConfigFieldSpecconfig_schema_find (const char *section, const char *key)
static bool config_assign_string (char *field, size_t field_size, const char *value)
bool config_apply_entry (DTTR_Config *config, const char *section, const char *key, const char *value)

Variables

static const DTTR_ConfigFieldSpec config_schema []

Macro Definition Documentation

◆ CONFIG_ASSIGN_CASE

#define CONFIG_ASSIGN_CASE ( value_type,
type,
default_val,
parse_fn,
fn_name )
Value:
case value_type: \
return fn_name(field, value);

Referenced by config_apply_entry().

◆ CONFIG_ASSIGN_FN

#define CONFIG_ASSIGN_FN ( value_type,
type,
default_val,
parse_fn,
fn_name )
Value:
static bool fn_name(char *field, const char *value) { \
type parsed = default_val; \
if (!parse_fn(value, &parsed)) { \
return false; \
} \
*(type *)field = parsed; \
return true; \
}
const DTTR_PrimitiveType type

Definition at line 234 of file schema.c.

◆ CONFIG_ASSIGN_TYPES

#define CONFIG_ASSIGN_TYPES ( X)

Definition at line 193 of file schema.c.

Referenced by config_apply_entry().

◆ CONFIG_LOOKUP_KEY_CAPACITY

#define CONFIG_LOOKUP_KEY_CAPACITY   64

Definition at line 11 of file schema.c.

Referenced by config_schema_find(), and khash_t().

◆ CONFIG_SCHEMA_COUNT

#define CONFIG_SCHEMA_COUNT   ((int)SDL_arraysize(config_schema))

◆ FIELD

#define FIELD ( _section,
_key,
_field,
_type )
Value:
{ \
.section = (_section), \
.key = (_key), \
.offset = offsetof(DTTR_Config, _field), \
.size = sizeof(((DTTR_Config *)0)->_field), \
.value_type = (_type) \
}

Definition at line 16 of file schema.c.

◆ FIELD_GAMEPAD_AXIS

#define FIELD_GAMEPAD_AXIS ( _key,
_index )
Value:
FIELD("gamepad", _key, gamepad_axes[_index], CONFIG_GAMEPAD_AXIS),
@ CONFIG_GAMEPAD_AXIS
#define FIELD(_section, _key, _field, _type)
Definition schema.c:16

Definition at line 26 of file schema.c.

◆ FIELD_GAMEPAD_DEADZONE

#define FIELD_GAMEPAD_DEADZONE ( _key,
_index )
Value:
FIELD("gamepad", _key, gamepad_axis_deadzone[_index], CONFIG_INT),
@ CONFIG_INT

Definition at line 28 of file schema.c.

◆ FIELD_TOP

#define FIELD_TOP ( _key,
_field,
_type )
Value:
FIELD(NULL, _key, _field, _type)
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL

Definition at line 25 of file schema.c.

Function Documentation

◆ config_apply_entry()

bool config_apply_entry ( DTTR_Config * config,
const char * section,
const char * key,
const char * value )

◆ config_assign_string()

bool config_assign_string ( char * field,
size_t field_size,
const char * value )
static

Definition at line 248 of file schema.c.

References config_parse_string().

Referenced by config_apply_entry().

◆ config_field_bytes()

const char * config_field_bytes ( const DTTR_Config * config,
const DTTR_ConfigFieldSpec * spec )
static

Definition at line 103 of file schema.c.

References DTTR_ConfigFieldSpec::offset.

Referenced by DTTR_Config_FieldChanged().

◆ config_schema_find()

const DTTR_ConfigFieldSpec * config_schema_find ( const char * section,
const char * key )

◆ config_schema_init()

void config_schema_init ( )
static

◆ DTTR_Config_FieldChanged()

bool DTTR_Config_FieldChanged ( const DTTR_Config * current,
const DTTR_Config * base,
const DTTR_ConfigFieldSpec * spec )

◆ DTTR_Config_SchemaChanged()

bool DTTR_Config_SchemaChanged ( const DTTR_Config * current,
const DTTR_Config * base )

Definition at line 128 of file schema.c.

References config_schema, CONFIG_SCHEMA_COUNT, and DTTR_Config_FieldChanged().

Referenced by config_has_unsaved_changes().

◆ DTTR_Config_SchemaCount()

int DTTR_Config_SchemaCount ( )

Definition at line 91 of file schema.c.

References CONFIG_SCHEMA_COUNT.

Referenced by config_add_schema_fields().

◆ DTTR_Config_SchemaGet()

const DTTR_ConfigFieldSpec * DTTR_Config_SchemaGet ( int index)

Definition at line 95 of file schema.c.

References config_schema, CONFIG_SCHEMA_COUNT, and NULL.

Referenced by config_add_schema_fields(), and config_schema_find().

◆ khash_t()

khash_t ( dttr_config_lookup )
static

Definition at line 77 of file schema.c.

References CONFIG_LOOKUP_KEY_CAPACITY, CONFIG_SCHEMA_COUNT, and NULL.

Referenced by khash_t().

Variable Documentation

◆ config_schema

const DTTR_ConfigFieldSpec config_schema[]
static

Definition at line 31 of file schema.c.

Referenced by config_schema_init(), DTTR_Config_SchemaChanged(), and DTTR_Config_SchemaGet().