📄 common.h
字号:
* \sa key_msgs */#define KS_SCROLLLOCK 0x00000040/** * \def KS_LEFTCTRL * \brief This status indicate that the left-Ctrl key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_LEFTCTRL 0x00000020/** * \def KS_RIGHTCTRL * \brief This status indicate that the right-Ctrl key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_RIGHTCTRL 0x00000010/** * \def KS_CTRL * \brief This status indicate that either the left-Ctrl key or the right-Ctrl key * was pressed when the key or mouse message posted to the window. * * \sa key_msgs */#define KS_CTRL 0x00000030/** * \def KS_LEFTALT * \brief This status indicate that left-Alt key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_LEFTALT 0x00000008/** * \def KS_RIGHTALT * \brief This status indicate that right-Alt key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_RIGHTALT 0x00000004/** * \def KS_ALT * \brief This status indicate that either the left-Alt key or the right-Alt key * was pressed when the key or mouse message posted to the window. * * \sa key_msgs */#define KS_ALT 0x0000000C/** * \def KS_LEFTSHIFT * \brief This status indicate that left-Shift key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_LEFTSHIFT 0x00000002/** * \def KS_RIGHTSHIFT * \brief This status indicate that right-Shift key was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_RIGHTSHIFT 0x00000001/** * \def KS_SHIFT * \brief This status indicate that either the left-Shift key or the right-Shift key * was pressed when the key or mouse message posted to the window. * * \sa key_msgs */#define KS_SHIFT 0x00000003/** * \def MASK_KS_SHIFTKEYS * \brief The mask of key status. */#define MASK_KS_SHIFTKEYS 0x00000FFF/** * \def KS_LEFTBUTTON * \brief This status indicate that left button was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_LEFTBUTTON 0x00001000/** * \def KS_RIGHTBUTTON * \brief This status indicate that right button was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_RIGHTBUTTON 0x00002000/** * \def KS_MIDDLBUTTON * \brief This status indicate that middle button was pressed when * the key or mouse message posted to the window. * * \sa key_msgs */#define KS_MIDDLBUTTON 0x00004000/** * \def MASK_KS_BUTTONS * \brief The mask of mouse button status. */#define MASK_KS_BUTTONS 0x0000F000 /** @} end of key_defs */ /** * \defgroup err_codes Error codes * @{ */#define ERR_OK 0#define ERR_INV_HWND -1#define ERR_QUEUE_FULL -2#define ERR_INVALID_HANDLE -3#define ERR_INVALID_HMENU -4#define ERR_INVALID_POS -5#define ERR_INVALID_ID -6#define ERR_RES_ALLOCATION -7#define ERR_CTRLCLASS_INVNAME -8#define ERR_CTRLCLASS_INVLEN -9#define ERR_CTRLCLASS_MEM -10#define ERR_CTRLCLASS_INUSE -11#define ERR_ALREADY_EXIST -12#define ERR_NO_MATCH -13#define ERR_BAD_OWNER -14#define ERR_IME_TOOMUCHIMEWND -15#define ERR_IME_NOSUCHIMEWND -16#define ERR_IME_NOIMEWND -17#define ERR_CONFIG_FILE -18#define ERR_FILE_IO -19#define ERR_GFX_ENGINE -20#define ERR_INPUT_ENGINE -21#define ERR_NO_ENGINE -22#ifdef __CC_ARM# define ENOMEM 200# define EINVAL 201# define EBUSY 202# define EAGAIN 203# define ESRCH 204# define EDEADLK 205# define ENOTSUP 206# define ENOSYS 207#endif /** @} end of err_codes */ /** * \defgroup misc_macros Miscellaneous macros * @{ *//** * \def TABLESIZE(table) * \brief A macro returns the number of elements in a \a table. */#define TABLESIZE(table) (sizeof(table)/sizeof(table[0]))/* MAX/MIN/ABS macors *//** * \def MAX(x, y) * \brief A macro returns the maximum of \a x and \a y. */#ifndef MAX#define MAX(x, y) ((x > y)?x:y)#endif/** * \def MIN(x, y) * \brief A macro returns the minimum of \a x and \a y. */#ifndef MIN#define MIN(x, y) ((x < y)?x:y)#endif/** * \def ABS(x) * \brief A macro returns the absolute value of \a x. */#ifndef ABS#define ABS(x) (((x)<0) ? -(x) : (x))#endif/* Commonly used definitions */#ifndef __NOUNIX__#include <dirent.h>#endif#ifndef PATH_MAX #define PATH_MAX 256#endif#ifndef NAME_MAX #define NAME_MAX 64#endif/** * \def MAX_PATH * \brief The possible maximal length of a path name. * \note This definition is an alias of PATH_MAX */#define MAX_PATH PATH_MAX/** * \def MAX_NAME * \brief The possible maximal length of a file name. * \note This definition is an alias of NAME_MAX */#define MAX_NAME NAME_MAX /** @} end of misc_macros */ /** @} end of macros_types */#ifdef __cplusplusextern "C" {#endif#ifdef __UCOSII__/* use our own implementation of strdup */#undef HAVE_STRDUP#define strdup own_strdup/* The entry of MiniGUI */int minigui_entry (int argc, const char* argv[]);int ucos2_posix_pthread_init (void);int ucos2_malloc_init (void);#endif#ifndef HAVE_STRDUPMG_EXPORT char *strdup(const char *s);#endif#ifndef HAVE_STRCASECMPMG_EXPORT int strcasecmp(const char *s1, const char *s2);#endif#ifdef __cplusplus}; /* end of extern "C" */#endif#ifdef _USE_OWN_MALLOC#define USE_DL_PREFIX#include "own_malloc.h"/* wrappers for malloc functions */#define calloc dlcalloc#define free dlfree#define malloc dlmalloc#define memalign dlmemalign#define realloc dlrealloc#define valloc dlvalloc#endif/* Do not use the alloca of ARMCC */#if defined(__CC_ARM)# undef HAVE_ALLOCA# undef HAVE_ALLOCA_H#endif#ifdef HAVE_ALLOCA_H# include <alloca.h># define ALLOCATE_LOCAL(size) alloca((int)(size))# define DEALLOCATE_LOCAL(ptr) /* as nothing */#else# define ALLOCATE_LOCAL(size) malloc((int)(size))# define DEALLOCATE_LOCAL(ptr) free(ptr)#endif#ifdef _USE_OWN_STDIO#if defined (__UCOSII__) || defined (__VXWORKS__) || defined(WIN32)# undef _PRINTF_FLOATING_POINT# undef _SCANF_FLOATING_POINT#else# ifdef HAVE_MATH_H# define _PRINTF_FLOATING_POINT 1# define _SCANF_FLOATING_POINT 1# endif#endif#undef _I18N_MB_REQUIRED#if defined(__VXWORKS__) || defined(WIN32) #define _USE_OWN_SNPRINTF #define _USE_OWN_VSNPRINTF #define _USE_OWN_VFNPRINTF#else #define _USE_OWN_PRINTF #define _USE_OWN_FPRINTF #define _USE_OWN_SPRINTF #define _USE_FNPRINTF #define _USE_OWN_SNPRINTF #define _USE_OWN_VPRINTF #define _USE_OWN_VFPRINTF #define _USE_OWN_VSPRINTF #define _USE_OWN_VFNPRINTF #define _USE_OWN_VSNPRINTF #define _USE_OWN_SCANF #define _USE_OWN_FSCANF #define _USE_OWN_SSCANF #define _USE_OWN_VSCANF #define _USE_OWN_VFSCANF #define _USE_OWN_VSSCANF#endif#include "own_stdio.h"/* wrappers for stdio functions */#ifdef _USE_OWN_PRINTF #define printf own_printf#endif#ifdef _USE_OWN_FPRINTF #define fprintf own_fprintf#endif#ifdef _USE_OWN_SPRINTF #define sprintf own_sprintf#endif#ifdef _USE_FNPRINTF #define fnprintf own_fnprintf#endif#ifdef _USE_OWN_SNPRINTF #define snprintf own_snprintf#endif#ifdef _USE_OWN_VPRINTF #define vprintf own_vprintf#endif#ifdef _USE_OWN_VFPRINTF #define vfprintf own_vfprintf#endif#ifdef _USE_OWN_VSPRINTF #define vsprintf own_vsprintf#endif#ifdef _USE_OWN_VFNPRINTF #define vfnprintf own_vfnprintf#endif#ifdef _USE_OWN_VSNPRINTF #define vsnprintf own_vsnprintf#endif#ifdef _USE_OWN_SCANF #define scanf own_scanf#endif#ifdef _USE_OWN_FSCANF #define fscanf own_fscanf#endif#ifdef _USE_OWN_SSCANF #define sscanf own_sscanf#endif#ifdef _USE_OWN_VSCANF #define vscanf own_vscanf#endif#ifdef _USE_OWN_VFSCANF #define vfscanf own_vfscanf#endif#ifdef _USE_OWN_VSSCANF #define vsscanf own_vsscanf#endif#endif /* _USE_OWN_STDIO */#if defined(__GNUC__)#ifdef _DEBUG_MSG# define _MG_PRINTF(fmt...) fprintf (stderr, fmt)#else# define _MG_PRINTF(fmt...)#endif#else /* __GNUC__ */static inline void _MG_PRINTF(const char* fmt, ...){#ifdef _DEBUG_MSG va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap);#endif}#endif /* __GNUC__ */#ifndef _LITE_VERSION #include <pthread.h> #include <semaphore.h>#endif#ifdef __DARWIN__#define _USE_SEM_ON_SYSVIPC 1#endif#if defined (_USE_MUTEX_ON_SYSVIPC) || defined (_USE_SEM_ON_SYSVIPC)int _sysvipc_mutex_sem_init (void);int _sysvipc_mutex_sem_term (void);#endif#ifdef _USE_MUTEX_ON_SYSVIPC#define pthread_mutex_t _sysvipc_pthread_mutex_t#define pthread_mutexattr_t _sysvipc_pthread_mutexattr_t#define pthread_mutexattr_init _sysvipc_pthread_mutexattr_init #define pthread_mutexattr_destroy _sysvipc_pthread_mutexattr_destroy #define pthread_mutexattr_settype _sysvipc_pthread_mutexattr_settype #define pthread_mutexattr_gettype _sysvipc_pthread_mutexattr_gettype#define pthread_init _sysvipc_pthread_init #define pthread_mutex_init _sysvipc_pthread_mutex_init #define pthread_mutex_destroy _sysvipc_pthread_mutex_destroy#define pthread_mutex_lock _sysvipc_pthread_mutex_lock #define pthread_mutex_trylock _sysvipc_pthread_mutex_trylock #define pthread_mutex_unlock _sysvipc_pthread_mutex_unlock typedef struct{ int kind; int semid; int sem_num; int locked_times;} pthread_mutex_t;#define SYSVIPC_PTHREAD_MUTEX_FAST_NP 0#define SYSVIPC_PTHREAD_MUTEX_RECURSIVE_NP 1#define SYSVIPC_PTHREAD_MUTEX_ERRORCHECK_NP 2typedef struct{ int kind;} pthread_mutexattr_t;int pthread_mutexattr_init (pthread_mutexattr_t *attr);int pthread_mutexattr_destroy (pthread_mutexattr_t *attr);int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type);int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int* type);int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr);int pthread_mutex_destroy (pthread_mutex_t *mutex);int pthread_mutex_lock (pthread_mutex_t *mutex);int pthread_mutex_trylock (pthread_mutex_t *mutex);int pthread_mutex_unlock (pthread_mutex_t *mutex);#endif /* _USE_MUTEX_ON_SYSVIPC */#ifdef _USE_SEM_ON_SYSVIPC#define sem_t _sysvipc_sem_t#define sem_init _sysvipc_sem_init#define sem_destroy _sysvipc_sem_destroy#define sem_wait _sysvipc_sem_wait#define sem_trywait _sysvipc_sem_trywait#define sem_post _sysvipc_sem_post#define sem_getvalue _sysvipc_sem_getvalue#define SYSVIPC_SEM_VALUE_MAX USHRT_MAX//-----------------------------------------------------------------------------// Semaphore object definitiontypedef struct{ int semid; int sem_num;} sem_t;int sem_init (sem_t *sem, int pshared, unsigned int value);int sem_destroy (sem_t *sem);int sem_wait (sem_t *sem);int sem_trywait (sem_t *sem);int sem_post (sem_t *sem);int sem_getvalue (sem_t *sem, int *sval);#endif /* _USE_SEM_ON_SYSVIPC */#endif /* _MGUI_COMMON_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -