76 #ifndef _PLATFORM_HELPER_H_INCLUDED_ 77 #define _PLATFORM_HELPER_H_INCLUDED_ 86 #include <X11/Xutil.h> 88 #include <X11/Xatom.h> 98 #if defined(__GNUC__) || defined(__DOXYGEN__) 106 #ifdef X11WORKBENCH_PROJECT_BUILD 109 #include "X11workbenchToolkit_config.h" 111 #else // X11WORKBENCH_PROJECT_BUILD 115 #include "X11workbenchToolkit_install_config.h" 117 #endif // X11WORKBENCH_PROJECT_BUILD 124 #if !defined( HAVE_ALARM ) || !defined( HAVE_CHOWN ) || \ 125 !defined( HAVE_CLOCK_GETTIME ) || !defined( HAVE_DUP2 ) || !defined( HAVE_FORK ) || \ 126 !defined( HAVE_FTRUNCATE ) || !defined( HAVE_GETCWD ) || !defined( HAVE_GETTIMEOFDAY ) || \ 127 !defined( HAVE_MALLOC ) || !defined( HAVE_MBLEN ) || !defined( HAVE_MEMCHR ) || \ 128 !defined( HAVE_MEMMOVE ) || !defined( HAVE_MEMSET ) || !defined( HAVE_MKDIR ) || \ 129 !defined( HAVE_PRINTF ) || !defined( HAVE_REALLOC ) || \ 130 !defined( HAVE_SELECT ) || !defined( HAVE_SETLOCALE ) || !defined( HAVE_STRCASECMP ) || \ 131 !defined( HAVE_STRCHR ) || !defined( HAVE_STRNCASECMP ) || !defined( HAVE_STRRCHR ) || \ 132 !defined( HAVE_STRSTR ) || !defined( HAVE__BOOL ) || \ 133 ( !defined(_MSC_VER) && ( !defined( LSTAT_FOLLOWS_SLASHED_SYMLINK ) || !defined( HAVE_VFORK ) || \ 134 !defined( HAVE_WORKING_FORK ) || !defined( HAVE_WORKING_VFORK ) )) 137 #error configure script feature check 1 fail 138 #error critical features missing 142 #error HAVE_ALARM is not defined 145 #error HAVE_CHOWN is not defined 147 #ifndef HAVE_CLOCK_GETTIME 148 #error HAVE_CLOCK_GETTIME is not defined 149 #endif // HAVE_CLOCK_GETTIME 151 #error HAVE_DUP2 is not defined 154 #error HAVE_FORK is not defined 156 #ifndef HAVE_FTRUNCATE 157 #error HAVE_FTRUNCATE is not defined 158 #endif // HAVE_FTRUNCATE 160 #error HAVE_GETCWD is not defined 161 #endif // HAVE_GETCWD 162 #ifndef HAVE_GETTIMEOFDAY 163 #error HAVE_GETTIMEOFDAY is not defined 164 #endif // HAVE_GETTIMEOFDAY 166 #error HAVE_MALLOC is not defined 167 #endif // HAVE_MALLOC 169 #error HAVE_MBLEN is not defined 172 #error HAVE_MEMCHR is not defined 173 #endif // HAVE_MEMCHR 175 #error HAVE_MEMMOVE is not defined 176 #endif // HAVE_MEMMOVE 178 #error HAVE_MEMSET is not defined 179 #endif // HAVE_MEMSET 181 #error HAVE_MKDIR is not defined 184 #error HAVE_PRINTF is not defined 185 #endif // HAVE_PRINTF 187 #error HAVE_REALLOC is not defined 188 #endif // HAVE_REALLOC 190 #error HAVE_SELECT is not defined 191 #endif // HAVE_SELECT 192 #ifndef HAVE_SETLOCALE 193 #error HAVE_SETLOCALE is not defined 194 #endif // HAVE_SETLOCALE 195 #ifndef HAVE_STRCASECMP 196 #error HAVE_STRCASECMP is not defined 197 #endif // HAVE_STRCASECMP 199 #error HAVE_STRCHR is not defined 200 #endif // HAVE_STRCHR 201 #ifndef HAVE_STRNCASECMP 202 #error HAVE_STRNCASECMP is not defined 203 #endif // HAVE_STRNCASECMP 205 #error HAVE_STRRCHR is not defined 206 #endif // HAVE_STRRCHR 208 #error HAVE_STRSTR is not defined 209 #endif // HAVE_STRSTR 211 #error HAVE__BOOL is not defined 213 #ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK 214 #error LSTAT_FOLLOWS_SLASHED_SYMLINK is not defined 215 #endif // LSTAT_FOLLOWS_SLASHED_SYMLINK 217 #error HAVE_VFORK is not defined 219 #ifndef HAVE_WORKING_FORK 220 #error HAVE_WORKING_FORK is not defined 221 #endif // HAVE_WORKING_FORK 222 #ifndef HAVE_WORKING_VFORK 223 #error HAVE_WORKING_VFORK is not defined 224 #endif // HAVE_WORKING_VFORK 230 #if !( HAVE_ALARM ) || !( HAVE_CHOWN ) || \ 231 !( HAVE_CLOCK_GETTIME ) || !( HAVE_DUP2 ) || !( HAVE_FORK ) || \ 232 !( HAVE_FTRUNCATE ) || !( HAVE_GETCWD ) || !( HAVE_GETTIMEOFDAY ) || \ 233 !( HAVE_MALLOC ) || !( HAVE_MBLEN ) || !( HAVE_MEMCHR ) || \ 234 !( HAVE_MEMMOVE ) || !( HAVE_MEMSET ) || !( HAVE_MKDIR ) || \ 235 !( HAVE_PRINTF ) || !( HAVE_REALLOC ) || \ 236 !( HAVE_SELECT ) || !( HAVE_SETLOCALE ) || !( HAVE_STRCASECMP ) || \ 237 !( HAVE_STRCHR ) || !( HAVE_STRNCASECMP ) || !( HAVE_STRRCHR ) || \ 238 !( HAVE_STRSTR ) || !( HAVE__BOOL ) || \ 239 ( !defined(_MSC_VER) && ( !( LSTAT_FOLLOWS_SLASHED_SYMLINK ) || !( HAVE_VFORK ) || \ 240 !( HAVE_WORKING_FORK ) || !( HAVE_WORKING_VFORK ) )) 242 #error configure script feature check 2 fail 243 #error critical features missing 251 #endif // all that stuff defined as a zero 253 #endif // all that prior stuff 257 #endif // !HAVE_BZERO 261 #define bzero(X,Y) memset((X),0,(Y)) 269 #undef NO_DEBUG // only one may be defined 293 #define INVALID_HANDLE_VALUE ((int)-1) 308 #define WB_STRINGIZE(X) WB_STRINGIZE_INTERNAL(X) 314 #define WB_STRINGIZE_INTERNAL(X) #X 321 #if defined(COMPILER_SUPPORTS_BUILTIN_EXPECT) || defined(__DOXYGEN__) 332 #define WB_UNLIKELY(x) (__builtin_expect (!!(x), 0)) 342 #define WB_LIKELY(x) (__builtin_expect (!!(x), 1)) 344 #else // !COMPILER_SUPPORTS_BUILTIN_EXPECT 346 #define WB_UNLIKELY(x) (x) 347 #define WB_LIKELY(x) (x) 349 #endif // COMPILER_SUPPORTS_BUILTIN_EXPECT 351 #if defined(COMPILER_SUPPORTS_UNUSED_ATTRIBUTE) || defined(__DOXYGEN__) 364 #define WB_UNUSED __attribute__((unused)) 366 #else // !COMPILER_SUPPORTS_UNUSED_ATTRIBUTE 370 #endif // COMPILER_SUPPORTS_UNUSED_ATTRIBUTE 391 #define WB_INTERNAL_ATOM_MIN_VAL 0x3f000000L 402 typedef int WB_INT32; 412 #if defined(HAVE_LONGLONG) || defined(__DOXYGEN__) 417 #define HAS_WB_UINT64_BUILTIN 434 #else // !defined HAVE_LONGLONG, unlikely (this part won't show up in doxygen either) 450 #if !defined(__SIZEOF_POINTER__) // TODO find a better way to deal with pointer size if this isn't defined 451 #define __SIZEOF_POINTER__ 0 454 #if defined(__LP64__) 456 #elif __SIZEOF_POINTER__ == 4 458 #else // assume long pointer 461 #endif // __DOXYGEN__ 467 #define WB_C99_INITIALIZERS 523 #else // !__DOXYGEN__ 525 #define __PACKED__ __attribute__((__packed__)) 527 #endif // __DOXYGEN__ 532 #elif defined(_MSC_VER) 544 #endif // _MSC_VER > xxxx 546 #define WB_UNLIKELY(x) (x) 547 #define WB_LIKELY(x) (x) 550 #define __inline__ inline 563 typedef DWORD WBTHREAD_KEY;
577 #else // !defined(_MSVC_VER) && !defined(__GNUC__) 579 #error unknown and/or unsupported compiler 590 #define WB_SECURE_HASH_TIMEOUT 60000 600 typedef char * WB_PSTR; 601 typedef const char * WB_PCSTR; 639 void __internal_startup_display(
const char *szVal);
640 void __internal_startup_minimize(
void);
641 void __internal_startup_maximize(
void);
642 void __internal_startup_geometry(
const char *szVal);
645 void __internal_disable_antialias(
void);
646 void __internal_disable_imagecache(
void);
697 #if defined(DOXYGEN) || !defined(_MSC_VER) 698 int WBMain(
int argc,
char *argv[],
char *envp[]);
700 int __declspec(selectany)
WBMain(
int argc,
char *argv[],
char *envp[]);
716 #if defined(DOXYGEN) || !defined(_MSC_VER) 719 void __declspec(selectany)
WBUsage(
void);
803 #if defined(HAS_WB_UINT64_BUILTIN) || defined(__DOXYGEN__) 805 #else // !defined(HAS_WB_UINT64_BUILTIN) && !defined(__DOXYGEN__) 807 #endif // defined(HAS_WB_UINT64_BUILTIN) || defined(__DOXYGEN__) 824 void WBDelay(uint32_t uiDelay);
906 void *
WBReAlloc(
void *pBuf,
int nNewSize);
952 char *
WBCopyStringN(
const char *pSrc,
unsigned int nMaxChars);
988 void WBCatStringN(
char **ppDest,
const char *pSrc,
unsigned int nMaxChars);
1073 int WBIsMultiByte(
const char *pszStr);
1087 XChar2b * WBConvertMultiByteTo16(
const char *pszStr);
1099 char *WBConvertMultiByteFrom16(
const XChar2b *pwzStr);
1117 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XPM) && !defined(__DOXYGEN__) 1121 #include <X11/xpm.h> 1125 #define XPM_ATTRIBUTES XpmAttributes 1126 #define XPM_CREATE_PIXMAP_FROM_DATA(A,B,C,D,E,F) XpmCreatePixmapFromData(A,B,C,D,E,F) 1127 #define XPM_FREE_ATTRIBUTES(pAttr) XpmFreeAttributes(pAttr) 1129 #else // !X11WORKBENCH_TOOLKIT_HAVE_XPM or __DOXYGEN__ 1233 #define XPM_CREATE_PIXMAP_FROM_DATA(A,B,C,D,E,F) MyLoadPixmapFromData(A,B,C,D,E,F) 1246 #define XPM_FREE_ATTRIBUTES(pAttr) 1263 #define NEXT_WORD(pX, pY, pZ) {while(*(pX) && *(pX) <= ' '){(pX)++;} (pY)=(pZ)=(pX); while(*(pX)>' '){(pX)++;} (pZ)=(pX);} 1271 #endif // __cplusplus 1286 #if defined(QSORT_R_BSD) && !defined(__DOXYGEN__) 1290 #define DECLARE_SORT_FUNCTION(fn_name,p0,p1,p2) int fn_name(void *p0, const void *p1, const void *p2) 1292 #define QSORT_R(A,B,C,D,E) qsort_r((A),(B),(C),(D),(E)) 1294 #elif defined(QSORT_R_GNUC) && !defined(__DOXYGEN__) 1298 #define DECLARE_SORT_FUNCTION(fn_name,p0,p1,p2) int fn_name(const void *p1, const void *p2, void *p0) 1300 #define QSORT_R(A,B,C,D,E) qsort_r((A),(B),(C),(E),(D)) 1319 void my_qsort_r(
void *base,
int nmemb,
int size,
void *thunk,
1320 int (*compar)(
void *,
const void *,
const void *));
1356 #define DECLARE_SORT_FUNCTION(fn_name,p0,p1,p2) int fn_name(void *p0, const void *p1, const void *p2) 1372 #define QSORT_R(base,nmemb,size,thunk,compar) my_qsort_r((base),(nmemb),(size),(thunk),(compar)) 1522 Atom
WBGetAtom(Display *pDisplay,
const char *szAtomName);
1551 Atom
WBLookupAtom(Display *pDisplay,
const char *szAtomName);
1604 int WBMkDir(
const char *szFileName,
int flags);
1684 #define WB_FILE_HANDLE HANDLE 1685 #define WB_PROCESS_ID HANDLE 1686 #define WB_INVALID_FILE_HANDLE INVALID_HANDLE_VALUE 1688 #define WB_FILE_HANDLE int 1689 #define WB_PROCESS_ID unsigned int 1690 #define WB_INVALID_FILE_HANDLE -1 1706 WB_PROCESS_ID
WBRunAsync(
const char *szAppName, ...);
1804 WB_PROCESS_ID
WBRunAsyncPipe(WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr,
1805 const char *szAppName, ...);
1837 WB_PROCESS_ID
WBRunAsyncPipeV(WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr,
1838 const char *szAppName, va_list va);
2328 #endif // __cplusplus 2331 #endif // _PLATFORM_HELPER_H_INCLDUED_
const char * GetStartupAppName(void)
returns a pointer to a copy of the application name from argv[0]
void WBPlatformOnExit(void)
Resource 'free-up' on exit (must call)
WB_THREAD_KEY WBThreadAllocLocal(void)
Allocate 'thread local' storage.
int bQuitFlag
'Quit' Flag - you should check this periodically in your main (message) loop and exit whenever it is ...
void WBThreadFreeLocal(WB_THREAD_KEY keyVal)
Free 'thread local' storage allocated by WBThreadAllocLocal()
int WBMutexUnlock(WB_MUTEX *pMtx)
Unlock a previously locked mutex.
void * WBThreadGetLocal(WB_THREAD_KEY keyVal)
Get 'thread local' data identified by 'keyVal'.
void WBCatStringN(char **ppDest, const char *pSrc, unsigned int nMaxChars)
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string up t...
int WBStringLineCount(const char *pSrc, unsigned int nMaxChars)
Determine how many 'lines' are in a block of text by counting 'linefeed' characters.
char * WBRunResult(const char *szAppName,...)
Run an application synchronously, returning 'stdout' output in a character buffer.
void WBSubAllocTrashMasher(void)
High performance memory sub-allocator 'trash masher' - call periodically to minimize wasted memory.
int MyLoadPixmapFromData(Display *pDisplay, Window wID, char *aData[], Pixmap *pPixmap, Pixmap *pMask, XPM_ATTRIBUTES *pAttr)
Alternate for XpmCreatePixmapFromData() whenever libXpm is not being used.
void WBFreeLibrary(WB_MODULE hModule)
Frees a shared library, DLL, module, or whatever, that was loaded via 'WBLoadLibrary()'.
WB_MODULE WBLoadLibrary(const char *szModuleName)
Loads a shared library, DLL, module, or whatever you call it on your operating system.
char * WBRunResultWithInput(const char *szStdInBuf, const char *szAppName,...)
Run an application synchronously, supplying an input buffer for 'stdin', and returning 'stdout' outpu...
void * WBThreadWait(WB_THREAD hThread)
Wait for a specified threat to exit.
void WBThreadExit(void *pRval)
Exit the current thread immediately, specifying return code.
WB_UINT32 WBInterlockedIncrement(volatile WB_UINT32 *pValue)
Interlocked 'atomic' increment of an unsigned integer.
Compatibility structure for use with MyLoadPixmapFromData() whenever libXpm is not in use.
int WBMain(int argc, char *argv[], char *envp[])
Startup function, equivalent to 'main()' - provided for convenience.
WB_PROCESS_ID WBRunAsyncPipe(WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr, const char *szAppName,...)
Run an application asynchronously, specifying file handles for STDIN, STDOUT, and STDERR.
WB_UINT32 WBInterlockedExchange(volatile WB_UINT32 *pValue, WB_UINT32 nNewVal)
Interlocked 'atomic' exchange of an unsigned integer with a specified value.
int width
The width of the returned pixmaps.
void * WBReAlloc(void *pBuf, int nNewSize)
High performance memory sub-allocator 're-allocate'.
int WBGetProcessState(WB_PROCESS_ID idProcess, WB_INT32 *pExitCode)
Check on a running process, and return its state, and optionally the exit code.
WB_THREAD WBThreadCreate(void *(*function)(void *), void *pParam)
Create a new thread, returning its WB_THREAD identifier.
void WBDeQuoteString(char *pszStr)
De-Quote a string 'in place', that is modifying the original string by removing quotes.
void WBToolkitUsage(void)
Displays 'usage' for toolkit options to stderr.
void WBThreadSetLocal(WB_THREAD_KEY keyVal, void *pValue)
Get 'thread local' data identified by 'keyVal'.
void * WBAlloc(int nSize)
High performance memory sub-allocator 'allocate'.
int WBCondSignal(WB_COND *pCond)
Signal a condition (event)
void * WBGetDataAddress(WB_MODULE hModule, const char *szDataName)
Obtains a data pointer for an exported data symbol in a shared library (or DLL)
WB_PROCESS_ID WBRunAsync(const char *szAppName,...)
Run an application asynchronously.
char * WBGetPrinterList(void)
Get a list of printer names.
WB_THREAD WBThreadGetCurrent(void)
Get 'current thread' identifier.
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
int WBParseStandardArguments(int *pargc, char ***pargv, char ***penvp)
parses standard C arguments as passed to 'main()'
void WBPlatformOnInit(void)
Resource initialization on startup.
WB_UINT32 WBInterlockedDecrement(volatile WB_UINT32 *pValue)
Interlocked 'atomic' decrement of an unsigned integer.
int WBAllocUsableSize(void *pBuf)
High performance memory sub-allocator, similar to 'malloc_usable_size'.
void WBUsage(void)
Optional startup function, sends 'usage' (help) info to stderr - application-defined function.
WB_PROCADDRESS WBGetProcAddress(WB_MODULE hModule, const char *szProcName)
Obtains a function pointer for an exported function symbol in a shared library (or DLL)
int WBMutexCreate(WB_MUTEX *pMtx)
Create a lockable mutex.
int WBMutexLock(WB_MUTEX *pMtx, int nTimeout)
Wait for and lock a mutex, blocking until it is available.
int WBThreadRunning(WB_THREAD hThread)
Determine whether a thread is running (can be suspended)
const char * WBStringNextLine(const char *pSrc, unsigned int *pnMaxChars)
Locate the next line in a block of text, returning its pointer (and updating remaining length)
struct tagXPM_ATTRIBUTES XPM_ATTRIBUTES
Compatibility structure for use with MyLoadPixmapFromData() whenever libXpm is not in use.
WB_PROCESS_ID WBRunAsyncPipeV(WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr, const char *szAppName, va_list va)
Run an application asynchronously, specifying file handles for STDIN, STDOUT, and STDERR,...
char * WBCopyStringN(const char *pSrc, unsigned int nMaxChars)
A simple utility that returns a WBAlloc() copy of a string up to a maximum length (can also be 0-byte...
int depth
depth of the returned 'image' pixmap. The mask pixmap always has a depth of '1'.
int WBCondWait(WB_COND *pCond, int nTimeout)
Wait for a signal on a condition (event)
void WBMutexFree(WB_MUTEX *pMtx)
Free a lockable mutex.
char * WBCopyString(const char *pSrc)
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string.
int WBCondWaitMutex(WB_COND *pCond, WB_MUTEX *pMtx, int nTimeout)
Wait for a signal on a condition (event)
void WBThreadClose(WB_THREAD hThread)
Close the specified WB_THREAD identifier.
WB_UINT32 WBInterlockedRead(volatile WB_UINT32 *pValue)
Interlocked 'atomic' read of an unsigned integer.
int height
height of the returned pixmaps
int WBPrintPostScriptFile(const char *szPrinterName, const char *szFileName)
Send postscript file to a printer (using lpr-cups or lpr on POSIX systems)
int WBCondCreate(WB_COND *pCond)
Create a signallable condition.
void WBNormalizeXMLString(char *pString)
De-Quote and 'normalize' an XML string 'in place', that is modifying the original string by removing ...
void WBCatString(char **ppDest, const char *pSrc)
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string.
void WBCondFree(WB_COND *pCond)
Free a signallable condition.