From: handa Date: Thu, 5 Jan 2006 06:33:41 +0000 (+0000) Subject: (read_integer_element): If '#' and '-' are followed by X-Git-Tag: REL-1-3-1~31 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd0672a2c8ee50e5805d9a3abd9536bcaad4a1ea;p=m17n%2Fm17n-lib.git (read_integer_element): If '#' and '-' are followed by non-integer-constituent, read them as a part of a symbol. (read_symbol_element): New arg C. (read_element): Adjust args to read_symbol_element. --- diff --git a/src/plist.c b/src/plist.c index 5769e63..7da5878 100644 --- a/src/plist.c +++ b/src/plist.c @@ -32,7 +32,27 @@ 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 @@ -338,69 +358,19 @@ read_character (MStream *st, int c) } -/** 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, int skip) -{ - int num; - - if (c == '0' || c == '#') - { - c = GETC (st); - if (c == 'x') - num = read_hexadesimal (st); - else - num = read_decimal (st, c); - } - else if (c == '?') - { - c = GETC (st); - if (c == EOF) - num = 0; - else if (c != '\\') - { - if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c)) - num = c; - else - num = read_character (st, c); - } - else - { - c = GETC (st); - if (c == EOF) - num = '\\'; - else if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c)) - num = escape_mnemonic[c]; - else - num = read_character (st, c); - } - } - else if (c == '-') - num = - read_decimal (st, GETC (st)); - else - num = read_decimal (st, c); - - if (! skip) - 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, int skip) +read_symbol_element (MPlist *plist, MStream *st, int c, int skip) { unsigned char buffer[1024]; int bufsize = 1024; unsigned char *buf = buffer; - int c, i; + int i; i = 0; - while ((c = GETC (st)) != EOF + while (c != EOF && c > ' ' && c != ')' && c != '(' && c != '"') { @@ -424,6 +394,7 @@ read_symbol_element (MPlist *plist, MStream *st, int skip) } if (! skip) buf[i++] = c; + c = GETC (st); } if (c > ' ') @@ -438,6 +409,71 @@ read_symbol_element (MPlist *plist, MStream *st, int skip) 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, int skip) +{ + int num; + + if (c == '#') + { + c = GETC (st); + 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 == '?') + { + c = GETC (st); + if (c == EOF) + num = 0; + else if (c != '\\') + { + if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c)) + num = c; + else + num = read_character (st, c); + } + else + { + c = GETC (st); + if (c == EOF) + num = '\\'; + else if (c < 128 || ! CHAR_UNITS_BY_HEAD_UTF8 (c)) + num = escape_mnemonic[c]; + else + num = read_character (st, c); + } + } + else if (c == '-') + { + c = GETC (st); + if (c < '0' || c > '9') + { + UNGETC (c, st); + return read_symbol_element (plist, st, '-', skip); + } + num = - read_decimal (st, c); + } + else + num = read_decimal (st, c); + + if (! skip) + MPLIST_SET_ADVANCE (plist, Minteger, (void *) num); + return plist; +} + /* Read an element of various type from stream ST, and add it to LIST. Return a list for the next element. The element type is decided by the first token character found as below: @@ -517,8 +553,7 @@ read_element (MPlist *plist, MStream *st, MPlist *keys) 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, keys ? 1 : 0)); + return (read_symbol_element (plist, st, c, keys ? 1 : 0)); } void