home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, John F. Haugh II
- * An unpublished work.
- * All rights reserved.
- *
- * Permission is granted to copy and create derivative works for any
- * non-commercial purpose, provided this copyright notice is preserved
- * in all copies of source code, or included in human readable form
- * and conspicuously displayed on all copies of object code or
- * distribution media.
- */
-
- #ifndef lint
- static char sccsid[] = "@(#)ttys.c 2.1 09:26:58 2/27/91";
- #endif
-
- #include <sys/types.h>
- #include <sys/termio.h>
- #include <sys/tty.h>
- #include <ctype.h>
- #include "crash.h"
-
- struct bits {
- char *b_name;
- int b_value;
- int b_mask;
- };
-
- struct bits ibits[] = {
- "ignbrk", IGNBRK, IGNBRK,
- "brkint", BRKINT, BRKINT,
- "ignpar", IGNPAR, IGNPAR,
- "parmrk", PARMRK, PARMRK,
- "inpck", INPCK, INPCK,
- "istrip", ISTRIP, ISTRIP,
- "inlcr", INLCR, INLCR,
- "igncr", IGNCR, IGNCR,
- "icrnl", ICRNL, ICRNL,
- "iuclc", IUCLC, IUCLC,
- "ixon", IXON, IXON,
- "ixany", IXANY, IXANY,
- "ixoff", IXOFF, IXOFF,
- 0, 0, 0
- };
-
- struct bits obits[] = {
- "opost", OPOST, OPOST,
- "olcuc", OLCUC, OLCUC,
- "onlcr", ONLCR, ONLCR,
- "ocrnl", OCRNL, OCRNL,
- "onocr", ONOCR, ONOCR,
- "onlret", ONLRET, ONLRET,
- "ofill", OFILL, OFILL,
- "ofdel", OFDEL, OFDEL,
- "nl1", NL1, NLDLY,
- "cr1", CR1, CRDLY,
- "cr2", CR2, CRDLY,
- "cr3", CR3, CRDLY,
- "tab1", TAB1, TABDLY,
- "tab2", TAB2, TABDLY,
- "tab3", TAB3, TABDLY,
- "bs1", BS1, BSDLY,
- "vt1", VT1, VTDLY,
- "ff1", FF1, FFDLY,
- 0, 0, 0
- };
-
- struct bits cbits[] = {
- "b50", B50, CBAUD,
- "b75", B75, CBAUD,
- "b110", B110, CBAUD,
- "b134", B134, CBAUD,
- "b150", B150, CBAUD,
- "b200", B200, CBAUD,
- "b300", B300, CBAUD,
- "b600", B600, CBAUD,
- "b1200", B1200, CBAUD,
- "b1800", B1800, CBAUD,
- "b2400", B2400, CBAUD,
- "b4800", B4800, CBAUD,
- "b9600", B9600, CBAUD,
- "exta", EXTA, CBAUD,
- "extb", EXTB, CBAUD,
- "cs6", CS6, CSIZE,
- "cs7", CS7, CSIZE,
- "cs8", CS8, CSIZE,
- "cstopb", CSTOPB, CSTOPB,
- "cread", CREAD, CREAD,
- "parenb", PARENB, PARENB,
- "parodd", PARODD, PARODD,
- "hupcl", HUPCL, HUPCL,
- "clocal", CLOCAL, CLOCAL,
- "loblk", LOBLK, LOBLK,
- "ctsflow", CTSFLOW,CTSFLOW,
- "rtsflow", RTSFLOW,RTSFLOW,
- 0, 0, 0
- };
-
- struct bits lbits[] = {
- "isig", ISIG, ISIG,
- "icanon", ICANON, ICANON,
- "xcase", XCASE, XCASE,
- "echo", ECHO, ECHO,
- "echoe", ECHOE, ECHOE,
- "echok", ECHOK, ECHOK,
- "echonl", ECHONL, ECHONL,
- "noflsh", NOFLSH, NOFLSH,
- 0, 0, 0
- };
-
- struct bits state[] = {
- "timeout", TIMEOUT, TIMEOUT,
- "wopen", WOPEN, WOPEN,
- "isopen", ISOPEN, ISOPEN,
- "tblock", TBLOCK, TBLOCK,
- "carr_on", CARR_ON, CARR_ON,
- "busy", BUSY, BUSY,
- "oaslp", OASLP, OASLP,
- "iaslp", IASLP, IASLP,
- "ttstop", TTSTOP, TTSTOP,
- "extproc", EXTPROC, EXTPROC,
- "tact", TACT, TACT,
- "clesc", CLESC, CLESC,
- "rto", RTO, RTO,
- "ttiow", TTIOW, TTIOW,
- "ttxon", TTXON, TTXON,
- "ttxoff", TTXOFF, TTXOFF,
- 0, 0, 0
- };
-
- static void
- prbits (table, value)
- struct bits *table;
- int value;
- {
- int i;
-
- for (i = 0;table[i].b_name;i++)
- if (table[i].b_value == (table[i].b_mask & value))
- printf (" %s", table[i].b_name);
- }
-
- prttys (string)
- char *string;
- {
- char *cp;
- char *device;
- int items[100];
- int cnt;
- long addr;
- long diff;
- int i, j;
- struct tty tty;
-
- while (*string && isspace (*string))
- string++;
-
- device = string;
-
- while (*string && *string != ',')
- string++;
-
- if (*string == ',') {
- *string++ = '\0';
- while (*string && isspace (*string))
- string++;
- }
- if (expr (&device, &addr)) {
- printf ("error in tty address at '%.15s'\n", device);
- return;
- }
- if (! *string) {
- printf ("no ttys requested\n");
- return;
- }
- if ((cnt = list (string, items, 100)) <= 0)
- return;
-
- *string++ = '\0';
-
- if (device = data2sym (addr, &diff))
- if (diff % sizeof tty != 0)
- device = (char *) 0;
-
- for (i = 0;i < cnt;i++) {
- if (l_lseek (memfd, addr + items[i] * sizeof tty, 0) == -1 ||
- r_read (memfd, &tty, sizeof tty) != sizeof tty)
- return;
-
- if (i != 0)
- putchar ('\n');
-
- if (device)
- printf ("%s[%d]:\n", device,
- diff / sizeof tty + items[i]);
- else
- printf ("tty[%d]:\n", items[i]);
-
- printf ("iflag:"); prbits (ibits, tty.t_iflag); putchar ('\n');
- printf ("oflag:"); prbits (obits, tty.t_oflag); putchar ('\n');
- printf ("cflag:"); prbits (cbits, tty.t_cflag); putchar ('\n');
- printf ("lflag:"); prbits (lbits, tty.t_lflag); putchar ('\n');
- printf ("state:"); prbits (state, tty.t_state); putchar ('\n');
- printf ("line disc: %d\n", tty.t_line);
- printf ("pgrp: %d\n", tty.t_pgrp);
-
- printf ("special characters:");
- for (j = 0;j < NCC;j++) {
- if (tty.t_cc[j] <= ' ' && tty.t_cc[j] >= 0)
- printf (" ^%c", tty.t_cc[j] + '@');
- else if (tty.t_cc[j] >= '~')
- printf (" %0.2x", tty.t_cc[j]);
- else
- printf (" '%c", tty.t_cc[j]);
- }
- putchar ('\n');
- }
- }
-