-#define COMPOSING_P(composing) (composing)
-/* 1 iff 1st char of composing element follows. */
-#define COMPOSING_HEAD_P(composing) \
- ((composing) && (composing) <= COMPOSING_NO_RULE_HEAD)
-/* 1 iff composing with embeded composition rule. */
-#define COMPOSING_WITH_RULE_P(composing) ((composing) & 1)
-
-/* Macros used for the member finish_status of the struct
+#define COMPOSING_P(coding) ((int) coding->composing > (int) COMPOSITION_NO)
+
+#define COMPOSITION_DATA_SIZE 4080
+#define COMPOSITION_DATA_MAX_BUNCH_LENGTH (4 + MAX_COMPOSITION_COMPONENTS*2)
+
+/* Data structure to hold information about compositions of text that
+ is being decoded or encode. ISO 2022 base code conversion routines
+ handle special ESC sequences for composition specification. But,
+ they can't get/put such information directly from/to a buffer in
+ the deepest place. So, they store or retrieve the information
+ through this structure.
+
+ The encoder stores the information in this structure when it meets
+ ESC sequences for composition while encoding codes, then, after all
+ text codes are encoded, puts `composition' properties on the text
+ by referring to the structure.
+
+ The decoder at first stores the information of a text to be
+ decoded, then, while decoding codes, generates ESC sequences for
+ composition at proper places by referring to the structure. */
+
+struct composition_data
+{
+ /* The character position of the first character to be encoded or
+ decoded. START and END (see below) are relative to this
+ position. */
+ int char_offset;
+
+ /* The composition data. These elements are repeated for each
+ composition:
+ LENGTH START END METHOD [ COMPONENT ... ]
+ where,
+ LENGTH is the number of elements for this composition.
+
+ START and END are starting and ending character positions of
+ the composition relative to `char_offset'.
+
+ METHOD is one of `enum composing_status' specifying the way of
+ composition.
+
+ COMPONENT is a character or an encoded composition rule. */
+ int data[COMPOSITION_DATA_SIZE];
+
+ /* The number of elements in `data' currently used. */
+ int used;
+
+ /* Pointers to the previous and next structures. When `data' is
+ filled up, another structure is allocated and linked in `next'.
+ The new structure has backward link to this structure in `prev'.
+ The number of chained structures depends on how many compositions
+ the text being encoded or decoded contains. */
+ struct composition_data *prev, *next;
+};
+
+/* Macros used for the member `result' of the struct