1 /* symbol.c -- symbol module.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 National Institute of Advanced Industrial Science and Technology (AIST)
4 Registration Number H15PRO112
6 This file is part of the m17n library.
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.
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.
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,
24 @addtogroup m17nSymbol
26 @brief Symbol objects and API for them.
28 The m17n library uses objects called @e symbols as unambiguous
29 identifiers. Symbols are similar to atoms in the X library, but a
30 symbol can have zero or more @e symbol @e properties. A symbol
31 property consists of a @e key and a @e value, where key is also a
32 symbol and value is anything that can be cast to <tt>(void *)</tt>.
33 "The symbol property that belongs to the symbol S and
34 whose key is K" may be shortened to "K property of S".
36 Symbols are used mainly in the following three ways.
38 @li As keys of symbol properties and other properties.
40 @li To represent various objects, e.g. charsets, coding systems,
43 @li As arguments of the m17n library functions to control
46 There is a special kind of symbol, a @e managing @e key. The
47 value of a property whose key is a managing key must be a @e
48 managed @e object. See @ref m17nObject for the detail.
51 @addtogroup m17nSymbol ¥·¥ó¥Ü¥ë
53 @brief ¥·¥ó¥Ü¥ë¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
55 m17n ¥é¥¤¥Ö¥é¥ê¤Ï°ì°Õ¤Ë·è¤Þ¤ë¼±Ê̻ҤȤ·¤Æ @e ¥·¥ó¥Ü¥ë
56 ¤È¸Æ¤Ö¥ª¥Ö¥¸¥§¥¯¥È¤òÍѤ¤¤ë¡£¥·¥ó¥Ü¥ë¤Ï X ¥é¥¤¥Ö¥é¥ê¤Î¥¢¥È¥à¤È»÷¤Æ¤¤¤ë¤¬¡¢
57 0 ¸Ä°Ê¾å¤Î @e ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£ ¤ò»ý¤Ä¤³¤È¤¬¤Ç¤¤ë¡£¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Ï
58 @e ¥¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£¥¡¼¤Ï¤½¤ì¼«ÂÎ¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃͤÏ
59 <tt>(void *)</tt> ·¿¤Ë¥¥ã¥¹¥È¤Ç¤¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£¡Ö¥·¥ó¥Ü¥ë
60 S ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¥¡¼¤¬ K ¤Î¤â¤Î¡×¤ò´Êñ¤Ë¡ÖS ¤Î K
61 ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£
63 ¥·¥ó¥Ü¥ë¤ÎÍÑÅӤϼç¤Ë°Ê²¼¤Î3Ä̤ê¤Ç¤¢¤ë¡£
65 @li ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ª¤è¤Ó¾¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òɽ¤¹¡£
67 @li ʸ»ú¥»¥Ã¥È¡¢¥³¡¼¥É·Ï¡¢¥Õ¥©¥ó¥È¥»¥Ã¥È¤Ê¤É¤Î³Æ¼ï¥ª¥Ö¥¸¥§¥¯¥È¤òɽ¤¹¡£
69 @li m17n ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Î°ú¿ô¤È¤Ê¤ê¡¢´Ø¿ô¤ÎµóÆ°¤òÀ©¸æ¤¹¤ë¡£
71 @e ´ÉÍý¥¡¼ ¤È¸Æ¤Ð¤ì¤ëÆÃÊ̤ʥ·¥ó¥Ü¥ë¤¬¤¢¤ê¡¢´ÉÍý¥¡¼¤ò¥¡¼¤È¤·¤Æ»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤÏ
72 @e ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¾ÜºÙ¤Ï @ref m17nObject »²¾È¡£
77 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
78 /*** @addtogroup m17nInternal
87 #include "m17n-misc.h"
90 #include "character.h"
94 static int num_symbols;
96 #define SYMBOL_TABLE_SIZE 1024
98 static MSymbol symbol_table[SYMBOL_TABLE_SIZE];
101 hash_string (const char *str, int len)
104 const char *end = str + len;
109 c = *((unsigned char *) str++);
112 hash = ((hash << 3) + (hash >> 28) + c);
114 return hash & (SYMBOL_TABLE_SIZE - 1);
119 serialize_symbol (void *val)
121 MPlist *plist = mplist ();
123 mplist_add (plist, Msymbol, val);
128 deserialize_symbol (MPlist *plist)
130 return (MPLIST_SYMBOL_P (plist) ? MPLIST_SYMBOL (plist) : Mnil);
142 Msymbol = msymbol ("symbol");
143 Mstring = msymbol ("string");
153 for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
154 for (sym = symbol_table[i]; sym; sym = sym->next)
155 if (! MPLIST_TAIL_P (&sym->plist))
157 if (sym->plist.key->managing_key)
158 M17N_OBJECT_UNREF (MPLIST_VAL (&sym->plist));
159 M17N_OBJECT_UNREF (sym->plist.next);
160 sym->plist.key = Mnil;
165 msymbol__free_table ()
169 int freed_symbols = 0;
171 for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
173 for (sym = symbol_table[i]; sym; sym = next)
180 symbol_table[i] = NULL;
182 if (mdebug__flags[MDEBUG_FINI])
183 fprintf (stderr, "%16s %7d %7d %7d\n", "Symbol",
184 num_symbols, freed_symbols, num_symbols - freed_symbols);
190 msymbol__with_len (const char *name, int len)
192 char *p = alloca (len + 1);
194 memcpy (p, name, len);
199 /** Return a plist of symbols that has non-NULL property PROP. If
200 PROP is Mnil, return a plist of all symbols. Values of the plist
204 msymbol__list (MSymbol prop)
206 MPlist *plist = mplist ();
210 for (i = 0; i < SYMBOL_TABLE_SIZE; i++)
211 for (sym = symbol_table[i]; sym; sym = sym->next)
212 if (prop == Mnil || msymbol_get (sym, prop))
213 mplist_push (plist, sym, NULL);
218 /** Canonicalize the name of SYM, and return a symbol of the
219 canonicalized name. Canonicalization is done by this rule:
220 o convert all uppercase characters to lowercase.
221 o remove all non alpha-numeric characters.
222 o change the leading "ibm" to "cp".
223 o change the leading "windows-" to "cp".
224 o change the leading "cp" to "ibm".
225 o remove the leading "iso".
227 "ISO-8859-2" -> "88592"
230 "windows-1250" -> "cp250"
232 This function is used to canonicalize charset and coding system
236 msymbol__canonicalize (MSymbol sym)
238 char *name = sym->name;
239 /* Extra 2 bytes are for changing "cpXXX" to "ibmXXX" and
241 char *canon = (char *) alloca (strlen (name) + 2);
244 for (; *name; name++)
246 *p++ = TOLOWER (*name);
248 if (p - canon > 3 && canon[0] == 'i')
250 if (canon[1] == 'b' && canon[2] == 'm' && isdigit (canon[3]))
252 /* Change "ibmXXX" to "cpXXX". */
257 else if (canon[1] == 's' && canon[2] == 'o')
259 /* Change "isoXXX" to "XXX". */
263 else if (p - canon > 2
264 && canon[0] == 'c' && canon[1] == 'p' && isdigit (canon[2]))
266 /* Change "cpXXX" to "ibmXXX". */
267 for (; p >= canon + 2; p--)
273 else if (canon[0] == 'w' && p - canon > 7
274 && memcmp (canon + 1, "indows", 6) == 0
275 && isdigit (canon[7]))
277 /* Change "windowsXXX" to "cpXXX" */
282 return msymbol (canon);
285 MTextPropSerializeFunc msymbol__serializer = serialize_symbol;
286 MTextPropDeserializeFunc msymbol__deserializer = deserialize_symbol;
289 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
294 /*** @addtogroup m17nSymbol */
299 @brief Symbol whose name is "nil".
301 The symbol #Mnil has the name <tt>"nil"</tt> and, in general,
302 represents @e false or @e no. When coerced to "int", its value is
303 zero. #Mnil can't have any symbol property. */
305 @brief "nil" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
307 ¥·¥ó¥Ü¥ë #Mnil ¤Ï <tt>"nil"</tt>
308 ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢°ìÈ̤ˡֵ¶¡×¤Þ¤¿¤Ï¡ÖÈÝÄê¡×¤ò°ÕÌ£¤¹¤ë¡£
309 "int" ¤ËÊÑ´¹¤µ¤ì¤¿¾ì¹ç¡¢ÃÍ¤Ï 0 ¤Ç¤¢¤ë¡£
310 #Mnil ¼«¿È¤Ï¤¤¤«¤Ê¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤â»ý¤¿¤Ê¤¤¡£ */
317 @brief Symbol whose name is "t".
319 The symbol #Mt has the name <tt>"t"</tt> and, in general,
320 represents @e true or @e yes. */
322 @brief "t" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
324 ¥·¥ó¥Ü¥ë #Mt ¤Ï <tt>"t"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢°ìÈ̤ˡֿ¿¡×¤Þ¤¿¤Ï¡Ö¹ÎÄê¡×¤ò°ÕÌ£¤¹¤ë¡£ */
331 @brief Symbol whose name is "string".
333 The symbol #Mstring has the name <tt>"string"</tt> and is used
334 as an argument of the functions mchar_define_property (),
337 @brief "string" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
339 ¥·¥ó¥Ü¥ë #Mstring ¤Ï <tt>"string"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢´Ø¿ô
340 mchar_define_property () ¤Ê¤É¤Î°ú¿ô¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£ */
347 @brief Symbol whose name is "symbol".
349 The symbol #Msymbol has the name <tt>"symbol"</tt> and is used
350 as an argument of the functions mchar_define_property (),
353 @brief "symbol" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
355 ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë #Msymbol ¤Ï <tt>"symbol"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢´Ø¿ô
356 mchar_define_property () ¤Ê¤É¤Î°ú¿ô¤È¤·¤Æ»È¤ï¤ì¤ë¡£ */
365 The msymbol () function returns the canonical symbol whose name is
366 $NAME. If there is none, one is created. The created one is not
369 Symbols whose name starts by two spaces are reserved by the m17n
370 library, and are used by the library only internally.
373 This function returns the found or created symbol.
376 This function never fails. */
378 @brief ¥·¥ó¥Ü¥ë¤òÆÀ¤ë.
380 ´Ø¿ô msymbol () ¤Ï $NAME
381 ¤È¤¤¤¦Ì¾Á°¤ò»ý¤ÄÀµµ¬²½¤µ¤ì¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤Î¤è¤¦¤Ê¥·¥ó¥Ü¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢À¸À®¤¹¤ë¡£À¸À®¤µ¤ì¤¿¥·¥ó¥Ü¥ë¤Ï´ÉÍý¥¡¼¤Ç¤Ï¤Ê¤¤¡£
383 ¶õÇòʸ»úÆó¤Ä¤Ç»Ï¤Þ¤ë¥·¥ó¥Ü¥ë¤Ï m17n ¥é¥¤¥Ö¥é¥êÍѤǤ¢¤ê¡¢ÆâÉôŪ¤Ë¤Î¤ßÍѤ¤¤é¤ì¤ë¡£
386 ¤³¤Î´Ø¿ô¤Ï¸«¤Ä¤±¤¿¤«À¸À®¤·¤¿¤«¤·¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£
389 ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£
391 @latexonly \IPAlabel{msymbol} @endlatexonly */
395 msymbol_as_managing_key (), msymbol_name (), msymbol_exist () */
398 msymbol (const char *name)
405 if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
407 hash = hash_string (name, len);
409 for (sym = symbol_table[hash]; sym; sym = sym->next)
410 if (len == sym->length
411 && *name == *(sym->name)
412 && ! memcmp (name, sym->name, len))
416 MTABLE_CALLOC (sym, 1, MERROR_SYMBOL);
417 MTABLE_MALLOC (sym->name, len, MERROR_SYMBOL);
418 memcpy (sym->name, name, len);
420 sym->next = symbol_table[hash];
421 symbol_table[hash] = sym;
426 @brief Create a managing key.
428 The msymbol_as_managing_key () function returns a newly created
429 managing key whose name is $NAME. It there already exists a
430 symbol of name $NAME, it returns #Mnil.
432 Symbols whose name starts by two spaces are reserved by the m17n
433 library, and are used by the library only internally.
436 If the operation was successful, this function returns the created
437 symbol. Otherwise, it returns #Mnil. */
439 @brief ´ÉÍý¥¡¼¤òºî¤ë.
441 ´Ø¿ô msymbol_as_managing_key () ¤Ï̾Á° $NAME
442 ¤ò»ý¤Ä¿·¤·¤¯ºî¤é¤ì¤¿´ÉÍý¥¡¼¤òÊÖ¤¹¡£¤¹¤Ç¤Ë̾Á° $NAME ¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤¬¤¢¤ì¤Ð¡¢
445 ¶õÇòʸ»úÆó¤Ä¤Ç»Ï¤Þ¤ë¥·¥ó¥Ü¥ë¤Ï m17n ¥é¥¤¥Ö¥é¥êÍѤǤ¢¤ê¡¢ÆâÉôŪ¤Ë¤Î¤ßÍѤ¤¤é¤ì¤ë¡£
448 ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤ÏÀ¸À®¤·¤¿¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
456 msymbol (), msymbol_exist () */
459 msymbol_as_managing_key (const char *name)
466 if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
467 MERROR (MERROR_SYMBOL, Mnil);
468 hash = hash_string (name, len);
470 for (sym = symbol_table[hash]; sym; sym = sym->next)
471 if (len == sym->length
472 && *name == *(sym->name)
473 && ! memcmp (name, sym->name, len))
474 MERROR (MERROR_SYMBOL, Mnil);
477 MTABLE_CALLOC (sym, 1, MERROR_SYMBOL);
478 sym->managing_key = 1;
479 MTABLE_MALLOC (sym->name, len, MERROR_SYMBOL);
480 memcpy (sym->name, name, len);
482 sym->next = symbol_table[hash];
483 symbol_table[hash] = sym;
490 @brief Check if a symbol is a managing key.
492 The msymbol_is_managing_key () function checks if the symbol
493 $SYMBOL is a managing key or not.
496 Return 1 if the symbol is a managing key. Otherwise,
500 msymbol_is_managing_key (MSymbol symbol)
502 return (symbol->managing_key == 1);
508 @brief Search for a symbol that has a specified name.
510 The msymbol_exist () function searches for the symbol whose name
514 If such a symbol exists, msymbol_exist () returns that symbol.
515 Otherwise it returns the predefined symbol #Mnil.
518 This function never fails. */
520 @brief »ØÄꤵ¤ì¤¿Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òõ¤¹.
522 ´Ø¿ô msymbol_exist () ¤Ï $NAME ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òõ¤¹¡£
525 ¤â¤·¤½¤Î¤è¤¦¤Ê¥·¥ó¥Ü¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¤½¤Î¥·¥ó¥Ü¥ë¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë
529 ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£ */
532 msymbol_name (), msymbol () */
535 msymbol_exist (const char *name)
542 if (len == 3 && name[0] == 'n' && name[1] == 'i' && name[2] == 'l')
544 hash = hash_string (name, len);
546 for (sym = symbol_table[hash]; sym; sym = sym->next)
547 if (len == sym->length
548 && *name == *(sym->name)
549 && ! memcmp (name, sym->name, len))
557 @brief Get symbol name.
559 The msymbol_name () function returns a pointer to a string
560 containing the name of $SYMBOL.
563 This function never fails. */
565 @brief ¥·¥ó¥Ü¥ë¤Î̾Á°¤òÆÀ¤ë.
567 ´Ø¿ô msymbol_name () ¤Ï»ØÄꤵ¤ì¤¿¥·¥ó¥Ü¥ë $SYMBOL
568 ¤Î̾Á°¤ò´Þ¤àʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
571 ¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£ */
574 msymbol (), msymbol_exist () */
577 msymbol_name (MSymbol symbol)
579 return (symbol == Mnil ? "nil" : symbol->name);
584 @brief Set the value of a symbol property.
586 The msymbol_put () function assigns $VAL to the value of the
587 symbol property that belongs to $SYMBOL and whose key is $KEY. If
588 the symbol property already has a value, $VAL overwrites the old
589 one. Both $SYMBOL and $KEY must not be #Mnil.
591 If $KEY is a managing key, $VAL must be a managed object. In this
592 case, the reference count of the old value, if not @c NULL, is
593 decremented by one, and that of $VAL is incremented by one.
596 If the operation was successful, msymbol_put () returns 0.
597 Otherwise it returns -1 and assigns an error code to the external
598 variable #merror_code. */
600 @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ËÃͤòÀßÄꤹ¤ë.
602 ´Ø¿ô msymbol_put () ¤Ï¡¢¥·¥ó¥Ü¥ë $SYMBOL Ãæ¤Ç¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤò
603 $VAL ¤ËÀßÄꤹ¤ë¡£¤½¤Î¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Ë¤¹¤Ç¤ËÃͤ¬¤¢¤ì¤Ð¾å½ñ¤¤¹¤ë¡£
604 $SYMBOL, $KEY ¤È¤â #Mnil ¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
606 $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢¸Å¤¤Ãͤλ²¾È¿ô¤Ï
607 @c NULL ¤Ç¤Ê¤±¤ì¤Ð 1 ¸º¤é¤µ¤ì¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
610 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢msymbol_put () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1
611 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
621 msymbol_put (MSymbol symbol, MSymbol key, void *val)
623 if (symbol == Mnil || key == Mnil)
624 MERROR (MERROR_SYMBOL, -1);
625 mplist_put (&symbol->plist, key, val);
632 @brief Get the value of a symbol property.
634 The msymbol_get () function searches for the value of the symbol
635 property that belongs to $SYMBOL and whose key is $KEY. If
636 $SYMBOL has such a symbol property, its value is returned.
637 Otherwise @c NULL is returned.
640 If an error is detected, msymbol_get () returns @c NULL and
641 assigns an error code to the external variable #merror_code. */
643 @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
645 ´Ø¿ô msymbol_get () ¤Ï¡¢¥·¥ó¥Ü¥ë $SYMBOL
646 ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼¤¬ $KEY
647 ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£¤â¤·³ºÅö¤¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤¬Â¸ºß¤¹¤ì¤Ð¡¢¤½¤ì¤ÎÃͤòÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
651 ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¡¢msymbol_get () ¤Ï @c NULL
652 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
662 msymbol_get (MSymbol symbol, MSymbol key)
666 if (symbol == Mnil || key == Mnil)
668 plist = &symbol->plist;
669 MPLIST_FIND (plist, key);
670 return (MPLIST_TAIL_P (plist) ? NULL : MPLIST_VAL (plist));
675 @brief Set the value (function pointer) of a symbol property.
677 The msymbol_put_func () function is similar to msymbol_put () but for
678 setting function pointer $FUNC as the property value of $SYMBOL for
682 @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ(´Ø¿ô¥Ý¥¤¥ó¥¿)¤òÀßÄꤹ¤ë.
684 ´Ø¿ô msymbol_put_func () ¤Ï¡¢´Ø¿ô msymbol_put () ¤ÈƱÍͤˡ¢¥·¥ó¥Ü¥ë
685 $SYMBOL ¤Î¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë¡£Ã¢¤·
686 ¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿ $FUNC ¤Ç¤¢¤ë¡£ */
690 msymbol_put (), M17N_FUNC () */
692 msymbol_put_func (MSymbol symbol, MSymbol key, M17NFunc func)
694 if (symbol == Mnil || key == Mnil)
695 MERROR (MERROR_SYMBOL, -1);
696 mplist_put_func (&symbol->plist, key, func);
703 @brief Get the value (function pointer) of a symbol property.
705 The msymbol_get_func () function is similar to msymbol_get () but for
706 getting a function pointer form the property of symbol $SYMBOL. */
709 @brief ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ (´Ø¿ô¥Ý¥¤¥ó¥¿) ¤òÆÀ¤ë.
711 ´Ø¿ô msymbol_get_func () ¤Ï¡¢´Ø¿ô msymbol_get () ¤ÈƱÍͤˡ¢¥·¥ó¥Ü¥ë
712 $SYMBOL ¤¬»ý¤Ä¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òÆÀ¤ë¡£Ã¢¤·
713 ¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿¤ò¤Ç¤¢¤ë¡£ */
720 msymbol_get_func (MSymbol symbol, MSymbol key)
722 if (symbol == Mnil || key == Mnil)
724 return mplist_get_func (&symbol->plist, key);
731 /*** @addtogroup m17nDebug */
736 @brief Dump a symbol.
738 The mdebug_dump_symbol () function prints symbol $SYMBOL in a human
739 readable way to the stderr. $INDENT specifies how many columns to
740 indent the lines but the first one.
743 This function returns $SYMBOL.
748 @brief ¥·¥ó¥Ü¥ë¤ò¥À¥ó¥×¤¹¤ë.
750 ´Ø¿ô mdebug_dump_symbol () ¤Ï¥·¥ó¥Ü¥ë $symbol ¤ò stderr
751 ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
754 ¤³¤Î´Ø¿ô¤Ï $SYMBOL ¤òÊÖ¤¹¡£
760 mdebug_dump_symbol (MSymbol symbol, int indent)
767 MERROR (MERROR_DEBUG, Mnil);
768 prefix = (char *) alloca (indent + 1);
769 memset (prefix, 32, indent);
773 plist = NULL, name = "nil";
775 plist = &symbol->plist, name = symbol->name;
777 fprintf (stderr, "%s%s", prefix, name);
778 while (plist && MPLIST_KEY (plist) != Mnil)
780 fprintf (stderr, ":%s", MPLIST_KEY (plist)->name);
781 plist = MPLIST_NEXT (plist);
787 @brief Dump all symbol names.
789 The mdebug_dump_all_symbols () function prints names of all
790 symbols to the stderr. $INDENT specifies how many columns to
791 indent the lines but the first one.
794 This function returns #Mnil.
799 @brief ¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë̾¤ò¥À¥ó¥×¤¹¤ë.
801 ´Ø¿ô mdebug_dump_all_symbols () ¤Ï¡¢¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë¤Î̾Á°¤ò
802 stderr ¤Ë°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
805 ¤³¤Î´Ø¿ô¤Ï #Mnil ¤òÊÖ¤¹¡£
812 mdebug_dump_all_symbols (int indent)
819 MERROR (MERROR_DEBUG, Mnil);
820 prefix = (char *) alloca (indent + 1);
821 memset (prefix, 32, indent);
824 fprintf (stderr, "(symbol-list");
825 for (i = n = 0; i < SYMBOL_TABLE_SIZE; i++)
826 if ((sym = symbol_table[i]))
828 fprintf (stderr, "\n%s (%4d", prefix, i);
829 for (; sym; sym = sym->next, n++)
830 fprintf (stderr, " '%s'", sym->name);
831 fprintf (stderr, ")");
833 fprintf (stderr, "\n%s (total %d)", prefix, n);
834 fprintf (stderr, ")");