00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __UTIL_H__
00031 #define __UTIL_H__
00032
00034
00035 #ifndef __unix
00036 #undef NOUSER
00037 #ifndef _WIN32_WINNT
00038 #define _WIN32_WINNT 0x0400
00039 #endif
00040 #endif
00041
00042
00043
00044
00045
00046 extern unsigned SyncRandSeed;
00047
00048 extern void InitSyncRand();
00049 extern int SyncRand();
00050 extern int SyncRand(int max);
00051
00053 extern int MyRand();
00054
00055
00056
00057
00058
00060 extern long isqrt(long num);
00061
00062 inline int square(int v)
00063 {
00064 return v * v;
00065 }
00066
00067 template <typename T>
00068 void clamp(T *value, T minValue, T maxValue)
00069 {
00070 Assert(minValue <= maxValue);
00071
00072 if (*value < minValue) {
00073 *value = minValue;
00074 } else if (maxValue < *value) {
00075 *value = maxValue;
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00084 #if !defined(_MSC_VER) || _MSC_VER < 1400
00085 #define _TRUNCATE ((size_t)-1)
00086 extern unsigned int strcpy_s(char *dst, size_t dstsize, const char *src);
00087 extern unsigned int strncpy_s(char *dst, size_t dstsize, const char *src, size_t count);
00088 extern unsigned int strcat_s(char *dst, size_t dstsize, const char *src);
00089 #endif
00090
00091 #ifndef HAVE_STRCASESTR
00093 extern char *strcasestr(const char *str, const char *substr);
00094 #endif // !HAVE_STRCASESTR
00095
00096 #ifndef HAVE_STRNLEN
00098 extern size_t strnlen(const char *str, size_t strsize);
00099 #endif // !HAVE_STRNLEN
00100
00101
00102
00103
00104
00105 #include <string>
00106
00107 int GetClipboard(std::string &str);
00108
00109
00110
00111
00112
00113 int UTF8GetNext(const std::string &text, int curpos);
00114 int UTF8GetPrev(const std::string &text, int curpos);
00115
00117
00118 #endif