[BACK]Return to ctype.h CVS log [TXT][DIR] Up to [local] / src / include

Annotation of src/include/ctype.h, Revision 1.12

1.12    ! millert     1: /*     $OpenBSD: ctype.h,v 1.11 2002/12/29 03:02:35 millert Exp $      */
1.1       deraadt     2: /*     $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1989 The Regents of the University of California.
                      6:  * All rights reserved.
                      7:  * (c) UNIX System Laboratories, Inc.
                      8:  * All or some portions of this file are derived from material licensed
                      9:  * to the University of California by American Telephone and Telegraph
                     10:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     11:  * the permission of UNIX System Laboratories, Inc.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. All advertising materials mentioning features or use of this software
                     22:  *    must display the following acknowledgement:
                     23:  *     This product includes software developed by the University of
                     24:  *     California, Berkeley and its contributors.
                     25:  * 4. Neither the name of the University nor the names of its contributors
                     26:  *    may be used to endorse or promote products derived from this software
                     27:  *    without specific prior written permission.
                     28:  *
                     29:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     30:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     31:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     32:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     33:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     34:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     35:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     36:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     37:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     38:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     39:  * SUCH DAMAGE.
                     40:  *
                     41:  *     @(#)ctype.h     5.3 (Berkeley) 4/3/91
                     42:  */
                     43:
                     44: #ifndef _CTYPE_H_
                     45: #define _CTYPE_H_
                     46: #include <sys/cdefs.h>
                     47:
                     48: #define        _U      0x01
                     49: #define        _L      0x02
                     50: #define        _N      0x04
                     51: #define        _S      0x08
                     52: #define        _P      0x10
                     53: #define        _C      0x20
                     54: #define        _X      0x40
                     55: #define        _B      0x80
                     56:
                     57: extern const char      *_ctype_;
                     58: extern const short     *_tolower_tab_;
                     59: extern const short     *_toupper_tab_;
                     60:
1.5       millert    61: #ifdef _ANSI_LIBRARY
1.1       deraadt    62: __BEGIN_DECLS
1.5       millert    63: int    isalnum(int);
                     64: int    isalpha(int);
                     65: int    iscntrl(int);
                     66: int    isdigit(int);
                     67: int    isgraph(int);
                     68: int    islower(int);
                     69: int    isprint(int);
                     70: int    ispunct(int);
                     71: int    isspace(int);
                     72: int    isupper(int);
                     73: int    isxdigit(int);
                     74: int    tolower(int);
                     75: int    toupper(int);
1.1       deraadt    76:
                     77: #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
1.5       millert    78: int    isblank(int);
                     79: int    isascii(int);
                     80: int    toascii(int);
                     81: int    _tolower(int);
                     82: int    _toupper(int);
1.1       deraadt    83: #endif
                     84: __END_DECLS
                     85:
1.5       millert    86: #else /* !_ANSI_LIBRARY */
                     87:
                     88: static __inline int isalnum(int c)
                     89: {
1.12    ! millert    90:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_U|_L|_N)));
1.5       millert    91: }
                     92:
                     93: static __inline int isalpha(int c)
                     94: {
1.12    ! millert    95:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_U|_L)));
1.5       millert    96: }
                     97:
                     98: static __inline int iscntrl(int c)
                     99: {
1.12    ! millert   100:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _C));
1.5       millert   101: }
                    102:
                    103: static __inline int isdigit(int c)
                    104: {
1.12    ! millert   105:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _N));
1.5       millert   106: }
                    107:
                    108: static __inline int isgraph(int c)
                    109: {
1.12    ! millert   110:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_P|_U|_L|_N)));
1.5       millert   111: }
                    112:
                    113: static __inline int islower(int c)
                    114: {
1.12    ! millert   115:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _L));
1.5       millert   116: }
                    117:
                    118: static __inline int isprint(int c)
                    119: {
1.12    ! millert   120:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_P|_U|_L|_N|_B)));
1.5       millert   121: }
                    122:
                    123: static __inline int ispunct(int c)
                    124: {
1.12    ! millert   125:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _P));
1.5       millert   126: }
                    127:
                    128: static __inline int isspace(int c)
                    129: {
1.12    ! millert   130:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _S));
1.5       millert   131: }
                    132:
                    133: static __inline int isupper(int c)
                    134: {
1.12    ! millert   135:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _U));
1.5       millert   136: }
                    137:
                    138: static __inline int isxdigit(int c)
                    139: {
1.12    ! millert   140:        return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_N|_X)));
1.5       millert   141: }
                    142:
                    143: static __inline int tolower(int c)
                    144: {
1.7       millert   145:        if ((unsigned int)c > 0177)
1.5       millert   146:                return (c);
                    147:        return ((_tolower_tab_ + 1)[c]);
                    148: }
                    149:
                    150: static __inline int toupper(int c)
                    151: {
1.7       millert   152:        if ((unsigned int)c > 0177)
1.5       millert   153:                return (c);
                    154:        return ((_toupper_tab_ + 1)[c]);
                    155: }
1.1       deraadt   156:
                    157: #if !defined(_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
1.5       millert   158: static __inline int isblank(int c)
                    159: {
                    160:        return (c == ' ' || c == '\t');
                    161: }
                    162:
                    163: static __inline int isascii(int c)
                    164: {
1.7       millert   165:        return ((unsigned int)c <= 0177);
1.5       millert   166: }
                    167:
                    168: static __inline int toascii(int c)
                    169: {
                    170:        return (c & 0177);
                    171: }
                    172:
                    173: static __inline int _tolower(int c)
                    174: {
                    175:        return (c - 'A' + 'a');
                    176: }
                    177:
                    178: static __inline int _toupper(int c)
                    179: {
                    180:        return (c - 'a' + 'A');
                    181: }
1.1       deraadt   182: #endif
1.5       millert   183:
                    184: #endif /* !_ANSI_LIBRARY */
1.1       deraadt   185:
                    186: #endif /* !_CTYPE_H_ */