This is an example on how to use the storage library in an application. It shows how to create four revisions of a file:
- an empty one,
- one containing a line,
- one containing the line, a box, and a circle,
- and one where the line is replaced by a net, and the box is deleted.
- See also
- Storage library
-
xornstorage.h
#include <stdio.h>
#include <string.h>
int main(void)
{
if (rev0 == NULL)
goto error0;
if (rev1 == NULL)
goto error1;
memset(&line_data, 0, sizeof line_data);
line_data.pos.x = 0;
line_data.pos.y = 1;
line_data.size.x = 3;
line_data.size.y = 2;
line_data.color = 3;
line_data.line.width = 1;
line = xornsch_add_line(rev1, &line_data);
if (line == NULL)
goto error2;
if (rev2 == NULL)
goto error2;
memset(&box_data, 0, sizeof box_data);
box_data.pos.x = 1;
box_data.pos.y = 1;
box_data.size.x = 2;
box_data.size.y = 2;
box_data.color = 3;
box_data.line.width = 1;
box = xornsch_add_box(rev2, &box_data);
if (box == NULL)
goto error3;
memset(&circle_data, 0, sizeof circle_data);
circle_data.pos.x = -1;
circle_data.pos.y = -1;
circle_data.radius = 2;
circle_data.color = 3;
circle_data.line.width = 1;
circle_data.fill.type = 1;
circle = xornsch_add_circle(rev2, &circle_data);
if (circle == NULL)
goto error3;
if (rev3 == NULL)
goto error3;
memset(&net_data, 0, sizeof net_data);
net_data.pos.x = 0;
net_data.pos.y = 1;
net_data.size.x = 3;
net_data.size.y = 2;
net_data.color = 4;
if (xornsch_set_net_data(rev3, line, &net_data) == -1)
goto error4;
return 0;
error4:
error3:
error2:
error1:
error0:
fprintf(stderr, "Out of memory\n");
return 1;
}
Copyright (C) 2013-2016 Roland Lutz
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts.