📄 ddutil.h
字号:
/* * This file was written by Bill Cox, originally in 1991, and maintained since. It is hereby * placed into the public domain. *//*================================================================================================== Module : Virtual Operating System Purpose: Hide system specific operations from other modules. This should help in portability.==================================================================================================*/#ifndef DD_UTIL_H#define DD_UTIL_H#if __cplusplusextern "C" {#endif#include <stdarg.h> /* For utVsprintf declaration */#include <setjmp.h> /* For utSetjmp */#include <stdio.h> /* Everyone uses it */#include <string.h> /* Has memset, used in generated macros *//*-------------------------------------------------------------------------------------------------- Datadraw defined Data types--------------------------------------------------------------------------------------------------*/#ifndef UTTYPES_H#include "uttypes.h"#endif/*-------------------------------------------------------------------------------------------------- Basic symbol table support. Note that user applications don't need to worry about which header gets included here, since they should only be reading from symbols.--------------------------------------------------------------------------------------------------*/#if defined(UT_USE_UTDATABASEUP_H)#include "utdatabaseup.h"#elif defined(UT_USE_UTDATABASEP_H)#include "utdatabasep.h"#elif defined(UT_USE_UTDATABASEU_H)#include "utdatabasep.h"#else#include "utdatabase.h"#endifutSym utSymCreate(char *name);utSym utSymCreateFormatted(char *format, ...);utSym utUniqueSymCreate(char *name, char *suffix);utSym utSymGetLowerSym(utSym sym);/*-------------------------------------------------------------------------------------------------- Basic memory management support.--------------------------------------------------------------------------------------------------*/#ifndef UTMEM_H#include "utmem.h"#endif#ifdef DMALLOC#include "dmalloc.h"#endif/*-------------------------------------------------------------------------------------------------- The max size of a string which the utFprintf, utExit, etc functions can print.--------------------------------------------------------------------------------------------------*/#define UTSTRLEN 4096extern uint32 utDebugVal;extern uint32 utVerboseVal;/*-------------------------------------------------------------------------------------------------- Initialization, cleaning up.--------------------------------------------------------------------------------------------------*/void utStop(bool reportTimeAndMemory);void utStart(void);extern bool _utInitialized;#define utInitialized() _utInitialized/*-------------------------------------------------------------------------------------------------- Functions you may want to call after initialization.--------------------------------------------------------------------------------------------------*/void utSetConfigDirectory(char *dirName);void utSetExeFullPath(char *fullName);void utSetVersion(char *version);char *utGetVersion(void);char *utGetExeDirectory(void);char *utGetConfigDirectory(void);char *utGetExeFullPath(void);/*-------------------------------------------------------------------------------------------------- Error Callback function to be provided by the user.--------------------------------------------------------------------------------------------------*/typedef void(*utErrorProc)(char *message);typedef bool(*utMessageYesNoProc)(char *message);typedef void(*utExitProc)(void);/*-------------------------------------------------------------------------------------------------- Basic interface to file system.--------------------------------------------------------------------------------------------------*/char *utGetcwd(void);bool utFileExists(char *fileName);bool utDirectoryExists(char *dirName);bool utAccess(char *name, char *mode);uint64 utFindFileSize(char *fileName);char *utExecPath(char *name);char *utFullPath(char *relativePath);char *utFindInPath(char *name, char *path);void utTruncateFile(char *fileName, uint64 length);/*-------------------------------------------------------------------------------------------------- Portable interface to launch an application.--------------------------------------------------------------------------------------------------*/bool utLaunchApp(char* cmdLine, char *wkgDir);/*-------------------------------------------------------------------------------------------------- Memory allocation. There are things called malloc, calloc and free, but they deal in the local heap, thus are to be avoided.--------------------------------------------------------------------------------------------------*/extern uint32 utUsedMem;#define utMalloc(sStruct, size) utMallocTrace(sStruct, size, __FILE__, __LINE__)#define utCalloc(sStruct, size) utCallocTrace(sStruct, size, \ __FILE__, __LINE__)#define utRealloc(mem, numBlocks, size) \ utReallocTrace((void *)mem, numBlocks, size, __FILE__, __LINE__)#define utResizeArray(array, num) \ ((array) = utRealloc((void *)(array), (num), sizeof(*(array))))#define utNew(type) (type *)utCalloc(1, sizeof(type))#define utNewA(type, num) (type *)utCalloc((num), sizeof(type))#define utFree(p) utFreeTrace(p, __FILE__, __LINE__)#define utAllocString(string) strcpy(utNewA(char, strlen(string) + 1), string)void * utReallocTrace(void *memPtr, size_t numBlocks, size_t size, char *fileName, uint32 line);void *utMallocTrace(size_t sStruct, size_t size, char *fileName, uint32 line);void *utCallocTrace(size_t sStruct, size_t size, char *fileName, uint32 line);void utFreeTrace(void *memPtr, char *fileName, uint32 line);/* maxmimum memory usage */extern uint32 utmByte;/*-------------------------------------------------------------------------------------------------- Random number support.--------------------------------------------------------------------------------------------------*/void utInitSeed(uint32 seed);uint32 utRand(void);#define utRandN(n) (utRand() % (n))#define utRandBool() ((bool) (utRand() & 1))/*-------------------------------------------------------------------------------------------------- String and temporary buffer manipulation.--------------------------------------------------------------------------------------------------*//* These use a queue of buffers */void *utMakeBuffer_(uint32 length);#define utNewBufA(type, num) (type *)utMakeBuffer_((num)*sizeof(type))#define utNewBuf(type) (type *)utMakeBuffer_(sizeof(type))#define utMakeString(length) (char *)utMakeBuffer_(length)char *utCopyString(char *string);char *utCatStrings(char *string1, char *string2);char *utStringToUpperCase(char *string);char *utStringToLowerCase(char *string);char *utSprintf(char *format, ...);char *utReplaceSuffix(char *originalName, char *newSuffix);char *utSuffix(char *name);char *utBaseName(char *name);char *utDirName(char *name);char *utExpandEnvVariables(char *string);char *utVsprintf(char *format, va_list ap);void utSetEnvironmentVariable(char *name, char *value);char *utGetEnvironmentVariable(char *name);char *utFindHexString(uint8 *values, uint32 size);char *utMemoryUnits(uint64 memory);/*-------------------------------------------------------------------------------------------------- Message loging, error reporting.--------------------------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -