summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/bits
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-09-08 20:33:10 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-09-08 20:33:10 +0000
commitf2239854568a38296d1a632321c6fee97410692b (patch)
tree24f769283ecd09756812fd69a55b53f3feceb770 /libc/sysdeps/linux/common/bits
parentc9781f6b04ed346407c0462488d2a4c425b69230 (diff)
Add back in table-less ctype funcs for those interested in minimizing
static build sizes and not needing wchar support. Add in a SUSv3 getopt as an option for those not needing gnu getopt. Again, mainly for the static linking crowd.
Diffstat (limited to 'libc/sysdeps/linux/common/bits')
-rw-r--r--libc/sysdeps/linux/common/bits/getopt.h162
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_ctype.h278
2 files changed, 333 insertions, 107 deletions
diff --git a/libc/sysdeps/linux/common/bits/getopt.h b/libc/sysdeps/linux/common/bits/getopt.h
new file mode 100644
index 000000000..fd1cb7b15
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/getopt.h
@@ -0,0 +1,162 @@
+/* Declarations for getopt.
+ Copyright (C) 1989-1994, 1996-1999, 2001 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 Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _GETOPT_H
+
+#ifndef __need_getopt
+# define _GETOPT_H 1
+#endif
+
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+ for unrecognized options. */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int optopt;
+
+#ifndef __need_getopt
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of `struct option' terminated by an element containing a name which is
+ zero.
+
+ The field `has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field `flag' is not NULL, it points to a variable that is set
+ to the value given in the field `val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an `int' to
+ a compiled-in constant, such as set a value from `optarg', set the
+ option's `flag' field to zero and its `val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero `flag' field, `getopt'
+ returns the contents of the `val' field. */
+
+struct option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
+
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, `optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in `optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU `getopt'.
+
+ The argument `--' causes premature termination of argument
+ scanning, explicitly telling `getopt' that there are no more
+ options.
+
+ If OPTS begins with `--', then non-option arguments are treated as
+ arguments to the option '\0'. This behavior is specific to the GNU
+ `getopt'. */
+
+/* Many other libraries have conflicting prototypes for getopt, with
+ differences in the consts, in stdlib.h. To avoid compilation
+ errors, only prototype getopt for the GNU C library. */
+extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
+
+#ifndef __need_getopt
+extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+
+/* Internal only. Users should not call this directly. */
+extern int _getopt_internal (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
+#endif /* getopt.h */
diff --git a/libc/sysdeps/linux/common/bits/uClibc_ctype.h b/libc/sysdeps/linux/common/bits/uClibc_ctype.h
index 294997b74..f682d9762 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_ctype.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_ctype.h
@@ -33,7 +33,7 @@
#ifndef _BITS_CTYPE_H
#define _BITS_CTYPE_H
-#warning uClibc_ctype.h is deprecated
+#ifdef __UCLIBC_GEN_LOCALE
/* Taking advantage of the C99 mutual-exclusion guarantees for the various
* (w)ctype classes, including the descriptions of printing and control
@@ -80,72 +80,9 @@ enum {
/* #define __CTYPE_isxdigit(D) -- isxdigit is untestable this way.
* But that's ok as isxdigit() (and isdigit() too) are locale-invariant. */
-/* The values for wctype_t. */
-enum {
- _CTYPE_unclassified = 0,
- _CTYPE_isalnum,
- _CTYPE_isalpha,
- _CTYPE_isblank,
- _CTYPE_iscntrl,
- _CTYPE_isdigit,
- _CTYPE_isgraph,
- _CTYPE_islower,
- _CTYPE_isprint,
- _CTYPE_ispunct,
- _CTYPE_isspace,
- _CTYPE_isupper,
- _CTYPE_isxdigit /* _MUST_ be last of the standard classes! */
-};
-
-
-/* The following is used to implement wctype(), but it is defined
- * here because the ordering must agree with that of the enumeration
- * above (ignoring unclassified). */
-#define __CTYPE_TYPESTRING \
- "\6alnum\0\6alpha\0\6blank\0\6cntrl\0\6digit\0\6graph\0\6lower\0" \
- "\6print\0\6punct\0\6space\0\6upper\0\7xdigit\0\0"
-
-/* Used in implementing iswctype(), but defined here as it must agree
- * in ordering with the string above. */
-#define __CTYPE_RANGES \
- 0, -1, /* unclassified */ \
- 1, __CTYPE_digit - 1, /* alnum */ \
- 1, __CTYPE_alpha_upper - 1, /* alpha */ \
- __CTYPE_print_space_blank, 5, /* blank -- also must be odd! */ \
- __CTYPE_cntrl_space_nonblank, 2, /* cntrl */ \
- __CTYPE_digit, 0, /* digit */ \
- 1, __CTYPE_graph - 1, /* graph */ \
- __CTYPE_alpha_lower, 1, /* lower */ \
- 1, __CTYPE_print_space_blank - 1, /* print */ \
- __CTYPE_punct, 0, /* punct */ \
- __CTYPE_print_space_nonblank, 5, /* space */ \
- __CTYPE_alpha_upper_lower, 1, /* upper */ \
- /* No entry for xdigit as it is handled specially. */
-
-#define _CTYPE_iswalnum _CTYPE_isalnum
-#define _CTYPE_iswalpha _CTYPE_isalpha
-#define _CTYPE_iswblank _CTYPE_isblank
-#define _CTYPE_iswcntrl _CTYPE_iscntrl
-#define _CTYPE_iswdigit _CTYPE_isdigit
-#define _CTYPE_iswgraph _CTYPE_isgraph
-#define _CTYPE_iswlower _CTYPE_islower
-#define _CTYPE_iswprint _CTYPE_isprint
-#define _CTYPE_iswpunct _CTYPE_ispunct
-#define _CTYPE_iswspace _CTYPE_isspace
-#define _CTYPE_iswupper _CTYPE_isupper
-#define _CTYPE_iswxdigit _CTYPE_isxdigit
-
-/* The following is used to implement wctrans(). */
-
-enum {
- _CTYPE_tolower = 1,
- _CTYPE_toupper,
- _CTYPE_totitle
-};
+#else /* __UCLIBC_GEN_LOCALE *****************************************/
-#define __CTYPE_TRANSTRING "\10tolower\0\10toupper\0\10totitle\0\0"
-
-/* Now define some ctype macros valid for the C/POSIX locale. */
+/* Define some ctype macros valid for the C/POSIX locale. */
/* ASCII ords of \t, \f, \n, \r, and \v are 9, 12, 10, 13, 11 respectively. */
#define __C_isspace(c) \
@@ -207,46 +144,173 @@ enum {
? (((unsigned char)(((c)) - 'A')) < 6) \
: (((unsigned int)(((c)) - 'A')) < 6)))
-/* TODO: Replace the above with expressions like the following? */
-/* #define __C_isdigit(c) ((sizeof(c) == sizeof(char)) \ */
-/* ? (((unsigned char)((c) - '0')) < 10) \ */
-/* : (((unsigned int)((c) - '0')) < 10)) */
-
-/* Similarly, define some wctype macros valid for the C/POSIX locale. */
-
-/* First, we need some way to make sure the arg is in range. */
-#define __C_classed(c) \
- ((sizeof(c) <= sizeof(int)) || (c == ((unsigned char)c)))
-
-#define __C_iswspace(c) (__C_classed(c) && __C_isspace(c))
-#define __C_iswblank(c) (__C_classed(c) && __C_isblank(c))
-#define __C_iswdigit(c) (__C_classed(c) && __C_isdigit(c))
-#define __C_iswxdigit(c) (__C_classed(c) && __C_isxdigit(c))
-#define __C_iswcntrl(c) (__C_classed(c) && __C_iscntrl(c))
-#define __C_iswalpha(c) (__C_classed(c) && __C_isalpha(c))
-#define __C_iswalnum(c) (__C_classed(c) && __C_isalnum(c))
-#define __C_iswprint(c) (__C_classed(c) && __C_isprint(c))
-#define __C_iswlower(c) (__C_classed(c) && __C_islower(c))
-#define __C_iswupper(c) (__C_classed(c) && __C_isupper(c))
-#define __C_iswpunct(c) (__C_classed(c) && __C_ispunct(c))
-#define __C_iswgraph(c) (__C_classed(c) && __C_isgraph(c))
-#define __C_towlower(c) \
- ((__C_classed(c) && __C_isupper(c)) ? ((c) | 0x20) : (c))
-#define __C_towupper(c) \
- ((__C_classed(c) && __C_islower(c)) ? ((c) ^ 0x20) : (c))
-
-/* Now define some macros to aviod the extra wrapper-function call. */
-#define __iswalnum(c) iswctype(c, _CTYPE_iswalnum)
-#define __iswalpha(c) iswctype(c, _CTYPE_iswalpha)
-#define __iswblank(c) iswctype(c, _CTYPE_iswblank)
-#define __iswcntrl(c) iswctype(c, _CTYPE_iswcntrl)
-#define __iswgraph(c) iswctype(c, _CTYPE_iswgraph)
-#define __iswlower(c) iswctype(c, _CTYPE_iswlower)
-#define __iswprint(c) iswctype(c, _CTYPE_iswprint)
-#define __iswpunct(c) iswctype(c, _CTYPE_iswpunct)
-#define __iswspace(c) iswctype(c, _CTYPE_iswspace)
-#define __iswupper(c) iswctype(c, _CTYPE_iswupper)
-#define __iswdigit(c) __C_iswdigit(c)
-#define __iswxdigit(c) __C_iswxdigit(c)
+/**********************************************************************/
+__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;
+
+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. */
+
+/* isdigit() is really locale-invariant, so provide some small fast macros.
+ * These are uClibc-specific. */
+#define __isdigit_char(C) (((unsigned char)((C) - '0')) <= 9)
+#define __isdigit_int(C) (((unsigned int)((C) - '0')) <= 9)
+#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) (((c) & ~0x7f) == 0)
+#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? */
+#if 0
+#define __isxlower(c) __C_isxlower(c) /* uClibc-specific. */
+#define __isxupper(c) __C_isxupper(c) /* uClibc-specific. */
+#endif
+
+/* 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 __UCLIBC_HAS_LOCALE__
+
+#endif /* __UCLIBC_HAS_LOCALE__ */
+
+__END_DECLS
+
+/**********************************************************************/
+#ifdef __GNUC__
+
+#define __isbody_C_macro(f,args) __C_ ## f args
+
+#define __isbody(f,c) \
+ (__extension__ ({ \
+ int __res; \
+ if (sizeof(c) > sizeof(char)) { \
+ int __c = (c); \
+ __res = __isbody_C_macro(f,(__c)); \
+ } else { \
+ unsigned char __c = (c); \
+ __res = __isbody_C_macro(f,(__c)); \
+ } \
+ __res; \
+ }))
+
+#define __body_C_macro(f,args) __C_ ## f args
+
+#define __body(f,c) \
+ (__extension__ ({ \
+ int __res; \
+ if (sizeof(c) > sizeof(char)) { \
+ int __c = (c); \
+ __res = __body_C_macro(f,(__c)); \
+ } else { \
+ unsigned char __c = (c); \
+ __res = __body_C_macro(f,(__c)); \
+ } \
+ __res; \
+ }))
+
+#define __isspace(c) __body(isspace,c)
+#define __isblank(c) __body(isblank,c)
+#define __isdigit(c) __body(isdigit,c)
+#define __isxdigit(c) __body(isxdigit,c)
+#define __iscntrl(c) __body(iscntrl,c)
+#define __isalpha(c) __body(isalpha,c)
+#define __isalnum(c) __body(isalnum,c)
+#define __isprint(c) __body(isprint,c)
+#define __islower(c) __body(islower,c)
+#define __isupper(c) __body(isupper,c)
+#define __ispunct(c) __body(ispunct,c)
+#define __isgraph(c) __body(isgraph,c)
+
+#define __isxlower(c) __body(isxlower,c)
+#define __isxupper(c) __body(isxupper,c)
+
+#define __tolower(c) __body(tolower,c)
+#define __toupper(c) __body(toupper,c)
+
+#if !defined __NO_CTYPE && !defined __cplusplus
+
+#define isspace(c) __isspace(c)
+#define isblank(c) __isblank(c)
+#define isdigit(c) __isdigit(c)
+#define isxdigit(c) __isxdigit(c)
+#define iscntrl(c) __iscntrl(c)
+#define isalpha(c) __isalpha(c)
+#define isalnum(c) __isalnum(c)
+#define isprint(c) __isprint(c)
+#define islower(c) __islower(c)
+#define isupper(c) __isupper(c)
+#define ispunct(c) __ispunct(c)
+#define isgraph(c) __isgraph(c)
+
+#define isxlower(c) __isxlower(c)
+#define isxupper(c) __isxupper(c)
+
+#define tolower(c) __tolower(c)
+#define toupper(c) __toupper(c)
+
+
+#endif
+
+#else /* _GNUC__ ***************************************************/
+
+#if !defined __NO_CTYPE && !defined __cplusplus
+
+/* These macros should be safe from side effects. */
+
+#define isdigit(c) __C_isdigit(c)
+#define isalpha(c) __C_isalpha(c)
+#define isprint(c) __C_isprint(c)
+#define islower(c) __C_islower(c)
+#define isupper(c) __C_isupper(c)
+#define isgraph(c) __C_isgraph(c)
+
+#endif
+
+#endif /* __GNUC__ */
+/**********************************************************************/
+
+#endif /* __UCLIBC_GEN_LOCALE */
#endif /* _BITS_CTYPE_H */