X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fplist.c;h=8cda7b9fb01131eb66f86218b3aeb7fbea29605d;hb=38c091dbfa19be7db173231b0b5101577de2098e;hp=0d30ee98d715ca8dc62254827c20c033163e07ad;hpb=22b2a29154f0b72bb24b7c269bceef570ae52f74;p=m17n%2Fm17n-lib.git diff --git a/src/plist.c b/src/plist.c index 0d30ee9..8cda7b9 100644 --- a/src/plist.c +++ b/src/plist.c @@ -1166,10 +1166,10 @@ mplist_put (MPlist *plist, MSymbol key, void *val) /***en @brief Get the value of a property in a property list. - The mplist_get () function searches property list $PLIST - from the beginning for a property whose key is $KEY. If such a - property is found, a pointer to its value is returned as the type - of (void *). If not found, @c NULL is returned. + The mplist_get () function searches property list $PLIST from the + beginning for a property whose key is $KEY. If such a property is + found, its value is returned as the type of (void *). If + not found, @c NULL is returned. When @c NULL is returned, there are two possibilities: one is the case where no property is found (see above); the other is the case @@ -1179,8 +1179,8 @@ mplist_put (MPlist *plist, MSymbol key, void *val) /***ja @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë. - ´Ø¿ô mplist_get () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥­¡¼¤¬ - $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤؤΥݥ¤¥ó¥¿¤ò + ´Ø¿ô mplist_get () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥­¡¼ + ¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò (void *) ·¿¤ÇÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ @c NULL ¤¬Ê֤俺ݤˤÏÆó¤Ä¤Î²ÄǽÀ­¤¬¤¢¤ë: @@ -1202,6 +1202,74 @@ mplist_get (MPlist *plist, MSymbol key) /*=*/ /***en + @brief Set the value (function pointer) of a property in a property list. + + The mplist_put_func () function is similar to mplist_put () but for + setting function pointer $FUNC in property list $PLIST for key + $KEY. */ + +/***ja + @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤Ë´Ø¿ô¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëÃͤòÀßÄꤹ¤ë. + + ´Ø¿ô mplist_put_func () ¤Ï´Ø¿ô mplist_put () ƱÍÍ¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST + Ãæ¤Ç¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ËÃͤòÀßÄꤹ¤ë¡£Ã¢¤·¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿ + $FUNC ¤Ç¤¢¤ë¡£ */ + + +/*** + @seealso + mplist_put (), M17N_FUNC () */ + +MPlist * +mplist_put_func (MPlist *plist, MSymbol key, M17NFunc func) +{ + if (key == Mnil) + MERROR (MERROR_PLIST, NULL); + while (1) + { + MPLIST_FIND (plist, key); + if (MPLIST_TAIL_P (plist) || MPLIST_VAL_FUNC_P (plist)) + break; + plist = MPLIST_NEXT (plist); + }; + + MPLIST_KEY (plist) = (key); + MPLIST_FUNC (plist) = func; + MPLIST_SET_VAL_FUNC_P (plist); + if (! plist->next) + MPLIST_NEW ((plist)->next); + return plist; +} + +/*=*/ + +/***en + @brief Get the value (function pointer) of a property in a property list. + + The mplist_get_func () function is similar to mplist_get () but for + getting a function pointer from property list $PLIST by key $KEY. */ + +/***ja + @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤«¤é¥×¥í¥Ñ¥Æ¥£¤Î´Ø¿ô¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëÃͤòÆÀ¤ë. + + ´Ø¿ô mplist_get_func () ¤Ï´Ø¿ô mplist_get () ¤ÈƱÍͤˡ¢¥×¥í¥Ñ¥Æ¥£¥ê + ¥¹¥È $PLIST Ãæ¤Ç¥­¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¡¢Ã¢¤·´Ø¿ô¥Ý¥¤¥ó¥¿¡¢ + ¤òÆÀ¤ë¡£ */ + + +/*** + @seealso + mplist_get () */ +M17NFunc +mplist_get_func (MPlist *plist, MSymbol key) +{ + MPLIST_FIND (plist, key); + return (MPLIST_TAIL_P (plist) ? NULL : MPLIST_FUNC (plist)); +} + +/*=*/ + +/***en @brief Add a property at the end of a property list. The mplist_add () function appends at the end of property list