comparison src/charset.h @ 20531:f019e056ad9a

(CHAR_HEAD_P): Take char, not pointer, as arg. (INC_POS, DEC_POS): Fix because arg is a bufpos. (BUF_INC_POS, BUF_DEC_POS): New macros. (INC_BOTH, DEC_BOTH): New macros.
author Richard M. Stallman <rms@gnu.org>
date Wed, 31 Dec 1997 21:49:31 +0000
parents e9b5f67264cc
children 3acb053e757e
comparison
equal deleted inserted replaced
20530:88d7475304df 20531:f019e056ad9a
132 extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */ 132 extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */
133 extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */ 133 extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */
134 extern int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */ 134 extern int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */
135 extern int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */ 135 extern int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */
136 136
137 /* Check if STR points the head of multi-byte form, i.e. *STR is an 137 /* Check if CH is the head of multi-byte form, i.e.,
138 ASCII character or a base leading-code. */ 138 an ASCII character or a base leading-code. */
139 #define CHAR_HEAD_P(str) ((unsigned char) *(str) < 0xA0) 139 #define CHAR_HEAD_P(ch) ((unsigned char) (ch) < 0xA0)
140 140
141 /*** GENERAL NOTE on CHARACTER REPRESENTATION *** 141 /*** GENERAL NOTE on CHARACTER REPRESENTATION ***
142 142
143 At first, the term "character" or "char" is used for a multilingual 143 At first, the term "character" or "char" is used for a multilingual
144 character (of course, including ASCII character), not for a byte in 144 character (of course, including ASCII character), not for a byte in
597 character boundary. This macro relies on the fact that *GPT_ADDR 597 character boundary. This macro relies on the fact that *GPT_ADDR
598 and *Z_ADDR are always accessible and the values are '\0'. No 598 and *Z_ADDR are always accessible and the values are '\0'. No
599 range checking of POS. */ 599 range checking of POS. */
600 #define INC_POS(pos) \ 600 #define INC_POS(pos) \
601 do { \ 601 do { \
602 unsigned char *p = POS_ADDR (pos); \ 602 unsigned char *p = BYTE_POS_ADDR (pos); \
603 pos++; \ 603 pos++; \
604 if (*p++ >= 0x80) \ 604 if (*p++ >= 0x80) \
605 while (!CHAR_HEAD_P (p)) p++, pos++; \ 605 while (!CHAR_HEAD_P (*p)) p++, pos++; \
606 } while (0) 606 } while (0)
607 607
608 /* Decrease the buffer point POS of the current buffer to the previous 608 /* Decrease the buffer point POS of the current buffer to the previous
609 character boundary. No range checking of POS. */ 609 character boundary. No range checking of POS. */
610 #define DEC_POS(pos) \ 610 #define DEC_POS(pos) \
611 do { \ 611 do { \
612 unsigned char *p, *p_min; \ 612 unsigned char *p, *p_min; \
613 int pos_saved = --pos; \ 613 int pos_saved = --pos; \
614 if (pos < GPT) \ 614 if (pos < GPT_BYTE) \
615 p = BEG_ADDR + pos - 1, p_min = BEG_ADDR; \ 615 p = BEG_ADDR + pos - 1, p_min = BEG_ADDR; \
616 else \ 616 else \
617 p = BEG_ADDR + GAP_SIZE + pos - 1, p_min = GAP_END_ADDR; \ 617 p = BEG_ADDR + GAP_SIZE + pos - 1, p_min = GAP_END_ADDR; \
618 while (p > p_min && !CHAR_HEAD_P (p)) p--, pos--; \ 618 while (p > p_min && !CHAR_HEAD_P (*p)) p--, pos--; \
619 if (*p < 0x80 && pos != pos_saved) pos = pos_saved; \
620 } while (0)
621
622 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way. */
623
624 #define INC_BOTH(charpos, bytepos) \
625 do \
626 { \
627 (charpos)++; \
628 INC_POS ((bytepos)); \
629 } \
630 while (0)
631
632 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way. */
633
634 #define DEC_BOTH(charpos, bytepos) \
635 do \
636 { \
637 (charpos)--; \
638 DEC_POS ((bytepos)); \
639 } \
640 while (0)
641
642 /* Increase the buffer point POS of the current buffer to the next
643 character boundary. This macro relies on the fact that *GPT_ADDR
644 and *Z_ADDR are always accessible and the values are '\0'. No
645 range checking of POS. */
646 #define BUF_INC_POS(buf, pos) \
647 do { \
648 unsigned char *p = BUF_BYTE_ADDRESS (buf, pos); \
649 pos++; \
650 if (*p++ >= 0x80) \
651 while (!CHAR_HEAD_P (*p)) p++, pos++; \
652 } while (0)
653
654 /* Decrease the buffer point POS of the current buffer to the previous
655 character boundary. No range checking of POS. */
656 #define BUF_DEC_POS(buf, pos) \
657 do { \
658 unsigned char *p, *p_min; \
659 int pos_saved = --pos; \
660 if (pos < BUF_GPT_BYTE (buf)) \
661 { \
662 p = BUF_BEG_ADDR (buf) + pos - 1; \
663 p_min = BUF_BEG_ADDR (buf); \
664 } \
665 else \
666 { \
667 p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos - 1; \
668 p_min = BUF_GAP_END_ADDR (buf); \
669 } \
670 while (p > p_min && !CHAR_HEAD_P (*p)) p--, pos--; \
619 if (*p < 0x80 && pos != pos_saved) pos = pos_saved; \ 671 if (*p < 0x80 && pos != pos_saved) pos = pos_saved; \
620 } while (0) 672 } while (0)
621 673
622 #endif /* emacs */ 674 #endif /* emacs */
623 675