w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

search.c (1691B)


      1 
      2 #include <stdlib.h>
      3 #include "wc.h"
      4 
      5 static int
      6 map_cmp(const void *a, const void *b)
      7 {
      8     return *(wc_uint16 *)a - ((wc_map *)b)->code;
      9 }
     10 
     11 static int
     12 map3_cmp(const void *a, const void *b)
     13 {
     14     return *(wc_uint32 *)a - (((wc_uint32)((wc_map3 *)b)->code << 16) | ((wc_map3 *)b)->code2);
     15 }
     16 
     17 static int
     18 map_range_cmp(const void *a, const void *b)
     19 {
     20     return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1
     21 	: ((*(wc_uint16 *)a > ((wc_map *)b)->code2) ? 1 : 0);
     22 }
     23 
     24 static int
     25 map2_range_cmp(const void *a, const void *b)
     26 {
     27     return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1
     28 	: ((*(wc_uint16 *)a >= ((wc_map *)b + 1)->code) ? 1 : 0);
     29 }
     30 
     31 static int
     32 map3_range_cmp(const void *a, const void *b)
     33 {
     34     return (*(wc_uint16 *)a < ((wc_map3 *)b)->code) ? -1
     35 	: ((*(wc_uint16 *)a > ((wc_map3 *)b)->code2) ? 1 : 0);
     36 }
     37 
     38 wc_map *
     39 wc_map_search(wc_uint16 code, wc_map *map, size_t n)
     40 {
     41     return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
     42 	map_cmp);
     43 }
     44 
     45 wc_map3 *
     46 wc_map3_search(wc_uint16 c1, wc_uint16 c2, wc_map3 *map, size_t n)
     47 {
     48     wc_uint32 code = ((wc_uint32)c1 << 16) | c2;
     49     return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3),
     50 	map3_cmp);
     51 }
     52 
     53 wc_map *
     54 wc_map_range_search(wc_uint16 code, wc_map *map, int n)
     55 {
     56     return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
     57 	map_range_cmp);
     58 }
     59 
     60 wc_map *
     61 wc_map2_range_search(wc_uint16 code, wc_map *map, size_t n)
     62 {
     63     return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map),
     64 	map2_range_cmp);
     65 }
     66 
     67 wc_map3 *
     68 wc_map3_range_search(wc_uint16 code, wc_map3 *map, size_t n)
     69 {
     70     return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3),
     71 	map3_range_cmp);
     72 }