00001
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _MGUI_COMMON_H
00037 #define _MGUI_COMMON_H
00038
00039 #ifndef MINIGUI_MAJOR_VERSION
00040 # ifdef __MINIGUI_LIB__
00041 #ifdef _FOR_DATANG
00042 #ifdef WIN32
00043 #include <config-win32/mgconfig.h>
00044 #elif defined (__THREADX__)
00045 # include "config-threadx/mgconfig.h"
00046 #elif defined (__NUCLEUS__)
00047 # include "config-nucleus/mgconfig.h"
00048 #endif
00049 #else
00050 # include "../mgconfig.h"
00051 #endif
00052 # else
00053 # include "mgconfig.h"
00054 # endif
00055 #endif
00056
00057
00078 #define _VERSION_CODE(major, minor, micro) (((major)<<16) | ((minor)<<8) | (micro))
00079
00086 #define _MINIGUI_VERSION_CODE \
00087 ((MINIGUI_MAJOR_VERSION << 16) | (MINIGUI_MINOR_VERSION << 8) | MINIGUI_MICRO_VERSION)
00088
00100 typedef unsigned char Uint8;
00105 typedef signed char Sint8;
00110 typedef unsigned short Uint16;
00115 typedef signed short Sint16;
00120 typedef unsigned int Uint32;
00125 typedef signed int Sint32;
00126
00127
00128 #if !defined(__STRICT_ANSI__)
00129 #if defined(__GNUC__)
00130 #define MGUI_HAS_64BIT_TYPE long long
00131 #endif
00132 #if defined(__CC_ARM)
00133 #define MGUI_HAS_64BIT_TYPE long long
00134 #endif
00135 #if defined(_MSC_VER)
00136 #define MGUI_HAS_64BIT_TYPE __int64
00137 #endif
00138 #endif
00139
00140
00141 #ifdef MGUI_HAS_64BIT_TYPE
00142
00149 typedef unsigned MGUI_HAS_64BIT_TYPE Uint64;
00156 typedef signed MGUI_HAS_64BIT_TYPE Sint64;
00157 #else
00158
00159 typedef struct {
00160 Uint32 hi;
00161 Uint32 lo;
00162 } Uint64, Sint64;
00163 #endif
00164
00165
00166 #define MGUI_COMPILE_TIME_ASSERT(name, x) \
00167 typedef int MGUI_dummy_ ## name[(x) * 2 - 1]
00168
00169 MGUI_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
00170 MGUI_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
00171 MGUI_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
00172 MGUI_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
00173 MGUI_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
00174 MGUI_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
00175 MGUI_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
00176 MGUI_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
00177
00178 #undef MGUI_COMPILE_TIME_ASSERT
00179
00191 #define MGUI_LIL_ENDIAN 1234
00192
00196 #define MGUI_BIG_ENDIAN 4321
00197
00198
00199
00200
00201
00202
00203
00221 #if defined(__i386__) || defined(__ia64__) || \
00222 (defined(__alpha__) || defined(__alpha)) || \
00223 defined(__arm__) || \
00224 (defined(__CC_ARM) && !defined(__BIG_ENDIAN)) || \
00225 (defined(__mips__) && defined(__MIPSEL__)) || \
00226 defined(__LITTLE_ENDIAN__) || \
00227 defined(WIN32)
00228 #define MGUI_BYTEORDER MGUI_LIL_ENDIAN
00229 #else
00230 #define MGUI_BYTEORDER MGUI_BIG_ENDIAN
00231 #endif
00232
00244 #ifndef _HAVE_TYPE_BOOL
00245 #ifndef BOOL
00246 typedef int BOOL;
00247 #endif
00248 #endif
00249
00253 #ifndef FALSE
00254 #define FALSE 0
00255 #endif
00256
00260 #ifndef TRUE
00261 #define TRUE 1
00262 #endif
00263
00268 #ifndef NULL
00269 #define NULL ((void *)0)
00270 #endif
00271
00272 #define GUIAPI
00273
00274 #if !defined(__NODLL__) && (defined (WIN32) || defined (__NUCLEUS_MNT__))
00275 #if defined(__MINIGUI_LIB__) && !defined(__MGEXT_LIB__)
00276 #define MG_EXPORT __declspec(dllexport)
00277 #else
00278 #define MG_EXPORT __declspec(dllimport)
00279 #endif
00280 #if defined(__MGEXT_LIB__)
00281 #define MGEXT_EXPORT __declspec(dllexport)
00282 #else
00283 #define MGEXT_EXPORT __declspec(dllimport)
00284 #endif
00285 #else
00286 #define MG_EXPORT
00287 #define MGEXT_EXPORT
00288 #endif
00289
00301 typedef unsigned int GHANDLE;
00306 typedef unsigned int HWND;
00311 typedef unsigned int HDC;
00316 typedef unsigned int HPALETTE;
00321 typedef unsigned int HCURSOR;
00326 typedef unsigned int HICON;
00331 typedef unsigned int HMENU;
00336 typedef unsigned int HACCEL;
00341 typedef unsigned int HDLG;
00346 typedef unsigned int HHOOK;
00347
00359 #ifndef _HAVE_TYPE_BYTE
00360 typedef unsigned char BYTE;
00361 #endif
00362
00366 typedef signed char SBYTE;
00367
00372 #ifndef _HAVE_TYPE_WORD
00373 typedef unsigned short WORD;
00374 #endif
00375
00380 typedef signed short SWORD;
00381
00386 #ifndef _HAVE_TYPE_DWORD
00387 typedef unsigned long DWORD;
00388 #endif
00389
00394 typedef signed long SDWORD;
00395
00400 #ifndef _HAVE_TYPE_UINT
00401 typedef unsigned int UINT;
00402 #endif
00403
00408 #ifndef _HAVE_TYPE_LONG
00409 typedef long LONG;
00410 #endif
00411
00416 typedef unsigned int WPARAM;
00417
00422 typedef unsigned long LPARAM;
00423
00430 #define LOBYTE(w) ((BYTE)(w))
00431
00437 #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
00438
00443 #define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))
00444
00451 #define LOWORD(l) ((WORD)(DWORD)(l))
00452
00458 #define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
00459
00466 #define LOSWORD(l) ((SWORD)(DWORD)(l))
00467
00473 #define HISWORD(l) ((SWORD)((((DWORD)(l)) >> 16) & 0xFFFF))
00474
00479 #define MAKELONG(low, high) ((DWORD)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
00480
00489 #define GetRValue(rgb) ((BYTE)(rgb))
00490
00498 #define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
00499
00507 #define GetBValue(rgb) ((BYTE)((rgb) >> 16))
00508
00518 #define MakeRGB(r, g, b) (((DWORD)((BYTE)(r))) | ((DWORD)((BYTE)(g)) << 8) \
00519 | ((DWORD)((BYTE)(b)) << 16))
00520
00525 typedef DWORD RGBCOLOR;
00526
00536 typedef struct _RECT
00537 {
00541 int left;
00545 int top;
00549 int right;
00553 int bottom;
00554 } RECT;
00561 typedef RECT* PRECT;
00562
00567 typedef struct _POINT
00568 {
00572 int x;
00576 int y;
00577 } POINT;
00584 typedef POINT* PPOINT;
00585
00590 typedef struct _SIZE
00591 {
00595 int cx;
00599 int cy;
00600 } SIZE;
00607 typedef SIZE* PSIZE;
00608
00613 typedef struct _RGB
00614 {
00618 BYTE r;
00622 BYTE g;
00626 BYTE b;
00630 BYTE a;
00631 } RGB;
00632
00639 typedef RGB* PRGB;
00640
00653 typedef Sint8 gal_sint8;
00660 typedef Uint8 gal_uint8;
00661
00668 typedef Sint16 gal_sint16;
00675 typedef Uint16 gal_uint16;
00676
00683 typedef Sint32 gal_sint32;
00690 typedef Uint32 gal_uint32;
00691
00696 typedef signed int gal_sint;
00701 typedef unsigned int gal_uint;
00702
00707 typedef Uint32 gal_pixel;
00712 typedef Uint32 gal_attr;
00713
00718 typedef long fixed;
00719
00724 typedef struct _GAL_Color
00725 {
00729 gal_uint8 r;
00733 gal_uint8 g;
00737 gal_uint8 b;
00741 gal_uint8 a;
00742 } GAL_Color;
00743
00748 typedef struct _GAL_Palette
00749 {
00753 int ncolors;
00757 GAL_Color* colors;
00758 } GAL_Palette;
00759
00764 typedef struct _GAL_Rect {
00768 Sint32 x, y;
00772 Sint32 w, h;
00773 } GAL_Rect;
00774
00797 #define MGUI_NR_KEYS 255
00798
00811 #ifndef NR_KEYS
00812 #define NR_KEYS 128
00813 #endif
00814
00831 #define SCANCODE_USER (NR_KEYS + 1)
00832
00833 #define SCANCODE_ESCAPE 1
00834
00835 #define SCANCODE_1 2
00836 #define SCANCODE_2 3
00837 #define SCANCODE_3 4
00838 #define SCANCODE_4 5
00839 #define SCANCODE_5 6
00840 #define SCANCODE_6 7
00841 #define SCANCODE_7 8
00842 #define SCANCODE_8 9
00843 #define SCANCODE_9 10
00844 #define SCANCODE_0 11
00845
00846 #define SCANCODE_MINUS 12
00847 #define SCANCODE_EQUAL 13
00848
00849 #define SCANCODE_BACKSPACE 14
00850 #define SCANCODE_TAB 15
00851
00852 #define SCANCODE_Q 16
00853 #define SCANCODE_W 17
00854 #define SCANCODE_E 18
00855 #define SCANCODE_R 19
00856 #define SCANCODE_T 20
00857 #define SCANCODE_Y 21
00858 #define SCANCODE_U 22
00859 #define SCANCODE_I 23
00860 #define SCANCODE_O 24
00861 #define SCANCODE_P 25
00862 #define SCANCODE_BRACKET_LEFT 26
00863 #define SCANCODE_BRACKET_RIGHT 27
00864
00865 #define SCANCODE_ENTER 28
00866
00867 #define SCANCODE_LEFTCONTROL 29
00868
00869 #define SCANCODE_A 30
00870 #define SCANCODE_S 31
00871 #define SCANCODE_D 32
00872 #define SCANCODE_F 33
00873 #define SCANCODE_G 34
00874 #define SCANCODE_H 35
00875 #define SCANCODE_J 36
00876 #define SCANCODE_K 37
00877 #define SCANCODE_L 38
00878 #define SCANCODE_SEMICOLON 39
00879 #define SCANCODE_APOSTROPHE 40
00880 #define SCANCODE_GRAVE 41
00881
00882 #define SCANCODE_LEFTSHIFT 42
00883 #define SCANCODE_BACKSLASH 43
00884
00885 #define SCANCODE_Z 44
00886 #define SCANCODE_X 45
00887 #define SCANCODE_C 46
00888 #define SCANCODE_V 47
00889 #define SCANCODE_B 48
00890 #define SCANCODE_N 49
00891 #define SCANCODE_M 50
00892 #define SCANCODE_COMMA 51
00893 #define SCANCODE_PERIOD 52
00894 #define SCANCODE_SLASH 53
00895
00896 #define SCANCODE_RIGHTSHIFT 54
00897 #define SCANCODE_KEYPADMULTIPLY 55
00898
00899 #define SCANCODE_LEFTALT 56
00900 #define SCANCODE_SPACE 57
00901 #define SCANCODE_CAPSLOCK 58
00902
00903 #define SCANCODE_F1 59
00904 #define SCANCODE_F2 60
00905 #define SCANCODE_F3 61
00906 #define SCANCODE_F4 62
00907 #define SCANCODE_F5 63
00908 #define SCANCODE_F6 64
00909 #define SCANCODE_F7 65
00910 #define SCANCODE_F8 66
00911 #define SCANCODE_F9 67
00912 #define SCANCODE_F10 68
00913
00914 #define SCANCODE_NUMLOCK 69
00915 #define SCANCODE_SCROLLLOCK 70
00916
00917 #define SCANCODE_KEYPAD7 71
00918 #define SCANCODE_CURSORUPLEFT 71
00919 #define SCANCODE_KEYPAD8 72
00920 #define SCANCODE_CURSORUP 72
00921 #define SCANCODE_KEYPAD9 73
00922 #define SCANCODE_CURSORUPRIGHT 73
00923 #define SCANCODE_KEYPADMINUS 74
00924 #define SCANCODE_KEYPAD4 75
00925 #define SCANCODE_CURSORLEFT 75
00926 #define SCANCODE_KEYPAD5 76
00927 #define SCANCODE_KEYPAD6 77
00928 #define SCANCODE_CURSORRIGHT 77
00929 #define SCANCODE_KEYPADPLUS 78
00930 #define SCANCODE_KEYPAD1 79
00931 #define SCANCODE_CURSORDOWNLEFT 79
00932 #define SCANCODE_KEYPAD2 80
00933 #define SCANCODE_CURSORDOWN 80
00934 #define SCANCODE_KEYPAD3 81
00935 #define SCANCODE_CURSORDOWNRIGHT 81
00936 #define SCANCODE_KEYPAD0 82
00937 #define SCANCODE_KEYPADPERIOD 83
00938
00939 #define SCANCODE_LESS 86
00940
00941 #define SCANCODE_F11 87
00942 #define SCANCODE_F12 88
00943
00944 #define SCANCODE_KEYPADENTER 96
00945 #define SCANCODE_RIGHTCONTROL 97
00946 #define SCANCODE_CONTROL 97
00947 #define SCANCODE_KEYPADDIVIDE 98
00948 #define SCANCODE_PRINTSCREEN 99
00949 #define SCANCODE_RIGHTALT 100
00950 #define SCANCODE_BREAK 101
00951 #define SCANCODE_BREAK_ALTERNATIVE 119
00952
00953 #define SCANCODE_HOME 102
00954 #define SCANCODE_CURSORBLOCKUP 103
00955 #define SCANCODE_PAGEUP 104
00956 #define SCANCODE_CURSORBLOCKLEFT 105
00957 #define SCANCODE_CURSORBLOCKRIGHT 106
00958 #define SCANCODE_END 107
00959 #define SCANCODE_CURSORBLOCKDOWN 108
00960 #define SCANCODE_PAGEDOWN 109
00961 #define SCANCODE_INSERT 110
00962 #define SCANCODE_REMOVE 111
00963
00964 #define SCANCODE_PAUSE 119
00965
00966 #define SCANCODE_POWER 120
00967 #define SCANCODE_SLEEP 121
00968 #define SCANCODE_WAKEUP 122
00969
00970 #define SCANCODE_LEFTWIN 125
00971 #define SCANCODE_RIGHTWIN 126
00972 #define SCANCODE_MENU 127
00973
00974 #define SCANCODE_LEFTBUTTON 0x1000
00975 #define SCANCODE_RIGHTBUTTON 0x2000
00976 #define SCANCODE_MIDDLBUTTON 0x4000
00977
00998 #define KS_REPEATED 0x00000800
00999
01020 #define KS_CAPTURED 0x00000400
01021
01028 #define KS_IMEPOST 0x00000200
01029
01050 #define KS_CAPSLOCK 0x00000100
01051
01059 #define KS_NUMLOCK 0x00000080
01060
01068 #define KS_SCROLLLOCK 0x00000040
01069
01077 #define KS_LEFTCTRL 0x00000020
01078
01086 #define KS_RIGHTCTRL 0x00000010
01087
01095 #define KS_CTRL 0x00000030
01096
01104 #define KS_LEFTALT 0x00000008
01105
01113 #define KS_RIGHTALT 0x00000004
01114
01122 #define KS_ALT 0x0000000C
01123
01131 #define KS_LEFTSHIFT 0x00000002
01132
01140 #define KS_RIGHTSHIFT 0x00000001
01141
01149 #define KS_SHIFT 0x00000003
01150
01155 #define MASK_KS_SHIFTKEYS 0x00000FFF
01156
01164 #define KS_LEFTBUTTON 0x00001000
01165
01173 #define KS_RIGHTBUTTON 0x00002000
01174
01182 #define KS_MIDDLBUTTON 0x00004000
01183
01188 #define MASK_KS_BUTTONS 0x0000F000
01189
01200 #define ERR_OK 0
01201
01206 #define ERR_INV_HWND -1
01207
01212 #define ERR_QUEUE_FULL -2
01213
01218 #define ERR_INVALID_HANDLE -3
01219
01224 #define ERR_INVALID_HMENU -4
01225
01230 #define ERR_INVALID_POS -5
01231
01236 #define ERR_INVALID_ID -6
01237
01242 #define ERR_RES_ALLOCATION -7
01243
01248 #define ERR_CTRLCLASS_INVNAME -8
01249
01254 #define ERR_CTRLCLASS_INVLEN -9
01255
01260 #define ERR_CTRLCLASS_MEM -10
01261
01266 #define ERR_CTRLCLASS_INUSE -11
01267
01272 #define ERR_ALREADY_EXIST -12
01273
01278 #define ERR_NO_MATCH -13
01279
01284 #define ERR_BAD_OWNER -14
01285
01290 #define ERR_IME_TOOMUCHIMEWND -15
01291
01296 #define ERR_IME_NOSUCHIMEWND -16
01297
01302 #define ERR_IME_NOIMEWND -17
01303
01308 #define ERR_CONFIG_FILE -18
01309
01314 #define ERR_FILE_IO -19
01315
01320 #define ERR_GFX_ENGINE -20
01321
01326 #define ERR_INPUT_ENGINE -21
01327
01332 #define ERR_NO_ENGINE -22
01333
01338 #define ERR_INVALID_ARGS -23
01339
01340 #ifdef __CC_ARM
01341 # define ENOMEM 200
01342 # define EINVAL 201
01343 # define EBUSY 202
01344 # define EAGAIN 203
01345 # define ESRCH 204
01346 # define EDEADLK 205
01347 # define ENOTSUP 206
01348 # define ENOSYS 207
01349 #endif
01350
01361 #define TABLESIZE(table) (sizeof(table)/sizeof(table[0]))
01362
01363
01368 #ifndef MAX
01369 #define MAX(x, y) (((x) > (y))?(x):(y))
01370 #endif
01371
01375 #ifndef MIN
01376 #define MIN(x, y) (((x) < (y))?(x):(y))
01377 #endif
01378
01382 #ifndef ABS
01383 #define ABS(x) (((x)<0) ? -(x) : (x))
01384 #endif
01385
01386
01387 #ifndef __NOUNIX__
01388 #include <dirent.h>
01389 #endif
01390
01391 #ifndef PATH_MAX
01392 #ifndef __VXWORKS__
01393 #define PATH_MAX 256
01394 #endif
01395 #endif
01396
01397 #ifndef NAME_MAX
01398 #ifndef __VXWORKS__
01399 #define NAME_MAX 64
01400 #endif
01401 #endif
01402
01403
01409 #define MAX_PATH PATH_MAX
01410
01415 #define MAX_NAME NAME_MAX
01416
01421 #ifdef __cplusplus
01422 extern "C" {
01423 #endif
01424
01425 #if defined (__THREADX__) && defined (__TARGET_VFANVIL__)
01426 #include "fx_api.h"
01427 #include "tx_api.h"
01428 #include "os_type.h"
01429 #include "os_file_api.h"
01430
01431 #define fopen tp_fopen
01432 #define fclose tp_fclose
01433 #define fwrite tp_fwrite
01434 #define fread tp_fread
01435 #define fseek tp_fseek
01436 #define feof tp_feof
01437
01438
01439 #undef assert
01440 #define _HAVE_ASSERT 1
01441
01442 #define assert(e) do { \
01443 e; \
01444 } while(0);
01445
01446 #undef stdin
01447 #undef stdout
01448 #undef stderr
01449
01450 #define stdin ((FILE*)0)
01451 #define stdout ((FILE*)1)
01452 #define stderr ((FILE*)2)
01453 void Comm_Lock_Screen (void);
01454 void Comm_Unlock_Screen (void);
01455
01456 #endif
01457
01458 #ifdef __UCOSII__
01459
01460
01461 #undef HAVE_STRDUP
01462 #define strdup own_strdup
01463
01464
01465 int minigui_entry (int argc, const char* argv[]);
01466 int ucos2_posix_pthread_init (void);
01467 int ucos2_malloc_init (void);
01468
01469 #endif
01470
01471 #ifndef HAVE_STRDUP
01472 MG_EXPORT char *strdup(const char *s);
01473 #endif
01474
01475 #ifndef HAVE_STRCASECMP
01476 MG_EXPORT int strcasecmp(const char *s1, const char *s2);
01477 #endif
01478
01479 #ifdef __cplusplus
01480 };
01481 #endif
01482
01483 #ifdef _USE_OWN_MALLOC
01484
01485 #define USE_DL_PREFIX
01486
01487 #include "own_malloc.h"
01488
01489
01490 #define calloc dlcalloc
01491 #define free dlfree
01492 #define malloc dlmalloc
01493 #define memalign dlmemalign
01494 #define realloc dlrealloc
01495 #define valloc dlvalloc
01496
01497 #endif
01498
01499
01500 #if defined(__CC_ARM)
01501 # undef HAVE_ALLOCA
01502 # undef HAVE_ALLOCA_H
01503 #endif
01504
01505 #ifdef HAVE_ALLOCA_H
01506 # include <alloca.h>
01507 # define ALLOCATE_LOCAL(size) alloca((int)(size))
01508 # define DEALLOCATE_LOCAL(ptr)
01509 #else
01510 # define ALLOCATE_LOCAL(size) malloc((int)(size))
01511 # define DEALLOCATE_LOCAL(ptr) free(ptr)
01512 #endif
01513
01514 #ifdef _USE_OWN_STDIO
01515
01516 #if defined (__UCOSII__) || defined (__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS__) || defined (__PSOS__)
01517 # undef _PRINTF_FLOATING_POINT
01518 # undef _SCANF_FLOATING_POINT
01519 #else
01520 # ifdef HAVE_MATH_H
01521 # define _PRINTF_FLOATING_POINT 1
01522 # define _SCANF_FLOATING_POINT 1
01523 # endif
01524 #endif
01525
01526 #undef _I18N_MB_REQUIRED
01527
01528 #if defined(__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (__PSOS__)
01529 #define _USE_OWN_SNPRINTF
01530 #define _USE_OWN_VSNPRINTF
01531 #define _USE_OWN_VFNPRINTF
01532 #else
01533 #define _USE_OWN_PRINTF
01534 #define _USE_OWN_FPRINTF
01535 #define _USE_OWN_SPRINTF
01536 #define _USE_FNPRINTF
01537 #define _USE_OWN_SNPRINTF
01538 #define _USE_OWN_VPRINTF
01539 #define _USE_OWN_VFPRINTF
01540 #define _USE_OWN_VSPRINTF
01541 #define _USE_OWN_VFNPRINTF
01542 #define _USE_OWN_VSNPRINTF
01543 #define _USE_OWN_SCANF
01544 #define _USE_OWN_FSCANF
01545 #define _USE_OWN_SSCANF
01546 #define _USE_OWN_VSCANF
01547 #define _USE_OWN_VFSCANF
01548 #define _USE_OWN_VSSCANF
01549 #endif
01550
01551 #include "own_stdio.h"
01552
01553
01554 #ifdef _USE_OWN_PRINTF
01555 #define printf own_printf
01556 #endif
01557
01558 #ifdef _USE_OWN_FPRINTF
01559 #define fprintf own_fprintf
01560 #endif
01561
01562 #ifdef _USE_OWN_SPRINTF
01563 #define sprintf own_sprintf
01564 #endif
01565
01566 #ifdef _USE_FNPRINTF
01567 #define fnprintf own_fnprintf
01568 #endif
01569
01570 #ifdef _USE_OWN_SNPRINTF
01571 #define snprintf own_snprintf
01572 #endif
01573
01574 #ifdef _USE_OWN_VPRINTF
01575 #define vprintf own_vprintf
01576 #endif
01577
01578 #ifdef _USE_OWN_VFPRINTF
01579 #define vfprintf own_vfprintf
01580 #endif
01581
01582 #ifdef _USE_OWN_VSPRINTF
01583 #define vsprintf own_vsprintf
01584 #endif
01585
01586 #ifdef _USE_OWN_VFNPRINTF
01587 #define vfnprintf own_vfnprintf
01588 #endif
01589
01590 #ifdef _USE_OWN_VSNPRINTF
01591 #define vsnprintf own_vsnprintf
01592 #endif
01593
01594 #ifdef _USE_OWN_SCANF
01595 #define scanf own_scanf
01596 #endif
01597
01598 #ifdef _USE_OWN_FSCANF
01599 #define fscanf own_fscanf
01600 #endif
01601
01602 #ifdef _USE_OWN_SSCANF
01603 #define sscanf own_sscanf
01604 #endif
01605
01606 #ifdef _USE_OWN_VSCANF
01607 #define vscanf own_vscanf
01608 #endif
01609
01610 #ifdef _USE_OWN_VFSCANF
01611 #define vfscanf own_vfscanf
01612 #endif
01613
01614 #ifdef _USE_OWN_VSSCANF
01615 #define vsscanf own_vsscanf
01616 #endif
01617
01618 #endif
01619
01620 #if defined(__GNUC__)
01621 #ifdef _DEBUG_MSG
01622 # define _MG_PRINTF(fmt...) fprintf (stderr, fmt)
01623 #else
01624 # define _MG_PRINTF(fmt...)
01625 #endif
01626 #else
01627 static inline void _MG_PRINTF(const char* fmt, ...)
01628 {
01629 #ifdef _DEBUG_MSG
01630 va_list ap;
01631 va_start(ap, fmt);
01632 vfprintf(stderr, fmt, ap);
01633 fprintf(stderr, "\n");
01634 va_end(ap);
01635 #endif
01636 }
01637 #endif
01638
01639
01640 #ifndef _LITE_VERSION
01641
01642 #if defined(_USE_OWN_PTHREAD) && defined(__VXWORKS__)
01643
01644 #define pthread_create vxworks_pthread_create
01645 #define pthread_self vxworks_pthread_self
01646 #define pthread_equal vxworks_pthread_equal
01647 #define pthread_exit vxworks_pthread_exit
01648 #define pthread_join vxworks_pthread_join
01649 #define pthread_detach vxworks_pthread_detach
01650 #define pthread_cancel vxworks_pthread_cancel
01651 #define pthread_once vxworks_pthread_once
01652 #define pthread_key_create vxworks_pthread_key_create
01653 #define pthread_key_delete vxworks_pthread_key_delete
01654 #define pthread_setspecific vxworks_pthread_setspecific
01655 #define pthread_getspecific vxworks_pthread_getspecific
01656 #define pthread_setcancelstate vxworks_pthread_setcancelstate
01657 #define pthread_setcanceltype vxworks_pthread_setcanceltype
01658 #define pthread_testcancel vxworks_pthread_testcancel
01659
01660 #define pthread_attr_init vxworks_pthread_attr_init
01661 #define pthread_attr_destroy vxworks_pthread_attr_destroy
01662 #define pthread_attr_setdetachstate vxworks_pthread_attr_setdetachstate
01663 #define pthread_attr_getdetachstate vxworks_pthread_attr_getdetachstate
01664 #define pthread_attr_setscope vxworks_pthread_attr_setscope
01665 #define pthread_attr_getscope vxworks_pthread_attr_getscope
01666 #define pthread_attr_setinheritsched vxworks_pthread_attr_setinheritsched
01667 #define pthread_attr_getinheritsched vxworks_pthread_attr_getinheritsched
01668 #define pthread_attr_setschedpolicy vxworks_pthread_attr_setschedpolicy
01669 #define pthread_attr_getschedpolicy vxworks_pthread_attr_getschedpolicy
01670 #define pthread_attr_setschedparam vxworks_pthread_attr_setschedparam
01671 #define pthread_attr_getschedparam vxworks_pthread_attr_getschedparam
01672 #define pthread_attr_setstackaddr vxworks_pthread_attr_setstackaddr
01673 #define pthread_attr_getstackaddr vxworks_pthread_attr_getstackaddr
01674 #define pthread_attr_setstacksize vxworks_pthread_attr_setstacksize
01675 #define pthread_attr_getstacksize vxworks_pthread_attr_getstacksize
01676 #define pthread_setschedparam vxworks_pthread_setschedparam
01677 #define pthread_getschedparam vxworks_pthread_getschedparam
01678
01679 #define pthread_mutex_init vxworks_pthread_mutex_init
01680 #define pthread_mutex_destroy vxworks_pthread_mutex_destroy
01681 #define pthread_mutex_lock vxworks_pthread_mutex_lock
01682 #define pthread_mutex_unlock vxworks_pthread_mutex_unlock
01683 #define pthread_mutex_trylock vxworks_pthread_mutex_trylock
01684 #define pthread_mutexattr_init vxworks_pthread_mutexattr_init
01685 #define pthread_mutexattr_destroy vxworks_pthread_mutexattr_destroy
01686 #define pthread_mutexattr_setpriorityinherit vxworks_pthread_mutexattr_setpriorityinherit
01687 #define pthread_mutexattr_getpriorityinherit vxworks_pthread_mutexattr_getpriorityinherit
01688
01689 #endif
01690 #if defined(_USE_OWN_PTHREAD) && defined(__MINIGUI_LIB__)
01691
01692 #if __UCOSII__
01693 #include "ucos2_pthread.h"
01694 #include "ucos2_semaphore.h"
01695 #elif __THREADX__
01696 #include "threadx_pthread.h"
01697 #include "threadx_semaphore.h"
01698 #elif __NUCLEUS__
01699 #include "nucleus_pthread.h"
01700 #include "nucleus_semaphore.h"
01701 #elif __VXWORKS__
01702 #include "vxworks_pthread.h"
01703 #include "semaphore.h"
01704 #elif __OSE__
01705 #include "pthread.h"
01706 #include "ose_semaphore.h"
01707 #else
01708 #error No own pthread implementation for this OS!
01709 #endif
01710
01711 #else
01712
01713 #if defined(_USE_OWN_PTHREAD) && defined(__VXWORKS__)
01714 #include <vxworks_pthread.h>
01715 #else
01716 #include <pthread.h>
01717 #endif
01718 #include <semaphore.h>
01719
01720 #endif
01721
01722
01723 #endif
01724
01725
01726 #ifdef __DARWIN__
01727
01728 #define _USE_SEM_ON_SYSVIPC 1
01729
01730 #endif
01731
01732 #if defined (_USE_MUTEX_ON_SYSVIPC) || defined (_USE_SEM_ON_SYSVIPC)
01733
01734 int _sysvipc_mutex_sem_init (void);
01735 int _sysvipc_mutex_sem_term (void);
01736
01737 #endif
01738
01739 #ifdef _USE_MUTEX_ON_SYSVIPC
01740
01741 #define pthread_mutex_t _sysvipc_pthread_mutex_t
01742 #define pthread_mutexattr_t _sysvipc_pthread_mutexattr_t
01743
01744 #define pthread_mutexattr_init _sysvipc_pthread_mutexattr_init
01745 #define pthread_mutexattr_destroy _sysvipc_pthread_mutexattr_destroy
01746 #define pthread_mutexattr_settype _sysvipc_pthread_mutexattr_settype
01747 #define pthread_mutexattr_gettype _sysvipc_pthread_mutexattr_gettype
01748
01749 #define pthread_init _sysvipc_pthread_init
01750 #define pthread_mutex_init _sysvipc_pthread_mutex_init
01751 #define pthread_mutex_destroy _sysvipc_pthread_mutex_destroy
01752 #define pthread_mutex_lock _sysvipc_pthread_mutex_lock
01753 #define pthread_mutex_trylock _sysvipc_pthread_mutex_trylock
01754 #define pthread_mutex_unlock _sysvipc_pthread_mutex_unlock
01755
01756 typedef struct
01757 {
01758 int kind;
01759 int semid;
01760 int sem_num;
01761 int locked_times;
01762 } pthread_mutex_t;
01763
01764 #define SYSVIPC_PTHREAD_MUTEX_FAST_NP 0
01765 #define SYSVIPC_PTHREAD_MUTEX_RECURSIVE_NP 1
01766 #define SYSVIPC_PTHREAD_MUTEX_ERRORCHECK_NP 2
01767
01768 typedef struct
01769 {
01770 int kind;
01771 } pthread_mutexattr_t;
01772
01773 int pthread_mutexattr_init (pthread_mutexattr_t *attr);
01774 int pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
01775 int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type);
01776 int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int* type);
01777
01778 int pthread_mutex_init (pthread_mutex_t *mutex,
01779 const pthread_mutexattr_t *mutex_attr);
01780
01781 int pthread_mutex_destroy (pthread_mutex_t *mutex);
01782
01783 int pthread_mutex_lock (pthread_mutex_t *mutex);
01784 int pthread_mutex_trylock (pthread_mutex_t *mutex);
01785 int pthread_mutex_unlock (pthread_mutex_t *mutex);
01786
01787 #endif
01788
01789 #ifdef _USE_SEM_ON_SYSVIPC
01790
01791 #define sem_t _sysvipc_sem_t
01792
01793 #define sem_init _sysvipc_sem_init
01794 #define sem_destroy _sysvipc_sem_destroy
01795 #define sem_wait _sysvipc_sem_wait
01796 #define sem_trywait _sysvipc_sem_trywait
01797 #define sem_post _sysvipc_sem_post
01798 #define sem_getvalue _sysvipc_sem_getvalue
01799
01800 #define SYSVIPC_SEM_VALUE_MAX USHRT_MAX
01801
01802
01803
01804
01805
01806 typedef struct
01807 {
01808 int semid;
01809 int sem_num;
01810 } sem_t;
01811
01812 int sem_init (sem_t *sem, int pshared, unsigned int value);
01813 int sem_destroy (sem_t *sem);
01814 int sem_wait (sem_t *sem);
01815 int sem_trywait (sem_t *sem);
01816 int sem_post (sem_t *sem);
01817 int sem_getvalue (sem_t *sem, int *sval);
01818
01819 #endif
01820
01821 #endif
01822