16c321187Smrg/*
26c321187Smrg
36c321187SmrgCopyright 1989, 1998  The Open Group
46c321187Smrg
56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its
66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that
76c321187Smrgthe above copyright notice appear in all copies and that both that
86c321187Smrgcopyright notice and this permission notice appear in supporting
96c321187Smrgdocumentation.
106c321187Smrg
116c321187SmrgThe above copyright notice and this permission notice shall be included in
126c321187Smrgall copies or substantial portions of the Software.
136c321187Smrg
146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
206c321187Smrg
216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be
226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings
236c321187Smrgin this Software without prior written authorization from The Open Group.
246c321187Smrg
256c321187Smrg*/
266c321187Smrg
276c321187Smrg#ifndef _Xct_h
286c321187Smrg#define _Xct_h
296c321187Smrg
306c321187Smrg#include <X11/Xfuncproto.h>
316c321187Smrg
326c321187Smrg#define XctVersion 1
336c321187Smrg
346c321187Smrgtypedef unsigned char *XctString;
356c321187Smrg
366c321187Smrgtypedef enum {
376c321187Smrg    XctUnspecified,
386c321187Smrg    XctLeftToRight,
396c321187Smrg    XctRightToLeft
406c321187Smrg} XctHDirection;
416c321187Smrg
426c321187Smrgtypedef unsigned long XctFlags;
436c321187Smrg
446c321187Smrg/* These are bits in XctFlags. */
456c321187Smrg
466c321187Smrg#define XctSingleSetSegments	0x0001
476c321187Smrg   /* This means that returned segments should contain characters from only
486c321187Smrg    * one set (C0, C1, GL, GR).  When this is requested, XctSegment is never
496c321187Smrg    * returned, instead XctC0Segment, XctC1Segment, XctGlSegment, and
506c321187Smrg    * XctGRSegment are returned.  C0 and C1 segments are always returned as
516c321187Smrg    * singleton characters.
526c321187Smrg    */
536c321187Smrg
546c321187Smrg#define XctProvideExtensions	0x0002
556c321187Smrg   /* This means that if the Compound Text string is from a higher version
566c321187Smrg    * than this code is implemented to, then syntactically correct but unknown
576c321187Smrg    * control sequences should be returned as XctExtension items.  If this
586c321187Smrg    * flag is not set, and the Compound Text string version indicates that
596c321187Smrg    * extensions cannot be ignored, then each unknown control sequence will be
606c321187Smrg    * reported as an XctError.
616c321187Smrg    */
626c321187Smrg
636c321187Smrg#define XctAcceptC0Extensions	0x0004
646c321187Smrg   /* This means that if the Compound Text string is from a higher version
656c321187Smrg    * than this code is implemented to, then unknown C0 characters should be
666c321187Smrg    * treated as if they were legal, and returned as C0 characters (regardless
676c321187Smrg    * of how XctProvideExtensions is set).  If this flag is not set, then all
686c321187Smrg    * unknown C0 characters are treated according to XctProvideExtensions.
696c321187Smrg    */
706c321187Smrg
716c321187Smrg#define XctAcceptC1Extensions	0x0008
726c321187Smrg   /* This means that if the Compound Text string is from a higher version
736c321187Smrg    * than this code is implemented to, then unknown C0 characters should be
746c321187Smrg    * treated as if they were legal, and returned as C0 characters (regardless
756c321187Smrg    * of how XctProvideExtensions is set).  If this flag is not set, then all
766c321187Smrg    * unknown C0 characters are treated according to XctProvideExtensions.
776c321187Smrg    */
786c321187Smrg
796c321187Smrg#define XctHideDirection	0x0010
806c321187Smrg   /* This means that horizontal direction changes should be reported as
816c321187Smrg    * XctHorizontal items.  If this flag is not set, then direction changes are
826c321187Smrg    * not returned as items, but the current direction is still maintained and
836c321187Smrg    * reported for other items.
846c321187Smrg    */
856c321187Smrg
866c321187Smrg#define XctFreeString		0x0020
876c321187Smrg   /* This means that XctFree should free the Compound Text string (that was
886c321187Smrg    * passed to XctCreate.  If this flag is not set, the string is not freed.
896c321187Smrg    */
906c321187Smrg
916c321187Smrg#define XctShiftMultiGRToGL	0x0040
926c321187Smrg   /* Translate GR segments on-the-fly into GL segments for the GR sets:
936c321187Smrg    * GB2312.1980-1, JISX0208.1983-1, and KSC5601.1987-1.
946c321187Smrg    */
956c321187Smrg
966c321187Smrg/* This is the return type for XctNextItem. */
976c321187Smrgtypedef enum {
986c321187Smrg    XctSegment,		/* used when XctSingleSetSegments is not requested */
996c321187Smrg    XctC0Segment,	/* used when XctSingleSetSegments is requested */
1006c321187Smrg    XctGLSegment,	/* used when XctSingleSetSegments is requested */
1016c321187Smrg    XctC1Segment,	/* used when XctSingleSetSegments is requested */
1026c321187Smrg    XctGRSegment,	/* used when XctSingleSetSegments is requested */
1036c321187Smrg    XctExtendedSegment,	/* an extended segment */
1046c321187Smrg    XctExtension,	/* used when XctProvideExtensions is requested */
1056c321187Smrg    XctHorizontal,	/* horizontal direction or depth change */
1066c321187Smrg    XctEndOfText,	/* end of text string */
1076c321187Smrg    XctError		/* syntactic or semantic error */
1086c321187Smrg} XctResult;
1096c321187Smrg
1106c321187Smrgtypedef struct _XctRec {
1116c321187Smrg    XctString		total_string;	/* as given to XctCreate */
1126c321187Smrg    int			total_length;	/* as given to XctCreate */
1136c321187Smrg    XctFlags		flags;		/* as given to XctCreate */
1146c321187Smrg    int			version;	/* indicates the version of the CT spec
1156c321187Smrg					 * the string was produced from */
1166c321187Smrg    int			can_ignore_exts;/* non-zero if ignoring extensions is
1176c321187Smrg					 * acceptable, else zero */
1186c321187Smrg    XctString		item;		/* item returned from XctNextItem */
1196c321187Smrg    unsigned		item_length;	/* length of item in bytes */
1206c321187Smrg    int			char_size;	/* number of bytes per character in
1216c321187Smrg					 * item, with zero meaning variable */
1226c321187Smrg    char		*encoding;	/* Encoding name for item */
1236c321187Smrg    XctHDirection	horizontal;	/* direction of item */
1246c321187Smrg    unsigned		horz_depth;	/* current direction nesting depth */
1256c321187Smrg    char		*GL;		/* "{I} F" string for current GL */
1266c321187Smrg    char		*GL_encoding;	/* Encoding name for current GL */
1276c321187Smrg    int			GL_set_size;	/* 94 or 96 */
1286c321187Smrg    int			GL_char_size;	/* number of bytes per GL character */
1296c321187Smrg    char		*GR;		/* "{I} F" string for current GR */
1306c321187Smrg    char		*GR_encoding;	/* Encoding name for current GR */
1316c321187Smrg    int			GR_set_size;	/* 94 or 96 */
1326c321187Smrg    int			GR_char_size;	/* number of bytes per GR character */
1336c321187Smrg    char		*GLGR_encoding;	/* Encoding name for current GL+GR,
1346c321187Smrg					 * if known */
1356c321187Smrg    struct _XctPriv	*priv;		/* private to parser, don't peek */
1366c321187Smrg} *XctData;
1376c321187Smrg
1386c321187Smrg/* these are the external routines */
1396c321187Smrg_XFUNCPROTOBEGIN
1406c321187Smrg
1416c321187SmrgXctData XctCreate
1426c321187Smrg(
1436c321187Smrg _Xconst unsigned char	*string,
1446c321187Smrg int			length,
1456c321187Smrg XctFlags		flags
1466c321187Smrg);
1476c321187Smrg
1486c321187SmrgXctResult XctNextItem
1496c321187Smrg(
1506c321187Smrg XctData		data
1516c321187Smrg);
1526c321187Smrg
1536c321187Smrgvoid XctFree
1546c321187Smrg(
1556c321187Smrg XctData		data
1566c321187Smrg );
1576c321187Smrg
1586c321187Smrgvoid XctReset
1596c321187Smrg(
1606c321187Smrg XctData		data
1616c321187Smrg );
1626c321187Smrg
1636c321187Smrg_XFUNCPROTOEND
1646c321187Smrg
1656c321187Smrg#endif /* _Xct_h */
166