aboutsummaryrefslogtreecommitdiffstats
path: root/libwc/search.c
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@vega.ocn.ne.jp>2011-05-04 07:05:14 +0000
committerTatsuya Kinoshita <tats@vega.ocn.ne.jp>2011-05-04 07:05:14 +0000
commit72f72d64a422d6628c4796f5c0bf2e508f134214 (patch)
tree0c9ea90cc53310832c977265521fb44db24a515e /libwc/search.c
parentAdding upstream version 0.3 (diff)
downloadw3m-1ef51c20e0ea7b35c8c9cad6f9d9bc1e16664cc5.tar.gz
w3m-1ef51c20e0ea7b35c8c9cad6f9d9bc1e16664cc5.zip
Adding upstream version 0.5.1upstream/0.5.1
Diffstat (limited to 'libwc/search.c')
-rw-r--r--libwc/search.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/libwc/search.c b/libwc/search.c
new file mode 100644
index 0000000..655d1e0
--- /dev/null
+++ b/libwc/search.c
@@ -0,0 +1,72 @@
+
+#include <stdlib.h>
+#include "wc.h"
+
+static int
+map_cmp(const void *a, const void *b)
+{
+ return *(wc_uint16 *)a - ((wc_map *)b)->code;
+}
+
+static int
+map3_cmp(const void *a, const void *b)
+{
+ return *(wc_uint32 *)a - (((wc_uint32)((wc_map3 *)b)->code << 16) | ((wc_map3 *)b)->code2);
+}
+
+static int
+map_range_cmp(const void *a, const void *b)
+{
+ return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1
+ : ((*(wc_uint16 *)a > ((wc_map *)b)->code2) ? 1 : 0);
+}
+
+static int
+map2_range_cmp(const void *a, const void *b)
+{
+ return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1
+ : ((*(wc_uint16 *)a >= ((wc_map *)b + 1)->code) ? 1 : 0);
+}
+
+static int
+map3_range_cmp(const void *a, const void *b)
+{
+ return (*(wc_uint16 *)a < ((wc_map3 *)b)->code) ? -1
+ : ((*(wc_uint16 *)a > ((wc_map3 *)b)->code2) ? 1 : 0);
+}
+
+wc_map *
+wc_map_search(wc_uint16 code, wc_map *map, size_t n)
+{
+ return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
+ map_cmp);
+}
+
+wc_map3 *
+wc_map3_search(wc_uint16 c1, wc_uint16 c2, wc_map3 *map, size_t n)
+{
+ wc_uint32 code = ((wc_uint32)c1 << 16) | c2;
+ return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3),
+ map3_cmp);
+}
+
+wc_map *
+wc_map_range_search(wc_uint16 code, wc_map *map, int n)
+{
+ return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
+ map_range_cmp);
+}
+
+wc_map *
+wc_map2_range_search(wc_uint16 code, wc_map *map, size_t n)
+{
+ return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
+ map2_range_cmp);
+}
+
+wc_map3 *
+wc_map3_range_search(wc_uint16 code, wc_map3 *map, size_t n)
+{
+ return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3),
+ map3_range_cmp);
+}