|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.1 2007/08/21 01:11:18 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.2 2007/08/22 04:13:15 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
14 | 14 | #include "postgres.h"
|
15 | 15 |
|
| 16 | +#include "commands/defrem.h" |
16 | 17 | #include "storage/fd.h"
|
17 | 18 | #include "tsearch/ts_locale.h"
|
18 | 19 | #include "tsearch/ts_public.h"
|
|
21 | 22 |
|
22 | 23 |
|
23 | 24 | #define SYNBUFLEN 4096
|
| 25 | + |
24 | 26 | typedef struct
|
25 | 27 | {
|
26 | 28 | char *in;
|
@@ -63,27 +65,37 @@ compareSyn(const void *a, const void *b)
|
63 | 65 | Datum
|
64 | 66 | dsynonym_init(PG_FUNCTION_ARGS)
|
65 | 67 | {
|
66 |
| - text *in; |
| 68 | + List *dictoptions = (List *) PG_GETARG_POINTER(0); |
67 | 69 | DictSyn *d;
|
68 |
| - int cur = 0; |
| 70 | + ListCell *l; |
| 71 | + char *filename = NULL; |
69 | 72 | FILE *fin;
|
70 |
| - char *filename; |
71 | 73 | char buf[SYNBUFLEN];
|
72 | 74 | char *starti,
|
73 | 75 | *starto,
|
74 | 76 | *end = NULL;
|
| 77 | + int cur = 0; |
75 | 78 | int slen;
|
76 | 79 |
|
77 |
| - /* init functions must defend against NULLs for themselves */ |
78 |
| - if (PG_ARGISNULL(0) || PG_GETARG_POINTER(0) == NULL) |
| 80 | + foreach(l, dictoptions) |
| 81 | + { |
| 82 | + DefElem *defel = (DefElem *) lfirst(l); |
| 83 | + |
| 84 | + if (pg_strcasecmp("Synonyms", defel->defname) == 0) |
| 85 | + filename = defGetString(defel); |
| 86 | + else |
| 87 | + ereport(ERROR, |
| 88 | + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 89 | + errmsg("unrecognized synonym parameter: \"%s\"", |
| 90 | + defel->defname))); |
| 91 | + } |
| 92 | + |
| 93 | + if (!filename) |
79 | 94 | ereport(ERROR,
|
80 | 95 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
81 |
| - errmsg("NULL config not allowed for Synonym"))); |
82 |
| - in = PG_GETARG_TEXT_P(0); |
83 |
| - |
84 |
| - filename = get_tsearch_config_filename(TextPGetCString(in), "syn"); |
| 96 | + errmsg("missing Synonyms parameter"))); |
85 | 97 |
|
86 |
| - PG_FREE_IF_COPY(in, 0); |
| 98 | + filename = get_tsearch_config_filename(filename, "syn"); |
87 | 99 |
|
88 | 100 | if ((fin = AllocateFile(filename, "r")) == NULL)
|
89 | 101 | ereport(ERROR,
|
@@ -142,7 +154,6 @@ dsynonym_init(PG_FUNCTION_ARGS)
|
142 | 154 | if (cur > 1)
|
143 | 155 | qsort(d->syn, d->len, sizeof(Syn), compareSyn);
|
144 | 156 |
|
145 |
| - pfree(filename); |
146 | 157 | PG_RETURN_POINTER(d);
|
147 | 158 | }
|
148 | 159 |
|
|
0 commit comments