C ABI
Create a parser, register sources, and request values through the opaque DIP handle.
Basic examples
Parse text and read one value. Link these C examples against snt-c:
#include <snt/c/dip.h>
#include <stdio.h>
int main(void) {
snt_dip* parser = NULL;
snt_dip_error error = {0};
char value[128];
int failed = snt_dip_parser_create(&parser, &error) ||
snt_dip_parser_add_string(parser, "steps int = 100", &error) ||
snt_dip_parser_parse(parser, &error) ||
snt_dip_parser_get(parser, "steps", value, sizeof(value), &error);
if (failed) fprintf(stderr, "%s\n", error.message);
else puts(value); /* 100 */
snt_dip_parser_free(parser);
return failed;
}
Register an override before parsing:
#include <snt/c/dip.h>
#include <stdio.h>
int main(void) {
snt_dip* parser = NULL;
snt_dip_error error = {0};
char value[128];
int failed = snt_dip_parser_create(&parser, &error) ||
snt_dip_parser_add_string(parser, "steps int = 100", &error) ||
snt_dip_parser_add_override_string(parser, "steps = 200", &error) ||
snt_dip_parser_parse(parser, &error) ||
snt_dip_parser_get(parser, "steps", value, sizeof(value), &error);
if (failed) fprintf(stderr, "%s\n", error.message);
else puts(value); /* 200 */
snt_dip_parser_free(parser);
return failed;
}
Common workflows
Task |
Call chain |
Result |
|---|---|---|
Create and evaluate |
|
Owned |
Read a scalar as text |
|
Caller-owned buffer |
Traverse a hierarchy |
|
Owned |
Read typed values or arrays |
|
C scalar or caller-owned array |
Persist, export, or report |
|
DIPH5, generated source, or report file |
Compare snapshots |
|
Owned |
Release owned objects |
|
No result; free nodes before their parser |
snt_dip* dip = NULL;
snt_dip_error error = {0};
int failed = snt_dip_parser_create(&dip, &error) ||
snt_dip_parser_add_string(dip, "steps int = 100", &error) ||
snt_dip_parser_parse(dip, &error) ||
snt_dip_environment_save(dip, "run.diph5", &error);
if (failed) {
fprintf(stderr, "%s\n", error.message);
} else {
snt_dip_comparison* changes = NULL;
size_t added = 0, removed = 0, changed = 0;
if (snt_dip_compare_files("before.diph5", "run.diph5",
SNT_DIP_COMPARE_EFFECTIVE, 3, &changes, &error) == 0) {
snt_dip_comparison_summary(changes, &added, &removed, &changed, &error);
printf("%zu changed\n", changed);
snt_dip_comparison_free(changes);
}
}
snt_dip_parser_free(dip);
Every node returned by snt_dip_node_get_child, get_item, get_element,
or get_entry is independently owned. Free it with snt_dip_node_free
before the parser. Comparison strings and index pointers borrow the comparison
handle and remain valid only until snt_dip_comparison_free.
See the C binding guide and C API reference.
DIPL developer tools. The C ABI parses and evaluates DIPL and reports
parser diagnostics through snt_dip_error. It does not currently expose
formatter, validator, or linter entry points. Use the CLI or the C++ tools for
those operations.
Current limitations and differences
Compared with the canonical C++ implementation:
The ABI exposes opaque parser and node handles, typed scalar/array getters, metadata, persistence, export, reports, and snapshot comparison. It does not expose host callbacks, adapters, semantic descriptions/previews, or the C++ editing, guided-setup, and experiment classes.
Dependency graphs can be recorded for persistence and reports, but the ABI has no graph-traversal interface.
Standalone formatter, validator, and linter entry points are absent; parsing reports validation errors. Use the CLI or C++ tooling API for source tools. Callers manage buffers and free handles; errors use return codes.
Binding reference
This is a lookup index, not a sequence to read from top to bottom. Use
Common workflows above to choose a task, then find the exact C function
below. Integer-returning calls return zero on success. Output handles and
buffers are passed by pointer; a nonzero result reports code and
message through snt_dip_error.
Parser and input registration
snt_dip_parser_create(&dip, &error)andsnt_dip_parser_free(dip).snt_dip_parser_add_stringandsnt_dip_parser_add_file.snt_dip_parser_add_schema_string,snt_dip_parser_add_schema_file,snt_dip_parser_add_override_string, andsnt_dip_parser_add_override_file.snt_dip_parser_add_project,snt_dip_parser_parse, andsnt_dip_parser_parse_with_graph.snt_dip_parser_get(dip, path, buffer, capacity, &error)andsnt_dip_environment_get_node(dip, path, &node, &error).
Node hierarchy and values
snt_dip_node_get_kind,snt_dip_node_get_node_type,snt_dip_node_get_path, andsnt_dip_node_get_link_target.snt_dip_node_get_child,snt_dip_node_get_item,snt_dip_node_get_key,snt_dip_node_get_element, andsnt_dip_node_get_entry.snt_dip_node_get_size,snt_dip_node_get_type,snt_dip_node_get_shape, andsnt_dip_node_get_value_size.snt_dip_node_get_bool,snt_dip_node_get_int64,snt_dip_node_get_uint64,snt_dip_node_get_double, andsnt_dip_node_get_string.snt_dip_node_get_bool_at,snt_dip_node_get_int64_at,snt_dip_node_get_uint64_at,snt_dip_node_get_double_at, andsnt_dip_node_get_string_at.snt_dip_node_copy_bool_array,snt_dip_node_copy_int64_array,snt_dip_node_copy_uint64_array,snt_dip_node_copy_double_array, andsnt_dip_node_copy_string_arraycopy whole arrays.snt_dip_node_get_provenance,snt_dip_node_get_metadata,snt_dip_node_has_metadata,snt_dip_node_get_metadata_list_size, andsnt_dip_node_get_metadata_list_item.snt_dip_node_has_units,snt_dip_node_get_units,snt_dip_node_is_overridden, andsnt_dip_node_free.
Options, persistence, export, and comparison
snt_dip_node_get_option_count,snt_dip_node_get_option_value,snt_dip_node_get_option_label, andsnt_dip_node_get_option_units.snt_dip_parser_is_overridden,snt_dip_environment_load, andsnt_dip_environment_save.snt_dip_environment_get_source_count,snt_dip_environment_get_source_path, andsnt_dip_environment_get_source_name.snt_dip_environment_generate,snt_dip_environment_generate_report, andsnt_dip_environment_generate_report_with_options.snt_dip_compare_files,snt_dip_comparison_summary,snt_dip_comparison_count,snt_dip_comparison_get,snt_dip_comparison_render_text, andsnt_dip_comparison_free.
Pass SNT_DIP_COMPARE_EFFECTIVE or SNT_DIP_COMPARE_FULL to comparisons.
Generated parameter lists use the SNT_DIP_EXPORT_* constants and reports
use the SNT_DIP_REPORT_* constants; snt_dip_difference.kind is one of
SNT_DIP_DIFFERENCE_ADDED, REMOVED, or CHANGED.