_ctype.h revision 3433
1100882Smike/* 2100882Smike * Copyright (c) 1989, 1993 3100882Smike * The Regents of the University of California. All rights reserved. 4100882Smike * (c) UNIX System Laboratories, Inc. 5100882Smike * All or some portions of this file are derived from material licensed 6100882Smike * to the University of California by American Telephone and Telegraph 7100882Smike * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8100882Smike * the permission of UNIX System Laboratories, Inc. 9100882Smike * 10100882Smike * This code is derived from software contributed to Berkeley by 11100882Smike * Paul Borman at Krystal Technologies. 12100882Smike * 13100882Smike * Redistribution and use in source and binary forms, with or without 14100882Smike * modification, are permitted provided that the following conditions 15100882Smike * are met: 16100882Smike * 1. Redistributions of source code must retain the above copyright 17100882Smike * notice, this list of conditions and the following disclaimer. 18100882Smike * 2. Redistributions in binary form must reproduce the above copyright 19100882Smike * notice, this list of conditions and the following disclaimer in the 20100882Smike * documentation and/or other materials provided with the distribution. 21100882Smike * 3. All advertising materials mentioning features or use of this software 22100882Smike * must display the following acknowledgement: 23100882Smike * This product includes software developed by the University of 24100882Smike * California, Berkeley and its contributors. 25100882Smike * 4. Neither the name of the University nor the names of its contributors 26100882Smike * may be used to endorse or promote products derived from this software 27100882Smike * without specific prior written permission. 28100882Smike * 29100882Smike * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30100882Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31100882Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32100882Smike * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33100882Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34100882Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35100882Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36100882Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37100882Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38100882Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39100882Smike * SUCH DAMAGE. 40100882Smike * 41100882Smike * @(#)ctype.h 8.4 (Berkeley) 1/21/94 42100882Smike */ 43100882Smike 44100882Smike#ifndef _CTYPE_H_ 45100882Smike#define _CTYPE_H_ 46100882Smike 47100882Smike#include <runetype.h> 48217147Stijl 49217147Stijl#define _A 0x00000100L /* Alpha */ 50100882Smike#define _C 0x00000200L /* Control */ 51100882Smike#define _D 0x00000400L /* Digit */ 52100882Smike#define _G 0x00000800L /* Graph */ 53100882Smike#define _L 0x00001000L /* Lower */ 54100882Smike#define _P 0x00002000L /* Punct */ 55100882Smike#define _S 0x00004000L /* Space */ 56100882Smike#define _U 0x00008000L /* Upper */ 57100882Smike#define _X 0x00010000L /* X digit */ 58100882Smike#define _B 0x00020000L /* Blank */ 59100882Smike#define _R 0x00040000L /* Print */ 60100882Smike#define _I 0x00080000L /* Ideogram */ 61100882Smike#define _T 0x00100000L /* Special */ 62100882Smike#define _Q 0x00200000L /* Phonogram */ 63100882Smike 64100882Smike#define isalnum(c) __istype((c), (_A|_D)) 65100882Smike#define isalpha(c) __istype((c), _A) 66100882Smike#define iscntrl(c) __istype((c), _C) 67100882Smike#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 68100882Smike#define isgraph(c) __istype((c), _G) 69100882Smike#define islower(c) __istype((c), _L) 70100882Smike#define isprint(c) __istype((c), _R) 71100882Smike#define ispunct(c) __istype((c), _P) 72100882Smike#define isspace(c) __istype((c), _S) 73100882Smike#define isupper(c) __istype((c), _U) 74100882Smike#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 75100882Smike 76100882Smike#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 77100882Smike#define isascii(c) ((c & ~0x7F) == 0) 78100882Smike#define toascii(c) ((c) & 0x7F) 79100882Smike#define digittoint(c) __istype((c), 0xFF) 80100882Smike#define isideogram(c) __istype((c), _I) 81100882Smike#define isphonogram(c) __istype((c), _T) 82100882Smike#define isspecial(c) __istype((c), _Q) 83100882Smike#define isblank(c) __istype((c), _B) 84100882Smike#define isrune(c) __istype((c), 0xFFFFFF00L) 85100882Smike#define isnumber(c) __istype((c), _D) 86100882Smike#define ishexnumber(c) __istype((c), _X) 87100882Smike#endif 88100882Smike 89100882Smike/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */ 90100882Smike__BEGIN_DECLS 91100882Smikeunsigned long ___runetype __P((_BSD_RUNE_T_)); 92100882Smike_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_)); 93100882Smike_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_)); 94100882Smike__END_DECLS 95100882Smike 96100882Smike/* 97100882Smike * If your compiler supports prototypes and inline functions, 98100882Smike * #define _USE_CTYPE_INLINE_. Otherwise, use the C library 99100882Smike * functions. 100100882Smike */ 101100882Smike#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus) 102100882Smike#define _USE_CTYPE_INLINE_ 1 103100882Smike#endif 104100882Smike 105100882Smike#if defined(_USE_CTYPE_INLINE_) 106100882Smike 107100882Smike#ifndef EOF 108100882Smike#define EOF (-1) 109100882Smike#endif 110100882Smike 111100882Smikestatic __inline int 112100882Smike__istype(_BSD_RUNE_T_ c, unsigned long f) 113100882Smike{ 114100882Smike if (c == EOF) 115100882Smike return 0; 116100882Smike if (c < 0) 117100882Smike c = (unsigned char) c; 118100882Smike return((((c & _CRMASK) ? ___runetype(c) : 119100882Smike _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0); 120100882Smike} 121100882Smike 122100882Smikestatic __inline int 123100882Smike__isctype(_BSD_RUNE_T_ c, unsigned long f) 124100882Smike{ 125100882Smike if (c == EOF) 126100882Smike return 0; 127100882Smike if (c < 0) 128100882Smike c = (unsigned char) c; 129100882Smike return((((c & _CRMASK) ? 0 : 130100882Smike _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0); 131100882Smike} 132100882Smike 133100882Smike/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */ 134100882Smike#if !defined(_ANSI_LIBRARY) 135100882Smikestatic __inline _BSD_RUNE_T_ 136100882Smiketoupper(_BSD_RUNE_T_ c) 137100882Smike{ 138100882Smike if (c == EOF) 139100882Smike return EOF; 140100882Smike if (c < 0) 141100882Smike c = (unsigned char) c; 142100882Smike return((c & _CRMASK) ? 143100882Smike ___toupper(c) : _CurrentRuneLocale->mapupper[c]); 144100882Smike} 145100882Smike 146100882Smikestatic __inline _BSD_RUNE_T_ 147100882Smiketolower(_BSD_RUNE_T_ c) 148100882Smike{ 149100882Smike if (c == EOF) 150100882Smike return EOF; 151100882Smike if (c < 0) 152100882Smike c = (unsigned char) c; 153100882Smike return((c & _CRMASK) ? 154100882Smike ___tolower(c) : _CurrentRuneLocale->maplower[c]); 155100882Smike} 156100882Smike#endif /* !_ANSI_LIBRARY */ 157100882Smike 158100882Smike#else /* !_USE_CTYPE_INLINE_ */ 159 160__BEGIN_DECLS 161int __istype __P((_BSD_RUNE_T_, unsigned long)); 162int __isctype __P((_BSD_RUNE_T_, unsigned long)); 163_BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_)); 164_BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_)); 165__END_DECLS 166#endif /* _USE_CTYPE_INLINE_ */ 167 168#endif /* !_CTYPE_H_ */ 169