home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / kpathsea / c-ctype.h < prev    next >
C/C++ Source or Header  |  2000-01-15  |  4KB  |  102 lines

  1. /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  18.  
  19. /* Modified by Klaus Gebhardt, 1999 */
  20.  
  21. #ifndef KPATHSEA_C_CTYPE_H
  22. #define KPATHSEA_C_CTYPE_H
  23.  
  24. #include <ctype.h>
  25.  
  26. /* Be sure we have `isascii'.  */
  27. #ifndef isascii
  28. #define isascii(c) 1
  29. #endif
  30.  
  31. #ifdef EMX09D
  32. #define ISALNUM(c)  (isascii ((int) (c)) && isalnum((int) (c)))
  33. #define ISALPHA(c)  (isascii ((int) (c)) && isalpha((int) (c)))
  34. #define ISASCII isascii
  35. #define ISCNTRL(c)  (isascii ((int) (c)) && iscntrl((int) (c)))
  36. #define ISDIGIT(c)  (isascii ((int) (c)) && isdigit((int) (c)))
  37. #define ISGRAPH(c)  (isascii ((int) (c)) && isgraph((int) (c)))
  38. #define ISLOWER(c)  (isascii ((int) (c)) && islower((int) (c)))
  39. #define ISPRINT(c)  (isascii ((int) (c)) && isprint((int) (c)))
  40. #define ISPUNCT(c)  (isascii ((int) (c)) && ispunct((int) (c)))
  41. #define ISSPACE(c)  (isascii ((int) (c)) && isspace((int) (c)))
  42. #define ISUPPER(c)  (isascii ((int) (c)) && isupper((int) (c)))
  43. #define ISXDIGIT(c) (isascii ((int) (c)) && isxdigit((int) (c)))
  44. #define TOASCII toascii
  45. #define TOLOWER(c)  (ISUPPER ((int) (c)) ? tolower ((int) (c)) : (c))
  46. #define TOUPPER(c)  (ISLOWER ((int) (c)) ? toupper ((int) (c)) : (c))
  47. #else
  48. #define ISALNUM(c) (isascii (c) && isalnum(c))
  49. #define ISALPHA(c) (isascii (c) && isalpha(c))
  50. #define ISASCII isascii
  51. #define ISCNTRL(c) (isascii (c) && iscntrl(c))
  52. #define ISDIGIT(c) (isascii (c) && isdigit (c))
  53. #define ISGRAPH(c) (isascii (c) && isgraph(c))
  54. #define ISLOWER(c) (isascii (c) && islower(c))
  55. #define ISPRINT(c) (isascii (c) && isprint(c))
  56. #define ISPUNCT(c) (isascii (c) && ispunct(c))
  57. #define ISSPACE(c) (isascii (c) && isspace(c))
  58. #define ISUPPER(c) (isascii (c) && isupper(c))
  59. #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
  60. #define TOASCII toascii
  61. #define TOLOWER(c) (ISUPPER (c) ? tolower (c) : (c))
  62. #define TOUPPER(c) (ISLOWER (c) ? toupper (c) : (c))
  63. #endif
  64.  
  65. /* This isn't part of the usual <ctype.h>, but it's useful sometimes.  */
  66. #ifndef isblank
  67. #define isblank(c) ((c) == ' ' || (c) == '\t')
  68. #endif
  69.  
  70.  
  71. /* Here's why this mess is necessary:
  72.  
  73. From: meyering@cs.utexas.edu (Jim Meyering)
  74. Date: Wed, 25 Nov 1992 09:52:33 -0600
  75. Subject: ss-921123: using isascii with <ctype.h> macros
  76.  
  77.   Yesterday some cursory regression testing found that GNU od
  78.   (in an upcoming release of textutils) generated incorrect output
  79.   when run on an SGI indigo because isprint ('\377') returned true.
  80.   Of course, '\377' is not a printing character;  the problem lay
  81.   in using isprint without first making sure its integer argument
  82.   corresponded to an ascii code.
  83.  
  84.   MORAL: always guard uses of ctype macros with isascii if it's available.
  85.   An obvious alternative is to avoid <ctype.h> and define and use your
  86.   own versions of the ctype macros.
  87.  
  88.   A pretty clean approach to using <ctype.h> and isascii was
  89.   suggested by David MacKenzie:
  90.  
  91.   #ifndef isascii
  92.   #define isascii(c) 1
  93.   #endif
  94.  
  95.   #define ISDIGIT(c) (isascii (c) && isdigit (c))
  96.   #define ISPRINT(c) (isascii (c) && isprint (c))
  97.   ...
  98.  
  99.   then, use ISDIGIT, etc. instead of isdigit, etc.  */
  100.   
  101. #endif /* not KPATHSEA_C_CTYPE_H */
  102.