aboutsummaryrefslogtreecommitdiff
path: root/src/dictionary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dictionary.c')
-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
@@ -39,26 +39,25 @@ static struct dictionary_descr dictionary_tab[] = {
39 { "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result, 39 { "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result,
40 sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote }, 40 sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote },
41 { "builtin", builtin_init, builtin_done, builtin_free_result, 41 { "builtin", builtin_init, builtin_done, builtin_free_result,
42 builtin_open, NULL, 42 builtin_open, NULL,
43 builtin_get, 43 builtin_get,
44 builtin_lookup }, 44 builtin_lookup },
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
59dictionary_init (struct dictionary *dict) 58dictionary_init (struct dictionary *dict)
60{ 59{
61 struct dictionary_descr *mp = dictionary_tab + dict->type; 60 struct dictionary_descr *mp = dictionary_tab + dict->type;
62 int rc = 0; 61 int rc = 0;
63 62
64 if (dict->init_passed++) 63 if (dict->init_passed++)
@@ -83,24 +82,26 @@ dictionary_open (struct dictionary *dict)
83{ 82{
84 struct dictionary_descr *mp = dictionary_tab + dict->type; 83 struct dictionary_descr *mp = dictionary_tab + dict->type;
85 84
86 if (!mp->open) 85 if (!mp->open)
87 return NULL; 86 return NULL;
88 return mp->open (dict); 87 return mp->open (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
101dictionary_done (struct dictionary *dict) 102dictionary_done (struct dictionary *dict)
102{ 103{
103 struct dictionary_descr *mp = dictionary_tab + dict->type; 104 struct dictionary_descr *mp = dictionary_tab + dict->type;
104 int rc = 0; 105 int rc = 0;
105 106
106 if (dict->init_passed == 0) 107 if (dict->init_passed == 0)
@@ -177,52 +178,52 @@ dictionary_result (struct dictionary *dict, void *handle,
177 if (nrow >= dict->nrow || ncol >= dict->ncol 178 if (nrow >= dict->nrow || ncol >= dict->ncol
178 || mp->get (dict, handle, nrow, ncol)) 179 || mp->get (dict, handle, nrow, ncol))
179 return NULL; 180 return NULL;
180 return dict->result; 181 return dict->result;
181} 182}
182 183
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
196 quoted string. Return its length. */ 197 quoted string. Return its length. */
197int 198int
198dictionary_quote_string (struct dictionary *dict, void *handle, 199dictionary_quote_string (struct dictionary *dict, void *handle,
199 const char *input, 200 const char *input,
200 char **poutput, size_t *psize) 201 char **poutput, size_t *psize)
201{ 202{
202 struct dictionary_descr *mp = dictionary_tab + dict->type; 203 struct dictionary_descr *mp = dictionary_tab + dict->type;
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;
226 return 0; 227 return 0;
227} 228}
228 229

Return to:

Send suggestions and report system problems to the System administrator.