Mercurial > emacs
comparison src/chartab.c @ 89424:7020f4f73751
(map_sub_char_table): New argument DEFAULT_VAL.
(map_char_table): Don't inherit the value from the parent on
initializing VAL. Adjusted for the above change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 06 May 2003 23:24:36 +0000 |
parents | 0b3ed65e4e97 |
children | 32e34aaffbe3 |
comparison
equal
deleted
inserted
replaced
89423:563e44e1fd68 | 89424:7020f4f73751 |
---|---|
705 return Qnil; | 705 return Qnil; |
706 } | 706 } |
707 | 707 |
708 | 708 |
709 static Lisp_Object | 709 static Lisp_Object |
710 map_sub_char_table (c_function, function, table, arg, val, range) | 710 map_sub_char_table (c_function, function, table, arg, val, range, default_val) |
711 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); | 711 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); |
712 Lisp_Object function, table, arg, val, range; | 712 Lisp_Object function, table, arg, val, range, default_val; |
713 { | 713 { |
714 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); | 714 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); |
715 int depth = XINT (tbl->depth); | 715 int depth = XINT (tbl->depth); |
716 int i, c; | 716 int i, c; |
717 | 717 |
720 { | 720 { |
721 Lisp_Object this; | 721 Lisp_Object this; |
722 | 722 |
723 this = tbl->contents[i]; | 723 this = tbl->contents[i]; |
724 if (SUB_CHAR_TABLE_P (this)) | 724 if (SUB_CHAR_TABLE_P (this)) |
725 val = map_sub_char_table (c_function, function, this, arg, val, range); | 725 val = map_sub_char_table (c_function, function, this, arg, val, range, |
726 else if (NILP (Fequal (val, this))) | 726 default_val); |
727 else | |
727 { | 728 { |
728 if (! NILP (val)) | 729 if (NILP (this)) |
730 this = default_val; | |
731 if (NILP (Fequal (val, this))) | |
729 { | 732 { |
730 XCDR (range) = make_number (c - 1); | 733 if (! NILP (val)) |
731 if (depth == 3 | |
732 && EQ (XCAR (range), XCDR (range))) | |
733 { | 734 { |
734 if (c_function) | 735 XCDR (range) = make_number (c - 1); |
735 (*c_function) (arg, XCAR (range), val); | 736 if (depth == 3 |
737 && EQ (XCAR (range), XCDR (range))) | |
738 { | |
739 if (c_function) | |
740 (*c_function) (arg, XCAR (range), val); | |
741 else | |
742 call2 (function, XCAR (range), val); | |
743 } | |
736 else | 744 else |
737 call2 (function, XCAR (range), val); | 745 { |
746 if (c_function) | |
747 (*c_function) (arg, range, val); | |
748 else | |
749 call2 (function, range, val); | |
750 } | |
738 } | 751 } |
739 else | 752 val = this; |
753 XCAR (range) = make_number (c); | |
754 } | |
755 } | |
756 } | |
757 return val; | |
758 } | |
759 | |
760 | |
761 /* Map C_FUNCTION or FUNCTION over TABLE, calling it for each | |
762 character or group of characters that share a value. | |
763 | |
764 ARG is passed to C_FUNCTION when that is called. | |
765 | |
766 DEPTH and INDICES are ignored. They are removed in the new | |
767 feature. */ | |
768 | |
769 void | |
770 map_char_table (c_function, function, table, arg, depth, indices) | |
771 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); | |
772 Lisp_Object function, table, arg, *indices; | |
773 int depth; | |
774 { | |
775 Lisp_Object range, val; | |
776 int c, i; | |
777 | |
778 range = Fcons (make_number (0), Qnil); | |
779 val = XCHAR_TABLE (table)->ascii; | |
780 if (SUB_CHAR_TABLE_P (val)) | |
781 val = XSUB_CHAR_TABLE (val)->contents[0]; | |
782 | |
783 for (i = 0, c = 0; i < chartab_size[0]; i++, c += chartab_chars[0]) | |
784 { | |
785 Lisp_Object this; | |
786 | |
787 this = XCHAR_TABLE (table)->contents[i]; | |
788 if (SUB_CHAR_TABLE_P (this)) | |
789 val = map_sub_char_table (c_function, function, this, arg, val, range, | |
790 XCHAR_TABLE (table)->defalt); | |
791 else | |
792 { | |
793 if (NILP (this)) | |
794 this = XCHAR_TABLE (table)->defalt; | |
795 if (NILP (Fequal (val, this))) | |
796 { | |
797 if (! NILP (val)) | |
740 { | 798 { |
799 XCDR (range) = make_number (c - 1); | |
741 if (c_function) | 800 if (c_function) |
742 (*c_function) (arg, range, val); | 801 (*c_function) (arg, range, val); |
743 else | 802 else |
744 call2 (function, range, val); | 803 call2 (function, range, val); |
745 } | 804 } |
805 val = this; | |
806 XCAR (range) = make_number (c); | |
746 } | 807 } |
747 val = this; | |
748 XCAR (range) = make_number (c); | |
749 } | 808 } |
750 } | 809 } |
751 return val; | 810 |
752 } | 811 if (! NILP (val)) |
753 | 812 { |
754 | 813 XCDR (range) = make_number (c - 1); |
755 /* Map C_FUNCTION or FUNCTION over TABLE, calling it for each | 814 if (c_function) |
756 character or group of characters that share a value. | 815 (*c_function) (arg, range, val); |
757 | 816 else |
758 ARG is passed to C_FUNCTION when that is called. | 817 call2 (function, range, val); |
759 | |
760 DEPTH and INDICES are ignored. They are removed in the new | |
761 feature. */ | |
762 | |
763 void | |
764 map_char_table (c_function, function, table, arg, depth, indices) | |
765 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); | |
766 Lisp_Object function, table, arg, *indices; | |
767 int depth; | |
768 { | |
769 Lisp_Object range, val; | |
770 int c, i; | |
771 | |
772 range = Fcons (make_number (0), Qnil); | |
773 val = char_table_ref (table, 0); | |
774 | |
775 for (i = 0, c = 0; i < chartab_size[0]; i++, c += chartab_chars[0]) | |
776 { | |
777 Lisp_Object this; | |
778 | |
779 this = XCHAR_TABLE (table)->contents[i]; | |
780 if (SUB_CHAR_TABLE_P (this)) | |
781 val = map_sub_char_table (c_function, function, this, arg, val, range); | |
782 else if (NILP (Fequal (val, this))) | |
783 { | |
784 if (! NILP (val)) | |
785 { | |
786 XCDR (range) = make_number (c - 1); | |
787 if (c_function) | |
788 (*c_function) (arg, range, val); | |
789 else | |
790 call2 (function, range, val); | |
791 } | |
792 val = this; | |
793 XCAR (range) = make_number (c); | |
794 } | |
795 } | 818 } |
796 } | 819 } |
797 | 820 |
798 DEFUN ("map-char-table", Fmap_char_table, Smap_char_table, | 821 DEFUN ("map-char-table", Fmap_char_table, Smap_char_table, |
799 2, 2, 0, | 822 2, 2, 0, |
800 doc: /* | 823 doc: /* |
801 Call FUNCTION for each character in CHAR-TABLE. | 824 Call FUNCTION for each character in CHAR-TABLE. |
802 FUNCTION is called with two arguments--a key and a value. | 825 FUNCTION is called with two arguments--a key and a value. |
803 The key is always a possible IDX argument to `aref'. */) | 826 The key is a character code or a cons of character codes specifying a |
827 range of characters that have the same value. */) | |
804 (function, char_table) | 828 (function, char_table) |
805 Lisp_Object function, char_table; | 829 Lisp_Object function, char_table; |
806 { | 830 { |
807 CHECK_CHAR_TABLE (char_table); | 831 CHECK_CHAR_TABLE (char_table); |
808 | 832 |