X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fplist.c;h=8cda7b9fb01131eb66f86218b3aeb7fbea29605d;hb=38c091dbfa19be7db173231b0b5101577de2098e;hp=d531a6b719a9d974344cc1f8d2ba1bbf899f881b;hpb=38ffc118af8122b546a12fbe4f1ab19e82cf82c8;p=m17n%2Fm17n-lib.git
diff --git a/src/plist.c b/src/plist.c
index d531a6b..8cda7b9 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public
License along with the m17n library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
02111-1307, USA. */
/***en
@@ -32,19 +32,40 @@
If the key of a property is a @e managing @e key, its @e value is
a @e managed @e object. A property list itself is a managed
- objects. */
+ objects.
+
+ If each key of a plist is one of #Msymbol, #Mtext, #Minteger, and
+ #Mplist, the plist is called as @e well-formed and represented by
+ the following notation in the documentation.
+
+@verbatim
+ PLIST ::= '(' ELEMENT * ')'
+
+ ELEMENT ::= INTEGER | SYMBOL | M-TEXT | PLIST
+
+ M-TEXT ::= '"' text data ... '"'
+@endverbatim
+
+ For instance, if a plist has four elements; integer -20, symbol of
+ name "sym", M-text of contents "abc", and plist of integer 10 and
+ symbol of name "another-symbol", it is represented as this:
+
+ (-20 sym "abc" (10 another-symbol))
+
+ */
/***ja
@addtogroup m17nPlist
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
- @e ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È (¤Þ¤¿¤Ï @e plist) ¤Ï 0 ¸Ä°Ê¾å¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥ê¥¹
- ¥È¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥¡¼ ¤È @e Ãͤ«¤é¤Ê¤ë¡£¥¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç
- ¤¢¤ê¡¢ÃÍ¤Ï (void *) ¤Ë¥¥ã¥¹¥È¤Ç¤¤ë¤â¤Î¤Ê¤é¤Ð²¿¤Ç¤âÎɤ¤¡£
+ @e ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È (¤Þ¤¿¤Ï @e plist) ¤Ï 0
+ ¸Ä°Ê¾å¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥ê¥¹¥È¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥¡¼ ¤È @e ÃÍ
+ ¤«¤é¤Ê¤ë¡£¥¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢¤ê¡¢ÃÍ¤Ï (void *)
+ ¤Ë¥¥ã¥¹¥È¤Ç¤¤ë¤â¤Î¤Ê¤é¤Ð²¿¤Ç¤âÎɤ¤¡£
- ¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤¬ @e ´ÉÍý¥¡¼ ¤Ê¤é¤Ð¡¢¤½¤Î @e ÃÍ ¤Ï@e ´ÉÍý²¼
- ¥ª¥Ö¥¸¥§¥¯¥È ¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¼«ÂΤâ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢
- ¤ë¡£ */
+ ¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤¬ @e ´ÉÍý¥¡¼ ¤Ê¤é¤Ð¡¢¤½¤Î @e ÃÍ ¤Ï @e ´ÉÍý²¼
+ @e ¥ª¥Ö¥¸¥§¥¯¥È
+ ¤Ç¤¢¤ë¡£¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¼«ÂΤâ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¡£ */
/*=*/
@@ -54,7 +75,9 @@
#include
#include
+#include
+#include "config.h"
#include "m17n.h"
#include "m17n-misc.h"
#include "internal.h"
@@ -149,12 +172,9 @@ get_byte (MStream *st)
return st->buffer[0];
}
-#define GETC(st) \
- ((st)->p < (st)->pend ? *(st)->p++ : get_byte (st))
-
+#define GETC(st) ((st)->p < (st)->pend ? *(st)->p++ : get_byte (st))
-#define UNGETC(c, st) \
- (*--(st)->p = (c))
+#define UNGETC(c, st) (--((st)->p))
/** Mapping table for reading a number. Hexadecimal chars
(0..9,A..F,a..F) are mapped to the corresponding numbers.
@@ -207,35 +227,34 @@ read_hexadesimal (MStream *st)
/** Read an M-text element from ST, and add it to LIST. Return a list
for the next element. */
+#define READ_MTEXT_BUF_SIZE 256
+
static MPlist *
-read_mtext_element (MPlist *plist, MStream *st)
+read_mtext_element (MPlist *plist, MStream *st, int skip)
{
- unsigned char buffer[1024];
- int bufsize = 1024;
- unsigned char *buf = buffer;
- int c, i;
+ union {
+ int chars[READ_MTEXT_BUF_SIZE];
+ unsigned char bytes[sizeof (int) * READ_MTEXT_BUF_SIZE];
+ } buffer;
+ unsigned char *bytes = buffer.bytes;
+ int nbytes = sizeof (int) * READ_MTEXT_BUF_SIZE;
+ int *chars = NULL;
+ int nchars = 0;
+ int c, i, j;
i = 0;
while ((c = GETC (st)) != EOF && c != '"')
{
- if (i + MAX_UTF8_CHAR_BYTES >= bufsize)
- {
- bufsize *= 2;
- if (buf == buffer)
- {
- MTABLE_MALLOC (buf, bufsize, MERROR_PLIST);
- memcpy (buf, buffer, i);
- }
- else
- MTABLE_REALLOC (buf, bufsize, MERROR_PLIST);
- }
+ int is_char = 0;
if (c == '\\')
{
c = GETC (st);
if (c == EOF)
break;
- if (c == 'x')
+ if (c == '\n')
+ continue;
+ if (c == 'x' || c == 'u')
{
int next_c;
@@ -243,18 +262,76 @@ read_mtext_element (MPlist *plist, MStream *st)
next_c = GETC (st);
if (next_c != ' ')
UNGETC (next_c, st);
+ if (c >= 0x80)
+ is_char = 1;
}
else
c = escape_mnemonic[c];
}
- buf[i++] = c;
+ if (! skip)
+ {
+ if (is_char && ! chars)
+ {
+ chars = buffer.chars;
+ for (j = i - 1; j >= 0; j--)
+ chars[j] = bytes[j];
+ nchars = READ_MTEXT_BUF_SIZE;
+ if (bytes != buffer.bytes)
+ free (bytes);
+ }
+
+ if (chars)
+ {
+ if (i + 1 >= nchars)
+ {
+ nchars *= 2;
+ if (chars == buffer.chars)
+ {
+ MTABLE_MALLOC (chars, nchars, MERROR_PLIST);
+ memcpy (chars, buffer.chars, sizeof (int) * i);
+ }
+ else
+ MTABLE_REALLOC (chars, nchars, MERROR_PLIST);
+ }
+ chars[i++] = c;
+ }
+ else
+ {
+ if (i + MAX_UTF8_CHAR_BYTES >= nbytes)
+ {
+ nbytes *= 2;
+ if (bytes == buffer.bytes)
+ {
+ MTABLE_MALLOC (bytes, nbytes, MERROR_PLIST);
+ memcpy (bytes, buffer.bytes, i);
+ }
+ else
+ MTABLE_REALLOC (bytes, nbytes, MERROR_PLIST);
+ }
+ bytes[i++] = c;
+ }
+ }
}
- MPLIST_SET_ADVANCE (plist, Mtext,
- mtext__from_data (buf, i, MTEXT_FORMAT_UTF_8, 1));
- if (buf != buffer)
- free (buf);
+ if (! skip)
+ {
+ MText *mt;
+
+ if (chars)
+ {
+ mt = mtext__from_data (chars, i, MTEXT_FORMAT_UTF_32, 1);
+ if (chars != buffer.chars)
+ free (chars);
+ }
+ else
+ {
+ mt = mtext__from_data (bytes, i, MTEXT_FORMAT_UTF_8, 1);
+ if (bytes != buffer.bytes)
+ free (bytes);
+ }
+ MPLIST_SET_ADVANCE (plist, Mtext, mt);
+ }
return plist;
}
@@ -282,22 +359,80 @@ read_character (MStream *st, int c)
}
+/** Read a symbol element from ST, and add it to LIST. Return a list
+ for the next element. */
+
+static MPlist *
+read_symbol_element (MPlist *plist, MStream *st, int c, int skip)
+{
+ unsigned char buffer[1024];
+ int bufsize = 1024;
+ unsigned char *buf = buffer;
+ int i;
+
+ i = 0;
+ while (c != EOF
+ && c > ' '
+ && c != ')' && c != '(' && c != '"')
+ {
+ if (i >= bufsize)
+ {
+ bufsize *= 2;
+ if (buf == buffer)
+ {
+ MTABLE_MALLOC (buf, bufsize, MERROR_PLIST);
+ memcpy (buf, buffer, i);
+ }
+ else
+ MTABLE_REALLOC (buf, bufsize, MERROR_PLIST);
+ }
+ if (c == '\\')
+ {
+ c = GETC (st);
+ if (c == EOF)
+ break;
+ c = escape_mnemonic[c];
+ }
+ if (! skip)
+ buf[i++] = c;
+ c = GETC (st);
+ }
+
+ if (c > ' ')
+ UNGETC (c, st);
+ if (! skip)
+ {
+ buf[i] = 0;
+ MPLIST_SET_ADVANCE (plist, Msymbol, msymbol ((char *) buf));
+ if (buf != buffer)
+ free (buf);
+ }
+ return plist;
+}
+
/** Read an integer element from ST, and add it to LIST. Return a
list for the next element. It is assumed that we have already
read the character C. */
static MPlist *
-read_integer_element (MPlist *plist, MStream *st, int c)
+read_integer_element (MPlist *plist, MStream *st, int c, int skip)
{
int num;
- if (c == '0' || c == '#')
+ if (c == '#')
{
c = GETC (st);
- if (c == 'x')
- num = read_hexadesimal (st);
- else
- num = read_decimal (st, c);
+ if (c != 'x')
+ {
+ UNGETC (c, st);
+ return read_symbol_element (plist, st, '#', skip);
+ }
+ num = read_hexadesimal (st);
+ }
+ else if (c == '0')
+ {
+ c = GETC (st);
+ num = (c == 'x' ? read_hexadesimal (st) : read_decimal (st, c));
}
else if (c == '?')
{
@@ -323,57 +458,20 @@ read_integer_element (MPlist *plist, MStream *st, int c)
}
}
else if (c == '-')
- num = - read_decimal (st, GETC (st));
- else
- num = read_decimal (st, c);
-
- MPLIST_SET_ADVANCE (plist, Minteger, (void *) num);
- return plist;
-}
-
-/** Read a symbol element from ST, and add it to LIST. Return a list
- for the next element. */
-
-static MPlist *
-read_symbol_element (MPlist *plist, MStream *st)
-{
- unsigned char buffer[1024];
- int bufsize = 1024;
- unsigned char *buf = buffer;
- int c, i;
-
- i = 0;
- while ((c = GETC (st)) != EOF
- && c > ' '
- && c != ')' && c != '(' && c != '"')
{
- if (i >= bufsize)
- {
- bufsize *= 2;
- if (buf == buffer)
- {
- MTABLE_MALLOC (buf, bufsize, MERROR_PLIST);
- memcpy (buf, buffer, i);
- }
- else
- MTABLE_REALLOC (buf, bufsize, MERROR_PLIST);
- }
- if (c == '\\')
+ c = GETC (st);
+ if (c < '0' || c > '9')
{
- c = GETC (st);
- if (c == EOF)
- break;
- c = escape_mnemonic[c];
+ UNGETC (c, st);
+ return read_symbol_element (plist, st, '-', skip);
}
- buf[i++] = c;
+ num = - read_decimal (st, c);
}
+ else
+ num = read_decimal (st, c);
- buf[i] = 0;
- MPLIST_SET_ADVANCE (plist, Msymbol, msymbol ((char *) buf));
- if (buf != buffer)
- free (buf);
- if (c > ' ')
- UNGETC (c, st);
+ if (! skip)
+ MPLIST_SET_ADVANCE (plist, Minteger, (void *) num);
return plist;
}
@@ -385,10 +483,14 @@ read_symbol_element (MPlist *plist, MStream *st)
'0'..'9', '-': integer
'?': integer representing character code
the other ASCII letters: symbol
-*/
+
+ If KEYS is not NULL, it is a plist contains target keys and stop
+ keys. In this caes, read only a plist whose key has value 1 in
+ KEYS, and return NULL when we encounter a plist whose key has value
+ 0 in KEYS while skipping any other elements. */
static MPlist *
-read_element (MPlist *plist, MStream *st)
+read_element (MPlist *plist, MStream *st, MPlist *keys)
{
int c;
@@ -409,45 +511,99 @@ read_element (MPlist *plist, MStream *st)
MPLIST_NEW (pl);
p = pl;
- while ((p = read_element (p, st)));
- MPLIST_SET_ADVANCE (plist, Mplist, pl);
+ p = read_element (p, st, NULL);
+ if (keys && p && MPLIST_SYMBOL_P (pl))
+ {
+ if (MPLIST_TAIL_P (keys))
+ {
+ while ((p = read_element (p, st, NULL)));
+ MPLIST_SET_ADVANCE (plist, Mplist, pl);
+ return NULL;
+ }
+ else
+ {
+ MPlist *p0 = keys;
+
+ MPLIST_FIND (p0, MPLIST_SYMBOL (pl));
+ if (! MPLIST_TAIL_P (p0) && ! MPLIST_VAL (p0))
+ {
+ M17N_OBJECT_UNREF (pl);
+ return NULL;
+ }
+ while ((p = read_element (p, st, NULL)));
+ if (! MPLIST_TAIL_P (p0))
+ {
+ MPLIST_SET_ADVANCE (plist, Mplist, pl);
+ return NULL;
+ }
+ else
+ M17N_OBJECT_UNREF (pl);
+ }
+ }
+ else
+ {
+ if (p)
+ while ((p = read_element (p, st, NULL)));
+ MPLIST_SET_ADVANCE (plist, Mplist, pl);
+ }
return plist;
}
if (c == '"')
- return read_mtext_element (plist, st);
+ return (read_mtext_element (plist, st, keys ? 1 : 0));
if ((c >= '0' && c <= '9') || c == '-' || c == '?' || c == '#')
- return read_integer_element (plist, st, c);
+ return (read_integer_element (plist, st, c, keys ? 1 : 0));
if (c == EOF || c == ')')
return NULL;
- UNGETC (c, st);
- return read_symbol_element (plist, st);
+ return (read_symbol_element (plist, st, c, keys ? 1 : 0));
}
-void
-write_element (MText *mt, MPlist *plist)
+#define PUTC(MT, C) \
+ do { \
+ if (MT) \
+ mtext_cat_char ((MT), (C)); \
+ else \
+ putc ((C), stderr); \
+ } while (0);
+
+#define PUTS(MT, STR) \
+ do { \
+ if (MT) \
+ MTEXT_CAT_ASCII ((MT), (STR)); \
+ else \
+ fputs ((STR), stderr); \
+ } while (0)
+
+
+static void
+write_symbol (MText *mt, MSymbol sym)
{
- if (MPLIST_SYMBOL_P (plist))
+ if (sym == Mnil)
+ {
+ PUTS (mt, "nil");
+ }
+ else
{
- MSymbol sym = MPLIST_SYMBOL (plist);
+ char *name = MSYMBOL_NAME (sym);
- if (sym == Mnil)
+ if (isdigit (*name))
+ PUTC (mt, '\\');
+ while (*name)
{
- MTEXT_CAT_ASCII (mt, "nil");
+ if (*name <= ' ' || *name == '\\' || *name == '"'
+ || *name == '(' || *name == ')')
+ PUTC (mt, '\\');
+ PUTC (mt, *name);
+ name++;
}
- else
- {
- char *name = MSYMBOL_NAME (sym);
- char *buf = alloca (MSYMBOL_NAMELEN (sym) * 2 + 1), *p = buf;
+ }
+}
- while (*name)
- {
- if (*name <= ' ' || *name == '"' || *name == ')' || *name == ')')
- *p++ = '\\';
- *p++ = *name++;
- }
- *p = '\0';
- MTEXT_CAT_ASCII (mt, buf);
- }
+static void
+write_element (MText *mt, MPlist *plist, int indent)
+{
+ if (MPLIST_SYMBOL_P (plist))
+ {
+ write_symbol (mt, MPLIST_SYMBOL (plist));
}
else if (MPLIST_INTEGER_P (plist))
{
@@ -455,91 +611,121 @@ write_element (MText *mt, MPlist *plist)
char buf[128];
sprintf (buf, "%d", num);
- MTEXT_CAT_ASCII (mt, buf);
+ PUTS (mt, buf);
}
else if (MPLIST_PLIST_P (plist))
{
MPlist *pl;
+ int newline = 0;
plist = MPLIST_PLIST (plist);
- mtext_cat_char (mt, '(');
+ PUTC (mt, '(');
+ if (indent >= 0)
+ indent++;
MPLIST_DO (pl, plist)
{
if (pl != plist)
- mtext_cat_char (mt, ' ');
- write_element (mt, pl);
+ {
+ if (indent > 0 && (MPLIST_PLIST_P (pl) || MPLIST_MTEXT_P (pl)))
+ newline = 1;
+ if (newline)
+ {
+ int i;
+
+ PUTC (mt, '\n');
+ for (i = 1; i < indent; i++)
+ PUTC (mt, ' ');
+ }
+ PUTC (mt, ' ');
+ }
+ write_element (mt, pl, indent);
+ if (indent >= 0)
+ newline = (MPLIST_PLIST_P (pl) || MPLIST_MTEXT_P (pl));
}
- mtext_cat_char (mt, ')');
+ PUTC (mt, ')');
}
else if (MPLIST_MTEXT_P (plist))
{
- mtext_cat_char (mt, '"');
- /* Not yet implemnted */
- mtext_cat_char (mt, '"');
- }
-}
+ MText *this_mt = MPLIST_MTEXT (plist);
+ int from = 0, to = mtext_nchars (this_mt);
+ int stop1 = 0, stop2 = 0;
-/* Support functions for mdebug_dump_plist. */
-
-static void
-dump_string (char *str)
-{
- char *p = str, *pend = p + strlen (p), *new, *p1;
-
- new = p1 = alloca ((pend - p) * 4 + 1);
- while (p < pend)
- {
- if (*p < 0)
+ if (! mt && this_mt->format > MTEXT_FORMAT_UTF_8)
{
- sprintf (p1, "\\x%02X", (unsigned char) *p);
- p1 += 4;
+ this_mt = mtext_dup (this_mt);
+ mtext__adjust_format (this_mt, MTEXT_FORMAT_UTF_8);
}
- else if (*p < ' ')
+
+ PUTC (mt, '"');
+ while (1)
{
- *p1++ = '^';
- *p1++ = *p + '@';
+ int stop, escaped;
+
+ if (from == stop1)
+ {
+ if ((stop1 = mtext_character (this_mt, from, to, '"')) < 0)
+ stop1 = to;
+ }
+ if (from == stop2)
+ {
+ if ((stop2 = mtext_character (this_mt, from, to, '\\')) < 0)
+ stop2 = to;
+ }
+ if (stop1 < stop2)
+ stop = stop1++, escaped = '"';
+ else
+ stop = stop2++, escaped = '\\';
+ if (mt)
+ mtext_copy (mt, mtext_nchars (mt), this_mt, from, stop);
+ else
+ {
+ unsigned char *data = MTEXT_DATA (this_mt);
+ unsigned char *beg = data + mtext__char_to_byte (this_mt, from);
+ unsigned char *end = data + mtext__char_to_byte (this_mt, stop);
+
+ while (beg < end)
+ putc (*beg, stderr), beg++;
+ }
+ if (stop == to)
+ break;
+ PUTC (mt, '\\');
+ PUTC (mt, escaped);
+ from = stop + 1;
}
- else if (*p == ' ')
+ PUTC (mt, '"');
+ if (this_mt != MPLIST_MTEXT (plist))
+ M17N_OBJECT_UNREF (this_mt);
+ }
+ else if (MPLIST_STRING_P (plist))
+ {
+ char *str = MPLIST_STRING (plist);
+
+ if (mt)
{
- *p1++ = '\\';
- *p1++ = ' ';
+ MText *this_mt = mtext__from_data (str, strlen (str),
+ MTEXT_FORMAT_UTF_8, 0);
+
+ mtext_copy (mt, mtext_nchars (mt),
+ this_mt, 0, mtext_nchars (this_mt));
+ M17N_OBJECT_UNREF (this_mt);
}
else
- *p1++ = *p;
- p++;
+ fprintf (stderr, "%s", str);
}
- *p1 = '\0';
- fprintf (stderr, "%s", new);
-}
-
-static void
-dump_plist_element (MPlist *plist, int indent)
-{
- char *prefix = (char *) alloca (indent + 1);
- MSymbol key;
-
- memset (prefix, 32, indent);
- prefix[indent] = 0;
-
- key = MPLIST_KEY (plist);
- fprintf (stderr, "(%s(#%d) ", msymbol_name (MPLIST_KEY (plist)),
- plist->control.ref_count);
- if (key == Msymbol)
- dump_string (msymbol_name (MPLIST_SYMBOL (plist)));
- else if (key == Mtext)
- mdebug_dump_mtext (MPLIST_MTEXT (plist), indent, 0);
- else if (key == Minteger)
- fprintf (stderr, "%x", MPLIST_INTEGER (plist));
- else if (key == Mstring)
- fprintf (stderr, "\"%s\"", MPLIST_STRING (plist));
- else if (key == Mplist)
+ else
{
- fprintf (stderr, "\n%s", prefix);
- mdebug_dump_plist (MPLIST_PLIST (plist), indent);
+ write_symbol (mt, MPLIST_KEY (plist));
+ PUTC (mt, ':');
+ if (MPLIST_NESTED_P (plist))
+ write_element (mt, plist, indent + 1);
+ else
+ {
+ char buf[128];
+
+ sprintf (buf, "%04X", (unsigned) MPLIST_VAL (plist));
+ PUTS (mt, buf);
+ }
}
- else
- fprintf (stderr, "0x%X", (unsigned) MPLIST_VAL (plist));
- fprintf (stderr, ")");
}
@@ -549,7 +735,7 @@ mplist__init ()
{
int i;
- plist_table.count = 0;
+ M17N_OBJECT_ADD_ARRAY (plist_table, "Plist");
Minteger = msymbol ("integer");
Mplist = msymbol_as_managing_key ("plist");
@@ -579,7 +765,6 @@ mplist__init ()
void
mplist__fini (void)
{
- mdebug__report_object ("Plist", &plist_table);
}
@@ -604,7 +789,7 @@ mplist__from_plist (MPlist *plist)
key = MPLIST_SYMBOL (plist);
plist = MPLIST_NEXT (plist);
type = MPLIST_KEY (plist);
- if (type->managing_key)
+ if (type->managing_key && MPLIST_VAL (plist))
M17N_OBJECT_REF (MPLIST_VAL (plist));
MPLIST_SET_ADVANCE (p, key, MPLIST_VAL (plist));
plist = MPLIST_NEXT (plist);
@@ -642,7 +827,7 @@ mplist__from_alist (MPlist *plist)
MPlist *
-mplist__from_file (FILE *fp)
+mplist__from_file (FILE *fp, MPlist *keys)
{
MPlist *plist, *pl;
MStream st;
@@ -652,7 +837,7 @@ mplist__from_file (FILE *fp)
st.p = st.pend = st.buffer;
MPLIST_NEW (plist);
pl = plist;
- while ((pl = read_element (pl, &st)));
+ while ((pl = read_element (pl, &st, keys)));
return plist;
}
@@ -701,24 +886,104 @@ mplist__from_string (unsigned char *str, int n)
st.pend = str + n;
MPLIST_NEW (plist);
pl = plist;
- while ((pl = read_element (pl, &st)));
+ while ((pl = read_element (pl, &st, NULL)));
return plist;
}
int
-mplist__serialize (MText *mt, MPlist *plist)
+mplist__serialize (MText *mt, MPlist *plist, int pretty)
{
MPlist *pl;
+ int separator = pretty ? '\n' : ' ';
MPLIST_DO (pl, plist)
{
if (pl != plist)
- mtext_cat_char (mt, ' ');
- write_element (mt, pl);
+ mtext_cat_char (mt, separator);
+ write_element (mt, pl, pretty ? 0 : -1);
}
+ if (pretty)
+ mtext_cat_char (mt, separator);
return 0;
}
+/**en
+ @brief Concatenate two plists.
+
+ The mplist__conc () function concatenates plist $TAIL at the end of
+ plist $PLIST and return $PLIST. If $TAIL is empty, return $PLIST
+ without modifying it. */
+
+MPlist *
+mplist__conc (MPlist *plist, MPlist *tail)
+{
+ MPlist *pl;
+
+ if (MPLIST_TAIL_P (tail))
+ return plist;
+ MPLIST_DO (pl, plist);
+ MPLIST_KEY (pl) = MPLIST_KEY (tail);
+ MPLIST_VAL (pl) = MPLIST_VAL (tail);
+ if (MPLIST_KEY (pl)->managing_key)
+ M17N_OBJECT_REF (MPLIST_VAL (pl));
+ tail = MPLIST_NEXT (tail);
+ MPLIST_NEXT (pl) = tail;
+ M17N_OBJECT_REF (tail);
+ return plist;
+}
+
+/*=*/
+/**en
+ @brief Discard a property at the beginning of a property list.
+
+ The mplist__pop_unref () function removes a property at the
+ beginning of property list $PLIST, and if the property value is a
+ managed object, unref it. As a result, the second key and value
+ of the original $PLIST become the first of those of the new
+ $PLIST. */
+
+void
+mplist__pop_unref (MPlist *plist)
+{
+ MSymbol key;
+ void *val;
+
+ if (MPLIST_TAIL_P (plist))
+ return;
+ key = MPLIST_KEY (plist);
+ val = mplist_pop (plist);
+ if (key->managing_key)
+ M17N_OBJECT_UNREF (val);
+}
+
+/**en
+ @brief Search for an element of an alist represented by a plist.
+
+ The mplist__assq () function treats $PLIST as an association list
+ (elements are plists (key is #Mplist) whose first element is a
+ symbol (key is #Msymbol)), and find an element whose first element
+ has key #Msymbol and value $KEY.
+
+ Non-plist elements of $PLIST are ignored.
+
+ @return
+ This function returns a found element or NULL if no element
+ matches with $KEY. */
+
+MPlist *
+mplist__assq (MPlist *plist, MSymbol key)
+{
+ MPLIST_DO (plist, plist)
+ if (MPLIST_PLIST_P (plist))
+ {
+ MPlist *pl = MPLIST_PLIST (plist);
+
+ if (MPLIST_SYMBOL_P (pl) && MPLIST_SYMBOL (pl) == key)
+ return plist;
+ }
+ return NULL;
+}
+
/*** @} */
#endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
@@ -732,7 +997,7 @@ mplist__serialize (MText *mt, MPlist *plist)
/***en
@brief Symbol whose name is "integer".
- The symbol @c Minteger has the name "integer". A value
+ The symbol @c Minteger has the name "integer". The value
of a property whose key is @c Minteger must be an integer. */
/***ja
@brief "integer" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
@@ -752,9 +1017,9 @@ MSymbol Minteger;
/***ja
@brief "plist" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
- ¥·¥ó¥Ü¥ë @c Mplist ¤Ï "plist" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¤³¤ì¤Ï´É
- Íý¥¡¼¤Ç¤¢¤ë¡£¥¡¼¤¬ @c Mplist ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¤Ï plist ¤Ç¤Ê¤¯
- ¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
+ ¥·¥ó¥Ü¥ë @c Mplist ¤Ï "plist"
+ ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¤³¤ì¤Ï´ÉÍý¥¡¼¤Ç¤¢¤ë¡£¥¡¼¤¬ @c Mplist
+ ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¤Ï plist ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
MSymbol Mplist;
/*=*/
@@ -769,9 +1034,9 @@ MSymbol Mplist;
/***ja
@brief "mtext" ¤ò̾Á°¤È¤·¤Æ»ý¤Ä¥·¥ó¥Ü¥ë.
- ¥·¥ó¥Ü¥ë @c Mtext ¤Ï "mtext" ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä´ÉÍý¥¡¼¤Ç¤¢
- ¤ë¡£¥¡¼¤¬ @c Mtext ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¤Ï M-text ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê
- ¤¤¡£ */
+ ¥·¥ó¥Ü¥ë @c Mtext ¤Ï "mtext"
+ ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä´ÉÍý¥¡¼¤Ç¤¢¤ë¡£¥¡¼¤¬ @c Mtext
+ ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ÎÃÍ¤Ï M-text ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
MSymbol Mtext;
@@ -790,8 +1055,7 @@ MSymbol Mtext;
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë.
- ´Ø¿ô mplist () ¤ÏŤµ 0 ¤Î¿·¤·¤¯ºî¤é¤ì¤¿¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯
- ¥È¤òÊÖ¤¹¡£
+ ´Ø¿ô mplist () ¤ÏŤµ 0 ¤Î¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤ò¿·¤·¤¯ºî¤Ã¤ÆÊÖ¤¹¡£
@returns
¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£
@@ -800,7 +1064,7 @@ MSymbol Mtext;
¤³¤Î´Ø¿ô¤Ï·è¤·¤Æ¼ºÇÔ¤·¤Ê¤¤¡£ */
MPlist *
-mplist ()
+mplist (void)
{
MPlist *plist;
@@ -824,8 +1088,8 @@ mplist ()
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ò¥³¥Ô¡¼¤¹¤ë.
- ´Ø¿ô mplist_copy () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò¥³¥Ô¡¼¤¹¤ë¡£¥³¥Ô¡¼¤Î¤¹¤Ù¤Æ¤Î
- Ãͤϥ³¥Ô¡¼¸µ $PLIST ¤ÎÃͤÈƱ¤¸¤Ç¤¢¤ë¡£
+ ´Ø¿ô mplist_copy () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+ ¤ò¥³¥Ô¡¼¤¹¤ë¡£¥³¥Ô¡¼¤Î¤¹¤Ù¤Æ¤ÎÃͤϥ³¥Ô¡¼¸µ $PLIST ¤ÎÃͤÈƱ¤¸¤Ç¤¢¤ë¡£
@return
¤³¤Î´Ø¿ô¤Ï¿·¤·¤¯ºî¤é¤ì¤¿¡¢$PLIST ¤Î¥³¥Ô¡¼¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òÊÖ¤¹¡£
@@ -866,19 +1130,19 @@ mplist_copy (MPlist *plist)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÀßÄꤹ¤ë.
- ´Ø¿ô mplist_put () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥¡¼
- ¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò $VALUE ¤Ë
- Êѹ¹¤¹¤ë¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¥¡¼¤¬ $KEY ¤ÇÃͤ¬ $VALUE ¤Ç¤¢¤ë¿·¤·¤¤
- ¥×¥í¥Ñ¥Æ¥£¤¬$PLIST ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£$KEY ¤È $VAL ¤ËÂФ¹¤ëÀ©¸Â¤Ë
- ¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
+ ´Ø¿ô mplist_put () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥¡¼¤¬
+ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò $VALUE
+ ¤ËÊѹ¹¤¹¤ë¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢¥¡¼¤¬ $KEY ¤ÇÃͤ¬ $VALUE
+ ¤Ç¤¢¤ë¿·¤·¤¤¥×¥í¥Ñ¥Æ¥£¤¬ $PLIST ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£$KEY ¤È $VAL
+ ¤ËÂФ¹¤ëÀ©¸Â¤Ë¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
- $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
- ¤³¤Î¾ì¹ç¡¢¸Å¤¤Ãͤλ²¾È¿ô¤Ï @c NULL ¤Ç¤Ê¤±¤ì¤Ð 1 ¸º¤é¤µ¤ì¡¢$VAL ¤Î
- »²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+ $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢
+ $VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢¸Å¤¤Ãͤλ²¾È¿ô¤Ï
+ @c NULL ¤Ç¤Ê¤±¤ì¤Ð 1 ¸º¤é¤µ¤ì¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
@return
- ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_put () ¤ÏÊѹ¹¤µ¤ì¤¿¤«Äɲ䵤줿Í×ÁǤ«¤é»Ï
- ¤Þ¤ë $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
+ ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_put () ¤ÏÊѹ¹¤µ¤ì¤¿¤«Äɲ䵤줿Í×ÁǤ«¤é»Ï¤Þ¤ë
+ $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
MPlist *
mplist_put (MPlist *plist, MSymbol key, void *val)
@@ -890,7 +1154,8 @@ mplist_put (MPlist *plist, MSymbol key, void *val)
{
if (! MPLIST_TAIL_P (plist))
M17N_OBJECT_UNREF (MPLIST_VAL (plist));
- M17N_OBJECT_REF (val);
+ if (val)
+ M17N_OBJECT_REF (val);
}
MPLIST_SET (plist, key, val);
return plist;
@@ -901,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
@@ -914,13 +1179,13 @@ mplist_put (MPlist *plist, MSymbol key, void *val)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÆÀ¤ë.
- ´Ø¿ô mplist_get () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢
- ¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤؤΥݥ¤
- ¥ó¥¿¤ò (void *) ·¿¤ÇÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
+ ´Ø¿ô mplist_get () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢¥¡¼
+ ¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ÎÃͤò
+ (void *) ·¿¤ÇÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
- @c NULL ¤¬Ê֤俺ݤˤÏÆó¤Ä¤Î²ÄǽÀ¤¬¤¢¤ë:¾åµ¤Î¤è¤¦¤Ë¥×¥í¥Ñ¥Æ¥£¤¬
- ¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤È¡¢¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ê¡¢¤½¤ÎÃͤ¬ @c NULL ¤Ç
- ¤¢¤ë¾ì¹ç¤Ç¤¢¤ë¡£¤³¤ì¤é¤ò¶èÊ̤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï´Ø¿ô
+ @c NULL ¤¬Ê֤俺ݤˤÏÆó¤Ä¤Î²ÄǽÀ¤¬¤¢¤ë:
+ ¾åµ¤Î¤è¤¦¤Ë¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤È¡¢¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ê¡¢¤½¤ÎÃͤ¬
+ @c NULL ¤Ç¤¢¤ë¾ì¹ç¤Ç¤¢¤ë¡£¤³¤ì¤é¤ò¶èÊ̤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï´Ø¿ô
mplist_find_by_key () ¤ò»È¤¦¤³¤È¡£ */
/***
@@ -937,11 +1202,79 @@ 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
- $PLIST a property whose key is $KEY and value is $VAL. $KEY can
- be any symbol other than @c Mnil.
+ $PLIST a property whose key is $KEY and value is $VAL. $KEY can
+ be any symbol other than @c Mnil.
If $KEY is a managing key, $VAL must be a managed object. In this
case, the reference count of $VAL is incremented by one.
@@ -954,14 +1287,13 @@ mplist_get (MPlist *plist, MSymbol key)
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈËöÈø¤Ë¥×¥í¥Ñ¥Æ¥£¤òÄɲ乤ë.
´Ø¿ô mplist_add () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎËöÈø¤Ë¥¡¼¤¬ $KEY
- ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤òÄɲ乤롣$KEY ¤Ï¡¢@c Mnil °Ê³°¤ÎǤ
- °Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
+ ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤òÄɲ乤롣$KEY ¤Ï¡¢@c Mnil °Ê³°¤ÎǤ°Õ¤Î¥·¥ó¥Ü¥ë¤Ç¤è¤¤¡£
- $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
- ¤³¤Î¾ì¹ç¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+ $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
+ $VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
@return
- ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_add () ¤ÏÄɲ䵤줿Í×ÁǤ«¤é»Ï¤Þ¤ë $PLIST
+ ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mplist_add () ¤ÏÄɲ䵤줿Í×ÁǤ«¤é»Ï¤Þ¤ë $PLIST
¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
MPlist *
@@ -970,7 +1302,7 @@ mplist_add (MPlist *plist, MSymbol key, void *val)
if (key == Mnil)
MERROR (MERROR_PLIST, NULL);
MPLIST_FIND (plist, Mnil);
- if (key->managing_key)
+ if (val && key->managing_key)
M17N_OBJECT_REF (val);
MPLIST_KEY (plist) = key;
MPLIST_VAL (plist) = val;
@@ -981,10 +1313,10 @@ mplist_add (MPlist *plist, MSymbol key, void *val)
/*=*/
/***en
- @brief Push a property to a property list.
+ @brief Add a property at the beginning of a property list.
- The mplist_push () function pushes at the top of property list
- $PLIST a property whose key is $KEY and value is $VAL.
+ The mplist_push () function inserts at the beginning of property
+ list $PLIST a property whose key is $KEY and value is $VAL.
If $KEY is a managing key, $VAL must be a managed object. In this
case, the reference count of $VAL is incremented by one.
@@ -993,17 +1325,17 @@ mplist_add (MPlist *plist, MSymbol key, void *val)
If the operation was successful, this function returns $PLIST.
Otherwise, it returns @c NULL. */
/***ja
- @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥×¥Ã¥·¥å¤¹¤ë.
+ @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎÀèƬ¤Ë¥×¥í¥Ñ¥Æ¥£¤òÁÞÆþ¤¹¤ë.
- ´Ø¿ô mplist_push () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤Î¾å¤Ë¤Ë¥¡¼¤¬ $KEY
- ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ò¥×¥Ã¥·¥å¤¹¤ë¡£
+ ´Ø¿ô mplist_push () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎÀèƬ¤Ë¥¡¼¤¬ $KEY
+ ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÁÞÆþ¤¹¤ë¡£
- $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
- ¤³¤Î¾ì¹ç¡¢$VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
+ $KEY ¤¬´ÉÍý¥¡¼¤Ê¤é¤Ð¡¢$VAL ¤Ï´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
+ $VAL ¤Î»²¾È¿ô¤Ï 1 Áý¤ä¤µ¤ì¤ë¡£
@return
- ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¤³¤Î´Ø¿ô¤Ï $PLIST ¤òÊÖ¤·¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð@c NULL ¤ò
- ÊÖ¤¹¡£ */
+ ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¤³¤Î´Ø¿ô¤Ï $PLIST ¤òÊÖ¤·¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð@c NULL
+ ¤òÊÖ¤¹¡£ */
MPlist *
mplist_push (MPlist *plist, MSymbol key, void *val)
@@ -1015,9 +1347,9 @@ mplist_push (MPlist *plist, MSymbol key, void *val)
MPLIST_NEW (pl);
MPLIST_KEY (pl) = MPLIST_KEY (plist);
MPLIST_VAL (pl) = MPLIST_VAL (plist);
- pl->next = plist->next;
+ MPLIST_NEXT (pl) = MPLIST_NEXT (plist);
plist->next = pl;
- if (key->managing_key)
+ if (val && key->managing_key)
M17N_OBJECT_REF (val);
MPLIST_KEY (plist) = key;
MPLIST_VAL (plist) = val;
@@ -1027,25 +1359,24 @@ mplist_push (MPlist *plist, MSymbol key, void *val)
/*=*/
/***en
- @brief Pop a property from a property list.
+ @brief Remove a property at the beginning of a property list.
- The mplist_pop () function pops the topmost property from property
- list $PLIST. As a result, the key and value of $PLIST becomes
- those of the next of $PLIST.
+ The mplist_pop () function removes a property at the beginning of
+ property list $PLIST. As a result, the second key and value of
+ the $PLIST become the first ones.
@return
If the operation was successful, this function return the value of
the just popped property. Otherwise, it returns @c NULL. */
/***ja
- @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ý¥Ã¥×¤¹¤ë.
+ @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎÀèƬ¤«¤é¥×¥í¥Ñ¥Æ¥£¤òºï½ü¤¹¤ë.
- The mplist_pop () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤«¤éºÇ¾å°Ì¤Î¥×¥í¥Ñ¥Æ¥£
- ¤ò¥Ý¥Ã¥×¤¹¤ë¡£·ë²Ì¤È¤·¤Æ $PLIST ¤Î¥¡¼¤ÈÃÍ¤Ï $PLIST ¤Î¼¡¤Î¤â¤Î¤Î¥¡¼
- ¤ÈÃͤˤʤ롣
+ ´Ø¿ô mplist_pop () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎÀèƬ¤Î¥×¥í¥Ñ¥Æ¥£¤òºï
+ ½ü¤¹¤ë¡£·ë²Ì¤È¤·¤Æ¡¢¸µ¤Î2ÈÖÌܤΥ¡¼¤ÈÃͤ¬ÀèƬ¤Î¥¡¼¤ÈÃͤˤʤ롣
@return
- ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ï¥Ý¥Ã¥×¤µ¤ì¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£¤½¤¦
- ¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
+ ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢¤³¤Î´Ø¿ô¤Ïºï½ü¤µ¤ì¤¿¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
+ @c NULL ¤òÊÖ¤¹¡£ */
void *
mplist_pop (MPlist *plist)
@@ -1056,14 +1387,14 @@ mplist_pop (MPlist *plist)
if (MPLIST_TAIL_P (plist))
return NULL;
val = MPLIST_VAL (plist);
- next = plist->next;
+ next = MPLIST_NEXT (plist);
MPLIST_KEY (plist) = MPLIST_KEY (next);
MPLIST_VAL (plist) = MPLIST_VAL (next);
if (MPLIST_KEY (plist) != Mnil
&& MPLIST_KEY (plist)->managing_key
&& MPLIST_VAL (plist))
M17N_OBJECT_REF (MPLIST_VAL (plist));
- plist->next = next->next;
+ MPLIST_NEXT (plist) = MPLIST_NEXT (next);
if (plist->next)
M17N_OBJECT_REF (plist->next);
M17N_OBJECT_UNREF (next);
@@ -1082,15 +1413,14 @@ mplist_pop (MPlist *plist)
If $KEY is @c Mnil, it returns a sublist of $PLIST whose
first element is the last one of $PLIST. */
/***ja
- @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤Î¥¡¼¤ò»ý¤Ä¥ª¥Ö¥¸¥§¥¯¥È¤òõ¤¹.
+ @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤Î¥¡¼¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤òõ¤¹.
- ´Ø¿ô mplist_find_by_key () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤éõ
- ¤·¤Æ¡¢¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í
- ¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð@c NULL
- ¤òÊÖ¤¹¡£
+ ´Ø¿ô mplist_find_by_key () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+ ¤ò»Ï¤á¤«¤éõ ¤·¤Æ¡¢¥¡¼¤¬ $KEY
+ ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë
+ $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£
- $KEY ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢$PLIST ¤ÎºÇ¸å¤ÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤ò
- ÊÖ¤¹¡£ */
+ $KEY ¤¬ @c Mnil ¤Ê¤é¤Ð¡¢$PLIST ¤ÎºÇ¸å¤ÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£ */
MPlist *
mplist_find_by_key (MPlist *plist, MSymbol key)
@@ -1110,12 +1440,12 @@ mplist_find_by_key (MPlist *plist, MSymbol key)
property is found, a sublist of $PLIST whose first element is the
found one is returned. Otherwise, @c NULL is returned. */
/***ja
- @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤ÎÃͤò»ý¤Ä¥ª¥Ö¥¸¥§¥¯¥È¤òõ¤¹.
+ @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃ椫¤é»ØÄê¤ÎÃͤò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤òõ¤¹.
- ´Ø¿ô mplist_find_by_value () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò»Ï¤á¤«¤é
- õ¤·¤Æ¡¢Ãͤ¬ $VAL ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í
- ¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð@c NULL
- ¤òÊÖ¤¹¡£ */
+ ´Ø¿ô mplist_find_by_value () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+ ¤ò»Ï¤á¤«¤éõ¤·¤Æ¡¢Ãͤ¬ $VAL
+ ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò¸«¤Ä¤±¤ë¡£¸«¤Ä¤«¤ì¤Ð¡¢¤½¤Î¥×¥í¥Ñ¥Æ¥£¤«¤é»Ï¤Þ¤ë
+ $PLIST ¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
MPlist *
mplist_find_by_value (MPlist *plist, void *val)
@@ -1139,9 +1469,9 @@ mplist_find_by_value (MPlist *plist, void *val)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤Î¼¡¤ÎÉôʬ¥ê¥¹¥È¤òÊÖ¤¹.
- ´Ø¿ô mplist_next () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤Î£²ÈÖÌÜ
- ¤ÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 ¤Ê
- ¤é¤Ð @c NULL ¤òÊÖ¤¹¡£ */
+ ´Ø¿ô mplist_next () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤Î 2
+ ÈÖÌܤÎÍ×ÁǤ«¤é»Ï¤Þ¤ëÉôʬ¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0
+ ¤Ê¤é¤Ð @c NULL ¤òÊÖ¤¹¡£ */
MPlist *
mplist_next (MPlist *plist)
@@ -1154,7 +1484,7 @@ mplist_next (MPlist *plist)
/***en
@brief Set the first property in a property list.
- The mplist_set () function sets the key and value of the first
+ The mplist_set () function sets the key and the value of the first
property in property list $PLIST to $KEY and $VALUE, respectively.
See the documentation of mplist_add () for the restriction on $KEY
and $VAL.
@@ -1165,13 +1495,12 @@ mplist_next (MPlist *plist)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë.
- ´Ø¿ô mplist_set () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î
- ¥¡¼¤ÈÃͤò¤½¤ì¤¾¤ì $KEY ¤È $VALUE ¤ËÀßÄꤹ¤ë¡£$KEY ¤È $VAL ¤ËÂФ¹
- ¤ëÀ©¸Â¤Ë¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
+ ´Ø¿ô mplist_set () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+ ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤ÈÃͤò¤½¤ì¤¾¤ì $KEY ¤È $VALUE ¤ËÀßÄꤹ¤ë¡£
+ $KEY ¤È $VAL ¤ËÂФ¹¤ëÀ©¸Â¤Ë¤Ä¤¤¤Æ¤Ï¡¢mplist_add () ¤ÎÀâÌÀ¤ò»²¾È¡£
@return
- ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mplist_set () ¤Ï $PLIST ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
- @c NULL ¤òÊÖ¤¹¡£ */
+ ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð mplist_set () ¤Ï $PLIST ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
MPlist *
mplist_set (MPlist *plist, MSymbol key, void * val)
@@ -1183,19 +1512,18 @@ mplist_set (MPlist *plist, MSymbol key, void * val)
key = MPLIST_KEY (plist);
M17N_OBJECT_UNREF (MPLIST_NEXT (plist));
MPLIST_KEY (plist) = Mnil;
- if (key->managing_key && MPLIST_VAL (plist))
+ if (key->managing_key)
M17N_OBJECT_UNREF (MPLIST_VAL (plist));
plist->next = NULL;
}
}
else
{
+ if (val && key->managing_key)
+ M17N_OBJECT_REF (val);
if (! MPLIST_TAIL_P (plist)
- && MPLIST_KEY (plist)->managing_key
- && MPLIST_VAL (plist))
+ && MPLIST_KEY (plist)->managing_key)
M17N_OBJECT_UNREF (MPLIST_VAL (plist));
- if (key->managing_key)
- M17N_OBJECT_REF (val);
MPLIST_SET (plist, key, val);
}
return plist;
@@ -1211,8 +1539,7 @@ mplist_set (MPlist *plist, MSymbol key, void * val)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ÎŤµ¤òÊÖ¤¹.
- ´Ø¿ô mplist_length () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤Î¥×¥í¥Ñ¥Æ¥£¤Î¿ô
- ¤òÊÖ¤¹¡£ */
+ ´Ø¿ô mplist_length () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤Î¥×¥í¥Ñ¥Æ¥£¤Î¿ô¤òÊÖ¤¹¡£ */
int
mplist_length (MPlist *plist)
@@ -1234,9 +1561,9 @@ mplist_length (MPlist *plist)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÊÖ¤¹.
- ´Ø¿ô mplist_key () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤ÎºÇ
- ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil ¤ò
- ÊÖ¤¹¡£ */
+ ´Ø¿ô mplist_key () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST
+ Ãæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil
+ ¤òÊÖ¤¹¡£ */
MSymbol
mplist_key (MPlist *plist)
@@ -1253,11 +1580,10 @@ mplist_key (MPlist *plist)
property in property list $PLIST. If the length of $PLIST
is zero, it returns @c NULL. */
/***ja
- @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÊÖ¤¹.
+ @brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥ÈÃæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
- ´Ø¿ô mplist_value () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤Î
- ºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£$PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil ¤ò
- ÊÖ¤¹¡£ */
+ ´Ø¿ô mplist_value () ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST Ãæ¤ÎºÇ½é¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£
+ $PLIST ¤ÎŤµ¤¬ 0 ¤Ê¤é¤Ð¡¢ @c Mnil ¤òÊÖ¤¹¡£ */
void *
mplist_value (MPlist *plist)
@@ -1266,7 +1592,7 @@ mplist_value (MPlist *plist)
}
/***en
- @brief Generate a property list by deserializaing an M-text.
+ @brief Generate a property list by deserializing an M-text.
The mplist_deserialize () function parses M-text $MT and returns a
property list.
@@ -1287,15 +1613,14 @@ mplist_value (MPlist *plist)
Each alternatives of @c ELEMENT is assigned one of these keys: @c
Msymbol, @c Minteger, @c Mtext, @c Mplist
- In an ascii-character-sequence, a backslush (\) is used as the escape
+ In an ascii-character-sequence, a backslash (\) is used as the escape
character, which means that, for instance, "abc\ def"
produces a symbol whose name is of length seven with the fourth
character being a space. */
/***ja
@brief M-text ¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òºî¤ë.
- ´Ø¿ô mplist_deserialize () ¤Ï M-text $MT ¤ò²òÀϤ·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹
- ¥È¤òÊÖ¤¹¡£
+ ´Ø¿ô mplist_deserialize () ¤Ï M-text $MT ¤ò²òÀϤ·¤Æ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤òÊÖ¤¹¡£
$MT ¤Î¥·¥ó¥¿¥Ã¥¯¥¹¤Ï°Ê²¼¤ÎÄ̤ꡣ
@@ -1310,22 +1635,30 @@ mplist_value (MPlist *plist)
M-TEXT ::= '"' character-sequence '"'
- @c ELEMENT ¤Î³ÆÁªÂò»è¤Ï¥¡¼¡§@c Msymbol, @c Minteger, @ c Mtext,
+ @c ELEMENT ¤Î³ÆÁªÂò»è¤Ï¥¡¼¡§@c Msymbol, @c Minteger, @c Mtext,
@c Mplist ¤Î¤¤¤º¤ì¤«¤ò³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤ë¡£
- ¥¢¥¹¥¡¼Ê¸»úÎóÆâ¤Ç¤Ï¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å (\) ¤¬¥¨¥¹¥±¡¼¥×ʸ»ú¤È¤·¤Æ
- ÍѤ¤¤é¤ì¤ë¡£¤¿¤È¤¨¤Ð "abc\ def" ¤Ï£´Ê¸»úÌܤ¬¶õÇòʸ»ú¤Ç¤¢
- ¤êŤµ¤¬£·¤Ç¤¢¤ë»ý¤Ä̾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òÀ¸À®¤¹¤ë¡£ */
+ ¥¢¥¹¥¡¼Ê¸»úÎóÆâ¤Ç¤Ï¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å (\) ¤¬¥¨¥¹¥±¡¼¥×ʸ»ú¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£¤¿¤È¤¨¤Ð
+ "abc\ def" ¤Ï 4 ʸ»úÌܤ¬¶õÇòʸ»ú¤Ç¤¢¤êŤµ¤¬ 7
+ ¤Ç¤¢¤ë»ý¤Ä̾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë¤òÀ¸À®¤¹¤ë¡£ */
MPlist *
mplist_deserialize (MText *mt)
{
+ MPlist *plist;
+ MText *tmp = NULL;
+
if (mt->format > MTEXT_FORMAT_UTF_8)
{
- if (mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8) < 0)
- MERROR (MERROR_PLIST, NULL);
+ if (MTEXT_READ_ONLY_P (mt))
+ mt = tmp = mtext_cpy (mtext (), mt);
+ else
+ mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
}
- return mplist__from_string (MTEXT_DATA (mt), mtext_nbytes (mt));
+ plist = mplist__from_string (MTEXT_DATA (mt), mtext_nbytes (mt));
+ if (tmp)
+ M17N_OBJECT_UNREF (tmp);
+ return plist;
}
/*** @} */
@@ -1346,9 +1679,8 @@ mplist_deserialize (MText *mt)
/***ja
@brief ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¤ò¥À¥ó¥×¤¹¤ë.
- ´Ø¿ô mdebug_dump_plist () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È @PLIST ¤ò stderr ¤Ë¿Í
- ´Ö¤Ë²ÄÆÉ¤Ê ·Á¤Ç°õºþ¤¹¤ë¡£ $UNDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ
- ¤ë¡£
+ ´Ø¿ô mdebug_dump_plist () ¤Ï¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È $PLIST ¤ò stderr
+ ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
@return
¤³¤Î´Ø¿ô¤Ï $PLIST ¤òÊÖ¤¹¡£ */
@@ -1357,7 +1689,6 @@ mdebug_dump_plist (MPlist *plist, int indent)
{
char *prefix = (char *) alloca (indent + 1);
MPlist *pl;
- int first = 1;
memset (prefix, 32, indent);
prefix[indent] = 0;
@@ -1365,11 +1696,9 @@ mdebug_dump_plist (MPlist *plist, int indent)
fprintf (stderr, "(");
MPLIST_DO (pl, plist)
{
- if (first)
- first = 0;
- else
+ if (pl != plist)
fprintf (stderr, "\n%s ", prefix);
- dump_plist_element (pl, indent + 2);
+ write_element (NULL, pl, indent + 1);
}
fprintf (stderr, ")");
return plist;