File: gcide.h

package info (click to toggle)
dico 2.12-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,300 kB
  • sloc: ansic: 94,671; sh: 52,520; lex: 4,023; tcl: 1,439; yacc: 1,439; makefile: 1,387; python: 1,310; perl: 1,200; lisp: 489; awk: 157; pascal: 127; javascript: 71; cpp: 50; fortran: 28; asm: 21; sed: 16; xml: 8
file content (170 lines) | stat: -rw-r--r-- 4,861 bytes parent folder | download | duplicates (2)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of GNU Dico.
   Copyright (C) 2012-2024 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_VERSION 1
#define GCIDE_IDX_HEADER_PAGESIZE 10240
#define GCIDE_IDX_FILE_NAME "GCIDE.IDX"

struct gcide_idx_header {
    char ihdr_magic[GCIDE_IDX_MAGIC_LEN];
    int  ihdr_version;
    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;
    char ref_primary;
};

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;

struct gcide_locus {
    char const *file;
    size_t offset;
};

enum {
    IDXE_OK,
    IDXE_BADFILE,
    IDXE_BADVER,
    IDXE_CORRUPT,
    IDXE_SYSERR
};

int gcide_idx_file_open(const char *name, size_t cachesize, int rw,
			struct gcide_idx_file **ret_file);
void gcide_idx_file_close(gcide_idx_file_t file);

int gcide_idx_lock(struct gcide_idx_file *file, int ex);
int gcide_idx_unlock(struct gcide_idx_file *file);
int gcide_idx_reopen(struct gcide_idx_file *file);
int gcide_idx_fileno(struct gcide_idx_file *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_top,  /* Top-level element: same as gcide_content_tag, but
			   with tag_parmc == 0 and tag_parmv == NULL. */
    gcide_content_tag,  /* Regular tag. */
    gcide_content_text, /* Text segment. */
    gcide_content_nl,   /* "Soft" newline. */
    gcide_content_br    /* Line break. */
};

struct gcide_tag {
    size_t offset;
    enum gcide_content_type tag_type;
    struct gcide_tag *tag_next;
#   define tag_name v.tag.tag_parmv[0]
    int delete;
    union {
	char *text;
	size_t textpos;
	struct {
	    size_t tag_parmc;
	    char **tag_parmv;
	    dico_list_t taglist;
	} tag;
    } v;
};

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, struct gcide_locus *loc);
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);

int gcide_is_block_tag(struct gcide_tag *tag);

struct gcide_tag *gcide_tag_alloc(const char *text, size_t len);
void gcide_tag_free(struct gcide_tag *tag);
int gcide_is_tag(struct gcide_tag *tag, char const *name);

typedef struct pollfd *WATCHER;

#if WITH_INOTIFY
WATCHER watcher_setup(char const *dbdir);
void watcher_close(WATCHER w);
int watcher_is_modified(WATCHER w);
#else
# define watcher_setup(dbdir) NULL
# define watcher_close(w)
# define watcher_is_modified(w) 1
#endif

#ifndef SIZE_MAX
# define SIZE_MAX ((size_t)-1)
#endif