1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 2 3 /* AbiSource Program Utilities 4 * Copyright (C) 1998 AbiSource, Inc. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 * 02110-1301 USA. 20 */ 21 22 #ifndef UT_TYPES_H 23 #define UT_TYPES_H 24 25 #ifdef HAVE_CONFIG_H 26 #include "config.h" 27 #endif 28 29 #include <stdlib.h> 30 #include <glib.h> 31 32 /* 33 * This macro allow using GNUC extension with -pedantic 34 */ 35 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) 36 # define GNUC_EXTENSION __extension__ 37 #else 38 # define GNUC_EXTENSION 39 #endif 40 41 typedef guint8 UT_Byte; 42 43 typedef gunichar UT_UCS4Char; 44 typedef guint16 UT_UCS2Char; 45 typedef gint32 UT_GrowBufElement; 46 47 /* NOTA BENE: UT_UCSChar is deprecated; all new code must use 48 UT_UCS4Char instead !!! */ 49 typedef UT_UCS4Char UT_UCSChar; /* Unicode */ 50 51 typedef guint8 UT_uint8; 52 typedef gint8 UT_sint8; 53 54 typedef guint16 UT_uint16; 55 typedef gint16 UT_sint16; 56 57 typedef guint32 UT_uint32; 58 typedef gint32 UT_sint32; 59 60 typedef guint64 UT_uint64; 61 typedef gint64 UT_sint64; 62 63 #ifdef _WIN64 64 typedef guint64 UT_uintptr; 65 typedef gint64 UT_sintptr; 66 #else 67 typedef unsigned long UT_uintptr; 68 typedef long UT_sintptr; 69 #endif 70 71 /** use to mark variable as unused */ 72 #define UT_UNUSED(x) (void)(x); 73 74 /** use to mark an argument as used in debug only 75 * otherwise equivalent to UT_UNUSED. 76 * If it is a local variable use UT_DebugOnly<> instead. 77 */ 78 #ifdef DEBUG 79 #define UT_DEBUG_ONLY_ARG(x) 80 #else 81 #define UT_DEBUG_ONLY_ARG(x) (void)(x); 82 #endif 83 84 /*! 85 * Confidence heuristic datatype normalized to the range 86 * [0,255] with 0 being least confident and 255 being the most confident 87 */ 88 typedef UT_uint8 UT_Confidence_t; 89 90 #define UT_CONFIDENCE_PERFECT 255 91 #define UT_CONFIDENCE_GOOD 170 92 #define UT_CONFIDENCE_SOSO 127 93 #define UT_CONFIDENCE_POOR 85 94 #define UT_CONFIDENCE_ZILCH 0 95 96 #include "ut_export.h" // ABI_EXPORT is defined in there. 97 98 #if __GNUC__ 99 #define ABI_NORETURN __attribute__((noreturn)) 100 #define ABI_PRINTF_FORMAT(f,a) __attribute__ ((format (printf, f, a))) 101 #else 102 #define ABI_NORETURN 103 #define ABI_PRINTF_FORMAT(f,a) 104 #endif 105 106 /* ABI_FAR_CALL: C function that we want to expose across plugin boundaries */ 107 #define ABI_FAR_CALL extern "C" ABI_PLUGIN_EXPORT 108 109 #define _abi_callonce /* only call me once! */ 110 111 /* 112 UT_Error should be used far more than it is. Any function 113 which reasonably could fail at runtime for anything other than 114 a coding error or bug should return an error code. Error codes 115 should be propogated properly. 116 117 Addendum: 1-23-99 118 If you have any problems with or suggestions for error codes, 119 please send them to Sam Tobin-Hochstadt (sytobinh@uchicago.edu). 120 I am the person that has worked the most with them. 121 */ 122 typedef UT_sint32 UT_Error; 123 #define UT_OK ((UT_Error) 0) 124 #define UT_ERROR ((UT_Error) -1) /* VERY generic */ 125 #define UT_OUTOFMEM ((UT_Error) -100) 126 #define UT_SAVE_WRITEERROR ((UT_Error) -201) 127 #define UT_SAVE_NAMEERROR ((UT_Error) -202) 128 #define UT_SAVE_EXPORTERROR ((UT_Error) -203) 129 #define UT_EXTENSIONERROR ((UT_Error) -204) 130 #define UT_SAVE_CANCELLED ((UT_Error) -205) 131 #define UT_SAVE_OTHERERROR ((UT_Error) -200) /* This should eventually dissapear. */ 132 #define UT_IE_FILENOTFOUND ((UT_Error) -301) 133 #define UT_IE_NOMEMORY ((UT_Error) -302) 134 #define UT_IE_UNKNOWNTYPE ((UT_Error) -303) 135 #define UT_IE_BOGUSDOCUMENT ((UT_Error) -304) 136 #define UT_IE_COULDNOTOPEN ((UT_Error) -305) 137 #define UT_IE_COULDNOTWRITE ((UT_Error) -306) 138 #define UT_IE_FAKETYPE ((UT_Error) -307) 139 #define UT_INVALIDFILENAME ((UT_Error) -308) 140 #define UT_NOPIECETABLE ((UT_Error) -309) 141 #define UT_IE_ADDLISTENERERROR ((UT_Error) -310) 142 #define UT_IE_UNSUPTYPE ((UT_Error) -311) 143 #define UT_IE_PROTECTED ((UT_Error) -312) // (pass) protected doc 144 #define UT_IE_SKIPINVALID ((UT_Error) -313) // (pass) protected doc 145 #define UT_IE_IMPORTERROR ((UT_Error) -300) /* The general case */ 146 #define UT_IE_IMPSTYLEUNSUPPORTED ((UT_Error) -314) 147 #define UT_IE_XMLNOANGLEBRACKET ((UT_Error) -360) 148 #define UT_IE_TRY_RECOVER ((UT_Error) -350) // try recovering the document. ie, we have 149 // imported something 150 151 #define UT_IS_IE_SUCCESS(x) (((x) == UT_OK) || ((x) == UT_IE_TRY_RECOVER)) 152 153 ABI_EXPORT UT_Error UT_errnoToUTError (void); 154 155 /* defined in ut_misc.cpp */ 156 ABI_EXPORT void * UT_calloc ( UT_uint32 nmemb, UT_uint32 size ); 157 158 /* 159 The MSVC debug runtime library can track leaks back to the 160 original allocation via the following black magic. 161 */ 162 #if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) 163 #include <crtdbg.h> 164 #define UT_DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 165 #define new UT_DEBUG_NEW 166 #endif /* _MSC_VER && _DEBUG && _CRTDBG_MAP_ALLOC */ 167 168 169 /* Unicode character constants. Try to use these rather than 170 ** decimal or hex constants throughout the code. See also bug 171 ** 512. 172 */ 173 174 /* When objects (fields, etc) must be represented in unicode, use the 175 BELL code and let UT_isWordDelimiter recognize it as a word 176 character. See bug 223. */ 177 #define UCS_ABI_OBJECT ((UT_UCSChar)0x0007) 178 179 #define UCS_TAB ((UT_UCSChar)0x0009) 180 #define UCS_LF ((UT_UCSChar)0x000a) 181 #define UCS_VTAB ((UT_UCSChar)0x000b) 182 #define UCS_FF ((UT_UCSChar)0x000c) 183 #define UCS_CR ((UT_UCSChar)0x000d) 184 #define UCS_SPACE ((UT_UCSChar)0x0020) 185 #define UCS_NBSP ((UT_UCSChar)0x00a0) 186 #define UCS_PILCROW ((UT_UCSChar)0x00b6) 187 #define UCS_LINESEP ((UT_UCSChar)0x2028) /* Unicode line separator */ 188 #define UCS_PARASEP ((UT_UCSChar)0x2029) /* Unicode paragraph separator */ 189 #define UCS_BOM ((UT_UCSChar)0xFEFF) /* Byte order mark */ 190 #define UCS_REPLACECHAR ((UT_UCSChar)0xFFFD) 191 #define UCS_HYPHEN ((UT_UCSChar)0x2010) 192 #define UCS_MINUS ((UT_UCSChar)0x2d) 193 194 /* Note: the following are our interpretations, not Unicode's */ 195 /* Note: use Unicode Private Use Area 0xE000 - 0xF8FF */ 196 /* Note: GB18030 mandates U+E000 - U+E765 for UDAs 1, 2 and 3 */ 197 /* Note: BIG5-HKSCS uses U+E000 - U+F848 */ 198 /* Note: Please update UCS_ABICONTROL_START/END if more */ 199 /* Note: special values are added. We need to watch out for */ 200 /* Note: them during import */ 201 #define UCS_ABICONTROL_START (UCS_FIELDSTART) 202 #define UCS_FIELDSTART ((UT_UCSChar)0xF850) 203 #define UCS_FIELDEND ((UT_UCSChar)0xF851) 204 #define UCS_BOOKMARKSTART ((UT_UCSChar)0xF852) 205 #define UCS_BOOKMARKEND ((UT_UCSChar)0xF853) 206 #define UCS_LIGATURE_PLACEHOLDER ((UT_UCS4Char)0xF854) 207 #define UCS_ABICONTROL_END (UCS_LIGATURE_PLACEHOLDER) 208 209 210 #if 1 /* try to use the unicode values for special chars */ 211 #define UCS_EN_SPACE ((UT_UCSChar)0x2002) 212 #define UCS_EM_SPACE ((UT_UCSChar)0x2003) 213 #define UCS_EN_DASH ((UT_UCSChar)0x2013) 214 #define UCS_EM_DASH ((UT_UCSChar)0x2014) 215 #define UCS_BULLET ((UT_UCSChar)0x2022) 216 /* TODO Quote marks need to be localized - not hard-coded */ 217 #define UCS_LQUOTE ((UT_UCSChar)0x2018) 218 #define UCS_RQUOTE ((UT_UCSChar)0x2019) 219 #define UCS_LDBLQUOTE ((UT_UCSChar)0x201c) 220 #define UCS_RDBLQUOTE ((UT_UCSChar)0x201d) 221 222 /* Note: the following is our interpretation, not Unicode's */ 223 #define UCS_UNKPUNK ((UT_UCSChar)0xFFFF) /* "unknown punctuation" used with UT_isWordDelimiter() */ 224 225 #else /* see bug 512 */ 226 227 #define UCS_EN_SPACE ((UT_UCSChar)0x0020) 228 #define UCS_EM_SPACE ((UT_UCSChar)0x0020) 229 #define UCS_EN_DASH ((UT_UCSChar)0x002d) 230 #define UCS_EM_DASH ((UT_UCSChar)0x002d) 231 #define UCS_BULLET ((UT_UCSChar)0x0095) 232 #define UCS_LQUOTE ((UT_UCSChar)0x0027) 233 #define UCS_RQUOTE ((UT_UCSChar)0x0027) 234 #define UCS_LDBLQUOTE ((UT_UCSChar)0x0022) 235 #define UCS_RDBLQUOTE ((UT_UCSChar)0x0022) 236 #define UCS_UNKPUNK ((UT_UCSChar)0x00FF) 237 238 #endif 239 240 /* direction markers */ 241 #define UCS_LRM 0x200E 242 #define UCS_RLM 0x200F 243 #define UCS_LRE 0x202a 244 #define UCS_RLE 0x202b 245 #define UCS_PDF 0x202c 246 #define UCS_LRO 0x202d 247 #define UCS_RLO 0x202e 248 249 /* 250 ** Some useful macros that we use throughout 251 */ 252 253 #define FREEP(p) do { if (p) { g_free((void *)p); (p)=NULL; } } while (0) 254 #define DELETEP(p) do { if (p) { delete(p); (p)=NULL; } } while (0) 255 #define DELETEPV(pa) do { if (pa) { delete [] (pa); (pa)=NULL; } } while (0) 256 #define REPLACEP(p,q) do { if (p) delete p; p = q; } while (0) 257 #define REFP(p) ((p)->ref(), (p)) 258 #define UNREFP(p) do { if (p) { (p)->unref(); (p)=NULL; } } while (0) 259 #define CLONEP(p,q) do { FREEP(p); if (q && *q) p = g_strdup(q); } while (0) 260 261 #define E2B(err) ((err) == UT_OK) 262 263 /* This is a value from the private-use space of FriBidi */ 264 #define FRIBIDI_TYPE_UNSET -1 265 #define FRIBIDI_TYPE_IGNORE -2 266 267 // this is maximum revision level; it is intentionally not defined as 268 // 0xffffffff to avoid problems with bad 64-bit compilers 269 270 #define PD_MAX_REVISION 0x0fffffff 271 272 #endif /* UT_TYPES_H */ 273