chardefs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* chardefs.h -- Character definitions for readline. */
  2. /* Copyright (C) 1994-2015 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. #include <string.h>
  20. #ifndef whitespace
  21. #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  22. #endif
  23. #ifdef CTRL
  24. # undef CTRL
  25. #endif
  26. #ifdef UNCTRL
  27. # undef UNCTRL
  28. #endif
  29. /* Some character stuff. */
  30. #define control_character_threshold 0x020 /* Smaller than this is control. */
  31. #define control_character_mask 0x1f /* 0x20 - 1 */
  32. #define meta_character_threshold 0x07f /* Larger than this is Meta. */
  33. #define control_character_bit 0x40 /* 0x000000, must be off. */
  34. #define meta_character_bit 0x080 /* x0000000, must be on. */
  35. #define largest_char 255 /* Largest character value. */
  36. #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
  37. #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
  38. #define CTRL(c) ((c) & control_character_mask)
  39. #define META(c) ((c) | meta_character_bit)
  40. #define UNMETA(c) ((c) & (~meta_character_bit))
  41. #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
  42. #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
  43. # define IN_CTYPE_DOMAIN(c) 1
  44. #else
  45. # define IN_CTYPE_DOMAIN(c) isascii(c)
  46. #endif
  47. #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus)
  48. # define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
  49. #endif
  50. #if defined (CTYPE_NON_ASCII)
  51. # define NON_NEGATIVE(c) 1
  52. #else
  53. # define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
  54. #endif
  55. /* Some systems define these; we want our definitions. */
  56. #undef ISPRINT
  57. /* Beware: these only work with single-byte ASCII characters. */
  58. #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c))
  59. #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c))
  60. #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c))
  61. #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c))
  62. #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c))
  63. #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c))
  64. #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c))
  65. #define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
  66. #define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
  67. #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
  68. #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
  69. #define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c))
  70. #ifndef _rl_to_upper
  71. # define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
  72. # define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
  73. #endif
  74. #ifndef _rl_digit_value
  75. # define _rl_digit_value(x) ((x) - '0')
  76. #endif
  77. #ifndef _rl_isident
  78. # define _rl_isident(c) (ISALNUM(c) || (c) == '_')
  79. #endif
  80. #ifndef ISOCTAL
  81. # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
  82. #endif
  83. #define OCTVALUE(c) ((c) - '0')
  84. #define HEXVALUE(c) \
  85. (((c) >= 'a' && (c) <= 'f') \
  86. ? (c)-'a'+10 \
  87. : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
  88. #ifndef NEWLINE
  89. #define NEWLINE '\n'
  90. #endif
  91. #ifndef RETURN
  92. #define RETURN CTRL('M')
  93. #endif
  94. #ifndef RUBOUT
  95. #define RUBOUT 0x7f
  96. #endif
  97. #ifndef TAB
  98. #define TAB '\t'
  99. #endif
  100. #ifdef ABORT_CHAR
  101. #undef ABORT_CHAR
  102. #endif
  103. #define ABORT_CHAR CTRL('G')
  104. #ifdef PAGE
  105. #undef PAGE
  106. #endif
  107. #define PAGE CTRL('L')
  108. #ifdef SPACE
  109. #undef SPACE
  110. #endif
  111. #define SPACE ' ' /* XXX - was 0x20 */
  112. #ifdef ESC
  113. #undef ESC
  114. #endif
  115. #define ESC CTRL('[')
  116. #endif /* _CHARDEFS_H_ */