Update FSF postal address.
[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., 51 Franklin Street, Fifth Floor,
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   Mname = msymbol ("name");
99   Mcategory = msymbol ("category");
100   Mcombining_class = msymbol ("combining-class");
101   Mbidi_category = msymbol ("bidirectional-category");
102   Msimple_case_folding = msymbol ("simple-case-folding");
103   Mcomplicated_case_folding = msymbol ("complicated-case-folding");
104   Mscript = msymbol ("script");
105
106   return 0;
107 }
108
109 void
110 mchar__fini (void)
111 {
112   MPlist *p;
113
114   if (char_prop_list)
115     {
116       for (p = char_prop_list; mplist_key (p) != Mnil; p = mplist_next (p))
117         {
118           MCharPropRecord *record = mplist_value (p);
119
120           if (record->table)
121             {
122               if (record->type == Mstring)
123                 mchartable_map (record->table, NULL, free_string, NULL);
124               M17N_OBJECT_UNREF (record->table);
125             }
126           free (record);
127         }
128       M17N_OBJECT_UNREF (char_prop_list);
129     }
130 }
131
132 void
133 mchar__define_prop (MSymbol key, MSymbol type, void *mdb)
134 {
135   MCharPropRecord *record;
136
137   if (char_prop_list)
138     record = mplist_get (char_prop_list, key);
139   else
140     char_prop_list = mplist (), record = NULL;
141   if (record)
142     {
143       if (record->table)
144         M17N_OBJECT_UNREF (record->table);
145     }
146   else
147     {
148       MSTRUCT_CALLOC (record, MERROR_CHAR);
149       mplist_put (char_prop_list, key, record);
150     }
151
152   record->type = type;
153   record->mdb = mdb;
154   if (mdb)
155     {
156       record->table = NULL;
157     }
158   else
159     {
160       void *default_value = NULL;
161
162       if (type == Minteger)
163         default_value = (void *) -1;
164       record->table = mchartable (type, default_value);
165     }
166 }
167
168
169 /*** @} */
170 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
171 \f
172 /* External API */
173
174 /*** @addtogroup m17nCharacter
175      @{ */
176 /*=*/
177
178 #ifdef FOR_DOXYGEN
179 /***en
180     @brief Maximum character code.
181
182     The macro #MCHAR_MAX gives the maximum character code.  */
183
184 /***ja
185     @brief Ê¸»ú¥³¡¼¥É¤ÎºÇÂçÃÍ.
186
187     ¥Þ¥¯¥í #MCHAR_MAX ¤Ïʸ»ú¥³¡¼¥É¤ÎºÇÂçÃͤòɽ¤¹¡£  */
188
189 #define MCHAR_MAX
190 /*=*/
191 #endif /* FOR_DOXYGEN */
192
193 /***en
194     @name Variables: Keys of character properties
195
196     These symbols are used as keys of character properties.  */
197
198 /***ja
199     @ingroup m17nCharacter
200     @name ÊÑ¿ô: Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
201
202     ¤³¤ì¤é¤Î¥·¥ó¥Ü¥ë¤Ïʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£*/
203 /*** @{ */
204
205 /***en
206     @brief Key for script.
207
208     The symbol #Mscript has the name <tt>"script"</tt> and is used as the key
209     of a character property.  The value of such a property is a symbol
210     representing the script to which the character belongs.
211
212     Each symbol that represents a script has one of the names listed in
213     the <em>Unicode Technical Report #24</em>.  */
214
215 /***ja
216     @brief ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥­¡¼.
217
218     ¥·¥ó¥Ü¥ë #Mscript ¤Ï <tt>"script"</tt> 
219     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
220     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¤³¤Îʸ»ú¤Î°¤¹¤ë¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
221
222     ¥¹¥¯¥ê¥×¥È¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Unicode Technical Report
223     #24</em> ¤Ë¥ê¥¹¥È¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£  */
224
225 MSymbol Mscript;
226
227 /*=*/
228
229 /***en
230     @brief Key for character name.
231
232     The symbol #Mname has the name <tt>"name"</tt> and is used as
233     the key of a character property.  The value of such a property is a
234     C-string representing the name of the character.  */
235
236 /***ja
237     @brief Ì¾Á°¤òɽ¤ï¤¹¥­¡¼.
238
239     ¥·¥ó¥Ü¥ë #Mname ¤Ï <tt>"name"</tt> 
240     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
241     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϤ½¤Îʸ»ú¤Î̾Á°¤òɽ¤ï¤¹ C ¤Îʸ»úÎó¤Ç¤¢¤ë¡£  */
242
243 MSymbol Mname;
244
245 /*=*/
246
247 /***en
248     @brief Key for general category.
249
250     The symbol #Mcategory has the name <tt>"category"</tt> and is
251     used as the key of a character property.  The value of such a
252     property is a symbol representing the <em>general category</em> of
253     the character.
254
255     Each symbol that represents a general category has one of the
256     names listed as abbreviations for <em>General Category</em> in
257     Unicode.  */
258
259 /***ja
260     @brief °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
261
262     ¥·¥ó¥Ü¥ë #Mcategory ¤Ï <tt>"category"</tt> 
263     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
264     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë <em>°ìÈÌ¥«¥Æ¥´¥ê</em> ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
265
266     °ìÈÌ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>General Category</em> 
267     ¤Î¾Êά·Á¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
268
269 MSymbol Mcategory;
270
271 /*=*/
272
273 /***en
274     @brief Key for canonical combining class.
275
276     The symbol #Mcombining_class has the name
277     <tt>"combining-class"</tt> and is used as the key of a character
278     property.  The value of such a property is an integer that
279     represents the <em>canonical combining class</em> of the character.
280
281     The meaning of each integer that represents a canonical combining
282     class is identical to the one defined in Unicode.  */
283
284 /***ja
285     @brief É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹¥­¡¼.
286
287     ¥·¥ó¥Ü¥ë #Mcombining_class ¤Ï <tt>"combining-class"</tt> 
288     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
289     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e É¸½à·ë¹ç¥¯¥é¥¹ ¤òɽ¤ï¤¹À°¿ô¤Ç¤¢¤ë¡£
290
291     É¸½à·ë¹ç¥¯¥é¥¹¤òɽ¤ï¤¹À°¿ô¤Î°ÕÌ£¤Ï¡¢Unicode 
292     ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤ÈƱ¤¸¤Ç¤¢¤ë¡£  */
293
294 MSymbol Mcombining_class;
295 /*=*/
296
297 /***en
298     @brief Key for bidi category.
299
300     The symbol #Mbidi_category has the name <tt>"bidi-category"</tt>
301     and is used as the key of a character property.  The value of such
302     a property is a symbol that represents the <em>bidirectional
303     category</em> of the character.
304
305     Each symbol that represents a bidirectional category has one of
306     the names listed as types of <em>Bidirectional Category</em> in
307     Unicode.  */
308
309 /***ja
310     @brief ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥­¡¼.
311
312     ¥·¥ó¥Ü¥ë #Mbidi_category ¤Ï <tt>"bidi-category"</tt> 
313     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
314     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë @e ÁÐÊý¸þ¥«¥Æ¥´¥ê ¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£
315
316     ÁÐÊý¸þ¥«¥Æ¥´¥ê¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤Î̾Á°¤Ï¡¢<em>Bidirectional
317     Category</em> ¤Î·¿¤È¤·¤Æ Unicode ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡£  */
318
319 MSymbol Mbidi_category;
320 /*=*/
321
322 /***en
323     @brief Key for corresponding single lowercase character.
324
325     The symbol #Msimple_case_folding has the name
326     <tt>"simple-case-folding"</tt> and is used as the key of a
327     character property.  The value of such a property is the
328     corresponding single lowercase character that is used when
329     comparing M-texts ignoring cases.
330
331     If a character requires a complicated comparison (i.e. cannot be
332     compared by simply mapping to another single character), the value
333     of such a property is @c 0xFFFF.  In this case, the character has
334     another property whose key is #Mcomplicated_case_folding.  */
335
336 /***ja
337     @brief Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤òɽ¤ï¤¹¥­¡¼.
338
339     ¥·¥ó¥Ü¥ë #Msimple_case_folding ¤Ï <tt>"simple-case-folding"</tt> 
340     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
341     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»ú°ìʸ»ú¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È¤ï¤ì¤ë¡£
342
343     Ê£»¨¤ÊÈæ³ÓÊýË¡¤òɬÍפȤ¹¤ëʸ»ú¤Ç¤¢¤Ã¤¿¾ì¹ç
344     ¡ÊÊ̤ΰìʸ»ú¤ÈÂбþÉÕ¤±¤ë¤³¤È¤Ë¤è¤Ã¤ÆÈæ³Ó¤Ç¤­¤Ê¤¤¾ì¹ç¡Ë¡¢¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϠ
345     @c 0xFFFF ¤Ë¤Ê¤ë¡£¤³¤Î¾ì¹ç¤½¤Îʸ»ú¤Ï¡¢#Mcomplicated_case_folding
346     ¤È¤¤¤¦¥­¡¼¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£  */
347
348 MSymbol Msimple_case_folding;
349 /***en
350     @brief Key for corresponding multiple lowercase characters.
351
352     The symbol #Mcomplicated_case_folding has the name
353     <tt>"complicated-case-folding"</tt> and is used as the key of a
354     character property.  The value of such a property is the
355     corresponding M-text that contains a sequence of lowercase
356     characters to be used for comparing M-texts ignoring case.  */
357
358 /***ja
359     @brief Âбþ¤¹¤ë¾®Ê¸»ú¤ÎÎó¤òɽ¤ï¤¹¥­¡¼.
360
361     ¥·¥ó¥Ü¥ë #Mcomplicated_case_folding ¤Ï 
362     <tt>"complicated-case-folding"</tt> 
363     ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£
364     ¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Âбþ¤¹¤ë¾®Ê¸»úÎ󤫤é¤Ê¤ë M-text ¤Ç¤¢¤ê¡¢Âçʸ»ú¡¿¾®Ê¸»ú¤Î¶èÊ̤ò̵»ë¤·¤¿Ê¸»úÎóÈæ³Ó¤ÎºÝ¤Ë»È
365     ¤ï¤ì¤ë¡£
366       */
367
368 MSymbol Mcomplicated_case_folding;
369 /*=*/
370 /*** @} */
371 /*=*/
372
373 /***en
374     @brief Define a character property.
375
376     The mchar_define_property () function searches the m17n database
377     for a data whose tags are \<#Mchar_table, $TYPE, $SYM \>.
378     Here, $SYM is a symbol whose name is $NAME.  $TYPE must be
379     #Mstring, #Mtext, #Msymbol, #Minteger, or #Mplist.
380
381     @return
382     If the operation was successful, mchar_define_property () returns
383     $SYM.  Otherwise it returns #Mnil.  */
384
385 /***ja
386     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤òÄêµÁ¤¹¤ë.
387
388     ´Ø¿ô mchar_define_property () ¤Ï¡¢ \<#Mchar_table, $TYPE, $SYM \>
389     ¤È¤¤¤¦¥¿¥°¤ò»ý¤Ã¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò m17n ¸À¸ì¾ðÊó¥Ù¡¼¥¹¤«¤éõ¤¹¡£  
390     ¤³¤³¤Ç $SYM ¤Ï $NAME ¤È¤¤¤¦Ì¾Á°¤Î¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£$TYPE ¤Ï#Mstring,
391     #Mtext, #Msymbol, #Minteger, #Mplist ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
392
393     @return
394     ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mchar_define_property () ¤Ï$SYM ¤òÊÖ¤¹¡£
395     ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï #Mnil ¤òÊÖ¤¹¡£  */
396
397 /***
398     @errors
399     @c MERROR_DB
400
401     @seealso
402     mchar_get_prop (), mchar_put_prop ()  */
403
404 MSymbol
405 mchar_define_property (const char *name, MSymbol type)
406 {
407   MSymbol key = msymbol (name);
408   void *mdb;
409
410   if (mdatabase__finder)
411     mdb = (*mdatabase__finder) (Mchar_table, type, key, Mnil);
412   else
413     mdb = NULL;
414   mchar__define_prop (key, type, mdb);
415   return key;
416 }
417
418 /*=*/
419
420 /***en
421     @brief Get the value of a character property.
422
423     The mchar_get_prop () function searches character $C for the
424     character property whose key is $KEY.
425
426     @return
427     If the operation was successful, mchar_get_prop () returns the
428     value of the character property.  Otherwise it returns @c
429     NULL.  */
430
431 /***ja
432     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
433
434     ´Ø¿ô mchar_get_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ 
435     $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£
436
437     @return
438     ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_get_prop () ¤Ï¸«¤Ä¤«¤Ã¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
439     ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï @c NULL ¤òÊÖ¤¹¡£
440
441     @latexonly \IPAlabel{mchar_get_prop} @endlatexonly
442 */
443 /***
444     @errors
445     @c MERROR_SYMBOL, @c MERROR_DB
446
447     @seealso
448     mchar_define_property (), mchar_put_prop ()  */
449
450 void *
451 mchar_get_prop (int c, MSymbol key)
452 {
453   MCharPropRecord *record;
454
455   if (! char_prop_list)
456     return NULL;
457   record = mplist_get (char_prop_list, key);
458   if (! record)
459     return NULL;
460   if (record->mdb)
461     {
462       record->table = (*mdatabase__loader) (record->mdb);
463       if (! record->table)
464         MERROR (MERROR_DB, NULL);
465       record->mdb = NULL;
466     }
467   return mchartable_lookup (record->table, c);
468 }
469
470 /*=*/
471
472 /***en
473     @brief Set the value of a character property.
474
475     The mchar_put_prop () function searches character $C for the
476     character property whose key is $KEY and assigns $VAL to the value
477     of the found property.
478
479     @return
480     If the operation was successful, mchar_put_prop () returns 0.
481     Otherwise, it returns -1.  */
482 /***ja
483     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
484
485     ´Ø¿ô mchar_put_prop () ¤Ï¡¢Ê¸»ú $C ¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥­¡¼¤¬ $KEY 
486     ¤Ç¤¢¤ë¤â¤Î¤òõ¤·¡¢¤½¤ÎÃͤȤ·¤Æ $VAL ¤òÀßÄꤹ¤ë¡£
487
488     @return
489     ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mchar_put_prop () ¤Ï0¤òÊÖ¤¹¡£¼ºÇÔ¤·¤¿¾ì¹ç¤Ï-1¤òÊÖ¤¹¡£  */
490 /***
491     @errors
492     @c MERROR_SYMBOL, @c MERROR_DB
493
494     @seealso
495     mchar_define_property (), mchar_get_prop ()   */
496
497 int
498 mchar_put_prop (int c, MSymbol key, void *val)
499 {
500   MCharPropRecord *record;
501
502   if (! char_prop_list)
503     MERROR (MERROR_CHAR, -1);
504   record = mplist_get (char_prop_list, key);
505   if (! record)
506     return -1;
507   if (record->mdb)
508     {
509       record->table = (*mdatabase__loader) (record->mdb);
510       if (! record->table)
511         MERROR (MERROR_DB, -1);
512       record->mdb = NULL;
513     }
514   return mchartable_set (record->table, c, val);
515 }
516
517 /*=*/
518
519 /***en
520     @brief Get the char-table for a character property.
521
522     The mchar_get_prop_table () function returns a char-table that
523     contains the character property whose key is $KEY.  If $TYPE is
524     not NULL, this function stores the type of the property in the
525     place pointed by $TYPE.  See mchar_define_property () for types of
526     character property.
527
528     @return
529     If $KEY is a valid character property key, this function returns a
530     char-table.  Otherwise NULL is retuned.  */
531
532 /***ja
533     @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Îʸ»ú¥Æ¡¼¥Ö¥ë¤òÆÀ¤ë.
534
535     ´Ø¿ô mchar_get_prop_table () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ëʸ»ú¥×¥í¥Ñ¥Æ¥£
536     ¤ò´Þ¤àʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£¤â¤· $TYPE ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ $TYPE ¤Ç
537     »Ø¤µ¤ì¤ë¾ì½ê¤Ë¤½¤Îʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤ò³ÊǼ¤¹¤ë¡£Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¼ïÎà
538     ¤Ë´Ø¤·¤Æ¤Ï mchar_define_property () ¤ò¸«¤è¡£
539
540     @return
541     ¤â¤· $KEY ¤¬ÀµÅö¤Êʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤¢¤ì¤Ð¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë¤¬ÊÖ¤µ
542     ¤ì¤ë¡£¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï NULL ¤¬ÊÖ¤µ¤ì¤ë¡£  */
543
544 MCharTable *
545 mchar_get_prop_table (MSymbol key, MSymbol *type)
546 {
547   MCharPropRecord *record;
548
549   if (! char_prop_list)
550     return NULL;
551   record = mplist_get (char_prop_list, key);
552   if (! record)
553     return NULL;
554   if (record->mdb)
555     {
556       record->table = (*mdatabase__loader) (record->mdb);
557       if (! record->table)
558         MERROR (MERROR_DB, NULL);
559       record->mdb = NULL;
560     }
561   if (type)
562     *type = record->type;
563   return record->table;
564 }
565
566 /*** @} */
567
568 /*
569   Local Variables:
570   coding: euc-japan
571   End:
572 */