Blame ctype/test_ctype.c

Packit 6c4009
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <limits.h>
Packit 6c4009
#include <ctype.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
Packit 6c4009
#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
Packit 6c4009
#define XOR(e,f) (((e) && !(f)) || (!(e) && (f)))
Packit 6c4009
Packit 6c4009
#ifdef	__GNUC__
Packit 6c4009
__inline
Packit 6c4009
#endif
Packit 6c4009
static void
Packit 6c4009
print_char (unsigned char c)
Packit 6c4009
{
Packit 6c4009
  printf("%d/", (int) c);
Packit 6c4009
  if (isgraph(c))
Packit 6c4009
    printf("'%c'", c);
Packit 6c4009
  else
Packit 6c4009
    printf("'\\%.3o'", c);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (int argc, char **argv)
Packit 6c4009
{
Packit 6c4009
  unsigned short int c;
Packit 6c4009
  int lose = 0;
Packit 6c4009
Packit 6c4009
#define TRYEM do {							      \
Packit 6c4009
      TRY (isascii);							      \
Packit 6c4009
      TRY (isalnum);							      \
Packit 6c4009
      TRY (isalpha);							      \
Packit 6c4009
      TRY (iscntrl);							      \
Packit 6c4009
      TRY (isdigit);							      \
Packit 6c4009
      TRY (isgraph);							      \
Packit 6c4009
      TRY (islower);							      \
Packit 6c4009
      TRY (isprint);							      \
Packit 6c4009
      TRY (ispunct);							      \
Packit 6c4009
      TRY (isspace);							      \
Packit 6c4009
      TRY (isupper);							      \
Packit 6c4009
      TRY (isxdigit);							      \
Packit 6c4009
      TRY (isblank);							      \
Packit 6c4009
    } while (0)
Packit 6c4009
Packit 6c4009
  for (c = 0; c <= UCHAR_MAX; ++c)
Packit 6c4009
    {
Packit 6c4009
      print_char (c);
Packit 6c4009
Packit 6c4009
      if (XOR (islower (c), ISLOWER (c)) || toupper (c) != TOUPPER (c))
Packit 6c4009
	{
Packit 6c4009
	  fputs (" BOGUS", stdout);
Packit 6c4009
	  ++lose;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
#define TRY(isfoo) if (isfoo (c)) fputs (" " #isfoo, stdout)
Packit 6c4009
      TRYEM;
Packit 6c4009
#undef TRY
Packit 6c4009
Packit 6c4009
      fputs("; lower = ", stdout);
Packit 6c4009
      print_char(tolower(c));
Packit 6c4009
      fputs("; upper = ", stdout);
Packit 6c4009
      print_char(toupper(c));
Packit 6c4009
      putchar('\n');
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  fputs ("EOF", stdout);
Packit 6c4009
  if (tolower (EOF) != EOF)
Packit 6c4009
    {
Packit 6c4009
      ++lose;
Packit 6c4009
      printf (" tolower BOGUS %d;", tolower (EOF));
Packit 6c4009
    }
Packit 6c4009
  if (toupper (EOF) != EOF)
Packit 6c4009
    {
Packit 6c4009
      ++lose;
Packit 6c4009
      printf (" toupper BOGUS %d;", toupper (EOF));
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
#define TRY(isfoo) if (isfoo (EOF)) fputs (" " #isfoo, stdout), ++lose
Packit 6c4009
  TRYEM;
Packit 6c4009
#undef TRY
Packit 6c4009
Packit 6c4009
  return lose ? EXIT_FAILURE : EXIT_SUCCESS;
Packit 6c4009
}