[2674] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: utypes.h 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifndef UTYPES_H |
---|
| 23 | #define UTYPES_H |
---|
| 24 | #include <wchar.h> |
---|
| 25 | #include <stdlib.h> |
---|
| 26 | |
---|
| 27 | /*===========================================================================*/ |
---|
| 28 | /* Include platform-dependent definitions */ |
---|
| 29 | /* which are contained in the platform-specific file platform.h */ |
---|
| 30 | /*===========================================================================*/ |
---|
| 31 | |
---|
| 32 | #include "pos400.h" |
---|
| 33 | |
---|
| 34 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 35 | |
---|
| 36 | /* XP_CPLUSPLUS is a cross-platform symbol which should be defined when |
---|
| 37 | using C++. It should not be defined when compiling under C. */ |
---|
| 38 | #ifdef __cplusplus |
---|
| 39 | # ifndef XP_CPLUSPLUS |
---|
| 40 | # define XP_CPLUSPLUS |
---|
| 41 | # endif |
---|
| 42 | #else |
---|
| 43 | # undef XP_CPLUSPLUS |
---|
| 44 | #endif |
---|
| 45 | |
---|
| 46 | /*===========================================================================*/ |
---|
| 47 | /* Boolean data type */ |
---|
| 48 | /*===========================================================================*/ |
---|
| 49 | |
---|
| 50 | #if ! HAVE_BOOL_T |
---|
| 51 | typedef int8_t bool_t; |
---|
| 52 | #endif |
---|
| 53 | |
---|
| 54 | #ifndef TRUE |
---|
| 55 | # define TRUE 1 |
---|
| 56 | #endif |
---|
| 57 | #ifndef FALSE |
---|
| 58 | # define FALSE 0 |
---|
| 59 | #endif |
---|
| 60 | |
---|
| 61 | /*===========================================================================*/ |
---|
| 62 | /* Unicode string offset */ |
---|
| 63 | /*===========================================================================*/ |
---|
| 64 | typedef int32_t UTextOffset; |
---|
| 65 | |
---|
| 66 | /*===========================================================================*/ |
---|
| 67 | /* Unicode character */ |
---|
| 68 | /*===========================================================================*/ |
---|
| 69 | typedef uint16_t UChar; |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /*===========================================================================*/ |
---|
| 73 | /* For C wrappers, we use the symbol U_CAPI. */ |
---|
| 74 | /* This works properly if the includer is C or C++. */ |
---|
| 75 | /* Functions are declared U_CAPI return-type U_EXPORT2 function-name() ... */ |
---|
| 76 | /*===========================================================================*/ |
---|
| 77 | |
---|
| 78 | #ifdef XP_CPLUSPLUS |
---|
| 79 | # define U_CFUNC extern "C" |
---|
| 80 | # define U_CDECL_BEGIN extern "C" { |
---|
| 81 | # define U_CDECL_END } |
---|
| 82 | #else |
---|
| 83 | # define U_CFUNC |
---|
| 84 | # define U_CDECL_BEGIN |
---|
| 85 | # define U_CDECL_END |
---|
| 86 | #endif |
---|
| 87 | #define U_CAPI U_CFUNC U_EXPORT |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | /* Define NULL pointer value if it isn't already defined */ |
---|
| 91 | |
---|
| 92 | #ifndef NULL |
---|
| 93 | #ifdef XP_CPLUSPLUS |
---|
| 94 | #define NULL 0 |
---|
| 95 | #else |
---|
| 96 | #define NULL ((void *)0) |
---|
| 97 | #endif |
---|
| 98 | #endif |
---|
| 99 | |
---|
| 100 | /* Maximum value of a (void*) - use to indicate the limit of |
---|
| 101 | an 'infinite' buffer. */ |
---|
| 102 | #define U_MAX_PTR ((void*)-1) |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /*===========================================================================*/ |
---|
| 107 | /* UErrorCode */ |
---|
| 108 | /*===========================================================================*/ |
---|
| 109 | |
---|
| 110 | /** Error code to replace exception handling */ |
---|
| 111 | #ifdef __OS400__ |
---|
| 112 | enum UErrorCode1 { |
---|
| 113 | #else |
---|
| 114 | enum UErrorCode { |
---|
| 115 | #endif |
---|
| 116 | U_ERROR_INFO_START = -128, /* Start of information results (semantically successful) */ |
---|
| 117 | U_USING_FALLBACK_ERROR = -128, |
---|
| 118 | U_USING_DEFAULT_ERROR = -127, |
---|
| 119 | U_ERROR_INFO_LIMIT, |
---|
| 120 | |
---|
| 121 | U_ZERO_ERROR = 0, /* success */ |
---|
| 122 | |
---|
| 123 | U_ILLEGAL_ARGUMENT_ERROR = 1, /* Start of codes indicating failure */ |
---|
| 124 | U_MISSING_RESOURCE_ERROR = 2, |
---|
| 125 | U_INVALID_FORMAT_ERROR = 3, |
---|
| 126 | U_FILE_ACCESS_ERROR = 4, |
---|
| 127 | U_INTERNAL_PROGRAM_ERROR = 5, /* Indicates a bug in the library code */ |
---|
| 128 | U_MESSAGE_PARSE_ERROR = 6, |
---|
| 129 | U_MEMORY_ALLOCATION_ERROR = 7, /* Memory allocation error */ |
---|
| 130 | U_INDEX_OUTOFBOUNDS_ERROR = 8, |
---|
| 131 | U_PARSE_ERROR = 9, /* Equivalent to Java ParseException */ |
---|
| 132 | U_INVALID_CHAR_FOUND = 10, /* In the Character conversion routines: Invalid character or sequence was encountered*/ |
---|
| 133 | U_TRUNCATED_CHAR_FOUND = 11, /* In the Character conversion routines: More bytes are required to complete the conversion successfully*/ |
---|
| 134 | U_ILLEGAL_CHAR_FOUND = 12, /* In codeset conversion: a sequence that does NOT belong in the codepage has been encountered*/ |
---|
| 135 | U_INVALID_TABLE_FORMAT = 13, /* Conversion table file found, but corrupted*/ |
---|
| 136 | U_INVALID_TABLE_FILE = 14, /* Conversion table file not found*/ |
---|
| 137 | U_BUFFER_OVERFLOW_ERROR = 15, /* A result would not fit in the supplied buffer */ |
---|
| 138 | U_UNSUPPORTED_ERROR = 16, /* Requested operation not supported in current context */ |
---|
| 139 | U_ERROR_LIMIT |
---|
| 140 | }; |
---|
| 141 | #ifdef __OS400__ |
---|
| 142 | typedef int UErrorCode; |
---|
| 143 | #define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) |
---|
| 144 | #define U_FAILURE(x) ((x)>U_ZERO_ERROR) |
---|
| 145 | #else |
---|
| 146 | #ifndef XP_CPLUSPLUS |
---|
| 147 | typedef enum UErrorCode UErrorCode; |
---|
| 148 | #endif |
---|
| 149 | #endif |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | /* Use the following to determine if an UErrorCode represents */ |
---|
| 153 | /* operational success or failure. */ |
---|
| 154 | #ifndef __OS400__ |
---|
| 155 | #ifdef XP_CPLUSPLUS |
---|
| 156 | inline bool_t U_SUCCESS(UErrorCode code) { return (bool_t)(code<=U_ZERO_ERROR); } |
---|
| 157 | inline bool_t U_FAILURE(UErrorCode code) { return (bool_t)(code>U_ZERO_ERROR); } |
---|
| 158 | #else |
---|
| 159 | #define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) |
---|
| 160 | #define U_FAILURE(x) ((x)>U_ZERO_ERROR) |
---|
| 161 | #endif |
---|
| 162 | #endif |
---|
| 163 | |
---|
| 164 | /* Casting function for int32_t (backward compatibility version, here until |
---|
| 165 | T_INT32 is replaced) */ |
---|
| 166 | #define T_INT32(i) ((int32_t)i) |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | /*===========================================================================*/ |
---|
| 170 | /* Debugging */ |
---|
| 171 | /*===========================================================================*/ |
---|
| 172 | |
---|
| 173 | /* remove this */ |
---|
| 174 | |
---|
| 175 | /* This function is useful for debugging; it returns the text name */ |
---|
| 176 | /* of an UErrorCode result. This is not the most efficient way of */ |
---|
| 177 | /* doing this but it's just for Debug builds anyway. */ |
---|
| 178 | |
---|
| 179 | /* Do not use these arrays directly: they will move to a .c file! */ |
---|
| 180 | static const char * |
---|
| 181 | _uErrorInfoName[U_ERROR_INFO_LIMIT-U_ERROR_INFO_START]={ |
---|
| 182 | "U_USING_FALLBACK_ERROR", |
---|
| 183 | "U_USING_DEFAULT_ERROR" |
---|
| 184 | }; |
---|
| 185 | |
---|
| 186 | static const char * |
---|
| 187 | _uErrorName[U_ERROR_LIMIT]={ |
---|
| 188 | "U_ZERO_ERROR", |
---|
| 189 | |
---|
| 190 | "U_ILLEGAL_ARGUMENT_ERROR", |
---|
| 191 | "U_MISSING_RESOURCE_ERROR", |
---|
| 192 | "U_INVALID_FORMAT_ERROR", |
---|
| 193 | "U_FILE_ACCESS_ERROR", |
---|
| 194 | "U_INTERNAL_PROGRAM_ERROR", |
---|
| 195 | "U_MESSAGE_PARSE_ERROR", |
---|
| 196 | "U_MEMORY_ALLOCATION_ERROR", |
---|
| 197 | "U_INDEX_OUTOFBOUNDS_ERROR", |
---|
| 198 | "U_PARSE_ERROR", |
---|
| 199 | "U_INVALID_CHAR_FOUND", |
---|
| 200 | "U_TRUNCATED_CHAR_FOUND", |
---|
| 201 | "U_ILLEGAL_CHAR_FOUND", |
---|
| 202 | "U_INVALID_TABLE_FORMAT", |
---|
| 203 | "U_INVALID_TABLE_FILE", |
---|
| 204 | "U_BUFFER_OVERFLOW_ERROR", |
---|
| 205 | "U_UNSUPPORTED_ERROR" |
---|
| 206 | }; |
---|
| 207 | |
---|
| 208 | #ifdef XP_CPLUSPLUS |
---|
| 209 | inline const char * |
---|
| 210 | errorName(UErrorCode code) |
---|
| 211 | { |
---|
| 212 | if(code>=0 && code<U_ERROR_LIMIT) { |
---|
| 213 | return _uErrorName[code]; |
---|
| 214 | } else if(code>=U_ERROR_INFO_START && code<U_ERROR_INFO_LIMIT) { |
---|
| 215 | return _uErrorInfoName[code-U_ERROR_INFO_START]; |
---|
| 216 | } else { |
---|
| 217 | return "[BOGUS UErrorCode]"; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | #else |
---|
| 221 | # define errorName(code) \ |
---|
| 222 | ((code)>=0 && (code)<U_ERROR_LIMIT) ? \ |
---|
| 223 | _uErrorName[code] : \ |
---|
| 224 | ((code)>=U_ERROR_INFO_START && (code)<U_ERROR_INFO_LIMIT) ? \ |
---|
| 225 | _uErrorInfoName[code-U_ERROR_INFO_START] : \ |
---|
| 226 | "[BOGUS UErrorCode]" |
---|
| 227 | #endif |
---|
| 228 | |
---|
| 229 | XERCES_CPP_NAMESPACE_END |
---|
| 230 | |
---|
| 231 | #endif /* _UTYPES */ |
---|