chardefs.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* chardefs.h -- Character definitions for readline. */
  2. /* Copyright (C) 1994-2009 Free Software Foundation, Inc.
  3. This file is part of the GNU Readline Library (Readline), a library
  4. for reading lines of text with interactive input and history editing.
  5. Readline is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Readline is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Readline. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef _CHARDEFS_H_
  17. #define _CHARDEFS_H_
  18. #include <ctype.h>
  19. #if defined (HAVE_CONFIG_H)
  20. # if defined (HAVE_STRING_H)
  21. # if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
  22. # include <memory.h>
  23. # endif
  24. # include <string.h>
  25. # endif /* HAVE_STRING_H */
  26. # if defined (HAVE_STRINGS_H)
  27. # include <strings.h>
  28. # endif /* HAVE_STRINGS_H */
  29. #else
  30. # include <string.h>
  31. #endif /* !HAVE_CONFIG_H */
  32. #ifndef whitespace
  33. #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  34. #endif
  35. #ifdef CTRL
  36. # undef CTRL
  37. #endif
  38. #ifdef UNCTRL
  39. # undef UNCTRL
  40. #endif
  41. /* Some character stuff. */
  42. #define control_character_threshold 0x020 /* Smaller than this is control. */
  43. #define control_character_mask 0x1f /* 0x20 - 1 */
  44. #define meta_character_threshold 0x07f /* Larger than this is Meta. */
  45. #define control_character_bit 0x40 /* 0x000000, must be off. */
  46. #define meta_character_bit 0x080 /* x0000000, must be on. */
  47. #define largest_char 255 /* Largest character value. */
  48. #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
  49. #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
  50. #define CTRL(c) ((c) & control_character_mask)
  51. #define META(c) ((c) | meta_character_bit)
  52. #define UNMETA(c) ((c) & (~meta_character_bit))
  53. #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
  54. #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
  55. # define IN_CTYPE_DOMAIN(c) 1
  56. #else
  57. # define IN_CTYPE_DOMAIN(c) isascii(c)
  58. #endif
  59. #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
  60. # define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
  61. #endif
  62. #if defined (CTYPE_NON_ASCII)
  63. # define NON_NEGATIVE(c) 1
  64. #else
  65. # define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
  66. #endif
  67. /* Some systems define these; we want our definitions. */
  68. #undef ISPRINT
  69. /* Beware: these only work with single-byte ASCII characters. */
  70. #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
  71. #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
  72. #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
  73. #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
  74. #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
  75. #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
  76. #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
  77. #define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
  78. #define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
  79. #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
  80. #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
  81. #define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c))
  82. #ifndef _rl_to_upper
  83. # define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
  84. # define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
  85. #endif
  86. #ifndef _rl_digit_value
  87. # define _rl_digit_value(x) ((x) - '0')
  88. #endif
  89. #ifndef _rl_isident
  90. # define _rl_isident(c) (ISALNUM(c) || (c) == '_')
  91. #endif
  92. #ifndef ISOCTAL
  93. # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
  94. #endif
  95. #define OCTVALUE(c) ((c) - '0')
  96. #define HEXVALUE(c) \
  97. (((c) >= 'a' && (c) <= 'f') \
  98. ? (c)-'a'+10 \
  99. : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
  100. #ifndef NEWLINE
  101. #define NEWLINE '\n'
  102. #endif
  103. #ifndef RETURN
  104. #define RETURN CTRL('M')
  105. #endif
  106. #ifndef RUBOUT
  107. #define RUBOUT 0x7f
  108. #endif
  109. #ifndef TAB
  110. #define TAB '\t'
  111. #endif
  112. #ifdef ABORT_CHAR
  113. #undef ABORT_CHAR
  114. #endif
  115. #define ABORT_CHAR CTRL('G')
  116. #ifdef PAGE
  117. #undef PAGE
  118. #endif
  119. #define PAGE CTRL('L')
  120. #ifdef SPACE
  121. #undef SPACE
  122. #endif
  123. #define SPACE ' ' /* XXX - was 0x20 */
  124. #ifdef ESC
  125. #undef ESC
  126. #endif
  127. #define ESC CTRL('[')
  128. #endif /* _CHARDEFS_H_ */