diff options
author | Roland McGrath <roland@gnu.org> | 1995-02-18 01:27:10 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1995-02-18 01:27:10 +0000 |
commit | 28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch) | |
tree | 15f07c4c43d635959c6afee96bde71fb1b3614ee /ctype | |
download | glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.zip glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.gz glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.bz2 |
initial import
Diffstat (limited to 'ctype')
-rw-r--r-- | ctype/Makefile | 29 | ||||
-rw-r--r-- | ctype/ctype-extn.c | 32 | ||||
-rw-r--r-- | ctype/ctype-info.c | 30 | ||||
-rw-r--r-- | ctype/ctype.c | 51 | ||||
-rw-r--r-- | ctype/ctype.h | 152 | ||||
-rw-r--r-- | ctype/test_ctype.c | 92 |
6 files changed, 386 insertions, 0 deletions
diff --git a/ctype/Makefile b/ctype/Makefile new file mode 100644 index 0000000..21dfc8e --- /dev/null +++ b/ctype/Makefile @@ -0,0 +1,29 @@ +# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. + +# You should have received a copy of the GNU Library General Public +# License along with the GNU C Library; see the file COPYING.LIB. If +# not, write to the Free Software Foundation, Inc., 675 Mass Ave, +# Cambridge, MA 02139, USA. + +# +# Sub-makefile for ctype portion of the library. +# +subdir := ctype + +routines := ctype ctype-extn +aux := ctype-info + +tests := test_ctype + +include ../Rules diff --git a/ctype/ctype-extn.c b/ctype/ctype-extn.c new file mode 100644 index 0000000..ccf5552 --- /dev/null +++ b/ctype/ctype-extn.c @@ -0,0 +1,32 @@ +/* Copyright (C) 1991 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <ansidecl.h> + +#define __NO_CTYPE +#include <ctype.h> + +/* Real function versions of the non-ANSI ctype functions. */ + +int DEFUN(isblank, (c), int c) { return __isctype ((c), _ISblank); } + +int DEFUN(_tolower, (c), int c) { return __tolower(c); } +int DEFUN(_toupper, (c), int c) { return __toupper(c); } + +int DEFUN(toascii, (c), int c) { return __toascii(c); } +int DEFUN(isascii, (c), int c) { return __isascii(c); } diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c new file mode 100644 index 0000000..2a1e596 --- /dev/null +++ b/ctype/ctype-info.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <ansidecl.h> +#include <ctype.h> +#include <localeinfo.h> + +/* Defined in locale/locale-C-ct.c. */ +extern CONST unsigned short int __ctype_b_C[]; +extern CONST short int __ctype_tolower_C[]; +extern CONST short int __ctype_toupper_C[]; + +CONST unsigned short int *__ctype_b = __ctype_b_C + 1; +CONST short int *__ctype_tolower = __ctype_tolower_C + 1; +CONST short int *__ctype_toupper = __ctype_toupper_C + 1; diff --git a/ctype/ctype.c b/ctype/ctype.c new file mode 100644 index 0000000..ee874de --- /dev/null +++ b/ctype/ctype.c @@ -0,0 +1,51 @@ +/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <ansidecl.h> + +#define __NO_CTYPE +#include <ctype.h> + +/* Provide real-function versions of all the ctype macros. */ + +#define func(name, type) \ + int DEFUN(name, (c), int c) { return __isctype(c, type); } + +func(isalnum, _ISalnum) +func(isalpha, _ISalpha) +func(iscntrl, _IScntrl) +func(isdigit, _ISdigit) +func(islower, _ISlower) +func(isgraph, _ISgraph) +func(isprint, _ISprint) +func(ispunct, _ISpunct) +func(isspace, _ISspace) +func(isupper, _ISupper) +func(isxdigit, _ISxdigit) + +int +DEFUN(tolower, (c), int c) +{ + return __tolower (c); +} + +int +DEFUN(toupper, (c), int c) +{ + return __toupper (c); +} diff --git a/ctype/ctype.h b/ctype/ctype.h new file mode 100644 index 0000000..0f35d2a --- /dev/null +++ b/ctype/ctype.h @@ -0,0 +1,152 @@ +/* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* + * ANSI Standard 4.3: CHARACTER HANDLING <ctype.h> + */ + +#ifndef _CTYPE_H + +#define _CTYPE_H 1 +#include <features.h> + +__BEGIN_DECLS + +/* These are all the characteristics of characters. All the + interdependencies (such as that an alphabetic is an uppercase or a + lowercase) are here. If there get to be more than + (sizeof (unsigned short int) * CHAR_BIT) distinct characteristics, + many things must be changed that use `unsigned short int's. */ +enum +{ + _ISupper = 1 << 0, /* UPPERCASE. */ + _ISlower = 1 << 1, /* lowercase. */ + _IScntrl = 1 << 2, /* Control character. */ + _ISdigit = 1 << 3, /* Numeric. */ + _ISspace = 1 << 4, /* Whitespace. */ + _IShex = 1 << 5, /* A - F, a - f. */ + _ISpunct = 1 << 6, /* Punctuation. */ + _NOgraph = 1 << 7, /* Printing but nongraphical. */ + _ISblank = 1 << 8, /* Blank (usually SPC and TAB). */ + _ISalpha = 1 << 9, /* Alphabetic. */ + _ISalnum = _ISalpha | _ISdigit, /* Alphanumeric. */ + _ISxdigit = _ISdigit | _IShex, /* Hexadecimal numeric. */ + _ISgraph = _ISalnum | _ISpunct, /* Graphical. */ + _ISprint = _ISgraph | _NOgraph /* Printing. */ +}; + +/* These are defined in localeinfo.c. + The declarations here must match those in localeinfo.h. + + These point to the second element ([1]) of arrays of size (UCHAR_MAX + 1). + EOF is -1, so [EOF] is the first element of the original array. + ANSI requires that the ctype functions work for `unsigned char' values + and for EOF. The case conversion arrays are of `short int's rather than + `unsigned char's because tolower (EOF) must be EOF, which doesn't fit + into an `unsigned char'. */ +extern __const unsigned short int *__ctype_b; /* Characteristics. */ +extern __const short int *__ctype_tolower; /* Case conversions. */ +extern __const short int *__ctype_toupper; /* Case conversions. */ + +#define __isctype(c, type) \ + (__ctype_b[(int) (c)] & (unsigned short int) type) + +#define __isascii(c) (((c) & (1 << 7)) == 0) /* If high bit is set. */ +#define __toascii(c) ((c) & 0x7f) /* Mask off high bit. */ + +#define __tolower(c) ((int) __ctype_tolower[(int) (c)]) +#define __toupper(c) ((int) __ctype_toupper[(int) (c)]) + +#define __exctype(name) extern int name __P ((int)) + +/* The following names are all functions: + int isCHARACTERISTIC(int c); + which return nonzero iff C has CHARACTERISTIC. + For the meaning of the characteristic names, see the `enum' above. */ +__exctype (isalnum); +__exctype (isalpha); +__exctype (iscntrl); +__exctype (isdigit); +__exctype (islower); +__exctype (isgraph); +__exctype (isprint); +__exctype (ispunct); +__exctype (isspace); +__exctype (isupper); +__exctype (isxdigit); + +#ifdef __USE_GNU +__exctype (isblank); +#endif + + +/* Return the lowercase version of C. */ +extern int tolower __P ((int __c)); + +/* Return the uppercase version of C. */ +extern int toupper __P ((int __c)); + + +#if defined(__USE_SVID) || defined(__USE_MISC) + +/* Return nonzero iff C is in the ASCII set + (i.e., is no more than 7 bits wide). */ +extern int isascii __P ((int __c)); + +/* Return the part of C that is in the ASCII set + (i.e., the low-order 7 bits of C). */ +extern int toascii __P ((int __c)); + +#endif /* Use SVID or use misc. */ + +#ifdef __USE_SVID +/* These are the same as `toupper' and and `tolower'. */ +__exctype (_toupper); +__exctype (_tolower); +#endif + +#ifndef __NO_CTYPE +#define isalnum(c) __isctype((c), _ISalnum) +#define isalpha(c) __isctype((c), _ISalpha) +#define iscntrl(c) __isctype((c), _IScntrl) +#define isdigit(c) __isctype((c), _ISdigit) +#define islower(c) __isctype((c), _ISlower) +#define isgraph(c) __isctype((c), _ISgraph) +#define isprint(c) __isctype((c), _ISprint) +#define ispunct(c) __isctype((c), _ISpunct) +#define isspace(c) __isctype((c), _ISspace) +#define isupper(c) __isctype((c), _ISupper) +#define isxdigit(c) __isctype((c), _ISxdigit) + +#ifdef __USE_GNU +#define isblank(c) __isctype((c), _ISblank) +#endif + +#define tolower(c) __tolower(c) +#define toupper(c) __toupper(c) + +#if defined(__USE_SVID) || defined(__USE_MISC) +#define isascii(c) __isascii(c) +#define toascii(c) __toascii(c) +#endif + +#endif /* Not __NO_CTYPE. */ + +__END_DECLS + +#endif /* ctype.h */ diff --git a/ctype/test_ctype.c b/ctype/test_ctype.c new file mode 100644 index 0000000..622e5bf --- /dev/null +++ b/ctype/test_ctype.c @@ -0,0 +1,92 @@ +/* Copyright (C) 1991, 1994 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include <ansidecl.h> +#include <limits.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> + +#define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#define XOR(e,f) (((e) && !(f)) || (!(e) && (f))) + +#ifdef __GNUC__ +__inline +#endif +static void +DEFUN(print_char, (c), unsigned char c) +{ + printf("%d/", (int) c); + if (isgraph(c)) + printf("'%c'", c); + else + printf("'\\%.3o'", c); +} + +int +DEFUN(main, (argc, argv), int argc AND char **argv) +{ + register unsigned short int c; + int lose = 0; + + for (c = 0; c <= UCHAR_MAX; ++c) + { + print_char (c); + + if (XOR (islower (c), ISLOWER (c)) || toupper (c) != TOUPPER (c)) + { + fputs (" BOGUS", stdout); + ++lose; + } + + if (isascii(c)) + fputs(" isascii", stdout); + if (isalnum(c)) + fputs(" isalnum", stdout); + if (isalpha(c)) + fputs(" isalpha", stdout); + if (iscntrl(c)) + fputs(" iscntrl", stdout); + if (isdigit(c)) + fputs(" isdigit", stdout); + if (isgraph(c)) + fputs(" isgraph", stdout); + if (islower(c)) + fputs(" islower", stdout); + if (isprint(c)) + fputs(" isprint", stdout); + if (ispunct(c)) + fputs(" ispunct", stdout); + if (isspace(c)) + fputs(" isspace", stdout); + if (isupper(c)) + fputs(" isupper", stdout); + if (isxdigit(c)) + fputs(" isxdigit", stdout); + if (isblank(c)) + fputs(" isblank", stdout); + fputs("; lower = ", stdout); + print_char(tolower(c)); + fputs("; upper = ", stdout); + print_char(toupper(c)); + putchar('\n'); + } + + exit (lose ? EXIT_FAILURE : EXIT_SUCCESS); +} |