-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commodity.c
223 lines (173 loc) · 6.57 KB
/
Commodity.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / INCLUDES / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
#include "Public.h"
#include "Commodity.h"
/****************************************************************************
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / FUNCTIONS / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
\ \ \ \ \ \ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
****************************************************************************/
BOOL InitCommodity()
{
LONG error;
BOOL cont = TRUE;
CxObj *Filter,
*Sender,
*Translate;
// attempt to create message port
if ( ! (BrokerMP = CreateMsgPort()) ) {
DoErrors( FATAL,
"Error creating `Exec' message port",
"low memory?|exec.library out of date?",
"Quit" );
return( FALSE );
}
// check to see if cxpriority is inside valid range; set to 0 if not
if (_cxpriority < -128 || _cxpriority > 127)
_cxpriority = 0;
// change presets in `NewBroker' structure
NewBroker.nb_Descr = DESC;
NewBroker.nb_Pri = _cxpriority;
NewBroker.nb_Port = BrokerMP;
// set up new broker
Broker = CxBroker( &NewBroker, &error );
// handle any errors caused by `CxBroker'
switch( error ) {
case CBERR_OK:
break;
case CBERR_DUP:
cont = FALSE;
break;
case CBERR_SYSERR:
DoErrors( FATAL,
"Error creating commodity",
"probably low memory",
"Quit" );
cont = FALSE;
break;
case CBERR_VERSION:
DoErrors( FATAL,
"Error creating commodity",
"problem in source code, slap nearest coder",
"Quit" );
cont = FALSE;
break;
}
if ( cont == FALSE )
return( FALSE );
// set up and attach new filter object
Filter = CxFilter( _opthotkey );
if ( CxObjError( Filter ) == COERR_BADFILTER ) {
BOOL returnerror;
returnerror = DoErrors( WARNING,
"The HOTKEY definition didn't make any sense",
"use default POPKEY (alt space)|Quit and alter POPKEY tooltype",
"Continue with default|Quit" );
ClearCxObjError( Filter );
if ( returnerror == TRUE ) {
SetFilter( Filter, DEF_HOTKEY );
if ( CxObjError( Filter ) == COERR_BADFILTER ) {
DoErrors ( WARNING,
"The default POPKEY definition didn't make any sense",
"bad coding?|your version of commodities.library is outdated?",
"Quit" );
return( FALSE );
}
} else
return( FALSE );
}
// set up and attach new signal object
Sender = CxSender( BrokerMP, EVT_HOTKEY );
AttachCxObj( Filter, Sender );
// set up and attach new translator
Translate = CxTranslate( NULL );
AttachCxObj( Filter, Translate );
AttachCxObj( Broker, Filter );
ActivateCxObj( Broker, 1 );
if ( CxObjError( Filter ) ) {
DoErrors( FATAL,
"Error creating commodity",
"low memory?|bad coding?",
"Quit" );
ClearCxObjError( Filter );
return( FALSE );
}
return( TRUE );
}
/***************************************************************************/
void CleanUpCommodity()
{
if ( Broker != NULL )
DeleteCxObjAll(Broker);
if ( BrokerMP != NULL ) {
while ( (BrokerMsg = (CxMsg *)GetMsg( BrokerMP )) )
ReplyMsg( (struct Message *)BrokerMsg );
DeleteMsgPort( BrokerMP );
}
}
/***************************************************************************/
void HandleCommodityMsgs( BOOL * quit_prog )
{
ULONG MsgID, MsgType;
while ( ( BrokerMsg = (CxMsg *)GetMsg(BrokerMP) ) ) {
MsgID = CxMsgID( BrokerMsg );
MsgType = CxMsgType( BrokerMsg );
ReplyMsg( (struct Message *)BrokerMsg );
switch ( MsgType ) {
case CXM_IEVENT:
switch ( MsgID )
{
case EVT_HOTKEY:
MainGUISequence();
break;
default:
break;
}
break;
case CXM_COMMAND: // Commodities has sent a command
switch ( MsgID ) {
case CXCMD_DISABLE:
interface = FALSE;
ActivateCxObj( Broker, FALSE );
break;
case CXCMD_ENABLE:
ActivateCxObj( Broker, TRUE );
break;
// unique signal recieved, pop up window
case CXCMD_UNIQUE:
// switch depending on prefs.
switch (_relaunch) {
default:
case RELAUNCH_POP:
MainGUISequence();
break;
case RELAUNCH_RELOAD:
case RELAUNCH_QUIT:
* quit_prog = TRUE;
break;
}
break;
case CXCMD_KILL:
* quit_prog = TRUE;
break;
case CXCMD_APPEAR:
break;
case CXCMD_DISAPPEAR:
break;
default:
break;
}
break;
default:
break;
}
}
}
/***************************************************************************/