1
/* $Xorg: miStrMacro.h,v 1.4 2001/02/09 02:04:08 xorgcvs Exp $ */
3
/***********************************************************
5
Copyright 1989, 1990, 1991, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
27
Copyright 1989, 1990, 1991 by Sun Microsystems, Inc.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Sun Microsystems,
36
not be used in advertising or publicity pertaining to distribution of
37
the software without specific, written prior permission.
39
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
40
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
41
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
42
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
******************************************************************/
49
/* some macros to use */
57
/* structure information */
58
#define MISTR_NUM_EL(PS) (PS)->numElements
60
#define MISTR_EDIT_MODE(PS) (PS)->editMode
62
#define MISTR_LENGTH(PS) (PS)->totalSize
64
#define MISTR_NUM_CHILDREN(PS) (PS)->children->numObj
66
#define MISTR_NUM_PARENTS(PS) (PS)->parents->numObj
68
#define MISTR_CURR_EL_OFFSET(PS) (PS)->currElementOffset
70
#define MISTR_CURR_EL_PTR(PS) (PS)->pCurrElement
72
#define MISTR_ZERO_EL(PS) (PS)->pZeroElement
74
#define MISTR_LAST_EL(PS) (PS)->pLastElement
76
#define MISTR_NEXT_EL(PE) (PE)->next
78
#define MISTR_PREV_EL(PE) (PE)->prev
80
#define MISTR_EL_DATA(PE) ((PE)->element)
82
#define MISTR_EL_TYPE(PE) (PE)->element.elementType
84
#define MISTR_EL_LENGTH(PE) (PE)->element.pexOClength
86
/* todo: make this more efficient by searching backwards if it's closer */
88
if (offset < current && offset < curr - off)
89
then start at 0 and go forward
90
else if (offset < current && offset > curr - off)
91
then start at curr and go backward
92
else if (offset > current && offset - curr < off - last)
93
then start at curr and go forward
94
else if (offset > current && offset - curr > off - last)
95
then start at last and go backward
98
#define MISTR_FIND_EL(PSTRUCT, OFFSET, PE) \
100
(PE) = MISTR_ZERO_EL(PSTRUCT); \
101
else if ((OFFSET) >= MISTR_NUM_EL(PSTRUCT)) \
102
(PE) = MISTR_PREV_EL(MISTR_LAST_EL(PSTRUCT)); \
103
else if ((OFFSET) == MISTR_CURR_EL_OFFSET(PSTRUCT)) \
104
(PE) = MISTR_CURR_EL_PTR(PSTRUCT); \
106
register int _i, _start; \
107
if ((OFFSET) < MISTR_CURR_EL_OFFSET(PSTRUCT)) { \
108
(PE) = MISTR_ZERO_EL(PSTRUCT); \
111
_start = MISTR_CURR_EL_OFFSET(PSTRUCT); \
112
(PE) = MISTR_CURR_EL_PTR(PSTRUCT); \
114
for (_i=_start; _i<(OFFSET); _i++, (PE) = MISTR_NEXT_EL(PE)); \
117
/* given pointer to element, find out what its OFFSET is in the struct */
118
/* the element better be in the struct! */
119
/* for now, don't know whether the element is near the beginning or end of
120
* the structure. todo: add hint to improve efficiency such as
121
* whether to start from the beginning or end or maybe some element
122
* and its known OFFSET from whic to start at (and go forwards)
124
#define MISTR_FIND_OFFSET(PSTRUCT, PEL, OFFSET) \
125
if (PEL == MISTR_PREV_EL(MISTR_LAST_EL(PSTRUCT))) \
126
(OFFSET) = MISTR_NUM_EL(PSTRUCT); \
129
register miGenericElementPtr ptemp; \
130
for (i = 0, ptemp = MISTR_ZERO_EL(PSTRUCT); \
131
((i < MISTR_NUM_EL(PSTRUCT)) && (ptemp != (PEL))); \
132
i++, ptemp = MISTR_NEXT_EL(ptemp)); \
136
/* Must check Proprietary and in Range to avoid Null function ptrs */
137
#define MISTR_DEL_ONE_EL(PSTRUCT, PPREV, PEL) { \
138
MISTR_NEXT_EL(PPREV) = MISTR_NEXT_EL(PEL); \
139
MISTR_PREV_EL(MISTR_NEXT_EL(PEL)) = (PPREV); \
140
if (MI_HIGHBIT_ON(MISTR_EL_TYPE(PEL))) \
141
(*DestroyCSSElementTable[MI_OC_PROP])((PSTRUCT), (PEL)); \
143
if (MI_IS_PEX_OC(MISTR_EL_TYPE(PEL))) \
144
(*DestroyCSSElementTable[MISTR_EL_TYPE(PEL)])((PSTRUCT), (PEL));\
147
#define MISTR_INSERT_ONE_EL(PPREV, PEL) \
148
MISTR_NEXT_EL(PEL) = MISTR_NEXT_EL(PPREV); \
149
MISTR_PREV_EL(MISTR_NEXT_EL(PEL)) = PEL; \
150
MISTR_NEXT_EL(PPREV) = (PEL); \
151
MISTR_PREV_EL(PEL) = (PPREV)
153
/* PSTRUCT is structure handle; DDSTRUCT is dd structure header */
154
/* first can't be 0, last can't be more than number in structure */
155
/* inclusive delete, does not update structure header info */
156
/* Must check Proprietary and in Range to avoid Null function ptrs */
157
#define MISTR_DEL_ELS(PSTRUCT, DDSTRUCT, FIRST, LAST) \
158
if ((int)((LAST) - (FIRST)) >= 0) { \
160
register miGenericElementPtr pe, pe1, pe2; \
161
MISTR_FIND_EL((DDSTRUCT), (FIRST), pe1); \
162
pe = MISTR_PREV_EL(pe1); \
163
for (num = (FIRST); num <= (LAST); num++) { \
164
pe2 = MISTR_NEXT_EL(pe1); \
165
if (MI_HIGHBIT_ON(MISTR_EL_TYPE(pe1))) \
166
(*DestroyCSSElementTable[MI_OC_PROP]) \
169
if (MI_IS_PEX_OC(MISTR_EL_TYPE(pe1))) \
170
(*DestroyCSSElementTable[MISTR_EL_TYPE(pe1)]) \
174
MISTR_NEXT_EL(pe) = pe1; \
175
MISTR_PREV_EL(pe1) = pe; \
178
/* macros for accessing specific data in some elements
179
* these MUST be changed to reflect the storage format of the elements
182
/* this macro returns the structure id in an execute structure element.
183
* for the SI, this element has the structure handle in the id field
184
* can't use these on left side of statement because of casting */
185
#define MISTR_GET_EXSTR_STR(PEL) \
186
((pexExecuteStructure *)((PEL)+1))->id
188
#define MISTR_GET_EXSTR_ID(PEL) \
189
((ddStructResource *)((pexExecuteStructure *)((PEL)+1))->id)->id
191
/* use this to change structure in ChangeStructureRefs */
192
#define MISTR_PUT_EXSTR_STR(PEL, PSTRUCT) \
193
{ pexExecuteStructure *pexstr; \
194
pexstr = (pexExecuteStructure *)((PEL)+1);\
195
pexstr->id = (pexStructure)(PSTRUCT); \
198
#define MISTR_GET_LABEL(PEL) ((pexLabel *)((PEL)+1))->label
200
#define MISTR_GET_PICK_ID(PEL) ((pexPickId *)((PEL)+1))->pickId
202
#endif /* MISTRMACRO_H */