2019-10-21 19:36:05 +00:00
|
|
|
// cmdlib.h
|
|
|
|
|
|
|
|
#ifndef __CMDLIB__
|
|
|
|
#define __CMDLIB__
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
2020-04-11 21:39:40 +00:00
|
|
|
#include <time.h>
|
2019-10-21 19:36:05 +00:00
|
|
|
#include "zstring.h"
|
2023-08-23 18:36:19 +00:00
|
|
|
#include "files.h"
|
2019-10-21 19:36:05 +00:00
|
|
|
|
2020-01-06 01:41:47 +00:00
|
|
|
#if !defined(GUID_DEFINED)
|
|
|
|
#define GUID_DEFINED
|
|
|
|
typedef struct _GUID
|
|
|
|
{
|
|
|
|
uint32_t Data1;
|
|
|
|
uint16_t Data2;
|
|
|
|
uint16_t Data3;
|
|
|
|
uint8_t Data4[8];
|
|
|
|
} GUID;
|
|
|
|
#endif
|
|
|
|
|
2019-10-21 19:36:05 +00:00
|
|
|
template <typename T, size_t N>
|
|
|
|
char(&_ArraySizeHelper(T(&array)[N]))[N];
|
|
|
|
|
|
|
|
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
|
|
|
|
|
|
|
|
// the dec offsetof macro doesnt work very well...
|
|
|
|
#define myoffsetof(type,identifier) ((size_t)&((type *)alignof(type))->identifier - alignof(type))
|
|
|
|
|
|
|
|
bool FileExists (const char *filename);
|
2023-10-07 16:44:31 +00:00
|
|
|
inline bool FileExists(const FString& filename)
|
|
|
|
{
|
|
|
|
return FileExists(filename.GetChars());
|
|
|
|
}
|
2021-02-12 13:44:54 +00:00
|
|
|
bool FileReadable (const char *filename);
|
2019-10-21 19:36:05 +00:00
|
|
|
bool DirExists(const char *filename);
|
|
|
|
bool DirEntryExists (const char *pathname, bool *isdir = nullptr);
|
2020-01-03 16:08:41 +00:00
|
|
|
bool GetFileInfo(const char* pathname, size_t* size, time_t* time);
|
2019-10-21 19:36:05 +00:00
|
|
|
|
|
|
|
extern FString progdir;
|
|
|
|
|
2020-04-11 21:39:40 +00:00
|
|
|
void FixPathSeperator (char *path);
|
2019-12-22 19:55:47 +00:00
|
|
|
static void inline FixPathSeperator (FString &path) { path.ReplaceChars('\\', '/'); }
|
|
|
|
|
2023-10-01 11:09:22 +00:00
|
|
|
void DefaultExtension (FString &path, const char *extension, bool forcebackslash = false);
|
2019-12-11 00:11:35 +00:00
|
|
|
void NormalizeFileName(FString &str);
|
2019-10-21 19:36:05 +00:00
|
|
|
|
2023-10-01 11:09:22 +00:00
|
|
|
FString ExtractFilePath (const char *path, bool forcebackslash = false);
|
|
|
|
FString ExtractFileBase (const char *path, bool keep_extension=false, bool forcebackslash = false);
|
2020-01-27 20:39:15 +00:00
|
|
|
FString StripExtension(const char* path);
|
2023-10-01 11:09:22 +00:00
|
|
|
void SplitPath(const char* path, FString& directory, FString& base, FString& ext, bool forcebackslash = false);
|
2019-10-21 19:36:05 +00:00
|
|
|
|
|
|
|
struct FScriptPosition;
|
|
|
|
bool IsNum (const char *str); // [RH] added
|
|
|
|
|
2020-04-11 21:39:40 +00:00
|
|
|
char *copystring(const char *s);
|
|
|
|
|
2019-10-21 19:36:05 +00:00
|
|
|
bool CheckWildcards (const char *pattern, const char *text);
|
|
|
|
|
2019-12-22 19:55:47 +00:00
|
|
|
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid);
|
|
|
|
|
|
|
|
const char *myasctime ();
|
|
|
|
|
2019-10-21 19:36:05 +00:00
|
|
|
int strbin (char *str);
|
|
|
|
FString strbin1 (const char *start);
|
|
|
|
|
|
|
|
void CreatePath(const char * fn);
|
|
|
|
|
|
|
|
FString ExpandEnvVars(const char *searchpathstring);
|
|
|
|
FString NicePath(const char *path);
|
|
|
|
|
|
|
|
bool IsAbsPath(const char*);
|
2020-04-11 21:39:40 +00:00
|
|
|
FString M_ZLibError(int zerrnum);
|
2019-10-21 19:36:05 +00:00
|
|
|
|
2022-09-18 09:21:12 +00:00
|
|
|
inline constexpr int32_t Scale(int32_t a, int32_t b, int32_t c)
|
2020-02-09 12:26:51 +00:00
|
|
|
{
|
|
|
|
return (int32_t)(((int64_t)a * b) / c);
|
|
|
|
}
|
2019-10-21 19:36:05 +00:00
|
|
|
|
2022-09-18 09:21:12 +00:00
|
|
|
inline constexpr double Scale(double a, double b, double c)
|
|
|
|
{
|
|
|
|
return (a * b) / c;
|
|
|
|
}
|
|
|
|
|
2020-04-11 21:54:33 +00:00
|
|
|
struct MD5Context;
|
|
|
|
|
|
|
|
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
|
|
|
|
void uppercopy(char* to, const char* from);
|
2023-09-23 07:56:27 +00:00
|
|
|
FString GetStringFromLump(int lump, bool zerotruncate = true);
|
2020-04-11 21:54:33 +00:00
|
|
|
|
2020-11-23 14:54:06 +00:00
|
|
|
inline void fillshort(void* buff, size_t count, uint16_t clear)
|
|
|
|
{
|
|
|
|
int16_t* b2 = (int16_t*)buff;
|
|
|
|
for (size_t i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
b2[i] = clear;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 06:31:17 +00:00
|
|
|
template<typename T> inline constexpr int Sgn(const T& val) { return (val > 0) - (val < 0); }
|
|
|
|
|
|
|
|
|
2021-03-15 22:46:03 +00:00
|
|
|
inline int sizeToBits(int w)
|
|
|
|
{
|
|
|
|
int j = 15;
|
|
|
|
|
|
|
|
while ((j > 1) && ((1 << j) > w))
|
|
|
|
j--;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-21 19:36:05 +00:00
|
|
|
#endif
|