Mercurial > hg > xemacs-beta
comparison src/chartab.c @ 104:cf808b4c4290 r20-1b4
Import from CVS: tag r20-1b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:16:51 +0200 |
parents | 131b0175ea99 |
children | fe104dbd9147 |
comparison
equal
deleted
inserted
replaced
103:30eda07fe280 | 104:cf808b4c4290 |
---|---|
27 | 27 |
28 /* Authorship: | 28 /* Authorship: |
29 | 29 |
30 Ben Wing: wrote, for 19.13 (Mule). Some category table stuff | 30 Ben Wing: wrote, for 19.13 (Mule). Some category table stuff |
31 loosely based on the original Mule. | 31 loosely based on the original Mule. |
32 Jareth Hein: fixed a couple of bugs in the implementation, and | |
33 added regex support for categories with check_category_at | |
32 */ | 34 */ |
33 | 35 |
34 #include <config.h> | 36 #include <config.h> |
35 #include "lisp.h" | 37 #include "lisp.h" |
36 | 38 |
784 return val; | 786 return val; |
785 } | 787 } |
786 | 788 |
787 #endif /* MULE */ | 789 #endif /* MULE */ |
788 | 790 |
789 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /* | 791 static Lisp_Object |
790 Find value for char CH in TABLE. | 792 get_char_table (Emchar ch, struct Lisp_Char_Table *ct) |
791 */ | 793 { |
792 (ch, table)) | |
793 { | |
794 struct Lisp_Char_Table *ct; | |
795 | |
796 CHECK_CHAR_TABLE (table); | |
797 ct = XCHAR_TABLE (table); | |
798 CHECK_CHAR_COERCE_INT (ch); | |
799 | |
800 #ifdef MULE | 794 #ifdef MULE |
801 { | 795 { |
802 Lisp_Object charset; | 796 Lisp_Object charset; |
803 int byte1, byte2; | 797 int byte1, byte2; |
804 Lisp_Object val; | 798 Lisp_Object val; |
805 | 799 |
806 BREAKUP_CHAR (XCHAR (ch), charset, byte1, byte2); | 800 BREAKUP_CHAR (ch, charset, byte1, byte2); |
807 | 801 |
808 if (EQ (charset, Vcharset_ascii)) | 802 if (EQ (charset, Vcharset_ascii)) |
809 val = ct->ascii[byte1]; | 803 val = ct->ascii[byte1]; |
810 else if (EQ (charset, Vcharset_control_1)) | 804 else if (EQ (charset, Vcharset_control_1)) |
811 val = ct->ascii[byte1 + 128]; | 805 val = ct->ascii[byte1 + 128]; |
828 } | 822 } |
829 | 823 |
830 return val; | 824 return val; |
831 } | 825 } |
832 #else /* not MULE */ | 826 #else /* not MULE */ |
833 return ct->ascii[(unsigned char) XCHAR (ch)]; | 827 return ct->ascii[(unsigned char)ch]; |
834 #endif /* not MULE */ | 828 #endif /* not MULE */ |
829 } | |
830 | |
831 | |
832 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /* | |
833 Find value for char CH in TABLE. | |
834 */ | |
835 (ch, table)) | |
836 { | |
837 struct Lisp_Char_Table *ct; | |
838 Emchar chr; | |
839 | |
840 CHECK_CHAR_TABLE (table); | |
841 ct = XCHAR_TABLE (table); | |
842 CHECK_CHAR_COERCE_INT (ch); | |
843 chr = XCHAR(ch); | |
844 | |
845 return (get_char_table (chr, ct)); | |
835 } | 846 } |
836 | 847 |
837 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /* | 848 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /* |
838 Find value for a range in TABLE. | 849 Find value for a range in TABLE. |
839 If there is more than one value, return MULTI (defaults to nil). | 850 If there is more than one value, return MULTI (defaults to nil). |
1384 XCHARSET_LEADING_BYTE (range->charset), | 1395 XCHARSET_LEADING_BYTE (range->charset), |
1385 fn, arg); | 1396 fn, arg); |
1386 | 1397 |
1387 case CHARTAB_RANGE_ROW: | 1398 case CHARTAB_RANGE_ROW: |
1388 { | 1399 { |
1389 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset)]; | 1400 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE]; |
1390 if (!CHAR_TABLE_ENTRYP (val)) | 1401 if (!CHAR_TABLE_ENTRYP (val)) |
1391 { | 1402 { |
1392 struct chartab_range rainj; | 1403 struct chartab_range rainj; |
1393 | 1404 |
1394 rainj.type = CHARTAB_RANGE_ROW; | 1405 rainj.type = CHARTAB_RANGE_ROW; |
1489 UNGCPRO; | 1500 UNGCPRO; |
1490 | 1501 |
1491 return slarg.retval; | 1502 return slarg.retval; |
1492 } | 1503 } |
1493 | 1504 |
1505 | |
1494 | 1506 |
1495 /************************************************************************/ | 1507 /************************************************************************/ |
1496 /* Char table read syntax */ | 1508 /* Char table read syntax */ |
1497 /************************************************************************/ | 1509 /************************************************************************/ |
1498 | 1510 |
1603 | 1615 |
1604 There are 95 different categories available, one for each printable | 1616 There are 95 different categories available, one for each printable |
1605 character (including space) in the ASCII charset. Each category | 1617 character (including space) in the ASCII charset. Each category |
1606 is designated by one such character, called a \"category designator\". | 1618 is designated by one such character, called a \"category designator\". |
1607 They are specified in a regexp using the syntax \"\\cX\", where X is | 1619 They are specified in a regexp using the syntax \"\\cX\", where X is |
1608 a category designator. (This is not yet implemented.) | 1620 a category designator. |
1609 | 1621 |
1610 A category table specifies, for each character, the categories that | 1622 A category table specifies, for each character, the categories that |
1611 the character is in. Note that a character can be in more than one | 1623 the character is in. Note that a character can be in more than one |
1612 category. More specifically, a category table maps from a character | 1624 category. More specifically, a category table maps from a character |
1613 to either the value nil (meaning the character is in no categories) | 1625 to either the value nil (meaning the character is in no categories) |
1631 obj = def; | 1643 obj = def; |
1632 while (NILP (Fcategory_table_p (obj))) | 1644 while (NILP (Fcategory_table_p (obj))) |
1633 obj = wrong_type_argument (Qcategory_table_p, obj); | 1645 obj = wrong_type_argument (Qcategory_table_p, obj); |
1634 return (obj); | 1646 return (obj); |
1635 } | 1647 } |
1648 | |
1649 int | |
1650 check_category_at(Emchar ch, Lisp_Object table, | |
1651 unsigned int designator, unsigned int not) | |
1652 { | |
1653 register Lisp_Object temp; | |
1654 struct Lisp_Char_Table *ctbl; | |
1655 #if 1 /* ifdef ERROR_CHECK_TYPECHECK */ | |
1656 if (NILP (Fcategory_table_p (table))) | |
1657 signal_simple_error("Expected category table", table); | |
1658 #endif | |
1659 ctbl = XCHAR_TABLE(table); | |
1660 temp = get_char_table(ch, ctbl); | |
1661 if (EQ (temp, Qnil)) return not; | |
1662 | |
1663 designator -= ' '; | |
1664 return (bit_vector_bit(XBIT_VECTOR (temp), designator) ? !not : not); | |
1665 } | |
1666 | |
1667 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /* | |
1668 Return t if category of a character at POS includes DESIGNATIOR, | |
1669 else return nil. Optional third arg specifies which buffer | |
1670 (defaulting to current), and fourth specifies the CATEGORY-TABLE, | |
1671 (defaulting to the buffer's category table). | |
1672 */ | |
1673 (pos, designator, buffer, category_table)) | |
1674 { | |
1675 Lisp_Object ctbl; | |
1676 Emchar ch; | |
1677 unsigned int des; | |
1678 struct buffer *buf = decode_buffer(buffer, 0); | |
1679 | |
1680 CHECK_INT (pos); | |
1681 CHECK_CATEGORY_DESIGNATOR (designator); | |
1682 des = XREALINT(designator); | |
1683 ctbl = check_category_table (category_table, Vstandard_category_table); | |
1684 ch = BUF_FETCH_CHAR (buf, XINT(pos)); | |
1685 return (check_category_at(ch, ctbl, des, 0) | |
1686 ? Qt : Qnil); | |
1687 } | |
1636 | 1688 |
1637 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /* | 1689 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /* |
1638 Return the current category table. | 1690 Return the current category table. |
1639 This is the one specified by the current buffer, or by BUFFER if it | 1691 This is the one specified by the current buffer, or by BUFFER if it |
1640 is non-nil. | 1692 is non-nil. |
1735 DEFSUBR (Fcategory_table_p); | 1787 DEFSUBR (Fcategory_table_p); |
1736 DEFSUBR (Fcategory_table); | 1788 DEFSUBR (Fcategory_table); |
1737 DEFSUBR (Fstandard_category_table); | 1789 DEFSUBR (Fstandard_category_table); |
1738 DEFSUBR (Fcopy_category_table); | 1790 DEFSUBR (Fcopy_category_table); |
1739 DEFSUBR (Fset_category_table); | 1791 DEFSUBR (Fset_category_table); |
1740 | 1792 DEFSUBR (Fcheck_category_at); |
1741 DEFSUBR (Fcategory_designator_p); | 1793 DEFSUBR (Fcategory_designator_p); |
1742 DEFSUBR (Fcategory_table_value_p); | 1794 DEFSUBR (Fcategory_table_value_p); |
1743 #endif /* MULE */ | 1795 #endif /* MULE */ |
1744 | 1796 |
1745 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */ | 1797 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */ |