Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / lib / readline / chardefs.h
index 8c92811..a537be2 100644 (file)
@@ -7,7 +7,7 @@
 
    The GNU Readline Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU General Public License
-   as published by the Free Software Foundation; either version 1, or
+   as published by the Free Software Foundation; either version 2, or
    (at your option) any later version.
 
    The GNU Readline Library is distributed in the hope that it will be
    The GNU General Public License is often shipped with GNU software, and
    is generally kept in a file called COPYING or LICENSE.  If you do not
    have a copy of the license, write to the Free Software Foundation,
-   675 Mass Ave, Cambridge, MA 02139, USA. */
+   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
 
-#ifndef _CHARDEFS_H
-#define _CHARDEFS_H
+#ifndef _CHARDEFS_H_
+#define _CHARDEFS_H_
 
 #include <ctype.h>
 
-#if defined (HAVE_STRING_H)
-#  include <string.h>
+#if defined (HAVE_CONFIG_H)
+#  if defined (HAVE_STRING_H)
+#    if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
+#      include <memory.h>
+#    endif
+#    include <string.h>
+#  endif /* HAVE_STRING_H */
+#  if defined (HAVE_STRINGS_H)
+#    include <strings.h>
+#  endif /* HAVE_STRINGS_H */
 #else
-#  include <strings.h>
-#endif /* HAVE_STRING_H */
+#  include <string.h>
+#endif /* !HAVE_CONFIG_H */
 
 #ifndef whitespace
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
 #endif
 
 #ifdef CTRL
-#undef CTRL
+#  undef CTRL
+#endif
+#ifdef UNCTRL
+#  undef UNCTRL
 #endif
 
 /* Some character stuff. */
 #define meta_character_bit 0x080           /* x0000000, must be on. */
 #define largest_char 255                   /* Largest character value. */
 
-#define CTRL_CHAR(c) ((c) < control_character_threshold)
+#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
 
 #define CTRL(c) ((c) & control_character_mask)
 #define META(c) ((c) | meta_character_bit)
 
 #define UNMETA(c) ((c) & (~meta_character_bit))
-#define UNCTRL(c) to_upper(((c)|control_character_bit))
+#define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
+
+#if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
+#  define IN_CTYPE_DOMAIN(c) 1
+#else
+#  define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+
+#if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
+#  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
+#endif
 
-/* Old versions
-#define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
-#define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
-#define digit_p(c)  ((c) >= '0' && (c) <= '9')
-*/
+#define NON_NEGATIVE(c)        ((unsigned char)(c) == (c))
 
-#define lowercase_p(c) (islower(c))
-#define uppercase_p(c) (isupper(c))
-#define digit_p(x)  (isdigit (x))
+/* Some systems define these; we want our definitions. */
+#undef ISPRINT
 
-#define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c))
+#define ISALNUM(c)     (IN_CTYPE_DOMAIN (c) && isalnum (c))
+#define ISALPHA(c)     (IN_CTYPE_DOMAIN (c) && isalpha (c))
+#define ISDIGIT(c)     (IN_CTYPE_DOMAIN (c) && isdigit (c))
+#define ISLOWER(c)     (IN_CTYPE_DOMAIN (c) && islower (c))
+#define ISPRINT(c)     (IN_CTYPE_DOMAIN (c) && isprint (c))
+#define ISUPPER(c)     (IN_CTYPE_DOMAIN (c) && isupper (c))
+#define ISXDIGIT(c)    (IN_CTYPE_DOMAIN (c) && isxdigit (c))
 
-/* Old versions
-#  define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c))
-#  define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c))
-*/
+#define _rl_lowercase_p(c)     (NON_NEGATIVE(c) && ISLOWER(c))
+#define _rl_uppercase_p(c)     (NON_NEGATIVE(c) && ISUPPER(c))
+#define _rl_digit_p(c)         ((c) >= '0' && (c) <= '9')
 
-#ifndef to_upper
-#  define to_upper(c) (islower(c) ? toupper(c) : (c))
-#  define to_lower(c) (isupper(c) ? tolower(c) : (c))
+#define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
+#define ALPHABETIC(c)          (NON_NEGATIVE(c) && ISALNUM(c))
+
+#ifndef _rl_to_upper
+#  define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
+#  define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
+#endif
+
+#ifndef _rl_digit_value
+#  define _rl_digit_value(x) ((x) - '0')
 #endif
 
-#ifndef digit_value
-#define digit_value(x) ((x) - '0')
+#ifndef _rl_isident
+#  define _rl_isident(c) (ISALNUM(c) || (c) == '_')
 #endif
 
+#ifndef ISOCTAL
+#  define ISOCTAL(c)   ((c) >= '0' && (c) <= '7')
+#endif
+#define OCTVALUE(c)    ((c) - '0')
+
+#define HEXVALUE(c) \
+  (((c) >= 'a' && (c) <= 'f') \
+       ? (c)-'a'+10 \
+       : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
+
 #ifndef NEWLINE
 #define NEWLINE '\n'
 #endif
 #ifdef ESC
 #undef ESC
 #endif
-
 #define ESC CTRL('[')
 
-#endif  /* _CHARDEFS_H */
+#endif  /* _CHARDEFS_H_ */