182
187
if (doinit > 0 && lockfile[0] && (fd = open(lockfile, O_RDONLY)) >= 0) {
183
n = read(fd, buf, 127);
188
/* Kermit-style lockfile. */
191
/* Ascii lockfile. */
193
sscanf(buf, "%d", &pid);
195
if (pid > 0 && kill((pid_t)pid, 0) < 0 &&
197
fprintf(stderr, _("Lockfile is stale. Overriding it..\n"));
204
if (stdwin != NIL_WIN) wclose(stdwin, 1);
205
fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
188
n = read(fd, buf, 127);
193
/* Kermit-style lockfile. */
196
/* Ascii lockfile. */
198
sscanf(buf, "%d", &pid);
200
if (pid > 0 && kill((pid_t)pid, 0) < 0 &&
202
fprintf(stderr, _("Lockfile is stale. Overriding it..\n"));
211
fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
211
217
if (doinit > 0 && lockfile[0]) {
212
/* Create lockfile compatible with UUCP-1.2 */
218
/* Create lockfile compatible with UUCP-1.2 */
215
if ((fd = creat(lockfile, 0666)) < 0) {
221
if ((fd = creat(lockfile, 0666)) < 0) {
217
if ((fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) {
223
if ((fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) {
219
if (stdwin != NIL_WIN) wclose(stdwin, 1);
220
fprintf(stderr, _("Cannot create lockfile. Sorry.\n"));
225
(void) chown(lockfile, (uid_t)real_uid, (gid_t)real_gid);
226
snprintf(buf, sizeof(buf), "%10ld minicom %.20s\n", (long)getpid(), username);
227
write(fd, buf, strlen(buf));
227
fprintf(stderr, _("Cannot create lockfile. Sorry.\n"));
232
chown(lockfile, (uid_t)real_uid, (gid_t)real_gid);
233
snprintf(buf, sizeof(buf), "%10ld minicom %.20s\n",
234
(long)getpid(), username);
235
write(fd, buf, strlen(buf));
231
239
/* Run a special program to disable callin if needed. */
232
if (doinit > 0 && P_CALLOUT[0]) {
233
if(fastsystem(P_CALLOUT, CNULL, CNULL, CNULL) < 0) {
234
if (stdwin != NIL_WIN) wclose(stdwin, 1);
235
fprintf(stderr, _("Could not setup for dial out.\n"));
236
if (lockfile[0]) unlink(lockfile);
240
if (doinit > 0 && P_CALLOUT[0]) {
241
if (fastsystem(P_CALLOUT, NULL, NULL, NULL) < 0) {
244
fprintf(stderr, _("Could not setup for dial out.\n"));
242
252
/* Now open the tty device. */
243
253
if (setjmp(albuf) == 0) {
245
signal(SIGALRM, get_alrm);
255
signal(SIGALRM, get_alrm);
248
258
#define SOCKET_PREFIX "unix#"
249
portfd_is_socket = portfd_is_connected = 0;
250
if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) == 0) {
251
portfd_is_socket = 1;
259
portfd_is_socket = portfd_is_connected = 0;
260
if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) == 0) {
261
portfd_is_socket = 1;
253
portfd_sock_addr.sun_family = AF_UNIX;
254
strncpy(portfd_sock_addr.sun_path,
255
dial_tty + strlen(SOCKET_PREFIX),
256
sizeof(portfd_sock_addr.sun_path)-1);
257
portfd_sock_addr.sun_path[sizeof(portfd_sock_addr.sun_path)-1] = 0;
258
term_socket_connect();
263
portfd_sock_addr.sun_family = AF_UNIX;
264
strncpy(portfd_sock_addr.sun_path,
265
dial_tty + strlen(SOCKET_PREFIX),
266
sizeof(portfd_sock_addr.sun_path)-1);
267
portfd_sock_addr.sun_path[sizeof(portfd_sock_addr.sun_path)-1] = 0;
268
term_socket_connect();
260
270
#endif /* USE_SOCKET */
261
if (!portfd_is_socket) {
271
if (!portfd_is_socket) {
262
272
#if defined(O_NDELAY) && defined(F_SETFL)
263
portfd = open(dial_tty, O_RDWR|O_NDELAY|O_NOCTTY);
265
/* Cancel the O_NDELAY flag. */
266
n = fcntl(portfd, F_GETFL, 0);
267
(void) fcntl(portfd, F_SETFL, n & ~O_NDELAY);
273
portfd = open(dial_tty, O_RDWR|O_NDELAY|O_NOCTTY);
275
/* Cancel the O_NDELAY flag. */
276
n = fcntl(portfd, F_GETFL, 0);
277
fcntl(portfd, F_SETFL, n & ~O_NDELAY);
271
portfd = open(dial_tty, O_RDWR|O_NOCTTY);
281
portfd = open(dial_tty, O_RDWR|O_NOCTTY);
275
if (doinit > 0) m_savestate(portfd);
279
290
#ifdef HAVE_ERRNO_H
283
294
signal(SIGALRM, SIG_IGN);
284
295
if (portfd < 0 && !portfd_is_socket) {
286
if (stdwin != NIL_WIN) wclose(stdwin, 1);
287
299
#ifdef HAVE_ERRNO_H
288
fprintf(stderr, _("minicom: cannot open %s: %s\n"),
289
dial_tty, strerror(s_errno));
300
fprintf(stderr, _("minicom: cannot open %s: %s\n"),
301
dial_tty, strerror(s_errno));
291
fprintf(stderr, _("minicom: cannot open %s. Sorry.\n"), dial_tty);
303
fprintf(stderr, _("minicom: cannot open %s. Sorry.\n"), dial_tty);
293
if (lockfile[0]) unlink(lockfile);
297
if (lockfile[0]) unlink(lockfile);
298
werror(_("Cannot open %s!"), dial_tty);
312
werror(_("Cannot open %s!"), dial_tty);
303
317
/* Remember owner of port */
306
320
portgid = stt.st_gid;
308
322
/* Give it to us! */
309
if (real_uid != 0) chown(dial_tty, (uid_t)real_uid, (gid_t)real_gid);
324
chown(dial_tty, (uid_t)real_uid, (gid_t)real_gid);
311
326
/* Set CLOCAL mode */
312
327
m_nohang(portfd);
314
329
/* Set Hangup on Close if program crashes. (Hehe) */
315
330
m_hupcl(portfd, 1);
316
if (doinit > 0) m_flush(portfd);
322
338
/* Function to write output. */
323
static void do_output(s, len)
339
static void do_output(const char *s, int len)
330
if (len == 0) len = strlen(s);
332
347
if (P_PARITY[0] == 'M') {
333
for(f = 0; f < len && f < 256; f++)
334
buf[f] = *s++ | 0x80;
335
write(portfd, buf, f);
348
for(f = 0; f < len && f < 256; f++)
349
buf[f] = *s++ | 0x80;
350
write(portfd, buf, f);
337
write(portfd, s, len);
352
write(portfd, s, len);
340
355
/* Function to handle keypad mode switches. */
341
static void kb_handler(a, b)
356
static void kb_handler(int a, int b)
346
if (st) curs_status();
350
365
* Initialize screen and status line.
352
void init_emul(type, do_init)
367
void init_emul(int type, int do_init)
356
369
int x = -1, y = -1;
360
extern int use_status;
369
x = us->curx; y = us->cury;
374
387
/* See if we have space for a fixed status line */
375
388
maxy = LINES - 1;
376
if ((use_status || LINES > 24)
377
&& P_STATLINE[0] == 'e') {
385
st = wopen(0, ypos, COLS - 1, ypos, BNONE,
386
st_attr, sfcolor, sbcolor, 1, 0, 1);
389
if ((use_status || LINES > 24) &&
390
P_STATLINE[0] == 'e') {
398
st = wopen(0, ypos, COLS - 1, ypos, BNONE,
399
st_attr, sfcolor, sbcolor, 1, 0, 1);
390
403
/* MARK updated 02/17/95 - Customizable size for history buffer */
391
404
num_hist_lines = atoi(P_HISTSIZE);
392
if (num_hist_lines < 0) num_hist_lines = 0;
393
if (num_hist_lines > 5000) num_hist_lines = 5000;
405
if (num_hist_lines < 0)
407
if (num_hist_lines > 5000)
408
num_hist_lines = 5000;
395
410
/* Open a new main window, and define the configured history buffer size. */
396
411
us = wopen(0, 0, COLS - 1, maxy,
397
BNONE, XA_NORMAL, tfcolor, tbcolor, 1, num_hist_lines, 0);
412
BNONE, XA_NORMAL, tfcolor, tbcolor, 1, num_hist_lines, 0);
405
420
us->wrap = wrapln;
408
lines = LINES - (st != NIL_WIN);
423
lines = LINES - (st != NULL);
411
426
/* Install and reset the terminal emulator. */
413
vt_install(do_output, kb_handler, us);
414
vt_init(type, tfcolor, tbcolor, us->wrap, 0);
428
vt_install(do_output, kb_handler, us);
429
vt_init(type, tfcolor, tbcolor, us->wrap, addlf);
416
vt_pinit(us, -1, -1);
431
vt_pinit(us, -1, -1);
418
if (st != NIL_WIN) show_status();
422
438
* Locate the cursor at the correct position in
423
439
* the user screen.
425
static void ret_csr()
441
static void ret_csr(void)
427
443
wlocate(us, us->curx, us->cury);
452
468
* If real dcd is not supported, Online and Offline will be
453
469
* shown in capitals.
471
void time_status(void)
457
473
if (!st || disable_online_time)
459
475
wlocate(st, 63, 0);
461
wprintf(st, " %12.12s ", P_HASDCD[0] == 'Y' ? _("Offline") : _("OFFLINE"));
477
wprintf(st, " %12.12s ", P_HASDCD[0] == 'Y' ? _("Offline") : _("OFFLINE"));
463
wprintf(st," %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? _("Online") : _("ONLINE"),
464
online / 3600, (online / 60) % 60);
479
wprintf(st, " %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? _("Online") : _("ONLINE"),
480
online / 3600, (online / 60) % 60);
470
486
* Show in which mode the cursor keys are (normal or application)
488
void curs_status(void)
474
490
wlocate(st, 33, 0);
475
491
wprintf(st, cursormode == NORMAL ? "NOR" : "APP");
482
498
* Update the online time.
484
static void updtime()
500
static void updtime(void)
487
if (old_online == online) return;
503
if (old_online == online)
488
505
if ((P_LOGCONN[0] == 'Y') && (old_online >= 0) && (online < 0)) {
489
506
do_log(_("Gone offline (%ld:%02ld:%02ld)"),
490
old_online / 3600, (old_online / 60) % 60, old_online % 60);
507
old_online / 3600, (old_online / 60) % 60, old_online % 60);
492
509
old_online = online;
501
517
/* Update the timer display. This can also be called from updown.c */
518
void timer_update(void)
504
520
static time_t t1, start;
505
521
int dcd_support = P_HASDCD[0] == 'Y';
507
523
/* See if we're online. */
508
524
if ((!dcd_support && bogus_dcd) || (dcd_support && m_getdcd(portfd))) {
509
/* We are online at the moment. */
511
/* This was a transition from off to online */
517
/* DCD has gotten high, we can turn on hw flow control */
518
if (P_HASRTS[0] == 'Y')
525
/* We are online at the moment. */
527
/* This was a transition from off to online */
533
/* DCD has gotten high, we can turn on hw flow control */
534
if (P_HASRTS[0] == 'Y')
523
/* We are offline at the moment. */
526
/* DCD has dropped, turn off hw flow control. */
539
/* We are offline at the moment. */
542
/* DCD has dropped, turn off hw flow control. */
530
if (online >= 0 && old_online >= 0) {
531
/* First update the timer for call duration.. */
536
/* ..and THEN notify that we are now offline */
546
if (online >= 0 && old_online >= 0) {
547
/* First update the timer for call duration.. */
552
/* ..and THEN notify that we are now offline */
541
557
/* Update online time */
577
593
* Show the name of the script running now.
595
void scriptname(const char *s)
582
if (st == NIL_WIN) return;
583
599
wlocate(st, 39, 0);
585
wprintf(st, "Minicom %-6.6s", VERSION);
601
wprintf(st, "Minicom %-6.6s", VERSION);
587
wprintf(st, "script %-7.7s", s);
603
wprintf(st, "script %-7.7s", s);
592
608
* Show status line temporarily
594
static void showtemp()
610
static void showtemp(void)
596
if (st != NIL_WIN) return;
598
615
st = wopen(0, LINES - 1, COLS - 1, LINES - 1,
599
BNONE, st_attr, sfcolor, sbcolor, 1, 0, 1);
616
BNONE, st_attr, sfcolor, sbcolor, 1, 0, 1);
628
643
/* If the status line was shown temporarily, delete it again. */
636
651
/* Auto Zmodem? */
637
if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z') zauto = P_PAUTO[0];
652
if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z')
638
654
/* Set the terminal modes */
639
(void) setcbreak(2); /* Raw, no echo */
655
setcbreak(2); /* Raw, no echo */
641
657
keyboard(KSTART, 0);
645
/* See if window size changed */
661
/* See if window size changed */
649
/* I got the resize code going again! Yeah! */
652
if (st) wclose(st, 0);
655
if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)
656
leave(_("Could not re-initialize window system."));
657
/* Set the terminal modes */
658
(void) setcbreak(2); /* Raw, no echo */
659
init_emul(terminal, 0);
665
/* I got the resize code going again! Yeah! */
672
if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)
673
leave(_("Could not re-initialize window system."));
674
/* Set the terminal modes */
675
setcbreak(2); /* Raw, no echo */
676
init_emul(terminal, 0);
661
werror(_("Resize not supported, screen may be messed up!"));
678
werror(_("Resize not supported, screen may be messed up!"));
664
/* Update the timer. */
667
/* Check for I/O or timer. */
668
x = check_io(portfd_connected, 0, 1000, buf, &blen);
670
/* Send data from the modem to the screen. */
674
/* Auto zmodem detect */
676
if (zsig[zpos] == *ptr) zpos++;
679
if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
682
if (zauto && zsig[zpos] == 0) {
685
updown('D', zauto - 'A');
695
/* Read from the keyboard and send to modem. */
697
/* See which key was pressed. */
698
c = keyboard(KGETKEY, 0);
699
if (c < 0) c += 256; /* XXX - shouldn't happen */
701
/* Was this a command key? */
704
(escape == 128 && c > 224 && c < 252) ||
705
#else /* filipg 8/22/97: needed to recognize Fkeys in RedHat 4.1 */
706
(escape == 128 && c > 128 && c < 256) ||
708
(escape != 27 && c == escape) ||
711
/* Stop keyserv process if we have it. */
714
/* Show status line temporarily */
716
if (c == escape) /* CTRL A */
717
c = keyboard(KGETKEY, 0);
719
/* Restore keyboard modes */
720
(void) setcbreak(1); /* Cbreak, no echo */
722
if (c > K_META) c -= K_META;
723
if (c > 128) c -= 128;
729
/* CTRLA - CTRLA means send one CTRLA */
681
/* Update the timer. */
684
/* Check for I/O or timer. */
685
x = check_io(portfd_connected, 0, 1000, buf, &blen);
687
/* Send data from the modem to the screen. */
691
/* Auto zmodem detect */
693
if (zsig[zpos] == *ptr)
698
if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
701
if (zauto && zsig[zpos] == 0) {
704
updown('D', zauto - 'A');
714
/* Read from the keyboard and send to modem. */
716
/* See which key was pressed. */
717
c = keyboard(KGETKEY, 0);
718
if (c < 0) /* XXX - shouldn't happen */
721
/* Was this a command key? */
722
if ((escape == 128 && c > 224 && c < 252) ||
723
(escape != 27 && c == escape) ||
726
/* Stop keyserv process if we have it. */
729
/* Show status line temporarily */
731
if (c == escape) /* CTRL A */
732
c = keyboard(KGETKEY, 0);
734
/* Restore keyboard modes */
735
setcbreak(1); /* Cbreak, no echo */
746
/* CTRLA - CTRLA means send one CTRLA */
731
write(portfd, &c, 1);
748
write(portfd, &c, 1);
738
/* No, just a key to be sent. */
740
if (c >= K_F1 && c <= K_F10 && P_MACENAB[0] == 'Y') {
743
case K_F1: s = P_MAC1; break;
744
case K_F2: s = P_MAC2; break;
745
case K_F3: s = P_MAC3; break;
746
case K_F4: s = P_MAC4; break;
747
case K_F5: s = P_MAC5; break;
748
case K_F6: s = P_MAC6; break;
749
case K_F7: s = P_MAC7; break;
750
case K_F8: s = P_MAC8; break;
751
case K_F9: s = P_MAC9; break;
752
case K_F10: s = P_MAC10; break;
755
/* No, just a key to be sent. */
756
if (c >= K_F1 && c <= K_F10 && P_MACENAB[0] == 'Y') {
759
case K_F1: s = P_MAC1; break;
760
case K_F2: s = P_MAC2; break;
761
case K_F3: s = P_MAC3; break;
762
case K_F4: s = P_MAC4; break;
763
case K_F5: s = P_MAC5; break;
764
case K_F6: s = P_MAC6; break;
765
case K_F7: s = P_MAC7; break;
766
case K_F8: s = P_MAC8; break;
767
case K_F9: s = P_MAC9; break;
768
case K_F10: s = P_MAC10; break;