1 /* This file is part of GNU Dico.
2    Copyright (C) 1998-2020 Sergey Poznyakoff
3 
4    GNU Dico is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8 
9    GNU Dico is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with GNU Dico.  If not, see <http://www.gnu.org/licenses/>. */
16 
17 #ifndef __dico_types_h
18 #define __dico_types_h
19 
20 #include <sys/types.h>
21 
22 #ifndef offsetof
23 # define offsetof(s,f) ((size_t)&((s*)0)->f)
24 #endif
25 #define DICO_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
26 
27 #ifndef DICO_ARG_UNUSED
28 # define DICO_ARG_UNUSED __attribute__ ((__unused__))
29 #endif
30 
31 #ifndef DICO_PRINTFLIKE
32 # define DICO_PRINTFLIKE(fmt,narg) __attribute__ ((__format__ (__printf__, fmt, narg)))
33 #endif
34 
35 #define DICO_DICT_PORT 2628
36 #define DICO_DICT_PORT_STR "2628"
37 
38 /* Maximum size of I/O buffer as per RFC2229 */
39 #define DICO_MAX_BUFFER 6144
40 
41 #define __dico_s_cat3__(a,b,c) a ## b ## c
42 #define DICO_EXPORT(module,name) __dico_s_cat3__(module,_LTX_,name)
43 
44 typedef struct dico_line_buffer *dico_linebuf_t;
45 typedef struct dico_stream *dico_stream_t;
46 typedef struct dico_list *dico_list_t;
47 typedef struct dico_assoc_list *dico_assoc_list_t;
48 typedef struct iterator *dico_iterator_t;
49 
50 typedef struct dico_handle_struct *dico_handle_t;
51 typedef struct dico_result_struct *dico_result_t;
52 
53 typedef struct dico_strategy *dico_strategy_t;
54 typedef struct dico_key *dico_key_t;
55 
56 typedef struct dicod_database dicod_database_t;
57 
58 #define DICO_SELECT_BEGIN 0
59 #define DICO_SELECT_RUN   1
60 #define DICO_SELECT_END   2
61 typedef int (*dico_select_t) (int, dico_key_t, const char *);
62 
63 #define DICO_MODULE_VERSION 3
64 
65 #define DICO_CAPA_NONE       0
66 #define DICO_CAPA_NODB       0x0001
67 #define DICO_CAPA_INIT_EXT   0x0002
68 #define DICO_CAPA_DEFAULT DICO_CAPA_NONE
69 
70 #define DICO_DBF_DEFAULT 0
71 #define DICO_DBF_VIRTUAL 0x01
72 #define DICO_DBF_MASK    0xffff
73 
74 struct dico_database_module {
75     unsigned dico_version;
76     unsigned dico_capabilities;
77     int (*dico_init) (int argc, char **argv);
78     dico_handle_t (*dico_init_db) (const char *db, int argc, char **argv);
79     int (*dico_free_db) (dico_handle_t hp);
80     int (*dico_open) (dico_handle_t hp);
81     int (*dico_close) (dico_handle_t hp);
82     char *(*dico_db_info) (dico_handle_t hp);
83     char *(*dico_db_descr) (dico_handle_t hp);
84     int (*dico_db_lang) (dico_handle_t hp, dico_list_t list[2]);
85     dico_result_t (*dico_match) (dico_handle_t hp,
86 				 const dico_strategy_t strat,
87 				 const char *word);
88     dico_result_t (*dico_define) (dico_handle_t hp, const char *word);
89     int (*dico_output_result) (dico_result_t rp, size_t n,
90 			       dico_stream_t str);
91     size_t (*dico_result_count) (dico_result_t rp);
92     size_t (*dico_compare_count) (dico_result_t rp);
93     void (*dico_free_result) (dico_result_t rp);
94     int (*dico_result_headers) (dico_result_t rp, dico_assoc_list_t hdr);
95     int (*dico_run_test) (int argc, char **argv);
96     char *(*dico_db_mime_header) (dico_handle_t hp);
97     dico_handle_t (*dico_init_db_ext) (const char *db, int argc, char **argv,
98 				       void *extra);
99     int (*dico_db_flags) (dico_handle_t hp);
100     dicod_database_t *(*dico_result_db)(dico_result_t rp, size_t n);
101 };
102 
103 #endif
104