cmap.h revision 131846
1131846Stjr/*- 2131846Stjr * Copyright (c) 2004 Tim J. Robbins. 3131846Stjr * All rights reserved. 4131846Stjr * 5131846Stjr * Redistribution and use in source and binary forms, with or without 6131846Stjr * modification, are permitted provided that the following conditions 7131846Stjr * are met: 8131846Stjr * 1. Redistributions of source code must retain the above copyright 9131846Stjr * notice, this list of conditions and the following disclaimer. 10131846Stjr * 2. Redistributions in binary form must reproduce the above copyright 11131846Stjr * notice, this list of conditions and the following disclaimer in the 12131846Stjr * documentation and/or other materials provided with the distribution. 13131846Stjr * 14131846Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131846Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131846Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131846Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131846Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131846Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131846Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131846Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131846Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131846Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131846Stjr * SUCH DAMAGE. 25131846Stjr * 26131846Stjr * $FreeBSD: head/usr.bin/tr/cmap.h 131846 2004-07-09 02:08:07Z tjr $ 27131846Stjr */ 28131846Stjr 29131846Stjr#ifndef CMAP_H 30131846Stjr#define CMAP_H 31131846Stjr 32131846Stjr#include <limits.h> 33131846Stjr#include <stdbool.h> 34131846Stjr#include <wchar.h> 35131846Stjr 36131846Stjrstruct cmapnode { 37131846Stjr wint_t cmn_from; 38131846Stjr wint_t cmn_to; 39131846Stjr struct cmapnode *cmn_left; 40131846Stjr struct cmapnode *cmn_right; 41131846Stjr}; 42131846Stjr 43131846Stjrstruct cmap { 44131846Stjr#define CM_CACHE_SIZE 128 45131846Stjr wint_t cm_cache[CM_CACHE_SIZE]; 46131846Stjr bool cm_havecache; 47131846Stjr struct cmapnode *cm_root; 48131846Stjr#define CM_DEF_SELF -2 49131846Stjr wint_t cm_def; 50131846Stjr wint_t cm_min; 51131846Stjr wint_t cm_max; 52131846Stjr}; 53131846Stjr 54131846Stjrstruct cmap * cmap_alloc(void); 55131846Stjrbool cmap_add(struct cmap *, wint_t, wint_t); 56131846Stjrwint_t cmap_lookup_hard(struct cmap *, wint_t); 57131846Stjrvoid cmap_cache(struct cmap *); 58131846Stjrwint_t cmap_default(struct cmap *, wint_t); 59131846Stjr 60131846Stjrstatic __inline wint_t 61131846Stjrcmap_lookup(struct cmap *cm, wint_t from) 62131846Stjr{ 63131846Stjr 64131846Stjr if (from < CM_CACHE_SIZE && cm->cm_havecache) 65131846Stjr return (cm->cm_cache[from]); 66131846Stjr return (cmap_lookup_hard(cm, from)); 67131846Stjr} 68131846Stjr 69131846Stjrstatic __inline wint_t 70131846Stjrcmap_min(struct cmap *cm) 71131846Stjr{ 72131846Stjr 73131846Stjr return (cm->cm_min); 74131846Stjr} 75131846Stjr 76131846Stjrstatic __inline wint_t 77131846Stjrcmap_max(struct cmap *cm) 78131846Stjr{ 79131846Stjr 80131846Stjr return (cm->cm_max); 81131846Stjr} 82131846Stjr 83131846Stjr#endif 84