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