-
Notifications
You must be signed in to change notification settings - Fork 0
/
ud_init.c
51 lines (43 loc) · 1.3 KB
/
ud_init.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
#include <chrono/taia.h>
#include <corelib/alloc.h>
#include <corelib/bin.h>
#include <corelib/open.h>
#include <corelib/hashtable.h>
#define UDOC_IMPLEMENTATION
#include "ud_part.h"
#include "ud_oht.h"
#include "ud_ref.h"
#include "udoc.h"
int
ud_init (struct udoc *ud)
{
bin_zero (ud, sizeof (*ud));
if (!ud_oht_init (&ud->ud_parts, sizeof (struct ud_part))) goto FAIL;
if (!ud_oht_init (&ud->ud_link_exts, sizeof (struct ud_ref))) goto FAIL;
if (!ud_oht_init (&ud->ud_refs, sizeof (struct ud_ref))) goto FAIL;
if (!ud_oht_init (&ud->ud_ref_names, sizeof (struct ud_ref))) goto FAIL;
if (!ud_oht_init (&ud->ud_footnotes, sizeof (struct ud_ref))) goto FAIL;
if (!ud_oht_init (&ud->ud_styles, sizeof (struct ud_ref))) goto FAIL;
if (!dstack_init (&ud->ud_errors, 16, sizeof (struct ud_err))) goto FAIL;
if (!token_init (&ud->ud_tok)) goto FAIL;
ud->ud_dirfd_pwd = open_ro (".");
if (ud->ud_dirfd_pwd == -1) goto FAIL;
ud->ud_dirfd_src = -1;
ud->ud_dirfd_out = -1;
ud->ud_main_doc = ud;
ud->ud_cur_doc = ud;
if (!ht_init (&ud->ud_loopchecks)) goto FAIL;
if (!ht_init (&ud->ud_documents)) goto FAIL;
taia_now (&ud->ud_time_start);
return 1;
FAIL:
ud_free (ud);
return 0;
}
int
ud_new (struct udoc **udp)
{
struct udoc *ud;
ud = alloc_zero (sizeof (*ud));
return !! (*udp = ud);
}