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
122
123
|
/* This file is part of GNU Dico.
Copyright (C) 2012-2019 Sergey Poznyakoff
GNU Dico is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Dico is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
#include "dico.h"
/* GCIDE-specific definitions. */
#define GCIDE_IDX_MAGIC "GCIDEIDX"
#define GCIDE_IDX_MAGIC_LEN (sizeof(GCIDE_IDX_MAGIC)-1)
#define GCIDE_IDX_HEADER_PAGESIZE 10240
struct gcide_idx_header {
char ihdr_magic[GCIDE_IDX_MAGIC_LEN];
unsigned long ihdr_pagesize;
unsigned long ihdr_maxpageref;
unsigned long ihdr_num_pages;
unsigned long ihdr_num_headwords;
unsigned long ihdr_num_defs;
};
struct gcide_ref {
unsigned long ref_hwoff;
unsigned long ref_hwlen;
unsigned long ref_hwbytelen;
int ref_letter;
unsigned long ref_offset;
unsigned long ref_size;
char *ref_headword;
};
struct gcide_page_header {
size_t phdr_numentries;
size_t phdr_text_offset;
};
struct gcide_idx_page {
union {
struct gcide_page_header hdr;
struct gcide_ref align;
} ipg_header;
struct gcide_ref ipg_ref[1];
};
typedef struct gcide_idx_file *gcide_idx_file_t;
typedef struct gcide_iterator *gcide_iterator_t;
gcide_idx_file_t gcide_idx_file_open(const char *name, size_t cachesize);
void gcide_idx_file_close(gcide_idx_file_t file);
size_t gcide_idx_headwords(struct gcide_idx_file *file);
size_t gcide_idx_defs(struct gcide_idx_file *file);
int gcide_idx_enumerate(struct gcide_idx_file *file,
int (*fun)(struct gcide_ref *, void *),
void *data);
gcide_iterator_t gcide_idx_locate(struct gcide_idx_file *file, char *headword,
size_t len);
void gcide_iterator_free(gcide_iterator_t itr);
int gcide_iterator_next(gcide_iterator_t itr);
int gcide_iterator_rewind(gcide_iterator_t itr);
struct gcide_ref *gcide_iterator_ref(gcide_iterator_t itr);
size_t gcide_iterator_count(gcide_iterator_t itr);
size_t gcide_iterator_compare_count(gcide_iterator_t itr);
void gcide_iterator_store_flags(gcide_iterator_t itr, int flags);
int gcide_iterator_flags(gcide_iterator_t itr);
extern char gcide_webchr[256][4];
char const *gcide_escape_to_utf8(const char *esc);
char const *gcide_entity_to_utf8(const char *str);
const char *gcide_grk_to_utf8(const char *input, size_t *prd);
enum gcide_content_type
{
gcide_content_unspecified,
gcide_content_text,
gcide_content_taglist
};
struct gcide_tag {
size_t tag_parmc;
char **tag_parmv;
#define tag_name tag_parmv[0]
enum gcide_content_type tag_type;
struct gcide_tag *tag_next;
union {
char *text;
size_t textpos;
dico_list_t taglist;
} tag_v;
};
#define TAG_HAS_NAME(t) ((t) && (t)->tag_parmv && (t)->tag_name)
struct gcide_parse_tree {
char *textspace;
size_t textsize;
struct gcide_tag *root;
};
struct gcide_parse_tree *gcide_markup_parse(char const *text, size_t len,
int dbg);
void gcide_parse_tree_free(struct gcide_parse_tree *tp);
int gcide_parse_tree_inorder(struct gcide_parse_tree *tp,
int (*fun)(int, struct gcide_tag *, void *),
void *data);
|