(M0_3): Delete it.
[m17n/m17n-lib.git] / src / character.c
1 /* character.c -- character module.
2    Copyright (C) 2003, 2004
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307, USA.  */
22
23 /***en
24     @addtogroup m17nCharacter
25     @brief Character objects and API for them.
26
27     The m17n library represents a @e character by a character code (an
28     integer).  The minimum character code is @c 0.  The maximum
29     character code is defined by the macro #MCHAR_MAX.  It is
30     assured that #MCHAR_MAX is not smaller than @c 0x3FFFFF (22
31     bits).
32
33     Characters @c 0 to @c 0x10FFFF are equivalent to the Unicode
34     characters of the same code values.
35
36     A character can have zero or more properties called @e character
37     @e properties.  A character property consists of a @e key and a
38     @e value, where key is a symbol and value is anything that can be
39     cast to <tt>(void *)</tt>.  "The character property that belongs
40     to character C and whose key is K" may be shortened to "the K
41     property of C".  */
42
43 /***ja
44     @addtogroup m17nCharacter
45     @brief Ê¸»ú¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
46
47     m17n ¥é¥¤¥Ö¥é¥ê¤Ï @e Ê¸»ú ¤òʸ»ú¥³¡¼¥É¡ÊÀ°¿ô¡Ë¤Çɽ¸½¤¹¤ë¡£
48     ºÇ¾®¤Îʸ»ú¥³¡¼¥É¤Ï @c 0 ¤Ç¤¢¤ê¡¢ºÇÂç¤Îʸ»ú¥³¡¼¥É¤Ï¥Þ¥¯¥í #MCHAR_MAX 
49     ¤Ë¤è¤Ã¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£#MCHAR_MAX ¤Ï @c 0x3FFFFF¡Ê22¥Ó¥Ã¥È¡Ë
50     °Ê¾å¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤ë¡£
51
52     @c 0 ¤«¤é @c 0x10FFFF ¤Þ¤Ç¤Îʸ»ú¤Ï¡¢¤½¤ì¤ÈƱ¤¸Ãͤò»ý¤Ä Unicode 
53     ¤Îʸ»ú¤Ë³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¡£
54
55     ³Æʸ»ú¤Ï @e Ê¸»ú¥×¥í¥Ñ¥Æ¥£ ¤È¸Æ¤Ö¥×¥í¥Ñ¥Æ¥£¤ò 0 ¸Ä°Ê¾å»ý¤Ä¤³¤È¤¬¤Ç¤­¤ë¡£
56     Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥­¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£
57     ¥­¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤϠ<tt>(void *)</tt> ·¿¤Ë¥­¥ã¥¹¥È¤Ç¤­¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£ 
58     ¡Öʸ»ú C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ K ¤Ç¤¢¤ë¤â¤Î¡×¤ò´Êñ¤Ë¡Öʸ»ú C 
59     ¤Î K ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£  */
60 /*=*/
61
62 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
63 /*** @addtogroup m17nInternal
64      @{ */
65
66 #include <config.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #include <limits.h>
70 #include <ctype.h>
71 #include <stdio.h>
72
73 #include "m17n-core.h"
74 #include "m17n-misc.h"
75 #include "internal.h"
76
77 typedef struct
78 {
79   MSymbol type;
80   void *mdb;
81   MCharTable *table;
82 } MCharPropRecord;
83
84 static MPlist *char_prop_list;
85
86 static void
87 free_string (int from, int to, void *str, void *arg)
88 {
89   free (str);
90 }
91
92 \f
93 /* Internal API */
94
95 int
96 mchar__init ()
97 {
98   char_prop_list = mplist ();
99
100   Mname
101     = mchar_define_property ("name", Mstring);
102   Mcategory
103     = mchar_define_property ("category", Msymbol);
104   Mcombining_class
105     = mchar_define_property ("combining-class", Minteger);
106   Mbidi_category
107     = mchar_define_property ("bidirectional-category", Msymbol);
108   Msimple_case_folding
109     = mchar_define_property ("simple-case-folding", Minteger);
110   Mcomplicated_case_folding
111     = mchar_define_property ("complicated-case-folding", Mtext);
112   Mscript
113     = mchar_define_property ("script", Msymbol);
114
115   mchar_define_property ("cased", Minteger);
116   mchar_define_property ("soft-dotted", Msymbol);
117   mchar_define_property ("case-mapping", Mplist);
118
119   return 0;
120 }
121
122 void
123 mchar__fini (void)
124 {
125   MPlist *p;
126
127   for (p = char_prop_list; mplist_key (p) != Mnil; p = mplist_next (p))
128     {
129       MCharPropRecord *record = mplist_value (p);
130
131       if (record->table)
132         {
133           if (record->type == Mstring)
134             mchartable_map (record->table, NULL, free_string, NULL);
135           M17N_OBJECT_UNREF (record->table);
136         }
137       free (record);
138     }
139   M17N_OBJECT_UNREF (char_prop_list);
140 }
141
142 /*** @} */
143 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
144 \f
145 /* External API */
146
147 /*** @addtogroup m17nCharacter
148      @{ */
149 /*=*/
150
151 #ifdef FOR_DOXYGEN
152 /***en
153     @brief Maximum character code.
154
155     The macro #MCHAR_MAX gives the maximum character code.  */
156
157 /***ja
158     @brief Ê¸»ú¥³¡¼¥É¤ÎºÇÂçÃÍ.
159
160     ¥Þ¥¯¥í #MCHAR_MAX ¤Ïʸ»ú¥³¡¼¥É¤ÎºÇÂçÃͤòɽ¤¹¡£  */
161
162 #define MCHAR_MAX
163 /*=*/
164 #endif /* FOR_DOXYGEN */
165
166 /***en
167     @name Variables: Keys of character properties
168
169     These symbols are used as keys of character properties.  */
170
171 /***ja
172     @ingroup m17nCharacter
173     @name ÊÑ¿ô: Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
174
175     ¤³¤ì¤é¤Î¥·¥ó¥Ü¥ë¤Ïʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£*/
176 /*** @{ */
177
178 /***en
179     @brief Key for script.
180
181     The symbol #Mscript has the name <tt>"script"</tt> and is used as the key
182     of a character property.  The value of such a property is a symbol
183     representing the script to which the character belongs.
184
185     Each symbol that represents a script has one of the names listed in
186     the <em>Unicode Technical Report #24</em>.  */
187
188 /***ja
189     @brief ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥­¡¼.
190
191     ¥·¥ó¥Ü¥ë #Mscript ¤Ï <tt>"script"</tt> 
192     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
193     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¤³¤Îʸ»ú¤Î°¤¹¤ë¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
194
195     ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Unicode Technical Report
196     #24</em> ¤Ë¥ê¥¹¥È¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£  */
197
198 MSymbol Mscript;
199
200 /*=*/
201
202 /***en
203     @brief Key for character name.
204
205     The symbol #Mname has the name <tt>"name"</tt> and is used as
206     the key of a character property.  The value of such a property is a
207     C-string representing the name of the character.  */
208
209 /***ja
210     @brief Ì¾Á°¤òɽ¤ï¤¹¥­¡¼.
211
212     ¥·¥ó¥Ü¥ë #Mname ¤Ï <tt>"name"</tt> 
213     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
214     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϤ½¤Îʸ»ú¤Î̾Á°¤òɽ¤ï¤¹ C ¤Îʸ»úÎó¤Ç¤¢¤ë¡£  */
215
216 MSymbol Mname;
217
218 /*=*/
219
220 /***en
221     @brief Key for general category.
222
223     The symbol #Mcategory has the name <tt>"category"</tt> and is
224     used as the key of a character property.  The value of such a
225     property is a symbol representing the <em>general category</em> of
226     the character.
227
228     Each symbol that represents a general category has one of the
229     names listed as abbreviations for <em>General Category</em> in
230     Unicode.  */
231
232 /***ja
233     @brief °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
234
235     ¥·¥ó¥Ü¥ë #Mcategory ¤Ï <tt>"category"</tt> 
236     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
237     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë <em>°ìÈÌ¥«¥Æ¥´¥ê</em> ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
238
239     °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>General Category</em> 
240     ¤Î¾Êά·Á¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
241
242 MSymbol Mcategory;
243
244 /*=*/
245
246 /***en
247     @brief Key for canonical combining class.
248
249     The symbol #Mcombining_class has the name
250     <tt>"combining-class"</tt> and is used as the key of a character
251     property.  The value of such a property is an integer that
252     represents the <em>canonical combining class</em> of the character.
253
254     The meaning of each integer that represents a canonical combining
255     class is identical to the one defined in Unicode.  */
256
257 /***ja
258     @brief É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹¥­¡¼.
259
260     ¥·¥ó¥Ü¥ë #Mcombining_class ¤Ï <tt>"combining-class"</tt> 
261     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
262     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e É¸½à·ë¹ç¥¯¥é¥¹ ¤òɽ¤ï¤¹À°¿ô¤Ç¤¢¤ë¡£
263
264     É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹À°¿ô¤Î°ÕÌ£¤Ï¡¢Unicode 
265     ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤ÈƱ¤¸¤Ç¤¢¤ë¡£  */
266
267 MSymbol Mcombining_class;
268 /*=*/
269
270 /***en
271     @brief Key for bidi category.
272
273     The symbol #Mbidi_category has the name <tt>"bidi-category"</tt>
274     and is used as the key of a character property.  The value of such
275     a property is a symbol that represents the <em>bidirectional
276     category</em> of the character.
277
278     Each symbol that represents a bidirectional category has one of
279     the names listed as types of <em>Bidirectional Category</em> in
280     Unicode.  */
281
282 /***ja
283     @brief ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
284
285     ¥·¥ó¥Ü¥ë #Mbidi_category ¤Ï <tt>"bidi-category"</tt> 
286     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
287     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e ÁÐÊý¸þ¥«¥Æ¥´¥ê ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
288
289     ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Bidirectional
290     Category</em> ¤Î·¿¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
291
292 MSymbol Mbidi_category;
293 /*=*/
294
295 /***en
296     @brief Key for corresponding single lowercase character.
297
298     The symbol #Msimple_case_folding has the name
299     <tt>"simple-case-folding"</tt> and is used as the key of a
300     character property.  The value of such a property is the
301     corresponding single lowercase character that is used when
302     comparing M-texts ignoring cases.
303
304     If a character requires a complicated comparison (i.e. cannot be
305     compared by simply mapping to another single character), the value
306     of such a property is @c 0xFFFF.  In this case, the character has
307     another property whose key is #Mcomplicated_case_folding.  */
308
309 /***ja
310     @brief Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤òɽ¤ï¤¹¥­¡¼.
311
312     ¥·¥ó¥Ü¥ë #Msimple_case_folding ¤Ï <tt>"simple-case-folding"</tt> 
313     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
314     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È¤ï¤ì¤ë¡£
315
316     Ê£»¨¤ÊÈæ³ÓÊýË¡¤òɬÍפȤ¹¤ëʸ»ú¤Ç¤¢¤Ã¤¿¾ì¹ç
317     ¡ÊÊ̤ΰìʸ»ú¤ÈÂбþÉÕ¤±¤ë¤³¤È¤Ë¤è¤Ã¤ÆÈæ³Ó¤Ç¤­¤Ê¤¤¾ì¹ç¡Ë¡¢¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϠ
318     @c 0xFFFF ¤Ë¤Ê¤ë¡£¤³¤Î¾ì¹ç¤½¤Îʸ»ú¤Ï¡¢#Mcomplicated_case_folding
319     ¤È¤¤¤¦¥­¡¼¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£  */
320
321 MSymbol Msimple_case_folding;
322 /***en
323     @brief Key for corresponding multiple lowercase characters.
324
325     The symbol #Mcomplicated_case_folding has the name
326     <tt>"complicated-case-folding"</tt> and is used as the key of a
327     character property.  The value of such a property is the
328     corresponding M-text that contains a sequence of lowercase
329     characters to be used for comparing M-texts ignoring case.  */
330
331 /***ja
332     @brief Âбþ¤¹¤ë¾®Ê¸»ú¤ÎÎó¤òɽ¤ï¤¹¥­¡¼.
333
334     ¥·¥ó¥Ü¥ë #Mcomplicated_case_folding ¤Ï 
335     <tt>"complicated-case-folding"</tt> 
336     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
337     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»úÎ󤫤é¤Ê¤ë M-text ¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È
338     ¤ï¤ì¤ë¡£
339       */
340
341 MSymbol Mcomplicated_case_folding;
342 /*=*/
343 /*** @} */
344 /*=*/
345
346 /***en
347     @brief Define a character property.
348
349     The mchar_define_property () function searches the m17n database
350     for a data whose tags are \<#Mchar_table, $TYPE, $SYM \>.
351     Here, $SYM is a symbol whose name is $NAME.  $TYPE must be
352     #Mstring, #Mtext, #Msymbol, #Minteger, or #Mplist.
353
354     @return
355     If the operation was successful, mchar_define_property () returns
356     $SYM.  Otherwise it returns #Mnil.  */
357
358 /***ja
359     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤òÄêµÁ¤¹¤ë.
360
361     ´Ø¿ô mchar_define_property () ¤Ï¡¢ \<#Mchar_table, $TYPE, $SYM \>
362     ¤È¤¤¤¦¥¿¥°¤ò»ý¤Ã¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò m17n ¸À¸ì¾ðÊó¥Ù¡¼¥¹¤«¤éõ¤¹¡£  
363     ¤³¤³¤Ç $SYM ¤Ï $NAME ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£$TYPE ¤Ï#Mstring,
364     #Mtext, #Msymbol, #Minteger, #Mplist ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
365
366     @return
367     ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mchar_define_property () ¤Ï$SYM ¤òÊÖ¤¹¡£
368     ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï #Mnil ¤òÊÖ¤¹¡£  */
369
370 /***
371     @errors
372     @c MERROR_DB
373
374     @seealso
375     mchar_get_prop (), mchar_put_prop ()  */
376
377 MSymbol
378 mchar_define_property (const char *name, MSymbol type)
379 {
380   MSymbol key = msymbol (name);
381   MCharPropRecord *record;
382
383   record = mplist_get (char_prop_list, key);
384   if (record)
385     {
386       if (record->table)
387         M17N_OBJECT_UNREF (record->table);
388     }
389   else
390     {
391       MSTRUCT_CALLOC (record, MERROR_CHAR);
392       mplist_put (char_prop_list, key, record);
393     }
394
395   record->type = type;
396   if (mdatabase__finder
397       && (record->mdb = (*mdatabase__finder) (Mchar_table, type, key, Mnil)))
398     {
399       record->table = NULL;
400     }
401   else
402     {
403       void *default_value = NULL;
404
405       record->mdb = NULL;
406       if (type == Minteger)
407         default_value = (void *) -1;
408       record->table = mchartable (type, default_value);
409     }
410
411   return key;
412 }
413
414 /*=*/
415
416 /***en
417     @brief Get the value of a character property.
418
419     The mchar_get_prop () function searches character $C for the
420     character property whose key is $KEY.
421
422     @return
423     If the operation was successful, mchar_get_prop () returns the
424     value of the character property.  Otherwise it returns @c
425     NULL.  */
426
427 /***ja
428     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
429
430     ´Ø¿ô mchar_get_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ 
431     $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£
432
433     @return
434     ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_get_prop () ¤Ï¸«¤Ä¤«¤Ã¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
435     ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£
436
437     @latexonly \IPAlabel{mchar_get_prop} @endlatexonly
438 */
439 /***
440     @errors
441     @c MERROR_SYMBOL, @c MERROR_DB
442
443     @seealso
444     mchar_define_property (), mchar_put_prop ()  */
445
446 void *
447 mchar_get_prop (int c, MSymbol key)
448 {
449   MCharPropRecord *record;
450
451   record = mplist_get (char_prop_list, key);
452   if (! record)
453     return NULL;
454   if (record->mdb)
455     {
456       record->table = (*mdatabase__loader) (record->mdb);
457       if (! record->table)
458         MERROR (MERROR_DB, NULL);
459       record->mdb = NULL;
460     }
461   return mchartable_lookup (record->table, c);
462 }
463
464 /*=*/
465
466 /***en
467     @brief Set the value of a character property.
468
469     The mchar_put_prop () function searches character $C for the
470     character property whose key is $KEY and assigns $VAL to the value
471     of the found property.
472
473     @return
474     If the operation was successful, mchar_put_prop () returns 0.
475     Otherwise, it returns -1.  */
476 /***ja
477     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
478
479     ´Ø¿ô mchar_put_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ $KEY 
480     ¤Ç¤¢¤ë¤â¤Î¤òõ¤·¡¢¤½¤ÎÃͤȤ·¤Æ $VAL ¤òÀßÄꤹ¤ë¡£
481
482     @return
483     ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_put_prop () ¤Ï0¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï-1¤òÊÖ¤¹¡£  */
484 /***
485     @errors
486     @c MERROR_SYMBOL, @c MERROR_DB
487
488     @seealso
489     mchar_define_property (), mchar_get_prop ()   */
490
491 int
492 mchar_put_prop (int c, MSymbol key, void *val)
493 {
494   MCharPropRecord *record;
495
496   record = mplist_get (char_prop_list, key);
497   if (! record)
498     return -1;
499   if (record->mdb)
500     {
501       record->table = (*mdatabase__loader) (record->mdb);
502       if (! record->table)
503         MERROR (MERROR_DB, -1);
504       record->mdb = NULL;
505     }
506   return mchartable_set (record->table, c, val);
507 }
508
509 /*=*/
510
511 /***en
512     @brief Get the char-table for a character property.
513
514     The mchar_get_prop_table () function returns a char-table that
515     contains the character property whose key is $KEY.  If $TYPE is
516     not NULL, this function stores the type of the property in the
517     place pointed by $TYPE.  See mchar_define_property () for types of
518     character property.
519
520     @return
521     If $KEY is a valid character property key, this function returns a
522     char-table.  Otherwise NULL is retuned.  */
523
524 /***ja
525     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Îʸ»ú¥Æ¡¼¥Ö¥ë¤òÆÀ¤ë.
526
527     ´Ø¿ô mchar_get_prop_table () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ëʸ»ú¥×¥í¥Ñ¥Æ¥£
528     ¤ò´Þ¤àʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£¤â¤· $TYPE ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ $TYPE ¤Ç
529     »Ø¤µ¤ì¤ë¾ì½ê¤Ë¤½¤Îʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤ò³ÊǼ¤¹¤ë¡£Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¼ïÎà
530     ¤Ë´Ø¤·¤Æ¤Ï mchar_define_property () ¤ò¸«¤è¡£
531
532     @return
533     ¤â¤· $KEY ¤¬ÀµÅö¤Êʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤¢¤ì¤Ð¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë¤¬ÊÖ¤µ
534     ¤ì¤ë¡£¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï NULL ¤¬ÊÖ¤µ¤ì¤ë¡£  */
535
536 MCharTable *
537 mchar_get_prop_table (MSymbol key, MSymbol *type)
538 {
539   MCharPropRecord *record;
540
541   record = mplist_get (char_prop_list, key);
542   if (! record)
543     return NULL;
544   if (record->mdb)
545     {
546       record->table = (*mdatabase__loader) (record->mdb);
547       if (! record->table)
548         MERROR (MERROR_DB, NULL);
549       record->mdb = NULL;
550     }
551   if (type)
552     *type = record->type;
553   return record->table;
554 }
555
556 /*** @} */
557
558 /*
559   Local Variables:
560   coding: euc-japan
561   End:
562 */