| 1 |  |  | /*	$OpenBSD: runeglue.c,v 1.5 2017/08/05 15:16:32 schwarze Exp $ */ | 
    
    | 2 |  |  | /*	$NetBSD: runeglue.c,v 1.10 2003/03/10 21:18:49 tshiozak Exp $	*/ | 
    
    | 3 |  |  |  | 
    
    | 4 |  |  | /*- | 
    
    | 5 |  |  |  * Copyright (c)1999 Citrus Project, | 
    
    | 6 |  |  |  * All rights reserved. | 
    
    | 7 |  |  |  * | 
    
    | 8 |  |  |  * Redistribution and use in source and binary forms, with or without | 
    
    | 9 |  |  |  * modification, are permitted provided that the following conditions | 
    
    | 10 |  |  |  * are met: | 
    
    | 11 |  |  |  * 1. Redistributions of source code must retain the above copyright | 
    
    | 12 |  |  |  *    notice, this list of conditions and the following disclaimer. | 
    
    | 13 |  |  |  * 2. Redistributions in binary form must reproduce the above copyright | 
    
    | 14 |  |  |  *    notice, this list of conditions and the following disclaimer in the | 
    
    | 15 |  |  |  *    documentation and/or other materials provided with the distribution. | 
    
    | 16 |  |  |  * | 
    
    | 17 |  |  |  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | 
    
    | 18 |  |  |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
    
    | 19 |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
    
    | 20 |  |  |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 
    
    | 21 |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
    
    | 22 |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
    
    | 23 |  |  |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
    
    | 24 |  |  |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
    
    | 25 |  |  |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
    
    | 26 |  |  |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
    
    | 27 |  |  |  * SUCH DAMAGE. | 
    
    | 28 |  |  |  * | 
    
    | 29 |  |  |  *	Id: runeglue.c,v 1.7 2000/12/22 22:52:29 itojun Exp | 
    
    | 30 |  |  |  */ | 
    
    | 31 |  |  |  | 
    
    | 32 |  |  | /* | 
    
    | 33 |  |  |  * Glue code to hide "rune" facility from user programs. | 
    
    | 34 |  |  |  * This is important to keep backward/future compatibility. | 
    
    | 35 |  |  |  */ | 
    
    | 36 |  |  |  | 
    
    | 37 |  |  | #include <assert.h> | 
    
    | 38 |  |  | #include <limits.h> | 
    
    | 39 |  |  | #include <stdio.h> | 
    
    | 40 |  |  | #include <sys/types.h> | 
    
    | 41 |  |  | #include <ctype.h> | 
    
    | 42 |  |  | #include <stdlib.h> | 
    
    | 43 |  |  | #include <string.h> | 
    
    | 44 |  |  | #include <wchar.h> | 
    
    | 45 |  |  | #include "rune.h" | 
    
    | 46 |  |  | #include "rune_local.h" | 
    
    | 47 |  |  | #include "ctype_private.h" | 
    
    | 48 |  |  |  | 
    
    | 49 |  |  | #if EOF != -1 | 
    
    | 50 |  |  | #error "EOF != -1" | 
    
    | 51 |  |  | #endif | 
    
    | 52 |  |  | #if _CACHED_RUNES != 256 | 
    
    | 53 |  |  | #error "_CACHED_RUNES != 256" | 
    
    | 54 |  |  | #endif | 
    
    | 55 |  |  |  | 
    
    | 56 |  |  | int | 
    
    | 57 |  |  | __make_ctype_tabs(_RuneLocale *rl) | 
    
    | 58 |  |  | { | 
    
    | 59 |  |  | 	int i, limit; | 
    
    | 60 |  |  | 	struct old_tabs *p; | 
    
    | 61 |  |  |  | 
    
    | 62 |  | 80 | 	p = malloc(sizeof *p); | 
    
    | 63 | ✗✓ | 40 | 	if (!p) | 
    
    | 64 |  |  | 		return -1; | 
    
    | 65 |  |  |  | 
    
    | 66 |  |  | 	/* By default, fill the ctype tab completely. */ | 
    
    | 67 |  |  | 	limit = CTYPE_NUM_CHARS; | 
    
    | 68 |  |  |  | 
    
    | 69 |  |  | 	/* In UTF-8-encoded locales, the single-byte ctype functions | 
    
    | 70 |  |  | 	 * must only return non-zero values for ASCII characters. | 
    
    | 71 |  |  | 	 * Any non-ASCII single-byte character is not a valid UTF-8 sequence. | 
    
    | 72 |  |  | 	 */ | 
    
    | 73 | ✓✗ | 40 | 	if (strcmp(rl->rl_encoding, "UTF8") == 0) | 
    
    | 74 |  | 40 | 		limit = 128; | 
    
    | 75 |  |  |  | 
    
    | 76 |  | 40 | 	rl->rl_tabs = p; | 
    
    | 77 |  | 40 | 	p->ctype_tab[0] = 0; | 
    
    | 78 |  | 40 | 	p->toupper_tab[0] = EOF; | 
    
    | 79 |  | 40 | 	p->tolower_tab[0] = EOF; | 
    
    | 80 | ✓✓ | 10320 | 	for (i = 0; i < limit; i++) { | 
    
    | 81 |  | 5120 | 		p->ctype_tab[i + 1] = 0; | 
    
    | 82 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_U) | 
    
    | 83 |  | 1040 | 			p->ctype_tab[i + 1] |= _U; | 
    
    | 84 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_L) | 
    
    | 85 |  | 1040 | 			p->ctype_tab[i + 1] |= _L; | 
    
    | 86 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_D) | 
    
    | 87 |  | 400 | 			p->ctype_tab[i + 1] |= _N; | 
    
    | 88 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_S) | 
    
    | 89 |  | 240 | 			p->ctype_tab[i + 1] |= _S; | 
    
    | 90 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_P) | 
    
    | 91 |  | 1280 | 			p->ctype_tab[i + 1] |= _P; | 
    
    | 92 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_C) | 
    
    | 93 |  | 1320 | 			p->ctype_tab[i + 1] |= _C; | 
    
    | 94 | ✓✓ | 5120 | 		if (rl->rl_runetype[i] & _CTYPE_X) | 
    
    | 95 |  | 880 | 			p->ctype_tab[i + 1] |= _X; | 
    
    | 96 |  |  | 		/* | 
    
    | 97 |  |  | 		 * _B has been used incorrectly (or with older declaration) | 
    
    | 98 |  |  | 		 * in ctype.h isprint() macro. | 
    
    | 99 |  |  | 		 * _B does not mean isblank, it means "isprint && !isgraph". | 
    
    | 100 |  |  | 		 * the following is okay since isblank() was hardcoded in | 
    
    | 101 |  |  | 		 * function (i.e. isblank() is inherently locale unfriendly). | 
    
    | 102 |  |  | 		 */ | 
    
    | 103 | ✓✓ | 10240 | 		if ((rl->rl_runetype[i] & (_CTYPE_R | _CTYPE_G)) | 
    
    | 104 |  | 5120 | 		    == _CTYPE_R) | 
    
    | 105 |  | 40 | 			p->ctype_tab[i + 1] |= _B; | 
    
    | 106 |  |  |  | 
    
    | 107 |  | 5120 | 		p->toupper_tab[i + 1] = (short)rl->rl_mapupper[i]; | 
    
    | 108 |  | 5120 | 		p->tolower_tab[i + 1] = (short)rl->rl_maplower[i]; | 
    
    | 109 |  |  | 	} | 
    
    | 110 | ✓✓ | 10320 | 	for (i = limit; i < CTYPE_NUM_CHARS; i++) | 
    
    | 111 |  | 5120 | 		p->ctype_tab[i + 1] = 0; | 
    
    | 112 |  |  |  | 
    
    | 113 |  | 40 | 	return 0; | 
    
    | 114 |  | 40 | } |