ctype.h revision 1539
1238384Sjkim/* 2238384Sjkim * Copyright (c) 1989, 1993 3238384Sjkim * The Regents of the University of California. All rights reserved. 4238384Sjkim * (c) UNIX System Laboratories, Inc. 5238384Sjkim * All or some portions of this file are derived from material licensed 6238384Sjkim * to the University of California by American Telephone and Telegraph 7238384Sjkim * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8238384Sjkim * the permission of UNIX System Laboratories, Inc. 9280304Sjkim * 10238384Sjkim * This code is derived from software contributed to Berkeley by 11238384Sjkim * Paul Borman at Krystal Technologies. 12238384Sjkim * 13238384Sjkim * Redistribution and use in source and binary forms, with or without 14238384Sjkim * modification, are permitted provided that the following conditions 15238384Sjkim * are met: 16238384Sjkim * 1. Redistributions of source code must retain the above copyright 17238384Sjkim * notice, this list of conditions and the following disclaimer. 18238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright 19238384Sjkim * notice, this list of conditions and the following disclaimer in the 20238384Sjkim * documentation and/or other materials provided with the distribution. 21238384Sjkim * 3. All advertising materials mentioning features or use of this software 22238384Sjkim * must display the following acknowledgement: 23238384Sjkim * This product includes software developed by the University of 24238384Sjkim * California, Berkeley and its contributors. 25238384Sjkim * 4. Neither the name of the University nor the names of its contributors 26238384Sjkim * may be used to endorse or promote products derived from this software 27238384Sjkim * without specific prior written permission. 28238384Sjkim * 29238384Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30238384Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32238384Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33238384Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34238384Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35238384Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37238384Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38238384Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39238384Sjkim * SUCH DAMAGE. 40238384Sjkim * 41238384Sjkim * @(#)ctype.h 8.4 (Berkeley) 1/21/94 42238384Sjkim */ 43238384Sjkim 44238384Sjkim#ifndef _CTYPE_H_ 45238384Sjkim#define _CTYPE_H_ 46238384Sjkim 47238384Sjkim#include <runetype.h> 48238384Sjkim 49238384Sjkim#define _A 0x00000100L /* Alpha */ 50238384Sjkim#define _C 0x00000200L /* Control */ 51238384Sjkim#define _D 0x00000400L /* Digit */ 52238384Sjkim#define _G 0x00000800L /* Graph */ 53238384Sjkim#define _L 0x00001000L /* Lower */ 54238384Sjkim#define _P 0x00002000L /* Punct */ 55238384Sjkim#define _S 0x00004000L /* Space */ 56238384Sjkim#define _U 0x00008000L /* Upper */ 57238384Sjkim#define _X 0x00010000L /* X digit */ 58238384Sjkim#define _B 0x00020000L /* Blank */ 59238384Sjkim#define _R 0x00040000L /* Print */ 60238384Sjkim#define _I 0x00080000L /* Ideogram */ 61238384Sjkim#define _T 0x00100000L /* Special */ 62280304Sjkim#define _Q 0x00200000L /* Phonogram */ 63280304Sjkim 64280304Sjkim#define isalnum(c) __istype((c), (_A|_D)) 65280304Sjkim#define isalpha(c) __istype((c), _A) 66238384Sjkim#define iscntrl(c) __istype((c), _C) 67238384Sjkim#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */ 68280304Sjkim#define isgraph(c) __istype((c), _G) 69280304Sjkim#define islower(c) __istype((c), _L) 70280304Sjkim#define isprint(c) __istype((c), _R) 71238384Sjkim#define ispunct(c) __istype((c), _P) 72238384Sjkim#define isspace(c) __istype((c), _S) 73238384Sjkim#define isupper(c) __istype((c), _U) 74238384Sjkim#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */ 75238384Sjkim 76238384Sjkim#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 77238384Sjkim#define isascii(c) ((c & ~0x7F) == 0) 78238384Sjkim#define toascii(c) ((c) & 0x7F) 79238384Sjkim#define digittoint(c) __istype((c), 0xFF) 80238384Sjkim#define isideogram(c) __istype((c), _I) 81280304Sjkim#define isphonogram(c) __istype((c), _T) 82280304Sjkim#define isspecial(c) __istype((c), _Q) 83280304Sjkim#define isblank(c) __istype((c), _B) 84280304Sjkim#define isrune(c) __istype((c), 0xFFFFFF00L) 85280304Sjkim#define isnumber(c) __istype((c), _D) 86280304Sjkim#define ishexnumber(c) __istype((c), _X) 87280304Sjkim#endif 88280304Sjkim 89280304Sjkim/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */ 90280304Sjkim__BEGIN_DECLS 91280304Sjkimunsigned long ___runetype __P((_BSD_RUNE_T_)); 92280304Sjkim_BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_)); 93280304Sjkim_BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_)); 94280304Sjkim__END_DECLS 95280304Sjkim 96280304Sjkim/* 97280304Sjkim * If your compiler supports prototypes and inline functions, 98280304Sjkim * #define _USE_CTYPE_INLINE_. Otherwise, use the C library 99280304Sjkim * functions. 100280304Sjkim */ 101280304Sjkim#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus) 102280304Sjkim#define _USE_CTYPE_INLINE_ 1 103280304Sjkim#endif 104280304Sjkim 105280304Sjkim#if defined(_USE_CTYPE_INLINE_) 106280304Sjkimstatic __inline int 107280304Sjkim__istype(_BSD_RUNE_T_ c, unsigned long f) 108280304Sjkim{ 109280304Sjkim return((((c & _CRMASK) ? ___runetype(c) : 110280304Sjkim _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0); 111280304Sjkim} 112280304Sjkim 113280304Sjkimstatic __inline int 114280304Sjkim__isctype(_BSD_RUNE_T_ c, unsigned long f) 115280304Sjkim{ 116238384Sjkim return((((c & _CRMASK) ? 0 : 117280304Sjkim _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0); 118280304Sjkim} 119280304Sjkim 120280304Sjkim/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */ 121280304Sjkim#if !defined(_ANSI_LIBRARY) 122280304Sjkimstatic __inline _BSD_RUNE_T_ 123280304Sjkimtoupper(_BSD_RUNE_T_ c) 124280304Sjkim{ 125280304Sjkim return((c & _CRMASK) ? 126238384Sjkim ___toupper(c) : _CurrentRuneLocale->mapupper[c]); 127238384Sjkim} 128280304Sjkim 129280304Sjkimstatic __inline _BSD_RUNE_T_ 130280304Sjkimtolower(_BSD_RUNE_T_ c) 131280304Sjkim{ 132280304Sjkim return((c & _CRMASK) ? 133280304Sjkim ___tolower(c) : _CurrentRuneLocale->maplower[c]); 134280304Sjkim} 135280304Sjkim#endif /* !_ANSI_LIBRARY */ 136280304Sjkim 137280304Sjkim#else /* !_USE_CTYPE_INLINE_ */ 138280304Sjkim 139280304Sjkim__BEGIN_DECLS 140280304Sjkimint __istype __P((_BSD_RUNE_T_, unsigned long)); 141280304Sjkimint __isctype __P((_BSD_RUNE_T_, unsigned long)); 142280304Sjkim_BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_)); 143280304Sjkim_BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_)); 144280304Sjkim__END_DECLS 145280304Sjkim#endif /* _USE_CTYPE_INLINE_ */ 146280304Sjkim 147280304Sjkim#endif /* !_CTYPE_H_ */ 148280304Sjkim