forked from adtools/clib2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commodities_functions.c
179 lines (144 loc) · 3.42 KB
/
test_commodities_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Checks the commodities functions: ArgArrayDone, ArgArrayInit, ArgInt, ArgString, HotKey, InvertString, FreeIEvents
// Inspired by https://wiki.amigaos.net/wiki/Commodities_Exchange_Library
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/commodities.h>
#include <proto/dos.h>
#include <proto/commodities.h>
#include <proto/utility.h>
#include <clib/alib_protos.h>
extern struct ExecBase *SysBase;
extern struct IntuitionBase *IntuitionBase;
extern struct DosLibrary *DOSBase;
#define TOOL_TYPES_CNT 3
#define EVT_HOTKEY_1 1L
#define EVT_HOTKEY_2 1L
static CONST_STRPTR toolTypes[] = {"command name","TOOL_LEVEL=5","TOOL_NAME=amiga","TOOL_VERSION=1.0.1"};
static const char hotkey_str_1[] = "ctrl alt a";
static const char hotkey_str_2[] = "shift alt a";
struct NewBroker newbroker = {
NB_VERSION,
"Amiga HotKey", /* string to identify this broker */
"A Simple HotKey",
"A simple hot key commodity",
NBU_UNIQUE | NBU_NOTIFY, /* Don't want any new commodities starting with this name. */
0, 0, 0, 0 /* If someone tries it, let me know */
};
CONST_STRPTR shift_alt_a = "\n<shift alt a>";
WORD testCommoditiesFunctions(void)
{
STRPTR *ttypes;
LONG toolLevel = 0;
char *toolStr;
struct MsgPort *cxPort = NULL;
struct Message *cxMsg;
CxObj *filter1 = NULL, *filter2 = NULL;
CxObj *broker = NULL;
CxMsg *msg = NULL;
ULONG cxsigflag;
ULONG sigrcvd;
BOOL loop = TRUE;
ULONG msgid,msgtype;
struct InputEvent *ie = NULL;
WORD errCnt = 0;
ttypes = ArgArrayInit(TOOL_TYPES_CNT,toolTypes);
toolLevel = (LONG)ArgInt((CONST_STRPTR *)ttypes,"TOOL_LEVEL",10);
#if OPTION_TRACE
Printf("toolLevel = %lu\n",toolLevel);
#endif
if(toolLevel != 5L)
{
errCnt++;
}
toolStr = ArgString((CONST_STRPTR *)ttypes, "TOOL_NAME", "no name");
#if OPTION_TRACE
Printf("toolStr = %ls\n",toolStr);
#endif
if(Stricmp(toolStr,"amiga"))
{
errCnt++;
}
ArgArrayDone();
cxPort = CreatePort(NULL,0);
if(cxPort == NULL)
{
errCnt++;
goto end;
}
newbroker.nb_Port = cxPort;
cxsigflag = 1L << cxPort->mp_SigBit;
newbroker.nb_Pri = 0;
broker = CxBroker(&newbroker,NULL);
if(broker == NULL)
{
errCnt++;
goto end;
}
filter1 = HotKey(hotkey_str_1,cxPort,EVT_HOTKEY_1);
if(filter1 == NULL)
{
errCnt++;
goto end;
}
filter2 = HotKey(hotkey_str_2,cxPort,EVT_HOTKEY_2);
if(filter2 == NULL)
{
errCnt++;
goto end;
}
ie = InvertString(shift_alt_a, NULL);
if(ie == NULL)
{
errCnt++;
goto end;
}
AttachCxObj(broker,filter1);
AttachCxObj(broker,filter2);
ActivateCxObj(broker,1L);
Printf("Please press %ls...\n",(long unsigned int)hotkey_str_1);
while(loop)
{
sigrcvd = Wait(SIGBREAKF_CTRL_C | cxsigflag);
while((msg = (CxMsg *)GetMsg(cxPort)))
{
msgid = CxMsgID(msg);
msgtype = CxMsgType(msg);
ReplyMsg((struct Message *)msg);
if(msgtype == CXM_IEVENT && msgid == EVT_HOTKEY_1)
{
AddIEvents(ie);
}
if(msgtype == CXM_IEVENT && msgid == EVT_HOTKEY_2)
{
loop = FALSE;
}
}
if(sigrcvd & SIGBREAKF_CTRL_C)
{
errCnt++;
loop = FALSE;
}
}
ActivateCxObj(filter1,FALSE);
ActivateCxObj(filter2,FALSE);
FreeIEvents(ie);
end:
if(broker != NULL)
{
DeleteCxObjAll(broker);
}
else
{
if(filter1 != NULL)
DeleteCxObj(filter1);
if(filter2 != NULL)
DeleteCxObj(filter2);
}
if(cxPort != NULL)
{
while(msg = (CxMsg *)GetMsg(cxPort))
ReplyMsg((struct Message *)msg);
DeletePort(cxPort);
}
return(errCnt);
}