MiniGUI API Reference (MiniGUI-Processes)  v4.0.7
A mature and proven cross-platform GUI system for embedded and smart IoT devices
common.h
Go to the documentation of this file.
1 //
3 // IMPORTANT NOTICE
4 //
5 // The following open source license statement does not apply to any
6 // entity in the Exception List published by FMSoft.
7 //
8 // For more information, please visit:
9 //
10 // https://www.fmsoft.cn/exception-list
11 //
13 
58 /*
59  * $Id: common.h 13674 2010-12-06 06:45:01Z wanzheng $
60  *
61  * MiniGUI for Linux/uClinux, eCos, uC/OS-II, VxWorks,
62  * pSOS, ThreadX, NuCleus, OSE, and Win32.
63  *
64  * The definitions of some data types and byte order macros
65  * borrowed from LGPL'ed SDL by Sam Lantinga.
66  *
67  * Fix point math routines come from Allegro (a gift software)
68  * by Shawn Hargreaves and others.
69  */
70 
71 #ifndef _MGUI_COMMON_H
72 
73 #define _MGUI_COMMON_H
74 
75 #ifndef MINIGUI_MAJOR_VERSION
76 # undef PACKAGE
77 # undef VERSION
78 # undef PACKAGE_BUGREPORT
79 # undef PACKAGE_NAME
80 # undef PACKAGE_STRING
81 # undef PACKAGE_TARNAME
82 # undef PACKAGE_VERSION
83 # ifdef __MINIGUI_LIB__
84 # ifdef _FOR_DATANG
85 # ifdef WIN32
86 # include <config-win32/mgconfig.h>
87 # elif defined (__THREADX__)
88 # include "config-threadx/mgconfig.h"
89 # elif defined (__NUCLEUS__)
90 # include "config-nucleus/mgconfig.h"
91 # endif
92 # else
93 # if defined(__CMAKE_PROJECT__) || defined(WIN32)
94 # include "mgconfig.h"
95 # else
96 # include "../mgconfig.h"
97 # endif
98 # endif
99 # else
100 # include "mgconfig.h"
101 # endif
102 #endif
103 
104 #include <stdio.h>
105 #include <stdlib.h>
106 #include <string.h>
107 #include <stdint.h>
108 #include <stdarg.h>
109 #include <errno.h>
110 #include <assert.h>
111 
132 #define _VERSION_CODE(major, minor, micro) (((major)<<16) | ((minor)<<8) | (micro))
133 
140 #define _MINIGUI_VERSION_CODE \
141  ((MINIGUI_MAJOR_VERSION << 16) | (MINIGUI_MINOR_VERSION << 8) | MINIGUI_MICRO_VERSION)
142 
154 typedef unsigned char Uint8;
159 typedef signed char Sint8;
164 typedef unsigned short Uint16;
169 typedef signed short Sint16;
174 typedef unsigned int Uint32;
179 typedef signed int Sint32;
180 
181 /* Figure out how to support 64-bit datatypes */
182 #if !defined(__STRICT_ANSI__)
183 # if defined(__GNUC__)
184 # define MGUI_HAS_64BIT_TYPE long long
185 # endif
186 # if defined(__CC_ARM)
187 # define MGUI_HAS_64BIT_TYPE long long
188 # endif
189 # if defined(_MSC_VER)
190 # define MGUI_HAS_64BIT_TYPE __int64
191 # endif
192 #endif /* !__STRICT_ANSI__ */
193 
194 /* The 64-bit datatype isn't supported on all platforms */
195 #ifdef MGUI_HAS_64BIT_TYPE
196 
203 typedef unsigned MGUI_HAS_64BIT_TYPE Uint64;
210 typedef signed MGUI_HAS_64BIT_TYPE Sint64;
211 #else
212 /* This is really just a hack to prevent the compiler from complaining */
213 typedef struct {
214  Uint32 hi;
215  Uint32 lo;
216 } Uint64, Sint64;
217 #endif
218 
219 /* Make sure the types really have the right sizes */
220 #define MGUI_COMPILE_TIME_ASSERT(name, x) \
221  typedef int MGUI_dummy_ ## name[(x) * 2 - 1]
222 
223 MGUI_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
224 MGUI_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
225 MGUI_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
226 MGUI_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
227 MGUI_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
228 MGUI_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
229 MGUI_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
230 MGUI_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
231 
232 #undef MGUI_COMPILE_TIME_ASSERT
233 
236 /* Here we provide MG_GNUC_EXTENSION as an alias for __extension__,
237  * where this is valid. This allows for warningless compilation of
238  * "long long" types even in the presence of '-ansi -pedantic'.
239  */
240 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
241 #define MG_GNUC_EXTENSION __extension__
242 #else
243 #define MG_GNUC_EXTENSION
244 #endif
245 
246 /*
247  * The MG_LIKELY and MG_UNLIKELY macros let the programmer give hints to
248  * the compiler about the expected result of an expression. Some compilers
249  * can use this information for optimizations.
250  */
251 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
252 #define _MG_BOOLEAN_EXPR(expr) \
253  MG_GNUC_EXTENSION ({ \
254  int _g_boolean_var_; \
255  if (expr) \
256  _g_boolean_var_ = 1; \
257  else \
258  _g_boolean_var_ = 0; \
259  _g_boolean_var_; \
260 })
261 #define MG_LIKELY(expr) (__builtin_expect (_MG_BOOLEAN_EXPR(expr), 1))
262 #define MG_UNLIKELY(expr) (__builtin_expect (_MG_BOOLEAN_EXPR(expr), 0))
263 #else
264 #define MG_LIKELY(expr) (expr)
265 #define MG_UNLIKELY(expr) (expr)
266 #endif
267 
277 #define MGUI_LIL_ENDIAN 1234
278 
282 #define MGUI_BIG_ENDIAN 4321
283 
284 /* Pardon the mess, I'm trying to determine the endianness of this host.
285  * I'm doing it by preprocessor defines rather than some sort of configure
286  * script so that application code can use this too. The "right" way would
287  * be to dynamically generate this file on install, but that's a lot of work.
288  */
289 
307 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || defined(__amd64) || \
308  (defined(__alpha__) || defined(__alpha)) || \
309  defined(__arm__) || defined(__aarch64__) || \
310  defined(__riscv) || \
311  (defined(__CC_ARM) && !defined(__BIG_ENDIAN)) || \
312  (defined(__mips__) && defined(__MIPSEL__)) || \
313  defined(__LITTLE_ENDIAN__) || \
314  defined(WIN32)
315 # define MGUI_BYTEORDER MGUI_LIL_ENDIAN
316 #else
317 # define MGUI_BYTEORDER MGUI_BIG_ENDIAN
318 #endif
319 
332 typedef void *PVOID;
333 
338 #ifndef BOOL
339 typedef int BOOL;
340 #endif
341 
346 #ifndef FALSE
347  #define FALSE 0
348 #endif
349 
353 #ifndef TRUE
354  #define TRUE 1
355 #endif
356 
361 #ifndef NULL
362 # ifdef __cplusplus
363 # define NULL (0)
364 # else
365 # define NULL ((void *)0)
366 # endif
367 #endif
368 
373 #define INV_PTR ((void *)-1)
374 
375 #define GUIAPI
376 
377 #if !defined(__NODLL__) && (defined (WIN32) || defined (__NUCLEUS_MNT__))
378 # if defined(__MINIGUI_LIB__)
379 # define MG_EXPORT __declspec(dllexport)
380 # else
381 # define MG_EXPORT __declspec(dllimport)
382 # endif
383 #else
384 # define MG_EXPORT
385 #endif
386 
398 typedef PVOID GHANDLE;
403 typedef GHANDLE HWND;
408 typedef GHANDLE HDC;
418 typedef GHANDLE HCURSOR;
423 typedef GHANDLE HICON;
428 typedef GHANDLE HMENU;
433 typedef GHANDLE HACCEL;
438 typedef GHANDLE HDLG;
443 typedef GHANDLE HHOOK;
444 
456 typedef unsigned char BYTE;
457 
462 typedef signed char SBYTE;
463 
472 #if defined(_WIN64)
473 # define SIZEOF_PTR 8
474 # define SIZEOF_HPTR 4
475 #elif defined(__LP64__)
476 # define SIZEOF_PTR 8
477 # define SIZEOF_HPTR 4
478 #else
479 # define SIZEOF_PTR 4
480 # define SIZEOF_HPTR 2
481 #endif
482 
483 #if SIZEOF_PTR == 8
484 # define NR_BITS_BYTE (8)
485 # define NR_BITS_WORD (32)
486 # define NR_BITS_DWORD (64)
487 
488 # define BITMASK_BYTE (0xFF)
489 # define BITMASK_WORD (0xFFFFFFFF)
490 # define BITMASK_DWORD (0xFFFFFFFFFFFFFFFF)
491 
492 # define INT_PTR_MIN (-9223372036854775807L-1)
493 # define INT_PTR_MAX (9223372036854775807L)
494 # define UINT_PTR_MAX (18446744073709551615UL)
495 #else
496 # define NR_BITS_BYTE (8)
497 # define NR_BITS_WORD (16)
498 # define NR_BITS_DWORD (32)
499 
500 # define BITMASK_BYTE (0xFF)
501 # define BITMASK_WORD (0xFFFF)
502 # define BITMASK_DWORD (0xFFFFFFFF)
503 
504 # define INT_PTR_MIN (-2147483647-1)
505 # define INT_PTR_MAX (2147483647)
506 # define UINT_PTR_MAX (4294967295U)
507 #endif
508 
513 #if defined(_WIN64)
514 typedef unsigned int WORD_HPTR;
515 #elif defined(__LP64__)
516 typedef unsigned int WORD_HPTR;
517 #else
518 typedef unsigned short WORD_HPTR;
519 #endif
520 
525 #if defined(_WIN64)
526 typedef signed int SWORD_HPTR;
527 #elif defined(__LP64__)
528 typedef signed int SWORD_HPTR;
529 #else
530 typedef signed short SWORD_HPTR;
531 #endif
532 
537 typedef WORD_HPTR WORD;
538 
544 
549 typedef unsigned short WORD16;
550 
555 typedef signed short SWORD16;
556 
561 #if defined(_WIN64)
562 typedef __int64 LONG_PTR;
563 #elif defined(__LP64__)
564 typedef long LONG_PTR;
565 #else
566 typedef long LONG_PTR;
567 #endif
568 
573 typedef LONG_PTR LINT;
574 
580 
588 #if defined(_WIN64)
589 typedef unsigned __int64 DWORD_PTR;
590 #elif defined(__LP64__)
591 typedef unsigned long DWORD_PTR;
592 #else
593 typedef unsigned long DWORD_PTR;
594 #endif
595 
600 typedef DWORD_PTR DWORD;
601 
606 typedef unsigned int DWORD32;
607 
615 #if defined(_WIN64)
616 typedef signed __int64 SDWORD_PTR;
617 #elif defined(__LP64__)
618 typedef signed long SDWORD_PTR;
619 #else
620 typedef signed long SDWORD_PTR;
621 #endif
622 
628 
633 typedef signed int SDWORD32;
634 
635 #if SIZEOF_PTR == 8
636 typedef unsigned short QDWORD;
637 #define QDWORD_SHIFT 16
638 #else
639 typedef unsigned char QDWORD;
640 #define QDWORD_SHIFT 8
641 #endif
642 
643 #define MAKEDWORD(q1, q2, q3, q4) \
644  ((DWORD)( \
645  (((DWORD)(QDWORD)(q1))) | \
646  (((DWORD)((QDWORD)(q2))) << QDWORD_SHIFT) | \
647  (((DWORD)((QDWORD)(q3))) << (QDWORD_SHIFT*2)) | \
648  (((DWORD)((QDWORD)(q4))) << (QDWORD_SHIFT*3)) \
649  ))
650 
651 #define FIRST_QDWORD(dw) ((QDWORD)(((DWORD)(dw))))
652 #define SECOND_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> QDWORD_SHIFT)))
653 #define THIRD_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> (QDWORD_SHIFT*2))))
654 #define FOURTH_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> (QDWORD_SHIFT*3))))
655 
660 typedef unsigned int UINT;
661 
666 #if defined(_WIN64)
667 typedef __int64 INT_PTR;
668 #elif defined(__LP64__)
669 typedef long INT_PTR;
670 #else
671 typedef int INT_PTR;
672 #endif
673 
678 #if defined(_WIN64)
679 typedef unsigned __int64 UINT_PTR;
680 #elif defined(__LP64__)
681 typedef unsigned long UINT_PTR;
682 #else
683 typedef unsigned long UINT_PTR;
684 #endif
685 
690 typedef long LONG;
691 
696 typedef unsigned long ULONG;
697 
702 typedef UINT_PTR WPARAM;
703 
708 typedef UINT_PTR LPARAM;
709 
716 #define LOBYTE(w) ((BYTE)(w))
717 
724 #define HIBYTE(w) ((BYTE)(((WORD)(w) >> NR_BITS_BYTE) & BITMASK_BYTE))
725 
732 #define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << NR_BITS_BYTE)))
733 
740 #define MAKEWORD16(low, high) ((WORD16)(((BYTE)(low)) | (((WORD16)((BYTE)(high))) << 8)))
741 
748 #define MAKEDWORD32(first, second, third, fourth) \
749  ((DWORD32)( \
750  ((BYTE)(first)) | \
751  (((DWORD32)((BYTE)(second))) << 8) | \
752  (((DWORD32)((BYTE)(third))) << 16) | \
753  (((DWORD32)((BYTE)(fourth))) << 24) \
754  ))
755 
762 #define MAKEWPARAM(first, second, third, fourth) \
763  ((WPARAM)( \
764  ((BYTE)(first)) | \
765  (((WPARAM)((BYTE)(second))) << 8) | \
766  (((WPARAM)((BYTE)(third))) << 16) | \
767  (((WPARAM)((BYTE)(fourth))) << 24) \
768  ))
769 
776 #define FIRSTBYTE(w) ((BYTE)(w))
777 
784 #define SECONDBYTE(w) ((BYTE)(((DWORD32)(w)) >> 8))
785 
792 #define THIRDBYTE(w) ((BYTE)(((DWORD32)(w)) >> 16))
793 
800 #define FOURTHBYTE(w) ((BYTE)(((DWORD32)(w)) >> 24))
801 
808 #define LOWORD(l) ((WORD)(DWORD)(l))
809 
815 #define HIWORD(l) ((WORD)((((DWORD)(l)) >> NR_BITS_WORD) & BITMASK_WORD))
816 
823 #define LOSWORD(l) ((SWORD)(DWORD)(l))
824 
830 #define HISWORD(l) ((SWORD)((((DWORD)(l)) >> NR_BITS_WORD) & BITMASK_WORD))
831 
837 #define MAKELONG32(low, high) ((DWORD32)(((WORD16)(low)) | (((DWORD32)((WORD16)(high))) << 16)))
838 
844 #define MAKELONG(low, high) ((DWORD)(((WORD)(low)) | (((DWORD)((WORD)(high))) << NR_BITS_WORD)))
845 
851 
860 #define GetRValue(rgba) ((BYTE)(rgba))
861 
869 #define GetGValue(rgba) ((BYTE)(((DWORD32)(rgba)) >> 8))
870 
878 #define GetBValue(rgba) ((BYTE)((DWORD32)(rgba) >> 16))
879 
887 #define GetAValue(rgba) ((BYTE)((DWORD32)(rgba) >> 24))
888 
899 #define MakeRGBA(r, g, b, a) \
900  (((DWORD32)((BYTE)(r))) \
901  | ((DWORD32)((BYTE)(g)) << 8) \
902  | ((DWORD32)((BYTE)(b)) << 16) \
903  | ((DWORD32)((BYTE)(a)) << 24))
904 
915 #define MakeRGB(r, g, b) MakeRGBA((r), (g), (b), 255)
916 
926 typedef struct _RECT {
930  int left;
934  int top;
938  int right;
942  int bottom;
943 } RECT;
950 typedef RECT* PRECT;
951 
956 typedef struct _POINT
957 {
961  int x;
965  int y;
966 } POINT;
973 typedef POINT* PPOINT;
974 
979 typedef struct _SIZE
980 {
984  int cx;
988  int cy;
989 } SIZE;
996 typedef SIZE* PSIZE;
997 
1002 typedef struct _RGB
1003 {
1020 } RGB;
1021 
1028 typedef RGB* PRGB;
1029 
1050 
1065 
1080 
1085 typedef signed int gal_sint;
1090 typedef unsigned int gal_uint;
1091 
1102 
1107 typedef long fixed;
1108 
1113 typedef struct _GAL_Color
1114 {
1131 } GAL_Color;
1132 
1137 typedef struct _GAL_Palette
1138 {
1142  int ncolors;
1147 } GAL_Palette;
1148 
1153 typedef struct _GAL_Rect {
1157  Sint32 x, y;
1161  Sint32 w, h;
1162 } GAL_Rect;
1163 
1186 #define MGUI_NR_KEYS 255
1187 
1200 #ifndef NR_KEYS
1201 #define NR_KEYS 250
1202 #endif
1203 
1220 #define SCANCODE_USER (NR_KEYS + 1)
1221 
1222 #define SCANCODE_RESERVED 0
1223 #define SCANCODE_ESCAPE 1
1224  #define SCANCODE_ESC SCANCODE_ESCAPE
1225 
1226 #define SCANCODE_1 2
1227 #define SCANCODE_2 3
1228 #define SCANCODE_3 4
1229 #define SCANCODE_4 5
1230 #define SCANCODE_5 6
1231 #define SCANCODE_6 7
1232 #define SCANCODE_7 8
1233 #define SCANCODE_8 9
1234 #define SCANCODE_9 10
1235 #define SCANCODE_0 11
1236 
1237 #define SCANCODE_MINUS 12
1238 #define SCANCODE_EQUAL 13
1239 
1240 #define SCANCODE_BACKSPACE 14
1241 #define SCANCODE_TAB 15
1242 
1243 #define SCANCODE_Q 16
1244 #define SCANCODE_W 17
1245 #define SCANCODE_E 18
1246 #define SCANCODE_R 19
1247 #define SCANCODE_T 20
1248 #define SCANCODE_Y 21
1249 #define SCANCODE_U 22
1250 #define SCANCODE_I 23
1251 #define SCANCODE_O 24
1252 #define SCANCODE_P 25
1253 #define SCANCODE_BRACKET_LEFT 26
1254  #define SCANCODE_LEFTBRACE SCANCODE_BRACKET_LEFT
1255 #define SCANCODE_BRACKET_RIGHT 27
1256  #define SCANCODE_RIGHTBRACE SCANCODE_BRACKET_RIGHT
1257 
1258 #define SCANCODE_ENTER 28
1259 
1260 #define SCANCODE_LEFTCONTROL 29
1261  #define SCANCODE_LEFTCTRL SCANCODE_LEFTCONTROL
1262 
1263 #define SCANCODE_A 30
1264 #define SCANCODE_S 31
1265 #define SCANCODE_D 32
1266 #define SCANCODE_F 33
1267 #define SCANCODE_G 34
1268 #define SCANCODE_H 35
1269 #define SCANCODE_J 36
1270 #define SCANCODE_K 37
1271 #define SCANCODE_L 38
1272 #define SCANCODE_SEMICOLON 39
1273 #define SCANCODE_APOSTROPHE 40
1274 #define SCANCODE_GRAVE 41
1275 #define SCANCODE_LEFTSHIFT 42
1276 #define SCANCODE_BACKSLASH 43
1277 
1278 #define SCANCODE_Z 44
1279 #define SCANCODE_X 45
1280 #define SCANCODE_C 46
1281 #define SCANCODE_V 47
1282 #define SCANCODE_B 48
1283 #define SCANCODE_N 49
1284 #define SCANCODE_M 50
1285 #define SCANCODE_COMMA 51
1286 #define SCANCODE_PERIOD 52
1287  #define SCANCODE_DOT SCANCODE_PERIOD
1288 #define SCANCODE_SLASH 53
1289 #define SCANCODE_RIGHTSHIFT 54
1290 #define SCANCODE_KEYPADMULTIPLY 55
1291  #define SCANCODE_KPASTERISK SCANCODE_KEYPADMULTIPLY
1292 #define SCANCODE_LEFTALT 56
1293 #define SCANCODE_SPACE 57
1294 #define SCANCODE_CAPSLOCK 58
1295 
1296 #define SCANCODE_F1 59
1297 #define SCANCODE_F2 60
1298 #define SCANCODE_F3 61
1299 #define SCANCODE_F4 62
1300 #define SCANCODE_F5 63
1301 #define SCANCODE_F6 64
1302 #define SCANCODE_F7 65
1303 #define SCANCODE_F8 66
1304 #define SCANCODE_F9 67
1305 #define SCANCODE_F10 68
1306 
1307 #define SCANCODE_NUMLOCK 69
1308 #define SCANCODE_SCROLLLOCK 70
1309 
1310 #define SCANCODE_KEYPAD7 71
1311  #define SCANCODE_KP7 SCANCODE_KEYPAD7
1312 #define SCANCODE_CURSORUPLEFT 71
1313 #define SCANCODE_KEYPAD8 72
1314  #define SCANCODE_KP8 SCANCODE_KEYPAD8
1315 #define SCANCODE_CURSORUP 72
1316 #define SCANCODE_KEYPAD9 73
1317  #define SCANCODE_KP9 SCANCODE_KEYPAD9
1318 #define SCANCODE_CURSORUPRIGHT 73
1319 #define SCANCODE_KEYPADMINUS 74
1320  #define SCANCODE_KPMINUS SCANCODE_KEYPADMINUS
1321 #define SCANCODE_KEYPAD4 75
1322  #define SCANCODE_KP4 SCANCODE_KEYPAD4
1323 #define SCANCODE_CURSORLEFT 75
1324 #define SCANCODE_KEYPAD5 76
1325  #define SCANCODE_KP5 SCANCODE_KEYPAD5
1326 #define SCANCODE_KEYPAD6 77
1327  #define SCANCODE_KP6 SCANCODE_KEYPAD6
1328 #define SCANCODE_CURSORRIGHT 77
1329 #define SCANCODE_KEYPADPLUS 78
1330  #define SCANCODE_KPPLUS SCANCODE_KEYPADPLUS
1331 #define SCANCODE_KEYPAD1 79
1332  #define SCANCODE_KP1 SCANCODE_KEYPAD1
1333 #define SCANCODE_CURSORDOWNLEFT 79
1334 #define SCANCODE_KEYPAD2 80
1335  #define SCANCODE_KP2 SCANCODE_KEYPAD2
1336 #define SCANCODE_CURSORDOWN 80
1337 #define SCANCODE_KEYPAD3 81
1338  #define SCANCODE_KP3 SCANCODE_KEYPAD3
1339 #define SCANCODE_CURSORDOWNRIGHT 81
1340 #define SCANCODE_KEYPAD0 82
1341  #define SCANCODE_KP0 SCANCODE_KEYPAD0
1342 #define SCANCODE_KEYPADPERIOD 83
1343  #define SCANCODE_KPDOT SCANCODE_KEYPADPERIOD
1344 
1345 #define SCANCODE_ZENKAKUHANKAKU 85
1346 
1347 #define SCANCODE_LESS 86
1348 #define SCANCODE_102ND SCANCODE_LESS
1349 
1350 #define SCANCODE_F11 87
1351 #define SCANCODE_F12 88
1352 
1353 #define SCANCODE_RO 89
1354 #define SCANCODE_KATAKANA 90
1355 #define SCANCODE_HIRAGANA 91
1356 #define SCANCODE_HENKAN 92
1357 #define SCANCODE_KATAKANAHIRAGANA 93
1358 #define SCANCODE_MUHENKAN 94
1359 #define SCANCODE_KPJPCOMMA 95
1360 
1361 #define SCANCODE_KEYPADENTER 96
1362  #define SCANCODE_KPENTER SCANCODE_KEYPADENTER
1363 #define SCANCODE_RIGHTCONTROL 97
1364  #define SCANCODE_RIGHTCTRL SCANCODE_RIGHTCONTROL
1365 #define SCANCODE_CONTROL 97
1366 #define SCANCODE_KEYPADDIVIDE 98
1367  #define SCANCODE_KPSLASH SCANCODE_KEYPADDIVIDE
1368 #define SCANCODE_PRINTSCREEN 99
1369  #define SCANCODE_SYSRQ SCANCODE_PRINTSCREEN
1370 #define SCANCODE_RIGHTALT 100
1371 #define SCANCODE_LINEFEED 101
1372 
1373 #define SCANCODE_HOME 102
1374 #define SCANCODE_CURSORBLOCKUP 103 /* Cursor key block */
1375  #define SCANCODE_UP SCANCODE_CURSORBLOCKUP
1376 #define SCANCODE_PAGEUP 104
1377 #define SCANCODE_CURSORBLOCKLEFT 105 /* Cursor key block */
1378  #define SCANCODE_LEFT SCANCODE_CURSORBLOCKLEFT
1379 #define SCANCODE_CURSORBLOCKRIGHT 106 /* Cursor key block */
1380  #define SCANCODE_RIGHT SCANCODE_CURSORBLOCKRIGHT
1381 #define SCANCODE_END 107
1382 #define SCANCODE_CURSORBLOCKDOWN 108 /* Cursor key block */
1383  #define SCANCODE_DOWN SCANCODE_CURSORBLOCKDOWN
1384 #define SCANCODE_PAGEDOWN 109
1385 #define SCANCODE_INSERT 110
1386 #define SCANCODE_REMOVE 111
1387  #define SCANCODE_DELETE SCANCODE_REMOVE
1388 
1389 #define SCANCODE_MACRO 112
1390 #define SCANCODE_MUTE 113
1391 #define SCANCODE_VOLUMEDOWN 114
1392 #define SCANCODE_VOLUMEUP 115
1393 #define SCANCODE_POWER 116 /* SC System Power Down */
1394 #define SCANCODE_KPEQUAL 117
1395 #define SCANCODE_KPPLUSMINUS 118
1396 #define SCANCODE_BREAK 119
1397  #define SCANCODE_BREAK_ALTERNATIVE SCANCODE_BREAK
1398  #define SCANCODE_PAUSE SCANCODE_BREAK
1399 
1400 #define SCANCODE_SCALE 120 /* AL Compiz Scale (Expose) */
1401 #define SCANCODE_KPCOMMA 121
1402 #define SCANCODE_HANGEUL 122
1403 #define SCANCODE_HANJA 123
1404 #define SCANCODE_YEN 124
1405 #define SCANCODE_LEFTWIN 125
1406  #define SCANCODE_LEFTMETA SCANCODE_LEFTWIN
1407 #define SCANCODE_RIGHTWIN 126
1408  #define SCANCODE_RIGHTMETA SCANCODE_RIGHTWIN
1409 #define SCANCODE_COMPOSE 127
1410 #define SCANCODE_STOP 128 /* AC Stop */
1411 #define SCANCODE_AGAIN 129
1412 #define SCANCODE_PROPS 130 /* AC Properties */
1413 #define SCANCODE_UNDO 131 /* AC Undo */
1414 #define SCANCODE_FRONT 132
1415 #define SCANCODE_COPY 133 /* AC Copy */
1416 #define SCANCODE_OPEN 134 /* AC Open */
1417 #define SCANCODE_PASTE 135 /* AC Paste */
1418 #define SCANCODE_FIND 136 /* AC Search */
1419 #define SCANCODE_CUT 137 /* AC Cut */
1420 #define SCANCODE_HELP 138 /* AL Integrated Help Center */
1421 #define SCANCODE_MENU 139 /* Menu (show menu) */
1422 #define SCANCODE_CALC 140 /* AL Calculator */
1423 #define SCANCODE_SETUP 141
1424 #define SCANCODE_SLEEP 142 /* SC System Sleep */
1425 #define SCANCODE_WAKEUP 143 /* System Wake Up */
1426 #define SCANCODE_FILE 144 /* AL Local Machine Browser */
1427 #define SCANCODE_SENDFILE 145
1428 #define SCANCODE_DELETEFILE 146
1429 #define SCANCODE_XFER 147
1430 #define SCANCODE_PROG1 148
1431 #define SCANCODE_PROG2 149
1432 #define SCANCODE_WWW 150 /* AL Internet Browser */
1433 #define SCANCODE_MSDOS 151
1434 #define SCANCODE_COFFEE 152 /* AL Terminal Lock/Screensaver */
1435  #define SCANCODE_SCREENLOCK SCANCODE_COFFEE
1436 #define SCANCODE_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */
1437  #define SCANCODE_DIRECTION SCANCODE_ROTATE_DISPLAY
1438 #define SCANCODE_CYCLEWINDOWS 154
1439 #define SCANCODE_MAIL 155
1440 #define SCANCODE_BOOKMARKS 156 /* AC Bookmarks */
1441 #define SCANCODE_COMPUTER 157
1442 #define SCANCODE_BACK 158 /* AC Back */
1443 #define SCANCODE_FORWARD 159 /* AC Forward */
1444 #define SCANCODE_CLOSECD 160
1445 #define SCANCODE_EJECTCD 161
1446 #define SCANCODE_EJECTCLOSECD 162
1447 #define SCANCODE_NEXTSONG 163
1448 #define SCANCODE_PLAYPAUSE 164
1449 #define SCANCODE_PREVIOUSSONG 165
1450 #define SCANCODE_STOPCD 166
1451 #define SCANCODE_RECORD 167
1452 #define SCANCODE_REWIND 168
1453 #define SCANCODE_PHONE 169 /* Media Select Telephone */
1454 #define SCANCODE_ISO 170
1455 #define SCANCODE_CONFIG 171 /* AL Consumer Control Configuration */
1456 #define SCANCODE_HOMEPAGE 172 /* AC Home */
1457 #define SCANCODE_REFRESH 173 /* AC Refresh */
1458 #define SCANCODE_EXIT 174 /* AC Exit */
1459 #define SCANCODE_MOVE 175
1460 #define SCANCODE_EDIT 176
1461 #define SCANCODE_SCROLLUP 177
1462 #define SCANCODE_SCROLLDOWN 178
1463 #define SCANCODE_KPLEFTPAREN 179
1464 #define SCANCODE_KPRIGHTPAREN 180
1465 #define SCANCODE_NEW 181 /* AC New */
1466 #define SCANCODE_REDO 182 /* AC Redo/Repeat */
1467 #define SCANCODE_F13 183
1468 #define SCANCODE_F14 184
1469 #define SCANCODE_F15 185
1470 #define SCANCODE_F16 186
1471 #define SCANCODE_F17 187
1472 #define SCANCODE_F18 188
1473 #define SCANCODE_F19 189
1474 #define SCANCODE_F20 190
1475 #define SCANCODE_F21 191
1476 #define SCANCODE_F22 192
1477 #define SCANCODE_F23 193
1478 #define SCANCODE_F24 194
1479 
1480 #define SCANCODE_PLAYCD 200
1481 #define SCANCODE_PAUSECD 201
1482 #define SCANCODE_PROG3 202
1483 #define SCANCODE_PROG4 203
1484 #define SCANCODE_DASHBOARD 204 /* AL Dashboard */
1485 #define SCANCODE_SUSPEND 205
1486 #define SCANCODE_CLOSE 206 /* AC Close */
1487 #define SCANCODE_PLAY 207
1488 #define SCANCODE_FASTFORWARD 208
1489 #define SCANCODE_BASSBOOST 209
1490 #define SCANCODE_PRINT 210 /* AC Print */
1491 #define SCANCODE_HP 211
1492 #define SCANCODE_CAMERA 212
1493 #define SCANCODE_SOUND 213
1494 #define SCANCODE_QUESTION 214
1495 #define SCANCODE_EMAIL 215
1496 #define SCANCODE_CHAT 216
1497 #define SCANCODE_SEARCH 217
1498 #define SCANCODE_CONNECT 218
1499 #define SCANCODE_FINANCE 219 /* AL Checkbook/Finance */
1500 #define SCANCODE_SPORT 220
1501 #define SCANCODE_SHOP 221
1502 #define SCANCODE_ALTERASE 222
1503 #define SCANCODE_CANCEL 223 /* AC Cancel */
1504 #define SCANCODE_BRIGHTNESSDOWN 224
1505 #define SCANCODE_BRIGHTNESSUP 225
1506 #define SCANCODE_MEDIA 226
1507 #define SCANCODE_SWITCHVIDEOMODE 227 /* Cycle between available video outputs (Monitor/LCD/TV-out/etc) */
1508 #define SCANCODE_KBDILLUMTOGGLE 228
1509 #define SCANCODE_KBDILLUMDOWN 229
1510 #define SCANCODE_KBDILLUMUP 230
1511 #define SCANCODE_SEND 231 /* AC Send */
1512 #define SCANCODE_REPLY 232 /* AC Reply */
1513 #define SCANCODE_FORWARDMAIL 233 /* AC Forward Msg */
1514 #define SCANCODE_SAVE 234 /* AC Save */
1515 #define SCANCODE_DOCUMENTS 235
1516 #define SCANCODE_BATTERY 236
1517 #define SCANCODE_BLUETOOTH 237
1518 #define SCANCODE_WLAN 238
1519 #define SCANCODE_UWB 239
1520 #define SCANCODE_UNKNOWN 240
1521 #define SCANCODE_VIDEO_NEXT 241 /* drive next video source */
1522 #define SCANCODE_VIDEO_PREV 242 /* drive previous video source */
1523 #define SCANCODE_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
1524 #define SCANCODE_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual brightness control is off, rely on ambient */
1525  #define SCANCODE_BRIGHTNESS_ZERO SCANCODE_BRIGHTNESS_AUTO
1526 #define SCANCODE_DISPLAY_OFF 245 /* display device to off state */
1527 #define SCANCODE_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */
1528  #define SCANCODE_WIMAX SCANCODE_WWAN
1529 #define SCANCODE_RFKILL 247 /* Key that controls all radios */
1530 #define SCANCODE_MICMUTE 248 /* Mute / unmute the microphone */
1531 
1532 #define SCANCODE_LEFTBUTTON 0x1000
1533 #define SCANCODE_RIGHTBUTTON 0x2000
1534 #define SCANCODE_MIDDLBUTTON 0x4000
1535 
1545 #define KS_LEFTMETA 0x00002000
1546 
1556 #define KS_RIGHTMETA 0x00001000
1557 
1567 #define KS_META 0x00003000
1568 
1589 #define KS_REPEATED 0x00000800
1590 
1611 #define KS_CAPTURED 0x00000400
1612 
1619 #define KS_IMEPOST 0x00000200
1620 
1641 #define KS_CAPSLOCK 0x00000100
1642 
1650 #define KS_NUMLOCK 0x00000080
1651 
1659 #define KS_SCROLLLOCK 0x00000040
1660 
1668 #define KS_LEFTCTRL 0x00000020
1669 
1677 #define KS_RIGHTCTRL 0x00000010
1678 
1686 #define KS_CTRL 0x00000030
1687 
1695 #define KS_LEFTALT 0x00000008
1696 
1704 #define KS_RIGHTALT 0x00000004
1705 
1713 #define KS_ALT 0x0000000C
1714 
1722 #define KS_LEFTSHIFT 0x00000002
1723 
1731 #define KS_RIGHTSHIFT 0x00000001
1732 
1740 #define KS_SHIFT 0x00000003
1741 
1746 #define MASK_KS_SHIFTKEYS 0x0000FFFF
1747 
1755 #define KS_LEFTBUTTON 0x00010000
1756 
1764 #define KS_RIGHTBUTTON 0x00020000
1765 
1773 #define KS_MIDDLEBUTTON 0x00040000
1774 
1779 #define MASK_KS_BUTTONS 0x000F0000
1780 
1791 #define ERR_OK 0
1792 
1797 #define ERR_INV_HWND -1
1798 
1803 #define ERR_QUEUE_FULL -2
1804 
1809 #define ERR_INVALID_HANDLE -3
1810 
1815 #define ERR_INVALID_HMENU -4
1816 
1821 #define ERR_INVALID_POS -5
1822 
1827 #define ERR_INVALID_ID -6
1828 
1833 #define ERR_RES_ALLOCATION -7
1834 
1839 #define ERR_CTRLCLASS_INVNAME -8
1840 
1845 #define ERR_CTRLCLASS_INVLEN -9
1846 
1851 #define ERR_CTRLCLASS_MEM -10
1852 
1857 #define ERR_CTRLCLASS_INUSE -11
1858 
1863 #define ERR_ALREADY_EXIST -12
1864 
1869 #define ERR_NO_MATCH -13
1870 
1875 #define ERR_BAD_OWNER -14
1876 
1881 #define ERR_IME_TOOMUCHIMEWND -15
1882 
1887 #define ERR_IME_NOSUCHIMEWND -16
1888 
1893 #define ERR_IME_NOIMEWND -17
1894 
1899 #define ERR_CONFIG_FILE -18
1900 
1905 #define ERR_FILE_IO -19
1906 
1911 #define ERR_GFX_ENGINE -20
1912 
1917 #define ERR_INPUT_ENGINE -21
1918 
1923 #define ERR_NO_ENGINE -22
1924 
1929 #define ERR_INVALID_ARGS -23
1930 
1941 #define TABLESIZE(table) (sizeof(table)/sizeof(table[0]))
1942 
1943 /* MAX/MIN/ABS macors */
1948 #ifndef MAX
1949 #define MAX(x, y) (((x) > (y))?(x):(y))
1950 #endif
1951 
1955 #ifndef MIN
1956 #define MIN(x, y) (((x) < (y))?(x):(y))
1957 #endif
1958 
1962 #ifndef ABS
1963 #define ABS(x) (((x)<0) ? -(x) : (x))
1964 #endif
1965 
1966 /* Commonly used definitions */
1967 #ifdef HAVE_LIMITS_H
1968 #include <limits.h>
1969 #endif
1970 
1971 #ifndef PATH_MAX
1972 # define PATH_MAX 256
1973 #endif
1974 
1975 #ifndef NAME_MAX
1976 # define NAME_MAX 64
1977 #endif
1978 
1979 
1985 #ifndef MAX_PATH
1986 # define MAX_PATH PATH_MAX
1987 #endif
1988 
1994 #ifndef MAX_NAME
1995 # define MAX_NAME NAME_MAX
1996 #endif
1997 
2002 #ifdef HAVE_TIME
2003 #include <time.h>
2004 #else
2005 typedef unsigned long time_t;
2006 
2007 struct tm {
2008  int tm_sec; /* seconds [0,61] */
2009  int tm_min; /* minutes [0,59] */
2010  int tm_hour; /* hour [0,23] */
2011  int tm_mday; /* day of month [1,31] */
2012  int tm_mon; /* month of year [0,11] */
2013  int tm_year; /* years since 1900 */
2014  int tm_wday; /* day of week [0,6] (Sunday = 0) */
2015  int tm_yday; /* day of year [0,365] */
2016  int tm_isdst; /* daylight savings flag */
2017 };
2018 #endif
2019 
2020 #ifdef __cplusplus
2021 extern "C" {
2022 #endif
2023 
2024 #if defined (__THREADX__) && defined (__TARGET_VFANVIL__)
2025 #include "fx_api.h"
2026 #include "tx_api.h"
2027 #include "os_type.h"
2028 #include "os_file_api.h"
2029 
2030 #define fopen tp_fopen
2031 #define fclose tp_fclose
2032 #define fwrite tp_fwrite
2033 #define fread tp_fread
2034 #define fseek tp_fseek
2035 #define feof tp_feof
2036 
2037 #undef assert
2038 #define _HAVE_ASSERT 1
2039 
2040 #define assert(e) do { \
2041  e; \
2042  } while (0)
2043 
2044 #undef stdin
2045 #undef stdout
2046 #undef stderr
2047 
2048 #define stdin ((FILE*)0)
2049 #define stdout ((FILE*)1)
2050 #define stderr ((FILE*)2)
2051 void Comm_Lock_Screen (void);
2052 void Comm_Unlock_Screen (void);
2053 
2054 #endif
2055 
2056 #ifdef __UCOSII__
2057 
2058 /* use our own implementation of strdup */
2059 #undef HAVE_STRDUP
2060 #undef strdup
2061 #define strdup own_strdup
2062 
2063 #endif /* __UCOSII__ */
2064 
2065 #ifndef HAVE_STRDUP
2066 MG_EXPORT char *strdup(const char *s);
2067 #endif
2068 
2069 #ifndef HAVE_STRCASECMP
2070 MG_EXPORT int strcasecmp(const char *s1, const char *s2);
2071 #endif
2072 
2073 #ifndef HAVE_STRNCASECMP
2074 MG_EXPORT int strncasecmp(const char *s1, const char *s2, unsigned int n);
2075 #endif
2076 
2077 #ifdef _MGUSE_OWN_MALLOC
2078 
2098 int init_minigui_malloc (unsigned char* heap, unsigned int heap_size,
2099  int (*lock_heap) (void), int (*unlock_heap) (void));
2100 
2101 #define USE_DL_PREFIX
2102 
2103 #include "own_malloc.h"
2104 
2105 /* wrappers for malloc functions */
2106 #define calloc dlcalloc
2107 #define free dlfree
2108 #define malloc dlmalloc
2109 #define memalign dlmemalign
2110 #define realloc dlrealloc
2111 #define valloc dlvalloc
2112 
2113 #endif
2114 
2115 /* Do not use the alloca of ARMCC */
2116 #if defined(__CC_ARM)
2117 # undef HAVE_ALLOCA
2118 # undef HAVE_ALLOCA_H
2119 #endif
2120 
2121 #ifdef HAVE_ALLOCA_H
2122 # include <alloca.h>
2123 # define ALLOCATE_LOCAL(size) alloca((int)(size))
2124 # define DEALLOCATE_LOCAL(ptr) /* as nothing */
2125 #else
2126 # define ALLOCATE_LOCAL(size) malloc((int)(size))
2127 # define DEALLOCATE_LOCAL(ptr) free(ptr)
2128 #endif
2129 
2130 #ifdef _MGUSE_OWN_STDIO
2131 
2144 int init_minigui_printf (int (*output_char) (int ch),
2145  int (*input_char) (void));
2146 
2147 #if defined (__UCOSII__) || defined (__VXWORKS__) || defined (__NUCLEUS__) || defined (__PSOS__)
2148 # undef _PRINTF_FLOATING_POINT
2149 # undef _SCANF_FLOATING_POINT
2150 #else
2151 # ifdef HAVE_MATH_H
2152 # define _PRINTF_FLOATING_POINT 1
2153 # define _SCANF_FLOATING_POINT 1
2154 # endif
2155 #endif
2156 
2157 #ifdef WIN32
2158 # include <float.h>
2159 # define isnan _isnan
2160 # define finite _finite
2161 #endif
2162 
2163 #undef _I18N_MB_REQUIRED
2164 
2165 #if defined(__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (__PSOS__)
2166  #define _MGUSE_OWN_SNPRINTF
2167  #define _MGUSE_OWN_VSNPRINTF
2168  #define _MGUSE_OWN_VFNPRINTF
2169 #else
2170  #define _MGUSE_OWN_PRINTF
2171  #define _MGUSE_OWN_FPRINTF
2172  #define _MGUSE_OWN_SPRINTF
2173  #define _MGUSE_OWN_FNPRINTF
2174  #define _MGUSE_OWN_SNPRINTF
2175  #define _MGUSE_OWN_VPRINTF
2176  #define _MGUSE_OWN_VFPRINTF
2177  #define _MGUSE_OWN_VSPRINTF
2178  #define _MGUSE_OWN_VFNPRINTF
2179  #define _MGUSE_OWN_VSNPRINTF
2180  #define _MGUSE_OWN_SCANF
2181  #define _MGUSE_OWN_FSCANF
2182  #define _MGUSE_OWN_SSCANF
2183  #define _MGUSE_OWN_VSCANF
2184  #define _MGUSE_OWN_VFSCANF
2185  #define _MGUSE_OWN_VSSCANF
2186 #endif
2187 
2188 #include "own_stdio.h"
2189 
2190 /* wrappers for stdio functions */
2191 #ifdef _MGUSE_OWN_PRINTF
2192  #define printf own_printf
2193 #endif
2194 
2195 #ifdef _MGUSE_OWN_FPRINTF
2196  #define fprintf own_fprintf
2197 #endif
2198 
2199 #ifdef _MGUSE_OWN_SPRINTF
2200  #define sprintf own_sprintf
2201 #endif
2202 
2203 #ifdef _MGUSE_OWN_FNPRINTF
2204  #define fnprintf own_fnprintf
2205 #endif
2206 
2207 #ifdef _MGUSE_OWN_SNPRINTF
2208  #define snprintf own_snprintf
2209 #endif
2210 
2211 #ifdef _MGUSE_OWN_VPRINTF
2212  #define vprintf own_vprintf
2213 #endif
2214 
2215 #ifdef _MGUSE_OWN_VFPRINTF
2216  #define vfprintf own_vfprintf
2217 #endif
2218 
2219 #ifdef _MGUSE_OWN_VSPRINTF
2220  #define vsprintf own_vsprintf
2221 #endif
2222 
2223 #ifdef _MGUSE_OWN_VFNPRINTF
2224  #define vfnprintf own_vfnprintf
2225 #endif
2226 
2227 #ifdef _MGUSE_OWN_VSNPRINTF
2228  #define vsnprintf own_vsnprintf
2229 #endif
2230 
2231 #ifdef _MGUSE_OWN_SCANF
2232  #define scanf own_scanf
2233 #endif
2234 
2235 #ifdef _MGUSE_OWN_FSCANF
2236  #define fscanf own_fscanf
2237 #endif
2238 
2239 #ifdef _MGUSE_OWN_SSCANF
2240  #define sscanf own_sscanf
2241 #endif
2242 
2243 #ifdef _MGUSE_OWN_VSCANF
2244  #define vscanf own_vscanf
2245 #endif
2246 
2247 #ifdef _MGUSE_OWN_VFSCANF
2248  #define vfscanf own_vfscanf
2249 #endif
2250 
2251 #ifdef _MGUSE_OWN_VSSCANF
2252  #define vsscanf own_vsscanf
2253 #endif
2254 
2255 #endif /* _MGUSE_OWN_STDIO */
2256 
2257 #ifdef __LINUX__
2258  #define TCS_NONE(fp) fprintf (fp, "\e[0m")
2259  #define TCS_BLACK(fp) fprintf (fp, "\e[0;30m")
2260  #define TCS_BOLD_BLACK(fp) fprintf (fp, "\e[1;30m")
2261  #define TCS_RED(fp) fprintf (fp, "\e[0;31m")
2262  #define TCS_BOLD_RED(fp) fprintf (fp, "\e[1;31m")
2263  #define TCS_GREEN(fp) fprintf (fp, "\e[0;32m")
2264  #define TCS_BOLD_GREEN(fp) fprintf (fp, "\e[1;32m")
2265  #define TCS_BROWN(fp) fprintf (fp, "\e[0;33m")
2266  #define TCS_YELLOW(fp) fprintf (fp, "\e[1;33m")
2267  #define TCS_BLUE(fp) fprintf (fp, "\e[0;34m")
2268  #define TCS_BOLD_BLUE(fp) fprintf (fp, "\e[1;34m")
2269  #define TCS_PURPLE(fp) fprintf (fp, "\e[0;35m")
2270  #define TCS_BOLD_PURPLE(fp) fprintf (fp, "\e[1;35m")
2271  #define TCS_CYAN(fp) fprintf (fp, "\e[0;36m")
2272  #define TCS_BOLD_CYAN(fp) fprintf (fp, "\e[1;36m")
2273  #define TCS_GRAY(fp) fprintf (fp, "\e[0;37m")
2274  #define TCS_WHITE(fp) fprintf (fp, "\e[1;37m")
2275  #define TCS_BOLD(fp) fprintf (fp, "\e[1m")
2276  #define TCS_UNDERLINE(fp) fprintf (fp, "\e[4m")
2277  #define TCS_BLINK(fp) fprintf (fp, "\e[5m")
2278  #define TCS_REVERSE(fp) fprintf (fp, "\e[7m")
2279  #define TCS_HIDE(fp) fprintf (fp, "\e[8m")
2280  #define TCS_CLEAR(fp) fprintf (fp, "\e[2J")
2281  #define TCS_CLRLINE(fp) fprintf (fp, "\e[1K\r")
2282 #else
2283  #define TCS_NONE(fp)
2284  #define TCS_BLACK(fp)
2285  #define TCS_BOLD_BLACK(fp)
2286  #define TCS_RED(fp)
2287  #define TCS_BOLD_RED(fp)
2288  #define TCS_GREEN(fp)
2289  #define TCS_BOLD_GREEN(fp)
2290  #define TCS_BROWN(fp)
2291  #define TCS_YELLOW(fp)
2292  #define TCS_BLUE(fp)
2293  #define TCS_BOLD_BLUE(fp)
2294  #define TCS_PURPLE(fp)
2295  #define TCS_BOLD_PURPLE(fp)
2296  #define TCS_CYAN(fp)
2297  #define TCS_BOLD_CYAN(fp)
2298  #define TCS_GRAY(fp)
2299  #define TCS_WHITE(fp)
2300  #define TCS_BOLD(fp)
2301  #define TCS_UNDERLINE(fp)
2302  #define TCS_BLINK(fp)
2303  #define TCS_REVERSE(fp)
2304  #define TCS_HIDE(fp)
2305  #define TCS_CLEAR(fp)
2306  #define TCS_CLRLINE(fp)
2307 #endif
2308 
2309 #define _MG_PRINTF(fmt, ...) \
2310  do { \
2311  TCS_GREEN (stdout); \
2312  fprintf (stdout, fmt, ##__VA_ARGS__); \
2313  TCS_NONE (stdout); \
2314  } while (0)
2315 
2316 #define _WRN_PRINTF(fmt, ...) \
2317  do { \
2318  TCS_BROWN (stderr); \
2319  fprintf (stderr, "%s: ", __FUNCTION__); \
2320  fprintf (stderr, fmt, ##__VA_ARGS__); \
2321  TCS_NONE (stderr); \
2322  } while (0)
2323 
2324 #define _ERR_PRINTF(fmt, ...) \
2325  do { \
2326  TCS_RED (stderr); \
2327  fprintf (stderr, fmt, ##__VA_ARGS__); \
2328  TCS_NONE (stderr); \
2329  } while (0)
2330 
2331 #if defined(_DEBUG)
2332 # define _DBG_PRINTF(fmt, ...) \
2333  do { \
2334  TCS_YELLOW (stderr); \
2335  fprintf (stderr, "%s: ", __FUNCTION__); \
2336  fprintf (stderr, fmt, ##__VA_ARGS__); \
2337  TCS_NONE (stderr); \
2338  } while (0)
2339 # else
2340 # define _DBG_PRINTF(fmt, ...) do { } while (0)
2341 #endif
2342 
2343 #ifdef _MGRM_THREADS
2344 
2345 #ifdef _MGUSE_OWN_PTHREAD
2346 
2347 #define MAIN_PTH_MIN_STACK_SIZE (1024)
2348 #define MAIN_PTH_DEF_STACK_SIZE (1024*4)
2349 
2373 int start_minigui_pthread (int (* pth_entry) (int argc, const char* argv []),
2374  int argc, const char* argv[],
2375  char* stack_base, unsigned int stack_size);
2376 
2377 #ifndef ESRCH
2378 # define ESRCH 3
2379 #endif
2380 
2381 #ifndef EAGAIN
2382 # define EAGAIN 11
2383 #endif
2384 
2385 #ifndef ENOMEM
2386 # define ENOMEM 12
2387 #endif
2388 
2389 #ifndef EBUSY
2390 # define EBUSY 16
2391 #endif
2392 
2393 #ifndef EINVAL
2394 # define EINVAL 22
2395 #endif
2396 
2397 #ifndef EDEADLK
2398 # define EDEADLK 35
2399 #endif
2400 
2401 #ifndef ENOSYS
2402 # define ENOSYS 38
2403 #endif
2404 
2405 #ifndef ENOTSUP
2406 # define ENOTSUP 95
2407 #endif
2408 
2409 #ifdef __VXWORKS__
2410 
2411 #define pthread_create vxworks_pthread_create
2412 #define pthread_self vxworks_pthread_self
2413 #define pthread_equal vxworks_pthread_equal
2414 #define pthread_exit vxworks_pthread_exit
2415 #define pthread_join vxworks_pthread_join
2416 #define pthread_detach vxworks_pthread_detach
2417 #define pthread_cancel vxworks_pthread_cancel
2418 #define pthread_once vxworks_pthread_once
2419 #define pthread_key_create vxworks_pthread_key_create
2420 #define pthread_key_delete vxworks_pthread_key_delete
2421 #define pthread_setspecific vxworks_pthread_setspecific
2422 #define pthread_getspecific vxworks_pthread_getspecific
2423 #define pthread_setcancelstate vxworks_pthread_setcancelstate
2424 #define pthread_setcanceltype vxworks_pthread_setcanceltype
2425 #define pthread_testcancel vxworks_pthread_testcancel
2426 
2427 #define pthread_attr_init vxworks_pthread_attr_init
2428 #define pthread_attr_destroy vxworks_pthread_attr_destroy
2429 #define pthread_attr_setdetachstate vxworks_pthread_attr_setdetachstate
2430 #define pthread_attr_getdetachstate vxworks_pthread_attr_getdetachstate
2431 #define pthread_attr_setscope vxworks_pthread_attr_setscope
2432 #define pthread_attr_getscope vxworks_pthread_attr_getscope
2433 #define pthread_attr_setinheritsched vxworks_pthread_attr_setinheritsched
2434 #define pthread_attr_getinheritsched vxworks_pthread_attr_getinheritsched
2435 #define pthread_attr_setschedpolicy vxworks_pthread_attr_setschedpolicy
2436 #define pthread_attr_getschedpolicy vxworks_pthread_attr_getschedpolicy
2437 #define pthread_attr_setschedparam vxworks_pthread_attr_setschedparam
2438 #define pthread_attr_getschedparam vxworks_pthread_attr_getschedparam
2439 #define pthread_attr_setstackaddr vxworks_pthread_attr_setstackaddr
2440 #define pthread_attr_getstackaddr vxworks_pthread_attr_getstackaddr
2441 #define pthread_attr_setstacksize vxworks_pthread_attr_setstacksize
2442 #define pthread_attr_getstacksize vxworks_pthread_attr_getstacksize
2443 #define pthread_setschedparam vxworks_pthread_setschedparam
2444 #define pthread_getschedparam vxworks_pthread_getschedparam
2445 
2446 #define pthread_mutex_init vxworks_pthread_mutex_init
2447 #define pthread_mutex_destroy vxworks_pthread_mutex_destroy
2448 #define pthread_mutex_lock vxworks_pthread_mutex_lock
2449 #define pthread_mutex_unlock vxworks_pthread_mutex_unlock
2450 #define pthread_mutex_trylock vxworks_pthread_mutex_trylock
2451 #define pthread_mutexattr_init vxworks_pthread_mutexattr_init
2452 #define pthread_mutexattr_destroy vxworks_pthread_mutexattr_destroy
2453 #define pthread_mutexattr_setpriorityinherit vxworks_pthread_mutexattr_setpriorityinherit
2454 #define pthread_mutexattr_getpriorityinherit vxworks_pthread_mutexattr_getpriorityinherit
2455 
2456 #ifdef _MGUSE_OWN_SEMAPHORE
2457 
2458 #define sem_t vxworks_sem_t
2459 
2460 #define sem_init vxworks_sem_init
2461 #define sem_destroy vxworks_sem_destroy
2462 #define sem_wait vxworks_sem_wait
2463 #define sem_trywait vxworks_sem_trywait
2464 #define sem_post vxworks_sem_post
2465 #define sem_getvalue vxworks_sem_getvalue
2466 
2467 #endif /* _MGUSE_OWN_SEMAPHORE */
2468 
2469 #endif /* __VXWORKS__ */
2470 
2471 #ifdef __MINIGUI_LIB__
2472 
2473 #ifdef __UCOSII__
2474 # include "ucos2_pthread.h"
2475 # include "ucos2_semaphore.h"
2476 #elif defined (__THREADX__)
2477 # include "threadx_pthread.h"
2478 # include "threadx_semaphore.h"
2479 #elif defined (__NUCLEUS__)
2480 # include "nucleus_pthread.h"
2481 # include "nucleus_semaphore.h"
2482 #elif defined (__VXWORKS__)
2483 # include "vxworks_pthread.h"
2484 # ifdef _MGUSE_OWN_SEMAPHORE
2485 # include "vxworks_semaphore.h"
2486 # else
2487 # include "semaphore.h"
2488 # endif
2489 #elif defined (__OSE__)
2490 # include "pthread.h"
2491 # include "ose_semaphore.h"
2492 #elif defined (__PSOS__)
2493 # include "psos_pthread.h"
2494 # include "psos_semaphore.h"
2495 #elif defined (WIN32)
2496 # include "win32_pthread.h"
2497 # include "win32_semaphore.h"
2498 #else
2499 # error No own pthread implementation for this OS!
2500 #endif
2501 
2502 #else
2503 
2504 # include <pthread.h>
2505 # include <semaphore.h>
2506 
2507 #endif /* __MINIGUI_LIB__ */
2508 
2509 #else /* _MGUSE_OWN_PTHREAD */
2510 
2511 #include <pthread.h>
2512 #include <semaphore.h>
2513 
2514 #endif /* !_MGUSE_OWN_PTHREAD */
2515 
2516 #ifdef __DARWIN__
2517 
2518 #define _USE_SEM_ON_SYSVIPC 1
2519 
2520 #endif
2521 
2522 #if defined (_USE_MUTEX_ON_SYSVIPC) || defined (_USE_SEM_ON_SYSVIPC)
2523 
2524 int _sysvipc_mutex_sem_init (void);
2525 int _sysvipc_mutex_sem_term (void);
2526 
2527 #endif
2528 
2529 #ifdef _USE_MUTEX_ON_SYSVIPC
2530 
2531 #define pthread_mutex_t _sysvipc_pthread_mutex_t
2532 #define pthread_mutexattr_t _sysvipc_pthread_mutexattr_t
2533 
2534 #define pthread_mutexattr_init _sysvipc_pthread_mutexattr_init
2535 #define pthread_mutexattr_destroy _sysvipc_pthread_mutexattr_destroy
2536 #define pthread_mutexattr_settype _sysvipc_pthread_mutexattr_settype
2537 #define pthread_mutexattr_gettype _sysvipc_pthread_mutexattr_gettype
2538 
2539 #define pthread_init _sysvipc_pthread_init
2540 #define pthread_mutex_init _sysvipc_pthread_mutex_init
2541 #define pthread_mutex_destroy _sysvipc_pthread_mutex_destroy
2542 #define pthread_mutex_lock _sysvipc_pthread_mutex_lock
2543 #define pthread_mutex_trylock _sysvipc_pthread_mutex_trylock
2544 #define pthread_mutex_unlock _sysvipc_pthread_mutex_unlock
2545 
2546 typedef struct
2547 {
2548  int kind;
2549  int semid;
2550  int sem_num;
2551  int locked_times;
2552 } pthread_mutex_t;
2553 
2554 #define SYSVIPC_PTHREAD_MUTEX_FAST_NP 0
2555 #define SYSVIPC_PTHREAD_MUTEX_RECURSIVE_NP 1
2556 #define SYSVIPC_PTHREAD_MUTEX_ERRORCHECK_NP 2
2557 
2558 typedef struct
2559 {
2560  int kind;
2561 } pthread_mutexattr_t;
2562 
2563 int pthread_mutexattr_init (pthread_mutexattr_t *attr);
2564 int pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
2565 int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type);
2566 int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int* type);
2567 
2568 int pthread_mutex_init (pthread_mutex_t *mutex,
2569  const pthread_mutexattr_t *mutex_attr);
2570 
2571 int pthread_mutex_destroy (pthread_mutex_t *mutex);
2572 
2573 int pthread_mutex_lock (pthread_mutex_t *mutex);
2574 int pthread_mutex_trylock (pthread_mutex_t *mutex);
2575 int pthread_mutex_unlock (pthread_mutex_t *mutex);
2576 
2577 #endif /* _USE_MUTEX_ON_SYSVIPC */
2578 
2579 #ifdef _USE_SEM_ON_SYSVIPC
2580 
2581 #define sem_t _sysvipc_sem_t
2582 
2583 #define sem_init _sysvipc_sem_init
2584 #define sem_destroy _sysvipc_sem_destroy
2585 #define sem_wait _sysvipc_sem_wait
2586 #define sem_trywait _sysvipc_sem_trywait
2587 #define sem_post _sysvipc_sem_post
2588 #define sem_getvalue _sysvipc_sem_getvalue
2589 
2590 #define SYSVIPC_SEM_VALUE_MAX USHRT_MAX
2591 
2592 /*-----------------------------------------------------------------------------
2593 ** Semaphore object definition
2594 */
2595 
2596 typedef struct
2597 {
2598  int semid;
2599  int sem_num;
2600 } sem_t;
2601 
2602 int sem_init (sem_t *sem, int pshared, unsigned int value);
2603 int sem_destroy (sem_t *sem);
2604 int sem_wait (sem_t *sem);
2605 int sem_trywait (sem_t *sem);
2606 int sem_post (sem_t *sem);
2607 int sem_getvalue (sem_t *sem, int *sval);
2608 
2609 #endif /* _USE_SEM_ON_SYSVIPC */
2610 
2611 #endif /* _MGRM_THREADS */
2612 
2613 #ifdef __cplusplus
2614 } /* end of extern "C" */
2615 #endif
2616 
2617 #endif /* _MGUI_COMMON_H */
2618 
struct _GAL_Rect GAL_Rect
GHANDLE HACCEL
Handle to accelarator.
Definition: common.h:433
struct _RECT RECT
Definition: common.h:956
int BOOL
A type definition for boolean value.
Definition: common.h:339
GAL_Color * colors
Definition: common.h:1146
long LONG
A type definition for long integer.
Definition: common.h:690
unsigned char BYTE
A type definition for an 8-bit unsigned character (byte).
Definition: common.h:456
SIZE * PSIZE
Data type of the pointer to a SIZE.
Definition: common.h:996
signed short SWORD16
A type definition for a 16-bit signed integer.
Definition: common.h:555
POINT * PPOINT
Data type of the pointer to a POINT.
Definition: common.h:973
BYTE g
Definition: common.h:1011
Uint32 gal_uint32
Data type of 32-bit unsigned integer.
Definition: common.h:1079
int cy
Definition: common.h:988
unsigned long DWORD_PTR
An unsigned long type for pointer precision.
Definition: common.h:593
Uint32 gal_attr
Data type of attribute value.
Definition: common.h:1101
Definition: common.h:926
Uint32 gal_pixel
Data type of pixel value.
Definition: common.h:1096
unsigned long long Uint64
A type definition for a 64-bit unsigned integer.
Definition: common.h:203
signed short Sint16
A type definition for a 16-bit signed integer.
Definition: common.h:169
int x
Definition: common.h:961
unsigned short Uint16
A type definition for a 16-bit unsigned integer.
Definition: common.h:164
DWORD32 RGBCOLOR
A type definition for a RGB color.
Definition: common.h:850
struct _GAL_Palette GAL_Palette
signed char Sint8
A type definition for an 8-bit signed character.
Definition: common.h:159
Sint32 x
Definition: common.h:1157
GHANDLE HDC
Handle to device context.
Definition: common.h:408
long LONG_PTR
A signed long type for pointer precision.
Definition: common.h:566
int ncolors
Definition: common.h:1142
int bottom
Definition: common.h:942
GHANDLE HHOOK
Handle to keyboard or mouse event hook.
Definition: common.h:443
unsigned int gal_uint
Data type of unsigned integer.
Definition: common.h:1090
unsigned short WORD16
A type definition for a 16-bit unsigned integer (word).
Definition: common.h:549
signed long long Sint64
A type definition for a 64-bit signed integer.
Definition: common.h:210
Uint8 gal_uint8
Data type of 8-bit unsigned integer.
Definition: common.h:1049
signed int Sint32
A type definition for a 32-bit signed integer.
Definition: common.h:179
GHANDLE HWND
Handle to main window or control.
Definition: common.h:403
GHANDLE HDLG
Handle to dialog box, same as HWND.
Definition: common.h:438
gal_uint8 a
Definition: common.h:1130
unsigned short WORD_HPTR
An unsigned int (word) type in half pointer precision.
Definition: common.h:518
int INT_PTR
A signed integer type for pointer precision.
Definition: common.h:671
Definition: common.h:979
RGB * PRGB
Data type of the pointer to a RGB.
Definition: common.h:1028
LONG_PTR LINT
Signed integer which has pointer precision.
Definition: common.h:573
struct _SIZE SIZE
GHANDLE HCURSOR
Handle to cursor.
Definition: common.h:418
PVOID GHANDLE
General handle.
Definition: common.h:398
RECT * PRECT
Data type of the pointer to a RECT.
Definition: common.h:950
int y
Definition: common.h:965
unsigned char Uint8
A type definition for an 8-bit unsigned character.
Definition: common.h:154
UINT_PTR LPARAM
A type definition for the second message paramter.
Definition: common.h:708
int right
Definition: common.h:938
GHANDLE HPALETTE
Handle to a logical palette.
Definition: common.h:413
Sint16 gal_sint16
Data type of 16-bit signed integer.
Definition: common.h:1057
Definition: common.h:1002
struct _RGB RGB
Sint8 gal_sint8
Data type of 8-bit signed integer.
Definition: common.h:1042
signed short SWORD_HPTR
An signed int type in half pointer precision.
Definition: common.h:530
unsigned long ULONG
A type definition for unsigned long integer.
Definition: common.h:696
struct _GAL_Color GAL_Color
long fixed
Data type of fixed point.
Definition: common.h:1107
WORD_HPTR WORD
A type definition for an unsigned integer (word).
Definition: common.h:537
unsigned int Uint32
A type definition for a 32-bit unsigned integer.
Definition: common.h:174
UINT_PTR WPARAM
A type definition for the first message paramter.
Definition: common.h:702
gal_uint8 r
Definition: common.h:1118
DWORD_PTR DWORD
A unsigned long type definition for pointer precision.
Definition: common.h:600
gal_uint8 g
Definition: common.h:1122
SWORD_HPTR SWORD
A type definition for a signed integer.
Definition: common.h:543
LONG_PTR LRESULT
Signed result of message processing.
Definition: common.h:579
int left
Definition: common.h:930
void * PVOID
A type definition for a pointer to any type.
Definition: common.h:332
signed long SDWORD_PTR
A signed long type for pointer precision.
Definition: common.h:620
unsigned long UINT_PTR
A unsigned integer type for pointer precision.
Definition: common.h:683
signed int gal_sint
Data type of signed integer.
Definition: common.h:1085
SDWORD_PTR SDWORD
A signed long type definition for pointer precision.
Definition: common.h:627
Sint32 w
Definition: common.h:1161
unsigned int UINT
A type definition for unsigned integer.
Definition: common.h:660
unsigned int DWORD32
A type definition for a 32-bit unsigned integer.
Definition: common.h:606
Sint32 gal_sint32
Data type of 32-bit signed integer.
Definition: common.h:1072
int cx
Definition: common.h:984
int top
Definition: common.h:934
BYTE b
Definition: common.h:1015
GHANDLE HMENU
Handle to menu.
Definition: common.h:428
struct _POINT POINT
Uint16 gal_uint16
Data type of 16-bit unsigned integer.
Definition: common.h:1064
gal_uint8 b
Definition: common.h:1126
signed char SBYTE
A type definition for an 8-bit signed character.
Definition: common.h:462
BYTE r
Definition: common.h:1007
BYTE a
Definition: common.h:1019
GHANDLE HICON
Handle to icon.
Definition: common.h:423
signed int SDWORD32
A type definition for a 32-bit signed integer.
Definition: common.h:633