comparison src/data.c @ 89483:2f877ed80fa6

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 08 Sep 2003 12:53:41 +0000
parents 375f2633d815 1271680eca43
children 58eb89f2fdfc
comparison
equal deleted inserted replaced
88123:375f2633d815 89483:2f877ed80fa6
23 #include <config.h> 23 #include <config.h>
24 #include <signal.h> 24 #include <signal.h>
25 #include <stdio.h> 25 #include <stdio.h>
26 #include "lisp.h" 26 #include "lisp.h"
27 #include "puresize.h" 27 #include "puresize.h"
28 #include "charset.h" 28 #include "character.h"
29 #include "buffer.h" 29 #include "buffer.h"
30 #include "keyboard.h" 30 #include "keyboard.h"
31 #include "frame.h" 31 #include "frame.h"
32 #include "syssignal.h" 32 #include "syssignal.h"
33 33
445 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0, 445 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
446 doc: /* Return t if OBJECT is a character (an integer) or a string. */) 446 doc: /* Return t if OBJECT is a character (an integer) or a string. */)
447 (object) 447 (object)
448 register Lisp_Object object; 448 register Lisp_Object object;
449 { 449 {
450 if (INTEGERP (object) || STRINGP (object)) 450 if (CHARACTERP (object) || STRINGP (object))
451 return Qt; 451 return Qt;
452 return Qnil; 452 return Qnil;
453 } 453 }
454 454
455 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, 455 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
1853 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR]; 1853 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR];
1854 return (val & (1 << (idxval % BITS_PER_CHAR)) ? Qt : Qnil); 1854 return (val & (1 << (idxval % BITS_PER_CHAR)) ? Qt : Qnil);
1855 } 1855 }
1856 else if (CHAR_TABLE_P (array)) 1856 else if (CHAR_TABLE_P (array))
1857 { 1857 {
1858 Lisp_Object val; 1858 CHECK_CHARACTER (idx);
1859 1859 return CHAR_TABLE_REF (array, idxval);
1860 val = Qnil;
1861
1862 if (idxval < 0)
1863 args_out_of_range (array, idx);
1864 if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
1865 {
1866 /* For ASCII and 8-bit European characters, the element is
1867 stored in the top table. */
1868 val = XCHAR_TABLE (array)->contents[idxval];
1869 if (NILP (val))
1870 val = XCHAR_TABLE (array)->defalt;
1871 while (NILP (val)) /* Follow parents until we find some value. */
1872 {
1873 array = XCHAR_TABLE (array)->parent;
1874 if (NILP (array))
1875 return Qnil;
1876 val = XCHAR_TABLE (array)->contents[idxval];
1877 if (NILP (val))
1878 val = XCHAR_TABLE (array)->defalt;
1879 }
1880 return val;
1881 }
1882 else
1883 {
1884 int code[4], i;
1885 Lisp_Object sub_table;
1886
1887 SPLIT_CHAR (idxval, code[0], code[1], code[2]);
1888 if (code[1] < 32) code[1] = -1;
1889 else if (code[2] < 32) code[2] = -1;
1890
1891 /* Here, the possible range of CODE[0] (== charset ID) is
1892 128..MAX_CHARSET. Since the top level char table contains
1893 data for multibyte characters after 256th element, we must
1894 increment CODE[0] by 128 to get a correct index. */
1895 code[0] += 128;
1896 code[3] = -1; /* anchor */
1897
1898 try_parent_char_table:
1899 sub_table = array;
1900 for (i = 0; code[i] >= 0; i++)
1901 {
1902 val = XCHAR_TABLE (sub_table)->contents[code[i]];
1903 if (SUB_CHAR_TABLE_P (val))
1904 sub_table = val;
1905 else
1906 {
1907 if (NILP (val))
1908 val = XCHAR_TABLE (sub_table)->defalt;
1909 if (NILP (val))
1910 {
1911 array = XCHAR_TABLE (array)->parent;
1912 if (!NILP (array))
1913 goto try_parent_char_table;
1914 }
1915 return val;
1916 }
1917 }
1918 /* Here, VAL is a sub char table. We try the default value
1919 and parent. */
1920 val = XCHAR_TABLE (val)->defalt;
1921 if (NILP (val))
1922 {
1923 array = XCHAR_TABLE (array)->parent;
1924 if (!NILP (array))
1925 goto try_parent_char_table;
1926 }
1927 return val;
1928 }
1929 } 1860 }
1930 else 1861 else
1931 { 1862 {
1932 int size = 0; 1863 int size = 0;
1933 if (VECTORP (array)) 1864 if (VECTORP (array))
1986 val &= ~(1 << (idxval % BITS_PER_CHAR)); 1917 val &= ~(1 << (idxval % BITS_PER_CHAR));
1987 XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR] = val; 1918 XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR] = val;
1988 } 1919 }
1989 else if (CHAR_TABLE_P (array)) 1920 else if (CHAR_TABLE_P (array))
1990 { 1921 {
1991 if (idxval < 0) 1922 CHECK_CHARACTER (idx);
1992 args_out_of_range (array, idx); 1923 CHAR_TABLE_SET (array, idxval, newelt);
1993 if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
1994 XCHAR_TABLE (array)->contents[idxval] = newelt;
1995 else
1996 {
1997 int code[4], i;
1998 Lisp_Object val;
1999
2000 SPLIT_CHAR (idxval, code[0], code[1], code[2]);
2001 if (code[1] < 32) code[1] = -1;
2002 else if (code[2] < 32) code[2] = -1;
2003
2004 /* See the comment of the corresponding part in Faref. */
2005 code[0] += 128;
2006 code[3] = -1; /* anchor */
2007 for (i = 0; code[i + 1] >= 0; i++)
2008 {
2009 val = XCHAR_TABLE (array)->contents[code[i]];
2010 if (SUB_CHAR_TABLE_P (val))
2011 array = val;
2012 else
2013 {
2014 Lisp_Object temp;
2015
2016 /* VAL is a leaf. Create a sub char table with the
2017 default value VAL or XCHAR_TABLE (array)->defalt
2018 and look into it. */
2019
2020 temp = make_sub_char_table (NILP (val)
2021 ? XCHAR_TABLE (array)->defalt
2022 : val);
2023 XCHAR_TABLE (array)->contents[code[i]] = temp;
2024 array = temp;
2025 }
2026 }
2027 XCHAR_TABLE (array)->contents[code[i]] = newelt;
2028 }
2029 } 1924 }
2030 else if (STRING_MULTIBYTE (array)) 1925 else if (STRING_MULTIBYTE (array))
2031 { 1926 {
2032 int idxval_byte, prev_bytes, new_bytes, nbytes; 1927 int idxval_byte, prev_bytes, new_bytes, nbytes;
2033 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; 1928 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2069 { 1964 {
2070 if (idxval < 0 || idxval >= SCHARS (array)) 1965 if (idxval < 0 || idxval >= SCHARS (array))
2071 args_out_of_range (array, idx); 1966 args_out_of_range (array, idx);
2072 CHECK_NUMBER (newelt); 1967 CHECK_NUMBER (newelt);
2073 1968
2074 if (XINT (newelt) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt))) 1969 if (XINT (newelt) < 0 || ASCII_CHAR_P (XINT (newelt)))
2075 SSET (array, idxval, XINT (newelt)); 1970 SSET (array, idxval, XINT (newelt));
2076 else 1971 else
2077 { 1972 {
2078 /* We must relocate the string data while converting it to 1973 /* We must relocate the string data while converting it to
2079 multibyte. */ 1974 multibyte. */