summaryrefslogtreecommitdiffabout
path: root/src/dictionary.c
Unidiff
Diffstat (limited to 'src/dictionary.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/dictionary.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -45,14 +45,13 @@ static struct dictionary_descr dictionary_tab[] = {
45 { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL } 45 { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL }
46}; 46};
47 47
48struct dictionary * 48struct dictionary *
49dictionary_new (enum dictionary_id id, enum dictionary_type type) 49dictionary_new (enum dictionary_id id, enum dictionary_type type)
50{ 50{
51 struct dictionary *mp = xmalloc (sizeof mp[0]); 51 struct dictionary *mp = grecs_zalloc (sizeof mp[0]);
52 memset (mp, 0, sizeof mp[0]);
53 mp->id = id; 52 mp->id = id;
54 mp->type = type; 53 mp->type = type;
55 return mp; 54 return mp;
56} 55}
57 56
58int 57int
@@ -89,12 +88,14 @@ dictionary_open (struct dictionary *dict)
89} 88}
90 89
91int 90int
92dictionary_close (struct dictionary *dict, void *handle) 91dictionary_close (struct dictionary *dict, void *handle)
93{ 92{
94 struct dictionary_descr *mp = dictionary_tab + dict->type; 93 struct dictionary_descr *mp = dictionary_tab + dict->type;
94 if (mp->free)
95 mp->free (dict, handle);
95 if (!mp->close) 96 if (!mp->close)
96 return 0; 97 return 0;
97 return mp->close (dict, handle); 98 return mp->close (dict, handle);
98} 99}
99 100
100int 101int
@@ -183,13 +184,13 @@ dictionary_result (struct dictionary *dict, void *handle,
183void 184void
184dictionary_copy_result (struct dictionary *dict, const char *res, size_t size) 185dictionary_copy_result (struct dictionary *dict, const char *res, size_t size)
185{ 186{
186 if (dict->result_size < size + 1) 187 if (dict->result_size < size + 1)
187 { 188 {
188 dict->result_size = size + 1; 189 dict->result_size = size + 1;
189 dict->result = x2realloc (dict->result, &dict->result_size); 190 dict->result = grecs_realloc (dict->result, dict->result_size);
190 } 191 }
191 memcpy (dict->result, res, size); 192 memcpy (dict->result, res, size);
192 dict->result[size] = 0; 193 dict->result[size] = 0;
193} 194}
194 195
195/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed 196/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed
@@ -203,23 +204,23 @@ dictionary_quote_string (struct dictionary *dict, void *handle,
203 size_t size; 204 size_t size;
204 int quote; 205 int quote;
205 char *output; 206 char *output;
206 207
207 if (!input) 208 if (!input)
208 { 209 {
209 *poutput = xmalloc (1); 210 *poutput = grecs_malloc (1);
210 (*poutput)[0] = 0; 211 (*poutput)[0] = 0;
211 *psize = 1; 212 *psize = 1;
212 return 0; 213 return 0;
213 } 214 }
214 215
215 if (mp->quote) 216 if (mp->quote)
216 return mp->quote (dict, handle, input, poutput, psize); 217 return mp->quote (dict, handle, input, poutput, psize);
217 218
218 size = wordsplit_c_quoted_length (input, 0, &quote); 219 size = wordsplit_c_quoted_length (input, 0, &quote);
219 output = xmalloc (size + 1); 220 output = grecs_malloc (size + 1);
220 wordsplit_c_quote_copy (output, input, 0); 221 wordsplit_c_quote_copy (output, input, 0);
221 output[size] = 0; 222 output[size] = 0;
222 223
223 *poutput = output; 224 *poutput = output;
224 if (psize) 225 if (psize)
225 *psize = size; 226 *psize = size;

Return to:

Send suggestions and report system problems to the System administrator.