+/* Store a multibyte character in three contiguous bytes starting
+ DESTINATION, and increment DESTINATION to the byte after where the
+ character is stored. Therefore, DESTINATION must be an lvalue. */
+
+#define STORE_CHARACTER_AND_INCR(destination, character) \
+ do { \
+ (destination)[0] = (character) & 0377; \
+ (destination)[1] = ((character) >> 8) & 0377; \
+ (destination)[2] = (character) >> 16; \
+ (destination) += 3; \
+ } while (0)
+
+/* Put into DESTINATION a character stored in three contiguous bytes
+ starting at SOURCE. */
+
+#define EXTRACT_CHARACTER(destination, source) \
+ do { \
+ (destination) = ((source)[0] \
+ | ((source)[1] << 8) \
+ | ((source)[2] << 16)); \
+ } while (0)
+
+
+/* Macros for charset. */
+
+/* Size of bitmap of charset P in bytes. P is a start of charset,
+ i.e. *P is (re_opcode_t) charset or (re_opcode_t) charset_not. */
+#define CHARSET_BITMAP_SIZE(p) ((p)[1] & 0x7F)
+
+/* Nonzero if charset P has range table. */
+#define CHARSET_RANGE_TABLE_EXISTS_P(p) ((p)[1] & 0x80)
+
+/* Return the address of range table of charset P. But not the start
+ of table itself, but the before where the number of ranges is
+ stored. `2 +' means to skip re_opcode_t and size of bitmap. */
+#define CHARSET_RANGE_TABLE(p) (&(p)[2 + CHARSET_BITMAP_SIZE (p)])
+
+/* Test if C is listed in the bitmap of charset P. */
+#define CHARSET_LOOKUP_BITMAP(p, c) \
+ ((c) < CHARSET_BITMAP_SIZE (p) * BYTEWIDTH \
+ && (p)[2 + (c) / BYTEWIDTH] & (1 << ((c) % BYTEWIDTH)))
+
+/* Return the address of end of RANGE_TABLE. COUNT is number of
+ ranges (which is a pair of (start, end)) in the RANGE_TABLE. `* 2'
+ is start of range and end of range. `* 3' is size of each start
+ and end. */
+#define CHARSET_RANGE_TABLE_END(range_table, count) \
+ ((range_table) + (count) * 2 * 3)
+
+/* Test if C is in RANGE_TABLE. A flag NOT is negated if C is in.
+ COUNT is number of ranges in RANGE_TABLE. */
+#define CHARSET_LOOKUP_RANGE_TABLE_RAW(not, c, range_table, count) \
+ do \
+ { \
+ int range_start, range_end; \
+ unsigned char *p; \
+ unsigned char *range_table_end \
+ = CHARSET_RANGE_TABLE_END ((range_table), (count)); \
+ \
+ for (p = (range_table); p < range_table_end; p += 2 * 3) \
+ { \
+ EXTRACT_CHARACTER (range_start, p); \
+ EXTRACT_CHARACTER (range_end, p + 3); \
+ \
+ if (range_start <= (c) && (c) <= range_end) \
+ { \
+ (not) = !(not); \
+ break; \
+ } \
+ } \
+ } \
+ while (0)
+
+/* Test if C is in range table of CHARSET. The flag NOT is negated if
+ C is listed in it. */
+#define CHARSET_LOOKUP_RANGE_TABLE(not, c, charset) \
+ do \
+ { \
+ /* Number of ranges in range table. */ \
+ int count; \
+ unsigned char *range_table = CHARSET_RANGE_TABLE (charset); \
+ \
+ EXTRACT_NUMBER_AND_INCR (count, range_table); \
+ CHARSET_LOOKUP_RANGE_TABLE_RAW ((not), (c), range_table, count); \
+ } \
+ while (0)
+\f