1296177Sjhibbits/* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
2296177Sjhibbits * All rights reserved.
3296177Sjhibbits *
4296177Sjhibbits * Redistribution and use in source and binary forms, with or without
5296177Sjhibbits * modification, are permitted provided that the following conditions are met:
6296177Sjhibbits *     * Redistributions of source code must retain the above copyright
7296177Sjhibbits *       notice, this list of conditions and the following disclaimer.
8296177Sjhibbits *     * Redistributions in binary form must reproduce the above copyright
9296177Sjhibbits *       notice, this list of conditions and the following disclaimer in the
10296177Sjhibbits *       documentation and/or other materials provided with the distribution.
11296177Sjhibbits *     * Neither the name of Freescale Semiconductor nor the
12296177Sjhibbits *       names of its contributors may be used to endorse or promote products
13296177Sjhibbits *       derived from this software without specific prior written permission.
14296177Sjhibbits *
15296177Sjhibbits *
16296177Sjhibbits * ALTERNATIVELY, this software may be distributed under the terms of the
17296177Sjhibbits * GNU General Public License ("GPL") as published by the Free Software
18296177Sjhibbits * Foundation, either version 2 of that License or (at your option) any
19296177Sjhibbits * later version.
20296177Sjhibbits *
21296177Sjhibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22296177Sjhibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23296177Sjhibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24296177Sjhibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25296177Sjhibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26296177Sjhibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27296177Sjhibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28296177Sjhibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29296177Sjhibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30296177Sjhibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31296177Sjhibbits */
32296177Sjhibbits
33296177Sjhibbits#ifndef __CTYPE_EXT_H
34296177Sjhibbits#define __CTYPE_EXT_H
35296177Sjhibbits
36296177Sjhibbits
37296177Sjhibbits#if defined(NCSW_LINUX) && defined(__KERNEL__) || defined(NCSW_FREEBSD)
38296177Sjhibbits/*
39296177Sjhibbits * NOTE! This ctype does not handle EOF like the standard C
40296177Sjhibbits * library is required to.
41296177Sjhibbits */
42296177Sjhibbits
43296177Sjhibbits#define _U    0x01    /* upper */
44296177Sjhibbits#define _L    0x02    /* lower */
45296177Sjhibbits#define _D    0x04    /* digit */
46296177Sjhibbits#define _C    0x08    /* cntrl */
47296177Sjhibbits#define _P    0x10    /* punct */
48296177Sjhibbits#define _S    0x20    /* white space (space/lf/tab) */
49296177Sjhibbits#define _X    0x40    /* hex digit */
50296177Sjhibbits#define _SP   0x80    /* hard space (0x20) */
51296177Sjhibbits
52296177Sjhibbitsextern unsigned char _ctype[];
53296177Sjhibbits
54296177Sjhibbits#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
55296177Sjhibbits
56296177Sjhibbits#define isalnum(c)    ((__ismask(c)&(_U|_L|_D)) != 0)
57296177Sjhibbits#define isalpha(c)    ((__ismask(c)&(_U|_L)) != 0)
58296177Sjhibbits#define iscntrl(c)    ((__ismask(c)&(_C)) != 0)
59296177Sjhibbits#define isdigit(c)    ((__ismask(c)&(_D)) != 0)
60296177Sjhibbits#define isgraph(c)    ((__ismask(c)&(_P|_U|_L|_D)) != 0)
61296177Sjhibbits#define islower(c)    ((__ismask(c)&(_L)) != 0)
62296177Sjhibbits#define isprint(c)    ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
63296177Sjhibbits#define ispunct(c)    ((__ismask(c)&(_P)) != 0)
64296177Sjhibbits#define isspace(c)    ((__ismask(c)&(_S)) != 0)
65296177Sjhibbits#define isupper(c)    ((__ismask(c)&(_U)) != 0)
66296177Sjhibbits#define isxdigit(c)   ((__ismask(c)&(_D|_X)) != 0)
67296177Sjhibbits
68296177Sjhibbits#define isascii(c) (((unsigned char)(c))<=0x7f)
69296177Sjhibbits#define toascii(c) (((unsigned char)(c))&0x7f)
70296177Sjhibbits
71296177Sjhibbitsstatic __inline__ unsigned char __tolower(unsigned char c)
72296177Sjhibbits{
73296177Sjhibbits    if (isupper(c))
74296177Sjhibbits        c -= 'A'-'a';
75296177Sjhibbits    return c;
76296177Sjhibbits}
77296177Sjhibbits
78296177Sjhibbitsstatic __inline__ unsigned char __toupper(unsigned char c)
79296177Sjhibbits{
80296177Sjhibbits    if (islower(c))
81296177Sjhibbits        c -= 'a'-'A';
82296177Sjhibbits    return c;
83296177Sjhibbits}
84296177Sjhibbits
85296177Sjhibbits#define tolower(c) __tolower(c)
86296177Sjhibbits#define toupper(c) __toupper(c)
87296177Sjhibbits
88296177Sjhibbits#else
89296177Sjhibbits#include <ctype.h>
90296177Sjhibbits#endif /* defined(NCSW_LINUX) && defined(__KERNEL__) || defined(NCSW_FREEBSD) */
91296177Sjhibbits
92296177Sjhibbits
93296177Sjhibbits#endif /* __CTYPE_EXT_H */
94