-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.c
66 lines (52 loc) · 1.11 KB
/
view.c
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
/* Copyright (c) 2016 Richard Russon <rich@flatcap.org>
* Released under the GPLv3 -- see LICENSE.md for details */
#include <stdio.h>
#include <stdlib.h>
#include "source.h"
#include "view.h"
static void
view_destroy (VIEW *v)
{
if (!v) {
return;
}
OBJECT *o = &v->container.object;
o->refcount--;
if (o->refcount < 1) {
int i;
for (i = 0; i < v->container.num_children; i++) {
release (v->container.children[i]);
}
free (o->name);
free (v);
}
}
void
view_display (VIEW *v, int indent)
{
if (!v) {
return;
}
printf ("%*s\033[1;31m%s\033[m\n", indent * 8, "", v->container.object.name);
if (v->container.num_children == 0) {
printf ("%*s\033[1;33m[empty]\033[m\n", (indent + 1) * 8, "");
} else {
container_display (&v->container, indent + 1);
}
}
VIEW *
view_create (VIEW *v)
{
if (!v) {
v = calloc (1, sizeof (VIEW));
if (!v) {
return NULL;
}
}
container_create (&v->container); // Construct parent
OBJECT *o = &v->container.object;
o->type = MAGIC_VIEW;
o->destroy = (object_destroy_fn) view_destroy;
o->display = (object_display_fn) view_display;
return v;
}