MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_toml.c File Reference
#include "mrtklib/mrtk_toml.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "mrtklib/mrtk_const.h"
#include "mrtklib/mrtk_trace.h"
#include "tomlc99/toml.h"
Include dependency graph for mrtk_toml.c:

Go to the source code of this file.

Classes

struct  toml_map_t
struct  toml_alias_t

Functions

static toml_table_t * navigate_table (toml_table_t *root, const char *path)
 Navigate to a nested TOML table by dotted path.
static int is_known_key (const char *section, const char *key)
 Report whether a section.key pair is recognized by the loader.
static void check_unknown_keys (toml_table_t *tab, const char *path)
 Recursively walk a parsed TOML table and warn on unrecognized keys. Sub-tables extend the dotted section path; scalar/array leaves are checked against is_known_key(). Catches values silently dropped because their section.key is not in the mapping (typo or stale name).
static int toml_val_to_str (toml_table_t *tbl, const char *key, char *buf, int bufsz)
 Read a TOML key value and convert to string representation compatible with str2opt().
static int navsys_stricmp (const char *a, const char *b)
static int navsys_str2mask (const char *name)
int loadopts_toml (const char *file, opt_t *opts)
 Load options from a TOML configuration file.
int saveopts_toml (const char *file, const char *comment, const opt_t *opts)
 Save options to a TOML configuration file.

Variables

static const toml_map_t toml_mapping []
static const toml_alias_t toml_alias []
static const char *const toml_app_sections [] = {"cssr2rtcm3", "signal_remap", NULL}

Function Documentation

◆ check_unknown_keys()

void check_unknown_keys ( toml_table_t * tab,
const char * path )
static

Recursively walk a parsed TOML table and warn on unrecognized keys. Sub-tables extend the dotted section path; scalar/array leaves are checked against is_known_key(). Catches values silently dropped because their section.key is not in the mapping (typo or stale name).

Parameters
[in]tabTOML table to walk.
[in]pathDotted section path accumulated so far ("" at the root).

Definition at line 455 of file mrtk_toml.c.

References check_unknown_keys(), is_known_key(), toml_key_in(), toml_table_in(), toml_table_narr(), toml_table_nkval(), and toml_table_ntab().

Referenced by check_unknown_keys(), and loadopts_toml().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_known_key()

int is_known_key ( const char * section,
const char * key )
static

Report whether a section.key pair is recognized by the loader.

Parameters
[in]sectionDotted TOML section path.
[in]keyLeaf key name.
Returns
1 if the key is in the mapping, an alias, or an app-owned section.

Definition at line 420 of file mrtk_toml.c.

References toml_alias_t::old_key, toml_alias_t::old_section, toml_alias, toml_app_sections, toml_map_t::toml_key, toml_mapping, and toml_map_t::toml_section.

Referenced by check_unknown_keys().

Here is the caller graph for this function:

◆ loadopts_toml()

int loadopts_toml ( const char * file,
opt_t * opts )
extern

Load options from a TOML configuration file.

Parameters
[in]filePath to the TOML file.
[out]optsOptions table (sysopts[]-compatible, terminated by empty name).
Returns
1 on success, 0 on error.

Reads a TOML file and maps semantic section.key paths to legacy option names in the opts table. Unknown TOML keys are silently skipped.

Definition at line 608 of file mrtk_toml.c.

References check_unknown_keys(), free, toml_alias_t::legacy_name, toml_map_t::legacy_name, MAXSTRPATH, navigate_table(), navsys_str2mask(), toml_alias_t::new_key, toml_alias_t::new_section, toml_datum_t::ok, toml_alias_t::old_key, toml_alias_t::old_section, toml_datum_t::s, searchopt(), str2opt(), toml_alias, toml_array_in(), toml_array_nelem(), toml_free(), toml_map_t::toml_key, toml_key_exists(), toml_mapping, toml_parse_file(), toml_map_t::toml_section, toml_string_at(), toml_val_to_str(), trace(), toml_datum_t::u, and opt_t::var.

Referenced by loadopts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ navigate_table()

toml_table_t * navigate_table ( toml_table_t * root,
const char * path )
static

Navigate to a nested TOML table by dotted path.

Parameters
[in]rootRoot TOML table.
[in]pathDotted path (e.g. "positioning.atmosphere").
Returns
Pointer to the nested table, or NULL if not found.

Definition at line 386 of file mrtk_toml.c.

References toml_table_in().

Referenced by loadopts_toml().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ navsys_str2mask()

int navsys_str2mask ( const char * name)
static

Definition at line 588 of file mrtk_toml.c.

References navsys_stricmp(), SYS_CMP, SYS_GAL, SYS_GLO, SYS_GPS, SYS_IRN, SYS_QZS, and SYS_SBS.

Referenced by loadopts_toml().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ navsys_stricmp()

int navsys_stricmp ( const char * a,
const char * b )
static

Definition at line 579 of file mrtk_toml.c.

Referenced by navsys_str2mask().

Here is the caller graph for this function:

◆ saveopts_toml()

int saveopts_toml ( const char * file,
const char * comment,
const opt_t * opts )
extern

Save options to a TOML configuration file.

Parameters
[in]filePath to the output TOML file.
[in]commentHeader comment (NULL for none).
[in]optsOptions table (terminated by empty name).
Returns
1 on success, 0 on error.

Definition at line 785 of file mrtk_toml.c.

References opt_t::format, toml_map_t::legacy_name, opt2str(), searchopt(), toml_map_t::toml_key, toml_mapping, toml_map_t::toml_section, and trace().

Referenced by saveopts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toml_val_to_str()

int toml_val_to_str ( toml_table_t * tbl,
const char * key,
char * buf,
int bufsz )
static

Read a TOML key value and convert to string representation compatible with str2opt().

Parameters
[in]tblTOML table containing the key.
[in]keyKey name within the table.
[out]bufBuffer to receive the string value.
[in]bufszSize of buf.
Returns
1 if key found and converted, 0 if not found.

Definition at line 490 of file mrtk_toml.c.

References toml_datum_t::b, toml_datum_t::d, free, toml_datum_t::i, toml_datum_t::ok, toml_datum_t::s, toml_array_in(), toml_array_nelem(), toml_bool_in(), toml_double_at(), toml_double_in(), toml_int_at(), toml_int_in(), toml_string_at(), toml_string_in(), and toml_datum_t::u.

Referenced by loadopts_toml().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ toml_alias

const toml_alias_t toml_alias[]
static

Definition at line 340 of file mrtk_toml.c.

Referenced by is_known_key(), and loadopts_toml().

◆ toml_app_sections

const char* const toml_app_sections[] = {"cssr2rtcm3", "signal_remap", NULL}
static

Definition at line 376 of file mrtk_toml.c.

Referenced by is_known_key().

◆ toml_mapping

const toml_map_t toml_mapping[]
static

Definition at line 30 of file mrtk_toml.c.

Referenced by is_known_key(), loadopts_toml(), and saveopts_toml().