GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/locale/runeglue.c Lines: 0 33 0.0 %
Date: 2017-11-13 Branches: 0 24 0.0 %

Line Branch Exec Source
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
	p = malloc(sizeof *p);
63
	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
	if (strcmp(rl->rl_encoding, "UTF8") == 0)
74
		limit = 128;
75
76
	rl->rl_tabs = p;
77
	p->ctype_tab[0] = 0;
78
	p->toupper_tab[0] = EOF;
79
	p->tolower_tab[0] = EOF;
80
	for (i = 0; i < limit; i++) {
81
		p->ctype_tab[i + 1] = 0;
82
		if (rl->rl_runetype[i] & _CTYPE_U)
83
			p->ctype_tab[i + 1] |= _U;
84
		if (rl->rl_runetype[i] & _CTYPE_L)
85
			p->ctype_tab[i + 1] |= _L;
86
		if (rl->rl_runetype[i] & _CTYPE_D)
87
			p->ctype_tab[i + 1] |= _N;
88
		if (rl->rl_runetype[i] & _CTYPE_S)
89
			p->ctype_tab[i + 1] |= _S;
90
		if (rl->rl_runetype[i] & _CTYPE_P)
91
			p->ctype_tab[i + 1] |= _P;
92
		if (rl->rl_runetype[i] & _CTYPE_C)
93
			p->ctype_tab[i + 1] |= _C;
94
		if (rl->rl_runetype[i] & _CTYPE_X)
95
			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
		if ((rl->rl_runetype[i] & (_CTYPE_R | _CTYPE_G))
104
		    == _CTYPE_R)
105
			p->ctype_tab[i + 1] |= _B;
106
107
		p->toupper_tab[i + 1] = (short)rl->rl_mapupper[i];
108
		p->tolower_tab[i + 1] = (short)rl->rl_maplower[i];
109
	}
110
	for (i = limit; i < CTYPE_NUM_CHARS; i++)
111
		p->ctype_tab[i + 1] = 0;
112
113
	return 0;
114
}