Back to index

glibc  2.9
test_ctype.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <limits.h>
00020 #include <ctype.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 
00024 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
00025 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
00026 #define XOR(e,f) (((e) && !(f)) || (!(e) && (f)))
00027 
00028 #ifdef __GNUC__
00029 __inline
00030 #endif
00031 static void
00032 print_char (unsigned char c)
00033 {
00034   printf("%d/", (int) c);
00035   if (isgraph(c))
00036     printf("'%c'", c);
00037   else
00038     printf("'\\%.3o'", c);
00039 }
00040 
00041 int
00042 main (int argc, char **argv)
00043 {
00044   unsigned short int c;
00045   int lose = 0;
00046 
00047 #define TRYEM do {                                                   \
00048       TRY (isascii);                                                 \
00049       TRY (isalnum);                                                 \
00050       TRY (isalpha);                                                 \
00051       TRY (iscntrl);                                                 \
00052       TRY (isdigit);                                                 \
00053       TRY (isgraph);                                                 \
00054       TRY (islower);                                                 \
00055       TRY (isprint);                                                 \
00056       TRY (ispunct);                                                 \
00057       TRY (isspace);                                                 \
00058       TRY (isupper);                                                 \
00059       TRY (isxdigit);                                                       \
00060       TRY (isblank);                                                 \
00061     } while (0)
00062 
00063   for (c = 0; c <= UCHAR_MAX; ++c)
00064     {
00065       print_char (c);
00066 
00067       if (XOR (islower (c), ISLOWER (c)) || toupper (c) != TOUPPER (c))
00068        {
00069          fputs (" BOGUS", stdout);
00070          ++lose;
00071        }
00072 
00073 #define TRY(isfoo) if (isfoo (c)) fputs (" " #isfoo, stdout)
00074       TRYEM;
00075 #undef TRY
00076 
00077       fputs("; lower = ", stdout);
00078       print_char(tolower(c));
00079       fputs("; upper = ", stdout);
00080       print_char(toupper(c));
00081       putchar('\n');
00082     }
00083 
00084   fputs ("EOF", stdout);
00085   if (tolower (EOF) != EOF)
00086     {
00087       ++lose;
00088       printf (" tolower BOGUS %d;", tolower (EOF));
00089     }
00090   if (toupper (EOF) != EOF)
00091     {
00092       ++lose;
00093       printf (" toupper BOGUS %d;", toupper (EOF));
00094     }
00095 
00096 #define TRY(isfoo) if (isfoo (EOF)) fputs (" " #isfoo, stdout), ++lose
00097   TRYEM;
00098 #undef TRY
00099 
00100   return lose ? EXIT_FAILURE : EXIT_SUCCESS;
00101 }