File: lowdown_diff.3

package info (click to toggle)
lowdown 2.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,484 kB
  • sloc: ansic: 21,512; sh: 1,892; xml: 861; makefile: 518
file content (121 lines) | stat: -rw-r--r-- 3,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.\" Copyright (c) Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate$
.Dt LOWDOWN_DIFF 3
.Os
.Sh NAME
.Nm lowdown_diff
.Nd compute difference between parsed Markdown trees
.Sh LIBRARY
.Lb liblowdown
.Sh SYNOPSIS
.In sys/queue.h
.In stdio.h
.In lowdown.h
.Ft "struct lowdown_node *"
.Fo lowdown_diff
.Fa "const struct lowdown_node *nold"
.Fa "const struct lowdown_node *nnew"
.Fa "size_t *maxn"
.Fc
.Sh DESCRIPTION
Computes the difference between two Markdown trees, the source
.Fa nold
and destination
.Fa nnew ,
parsed by
.Xr lowdown_doc_parse 3 .
It uses the
.Vt enum lowdown_chng
type in the return tree's nodes to dictate insertions into and deletions
from
.Fa nold .
The
.Fa maxn
argument, if not
.Dv NULL ,
is set to one greater than the highest node identifier of the returned
tree.
.Sh RETURN VALUES
Returns a pointer to the difference tree or
.Dv NULL
on memory exhaustion.
The pointer must be freed with
.Xr lowdown_node_free 3 .
.Sh EXAMPLES
The following parses and compares
.Va old
of length
.Va osz
and
.Va new
of length
.Va nsz .
It first allocates the parser, then the document, then the renderer
(HTML is used in this case).
Then it passes output to the renderer, prints it, and cleans up
resources.
On any memory errors, it exits with
.Xr err 3 .
.Bd -literal -offset indent
struct lowdown_doc *doc;
struct lowdown_node *no, *nn, *diff;
struct lowdown_buf *ob;
void *rndr;

if ((doc = lowdown_doc_new(NULL)) == NULL)
	err(1, NULL);
if ((no = lowdown_doc_parse(doc, NULL, old, osz, NULL)) == NULL)
	err(1, NULL);
if ((nn = lowdown_doc_parse(doc, NULL, new, nsz, NULL)) == NULL)
	err(1, NULL);
if ((diff = lowdown_diff(no, nn, NULL)) == NULL)
	err(1, NULL);
if ((rndr = lowdown_html_new(NULL)) == NULL)
	err(1, NULL);
if ((ob = lowdown_buf_new(1024)) == NULL)
	err(1, NULL);
if (!lowdown_html_rndr(ob, rndr, diff))
	err(1, NULL);

fwrite(stdout, 1, ob->size, ob->data);

lowdown_buf_free(ob);
lowdown_html_rndr_free(rndr);
lowdown_node_free(no);
lowdown_node_free(nn);
lowdown_node_free(diff);
lowdown_doc_free(doc);
.Ed
.Sh SEE ALSO
.Xr lowdown 3
.Rs
.%A Gregory Cobena
.%A Serge Abiteboul
.%A Amelie Marian
.%D 2002
.%T "Detecting Changes in XML Documents"
.%U https://www.cs.rutgers.edu/~amelie/papers/2002/diff.pdf
.Re
.Rs
.%A Wu Sun
.%A Manber Udi
.%A Myers Gene
.%T "An O(NP) sequence comparison algorithm"
.%J Information Processing Letters
.%V Volume 35
.%I Issue 6
.%D 1990
.Re