diff options
| author | Simon Tatham <anakin@pobox.com> | 1999-10-18 18:03:37 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 1999-10-18 18:03:37 +0000 |
| commit | e44f985bd4f796d4c4b11eb3555436dbaa2d163b (patch) | |
| tree | 8e037d5b32c5349760277e79ac53993b34035885 /misc.c | |
| parent | 00f6e0ee13c753d98e8665ad1ff2e992f43ef6e4 (diff) | |
| download | halibut-e44f985bd4f796d4c4b11eb3555436dbaa2d163b.zip halibut-e44f985bd4f796d4c4b11eb3555436dbaa2d163b.tar.gz halibut-e44f985bd4f796d4c4b11eb3555436dbaa2d163b.tar.bz2 halibut-e44f985bd4f796d4c4b11eb3555436dbaa2d163b.tar.xz | |
Further development; mid-end index handling pretty much there!
[originally from svn r238]
Diffstat (limited to '')
| -rw-r--r-- | misc.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -40,3 +40,47 @@ void *stk_pop(stack s) { else return NULL; } + +int compare_wordlists(word *a, word *b) { + int t; + while (a && b) { + if (a->type != b->type) + return (a->type < b->type ? -1 : +1); /* FIXME? */ + t = a->type; + if ((t != word_Normal && t != word_Code && + t != word_WeakCode && t != word_Emph) || + a->alt || b->alt) { + int c; + if (a->text && b->text) { + c = ustricmp(a->text, b->text); + if (c) + return c; + } + c = compare_wordlists(a->alt, b->alt); + if (c) + return c; + a = a->next; + b = b->next; + } else { + wchar_t *ap = a->text, *bp = b->text; + while (*ap && *bp) { + wchar_t ac = utolower(*ap), bc = utolower(*bp); + if (ac != bc) + return (ac < bc ? -1 : +1); + if (!*++ap && a->next && a->next->type == t && !a->next->alt) + a = a->next, ap = a->text; + if (!*++bp && b->next && b->next->type == t && !b->next->alt) + b = b->next, bp = b->text; + } + if (*ap || *bp) + return (*ap ? +1 : -1); + a = a->next; + b = b->next; + } + } + + if (a || b) + return (a ? +1 : -1); + else + return 0; +} |