00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _ATX_UTILS_H_
00011 #define _ATX_UTILS_H_
00012
00013
00014
00015
00016 #include "AtxConfig.h"
00017 #include "AtxString.h"
00018 #include "AtxTypes.h"
00019
00020 #if defined(ATX_CONFIG_HAVE_STDLIB_H)
00021 #include <stdlib.h>
00022 #endif
00023
00024 #if defined(ATX_CONFIG_HAVE_STRING_H)
00025 #include <string.h>
00026 #endif
00027
00028 #if defined(ATX_CONFIG_HAVE_STDIO_H)
00029 #include <stdio.h>
00030 #endif
00031
00032 #if defined(ATX_CONFIG_HAVE_STDARG_H)
00033 #include <stdarg.h>
00034 #endif
00035
00036 #if defined(ATX_CONFIG_HAVE_CTYPE_H)
00037 #include <ctype.h>
00038 #endif
00039
00040 #if defined(DMALLOC)
00041 #include <dmalloc.h>
00042 #endif
00043
00044 #if defined(_WIN32) && defined(_DEBUG) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
00045 #include <crtdbg.h>
00046 #endif
00047
00048
00049
00050
00051 #define ATX_ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
00052 #define ATX_QUOTE(x) #x
00053
00054
00055
00056
00057 #define ATX_SET_CSTRING(s, n) \
00058 do { \
00059 if ((s) != (ATX_CString)(0)) { \
00060 ATX_FreeMemory((void*)(s)); \
00061 (s) = 0; \
00062 } \
00063 if ((n) != (ATX_CString)(0)) { \
00064 (s) = ATX_DuplicateString(n); \
00065 } \
00066 } while (0)
00067
00068 #define ATX_DESTROY_CSTRING(s) \
00069 do { \
00070 if ((s) != (ATX_CString)(0)) { \
00071 ATX_FreeMemory((void*)(s)); \
00072 (s) = 0; \
00073 } \
00074 } while (0)
00075
00076 #ifdef __cplusplus
00077 extern "C" {
00078 #endif
00079
00080
00081
00082
00083 extern ATX_Result
00084 ATX_ParseFloat(const char* str, float* result, ATX_Boolean relaxed);
00085
00086 extern ATX_Result
00087 ATX_ParseInteger(const char* str, long* result, ATX_Boolean relaxed);
00088
00089 extern ATX_Result
00090 ATX_ParseIntegerU(const char* str, unsigned long* result, ATX_Boolean relaxed);
00091
00092 extern ATX_Result
00093 ATX_ParseInteger32(const char* str, ATX_Int32* result, ATX_Boolean relaxed);
00094
00095 extern ATX_Result
00096 ATX_ParseInteger32U(const char* str, ATX_UInt32* result, ATX_Boolean relaxed);
00097
00098 extern ATX_Result
00099 ATX_FloatToString(float value, char* buffer, ATX_Size buffer_size);
00100
00101 extern ATX_Result
00102 ATX_IntegerToString(ATX_Int3264 value, char* buffer, ATX_Size buffer_size);
00103
00104 extern ATX_Result
00105 ATX_IntegerToStringU(ATX_UInt3264 value, char* buffer, ATX_Size buffer_size);
00106
00107
00108
00109
00110 extern void ATX_BytesFromInt32Be(unsigned char* buffer, ATX_UInt32 value);
00111 extern void ATX_BytesFromInt16Be(unsigned char* buffer, ATX_UInt16 value);
00112 extern ATX_UInt32 ATX_BytesToInt32Be(const unsigned char* buffer);
00113 extern ATX_UInt16 ATX_BytesToInt16Be(const unsigned char* buffer);
00114
00115 extern void ATX_BytesFromInt32Le(unsigned char* buffer, ATX_UInt32 value);
00116 extern void ATX_BytesFromInt16Le(unsigned char* buffer, ATX_UInt16 value);
00117 extern ATX_UInt32 ATX_BytesToInt32Le(const unsigned char* buffer);
00118 extern ATX_UInt16 ATX_BytesToInt16Le(const unsigned char* buffer);
00119
00120
00121
00122
00123 extern void
00124 ATX_FormatOutput(void (*function)(void* parameter, const char* message),
00125 void* function_parameter,
00126 const char* format,
00127 va_list args);
00128
00129
00130
00131
00143 ATX_Result ATX_GetEnvironment(const char* name, ATX_String* value);
00144
00145
00146
00147
00152 void ATX_ScrubMemory(void* buffer, ATX_Size size);
00153
00154
00155
00156
00157 #if defined(ATX_CONFIG_HAVE_MALLOC)
00158 #define ATX_AllocateMemory malloc
00159 #else
00160 extern void* ATX_AllocateMemory(unsigned int);
00161 #endif
00162
00163 #if defined(ATX_CONFIG_HAVE_CALLOC)
00164 #define ATX_AllocateZeroMemory(x) calloc(1,(x))
00165 #else
00166 extern void* ATX_AllocateZeroMemory(unsigned int);
00167 #endif
00168
00169 #if defined(ATX_CONFIG_HAVE_FREE)
00170 #define ATX_FreeMemory free
00171 #else
00172 extern void ATX_FreeMemory(void* pointer);
00173 #endif
00174
00175 #if defined(ATX_CONFIG_HAVE_MEMCPY)
00176 #define ATX_CopyMemory memcpy
00177 #else
00178 extern void ATX_CopyMemory(void* dest, const void* src, ATX_Size size);
00179 #endif
00180
00181 #if defined(ATX_CONFIG_HAVE_MEMMOVE)
00182 #define ATX_MoveMemory memmove
00183 #else
00184 extern void ATX_MoveMemory(void* dest, const void* src, ATX_Size size);
00185 #endif
00186
00187 #if defined(ATX_CONFIG_HAVE_MEMSET)
00188 #define ATX_SetMemory memset
00189 #else
00190 extern void ATX_SetMemory(void* dest, int c, ATX_Size size);
00191 #endif
00192
00193 #if defined(ATX_CONFIG_HAVE_STRCPY)
00194 #define ATX_CopyString(dst, src) ((void)strcpy((dst), (src)))
00195 #else
00196 extern void ATX_CopyString(char* dst, const char* src);
00197 #endif
00198
00199 #if defined(ATX_CONFIG_HAVE_STRNCPY)
00200 #define ATX_CopyStringN(dst, src, n) ((void)ATX_strncpy((dst), (src), n))
00201 #else
00202 extern int ATX_CopyStringN(char* dst, const char* src, unsigned long n);
00203 #endif
00204
00205 #if defined(ATX_CONFIG_HAVE_STRCMP)
00206 #define ATX_StringsEqual(s1, s2) (strcmp((s1), (s2)) == 0)
00207 #define ATX_CompareStrings(s1, s2) strcmp(s1, s2)
00208 #else
00209 extern int ATX_StringsEqual(const char* s1, const char* s2);
00210 extern int ATX_CompareStrings(const char* s1, const char* s2);
00211 #endif
00212
00213 #if defined(ATX_CONFIG_HAVE_STRNCMP)
00214 #define ATX_StringsEqualN(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
00215 #else
00216 extern int ATX_StringsEqualN(const char* s1, const char* s2, unsigned long size);
00217 #endif
00218
00219 #if defined(ATX_CONFIG_HAVE_STRCHR)
00220 #define ATX_FindChar(s, c) strchr(s, c)
00221 #else
00222 extern int ATX_FindChar(const char* s, char c);
00223 #endif
00224
00225 #if defined(ATX_CONFIG_HAVE_STRDUP)
00226 #define ATX_DuplicateString(s) ATX_strdup(s)
00227 #else
00228 extern char* ATX_DuplicateString(const char* s);
00229 #endif
00230
00231 #if defined(ATX_CONFIG_HAVE_STRLEN)
00232 #define ATX_StringLength(s) (ATX_Size)strlen(s)
00233 #else
00234 extern unsigned long ATX_StringLength(const char* s);
00235 #endif
00236
00237 #if defined(ATX_CONFIG_HAVE_SNPRINTF)
00238 #define ATX_FormatStringN ATX_snprintf
00239 #else
00240 extern int ATX_FormatStringN(char *buffer, size_t count, const char *format, ...);
00241 #endif
00242
00243 #if defined(ATX_CONFIG_HAVE_VSNPRINTF)
00244 #define ATX_FormatStringVN(s,c,f,a) ATX_vsnprintf(s,c,f,a)
00245 #else
00246 extern int ATX_FormatStringVN(char *buffer, size_t count, const char *format, va_list argptr);
00247 #endif
00248
00249 #if defined(ATX_CONFIG_HAVE_IS_SPACE)
00250 #define ATX_IsSpace(c) isspace(c)
00251 #else
00252 extern int ATX_IsSpace(int c);
00253 #endif
00254
00255 #if defined(ATX_CONFIG_HAVE_IS_ALNUM)
00256 #define ATX_IsAlphaNumeric(c) isalnum(c)
00257 #else
00258 extern int ATX_IsAlphaNumeric(int c);
00259 #endif
00260
00261 #if defined(ATX_CONFIG_HAVE_MEMCMP)
00262 #define ATX_MemoryEqual(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
00263 #else
00264 extern int ATX_MemoryEqual(const void* s1, const void* s2, unsigned long n);
00265 #endif
00266
00267 #if defined(ATX_CONFIG_HAVE_ATEXIT)
00268 #define ATX_AtExit(_fun) atexit(_fun)
00269 #else
00270 extern int atexit(void (*func )( void ));
00271 #endif
00272
00273 #ifdef __cplusplus
00274 }
00275 #endif
00276
00277 #endif