-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeActions.c
473 lines (402 loc) · 11.7 KB
/
SeActions.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
* This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
* Saggaf. All rights reserved.
*
* See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
* statement of rights and permissions for this program.
*/
/* -*- Mode: C -*-
* SeActions.c --- Actions
* Author : Muhammad M. Saggaf
* Created On : sometime in 1992
* Last Modified By: system admin
* Last Modified On: Wed Jun 9 19:49:36 1993
* Update Count : 10
* Status : Mostly OK, needs some cleaning up
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Command.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* SeDecl.h includes stdio.h */
#include "SeDecl.h"
#include "config.h"
#include "version.h"
#define CheckNumParam(num) \
{ \
if (*numParam != num) \
SimpleError("Wrong Number of Parameters"); \
}
extern Widget dialWidget;
void CallCallbacksAction(widget) Widget widget;
{ XtCallCallbacks(widget, XtNdestroyCallback, NULL); }
void BeepAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
CheckNumParam(0);
Beep();
}
void CloseWindowAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
int DismissDirectory();
Widget dirWidget;
int i;
for (i = 0; i < *numParam; i++) {
if (strcmp(param[i], "Dial") == 0) {
if ((dirWidget = XtNameToWidget(dialWidget, "directory")))
DismissDirectory(dirWidget);
} else
SimpleErrorF("Invalid Parameter `%s'", param[i], "", "");
} /* for... */
}
void DialEntriesAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
ErrorIfBusy();
CheckNumParam(1);
if (strcmp(*param, "Default"))
TopDial(dialWidget, (XtPointer)*param);
else
TopDial(dialWidget, (XtPointer)qres.defaultPhoneEntries);
}
void DivertFileAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void DivertFile(), ExecDivertFile();
ErrorIfBusy();
if (*numParam > 1)
SimpleError("Wrong Number of Parameters");
if (*numParam == 0)
DivertFile(widget);
else
ExecDivertFile(widget, *param);
}
void DoNothingAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{ CheckNumParam(0); }
void EchoAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
if (*numParam == 0)
show("");
CheckNumParam(1);
show(*param);
}
void FileTransferAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void TopTransfer();
static String pParam[2];
int i;
ErrorIfBusy();
if (*numParam < 1 || *numParam > 2)
SimpleError("Wrong Number of Parameters");
for (i = 0; i < *numParam;) {
pParam[i] = param[i];
pParam[++i] = NULL;
}
TopTransfer(widget, (XtPointer)pParam);
}
void IconifyWindowAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
int IconifyShell();
Widget dirWidget;
static String termWindowId = NULL;
int i;
for (i = 0; i < *numParam; i++) {
if (strcmp(param[i], "Main") == 0)
IconifyShell(widget);
else if (strcmp(param[i], "Dial") == 0) {
if ((dirWidget = XtNameToWidget(dialWidget, "directory")))
IconifyShell(dirWidget);
} else if (strcmp(param[i], "Term") == 0) {
if (termWindowId == NULL)
termWindowId = (String)getenv("WINDOWID");
if (termWindowId)
XIconifyWindow(XtDisplay(widget), (Window)atol(termWindowId),
XScreenNumberOfScreen(XtScreen(widget)));
else {
SeError("Could not get terminal window ID");
SeNotice("Maybe you're not using xterm?");
SimpleError("WINDOWID not Found");
}
} /* if strcmp Term... */
else
SimpleErrorF("Invalid Parameter `%s'", param[i], "", "");
} /* for... */
}
void HangupAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void ExecHangup();
ErrorIfBusy();
CheckNumParam(0);
ExecHangup();
}
void ManualDialAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void ManualDial(), ExecManualDial();
ErrorIfBusy();
if (*numParam > 1)
SimpleError("Wrong Number of Parameters");
if (*numParam == 0)
ManualDial(widget);
else
ExecManualDial(widget, *param);
}
void MessageAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
if (*numParam == 0)
SeyonMessage("");
CheckNumParam(1);
SeyonMessage(*param);
}
void OpenWindowAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
int IconifyShell();
/* Widget dirWidget; */
static String termWindowId = NULL;
int i;
for (i = 0; i < *numParam; i++) {
if (strcmp(param[i], "Main") == 0)
XMapRaised(XtDisplay(widget), XtWindow(GetShell(widget)));
else if (strcmp(param[i], "Dial") == 0)
TopDial(dialWidget, NULL);
/* if ((dirWidget = XtNameToWidget(dialWidget, "directory")))
{XtPopup(dirWidget, XtGrabNone); XtMapWidget(dirWidget);}
else TopDial(dialWidget, NULL);*/
else if (strcmp(param[i], "Term") == 0) {
if (termWindowId == NULL)
termWindowId = (String)getenv("WINDOWID");
if (termWindowId)
XMapRaised(XtDisplay(widget), (Window)atol(termWindowId));
else {
SeError("Could not get terminal window ID");
SeNotice("Maybe you're not using xterm?");
SimpleError("WINDOWID not Found");
}
} /* if strcmp Term... */
else
SimpleErrorF("Invalid Parameter `%s'", param[i], "", "");
} /* for... */
}
void QuitAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
ErrorIfBusy();
CheckNumParam(0);
ExecExit();
}
void RestartTerminalAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
ErrorIfBusy();
CheckNumParam(0);
RestartTerminal();
}
void RunScriptAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void DialogRunScript(), RunScript();
ErrorIfBusy();
if (*numParam == 0)
DialogRunScript(widget);
CheckNumParam(1);
RunScript(widget, *param);
}
void SetAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
void s_set();
int length;
int length_remaining;
ErrorIfBusy();
CheckNumParam(2);
length_remaining = WBSIZE;
length = 1 + strlen(param[0]) + strlen(param[1]);
if (length_remaining > length)
sprintf((lptr = line), "%s %s", param[0], param[1]);
else
printf("SetAction: string buffer would have overrun: %s %s\n", param[0],
param[1]);
eof_flag = 0;
s_set();
}
void ShellCommandAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
ErrorIfBusy();
CheckNumParam(1);
ShellCommand(*param);
}
void SleepAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
CheckNumParam(1);
sleep(atoi(*param));
}
void TransmitAction(widget, event, param, numParam) Widget widget;
XEvent *event;
String *param;
Cardinal *numParam;
{
ErrorIfBusy();
CheckNumParam(1);
MdmPutString(*param);
}
/*---------------------------------------------------------------------------+
| DispatchActions - parses an action stack and dispatches its actions.
+---------------------------------------------------------------------------*/
void DispatchActions(intData, stringData, widget) int intData;
String stringData;
Widget widget;
{
int SeAppMSleep();
void ParseThis();
static Boolean actionRunning = False, prevActionAsync = False, startup = True;
static Widget actionWidget;
static String actionStack = "";
void (*actionProc)();
static char actionName[SM_BUF], args[SM_BUF][SM_BUF];
static String argsArray[SM_BUF];
static Cardinal numArgs;
int i;
struct _actionTable {
String actionKeyWord;
void (*actionProc)();
Boolean async;
};
/* A string containing a script of actions to perform at startup. */
String startScript;
static struct _actionTable actionTable[] = {
{"Beep", BeepAction, False},
{"CloseWindow", CloseWindowAction, False},
{"DialEntries", DialEntriesAction, True},
{"DivertFile", DivertFileAction, True},
{"DoNothing", DoNothingAction, False},
{"Echo", EchoAction, False},
{"FileTransfer", FileTransferAction, True},
{"IconifyWindow", IconifyWindowAction, False},
{"Hangup", HangupAction, False},
{"ManualDial", ManualDialAction, True},
{"Message", MessageAction, False},
{"OpenWindow", OpenWindowAction, False},
{"Quit", QuitAction, False},
{"RestartTerminal", RestartTerminalAction, False},
{"RunScript", RunScriptAction, True},
{"Set", SetAction, False},
{"ShellCommand", ShellCommandAction, True},
{"Sleep", SleepAction, False},
{"Transmit", TransmitAction, False},
{NULL, NULL, False},
};
switch (intData) {
case ACTION_NEW_ACTION:
strncpy(actionName, stringData, sizeof(actionName));
numArgs = 0;
return;
case ACTION_NEW_ARG:
strncpy((argsArray[numArgs] = args[numArgs]), stringData, SM_BUF);
numArgs++;
return;
case ACTION_ARGS_END:
if (prevActionAsync)
while (inhibit_child)
XtAppProcessEvent(XtWidgetToApplicationContext(actionWidget), XtIMAll);
for (i = 0; (actionProc = actionTable[i].actionProc) &&
strcmp(actionName, actionTable[i].actionKeyWord);
i++)
;
if (actionProc == NULL) {
SeError(FmtString("Invalid action: ``%s''", actionName, "", ""));
SimpleError("Invalid Action Specified");
}
(*actionProc)(actionWidget, NULL, argsArray, &numArgs);
prevActionAsync = actionTable[i].async;
return;
case ACTION_PARSE_ERROR:
SeError(FmtString("%s in ``%s''", stringData, actionStack, ""));
return;
case ACTION_DISPATCH:
if (actionRunning)
SimpleError("Action Still Running");
if (stringData == NULL) {
SeError("Serious (report it): stringData = NULL in DispatchActions");
return;
}
actionWidget = widget;
actionStack = XtNewString(stringData);
actionRunning = True;
prevActionAsync = False;
ParseThis(actionStack, DispatchActions);
actionRunning = False;
XtFree(actionStack);
if (startup) {
startup = False;
startScript = XtNewString(
FmtString("Message(\"Welcome to Seyon version %s.%s\"); %s", VERSION,
REVISION, "RestartTerminal();"));
ParseThis(startScript, DispatchActions);
XtFree(startScript);
}
return;
}
}
/*---------------------------------------------------------------------------+
| DispatchActionsCallback - callback for dispatching SeQuickKey actions.
+---------------------------------------------------------------------------*/
void DispatchActionsCallback(widget, clientData) XtPointer widget;
XtPointer clientData;
{
void GetQuickKeyResources();
String widgetName;
struct _quickKeyRes quickKeyRes;
GetQuickKeyResources((widgetName = XtName(widget)), &quickKeyRes);
if (quickKeyRes.action == NULL || quickKeyRes.action[0] == '\0')
SimpleError("No Action Attached");
DispatchActions(ACTION_DISPATCH, quickKeyRes.action, widget);
}