-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seyon.c
385 lines (307 loc) · 9.15 KB
/
Seyon.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
/*
* 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 -*-
* Seyon.c --- Main module
* Author : Muhammad M. Saggaf
* Created On : sometime in 1992
* Last Modified By: system admin
* Last Modified On: Wed Jun 9 20:07:26 1993
* Update Count : 11
* Status : Mostly OK, needs some cleaning up
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <signal.h>
#include "seyon.h"
#include "SeDecl.h"
#if HAVE_TERMIOS
#include <termios.h>
struct termios newmode,
oldmode;
#else
#if HAVE_TERMIO
#include <termio.h>
struct termio newmode,
oldmode;
#else
#if HAVE_SGTTYB
#include <sys/ioctl.h>
struct sgttyb newmode,
oldmode;
#endif
#endif
#endif
#define SEYON_EMU_NAME "seyon-emu"
#define IS_MAIN
#include "version.h"
extern Widget CreateCommandCenter();
extern void SetIcon(),
GetResources(),
InitVariables();
extern void PopupInitError(),
PopupFatalError();
void s_script(),
s_set(),
s_exit(),
die(),
cleanup_exit();
int tfd,
child_pipe[2],
scriptToMainPipe[2],
mainToTermPipe[2];
FILE *tfp;
struct QueryResources qres;
XtAppContext app_con;
Widget topLevel;
pid_t mainPid;
int
main(argc, argv)
int argc;
char *argv[];
{
int OpenModem();
void DispatchActions(),
GetParameters(),
ShowOpenModemErrMsg();
char *arg[REG_BUF], termEmu[REG_BUF];
int sepIndex, i, n, retStatus;
#ifdef HAVE_FAS
char large_string[1024];
#endif
XtAppContext appContext;
char modemList[LRG_BUF],
*curModem,
*startupAction = modemList;
static char *fallbackResources[] = {
#include "Seyon.ad.h"
NULL,
};
static XrmOptionDescRec optionList[] = {
{"-modems", "modems", XrmoptionSepArg, NULL},
{"-script", "script", XrmoptionSepArg, NULL},
{"-entries", "defaultPhoneEntries", XrmoptionSepArg, NULL},
{"-dial", "dialAutoStart", XrmoptionNoArg, "True"},
{"-nodial", "dialAutoStart", XrmoptionNoArg, "False"},
{"-emulator", "emulator", XrmoptionSepArg, ""},
{"-noemulator", "noemulator", XrmoptionNoArg, ""},
{"-nodefargs", "nodefargs", XrmoptionNoArg, ""},
};
for (i = 1; i < argc && strcmp(argv[i], "--"); i++);
sepIndex = i;
/* Find if the -noemulator switch is given */
for (i = 1; i < sepIndex &&
strncmp(argv[i], "-noemulator", max(4, strlen(argv[i]))); i++);
/* If no, launch Seyon via the emulator */
if (i >= sepIndex) {
for (i = 1; i < sepIndex &&
strncmp(argv[i], "-emulator", max(3, strlen(argv[i]))); i++);
if (i < sepIndex - 1)
strcpy(termEmu, argv[i+1]);
else
strcpy(termEmu, SEYON_EMU_NAME);
/* Find if the -nodefargs switch is given */
for (i = 1; i < sepIndex &&
strncmp(argv[i], "-nodefargs", max(5, strlen(argv[i]))); i++);
n = 1;
/* If no, use the default emulator arguments */
if (i >= sepIndex) {
arg[n] = "-name"; n++;
arg[n] = "Seyon"; n++;
arg[n] = "-T"; n++;
arg[n] = "Seyon Terminal Emulator"; n++;
arg[n] = "-n"; n++;
arg[n] = "Terminal"; n++;
}
/* Pass all switches aftetr '--' to the emulator */
for (i = sepIndex + 1; i < argc; i++, n++)
arg[n] = argv[i];
arg[n] = "-e"; n++;
#ifndef HAVE_FAS
arg[n] = argv[0]; n++;
arg[n] = "-noemulator"; n++;
/* Pass all switches before '--' to Seyon */
for (i = 1; i < sepIndex; i++, n++)
arg[n] = argv[i];
#else
arg[n] = "/bin/sh"; n++;
arg[n] = "-c"; n++;
arg[n] = large_string;
strcpy(arg[n], argv[0]);
strcat(arg[n], " -noemulator");
for (i = 1; i < sepIndex; i++) {
strcat(arg[n]," ");
strcat(arg[n],argv[i]);
}
n++;
#endif
arg[n] = NULL; n++;
arg[0] = termEmu;
execvp(arg[0], arg);
fprintf(stderr, "%s `%s.\n%s\n", ">> Warning: Could not execute",
termEmu, ">> Notice: Falling to `xterm'.");
arg[0] = "xterm";
execvp(arg[0], arg);
fprintf(stderr, "%s\n%s\n", ">> Error: Could not execute `xterm'.",
">> Notice: Giving up.");
exit(1);
} /* if (i >= sepIndex)... */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* The real program begins here */
topLevel = XtAppInitialize(&appContext, "Seyon", optionList,
XtNumber(optionList), &argc, argv,
fallbackResources, NULL, 0);
app_con = appContext;
GetResources(topLevel);
mainPid = getpid();
setup_signal_handlers();
SetIcon(topLevel);
printf("\r\n%s %s\r\n", "Seyon Copyright (c) 1992-1993 Muhammad M. Saggaf.",
"All rights reserved.");
printf("\rVersion %s rev. %s %s-%s %s@%s %s %s.\r\n\n", VERSION, REVISION,
COMPILE_HOSTTYPE, COMPILE_OSNAME, COMPILE_BY, COMPILE_HOST,
COMPILE_DATE, COMPILE_TIME);
if ((tfp = fopen("/dev/tty", "r+")) == NULL) {
PopupInitError("errTtyAccess", exit);
goto MainLoop;
}
tfd = fileno(tfp);
io_get_attr(tfd, &oldmode); /* get current console tty mode */
newmode = oldmode; /* copy (structure) to newmode */
#if HAVE_TERMIOS || HAVE_TERMIO
newmode.c_oflag &= ~OPOST;
newmode.c_iflag |= (IGNBRK | IGNPAR);
newmode.c_iflag &= ~(IXON | IXOFF | ISTRIP | BRKINT);
newmode.c_lflag &= ~(ICANON | ISIG | ECHO);
newmode.c_cflag |= CREAD;
newmode.c_cc[VMIN] = 1;
newmode.c_cc[VTIME] = 1;
#else
#if HAVE_SGTTYB
newmode.sg_flags = CBREAK;
#endif
#endif
set_tty_mode();
InitVariables(topLevel);
if (argc > 1 && strcmp(argv[1], "--")) {
SeErrorF("Unknown or incomplete command-line switch: `%s'", argv[1],
"", "");
PopupInitError("errSwitches", do_exit);
goto MainLoop;
}
/* ---------------------------------------------------------------------- */
/* Open modem port and configure it */
strcpy(modemList, qres.modems);
curModem = GetFirstWord(modemList);
show("Locating Modems...");
do {
if ((retStatus = OpenModem(curModem)) >= 0) break;
ShowOpenModemErrMsg(curModem, retStatus);
if (retStatus != ERR_MDM_NOMODEM)
show(FmtString("Modem `%s' is Unavailable.\n", curModem, "", ""));
curModem = GetNextWord();
} while (curModem[0] != '\0');
if (retStatus < 0) {
SeError("No Modems Available");
PopupInitError("errModemInit", do_exit);
goto MainLoop;
}
show(FmtString("Modem `%s' is Available.\n", curModem, "", ""));
/* ---------------------------------------------------------------------- */
CreateCommandCenter();
/* ---------------------------------------------------------------------- */
pipe(child_pipe);
pipe(scriptToMainPipe);
pipe(mainToTermPipe);
XtAppAddInput(appContext, child_pipe[0], (XtPointer)XtInputReadMask,
ExecProcRequest, NULL);
XtAppAddInput(appContext, scriptToMainPipe[0], (XtPointer)XtInputReadMask,
GetParameters, NULL);
IdleGuard();
if (qres.showFunMessages) XtAppAddTimeOut(appContext,
qres.funMessagesInterval*1000, FunMessage, NULL);
/* ---------------------------------------------------------------------- */
strcpy(startupAction, qres.startupAction);
if (qres.script) sprintf(startupAction + strlen(startupAction),
" RunScript(%s);", qres.script);
if (qres.dialAutoStart) strcat(startupAction, " DialEntries(Default);");
/* ---------------------------------------------------------------------- */
linkflag = 2;
ProcRequest(DISPATCH_ACTION, "", startupAction);
/* ---------------------------------------------------------------------- */
XtSetMappedWhenManaged(topLevel, True);
XtMapWidget(topLevel); /* I don't know why I need this, but I do */
MainLoop:
XtAppMainLoop(app_con);
return 0;
}
void
setup_signal_handlers()
{
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
#ifdef SIGBUS
signal(SIGBUS, die);
#endif
signal(SIGFPE, die);
signal(SIGILL, die);
signal(SIGIOT, die);
signal(SIGSEGV, die);
signal(SIGTERM, die);
signal(SIGTRAP, die);
}
void
die(sig)
int sig;
{
void KillChildProc();
signal(sig, SIG_IGN);
SeErrorF("Killed by signal %d", sig, "", "");
SeNoticeF("Debugging info: pid=%d.", getpid(), "", "");
if (getpid() == mainPid) {
KillTerminal();
KillChildProc();
SeNotice("Press any key to exit");
getchar();
cleanup_exit(1);
}
else {
write_child_info(child_pipe, KILL_TERM, "Terminal Proc Exited");
exit(1);
}
}
void
do_exit(rc)
int rc;
{
void KillChildProc();
XtUnmapWidget(topLevel);
KillTerminal();
KillChildProc();
unlock_tty();
fflush(tfp);
restore_orig_mode();
fclose(tfp);
CloseModem();
XtDestroyApplicationContext(XtWidgetToApplicationContext(topLevel));
/* XCloseDisplay(XtDisplay(topLevel));*/
exit(rc);
}
void
cleanup_exit(status)
int status;
{
SeNotice("cleaning up..");
do_exit(status);
}
void
s_exit()
{
show("I'm rated PG-34!!");
do_exit(0);
}