1*163bd69bSGarrett D'Amore /* 2*163bd69bSGarrett D'Amore * Copyright (c) 2004 Tim J. Robbins. 3*163bd69bSGarrett D'Amore * All rights reserved. 4*163bd69bSGarrett D'Amore * 5*163bd69bSGarrett D'Amore * Redistribution and use in source and binary forms, with or without 6*163bd69bSGarrett D'Amore * modification, are permitted provided that the following conditions 7*163bd69bSGarrett D'Amore * are met: 8*163bd69bSGarrett D'Amore * 1. Redistributions of source code must retain the above copyright 9*163bd69bSGarrett D'Amore * notice, this list of conditions and the following disclaimer. 10*163bd69bSGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright 11*163bd69bSGarrett D'Amore * notice, this list of conditions and the following disclaimer in the 12*163bd69bSGarrett D'Amore * documentation and/or other materials provided with the distribution. 13*163bd69bSGarrett D'Amore * 14*163bd69bSGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*163bd69bSGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*163bd69bSGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*163bd69bSGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*163bd69bSGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*163bd69bSGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*163bd69bSGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*163bd69bSGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*163bd69bSGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*163bd69bSGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*163bd69bSGarrett D'Amore * SUCH DAMAGE. 25*163bd69bSGarrett D'Amore */ 26*163bd69bSGarrett D'Amore 27*163bd69bSGarrett D'Amore #ifndef CMAP_H 28*163bd69bSGarrett D'Amore #define CMAP_H 29*163bd69bSGarrett D'Amore 30*163bd69bSGarrett D'Amore #include <limits.h> 31*163bd69bSGarrett D'Amore #include <stdbool.h> 32*163bd69bSGarrett D'Amore #include <wchar.h> 33*163bd69bSGarrett D'Amore 34*163bd69bSGarrett D'Amore struct cmapnode { 35*163bd69bSGarrett D'Amore wint_t cmn_from; 36*163bd69bSGarrett D'Amore wint_t cmn_to; 37*163bd69bSGarrett D'Amore struct cmapnode *cmn_left; 38*163bd69bSGarrett D'Amore struct cmapnode *cmn_right; 39*163bd69bSGarrett D'Amore }; 40*163bd69bSGarrett D'Amore 41*163bd69bSGarrett D'Amore struct cmap { 42*163bd69bSGarrett D'Amore #define CM_CACHE_SIZE 128 43*163bd69bSGarrett D'Amore wint_t cm_cache[CM_CACHE_SIZE]; 44*163bd69bSGarrett D'Amore bool cm_havecache; 45*163bd69bSGarrett D'Amore struct cmapnode *cm_root; 46*163bd69bSGarrett D'Amore #define CM_DEF_SELF -2 47*163bd69bSGarrett D'Amore wint_t cm_def; 48*163bd69bSGarrett D'Amore wint_t cm_min; 49*163bd69bSGarrett D'Amore wint_t cm_max; 50*163bd69bSGarrett D'Amore }; 51*163bd69bSGarrett D'Amore 52*163bd69bSGarrett D'Amore struct cmap *cmap_alloc(void); 53*163bd69bSGarrett D'Amore bool cmap_add(struct cmap *, wint_t, wint_t); 54*163bd69bSGarrett D'Amore wint_t cmap_lookup_hard(struct cmap *, wint_t); 55*163bd69bSGarrett D'Amore void cmap_cache(struct cmap *); 56*163bd69bSGarrett D'Amore wint_t cmap_default(struct cmap *, wint_t); 57*163bd69bSGarrett D'Amore 58*163bd69bSGarrett D'Amore #endif 59