19 #ifndef _DSL_GENLIB_H_
20 #define _DSL_GENLIB_H_
22 DSL_API_CLASS
const char * DSL_CC
nopathA(
const char * filename);
23 DSL_API_CLASS
const wchar_t * DSL_CC
nopathW(
const wchar_t * filename);
24 DSL_API_CLASS
char * DSL_CC
nopathA(
char * filename);
25 DSL_API_CLASS
wchar_t * DSL_CC
nopathW(
wchar_t * filename);
34 DSL_API_CLASS
char * DSL_CC
bin2hex(
const uint8_t * data,
size_t datalen,
char * out,
size_t outsize);
40 DSL_API_CLASS
string DSL_CC
bin2hex(
const uint8_t * data,
size_t datalen);
49 DSL_API_CLASS
bool DSL_CC
hex2bin(
const char * instr,
size_t inlen, uint8 * out,
size_t outsize);
56 DSL_API_CLASS
bool DSL_CC
hex2bin(
const char * instr, uint8 * out,
size_t outsize);
61 DSL_API_CLASS
bool DSL_CC
hex2bin(
const string instr, vector<uint8_t>& out);
63 DSL_API
void DSL_CC
PrintData(FILE * fp,
const uint8 * ptr,
size_t len);
65 #if defined(WIN32) || defined(DOXYGEN_SKIP)
66 DSL_API_CLASS
const char * DSL_CC stristr(
const char * haystack,
const char * needle);
67 DSL_API_CLASS
char * DSL_CC stristr(
char * haystack,
const char * needle);
68 DSL_API
char * DSL_CC strtok_r(
char *newstring,
const char *delimiters,
char ** save_ptr);
69 time_t filetime_2_time_t(FILETIME ft);
70 DSL_API
struct tm * DSL_CC localtime_r(
const time_t * tme,
struct tm * out);
71 DSL_API
struct tm * DSL_CC gmtime_r(
const time_t * tme,
struct tm * out);
73 DSL_API
char * DSL_CC
strlwr(
char * str);
78 DSL_API
bool DSL_CC
dsl_mkdir_r(
const char * p,
int mode);
79 DSL_API
bool DSL_CC
strempty(
const char * p);
80 DSL_API int64 DSL_CC
dsl_clamp(int64 value, int64 vMin, int64 vMax);
82 DSL_API_CLASS
char * DSL_CC
escapeshellarg(
const char * p,
char * out,
size_t outSize);
85 #if defined(OPENBSD) || defined(FREEBSD)
89 #if !defined(HAVE_STRLCPY)
93 DSL_API
size_t DSL_CC
strlcpy(
char * dst,
const char * src,
size_t siz);
97 DSL_API
size_t DSL_CC
strlcat(
char * dst,
const char * src,
size_t siz);
102 #define sstrcpy(x,y) strlcpy(x,y,sizeof(x))
106 #define sstrcat(x,y) strlcat(x,y,sizeof(x))
109 #define TRIM_LEFT 0x01
110 #define TRIM_RIGHT 0x02
111 #define TRIM_BOTH (TRIM_LEFT|TRIM_RIGHT)
120 DSL_API
char * DSL_CC
strtrim(
char *buf,
const char * trim =
"\r\n\t ", uint8 sides = TRIM_BOTH);
126 DSL_API
int DSL_CC
wildcmp(
const char *wild,
const char *
string);
131 DSL_API
int DSL_CC
wildicmp(
const char *wild,
const char *
string);
137 DSL_API
int DSL_CC
wildicmp_multi(
const char *wild,
const char *
string,
const char *sep =
"|");
139 DSL_API int64 DSL_CC
fseek64(FILE * fp, int64 offset,
int whence);
140 DSL_API int64 DSL_CC
ftell64(FILE * fp);
141 DSL_API int64 DSL_CC
filesize(
const char * fn);
143 DSL_API
int DSL_CC truncate(
const char * fn, int64 size);
152 DSL_API_CLASS
bool DSL_CC
file_get_contents(
const string& fn, vector<uint8>& data, int64 maxSize=INT32_MAX);
159 DSL_API_CLASS
bool DSL_CC
file_get_contents(
const string& fn,
string& data, int64 maxSize=INT32_MAX);
167 DSL_API_CLASS
bool DSL_CC
file_get_contents(
const string& fn, uint8 ** data, int64& fileSize, int64 maxSize=INT32_MAX);
168 DSL_API_CLASS
bool DSL_CC file_put_contents(
const string& fn,
const vector<uint8>& data,
bool append =
false);
169 DSL_API_CLASS
bool DSL_CC file_put_contents(
const string& fn,
const string& data,
bool append =
false);
170 DSL_API_CLASS
bool DSL_CC file_put_contents(
const string& fn,
const uint8 * data,
size_t fileSize,
bool append =
false);
176 DSL_API int64 DSL_CC
copy_file(
const string& src,
const string& dest,
bool allow_overwrite =
false);
178 DSL_API_CLASS
int DSL_CC
str_replaceA(
char *Str,
size_t BufSize,
const char *FindStr,
const char *ReplStr);
179 DSL_API_CLASS
int DSL_CC
str_replaceW(
wchar_t *Str,
size_t BufSize,
const wchar_t * FindStr,
const wchar_t * ReplStr);
181 DSL_API_CLASS
string DSL_CC
str_replaceA(
const string& str,
const string& FindStr,
const string& ReplStr);
182 DSL_API_CLASS wstring DSL_CC
str_replaceW(
const wstring& str,
const wstring& FindStr,
const wstring& ReplStr);
184 DSL_API
char * DSL_CC tchar2charA(
char * str);
185 DSL_API
char * DSL_CC tchar2charW(
wchar_t * str);
206 DSL_API
wchar_t * DSL_CC
GetUserConfigFileW(
const wchar_t * name,
const wchar_t * fn);
217 DSL_API
char * DSL_CC tcstombsA(
const char * str);
218 DSL_API
char * DSL_CC tcstombsW(
const wchar_t * str);
219 DSL_API
wchar_t * DSL_CC tcstowcsW(
const wchar_t * str);
220 DSL_API
wchar_t * DSL_CC tcstowcsA(
const char * str);
221 DSL_API
char * DSL_CC mbstotcsA(
const char * str);
222 DSL_API
char * DSL_CC wcstotcsA(
const wchar_t * str);
223 DSL_API
wchar_t * DSL_CC mbstotcsW(
const char * str);
224 DSL_API
wchar_t * DSL_CC wcstotcsW(
const wchar_t * str);
225 DSL_API
size_t DSL_CC wcscnt(
const wchar_t * ptr);
229 #define str_replace str_replaceW
230 #define tchar2char tchar2charW
231 #define tcstombs tcstombsW
232 #define tcstowcs tcstowcsW
233 #define mbstotcs mbstotcsW
234 #define wcstotcs wcstotcsW
235 #define nopath nopathW
236 #define GetUserConfigFolder GetUserConfigFolderW
237 #define GetUserConfigFile GetUserConfigFileW
238 #define GetUserDocumentsFolder #error Not implemented
240 #define str_replace str_replaceA
241 #define tchar2char tchar2charA
242 #define tcstombs tcstombsA
243 #define tcstowcs tcstowcsA
244 #define mbstotcs mbstotcsA
245 #define wcstotcs wcstotcsA
246 #define nopath nopathA
247 #define GetUserConfigFolder GetUserConfigFolderA
248 #define GetUserConfigFile GetUserConfigFileA
249 #define GetUserDocumentsFolder GetUserDocumentsFolderA
257 template <
typename T>
259 T in = value - srcmin;
260 T indiff = srcmax - srcmin;
261 T outdiff = destmax - destmin;
262 return ((in * outdiff) / indiff) + destmin;
269 #if defined(__cplusplus) && __cplusplus < 201703L
270 template <
typename T>
272 if (v < vMin) {
return vMin; }
273 if (v > vMax) {
return vMax; }
283 bool b_strdup =
false;
284 char *
string = NULL;
286 char sep_str[2] = { 0,0 };
288 size_t num_tokens = 0;
289 char ** tokens = NULL;
296 StrTokenizer(
char * str,
char separater,
bool do_strdup=
true);
301 char * GetTok(
size_t first,
size_t last);
302 char * GetSingleTok(
size_t num);
303 void FreeString(
char * buf);
305 std::string stdGetTok(
size_t first,
size_t last);
306 std::string stdGetSingleTok(
size_t num);
312 DSL_API
const char * DSL_CC FirstInvalidUTF8(
const char *s);
330 DSL_API uint16 DSL_CC
Get_ULE16(uint16 x);
332 DSL_API uint32 DSL_CC
Get_ULE32(uint32 x);
334 DSL_API uint64 DSL_CC
Get_ULE64(uint64 x);
337 DSL_API uint16 DSL_CC
Get_UBE16(uint16 x);
339 DSL_API uint32 DSL_CC
Get_UBE32(uint32 x);
341 DSL_API uint64 DSL_CC
Get_UBE64(uint64 x);
DSL_API uint64 DSL_CC Get_ULE64(uint64 x)
Convert from the native endianness to Little Endian.
DSL_API int64 DSL_CC Get_SBE64(int64 x)
Convert from the native endianness to Big Endian.
DSL_API uint16 DSL_CC ByteSwap16(uint16 X)
Byte swap a 16-bit unsigned integer.
DSL_API int32 DSL_CC Get_SBE32(int32 x)
Convert from the native endianness to Big Endian.
DSL_API int32 DSL_CC Get_SLE32(int32 x)
Convert from the native endianness to Little Endian.
DSL_API uint16 DSL_CC Get_UBE16(uint16 x)
Convert from the native endianness to Big Endian.
DSL_API uint64 DSL_CC ByteSwap64(uint64 val)
Byte swap a 64-bit unsigned integer.
DSL_API int16 DSL_CC Get_SBE16(int16 x)
Convert from the native endianness to Big Endian.
DSL_API uint32 DSL_CC Get_ULE32(uint32 x)
Convert from the native endianness to Little Endian.
DSL_API int16 DSL_CC Get_SLE16(int16 x)
Convert from the native endianness to Little Endian.
DSL_API uint32 DSL_CC Get_UBE32(uint32 x)
Convert from the native endianness to Big Endian.
DSL_API uint32 DSL_CC ByteSwap32(uint32 X)
Byte swap a 32-bit unsigned integer.
DSL_API uint64 DSL_CC Get_UBE64(uint64 x)
Convert from the native endianness to Big Endian.
DSL_API uint16 DSL_CC Get_ULE16(uint16 x)
Convert from the native endianness to Little Endian.
DSL_API int64 DSL_CC Get_SLE64(int64 x)
Convert from the native endianness to Little Endian.
DSL_API char *DSL_CC strlwr(char *str)
Linux version of strlwr.
DSL_API uint64 DSL_CC GetTickCount64()
Linux version of GetTickCount64.
DSL_API bool DSL_CC IsValidUTF8(const char *s)
Checks if the string is valid UTF-8 (no invalid UTF-8 sequences, etc.)
DSL_API int64 DSL_CC copy_file(const string &src, const string &dest, bool allow_overwrite=false)
DSL_API size_t DSL_CC strlcpy(char *dst, const char *src, size_t siz)
DSL_API_CLASS char *DSL_CC bin2hex(const uint8_t *data, size_t datalen, char *out, size_t outsize)
DSL_API_CLASS bool DSL_CC hex2bin(const char *instr, size_t inlen, uint8 *out, size_t outsize)
DSL_API bool DSL_CC dsl_mkdir_r(const char *p, int mode)
Cross-platform recursive mkdir()
DSL_API wchar_t *DSL_CC GetUserConfigFolderW(const wchar_t *name)
Unicode version of...
DSL_API bool DSL_CC strempty(const char *p)
Returns true if a string is empty (p == NULL || *p == 0)
DSL_API_CLASS int DSL_CC str_replaceA(char *Str, size_t BufSize, const char *FindStr, const char *ReplStr)
Simple string replacement.
DSL_API void DSL_CC PrintData(FILE *fp, const uint8 *ptr, size_t len)
Prints binary data in a pretty format.
DSL_API_CLASS const char *DSL_CC nopathA(const char *filename)
Returns just the file portion of the full path and filename.
T clamp(T v, T vMin, T vMax)
DSL_API int64 DSL_CC ftell64(FILE *fp)
Cross-platform 64-bit ftell.
DSL_API_CLASS char *DSL_CC GetUserConfigFileA(const char *name, const char *fn)
DSL_API_CLASS char *DSL_CC GetUserConfigFolderA(const char *name)
T scale_ranges(T value, T srcmin, T srcmax, T destmin, T destmax)
DSL_API size_t DSL_CC strlcat(char *dst, const char *src, size_t siz)
DSL_API_CLASS const wchar_t *DSL_CC nopathW(const wchar_t *filename)
Returns just the file portion of the full path and filename.
DSL_API int DSL_CC wildicmp(const char *wild, const char *string)
DSL_API int DSL_CC wildcmp(const char *wild, const char *string)
DSL_API char *DSL_CC GetUserDocumentsFolderA(const char *name)
DSL_API int64 DSL_CC filesize(const char *fn)
Get the size in bytes of a file.
DSL_API int64 DSL_CC fseek64(FILE *fp, int64 offset, int whence)
Cross-platform 64-bit fseek.
DSL_API char *DSL_CC strtrim(char *buf, const char *trim="\r\n\t ", uint8 sides=TRIM_BOTH)
DSL_API_CLASS int DSL_CC str_replaceW(wchar_t *Str, size_t BufSize, const wchar_t *FindStr, const wchar_t *ReplStr)
Simple string replacement.
DSL_API int DSL_CC wildicmp_multi(const char *wild, const char *string, const char *sep="|")
DSL_API wchar_t *DSL_CC GetUserConfigFileW(const wchar_t *name, const wchar_t *fn)
Unicode version of...
DSL_API_CLASS char *DSL_CC escapeshellarg(const char *p, char *out, size_t outSize)
Escapes an argument for passing to shell functions, only escapes quotes atm so keep that in mind.
DSL_API_CLASS bool DSL_CC file_get_contents(const string &fn, vector< uint8 > &data, int64 maxSize=INT32_MAX)
DSL_API uint32 DSL_CC GetTickCount()
Linux version of GetTickCount.
DSL_API int64 DSL_CC dsl_clamp(int64 value, int64 vMin, int64 vMax)
Clamps a given value to the range of vMin to vMax (inclusive)