Imported Upstream version 0.19.7
[platform/upstream/fribidi.git] / lib / common.h
1 /* FriBidi
2  * common.h - common include for library sources
3  *
4  * $Id: common.h,v 1.21 2010-02-24 19:40:04 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2010-02-24 19:40:04 $
7  * $Revision: 1.21 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/common.h,v $
9  *
10  * Author:
11  *   Behdad Esfahbod, 2004
12  *
13  * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14  * 
15  * This library is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU Lesser General Public
17  * License as published by the Free Software Foundation; either
18  * version 2.1 of the License, or (at your option) any later version.
19  * 
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * Lesser General Public License for more details.
24  * 
25  * You should have received a copy of the GNU Lesser General Public License
26  * along with this library, in a file named COPYING; if not, write to the
27  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28  * Boston, MA 02110-1301, USA
29  *
30  * For licensing issues, contact <license@farsiweb.info>.
31  */
32 #ifndef _COMMON_H
33 #define _COMMON_H
34
35 #if HAVE_CONFIG_H+0
36 # include <config.h>
37 #endif
38
39 #include <fribidi-common.h>
40
41 /* FRIBIDI_PRIVATESPACE is a macro used to name library internal symbols. */
42 #ifndef FRIBIDI_PRIVATESPACE
43 # define FRIBIDI_PRIVATESPACE1(A,B) A##B
44 # define FRIBIDI_PRIVATESPACE0(A,B) FRIBIDI_PRIVATESPACE1(A,B)
45 # define FRIBIDI_PRIVATESPACE(SYMBOL) FRIBIDI_PRIVATESPACE0(_,FRIBIDI_NAMESPACE(_##SYMBOL##__internal__))
46 #endif /* !FRIBIDI_PRIVATESPACE */
47
48 #if FRIBIDI_USE_GLIB+0
49 # ifndef SIZEOF_LONG
50 #  define SIZEOF_LONG GLIB_SIZEOF_LONG
51 # endif /* !SIZEOF_LONG */
52 # ifndef SIZEOF_VOID_P
53 #  define SIZEOF_VOID_P GLIB_SIZEOF_VOID_P
54 # endif /* !SIZEOF_VOID_P */
55 # ifndef __FRIBIDI_DOC
56 #  include <glib.h>
57 # endif /* !__FRIBIDI_DOC */
58 # ifndef fribidi_malloc
59 #  define fribidi_malloc g_try_malloc
60 #  define fribidi_free g_free
61 # endif /* !fribidi_malloc */
62 # ifndef fribidi_assert
63 #  ifndef __FRIBIDI_DOC
64 #   include <glib.h>
65 #  endif /* !__FRIBIDI_DOC */
66 #  define fribidi_assert g_assert
67 # endif /* !fribidi_assert */
68 # ifndef __FRIBIDI_DOC
69 #  include <glib.h>
70 # endif /* !__FRIBIDI_DOC */
71 # ifndef FRIBIDI_BEGIN_STMT
72 #  define FRIBIDI_BEGIN_STMT G_STMT_START {
73 #  define FRIBIDI_END_STMT } G_STMT_END
74 # endif /* !FRIBIDI_BEGIN_STMT */
75 # ifndef LIKELY
76 #  define LIKELY G_LIKELY
77 #  define UNLIKELY G_UNLIKELY
78 # endif /* !LIKELY */
79 # ifndef false
80 #  define false FALSE
81 # endif /* !false */
82 # ifndef true
83 #  define true TRUE
84 # endif /* !true */
85 #endif /* FRIBIDI_USE_GLIB */
86
87 #ifndef false
88 # define false (0)
89 # endif /* !false */
90 # ifndef true
91 #  define true (!false)
92 # endif /* !true */
93
94 #ifndef NULL
95 #  ifdef __cplusplus
96 #    define NULL        (0L)
97 #  else /* !__cplusplus */
98 #    define NULL        ((void*) 0)
99 #  endif /* !__cplusplus */
100 #endif /* !NULL */
101
102 /* fribidi_malloc and fribidi_free should be used instead of malloc and free. 
103  * No need to include any headers. */
104 #ifndef fribidi_malloc
105 # if HAVE_STDLIB_H
106 #  ifndef __FRIBIDI_DOC
107 #   include <stdlib.h>
108 #  endif /* __FRIBIDI_DOC */
109 #  define fribidi_malloc malloc
110 # else /* !HAVE_STDLIB_H */
111 #  define fribidi_malloc (void *) malloc
112 # endif /* !HAVE_STDLIB_H */
113 # define fribidi_free free
114 #else /* fribidi_malloc */
115 # ifndef fribidi_free
116 #  error You should define fribidi_free too when you define fribidi_malloc.
117 # endif /* !fribidi_free */
118 #endif /* fribidi_malloc */
119
120 #if HAVE_STRING_H+0
121 # if !STDC_HEADERS && HAVE_MEMORY_H
122 #  include <memory.h>
123 # endif
124 # include <string.h>
125 #endif
126 #if HAVE_STRINGS_H+0
127 # include <strings.h>
128 #endif
129
130 /* FRIBIDI_CHUNK_SIZE is the number of bytes in each chunk of memory being
131  * allocated for data structure pools. */
132 #ifndef FRIBIDI_CHUNK_SIZE
133 # if HAVE_ASM_PAGE_H
134 #  ifndef __FRIBIDI_DOC
135 #   include <asm/page.h>
136 #  endif /* __FRIBIDI_DOC */
137 #  define FRIBIDI_CHUNK_SIZE (PAGE_SIZE - 16)
138 # else /* !HAVE_ASM_PAGE_H */
139 #  define FRIBIDI_CHUNK_SIZE (4096 - 16)
140 # endif /* !HAVE_ASM_PAGE_H */
141 #else /* FRIBIDI_CHUNK_SIZE */
142 # if FRIBIDI_CHUNK_SIZE < 256
143 #  error FRIBIDI_CHUNK_SIZE now should define the size of a chunk in bytes.
144 # endif /* FRIBIDI_CHUNK_SIZE < 256 */
145 #endif /* FRIBIDI_CHUNK_SIZE */
146
147 /* FRIBIDI_BEGIN_STMT should be used at the beginning of your macro
148  * definitions that are to behave like simple statements.  Use
149  * FRIBIDI_END_STMT at the end of the macro after the semicolon or brace. */
150 #ifndef FRIBIDI_BEGIN_STMT
151 # define FRIBIDI_BEGIN_STMT do {
152 # define FRIBIDI_END_STMT } while (0)
153 #endif /* !FRIBIDI_BEGIN_STMT */
154
155 /* LIKEYLY and UNLIKELY are used to give a hint on branch prediction to the
156  * compiler. */
157 #ifndef LIKELY
158 # define LIKELY
159 # define UNLIKELY
160 #endif /* !LIKELY */
161
162 #ifndef FRIBIDI_EMPTY_STMT
163 # define FRIBIDI_EMPTY_STMT FRIBIDI_BEGIN_STMT (void) 0; FRIBIDI_END_STMT
164 #endif /* !FRIBIDI_EMPTY_STMT */
165
166 #if HAVE_STRINGIZE+0
167 # define STRINGIZE(symbol) #symbol
168 #else /* !HAVE_STRINGIZE */
169 # define STRINGIZE(symbol) (no stringize operator available)
170 #endif /* !HAVE_STRINGIZE */
171
172 /* As per recommendation of GNU Coding Standards. */
173 #ifndef _GNU_SOURCE
174 # define _GNU_SOURCE
175 #endif /* !_GNU_SOURCE */
176
177 /* We respect our own rules. */
178 #define FRIBIDI_NO_DEPRECATED
179
180
181 #include "debug.h"
182
183 #endif /* !_COMMON_H */
184 /* Editor directions:
185  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
186  */