summaryrefslogtreecommitdiff
path: root/include/ctype.h
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-05-06 07:37:32 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-05-06 07:37:32 +0000
commitd07fdf8b9ece2c4339b325921add50792077bf97 (patch)
treeb0886656bdd854728f2d1c05597368c4739ecc1b /include/ctype.h
parent7f09a14cabbec158d683542e53f53ccfe75031fa (diff)
New locale support (in development). Supports LC_CTYPE, LC_NUMERIC,
LC_TIME, LC_MONETARY, and LC_MESSAGES for the SUSv3 items. Also, nl_langinfo() when real locale support is enabled. New implementation of ctype.h. New implementation of wctype.h. New implementation of most of the string functions (smaller). New implementation of the wcs/wmem functions. These are untested, but they're also just preprocessor-modified versions ot the corresponding str/mem functions. Tweaked qsort and new bsearch. Stuff still pending: stdlib.h and wchar.h mb<->wc functions. I actually have working versions of the stdlib ones, but the reentrant versions from wchar.h require some reworking. Basic replacement and translit support for wc->mb conversions. (groundwork laid). Simple-minded collate support such as was provided by the previous locale implementation. (mostly done -- 8-bit codesets only) Shared mmaping of the locale data and strerror message text.
Diffstat (limited to 'include/ctype.h')
-rw-r--r--include/ctype.h176
1 files changed, 110 insertions, 66 deletions
diff --git a/include/ctype.h b/include/ctype.h
index a7e397e3d..c39bd3ccd 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -1,82 +1,126 @@
-/* vi: set sw=4 ts=4: */
-/*
- * ctype.h
- * Character classification and conversion
+/* Copyright (C) 2002 Manuel Novoa III
*
- * Copyright (C) 2000 by Lineo, inc.
- * Copyright (C) 2000,2001 Erik Andersen <andersee@debian.org>
+ * This 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.
*
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This 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 this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#ifndef __CTYPE_H
-#define __CTYPE_H
+/* NOTE: It is assumed here and throughout the library that the underlying
+ * char encoding for the portable C character set is ASCII (host & target). */
+
+#ifndef _CTYPE_H
+#define _CTYPE_H
#include <features.h>
+#include <bits/uClibc_ctype.h>
__BEGIN_DECLS
+extern int isalnum(int c) __THROW;
+extern int isalpha(int c) __THROW;
+#ifdef __USE_ISOC99
+extern int isblank(int c) __THROW;
+#endif
+extern int iscntrl(int c) __THROW;
+extern int isdigit(int c) __THROW;
+extern int isgraph(int c) __THROW;
+extern int islower(int c) __THROW;
+extern int isprint(int c) __THROW;
+extern int ispunct(int c) __THROW;
+extern int isspace(int c) __THROW;
+extern int isupper(int c) __THROW;
+extern int isxdigit(int c) __THROW;
-/* function prototpes */
-extern int isalnum(int c);
-extern int isalpha(int c);
-extern int isascii(int c);
-extern int isblank(int c);
-extern int iscntrl(int c);
-extern int isdigit(int c);
-extern int isgraph(int c);
-extern int islower(int c);
-extern int isprint(int c);
-extern int ispunct(int c);
-extern int isspace(int c);
-extern int isupper(int c);
-extern int isxdigit(int c);
-extern int isxlower(int c);
-extern int isxupper(int c);
-extern int toascii(int c);
-extern int tolower(int c);
-extern int toupper(int c);
-
-
-/* Locale-compatible macros/inlines have yet to be implemented. */
-#if defined(__USE_CTYPE_MACROS) && !defined __UCLIBC_HAS_LOCALE__
-
-/* macro definitions */
-#define isalnum(c) (isalpha(c) || isdigit(c))
-#define isalpha(c) (isupper(c) || islower(c))
-#define isascii(c) (c > 0 && c <= 0x7f)
-#define isblank(c) (c == ' ' || c == '\t')
-#define iscntrl(c) ((c >= 0) && ((c <= 0x1F) || (c == 0x7f)))
-#define isdigit(c) (c >= '0' && c <= '9')
-#define isgraph(c) (c != ' ' && isprint(c))
-#define islower(c) (c >= 'a' && c <= 'z')
-#define isprint(c) (c >= ' ' && c <= '~')
-#define ispunct(c) ((c > ' ' && c <= '~') && !isalnum(c))
-#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\
- c == '\t' || c == '\v')
-#define isupper(c) (c >= 'A' && c <= 'Z')
-#define isxdigit(c) (isxupper(c) || isxlower(c))
-#define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
-#define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
-#define toascii(c) (c & 0x7f)
-#define tolower(c) (isupper(c) ? ( c - 'A' + 'a') : (c))
-#define toupper(c) (islower(c) ? (c - 'a' + 'A') : (c))
+extern int tolower(int c) __THROW;
+extern int toupper(int c) __THROW;
+#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
+extern int isascii(int c) __THROW;
+extern int toascii(int c) __THROW;
#endif
+/* The following are included for compatibility with older versions of
+ * uClibc; but now they're only visible if MISC funcctionality is requested.
+ * However, as they are locale-independent, the hidden macro versions are
+ * always present. */
+#ifdef __USE_MISC
+extern int isxlower(int c) __THROW; /* uClibc-specific. */
+extern int isxupper(int c) __THROW; /* uClibc-specific. */
+#endif
+
+/* Next, some ctype macros which are valid for all supported locales. */
+/* WARNING: isspace and isblank need to be reverified if more 8-bit codesets
+ * are added!!! But isdigit and isxdigit are always valid. */
+
+#define __isspace(c) __C_isspace(c)
+#define __isblank(c) __C_isblank(c)
+
+#define __isdigit(c) __C_isdigit(c)
+#define __isxdigit(c) __C_isxdigit(c)
+
+/* Now some non-ansi/iso c99 macros. */
+
+#define __isascii(c) (((unsigned int)(c)) <= 0x7f)
+#define __toascii(c) ((c) & 0x7f)
+
+#define _toupper(c) ((c) | 0x20)
+#define _tolower(c) ((c) ^ 0x20)
+
+/* For compatibility with older versions of uClibc. Are these ever used? */
+#define __isxlower(c) __C_isxlower(c) /* uClibc-specific. */
+#define __isxupper(c) __C_isxupper(c) /* uClibc-specific. */
+
+/* Apparently, glibc implements things as macros if __NO_CTYPE isn't defined.
+ * If we don't have locale support, we'll do the same. Otherwise, we'll
+ * only use macros for the supported-locale-invariant cases. */
+#ifndef __NO_CTYPE
+
+#define isdigit(c) __isdigit(c)
+#define isxdigit(c) __isxdigit(c)
+#define isspace(c) __isspace(c)
+#ifdef __USE_ISOC99
+#define isblank(c) __isblank(c)
+#endif
+
+#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
+#define isascii(c) __isascii(c)
+#define toascii(c) __toascii(c)
+#endif
+
+#ifdef __USE_MISC
+#define isxlower(c) __C_isxlower(c) /* uClibc-specific. */
+#define isxupper(c) __C_isxupper(c) /* uClibc-specific. */
+#endif
+
+/* TODO - Should test for 8-bit codesets instead, but currently impossible. */
+#ifndef __UCLIBC_HAS_LOCALE__
+
+#define isalnum(c) __C_isalnum(c)
+#define isalpha(c) __C_isalpha(c)
+#define iscntrl(c) __C_iscntrl(c)
+#define isgraph(c) __C_isgraph(c)
+#define islower(c) __C_islower(c)
+#define isprint(c) __C_isprint(c)
+#define ispunct(c) __C_ispunct(c)
+#define isupper(c) __C_isupper(c)
+
+#define tolower(c) __C_tolower(c)
+#define toupper(c) __C_toupper(c)
+
+#endif /* __UCLIBC_HAS_LOCALE__ */
+
+#endif /* __NO_CTYPE */
+
__END_DECLS
-#endif /* __CTYPE_H */
+#endif /* _CTYPE_H */