aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-09-15 11:08:13 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-09-15 11:08:13 +0300
commit1cf9d2d93642283bf7a338d2541eb5a5b396dd0c (patch)
tree1e2ff3bbab267ac7b9f7d72e960ce4ae3eb64bbc
parent99c0c1288e1c1c6a31cff7901ce93db012e9955f (diff)
downloaddico-1cf9d2d93642283bf7a338d2541eb5a5b396dd0c.tar.gz
dico-1cf9d2d93642283bf7a338d2541eb5a5b396dd0c.tar.bz2
dictorg: Fix unique headword selection
* modules/dict.org/dictorg.c (uniq_comp): New function. (common_match,suffix_match): Use uniq_comp to select headwords. (exact_match): Disable unique selector.
-rw-r--r--modules/dict.org/dictorg.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/modules/dict.org/dictorg.c b/modules/dict.org/dictorg.c
index 6e7b2dd..a6ebdf7 100644
--- a/modules/dict.org/dictorg.c
+++ b/modules/dict.org/dictorg.c
@@ -641,15 +641,38 @@ comparator(struct dictdb *db)
}
}
-//FIXME
static int
compare_entry_ptr(const void *a, const void *b)
{
const struct index_entry *epa = *(const struct index_entry **)a;
const struct index_entry *epb = *(const struct index_entry **)b;
+ /* FIXME: This should use comparator(db) instead. But that would
+ need using qsort_r */
return compare_alnumspace_ci(epa, epb);
}
+/* FIXME: This should use comparator(db) instead of utf8_strcasecmp.
+ Will need a customized bsearch version for that. */
+static int
+uniq_comp(const void *a, void *b)
+{
+ const struct index_entry *epa = a;
+ const struct index_entry *epb = b;
+
+ /* Entries differ if their headwords differ */
+ if (utf8_strcasecmp(epa->word, epb->word))
+ return 1;
+ /* Otherwise, if neither entry has the original headword, they
+ are equal */
+ if (!epa->orig && !epb->orig)
+ return 0;
+ /* If only one original headword is present, entries differ */
+ if (!epa->orig || !epb->orig)
+ return 1;
+ /* We have both original headwords. Compare them to decide. */
+ return utf8_strcasecmp(epa->orig, epb->orig);
+}
+
static int
common_match(struct dictdb *db, const char *word,
COMPARATOR compare,
@@ -679,9 +702,7 @@ common_match(struct dictdb *db, const char *word,
}
res->itr = NULL;
if (unique) {
- dico_list_set_comparator(res->list,
- (int (*)(const void *, void *))
- comparator(db));
+ dico_list_set_comparator(res->list, uniq_comp);
dico_list_set_flags(res->list, DICO_LIST_COMPARE_TAIL);
}
for (p++; p < ep; p++)
@@ -697,7 +718,7 @@ common_match(struct dictdb *db, const char *word,
static int
exact_match(struct dictdb *db, const char *word, struct result *res)
{
- return common_match(db, word, comparator(db), 1, res);
+ return common_match(db, word, comparator(db), 0, res);
}
static int
@@ -794,9 +815,7 @@ suffix_match(struct dictdb *db, const char *word, struct result *res)
free(tmp);
return 1;
}
- dico_list_set_comparator(list,
- (int (*)(const void *, void *))
- comparator(db));
+ dico_list_set_comparator(list, uniq_comp);
dico_list_set_flags(list, DICO_LIST_COMPARE_TAIL);
for (i = 0; i < count; i++)
dico_list_append(list, tmp[i]);
@@ -927,9 +946,7 @@ _match_all(struct dictdb *db, dico_strategy_t strat, const char *word)
return NULL;
}
- dico_list_set_comparator(list,
- (int (*)(const void *, void *))
- comparator(db));
+ dico_list_set_comparator(list, uniq_comp);
dico_list_set_flags(list, DICO_LIST_COMPARE_TAIL);
if (dico_key_init(&key, strat, word)) {

Return to:

Send suggestions and report system problems to the System administrator.