00001
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _MGUI_COMMON_H
00039 #define _MGUI_COMMON_H
00040
00041 #ifndef MINIGUI_MAJOR_VERSION
00042 # ifdef __MINIGUI_LIB__
00043 # ifdef _FOR_DATANG
00044 # ifdef WIN32
00045 # include <config-win32/mgconfig.h>
00046 # elif defined (__THREADX__)
00047 # include "config-threadx/mgconfig.h"
00048 # elif defined (__NUCLEUS__)
00049 # include "config-nucleus/mgconfig.h"
00050 # endif
00051 # else
00052 # if defined(__CMAKE_PROJECT__) || defined(WIN32)
00053 # include "mgconfig.h"
00054 # else
00055 # include "../mgconfig.h"
00056 # endif
00057 # endif
00058 # else
00059 # include "mgconfig.h"
00060 # undef PACKAGE_BUGREPORT
00061 # undef PACKAGE_NAME
00062 # undef PACKAGE_STRING
00063 # undef PACKAGE_TARNAME
00064 # undef PACKAGE_VERSION
00065 # endif
00066 #endif
00067
00088 #define _VERSION_CODE(major, minor, micro) (((major)<<16) | ((minor)<<8) | (micro))
00089
00096 #define _MINIGUI_VERSION_CODE \
00097 ((MINIGUI_MAJOR_VERSION << 16) | (MINIGUI_MINOR_VERSION << 8) | MINIGUI_MICRO_VERSION)
00098
00110 typedef unsigned char Uint8;
00115 typedef signed char Sint8;
00120 typedef unsigned short Uint16;
00125 typedef signed short Sint16;
00130 typedef unsigned int Uint32;
00135 typedef signed int Sint32;
00136
00137
00138 #if !defined(__STRICT_ANSI__)
00139 #if defined(__GNUC__)
00140 #define MGUI_HAS_64BIT_TYPE long long
00141 #endif
00142 #if defined(__CC_ARM)
00143 #define MGUI_HAS_64BIT_TYPE long long
00144 #endif
00145 #if defined(_MSC_VER)
00146 #define MGUI_HAS_64BIT_TYPE __int64
00147 #endif
00148 #endif
00149
00150
00151 #ifdef MGUI_HAS_64BIT_TYPE
00152
00159 typedef unsigned MGUI_HAS_64BIT_TYPE Uint64;
00166 typedef signed MGUI_HAS_64BIT_TYPE Sint64;
00167 #else
00168
00169 typedef struct {
00170 Uint32 hi;
00171 Uint32 lo;
00172 } Uint64, Sint64;
00173 #endif
00174
00175
00176 #define MGUI_COMPILE_TIME_ASSERT(name, x) \
00177 typedef int MGUI_dummy_ ## name[(x) * 2 - 1]
00178
00179 MGUI_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
00180 MGUI_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
00181 MGUI_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
00182 MGUI_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
00183 MGUI_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
00184 MGUI_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
00185 MGUI_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
00186 MGUI_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
00187
00188 #undef MGUI_COMPILE_TIME_ASSERT
00189
00201 #define MGUI_LIL_ENDIAN 1234
00202
00206 #define MGUI_BIG_ENDIAN 4321
00207
00208
00209
00210
00211
00212
00213
00231 #if defined(__i386__) || defined(__ia64__) || \
00232 (defined(__alpha__) || defined(__alpha)) || \
00233 defined(__arm__) || \
00234 (defined(__CC_ARM) && !defined(__BIG_ENDIAN)) || \
00235 (defined(__mips__) && defined(__MIPSEL__)) || \
00236 defined(__LITTLE_ENDIAN__) || \
00237 defined(WIN32)
00238 #define MGUI_BYTEORDER MGUI_LIL_ENDIAN
00239 #else
00240 #define MGUI_BYTEORDER MGUI_BIG_ENDIAN
00241 #endif
00242
00254 #ifndef _HAVE_TYPE_BOOL
00255 #ifndef BOOL
00256 typedef int BOOL;
00257 #endif
00258 #endif
00259
00263 #ifndef FALSE
00264 #define FALSE 0
00265 #endif
00266
00270 #ifndef TRUE
00271 #define TRUE 1
00272 #endif
00273
00278 #ifndef NULL
00279 # ifdef __cplusplus
00280 # define NULL (0)
00281 # else
00282 # define NULL ((void *)0)
00283 # endif
00284 #endif
00285
00286 #define GUIAPI
00287
00288 #if !defined(__NODLL__) && (defined (WIN32) || defined (__NUCLEUS_MNT__))
00289 #if defined(__MINIGUI_LIB__) && !defined(__MGEXT_LIB__)
00290 #define MG_EXPORT __declspec(dllexport)
00291 #else
00292 #define MG_EXPORT __declspec(dllimport)
00293 #endif
00294 #if defined(__MGEXT_LIB__)
00295 #define MGEXT_EXPORT __declspec(dllexport)
00296 #else
00297 #define MGEXT_EXPORT __declspec(dllimport)
00298 #endif
00299 #else
00300 #define MG_EXPORT
00301 #define MGEXT_EXPORT
00302 #endif
00303
00315 typedef unsigned int GHANDLE;
00320 typedef unsigned int HWND;
00325 typedef unsigned int HDC;
00330 typedef unsigned int HPALETTE;
00335 typedef unsigned int HCURSOR;
00340 typedef unsigned int HICON;
00345 typedef unsigned int HMENU;
00350 typedef unsigned int HACCEL;
00355 typedef unsigned int HDLG;
00360 typedef unsigned int HHOOK;
00361
00373 #ifndef _HAVE_TYPE_BYTE
00374 typedef unsigned char BYTE;
00375 #endif
00376
00380 typedef signed char SBYTE;
00381
00386 #ifndef _HAVE_TYPE_WORD
00387 typedef unsigned short WORD;
00388 #endif
00389
00394 typedef signed short SWORD;
00395
00400 #ifndef _HAVE_TYPE_DWORD
00401 typedef unsigned long DWORD;
00402 #endif
00403
00408 typedef signed long SDWORD;
00409
00414 #ifndef _HAVE_TYPE_UINT
00415 typedef unsigned int UINT;
00416 #endif
00417
00422 #ifndef _HAVE_TYPE_LONG
00423 typedef long LONG;
00424 #endif
00425
00430 typedef unsigned int WPARAM;
00431
00436 typedef unsigned long LPARAM;
00437
00444 #define LOBYTE(w) ((BYTE)(w))
00445
00451 #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
00452
00457 #define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))
00458
00465 #define LOWORD(l) ((WORD)(DWORD)(l))
00466
00472 #define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
00473
00480 #define LOSWORD(l) ((SWORD)(DWORD)(l))
00481
00487 #define HISWORD(l) ((SWORD)((((DWORD)(l)) >> 16) & 0xFFFF))
00488
00493 #define MAKELONG(low, high) ((DWORD)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
00494
00503 #define GetRValue(rgba) ((BYTE)(rgba))
00504
00512 #define GetGValue(rgba) ((BYTE)(((DWORD)(rgba)) >> 8))
00513
00521 #define GetBValue(rgba) ((BYTE)((DWORD)(rgba) >> 16))
00522
00530 #define GetAValue(rgba) ((BYTE)((DWORD)(rgba) >> 24))
00531
00542 #define MakeRGBA(r, g, b, a) (((DWORD)((BYTE)(r))) | ((DWORD)((BYTE)(g)) << 8) \
00543 | ((DWORD)((BYTE)(b)) << 16) | ((DWORD)((BYTE)(a)) << 24))
00544
00554 #define MakeRGB(r, g, b) (((DWORD)((BYTE)(r))) | ((DWORD)((BYTE)(g)) << 8) \
00555 | ((DWORD)((BYTE)(b)) << 16))
00556
00561 typedef DWORD RGBCOLOR;
00562
00572 typedef struct _RECT
00573 {
00577 int left;
00581 int top;
00585 int right;
00589 int bottom;
00590 } RECT;
00597 typedef RECT* PRECT;
00598
00603 typedef struct _POINT
00604 {
00608 int x;
00612 int y;
00613 } POINT;
00620 typedef POINT* PPOINT;
00621
00626 typedef struct _SIZE
00627 {
00631 int cx;
00635 int cy;
00636 } SIZE;
00643 typedef SIZE* PSIZE;
00644
00649 typedef struct _RGB
00650 {
00654 BYTE r;
00658 BYTE g;
00662 BYTE b;
00666 BYTE a;
00667 } RGB;
00668
00675 typedef RGB* PRGB;
00676
00689 typedef Sint8 gal_sint8;
00696 typedef Uint8 gal_uint8;
00697
00704 typedef Sint16 gal_sint16;
00711 typedef Uint16 gal_uint16;
00712
00719 typedef Sint32 gal_sint32;
00726 typedef Uint32 gal_uint32;
00727
00732 typedef signed int gal_sint;
00737 typedef unsigned int gal_uint;
00738
00743 typedef Uint32 gal_pixel;
00748 typedef Uint32 gal_attr;
00749
00754 typedef long fixed;
00755
00760 typedef struct _GAL_Color
00761 {
00765 gal_uint8 r;
00769 gal_uint8 g;
00773 gal_uint8 b;
00777 gal_uint8 a;
00778 } GAL_Color;
00779
00784 typedef struct _GAL_Palette
00785 {
00789 int ncolors;
00793 GAL_Color* colors;
00794 } GAL_Palette;
00795
00800 typedef struct _GAL_Rect {
00804 Sint32 x, y;
00808 Sint32 w, h;
00809 } GAL_Rect;
00810
00833 #define MGUI_NR_KEYS 255
00834
00847 #ifndef NR_KEYS
00848 #define NR_KEYS 128
00849 #endif
00850
00867 #define SCANCODE_USER (NR_KEYS + 1)
00868
00869 #define SCANCODE_ESCAPE 1
00870
00871 #define SCANCODE_1 2
00872 #define SCANCODE_2 3
00873 #define SCANCODE_3 4
00874 #define SCANCODE_4 5
00875 #define SCANCODE_5 6
00876 #define SCANCODE_6 7
00877 #define SCANCODE_7 8
00878 #define SCANCODE_8 9
00879 #define SCANCODE_9 10
00880 #define SCANCODE_0 11
00881
00882 #define SCANCODE_MINUS 12
00883 #define SCANCODE_EQUAL 13
00884
00885 #define SCANCODE_BACKSPACE 14
00886 #define SCANCODE_TAB 15
00887
00888 #define SCANCODE_Q 16
00889 #define SCANCODE_W 17
00890 #define SCANCODE_E 18
00891 #define SCANCODE_R 19
00892 #define SCANCODE_T 20
00893 #define SCANCODE_Y 21
00894 #define SCANCODE_U 22
00895 #define SCANCODE_I 23
00896 #define SCANCODE_O 24
00897 #define SCANCODE_P 25
00898 #define SCANCODE_BRACKET_LEFT 26
00899 #define SCANCODE_BRACKET_RIGHT 27
00900
00901 #define SCANCODE_ENTER 28
00902
00903 #define SCANCODE_LEFTCONTROL 29
00904
00905 #define SCANCODE_A 30
00906 #define SCANCODE_S 31
00907 #define SCANCODE_D 32
00908 #define SCANCODE_F 33
00909 #define SCANCODE_G 34
00910 #define SCANCODE_H 35
00911 #define SCANCODE_J 36
00912 #define SCANCODE_K 37
00913 #define SCANCODE_L 38
00914 #define SCANCODE_SEMICOLON 39
00915 #define SCANCODE_APOSTROPHE 40
00916 #define SCANCODE_GRAVE 41
00917
00918 #define SCANCODE_LEFTSHIFT 42
00919 #define SCANCODE_BACKSLASH 43
00920
00921 #define SCANCODE_Z 44
00922 #define SCANCODE_X 45
00923 #define SCANCODE_C 46
00924 #define SCANCODE_V 47
00925 #define SCANCODE_B 48
00926 #define SCANCODE_N 49
00927 #define SCANCODE_M 50
00928 #define SCANCODE_COMMA 51
00929 #define SCANCODE_PERIOD 52
00930 #define SCANCODE_SLASH 53
00931
00932 #define SCANCODE_RIGHTSHIFT 54
00933 #define SCANCODE_KEYPADMULTIPLY 55
00934
00935 #define SCANCODE_LEFTALT 56
00936 #define SCANCODE_SPACE 57
00937 #define SCANCODE_CAPSLOCK 58
00938
00939 #define SCANCODE_F1 59
00940 #define SCANCODE_F2 60
00941 #define SCANCODE_F3 61
00942 #define SCANCODE_F4 62
00943 #define SCANCODE_F5 63
00944 #define SCANCODE_F6 64
00945 #define SCANCODE_F7 65
00946 #define SCANCODE_F8 66
00947 #define SCANCODE_F9 67
00948 #define SCANCODE_F10 68
00949
00950 #define SCANCODE_NUMLOCK 69
00951 #define SCANCODE_SCROLLLOCK 70
00952
00953 #define SCANCODE_KEYPAD7 71
00954 #define SCANCODE_CURSORUPLEFT 71
00955 #define SCANCODE_KEYPAD8 72
00956 #define SCANCODE_CURSORUP 72
00957 #define SCANCODE_KEYPAD9 73
00958 #define SCANCODE_CURSORUPRIGHT 73
00959 #define SCANCODE_KEYPADMINUS 74
00960 #define SCANCODE_KEYPAD4 75
00961 #define SCANCODE_CURSORLEFT 75
00962 #define SCANCODE_KEYPAD5 76
00963 #define SCANCODE_KEYPAD6 77
00964 #define SCANCODE_CURSORRIGHT 77
00965 #define SCANCODE_KEYPADPLUS 78
00966 #define SCANCODE_KEYPAD1 79
00967 #define SCANCODE_CURSORDOWNLEFT 79
00968 #define SCANCODE_KEYPAD2 80
00969 #define SCANCODE_CURSORDOWN 80
00970 #define SCANCODE_KEYPAD3 81
00971 #define SCANCODE_CURSORDOWNRIGHT 81
00972 #define SCANCODE_KEYPAD0 82
00973 #define SCANCODE_KEYPADPERIOD 83
00974
00975 #define SCANCODE_LESS 86
00976
00977 #define SCANCODE_F11 87
00978 #define SCANCODE_F12 88
00979
00980 #define SCANCODE_KEYPADENTER 96
00981 #define SCANCODE_RIGHTCONTROL 97
00982 #define SCANCODE_CONTROL 97
00983 #define SCANCODE_KEYPADDIVIDE 98
00984 #define SCANCODE_PRINTSCREEN 99
00985 #define SCANCODE_RIGHTALT 100
00986 #define SCANCODE_BREAK 101
00987 #define SCANCODE_BREAK_ALTERNATIVE 119
00988
00989 #define SCANCODE_HOME 102
00990 #define SCANCODE_CURSORBLOCKUP 103
00991 #define SCANCODE_PAGEUP 104
00992 #define SCANCODE_CURSORBLOCKLEFT 105
00993 #define SCANCODE_CURSORBLOCKRIGHT 106
00994 #define SCANCODE_END 107
00995 #define SCANCODE_CURSORBLOCKDOWN 108
00996 #define SCANCODE_PAGEDOWN 109
00997 #define SCANCODE_INSERT 110
00998 #define SCANCODE_REMOVE 111
00999
01000 #define SCANCODE_PAUSE 119
01001
01002 #define SCANCODE_POWER 120
01003 #define SCANCODE_SLEEP 121
01004 #define SCANCODE_WAKEUP 122
01005
01006 #define SCANCODE_LEFTWIN 125
01007 #define SCANCODE_RIGHTWIN 126
01008 #define SCANCODE_MENU 127
01009
01010 #define SCANCODE_LEFTBUTTON 0x1000
01011 #define SCANCODE_RIGHTBUTTON 0x2000
01012 #define SCANCODE_MIDDLBUTTON 0x4000
01013
01034 #define KS_REPEATED 0x00000800
01035
01056 #define KS_CAPTURED 0x00000400
01057
01064 #define KS_IMEPOST 0x00000200
01065
01086 #define KS_CAPSLOCK 0x00000100
01087
01095 #define KS_NUMLOCK 0x00000080
01096
01104 #define KS_SCROLLLOCK 0x00000040
01105
01113 #define KS_LEFTCTRL 0x00000020
01114
01122 #define KS_RIGHTCTRL 0x00000010
01123
01131 #define KS_CTRL 0x00000030
01132
01140 #define KS_LEFTALT 0x00000008
01141
01149 #define KS_RIGHTALT 0x00000004
01150
01158 #define KS_ALT 0x0000000C
01159
01167 #define KS_LEFTSHIFT 0x00000002
01168
01176 #define KS_RIGHTSHIFT 0x00000001
01177
01185 #define KS_SHIFT 0x00000003
01186
01191 #define MASK_KS_SHIFTKEYS 0x00000FFF
01192
01200 #define KS_LEFTBUTTON 0x00001000
01201
01209 #define KS_RIGHTBUTTON 0x00002000
01210
01218 #define KS_MIDDLBUTTON 0x00004000
01219
01224 #define MASK_KS_BUTTONS 0x0000F000
01225
01236 #define ERR_OK 0
01237
01242 #define ERR_INV_HWND -1
01243
01248 #define ERR_QUEUE_FULL -2
01249
01254 #define ERR_INVALID_HANDLE -3
01255
01260 #define ERR_INVALID_HMENU -4
01261
01266 #define ERR_INVALID_POS -5
01267
01272 #define ERR_INVALID_ID -6
01273
01278 #define ERR_RES_ALLOCATION -7
01279
01284 #define ERR_CTRLCLASS_INVNAME -8
01285
01290 #define ERR_CTRLCLASS_INVLEN -9
01291
01296 #define ERR_CTRLCLASS_MEM -10
01297
01302 #define ERR_CTRLCLASS_INUSE -11
01303
01308 #define ERR_ALREADY_EXIST -12
01309
01314 #define ERR_NO_MATCH -13
01315
01320 #define ERR_BAD_OWNER -14
01321
01326 #define ERR_IME_TOOMUCHIMEWND -15
01327
01332 #define ERR_IME_NOSUCHIMEWND -16
01333
01338 #define ERR_IME_NOIMEWND -17
01339
01344 #define ERR_CONFIG_FILE -18
01345
01350 #define ERR_FILE_IO -19
01351
01356 #define ERR_GFX_ENGINE -20
01357
01362 #define ERR_INPUT_ENGINE -21
01363
01368 #define ERR_NO_ENGINE -22
01369
01374 #define ERR_INVALID_ARGS -23
01375
01386 #define TABLESIZE(table) (sizeof(table)/sizeof(table[0]))
01387
01388
01393 #ifndef MAX
01394 #define MAX(x, y) (((x) > (y))?(x):(y))
01395 #endif
01396
01400 #ifndef MIN
01401 #define MIN(x, y) (((x) < (y))?(x):(y))
01402 #endif
01403
01407 #ifndef ABS
01408 #define ABS(x) (((x)<0) ? -(x) : (x))
01409 #endif
01410
01411
01412 #if !defined(__NOUNIX__) || defined (__ECOS__)
01413 #include <limits.h>
01414 #endif
01415
01416 #ifndef PATH_MAX
01417 #define PATH_MAX 256
01418 #endif
01419
01420 #ifndef NAME_MAX
01421 #define NAME_MAX 64
01422 #endif
01423
01424
01430 #ifndef MAX_PATH
01431 # define MAX_PATH PATH_MAX
01432 #endif
01433
01439 #ifndef MAX_NAME
01440 #define MAX_NAME NAME_MAX
01441 #endif
01442
01447 #ifdef __cplusplus
01448 extern "C" {
01449 #endif
01450
01451 #ifndef HAVE_TIME
01452 typedef unsigned int time_t;
01453
01454 struct tm {
01455 int tm_sec;
01456 int tm_min;
01457 int tm_hour;
01458 int tm_mday;
01459 int tm_mon;
01460 int tm_year;
01461 int tm_wday;
01462 int tm_yday;
01463 int tm_isdst;
01464 };
01465 #endif
01466
01467 #if defined (__THREADX__) && defined (__TARGET_VFANVIL__)
01468 #include "fx_api.h"
01469 #include "tx_api.h"
01470 #include "os_type.h"
01471 #include "os_file_api.h"
01472
01473 #define fopen tp_fopen
01474 #define fclose tp_fclose
01475 #define fwrite tp_fwrite
01476 #define fread tp_fread
01477 #define fseek tp_fseek
01478 #define feof tp_feof
01479
01480
01481 #undef assert
01482 #define _HAVE_ASSERT 1
01483
01484 #define assert(e) do { \
01485 e; \
01486 } while(0);
01487
01488 #undef stdin
01489 #undef stdout
01490 #undef stderr
01491
01492 #define stdin ((FILE*)0)
01493 #define stdout ((FILE*)1)
01494 #define stderr ((FILE*)2)
01495 void Comm_Lock_Screen (void);
01496 void Comm_Unlock_Screen (void);
01497
01498 #endif
01499
01500 #ifdef __UCOSII__
01501
01502
01503 #undef HAVE_STRDUP
01504 #undef strdup
01505 #define strdup own_strdup
01506
01507 #endif
01508
01509 #ifndef HAVE_STRDUP
01510 MG_EXPORT char *strdup(const char *s);
01511 #endif
01512
01513 #ifndef HAVE_STRCASECMP
01514 MG_EXPORT int strcasecmp(const char *s1, const char *s2);
01515 #endif
01516
01517 #ifndef HAVE_STRNCASECMP
01518 MG_EXPORT int strncasecmp(const char *s1, const char *s2, unsigned int n);
01519 #endif
01520
01521 #ifdef _MGUSE_OWN_MALLOC
01522
01542 int init_minigui_malloc (unsigned char* heap, unsigned int heap_size,
01543 int (*lock_heap) (void), int (*unlock_heap) (void));
01544
01545 #define USE_DL_PREFIX
01546
01547 #include "own_malloc.h"
01548
01549
01550 #define calloc dlcalloc
01551 #define free dlfree
01552 #define malloc dlmalloc
01553 #define memalign dlmemalign
01554 #define realloc dlrealloc
01555 #define valloc dlvalloc
01556
01557 #endif
01558
01559
01560 #if defined(__CC_ARM)
01561 # undef HAVE_ALLOCA
01562 # undef HAVE_ALLOCA_H
01563 #endif
01564
01565 #ifdef HAVE_ALLOCA_H
01566 # include <alloca.h>
01567 # define ALLOCATE_LOCAL(size) alloca((int)(size))
01568 # define DEALLOCATE_LOCAL(ptr)
01569 #else
01570 # define ALLOCATE_LOCAL(size) malloc((int)(size))
01571 # define DEALLOCATE_LOCAL(ptr) free(ptr)
01572 #endif
01573
01574 #ifdef _MGUSE_OWN_STDIO
01575
01588 int init_minigui_printf (int (*output_char) (int ch),
01589 int (*input_char) (void));
01590
01591 #if defined (__UCOSII__) || defined (__VXWORKS__) || defined (__NUCLEUS__) || defined (__PSOS__)
01592 # undef _PRINTF_FLOATING_POINT
01593 # undef _SCANF_FLOATING_POINT
01594 #else
01595 # ifdef HAVE_MATH_H
01596 # define _PRINTF_FLOATING_POINT 1
01597 # define _SCANF_FLOATING_POINT 1
01598 # endif
01599 #endif
01600
01601 #ifdef WIN32
01602 # include <float.h>
01603 # define isnan _isnan
01604 # define finite _finite
01605 #endif
01606
01607 #undef _I18N_MB_REQUIRED
01608
01609 #if defined(__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (__PSOS__)
01610 #define _MGUSE_OWN_SNPRINTF
01611 #define _MGUSE_OWN_VSNPRINTF
01612 #define _MGUSE_OWN_VFNPRINTF
01613 #else
01614 #define _MGUSE_OWN_PRINTF
01615 #define _MGUSE_OWN_FPRINTF
01616 #define _MGUSE_OWN_SPRINTF
01617 #define _MGUSE_OWN_FNPRINTF
01618 #define _MGUSE_OWN_SNPRINTF
01619 #define _MGUSE_OWN_VPRINTF
01620 #define _MGUSE_OWN_VFPRINTF
01621 #define _MGUSE_OWN_VSPRINTF
01622 #define _MGUSE_OWN_VFNPRINTF
01623 #define _MGUSE_OWN_VSNPRINTF
01624 #define _MGUSE_OWN_SCANF
01625 #define _MGUSE_OWN_FSCANF
01626 #define _MGUSE_OWN_SSCANF
01627 #define _MGUSE_OWN_VSCANF
01628 #define _MGUSE_OWN_VFSCANF
01629 #define _MGUSE_OWN_VSSCANF
01630 #endif
01631
01632 #include "own_stdio.h"
01633
01634
01635 #ifdef _MGUSE_OWN_PRINTF
01636 #define printf own_printf
01637 #endif
01638
01639 #ifdef _MGUSE_OWN_FPRINTF
01640 #define fprintf own_fprintf
01641 #endif
01642
01643 #ifdef _MGUSE_OWN_SPRINTF
01644 #define sprintf own_sprintf
01645 #endif
01646
01647 #ifdef _MGUSE_OWN_FNPRINTF
01648 #define fnprintf own_fnprintf
01649 #endif
01650
01651 #ifdef _MGUSE_OWN_SNPRINTF
01652 #define snprintf own_snprintf
01653 #endif
01654
01655 #ifdef _MGUSE_OWN_VPRINTF
01656 #define vprintf own_vprintf
01657 #endif
01658
01659 #ifdef _MGUSE_OWN_VFPRINTF
01660 #define vfprintf own_vfprintf
01661 #endif
01662
01663 #ifdef _MGUSE_OWN_VSPRINTF
01664 #define vsprintf own_vsprintf
01665 #endif
01666
01667 #ifdef _MGUSE_OWN_VFNPRINTF
01668 #define vfnprintf own_vfnprintf
01669 #endif
01670
01671 #ifdef _MGUSE_OWN_VSNPRINTF
01672 #define vsnprintf own_vsnprintf
01673 #endif
01674
01675 #ifdef _MGUSE_OWN_SCANF
01676 #define scanf own_scanf
01677 #endif
01678
01679 #ifdef _MGUSE_OWN_FSCANF
01680 #define fscanf own_fscanf
01681 #endif
01682
01683 #ifdef _MGUSE_OWN_SSCANF
01684 #define sscanf own_sscanf
01685 #endif
01686
01687 #ifdef _MGUSE_OWN_VSCANF
01688 #define vscanf own_vscanf
01689 #endif
01690
01691 #ifdef _MGUSE_OWN_VFSCANF
01692 #define vfscanf own_vfscanf
01693 #endif
01694
01695 #ifdef _MGUSE_OWN_VSSCANF
01696 #define vsscanf own_vsscanf
01697 #endif
01698
01699 #endif
01700
01701 #if defined(__GNUC__)
01702 #ifdef _DEBUG
01703 # define _MG_PRINTF(fmt...) fprintf (stderr, fmt)
01704 #else
01705 # define _MG_PRINTF(fmt...)
01706 #endif
01707 #else
01708 #include <stdio.h>
01709 #include <stdarg.h>
01710
01711 static inline void _MG_PRINTF(const char* fmt, ...)
01712 {
01713 #ifdef _DEBUG
01714 va_list ap;
01715 va_start(ap, fmt);
01716 vfprintf(stderr, fmt, ap);
01717 fprintf(stderr, "\n");
01718 va_end(ap);
01719 #endif
01720 }
01721 #endif
01722
01723 #ifdef _MGRM_THREADS
01724
01725 #ifdef _MGUSE_OWN_PTHREAD
01726
01727 #define MAIN_PTH_MIN_STACK_SIZE (1024)
01728 #define MAIN_PTH_DEF_STACK_SIZE (1024*4)
01729
01753 int start_minigui_pthread (int (* pth_entry) (int argc, const char* argv []),
01754 int argc, const char* argv[],
01755 char* stack_base, unsigned int stack_size);
01756
01757 #include <errno.h>
01758
01759 #ifndef ESRCH
01760 # define ESRCH 3
01761 #endif
01762
01763 #ifndef EAGAIN
01764 # define EAGAIN 11
01765 #endif
01766
01767 #ifndef ENOMEM
01768 # define ENOMEM 12
01769 #endif
01770
01771 #ifndef EBUSY
01772 # define EBUSY 16
01773 #endif
01774
01775 #ifndef EINVAL
01776 # define EINVAL 22
01777 #endif
01778
01779 #ifndef EDEADLK
01780 # define EDEADLK 35
01781 #endif
01782
01783 #ifndef ENOSYS
01784 # define ENOSYS 38
01785 #endif
01786
01787 #ifndef ENOTSUP
01788 # define ENOTSUP 95
01789 #endif
01790
01791 #ifdef __VXWORKS__
01792
01793 #define pthread_create vxworks_pthread_create
01794 #define pthread_self vxworks_pthread_self
01795 #define pthread_equal vxworks_pthread_equal
01796 #define pthread_exit vxworks_pthread_exit
01797 #define pthread_join vxworks_pthread_join
01798 #define pthread_detach vxworks_pthread_detach
01799 #define pthread_cancel vxworks_pthread_cancel
01800 #define pthread_once vxworks_pthread_once
01801 #define pthread_key_create vxworks_pthread_key_create
01802 #define pthread_key_delete vxworks_pthread_key_delete
01803 #define pthread_setspecific vxworks_pthread_setspecific
01804 #define pthread_getspecific vxworks_pthread_getspecific
01805 #define pthread_setcancelstate vxworks_pthread_setcancelstate
01806 #define pthread_setcanceltype vxworks_pthread_setcanceltype
01807 #define pthread_testcancel vxworks_pthread_testcancel
01808
01809 #define pthread_attr_init vxworks_pthread_attr_init
01810 #define pthread_attr_destroy vxworks_pthread_attr_destroy
01811 #define pthread_attr_setdetachstate vxworks_pthread_attr_setdetachstate
01812 #define pthread_attr_getdetachstate vxworks_pthread_attr_getdetachstate
01813 #define pthread_attr_setscope vxworks_pthread_attr_setscope
01814 #define pthread_attr_getscope vxworks_pthread_attr_getscope
01815 #define pthread_attr_setinheritsched vxworks_pthread_attr_setinheritsched
01816 #define pthread_attr_getinheritsched vxworks_pthread_attr_getinheritsched
01817 #define pthread_attr_setschedpolicy vxworks_pthread_attr_setschedpolicy
01818 #define pthread_attr_getschedpolicy vxworks_pthread_attr_getschedpolicy
01819 #define pthread_attr_setschedparam vxworks_pthread_attr_setschedparam
01820 #define pthread_attr_getschedparam vxworks_pthread_attr_getschedparam
01821 #define pthread_attr_setstackaddr vxworks_pthread_attr_setstackaddr
01822 #define pthread_attr_getstackaddr vxworks_pthread_attr_getstackaddr
01823 #define pthread_attr_setstacksize vxworks_pthread_attr_setstacksize
01824 #define pthread_attr_getstacksize vxworks_pthread_attr_getstacksize
01825 #define pthread_setschedparam vxworks_pthread_setschedparam
01826 #define pthread_getschedparam vxworks_pthread_getschedparam
01827
01828 #define pthread_mutex_init vxworks_pthread_mutex_init
01829 #define pthread_mutex_destroy vxworks_pthread_mutex_destroy
01830 #define pthread_mutex_lock vxworks_pthread_mutex_lock
01831 #define pthread_mutex_unlock vxworks_pthread_mutex_unlock
01832 #define pthread_mutex_trylock vxworks_pthread_mutex_trylock
01833 #define pthread_mutexattr_init vxworks_pthread_mutexattr_init
01834 #define pthread_mutexattr_destroy vxworks_pthread_mutexattr_destroy
01835 #define pthread_mutexattr_setpriorityinherit vxworks_pthread_mutexattr_setpriorityinherit
01836 #define pthread_mutexattr_getpriorityinherit vxworks_pthread_mutexattr_getpriorityinherit
01837
01838 #ifdef _MGUSE_OWN_SEMAPHORE
01839
01840 #define sem_t vxworks_sem_t
01841
01842 #define sem_init vxworks_sem_init
01843 #define sem_destroy vxworks_sem_destroy
01844 #define sem_wait vxworks_sem_wait
01845 #define sem_trywait vxworks_sem_trywait
01846 #define sem_post vxworks_sem_post
01847 #define sem_getvalue vxworks_sem_getvalue
01848
01849 #endif
01850
01851 #endif
01852
01853 #ifdef __MINIGUI_LIB__
01854
01855 #ifdef __UCOSII__
01856 #include "ucos2_pthread.h"
01857 #include "ucos2_semaphore.h"
01858 #elif defined (__THREADX__)
01859 #include "threadx_pthread.h"
01860 #include "threadx_semaphore.h"
01861 #elif defined (__NUCLEUS__)
01862 #include "nucleus_pthread.h"
01863 #include "nucleus_semaphore.h"
01864 #elif defined (__VXWORKS__)
01865 #include "vxworks_pthread.h"
01866 #ifdef _MGUSE_OWN_SEMAPHORE
01867 #include "vxworks_semaphore.h"
01868 #else
01869 #include "semaphore.h"
01870 #endif
01871 #elif defined (__OSE__)
01872 #include "pthread.h"
01873 #include "ose_semaphore.h"
01874 #elif defined (__PSOS__)
01875 #include "psos_pthread.h"
01876 #include "psos_semaphore.h"
01877 #elif defined (WIN32)
01878 #include "win32_pthread.h"
01879 #include "win32_semaphore.h"
01880 #else
01881 #error No own pthread implementation for this OS!
01882 #endif
01883 #else
01884 #include <pthread.h>
01885 #include <semaphore.h>
01886 #endif
01887
01888 #else
01889
01890 #include <pthread.h>
01891 #include <semaphore.h>
01892
01893 #endif
01894
01895 #ifdef __DARWIN__
01896
01897 #define _USE_SEM_ON_SYSVIPC 1
01898
01899 #endif
01900
01901 #if defined (_USE_MUTEX_ON_SYSVIPC) || defined (_USE_SEM_ON_SYSVIPC)
01902
01903 int _sysvipc_mutex_sem_init (void);
01904 int _sysvipc_mutex_sem_term (void);
01905
01906 #endif
01907
01908 #ifdef _USE_MUTEX_ON_SYSVIPC
01909
01910 #define pthread_mutex_t _sysvipc_pthread_mutex_t
01911 #define pthread_mutexattr_t _sysvipc_pthread_mutexattr_t
01912
01913 #define pthread_mutexattr_init _sysvipc_pthread_mutexattr_init
01914 #define pthread_mutexattr_destroy _sysvipc_pthread_mutexattr_destroy
01915 #define pthread_mutexattr_settype _sysvipc_pthread_mutexattr_settype
01916 #define pthread_mutexattr_gettype _sysvipc_pthread_mutexattr_gettype
01917
01918 #define pthread_init _sysvipc_pthread_init
01919 #define pthread_mutex_init _sysvipc_pthread_mutex_init
01920 #define pthread_mutex_destroy _sysvipc_pthread_mutex_destroy
01921 #define pthread_mutex_lock _sysvipc_pthread_mutex_lock
01922 #define pthread_mutex_trylock _sysvipc_pthread_mutex_trylock
01923 #define pthread_mutex_unlock _sysvipc_pthread_mutex_unlock
01924
01925 typedef struct
01926 {
01927 int kind;
01928 int semid;
01929 int sem_num;
01930 int locked_times;
01931 } pthread_mutex_t;
01932
01933 #define SYSVIPC_PTHREAD_MUTEX_FAST_NP 0
01934 #define SYSVIPC_PTHREAD_MUTEX_RECURSIVE_NP 1
01935 #define SYSVIPC_PTHREAD_MUTEX_ERRORCHECK_NP 2
01936
01937 typedef struct
01938 {
01939 int kind;
01940 } pthread_mutexattr_t;
01941
01942 int pthread_mutexattr_init (pthread_mutexattr_t *attr);
01943 int pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
01944 int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type);
01945 int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int* type);
01946
01947 int pthread_mutex_init (pthread_mutex_t *mutex,
01948 const pthread_mutexattr_t *mutex_attr);
01949
01950 int pthread_mutex_destroy (pthread_mutex_t *mutex);
01951
01952 int pthread_mutex_lock (pthread_mutex_t *mutex);
01953 int pthread_mutex_trylock (pthread_mutex_t *mutex);
01954 int pthread_mutex_unlock (pthread_mutex_t *mutex);
01955
01956 #endif
01957
01958 #ifdef _USE_SEM_ON_SYSVIPC
01959
01960 #define sem_t _sysvipc_sem_t
01961
01962 #define sem_init _sysvipc_sem_init
01963 #define sem_destroy _sysvipc_sem_destroy
01964 #define sem_wait _sysvipc_sem_wait
01965 #define sem_trywait _sysvipc_sem_trywait
01966 #define sem_post _sysvipc_sem_post
01967 #define sem_getvalue _sysvipc_sem_getvalue
01968
01969 #define SYSVIPC_SEM_VALUE_MAX USHRT_MAX
01970
01971
01972
01973
01974
01975 typedef struct
01976 {
01977 int semid;
01978 int sem_num;
01979 } sem_t;
01980
01981 int sem_init (sem_t *sem, int pshared, unsigned int value);
01982 int sem_destroy (sem_t *sem);
01983 int sem_wait (sem_t *sem);
01984 int sem_trywait (sem_t *sem);
01985 int sem_post (sem_t *sem);
01986 int sem_getvalue (sem_t *sem, int *sval);
01987
01988 #endif
01989
01990 #endif
01991
01992 #ifdef __cplusplus
01993 }
01994 #endif
01995
01996 #endif
01997