Back to index

tetex-bin  3.0
c-ctype.h
Go to the documentation of this file.
00001 /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
00002 
00003 Copyright (C) 1992, 2000 Free Software Foundation, Inc.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #ifndef KPATHSEA_C_CTYPE_H
00020 #define KPATHSEA_C_CTYPE_H
00021 
00022 #include <ctype.h>
00023 
00024 /* Be sure we have `isascii'.  */
00025 #ifdef WIN32
00026 #include <oldnames.h>
00027 #else
00028 #ifndef isascii
00029 #define isascii(c) 1
00030 #endif
00031 #endif
00032 
00033 #define ISALNUM(c) (isascii (c) && isalnum(c))
00034 #define ISALPHA(c) (isascii (c) && isalpha(c))
00035 #define ISASCII isascii
00036 #define ISCNTRL(c) (isascii (c) && iscntrl(c))
00037 #define ISDIGIT(c) (isascii (c) && isdigit (c))
00038 #define ISGRAPH(c) (isascii (c) && isgraph(c))
00039 #define ISLOWER(c) (isascii (c) && islower(c))
00040 #define ISPRINT(c) (isascii (c) && isprint(c))
00041 #define ISPUNCT(c) (isascii (c) && ispunct(c))
00042 #define ISSPACE(c) (isascii (c) && isspace(c))
00043 #define ISUPPER(c) (isascii (c) && isupper(c))
00044 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
00045 #define TOASCII toascii
00046 #define TOLOWER(c) (ISUPPER (c) ? tolower (c) : (c))
00047 #define TOUPPER(c) (ISLOWER (c) ? toupper (c) : (c))
00048 
00049 /* This isn't part of the usual <ctype.h>, but it's useful sometimes.  */
00050 #ifndef isblank
00051 #define isblank(c) ((c) == ' ' || (c) == '\t')
00052 #endif
00053 
00054 #define ISBLANK(c) (isascii (c) && isblank (c))
00055 
00056 
00057 /* Here's why this mess is necessary:
00058 
00059 From: meyering@cs.utexas.edu (Jim Meyering)
00060 Date: Wed, 25 Nov 1992 09:52:33 -0600
00061 Subject: ss-921123: using isascii with <ctype.h> macros
00062 
00063   Yesterday some cursory regression testing found that GNU od
00064   (in an upcoming release of textutils) generated incorrect output
00065   when run on an SGI indigo because isprint ('\377') returned true.
00066   Of course, '\377' is not a printing character;  the problem lay
00067   in using isprint without first making sure its integer argument
00068   corresponded to an ascii code.
00069 
00070   MORAL: always guard uses of ctype macros with isascii if it's available.
00071   An obvious alternative is to avoid <ctype.h> and define and use your
00072   own versions of the ctype macros.
00073 
00074   A pretty clean approach to using <ctype.h> and isascii was
00075   suggested by David MacKenzie:
00076 
00077   #ifndef isascii
00078   #define isascii(c) 1
00079   #endif
00080 
00081   #define ISDIGIT(c) (isascii (c) && isdigit (c))
00082   #define ISPRINT(c) (isascii (c) && isprint (c))
00083   ...
00084 
00085   then, use ISDIGIT, etc. instead of isdigit, etc.  */
00086   
00087 #endif /* not KPATHSEA_C_CTYPE_H */