~ubuntu-branches/ubuntu/hardy/minicom/hardy

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2006-10-27 05:41:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061027054123-9cyfsdx649zetdrv
Tags: 2.2-3
* Added upstream NEWS file, closes: #394827.
* Fixed spelling errors, closes: #395449.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#endif
21
21
 
22
22
#include "rcsid.h"
23
 
RCSID("$Id: main.c,v 1.7 2003/05/10 18:10:37 al-guest Exp $")
 
23
RCSID("$Id: main.c,v 1.16 2005/10/31 12:13:51 al-guest Exp $")
24
24
 
25
25
#include "port.h"
26
26
#include "minicom.h"
38
38
static jmp_buf albuf;
39
39
 
40
40
/* Compile SCCS ID into executable. */
41
 
char *Version = VERSION;
 
41
const char *Version = VERSION;
42
42
 
43
 
void curs_status();
 
43
void curs_status(void);
44
44
 
45
45
/*
46
46
 * Find out name to use for lockfile when locking tty.
50
50
  char *p;
51
51
  
52
52
  if (strncmp(s, "/dev/", 5) == 0) {
53
 
        /* In /dev */
54
 
        strncpy(res, s + 5, reslen - 1);
55
 
        res[reslen-1] = 0;
56
 
        for (p = res; *p; p++)
57
 
                if (*p == '/') *p = '_';
 
53
    /* In /dev */
 
54
    strncpy(res, s + 5, reslen - 1);
 
55
    res[reslen-1] = 0;
 
56
    for (p = res; *p; p++)
 
57
      if (*p == '/')
 
58
        *p = '_';
58
59
  } else {
59
 
        /* Outside of /dev. Do something sensible. */
60
 
        if ((p = strrchr(s, '/')) == NULL)
61
 
                p = s;
62
 
        else
63
 
                p++;
64
 
        strncpy(res, p, reslen - 1);
65
 
        res[reslen-1] = 0;
 
60
    /* Outside of /dev. Do something sensible. */
 
61
    if ((p = strrchr(s, '/')) == NULL)
 
62
      p = s;
 
63
    else
 
64
      p++;
 
65
    strncpy(res, p, reslen - 1);
 
66
    res[reslen-1] = 0;
66
67
  }
67
68
 
68
69
  return res;
71
72
/*
72
73
 * Leave.
73
74
 */
74
 
void leave(s)
75
 
char *s;
 
75
void leave(const char *s)
76
76
{
77
 
  if (stdwin) wclose(stdwin, 1);
 
77
  if (stdwin)
 
78
    wclose(stdwin, 1);
78
79
  if (portfd > 0) {
79
 
        m_restorestate(portfd);
80
 
        close(portfd);
 
80
    m_restorestate(portfd);
 
81
    close(portfd);
81
82
  }
82
83
  set_privs();
83
 
  if (lockfile[0]) unlink(lockfile);
84
 
  if (P_CALLIN[0]) (void) fastsystem(P_CALLIN, CNULL, CNULL, CNULL);
85
 
  if (real_uid) chown(dial_tty, (uid_t)portuid, (gid_t)portgid);
 
84
  if (lockfile[0])
 
85
    unlink(lockfile);
 
86
  if (P_CALLIN[0])
 
87
    fastsystem(P_CALLIN, NULL, NULL, NULL);
 
88
  if (real_uid)
 
89
    chown(dial_tty, (uid_t)portuid, (gid_t)portgid);
86
90
  fprintf(stderr, "%s", s);
87
91
  exit(1);
88
92
}
90
94
/*
91
95
 * Return text describing command-key.
92
96
 */
93
 
char *esc_key()
 
97
char *esc_key(void)
94
98
{
95
99
  static char buf[16];
96
100
 
97
101
  if (!alt_override && P_ESCAPE[0] == '^' && P_ESCAPE[1] != '[') {
98
 
        sprintf(buf, "CTRL-%c ", P_ESCAPE[1]);
99
 
        return(buf);
 
102
    sprintf(buf, "CTRL-%c ", P_ESCAPE[1]);
 
103
    return buf;
100
104
  }
101
105
#if defined(_COHERENT) || defined(i386) || defined(__i386__)
102
106
  sprintf(buf, "ESC,");
103
107
#else
104
108
  sprintf(buf, "Meta-");
105
109
#endif
106
 
  return(buf);
 
110
  return buf;
107
111
}
108
112
 
109
113
/*ARGSUSED*/
110
 
static void get_alrm(dummy)
111
 
int dummy;
 
114
static void get_alrm(int dummy)
112
115
{
113
116
  (void)dummy;
114
117
  longjmp(albuf, 1);
118
121
/*
119
122
 * If portfd is a socket, we try to (re)connect
120
123
 */
121
 
void term_socket_connect()
 
124
void term_socket_connect(void)
122
125
{
123
126
 
124
127
  if (!portfd_is_socket || portfd_is_connected)
137
140
/*
138
141
 * Close the connection if the socket delivers "eof" (read returns 0)
139
142
 */
140
 
void term_socket_close()
 
143
void term_socket_close(void)
141
144
{
142
145
  close(portfd);
143
146
  portfd_is_connected = 0;
148
151
/*
149
152
 * Open the terminal.
150
153
 */
151
 
int open_term(doinit)
152
 
int doinit;
 
154
int open_term(int doinit)
153
155
{
154
156
  struct stat stt;
155
157
  char buf[128];
168
170
 
169
171
#ifdef SVR4_LOCKS
170
172
    stat(dial_tty, &stt);
171
 
    sprintf(lockfile, "%s/LK.%03d.%03d.%03d", P_LOCK, major(stt.st_dev), major(stt.st_rdev), minor(stt.st_rdev));
 
173
    sprintf(lockfile, "%s/LK.%03d.%03d.%03d",
 
174
                      P_LOCK, major(stt.st_dev),
 
175
                      major(stt.st_rdev), minor(stt.st_rdev));
172
176
 
173
177
#else /* SVR4_LOCKS */
174
 
    snprintf(lockfile, sizeof(lockfile), "%s/LCK..%s", P_LOCK, mbasename(dial_tty, buf, sizeof(buf)));
175
 
 
 
178
    snprintf(lockfile, sizeof(lockfile),
 
179
                       "%s/LCK..%s",
 
180
                       P_LOCK, mbasename(dial_tty, buf, sizeof(buf)));
176
181
#endif /* SVR4_LOCKS */
177
182
 
178
183
  }
180
185
    lockfile[0] = 0;
181
186
 
182
187
  if (doinit > 0 && lockfile[0] && (fd = open(lockfile, O_RDONLY)) >= 0) {
183
 
        n = read(fd, buf, 127);
184
 
        close(fd);
185
 
        if (n > 0) {
186
 
                pid = -1;
187
 
                if (n == 4)
188
 
                        /* Kermit-style lockfile. */
189
 
                        pid = *(int *)buf;
190
 
                else {
191
 
                        /* Ascii lockfile. */
192
 
                        buf[n] = 0;
193
 
                        sscanf(buf, "%d", &pid);
194
 
                }
195
 
                if (pid > 0 && kill((pid_t)pid, 0) < 0 &&
196
 
                        errno == ESRCH) {
197
 
                    fprintf(stderr, _("Lockfile is stale. Overriding it..\n"));
198
 
                    sleep(1);
199
 
                    unlink(lockfile);
200
 
                } else
201
 
                    n = 0;
202
 
        }
203
 
        if (n == 0) {
204
 
                if (stdwin != NIL_WIN) wclose(stdwin, 1);
205
 
                fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
206
 
                drop_privs();
207
 
                return(-1);
208
 
        }
 
188
    n = read(fd, buf, 127);
 
189
    close(fd);
 
190
    if (n > 0) {
 
191
      pid = -1;
 
192
      if (n == 4)
 
193
        /* Kermit-style lockfile. */
 
194
        pid = *(int *)buf;
 
195
      else {
 
196
        /* Ascii lockfile. */
 
197
        buf[n] = 0;
 
198
        sscanf(buf, "%d", &pid);
 
199
      }
 
200
      if (pid > 0 && kill((pid_t)pid, 0) < 0 &&
 
201
          errno == ESRCH) {
 
202
        fprintf(stderr, _("Lockfile is stale. Overriding it..\n"));
 
203
        sleep(1);
 
204
        unlink(lockfile);
 
205
      } else
 
206
        n = 0;
 
207
    }
 
208
    if (n == 0) {
 
209
      if (stdwin)
 
210
        wclose(stdwin, 1);
 
211
      fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
 
212
      drop_privs();
 
213
      return -1;
 
214
    }
209
215
  }
210
216
 
211
217
  if (doinit > 0 && lockfile[0]) {
212
 
        /* Create lockfile compatible with UUCP-1.2 */
213
 
        mask = umask(022);
 
218
    /* Create lockfile compatible with UUCP-1.2 */
 
219
    mask = umask(022);
214
220
#ifdef _COH3
215
 
        if ((fd = creat(lockfile, 0666)) < 0) {
 
221
    if ((fd = creat(lockfile, 0666)) < 0) {
216
222
#else
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) {
218
224
#endif
219
 
                if (stdwin != NIL_WIN) wclose(stdwin, 1);
220
 
                fprintf(stderr, _("Cannot create lockfile. Sorry.\n"));
221
 
                drop_privs();
222
 
                return(-1);
223
 
        }
224
 
        (void) umask(mask);
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));
228
 
        close(fd);
 
225
        if (stdwin)
 
226
          wclose(stdwin, 1);
 
227
        fprintf(stderr, _("Cannot create lockfile. Sorry.\n"));
 
228
        drop_privs();
 
229
        return -1;
 
230
      }
 
231
      umask(mask);
 
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));
 
236
      close(fd);
229
237
  }
230
238
 
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);
237
 
                drop_privs();
238
 
                return(-1);
239
 
        }
240
 
  }
 
240
    if (doinit > 0 && P_CALLOUT[0]) {
 
241
      if (fastsystem(P_CALLOUT, NULL, NULL, NULL) < 0) {
 
242
        if (stdwin)
 
243
          wclose(stdwin, 1);
 
244
        fprintf(stderr, _("Could not setup for dial out.\n"));
 
245
        if (lockfile[0])
 
246
          unlink(lockfile);
 
247
        drop_privs();
 
248
        return -1;
 
249
      }
 
250
    }
241
251
 
242
252
  /* Now open the tty device. */
243
253
  if (setjmp(albuf) == 0) {
244
 
        portfd = -1;
245
 
        signal(SIGALRM, get_alrm);
246
 
        alarm(4);
247
 
#if USE_SOCKET
 
254
    portfd = -1;
 
255
    signal(SIGALRM, get_alrm);
 
256
    alarm(4);
 
257
#ifdef USE_SOCKET
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;
252
262
 
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();
259
 
        }
 
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();
 
269
    }
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);
264
 
                if (portfd >= 0) {
265
 
                        /* Cancel the O_NDELAY flag. */
266
 
                        n = fcntl(portfd, F_GETFL, 0);
267
 
                        (void) fcntl(portfd, F_SETFL, n & ~O_NDELAY);
268
 
                }
 
273
      portfd = open(dial_tty, O_RDWR|O_NDELAY|O_NOCTTY);
 
274
      if (portfd >= 0) {
 
275
        /* Cancel the O_NDELAY flag. */
 
276
        n = fcntl(portfd, F_GETFL, 0);
 
277
        fcntl(portfd, F_SETFL, n & ~O_NDELAY);
 
278
      }
269
279
#else
270
 
                if (portfd < 0)
271
 
                        portfd = open(dial_tty, O_RDWR|O_NOCTTY);
 
280
      if (portfd < 0)
 
281
        portfd = open(dial_tty, O_RDWR|O_NOCTTY);
272
282
#endif
273
 
        }
274
 
        if (portfd >= 0) {
275
 
                if (doinit > 0) m_savestate(portfd);
276
 
                port_init();
277
 
        }
 
283
    }
 
284
    if (portfd >= 0) {
 
285
      if (doinit > 0)
 
286
        m_savestate(portfd);
 
287
      port_init();
 
288
    }
278
289
  }
279
290
#ifdef HAVE_ERRNO_H
280
291
  s_errno = errno;
282
293
  alarm(0);
283
294
  signal(SIGALRM, SIG_IGN);
284
295
  if (portfd < 0 && !portfd_is_socket) {
285
 
        if (doinit > 0) {
286
 
                if (stdwin != NIL_WIN) wclose(stdwin, 1);
 
296
    if (doinit > 0) {
 
297
      if (stdwin)
 
298
        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));
290
302
#else
291
 
                fprintf(stderr, _("minicom: cannot open %s. Sorry.\n"), dial_tty);
 
303
      fprintf(stderr, _("minicom: cannot open %s. Sorry.\n"), dial_tty);
292
304
#endif
293
 
                if (lockfile[0]) unlink(lockfile);
294
 
                drop_privs();
295
 
                return(-1);
296
 
        }
297
 
        if (lockfile[0]) unlink(lockfile);
298
 
        werror(_("Cannot open %s!"), dial_tty);
299
 
        drop_privs();
300
 
        return(-1);
 
305
      if (lockfile[0])
 
306
        unlink(lockfile);
 
307
      drop_privs();
 
308
      return -1;
 
309
    }
 
310
    if (lockfile[0])
 
311
      unlink(lockfile);
 
312
    werror(_("Cannot open %s!"), dial_tty);
 
313
    drop_privs();
 
314
    return -1;
301
315
  }
302
316
 
303
317
  /* Remember owner of port */
306
320
  portgid = stt.st_gid;
307
321
 
308
322
  /* Give it to us! */
309
 
  if (real_uid != 0) chown(dial_tty, (uid_t)real_uid, (gid_t)real_gid);
 
323
  if (real_uid != 0)
 
324
    chown(dial_tty, (uid_t)real_uid, (gid_t)real_gid);
310
325
 
311
326
  /* Set CLOCAL mode */
312
327
  m_nohang(portfd);
313
328
 
314
329
  /* Set Hangup on Close if program crashes. (Hehe) */
315
330
  m_hupcl(portfd, 1);
316
 
  if (doinit > 0) m_flush(portfd);
 
331
  if (doinit > 0)
 
332
    m_flush(portfd);
317
333
  drop_privs();
318
 
  return(0);
 
334
  return 0;
319
335
}
320
336
 
321
337
 
322
338
/* Function to write output. */
323
 
static void do_output(s, len)
324
 
char *s;
325
 
int len;
 
339
static void do_output(const char *s, int len)
326
340
{
327
341
  char buf[256];
328
342
  int f;
329
343
 
330
 
  if (len == 0) len = strlen(s);
 
344
  if (len == 0)
 
345
    len = strlen(s);
331
346
 
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);
336
351
  } else
337
 
        write(portfd, s, len);
 
352
    write(portfd, s, len);
338
353
}
339
354
 
340
355
/* Function to handle keypad mode switches. */
341
 
static void kb_handler(a, b)
342
 
int a,b;
 
356
static void kb_handler(int a, int b)
343
357
{
344
358
  cursormode = b;
345
359
  keypadmode = a;
346
 
  if (st) curs_status();
 
360
  if (st)
 
361
    curs_status();
347
362
}
348
363
 
349
364
/*
350
365
 * Initialize screen and status line.
351
366
 */
352
 
void init_emul(type, do_init)
353
 
int type;
354
 
int do_init;
 
367
void init_emul(int type, int do_init)
355
368
{
356
369
  int x = -1, y = -1;
357
370
  char attr = 0;
358
371
  int maxy;
359
372
  int ypos;
360
 
  extern int use_status;
361
 
 
362
 
  if (st != NIL_WIN) {
363
 
        wclose(st, 1);
364
 
        tempst = 0;
365
 
        st = NIL_WIN;
366
 
  }
367
 
 
368
 
  if (us != NIL_WIN) {
369
 
        x = us->curx; y = us->cury;
370
 
        attr = us->attr;
371
 
        wclose(us, 0);
372
 
  }     
 
373
 
 
374
  if (st) {
 
375
    wclose(st, 1);
 
376
    tempst = 0;
 
377
    st = NULL;
 
378
  }
 
379
 
 
380
  if (us) {
 
381
    x = us->curx;
 
382
    y = us->cury;
 
383
    attr = us->attr;
 
384
    wclose(us, 0);
 
385
  }
373
386
 
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') {
378
 
        if (use_status) {
379
 
                ypos = LINES;
380
 
                maxy = LINES - 1;
381
 
        } else {
382
 
                ypos = LINES - 1;
383
 
                maxy = LINES - 2;
384
 
        }
385
 
        st = wopen(0, ypos, COLS - 1, ypos, BNONE,
386
 
                st_attr, sfcolor, sbcolor, 1, 0, 1);
387
 
        wredraw(st, 1);
 
389
  if ((use_status || LINES > 24) &&
 
390
      P_STATLINE[0] == 'e') {
 
391
    if (use_status) {
 
392
      ypos = LINES;
 
393
      maxy = LINES - 1;
 
394
    } else {
 
395
      ypos = LINES - 1;
 
396
      maxy = LINES - 2;
 
397
    }
 
398
    st = wopen(0, ypos, COLS - 1, ypos, BNONE,
 
399
               st_attr, sfcolor, sbcolor, 1, 0, 1);
 
400
    wredraw(st, 1);
388
401
  }
389
402
 
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)
 
406
    num_hist_lines = 0;
 
407
  if (num_hist_lines > 5000)
 
408
    num_hist_lines = 5000;
394
409
 
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);
398
413
 
399
414
  if (x >= 0) {
400
 
        wlocate(us, x, y);
401
 
        wsetattr(us, attr);
 
415
    wlocate(us, x, y);
 
416
    wsetattr(us, attr);
402
417
  }
403
418
 
404
419
  us->autocr = 0;
405
420
  us->wrap = wrapln;
406
421
 
407
422
  terminal = type;
408
 
  lines = LINES - (st != NIL_WIN);
 
423
  lines = LINES - (st != NULL);
409
424
  cols = COLS;
410
 
  
 
425
 
411
426
  /* Install and reset the terminal emulator. */
412
427
  if (do_init) {
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);
415
430
  } else
416
 
        vt_pinit(us, -1, -1);
 
431
    vt_pinit(us, -1, -1);
417
432
 
418
 
  if (st != NIL_WIN) show_status();
 
433
  if (st)
 
434
    show_status();
419
435
}
420
436
 
421
437
/*
422
438
 * Locate the cursor at the correct position in
423
439
 * the user screen.
424
440
 */
425
 
static void ret_csr()
 
441
static void ret_csr(void)
426
442
{
427
443
  wlocate(us, us->curx, us->cury);
428
444
  wflush();
431
447
/*
432
448
 * Show baudrate, parity etc.
433
449
 */
434
 
void mode_status()
 
450
void mode_status(void)
435
451
{
436
452
  if (st) { /* if swich off status line - NOT print !!! (vlk@st.simbirsk.su) */
437
453
    wlocate(st, 20, 0);
439
455
      wprintf(st, "unix-socket");
440
456
    } else {
441
457
      if (P_SHOWSPD[0] == 'l')
442
 
        wprintf(st, "%6ld %s%s%s", linespd, P_BITS, P_PARITY, P_STOPB);
 
458
        wprintf(st, "%6ld %s%s%s", linespd, P_BITS, P_PARITY, P_STOPB);
443
459
      else
444
 
        wprintf(st, "%6.6s %s%s%s", P_BAUDRATE, P_BITS, P_PARITY, P_STOPB);
 
460
        wprintf(st, "%6.6s %s%s%s", P_BAUDRATE, P_BITS, P_PARITY, P_STOPB);
445
461
    }
446
462
    ret_csr();
447
463
  }
452
468
 * If real dcd is not supported, Online and Offline will be
453
469
 * shown in capitals.
454
470
 */
455
 
void time_status()
 
471
void time_status(void)
456
472
{
457
473
  if (!st || disable_online_time)
458
474
    return;
459
475
  wlocate(st, 63, 0);
460
476
  if (online < 0)
461
 
        wprintf(st, " %12.12s ", P_HASDCD[0] == 'Y' ? _("Offline") : _("OFFLINE"));
 
477
    wprintf(st, " %12.12s ", P_HASDCD[0] == 'Y' ? _("Offline") : _("OFFLINE"));
462
478
  else
463
 
        wprintf(st," %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? _("Online") : _("ONLINE"),
464
 
                online / 3600, (online / 60) % 60);
465
 
                
 
479
    wprintf(st, " %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? _("Online") : _("ONLINE"),
 
480
            online / 3600, (online / 60) % 60);
 
481
 
466
482
  ret_csr();
467
483
}
468
484
 
469
485
/*
470
486
 * Show in which mode the cursor keys are (normal or application)
471
487
 */
472
 
void curs_status()
 
488
void curs_status(void)
473
489
{
474
490
  wlocate(st, 33, 0);
475
491
  wprintf(st, cursormode == NORMAL ? "NOR" : "APP");
481
497
/*
482
498
 * Update the online time.
483
499
 */
484
 
static void updtime()
 
500
static void updtime(void)
485
501
{
486
502
 
487
 
  if (old_online == online) return;
 
503
  if (old_online == online)
 
504
    return;
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);
491
508
  }
492
509
  old_online = online;
493
 
  if (st != NIL_WIN) {
494
 
        time_status();
495
 
        ret_csr();
 
510
  if (st) {
 
511
    time_status();
 
512
    ret_csr();
496
513
  }
497
514
  wflush();
498
515
}
499
516
 
500
 
 
501
517
/* Update the timer display. This can also be called from updown.c */
502
 
void timer_update()
 
518
void timer_update(void)
503
519
{
504
520
  static time_t t1, start;
505
521
  int dcd_support = P_HASDCD[0] == 'Y';
506
522
 
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. */
510
 
        if (online < 0) {
511
 
                /* This was a transition from off to online */
512
 
                time(&start);
513
 
                t1 = start;
514
 
                online = 0;
515
 
                updtime();
516
 
#if _DCDFLOW
517
 
                /* DCD has gotten high, we can turn on hw flow control */
518
 
                if (P_HASRTS[0] == 'Y')
519
 
                        m_sethwf(portfd, 1);
 
525
    /* We are online at the moment. */
 
526
    if (online < 0) {
 
527
      /* This was a transition from off to online */
 
528
      time(&start);
 
529
      t1 = start;
 
530
      online = 0;
 
531
      updtime();
 
532
#ifdef _DCDFLOW
 
533
      /* DCD has gotten high, we can turn on hw flow control */
 
534
      if (P_HASRTS[0] == 'Y')
 
535
        m_sethwf(portfd, 1);
520
536
#endif
521
 
        }
 
537
    }
522
538
  } else {
523
 
        /* We are offline at the moment. */
524
 
#if _DCDFLOW
525
 
        if (online >= 0) {
526
 
                /* DCD has dropped, turn off hw flow control. */
527
 
                m_sethwf(portfd, 0);
528
 
        }
 
539
    /* We are offline at the moment. */
 
540
#ifdef _DCDFLOW
 
541
    if (online >= 0) {
 
542
      /* DCD has dropped, turn off hw flow control. */
 
543
      m_sethwf(portfd, 0);
 
544
    }
529
545
#endif
530
 
        if (online >= 0 && old_online >= 0) {
531
 
          /* First update the timer for call duration.. */
532
 
          time(&t1);
533
 
          online = t1 - start;
534
 
          updtime();
535
 
        }
536
 
        /* ..and THEN notify that we are now offline */
537
 
        online = -1;
538
 
        updtime();
 
546
    if (online >= 0 && old_online >= 0) {
 
547
      /* First update the timer for call duration.. */
 
548
      time(&t1);
 
549
      online = t1 - start;
 
550
      updtime();
 
551
    }
 
552
    /* ..and THEN notify that we are now offline */
 
553
    online = -1;
 
554
    updtime();
539
555
  }
540
556
 
541
557
  /* Update online time */
550
566
/*
551
567
 * Show the status line 
552
568
 */
553
 
void show_status()
 
569
void show_status(void)
554
570
{
555
571
  st->direct = 0;
556
572
  wlocate(st, 0, 0);
557
573
  wprintf(st,
558
 
          _(" %7.7sZ for help |           |     | Minicom %-6.6s |       | "),
559
 
          esc_key(), VERSION);
 
574
          _(" %7.7sZ for help |           |     | Minicom %-6.6s |       | "),
 
575
          esc_key(), VERSION);
560
576
  mode_status();
561
577
  time_status();
562
578
  curs_status();
563
579
  wlocate(st, 56, 0);
564
580
  switch(terminal) {
565
 
        case VT100:
566
 
                wputs(st, "VT102");
567
 
                break;
568
 
        case ANSI:
569
 
                wputs(st, "ANSI");
570
 
                break;
 
581
    case VT100:
 
582
      wputs(st, "VT102");
 
583
      break;
 
584
    case ANSI:
 
585
      wputs(st, "ANSI");
 
586
      break;
571
587
  }
572
588
  wredraw(st, 1);
573
589
  ret_csr();
576
592
/*
577
593
 * Show the name of the script running now.
578
594
 */
579
 
void scriptname(s)
580
 
char *s;
 
595
void scriptname(const char *s)
581
596
{
582
 
  if (st == NIL_WIN) return;
 
597
  if (st == NULL)
 
598
    return;
583
599
  wlocate(st, 39, 0);
584
600
  if (*s == 0)
585
 
        wprintf(st, "Minicom %-6.6s", VERSION);
 
601
    wprintf(st, "Minicom %-6.6s", VERSION);
586
602
  else
587
 
        wprintf(st, "script %-7.7s", s);
 
603
    wprintf(st, "script %-7.7s", s);
588
604
  ret_csr();
589
605
}
590
606
 
591
607
/*
592
608
 * Show status line temporarily
593
609
 */
594
 
static void showtemp()
 
610
static void showtemp(void)
595
611
{
596
 
  if (st != NIL_WIN) return;
 
612
  if (st)
 
613
    return;
597
614
 
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);
600
617
  show_status();
601
618
  tempst = 1;
602
619
}
606
623
 *      - If there are characters recieved send them
607
624
 *        to the screen via the appropriate translate function.
608
625
 */
609
 
int do_terminal()
 
626
int do_terminal(void)
610
627
{
611
628
  char buf[128];
612
629
  char *ptr;
614
631
  int x;
615
632
  int blen;
616
633
  int zauto = 0;
617
 
  char *zsig = "**\030B00";
 
634
  static const char zsig[] = "**\030B00";
618
635
  int zpos = 0;
619
 
#if _HAVE_MACROS
620
 
  char *s;
621
 
#endif
 
636
  const char *s;
622
637
  dirflush = 0;
623
638
 
624
639
dirty_goto:
627
642
 
628
643
  /* If the status line was shown temporarily, delete it again. */
629
644
  if (tempst) {
630
 
        tempst = 0;
631
 
        wclose(st, 1);
632
 
        st = NIL_WIN;
 
645
    tempst = 0;
 
646
    wclose(st, 1);
 
647
    st = NULL;
633
648
  }
634
649
 
635
650
 
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')
 
653
    zauto = P_PAUTO[0];
638
654
  /* Set the terminal modes */
639
 
  (void) setcbreak(2); /* Raw, no echo */
 
655
  setcbreak(2); /* Raw, no echo */
640
656
 
641
657
  keyboard(KSTART, 0);
642
658
 
643
659
  /* Main loop */
644
 
  while(1) {
645
 
        /* See if window size changed */
646
 
        if (size_changed) {
647
 
                size_changed = 0;
 
660
  while (1) {
 
661
    /* See if window size changed */
 
662
    if (size_changed) {
 
663
      size_changed = 0;
648
664
#if 1
649
 
                /* I got the resize code going again! Yeah! */
650
 
                wclose(us, 0);
651
 
                us = NIL_WIN;
652
 
                if (st) wclose(st, 0);
653
 
                st = NIL_WIN;
654
 
                wclose(stdwin, 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! */
 
666
      wclose(us, 0);
 
667
      us = NULL;
 
668
      if (st)
 
669
        wclose(st, 0);
 
670
      st = NULL;
 
671
      wclose(stdwin, 0);
 
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);
660
677
#else
661
 
                werror(_("Resize not supported, screen may be messed up!"));
 
678
      werror(_("Resize not supported, screen may be messed up!"));
662
679
#endif
663
 
        }
664
 
        /* Update the timer. */
665
 
        timer_update();
666
 
 
667
 
        /* Check for I/O or timer. */
668
 
        x = check_io(portfd_connected, 0, 1000, buf, &blen);
669
 
 
670
 
        /*  Send data from the modem to the screen. */
671
 
        if ((x & 1) == 1) {
672
 
                ptr = buf;
673
 
                while(blen-- > 0) {
674
 
                        /* Auto zmodem detect */
675
 
                        if (zauto) {
676
 
                                if (zsig[zpos] == *ptr) zpos++;
677
 
                                  else zpos = 0;
678
 
                        }
679
 
                        if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
680
 
                                *ptr &= 0x7f;
681
 
                        vt_out(*ptr++);
682
 
                        if (zauto && zsig[zpos] == 0) {
683
 
                                dirflush = 1;
684
 
                                keyboard(KSTOP, 0);
685
 
                                updown('D', zauto - 'A');
686
 
                                dirflush = 0;
687
 
                                zpos = 0;
688
 
                                blen = 0;
689
 
                                goto dirty_goto;
690
 
                        }
691
 
                }
692
 
                wflush();
693
 
        }
694
 
        
695
 
        /* Read from the keyboard and send to modem. */
696
 
        if ((x & 2) == 2) {
697
 
                /* See which key was pressed. */
698
 
                c = keyboard(KGETKEY, 0);
699
 
                if (c < 0) c += 256; /* XXX - shouldn't happen */
700
 
 
701
 
                /* Was this a command key? */
702
 
                if (
703
 
#ifndef RH_FIX
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) ||
707
 
#endif /* RH_FIX */
708
 
                    (escape != 27 && c == escape) || 
709
 
                    (c > K_META)) {
710
 
 
711
 
                        /* Stop keyserv process if we have it. */
712
 
                        keyboard(KSTOP, 0);
713
 
 
714
 
                        /* Show status line temporarily */
715
 
                        showtemp();
716
 
                        if (c == escape) /* CTRL A */
717
 
                                c = keyboard(KGETKEY, 0);
718
 
 
719
 
                        /* Restore keyboard modes */
720
 
                        (void) setcbreak(1); /* Cbreak, no echo */
721
 
 
722
 
                        if (c > K_META) c -= K_META;
723
 
                        if (c > 128) c -= 128;
724
 
                        if (c > ' ') {
725
 
                                dirflush = 1;
726
 
                                m_flush(0);
727
 
                                return(c);
728
 
                        }
729
 
                        /* CTRLA - CTRLA means send one CTRLA */
 
680
    }
 
681
    /* Update the timer. */
 
682
    timer_update();
 
683
 
 
684
    /* Check for I/O or timer. */
 
685
    x = check_io(portfd_connected, 0, 1000, buf, &blen);
 
686
 
 
687
    /*  Send data from the modem to the screen. */
 
688
    if ((x & 1) == 1) {
 
689
      ptr = buf;
 
690
      while (blen-- > 0) {
 
691
        /* Auto zmodem detect */
 
692
        if (zauto) {
 
693
          if (zsig[zpos] == *ptr)
 
694
            zpos++;
 
695
          else
 
696
            zpos = 0;
 
697
        }
 
698
        if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
 
699
          *ptr &= 0x7f;
 
700
        vt_out(*ptr++);
 
701
        if (zauto && zsig[zpos] == 0) {
 
702
          dirflush = 1;
 
703
          keyboard(KSTOP, 0);
 
704
          updown('D', zauto - 'A');
 
705
          dirflush = 0;
 
706
          zpos = 0;
 
707
          blen = 0;
 
708
          goto dirty_goto;
 
709
        }
 
710
      }
 
711
      wflush();
 
712
    }
 
713
 
 
714
    /* Read from the keyboard and send to modem. */
 
715
    if ((x & 2) == 2) {
 
716
      /* See which key was pressed. */
 
717
      c = keyboard(KGETKEY, 0);
 
718
      if (c < 0) /* XXX - shouldn't happen */
 
719
        c += 256;
 
720
 
 
721
      /* Was this a command key? */
 
722
      if ((escape == 128 && c > 224 && c < 252) ||
 
723
          (escape != 27 && c == escape) ||
 
724
          (c > K_META)) {
 
725
 
 
726
        /* Stop keyserv process if we have it. */
 
727
        keyboard(KSTOP, 0);
 
728
 
 
729
        /* Show status line temporarily */
 
730
        showtemp();
 
731
        if (c == escape) /* CTRL A */
 
732
          c = keyboard(KGETKEY, 0);
 
733
 
 
734
        /* Restore keyboard modes */
 
735
        setcbreak(1); /* Cbreak, no echo */
 
736
 
 
737
        if (c > K_META)
 
738
          c -= K_META;
 
739
        if (c > 128)
 
740
          c -= 128;
 
741
        if (c > ' ') {
 
742
          dirflush = 1;
 
743
          m_flush(0);
 
744
          return c;
 
745
        }
 
746
        /* CTRLA - CTRLA means send one CTRLA */
730
747
#if 0
731
 
                        write(portfd, &c, 1);
 
748
        write(portfd, &c, 1);
732
749
#else
733
 
                        vt_send(c);
 
750
        vt_send(c);
734
751
#endif
735
 
                        goto dirty_goto;
736
 
                }
 
752
        goto dirty_goto;
 
753
      }
737
754
 
738
 
                /* No, just a key to be sent. */
739
 
#if _HAVE_MACROS
740
 
                if (c >= K_F1 && c <= K_F10 && P_MACENAB[0] == 'Y') {
741
 
                    s = "";
742
 
                    switch(c) {
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;
753
 
                    }
754
 
                    if (*s)
755
 
                        mputs(s, 1);
756
 
                    else
757
 
                        vt_send(c);
758
 
                } else
759
 
#endif
760
 
                vt_send(c);
761
 
        }
 
755
      /* No, just a key to be sent. */
 
756
      if (c >= K_F1 && c <= K_F10 && P_MACENAB[0] == 'Y') {
 
757
        s = "";
 
758
        switch(c) {
 
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;
 
769
        }
 
770
        if (*s)
 
771
          mputs(s, 1);
 
772
        else
 
773
          vt_send(c);
 
774
      } else
 
775
        vt_send(c);
 
776
    }
762
777
  }
763
778
}