]> git.sur5r.net Git - openldap/blob - libraries/liblunicode/ucdata/ucpgba.h
Cyrus SASL uses screwy terms.
[openldap] / libraries / liblunicode / ucdata / ucpgba.h
1 /*
2  * Copyright 1999 Computing Research Labs, New Mexico State University
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #ifndef _h_ucpgba
23 #define _h_ucpgba
24
25 #include "portable.h"
26
27 /*
28  * $Id: ucpgba.h,v 1.4 1999/11/19 15:24:30 mleisher Exp $
29  */
30
31 LDAP_BEGIN_DECL
32
33 #undef __
34 #define __(x) x
35
36 /***************************************************************************
37  *
38  * Macros and types.
39  *
40  ***************************************************************************/
41
42 /*
43  * These are the direction values that can appear in render runs and render
44  * strings.
45  */
46 #define UCPGBA_LTR 0
47 #define UCPGBA_RTL 1
48
49 /*
50  * These are the flags for cursor motion.
51  */
52 #define UCPGBA_CURSOR_VISUAL  0
53 #define UCPGBA_CURSOR_LOGICAL 1
54
55 /*
56  * This structure is used to contain runs of text in a particular direction.
57  */
58 typedef struct _ucrun_t {
59     struct _ucrun_t *visual_prev;  /* Pointer to the previous visual run.    */
60     struct _ucrun_t *visual_next;  /* Pointer to the next visual run.        */
61
62     struct _ucrun_t *logical_prev; /* Pointer to the previous logical run.   */
63     struct _ucrun_t *logical_next; /* Pointer to the next logical run.       */
64
65     int direction;                 /* Direction of the run.                  */
66
67     long cursor;                   /* Position of "cursor" in the string.    */
68
69     unsigned long *chars;          /* List of characters for the run.        */
70     unsigned long *positions;      /* List of original positions in source.  */
71
72     unsigned long *source;         /* The source string.                     */
73     unsigned long start;           /* Beginning offset in the source string. */
74     unsigned long end;             /* Ending offset in the source string.    */
75 } ucrun_t;
76
77 /*
78  * This represents a string of runs rendered up to a point that is not
79  * platform specific.
80  */
81 typedef struct _ucstring_t {
82     int direction;                /* Overall direction of the string.       */
83
84     int cursor_motion;            /* Logical or visual cursor motion flag.  */
85
86     ucrun_t *cursor;              /* The run containing the "cursor."       */
87
88     ucrun_t *logical_first;       /* First run in the logical order.        */
89     ucrun_t *logical_last;        /* Last run in the logical order.         */
90
91     ucrun_t *visual_first;        /* First run in the visual order.         */
92     ucrun_t *visual_last;         /* Last run in the visual order.          */
93
94     unsigned long *source;        /* The source string.                     */
95     unsigned long start;          /* The beginning offset in the source.    */
96     unsigned long end;            /* The ending offset in the source.       */
97 } ucstring_t;
98
99 /***************************************************************************
100  *
101  * API
102  *
103  ***************************************************************************/
104
105 /*
106  * This creates and reorders the specified substring using the
107  * "Pretty Good Bidi Algorithm."  A default direction is provided for cases
108  * of a string containing no strong direction characters and the default
109  * cursor motion should be provided.
110  */
111 extern ucstring_t *ucstring_create __((unsigned long *source,
112                                        unsigned long start,
113                                        unsigned long end,
114                                        int default_direction,
115                                        int cursor_motion));
116 /*
117  * This releases the string.
118  */
119 extern void ucstring_free __((ucstring_t *string));
120
121 /*
122  * This changes the cursor motion flag for the string.
123  */
124 extern int ucstring_set_cursor_motion __((ucstring_t *string,
125                                           int cursor_motion));
126
127 /*
128  * This function will move the cursor to the right depending on the
129  * type of cursor motion that was specified for the string.
130  *
131  * A 0 is returned if no cursor motion is performed, otherwise a
132  * 1 is returned.
133  */
134 extern int ucstring_cursor_right __((ucstring_t *string, int count));
135
136 /*
137  * This function will move the cursor to the left depending on the
138  * type of cursor motion that was specified for the string.
139  *
140  * A 0 is returned if no cursor motion is performed, otherwise a
141  * 1 is returned.
142  */
143 extern int ucstring_cursor_left __((ucstring_t *string, int count));
144
145 /*
146  * This routine retrieves the direction of the run containing the cursor
147  * and the actual position in the original text string.
148  */
149 extern void ucstring_cursor_info __((ucstring_t *string, int *direction,
150                                      unsigned long *position));
151
152 #undef __
153
154 LDAP_END_DECL
155
156 #endif /* _h_ucpgba */