-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathav_prot.c
324 lines (290 loc) · 8.22 KB
/
av_prot.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* @(#)highwire/av_prot.c
*/
#include <string.h>
#include <stdlib.h>
#include <gem.h>
#include "global.h"
#include "vaproto.h"
/* #include "av_comm.h" */
#include "hwWind.h" /* new_hwWind, window_raise */
#include "Loader.h"
static BOOL acc_wind_OK = TRUE;
static void handle_avdd (short win_handle, short kstate, char * arg);
/* All GLOBAL memory is merged to one block and allocated in main(). */
char *va_helpbuf; /* HW_PATH_MAX byte */
short av_shell_id = -1; /* Desktop's AES ID */
short av_shell_status = 0; /* What AV commands can desktop do? */
extern char *thisapp;
/*============================================================================*/
short
get_avserver(void)
{
short ret = -100;
const char * av_env = getenv("AVSERVER");
if (av_env) {
char av_envname[9];
strncpy(av_envname,av_env, 8);
av_envname[8] = '\0';
while (strlen (av_envname) < 8) {
strcat(av_envname, " ");
}
ret = appl_find (av_envname);
}
return ret;
}
/*============================================================================*/
BOOL
Send_AV (short message, const char * data1, const char * data2)
{
short msg[8];
short to_ap_id = av_shell_id;
(void)data2; /* unused at the moment, so suppress warning by Pure C */
/* - 100 to ap id would be no AV server */
if (to_ap_id == -100)
return FALSE;
msg[0] = message;
msg[1] = gl_apid;
msg[7] = msg[6] = msg[5] = msg[4] = msg[3] = msg[2] = 0;
switch (message)
{
/* case PDF_AV_OPEN_FILE:
to_ap_id = appl_find("MYPDF ");
*(char **)&msg[3] = strcpy(va_helpbuf, data1);
break; */ /* commented out for the moment */
case AV_EXIT:
msg[3] = gl_apid;
break;
case AV_PROTOKOLL:
msg[3] = VV_START | VV_ACC_QUOTING;
*(char **)(msg+6) = strcpy (va_helpbuf, thisapp);
break;
case AV_ACCWINDOPEN:
if (!cfg_AVWindow) {
return FALSE;
}
msg[3] = *(const short *)data1;
break;
case AV_ACCWINDCLOSED:
if (!cfg_AVWindow) {
return FALSE;
}
msg[3] = *(const short *)data1;
break;
case AV_SENDKEY :
if (!cfg_AVWindow) {
return FALSE;
}
msg[3] = 0x0004;
msg[4] = 0x1117; /* ^W */
break;
case AV_PATH_UPDATE:
*(char **)(msg+3) = strcpy(va_helpbuf, data1);
break;
case VA_START:
*(char **)(msg+3) = strcpy(va_helpbuf, data1);
break;
default:
return FALSE; /* not supported here */
}
return (appl_write (to_ap_id, 16, msg) > 0);
}
/*============================================================================*/
BOOL
Receive_AV (WORD msg[8])
{
WORD d;
char * str_p; /* *arg; */
WORD kstate = 0, whandle;
/* POSENTRY *va_list = NULL; */
switch (msg[0]) {
case VA_PROTOSTATUS :
if (msg[1] == av_shell_id) {
av_shell_status = msg[3];
}
if (acc_wind_OK && !(av_shell_status & AA_ACCWIND)) {
acc_wind_OK = FALSE;
}
#ifdef AVSERVER_TEST
if (av_shell_status & AA_SENDKEY) puts ("SENDKEY\r");
else puts ("SENDKEY error\r");
if (av_shell_status & AA_ASKFILEFONT) puts ("ASKFILEFONT\r");
else puts ("ASKFILEFONT error\r");
if (av_shell_status & AA_ASKCONFONT) puts ("ASKCONFONT\r");
else puts ("ASKCONFONT error\r");
if (av_shell_status & AA_ASKOBJECT) puts ("ASKOBJECT\r");
else puts ("ASKOBJEKT error\r");
if (av_shell_status & AA_OPENWIND) puts ("OPENWIND\r");
else puts ("OPENWIND error\r");
if (av_shell_status & AA_STARTPROG) puts ("STARTPROG\r");
else puts ("STARTPROG error\r");
if (av_shell_status & AA_ACCWIND) puts ("ACCWIND\r");
else puts ("ACCWIND error\r");
if (av_shell_status & AA_STATUS) puts ("STATUS\r");
else puts ("STATUS error\r");
if (av_shell_status & AA_COPY_DRAGGED) puts ("COPY_DRAGGED\r");
else puts ("COPY_DRAGGED error\r");
if (av_shell_status & AA_DRAG_ON_WINDOW) puts ("DRAG_ON_WINDOW\r");
else puts ("DRAG_ON_WINDOW error\r");
if (av_shell_status & AA_EXIT) puts ("EXIT\r");
else puts ("EXIT error\r");
if (av_shell_status & AA_XWIND) puts ("XWIND\r");
else puts ("XWIND error\r");
if (av_shell_status & AA_FONTCHANGED) puts ("FONTCHANGED\r");
else puts ("FONTCHANGED error\r");
if (av_shell_status & AA_STARTED) puts ("STARTED\r");
else puts ("STARTED error\r");
if (av_shell_status & AA_SRV_QUOTING) puts ("SRV_QUOTING\r");
else puts ("SRV_QUOTING error\r");
if (av_shell_status & AA_FILE) puts ("FILE\r");
else puts ("FILE error\r");
#endif
break;
case AV_SENDKEY : /* doesn't seem to be necessary at all ??? */
printf ("AV_SENDKEY von %d: %x, %x\r\n", msg[1], msg[3], msg[4]);
if ((msg[3] == 0x0004) && (msg[4] == 0x1117)) { /* ^W */
window_raise (NULL, TRUE, NULL);
}
break;
#if 0
case VA_DRAG_COMPLETE :
if (debug_level & DBG_AV)
debug("VA_DRAG_COMPLETE.\n");
if (glob_data != NULL)
{
free(glob_data);
glob_data = NULL;
}
break;
#endif
case VA_DRAGACCWIND : /* bei D&D mit glob. Fensterwechsel */
str_p = *(char **)(msg+6);
whandle = msg[3];
graf_mkstate (&d, &d, &d, &kstate);
/* printf ("VA_DRAGACCWIND von %d: %x, %x\r\n", msg[1], msg[3], msg[4]);*/
if (str_p != NULL) {
handle_avdd (whandle, kstate, str_p);
}
break;
}
return TRUE;
}
/*============================================================================*/
void
Init_AV_Protocol(void)
{
va_helpbuf[0] = '\0';
av_shell_id = get_avserver();
Send_AV (AV_PROTOKOLL, NULL, NULL);
}
/*============================================================================*/
void
Exit_AV_Protocol(void)
{
if (av_shell_status & AA_EXIT) { /* AV server knows AV_EXIT */
Send_AV (AV_EXIT, NULL, NULL);
}
}
/*============================================================================*/
void
send_avwinopen (short handle)
{
if (acc_wind_OK) {
Send_AV (AV_ACCWINDOPEN, (char*)&handle, NULL);
}
}
/*============================================================================*/
void
send_avwinclose (short handle)
{
if (acc_wind_OK) {
Send_AV (AV_ACCWINDCLOSED, (char*)&handle, NULL);
}
}
/*----------------------------------------------------------------------------*/
static void
handle_avdd (short win_handle, short kstate, char * arg)
{
char filename[HW_PATH_MAX];
char * cmd_orig = strdup(arg);
BOOL quoted;
if (win_handle && cmd_orig) {
HwWIND wind;
char * cmd = cmd_orig;
char * p = filename;
char * s;
if (cmd[0] == '\'') {
cmd++;
quoted = TRUE;
} else {
quoted = FALSE;
}
while (cmd[0] != '\0') {
if (cmd[0] == '\'') {
quoted = TRUE;
switch (cmd[1]) {
case '\'':
cmd++;
break;
case ' ':
p[0] = '\0';
s = cmd +1;
cmd = filename;
new_hwWind ("", cmd, TRUE);
quoted = FALSE;
cmd = s;
if (cmd[0] == '\'')
cmd++;
if (cmd[0] != '\0') {
p = filename;
}
cmd++;
if (cmd[0] == '\'') {
cmd++;
quoted = TRUE;
}
break;
default:
break;
}
}
p++[0] = cmd++[0];
if (!quoted && cmd[0] == ' ') {
p[0] = '\0';
s = cmd +1;
cmd = filename;
if ((kstate & K_ALT)
|| ((wind = hwWind_byHandle (win_handle)) != NULL
&& wind->Base.Ident != WIDENT_BRWS)) {
wind = NULL;
}
if (!wind) new_hwWind ("", cmd, TRUE);
else start_cont_load (wind->Pane, cmd, NULL, TRUE, TRUE);
cmd = s;
if (cmd[0] == '\'') {
quoted = TRUE;
cmd++;
}
if (cmd[0] != '\0') {
p = filename;
}
if (cmd[0] == '\'') {
cmd++;
}
}
}
if (cmd > cmd_orig && cmd[-1] == '\'') {
p[-1] = '\0';
} else {
p[0] = '\0';
}
cmd = filename;
if ((kstate & K_ALT)
|| ((wind = hwWind_byHandle (win_handle)) != NULL
&& wind->Base.Ident != WIDENT_BRWS)) {
wind = NULL;
}
if (!wind) new_hwWind ("", cmd, TRUE);
else start_cont_load (wind->Pane, cmd, NULL, TRUE, TRUE);
}
if (cmd_orig) free (cmd_orig);
}