summary refs log tree commit diff
path: root/doc.h
blob: a71ca4985bf553f601b48a72936784d26c4cf7f3 (plain)
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
#ifndef DOC_H
#define DOC_H

#include "buf.h"
#include "strv.h"

#define DOC_LINK_NONE 0xffff

struct doc_line {
	unsigned short prev, link, len;
	char txt[];
};

enum doc_type {
	DOC_UNKNOWN,
	DOC_GOPHERMAP,
	DOC_GEMTEXT,
	DOC_PLAIN,
};

struct doc {
	buf_t txt, lnk;
	size_t latest;
	unsigned short linkc;
};

void doc_init(struct doc *);
void doc_fini(struct doc *);

void doc_new_line(struct doc *);
void doc_add_line(struct doc *, strv_t);
void doc_add_text(struct doc *, const char *);
void doc_add_textn(struct doc *, const char *, size_t);

struct doc_line *doc_line_at(struct doc *d, size_t ofs);
int doc_line_prevp(struct doc *d, size_t ofs);
int doc_line_nextp(struct doc *d, size_t ofs);
int doc_line_prev(struct doc *d, size_t *ofs);
int doc_line_next(struct doc *d, size_t *ofs);

const char *doc_get_link(struct doc *d, unsigned short lnk);

void doc_set_link(struct doc *d, unsigned short lnk);
unsigned short doc_add_link(struct doc *d, const char *url);

#endif