1 /*
2  * fontconfig/fontconfig/fcprivate.h
3  *
4  * Copyright © 2001 Keith Packard
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the author(s) not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  The authors make no
13  * representations about the suitability of this software for any purpose.  It
14  * is provided "as is" without express or implied warranty.
15  *
16  * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24 
25 #ifndef _FCPRIVATE_H_
26 #define _FCPRIVATE_H_
27 
28 /*
29  * I tried this with functions that took va_list* arguments
30  * but portability concerns made me change these functions
31  * into macros (sigh).
32  */
33 
34 #define FcPatternVapBuild(result, orig, va)			    \
35 {								    \
36     FcPattern	*__p__ = (orig);				    \
37     const char	*__o__;						    \
38     FcValue	__v__;						    \
39 								    \
40     if (!__p__)							    \
41     {								    \
42 	__p__ = FcPatternCreate ();				    \
43 	if (!__p__)		    				    \
44 	    goto _FcPatternVapBuild_bail0;			    \
45     }				    				    \
46     for (;;)			    				    \
47     {				    				    \
48 	__o__ = va_arg (va, const char *);			    \
49 	if (!__o__)		    				    \
50 	    break;		    				    \
51 	__v__.type = va_arg (va, int);				    \
52 	switch (__v__.type) {	    				    \
53 	case FcTypeUnknown:					    \
54 	case FcTypeVoid:					    \
55 	    goto _FcPatternVapBuild_bail1;       		    \
56 	case FcTypeInteger:	    				    \
57 	    __v__.u.i = va_arg (va, int);			    \
58 	    break;						    \
59 	case FcTypeDouble:					    \
60 	    __v__.u.d = va_arg (va, double);			    \
61 	    break;						    \
62 	case FcTypeString:					    \
63 	    __v__.u.s = va_arg (va, const FcChar8 *);		    \
64 	    break;						    \
65 	case FcTypeBool:					    \
66 	    __v__.u.b = va_arg (va, FcBool);			    \
67 	    break;						    \
68 	case FcTypeMatrix:					    \
69 	    __v__.u.m = va_arg (va, const FcMatrix *);		    \
70 	    break;						    \
71 	case FcTypeCharSet:					    \
72 	    __v__.u.c = va_arg (va, const FcCharSet *); 	    \
73 	    break;						    \
74 	case FcTypeFTFace:					    \
75 	    __v__.u.f = va_arg (va, FT_Face);			    \
76 	    break;						    \
77 	case FcTypeLangSet:					    \
78 	    __v__.u.l = va_arg (va, const FcLangSet *);		    \
79 	    break;						    \
80 	case FcTypeRange:					    \
81 	    __v__.u.r = va_arg (va, const FcRange *);		    \
82 	    break;						    \
83 	}							    \
84 	if (!FcPatternAdd (__p__, __o__, __v__, FcTrue))	    \
85 	    goto _FcPatternVapBuild_bail1;			    \
86     }								    \
87     result = __p__;						    \
88     goto _FcPatternVapBuild_return;				    \
89 								    \
90 _FcPatternVapBuild_bail1:					    \
91     if (!orig)							    \
92 	FcPatternDestroy (__p__);				    \
93 _FcPatternVapBuild_bail0:					    \
94     result = (void*)0;						    \
95 								    \
96 _FcPatternVapBuild_return:					    \
97     ;								    \
98 }
99 
100 
101 #define FcObjectSetVapBuild(__ret__, __first__, __va__) 		\
102 {									\
103     FcObjectSet    *__os__;						\
104     const char	    *__ob__;						\
105 									\
106     __ret__ = 0;						    	\
107     __os__ = FcObjectSetCreate ();					\
108     if (!__os__)							\
109 	goto _FcObjectSetVapBuild_bail0;				\
110     __ob__ = __first__;							\
111     while (__ob__)							\
112     {									\
113 	if (!FcObjectSetAdd (__os__, __ob__))				\
114 	    goto _FcObjectSetVapBuild_bail1;				\
115 	__ob__ = va_arg (__va__, const char *);				\
116     }									\
117     __ret__ = __os__;							\
118 									\
119 _FcObjectSetVapBuild_bail1:						\
120     if (!__ret__ && __os__)					    	\
121 	FcObjectSetDestroy (__os__);					\
122 _FcObjectSetVapBuild_bail0:						\
123     ;									\
124 }
125 
126 #ifndef FC_ATTRIBUTE_VISIBILITY_HIDDEN
127 #define FC_ATTRIBUTE_VISIBILITY_HIDDEN __attribute((visibility("hidden")))
128 #endif
129 
130 #ifndef FC_ATTRIBUTE_VISIBILITY_EXPORT
131 #define FC_ATTRIBUTE_VISIBILITY_EXPORT __attribute((visibility("default")))
132 #endif
133 
134 #endif /* _FCPRIVATE_H_ */
135