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