Home | History | Annotate | Download | only in stdlib
      1 /*	$OpenBSD: ctype_.c,v 1.9 2005/08/08 08:05:33 espie Exp $ */
      2 /*
      3  * Copyright (c) 1989 The Regents of the University of California.
      4  * All rights reserved.
      5  * (c) UNIX System Laboratories, Inc.
      6  * All or some portions of this file are derived from material licensed
      7  * to the University of California by American Telephone and Telegraph
      8  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
      9  * the permission of UNIX System Laboratories, Inc.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <ctype.h>
     37 #include "ctype_private.h"
     38 
     39 #define _U _CTYPE_U
     40 #define _L _CTYPE_L
     41 #define _N _CTYPE_N
     42 #define _S _CTYPE_S
     43 #define _P _CTYPE_P
     44 #define _C _CTYPE_C
     45 #define _X _CTYPE_X
     46 #define _B _CTYPE_B
     47 
     48 const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
     49 	0,
     50 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
     51 	_C,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C|_S,	_C,	_C,
     52 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
     53 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
     54    _S|(char)_B,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
     55 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
     56 	_N,	_N,	_N,	_N,	_N,	_N,	_N,	_N,
     57 	_N,	_N,	_P,	_P,	_P,	_P,	_P,	_P,
     58 	_P,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U,
     59 	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
     60 	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
     61 	_U,	_U,	_U,	_P,	_P,	_P,	_P,	_P,
     62 	_P,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L,
     63 	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
     64 	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
     65 	/* determine printability based on the IS0 8859 8-bit standard */
     66 	_L,	_L,	_L,	_P,	_P,	_P,	_P,	_C,
     67 
     68 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 80 */
     69 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 88 */
     70 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 90 */
     71 	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C, /* 98 */
     72 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A0 */
     73 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* A8 */
     74 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B0 */
     75 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* B8 */
     76 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C0 */
     77 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* C8 */
     78 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D0 */
     79 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* D8 */
     80 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E0 */
     81 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* E8 */
     82 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P, /* F0 */
     83 	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P  /* F8 */
     84 };
     85 
     86 const char *_ctype_ = _C_ctype_;
     87 
     88 
     89 // TODO: fix the header file so we don't have to duplicate all this inlined stuff.
     90 
     91 #if 1 /* ndef NDEBUG */
     92 int isalnum(int c)
     93 {
     94 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
     95 }
     96 
     97 int isalpha(int c)
     98 {
     99 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
    100 }
    101 
    102 int iscntrl(int c)
    103 {
    104 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C));
    105 }
    106 
    107 int isdigit(int c)
    108 {
    109 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
    110 }
    111 
    112 int isgraph(int c)
    113 {
    114 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
    115 }
    116 
    117 int islower(int c)
    118 {
    119 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L));
    120 }
    121 
    122 int isprint(int c)
    123 {
    124 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
    125 }
    126 
    127 int ispunct(int c)
    128 {
    129 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
    130 }
    131 
    132 int isspace(int c)
    133 {
    134 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
    135 }
    136 
    137 int isupper(int c)
    138 {
    139 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U));
    140 }
    141 
    142 int isxdigit(int c)
    143 {
    144 	return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
    145 }
    146 
    147 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
    148     || __XPG_VISIBLE > 600
    149 int isblank(int c)
    150 {
    151 	return (c == ' ' || c == '\t');
    152 }
    153 #endif
    154 
    155 #if __BSD_VISIBLE || __XPG_VISIBLE
    156 int isascii(int c)
    157 {
    158 	return ((unsigned int)c <= 0177);
    159 }
    160 
    161 int toascii(int c)
    162 {
    163 	return (c & 0177);
    164 }
    165 
    166 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
    167 
    168 #endif /* !NDBEUG */
    169