ORT_DIFF(3) | Library Functions Manual | ORT_DIFF(3) |
ort_diff
— compute
ort configuration differences
library “libort”
#include
<sys/queue.h>
#include <stdio.h>
#include <ort.h>
struct diffq *
ort_diff
(const struct config
*from, const struct config *into);
Computes the differences from the old ort(5) configuration from and the new into. It does not return all differences yet: it's a work in progress.
The differences are returned as a queue of structures that indicate whether any configuration component has changed, has not changed, has been added, or has been removed.
The result should be freed by ort_diffq_free(3) after use.
Both from and into must be fully linked as driven by ort_parse_close(3).
The differences are typed according to enum difftype, which may be any of the following:
DIFF_ADD_BITF
DIFF_ADD_BITIDX
DIFF_ADD_EITEM
DIFF_ADD_ENM
DIFF_ADD_FIELD
DIFF_ADD_INSERT
DIFF_ADD_ROLE
DIFF_ADD_ROLES
DIFF_ADD_SEARCH
DIFF_ADD_STRCT
DIFF_ADD_UNIQUE
DIFF_ADD_UPDATE
DIFF_DEL_BITF
DIFF_DEL_BITIDX
DIFF_DEL_EITEM
DIFF_DEL_ENM
DIFF_DEL_FIELD
DIFF_DEL_INSERT
DIFF_DEL_ROLE
DIFF_DEL_ROLES
DIFF_DEL_SEARCH
DIFF_DEL_STRCT
DIFF_DEL_UNIQUE
DIFF_DEL_UPDATE
DIFF_MOD_BITF
DIFF_MOD_BITF_COMMENT
,
DIFF_MOD_BITF_LABELS
,
DIFF_ADD_BITIDX
,
DIFF_DEL_BITIDX
, or
DIFF_MOD_BITIDX
will also be set for the given
object.DIFF_MOD_BITF_COMMENT
DIFF_MOD_BITF_LABELS
DIFF_MOD_BITIDX
DIFF_MOD_BITIDX_COMMENT
,
DIFF_MOD_BITIDX_LABELS
, or
DIFF_MOD_BITIDX_VALUE
will also be set for the
given object.DIFF_MOD_BITIDX_COMMENT
DIFF_MOD_BITIDX_LABELS
DIFF_MOD_BITIDX_VALUE
DIFF_MOD_EITEM
DIFF_MOD_EITEM_COMMENT
,
DIFF_MOD_EITEM_LABELS
, or
DIFF_MOD_EITEM_VALUE
will also be set for the
given object.DIFF_MOD_EITEM_COMMENT
DIFF_MOD_EITEM_LABELS
DIFF_MOD_EITEM_VALUE
DIFF_MOD_ENM
DIFF_MOD_ENM_COMMENT
,
DIFF_MOD_ENM_LABELS
,
DIFF_ADD_EITEM
,
DIFF_DEL_EITEM
, or
DIFF_MOD_EITEM
will also be set for the given
object.DIFF_MOD_ENM_COMMENT
DIFF_MOD_ENM_LABELS
DIFF_MOD_FIELD
DIFF_MOD_FIELD_ACTIONS
,
DIFF_MOD_FIELD_BITF
,
DIFF_MOD_FIELD_COMMENT
,
DIFF_MOD_FIELD_DEF
,
DIFF_MOD_FIELD_ENM
,
DIFF_MOD_FIELD_FLAGS
,
DIFF_MOD_FIELD_REFERENCE
,
DIFF_MOD_FIELD_ROLEMAP
,
DIFF_MOD_FIELD_TYPE
, or
DIFF_MOD_FIELD_VALIDS
will also be set for the
given object.DIFF_MOD_FIELD_ACTIONS
DIFF_MOD_FIELD_BITF
DIFF_MOD_FIELD_COMMENT
DIFF_MOD_FIELD_DEF
DIFF_MOD_FIELD_ENM
DIFF_MOD_FIELD_FLAGS
DIFF_MOD_FIELD_REFERENCE
DIFF_MOD_FIELD_ROLEMAP
DIFF_MOD_FIELD_TYPE
DIFF_MOD_FIELD_VALIDS
DIFF_MOD_INSERT
DIFF_MOD_INSERT_PARAMS
or
DIFF_MOD_INSERT_ROLEMAP
will also be set for the
given object.DIFF_MOD_INSERT_PARAMS
DIFF_MOD_INSERT_ROLEMAP
DIFF_MOD_ROLE
DIFF_MOD_ROLE_CHILDREN
,
DIFF_MOD_ROLE_COMMENT
, or
DIFF_MOD_ROLE_PARENT
will also be set for the
given object.DIFF_MOD_ROLE_CHILDREN
DIFF_MOD_ROLE_COMMENT
DIFF_MOD_ROLE_PARENT
DIFF_MOD_ROLES
DIFF_ADD_ROLE
,
DIFF_DEL_ROLE
, or
DIFF_MOD_ROLE
will also be set for the given
object.DIFF_MOD_SEARCH
DIFF_MOD_SEARCH_AGGR
,
DIFF_MOD_SEARCH_COMMENT
,
DIFF_MOD_SEARCH_DISTINCT
,
DIFF_MOD_SEARCH_GROUP
,
DIFF_MOD_SEARCH_LIMIT
,
DIFF_MOD_SEARCH_OFFSET
,
DIFF_MOD_SEARCH_ORDER
,
DIFF_MOD_SEARCH_PARAMS
, or
DIFF_MOD_SEARCH_ROLEMAP
will also be set for the
given object.DIFF_MOD_SEARCH_AGGR
DIFF_MOD_SEARCH_COMMENT
DIFF_MOD_SEARCH_DISTINCT
DIFF_MOD_SEARCH_GROUP
DIFF_MOD_SEARCH_LIMIT
DIFF_MOD_SEARCH_OFFSET
DIFF_MOD_SEARCH_ORDER
DIFF_MOD_SEARCH_PARAMS
DIFF_MOD_SEARCH_ROLEMAP
DIFF_MOD_STRCT
DIFF_ADD_FIELD
,
DIFF_ADD_INSERT
,
DIFF_ADD_SEARCH
,
DIFF_ADD_UNIQUE
,
DIFF_ADD_UPDATE
,
DIFF_DEL_FIELD
,
DIFF_DEL_INSERT
,
DIFF_DEL_STRCT
,
DIFF_DEL_UNIQUE
,
DIFF_DEL_UPDATE
,
DIFF_MOD_FIELD
,
DIFF_MOD_INSERT
,
DIFF_MOD_SEARCH
,
DIFF_MOD_STRCT_COMMENT
, or
DIFF_MOD_UPDATE
will also be set for the given
object.DIFF_MOD_STRCT_COMMENT
DIFF_MOD_UPDATE
NULL
. This
stipulates that one or more of
DIFF_MOD_UPDATE_COMMENT
,
DIFF_MOD_UPDATE_FLAGS
,
DIFF_MOD_UPDATE_PARAMS
, or
DIFF_MOD_UPDATE_ROLEMAP
will also be set for the
given object.DIFF_MOD_UPDATE_COMMENT
DIFF_MOD_UPDATE_FLAGS
DIFF_MOD_UPDATE_PARAMS
DIFF_MOD_UPDATE_ROLEMAP
DIFF_SAME_BITF
DIFF_SAME_BITIDX
DIFF_SAME_EITEM
DIFF_SAME_ENM
DIFF_SAME_FIELD
DIFF_SAME_ROLES
DIFF_SAME_ROLE
DIFF_SAME_SEARCH
DIFF_SAME_STRCT
DIFF_SAME_UPDATE
The returned structure is a queue of struct diff, which consists of the following:
DIFF_ADD_BITF
and
DIFF_DEL_BITF
.DIFF_MOD_BITF
,
DIFF_MOD_BITF_COMMENT
,
DIFF_MOD_BITF_LABELS
, and
DIFF_SAME_BITF
.DIFF_ADD_BITIDX
and
DIFF_DEL_BITIDX
.DIFF_MOD_BITIDX
,
DIFF_MOD_BITIDX_COMMENT
,
DIFF_MOD_BITIDX_LABELS
,
DIFF_MOD_BITIDX_VALUE
, and
DIFF_SAME_BITIDX
.DIFF_ADD_ENM
and
DIFF_DEL_ENM
.DIFF_MOD_ENM
,
DIFF_MOD_ENM_COMMENT
,
DIFF_MOD_ENM_LABELS
, and
DIFF_SAME_ENM
.DIFF_ADD_EITEM
and
DIFF_DEL_EITEM
.DIFF_MOD_EITEM
,
DIFF_MOD_EITEM_COMMENT
,
DIFF_MOD_EITEM_LABELS
,
DIFF_MOD_EITEM_VALUE
, and
DIFF_SAME_EITEM
.DIFF_ADD_FIELD
and
DIFF_DEL_FIELD
.DIFF_MOD_FIELD
,
DIFF_MOD_FIELD_ACTIONS
,
DIFF_MOD_FIELD_BITF
,
DIFF_MOD_FIELD_COMMENT
,
DIFF_MOD_FIELD_DEF
,
DIFF_MOD_FIELD_ENM
,
DIFF_MOD_FIELD_FLAGS
,
DIFF_MOD_FIELD_REFERENCE
,
DIFF_MOD_FIELD_ROLEMAP
,
DIFF_MOD_FIELD_TYPE
,
DIFF_MOD_FIELD_VALIDS
, and
DIFF_SAME_FIELD
.DIFF_ADD_ROLE
and
DIFF_DEL_ROLE
. Also used by
DIFF_ADD_ROLES
and
DIFF_DEL_ROLES
, where
role is the first of the new or deleted
roles.DIFF_MOD_ROLES
and
DIFF_SAME_ROLES
, where
into and from are set to
the first of the modified or same roles. Also set by
DIFF_MOD_ROLE_CHILDREN
,
DIFF_MOD_ROLE_COMMENT
,
DIFF_MOD_ROLE_PARENT
, and
DIFF_SAME_ROLE
.DIFF_ADD_SEARCH
, and
DIFF_DEL_SEARCH
.DIFF_MOD_SEARCH
,
DIFF_MOD_SEARCH_AGGR
,
DIFF_MOD_SEARCH_COMMENT
,
DIFF_MOD_SEARCH_DISTINCT
,
DIFF_MOD_SEARCH_GROUP
,
DIFF_MOD_SEARCH_LIMIT
,
DIFF_MOD_SEARCH_OFFSET
,
DIFF_MOD_SEARCH_ORDER
,
DIFF_MOD_SEARCH_PARAMS
, and
DIFF_MOD_SEARCH_ROLEMAP
.DIFF_ADD_INSERT
,
DIFF_ADD_STRCT
,
DIFF_DEL_INSERT
. and
DIFF_DEL_STRCT
.DIFF_MOD_INSERT
,
DIFF_MOD_INSERT_PARAMS
,
DIFF_MOD_INSERT_ROLEMAP
,
DIFF_MOD_STRCT
,
DIFF_MOD_STRCT_COMMENT
,
DIFF_SAME_INSERT
, and
DIFF_SAME_FIELD
.DIFF_ADD_UNIQUE
and
DIFF_DEL_UNIQUE
.DIFF_ADD_UPDATE
and
DIFF_DEL_UPDATE
.DIFF_MOD_UPDATE
,
DIFF_MOD_UPDATE_COMMENT
,
DIFF_MOD_UPDATE_FLAGS
,
DIFF_MOD_UPDATE_PARAMS
,
DIFF_MOD_UPDATE_ROLEMAP
, and
DIFF_SAME_UPDATE
.A configuration that has not changed at all will consists solely
of DIFF_SAME_xxxx
entries.
Returns the queue of differences or NULL
on memory allocation failure.
The following passes the differences between two files,
old.ort and new.ort, to a
function differ
().
struct config *oldcfg, *newcfg; struct diffq *diff; FILE *old, *new; if ((old = fopen("old.ort", "r")) == NULL) err(1, "old.ort"); if ((new = fopen("new.ort", "r")) == NULL) err(1, "new.ort"); if ((oldcfg = ort_config_alloc()) == NULL) { err(1, NULL); if (!ort_parse_file(oldcfg, old, "old.ort")) errx(1, "old.ort: parse failure"); if (!ort_parse_close(oldcfg)) errx(1, "old.ort: parse failure"); fclose(old); if ((newcfg = ort_config_alloc()) == NULL) { err(1, NULL); if (!ort_parse_file(newcfg, new, "new.ort")) errx(1, "new.ort: parse failure"); if (!ort_parse_close(newcfg)) errx(1, "new.ort: parse failure"); fclose(new); if ((diff = ort_diff(old, new)) == NULL) errx(1, "old.ort -> new.ort"); differ(diff); ort_config_free(oldcfg); ort_config_free(newcfg); return 0;
October 25, 2021 | OpenBSD 6.7 |