home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2870 / ttys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  4.6 KB  |  219 lines

  1. /*
  2.  * Copyright 1991, John F. Haugh II
  3.  * An unpublished work.
  4.  * All rights reserved.
  5.  *
  6.  * Permission is granted to copy and create derivative works for any
  7.  * non-commercial purpose, provided this copyright notice is preserved
  8.  * in all copies of source code, or included in human readable form
  9.  * and conspicuously displayed on all copies of object code or
  10.  * distribution media.
  11.  */
  12.  
  13. #ifndef    lint
  14. static    char    sccsid[] = "@(#)ttys.c    2.1    09:26:58    2/27/91";
  15. #endif
  16.  
  17. #include <sys/types.h>
  18. #include <sys/termio.h>
  19. #include <sys/tty.h>
  20. #include <ctype.h>
  21. #include "crash.h"
  22.  
  23. struct    bits {
  24.     char    *b_name;
  25.     int    b_value;
  26.     int    b_mask;
  27. };
  28.  
  29. struct    bits    ibits[] = {
  30.     "ignbrk",    IGNBRK,    IGNBRK,
  31.     "brkint",    BRKINT,    BRKINT,
  32.     "ignpar",    IGNPAR,    IGNPAR,
  33.     "parmrk",    PARMRK,    PARMRK,
  34.     "inpck",    INPCK,    INPCK,
  35.     "istrip",    ISTRIP,    ISTRIP,
  36.     "inlcr",    INLCR,    INLCR,
  37.     "igncr",    IGNCR,    IGNCR,
  38.     "icrnl",    ICRNL,    ICRNL,
  39.     "iuclc",    IUCLC,    IUCLC,
  40.     "ixon",        IXON,    IXON,
  41.     "ixany",    IXANY,    IXANY,
  42.     "ixoff",    IXOFF,    IXOFF,
  43.     0,        0,    0
  44. };
  45.  
  46. struct    bits    obits[] = {
  47.     "opost",    OPOST,    OPOST,
  48.     "olcuc",    OLCUC,    OLCUC,
  49.     "onlcr",    ONLCR,    ONLCR,
  50.     "ocrnl",    OCRNL,    OCRNL,
  51.     "onocr",    ONOCR,    ONOCR,
  52.     "onlret",    ONLRET,    ONLRET,
  53.     "ofill",    OFILL,    OFILL,
  54.     "ofdel",    OFDEL,    OFDEL,
  55.     "nl1",        NL1,    NLDLY,
  56.     "cr1",        CR1,    CRDLY,
  57.     "cr2",        CR2,    CRDLY,
  58.     "cr3",        CR3,    CRDLY,
  59.     "tab1",        TAB1,    TABDLY,
  60.     "tab2",        TAB2,    TABDLY,
  61.     "tab3",        TAB3,    TABDLY,
  62.     "bs1",        BS1,    BSDLY,
  63.     "vt1",        VT1,    VTDLY,
  64.     "ff1",        FF1,    FFDLY,
  65.     0,        0,    0
  66. };
  67.  
  68. struct    bits    cbits[] = {
  69.     "b50",        B50,    CBAUD,
  70.     "b75",        B75,    CBAUD,
  71.     "b110",        B110,    CBAUD,
  72.     "b134",        B134,    CBAUD,
  73.     "b150",        B150,    CBAUD,
  74.     "b200",        B200,    CBAUD,
  75.     "b300",        B300,    CBAUD,
  76.     "b600",        B600,    CBAUD,
  77.     "b1200",    B1200,    CBAUD,
  78.     "b1800",    B1800,    CBAUD,
  79.     "b2400",    B2400,    CBAUD,
  80.     "b4800",    B4800,    CBAUD,
  81.     "b9600",    B9600,    CBAUD,
  82.     "exta",        EXTA,    CBAUD,
  83.     "extb",        EXTB,    CBAUD,
  84.     "cs6",        CS6,    CSIZE,
  85.     "cs7",        CS7,    CSIZE,
  86.     "cs8",        CS8,    CSIZE,
  87.     "cstopb",    CSTOPB,    CSTOPB,
  88.     "cread",    CREAD,    CREAD,
  89.     "parenb",    PARENB,    PARENB,
  90.     "parodd",    PARODD,    PARODD,
  91.     "hupcl",    HUPCL,    HUPCL,
  92.     "clocal",    CLOCAL,    CLOCAL,
  93.     "loblk",    LOBLK,    LOBLK,
  94.     "ctsflow",    CTSFLOW,CTSFLOW,
  95.     "rtsflow",    RTSFLOW,RTSFLOW,
  96.     0,        0,    0
  97. };
  98.  
  99. struct    bits    lbits[] = {
  100.     "isig",        ISIG,    ISIG,
  101.     "icanon",    ICANON,    ICANON,
  102.     "xcase",    XCASE,    XCASE,
  103.     "echo",        ECHO,    ECHO,
  104.     "echoe",    ECHOE,    ECHOE,
  105.     "echok",    ECHOK,    ECHOK,
  106.     "echonl",    ECHONL,    ECHONL,
  107.     "noflsh",    NOFLSH,    NOFLSH,
  108.     0,        0,    0
  109. };
  110.  
  111. struct    bits    state[] = {
  112.     "timeout",    TIMEOUT,    TIMEOUT,
  113.     "wopen",    WOPEN,        WOPEN,
  114.     "isopen",    ISOPEN,        ISOPEN,
  115.     "tblock",    TBLOCK,        TBLOCK,
  116.     "carr_on",    CARR_ON,    CARR_ON,
  117.     "busy",        BUSY,        BUSY,
  118.     "oaslp",    OASLP,        OASLP,
  119.     "iaslp",    IASLP,        IASLP,
  120.     "ttstop",    TTSTOP,        TTSTOP,
  121.     "extproc",    EXTPROC,    EXTPROC,
  122.     "tact",        TACT,        TACT,
  123.     "clesc",    CLESC,        CLESC,
  124.     "rto",        RTO,        RTO,
  125.     "ttiow",    TTIOW,        TTIOW,
  126.     "ttxon",    TTXON,        TTXON,
  127.     "ttxoff",    TTXOFF,        TTXOFF,
  128.     0,        0,    0
  129. };
  130.  
  131. static void
  132. prbits (table, value)
  133. struct    bits    *table;
  134. int    value;
  135. {
  136.     int    i;
  137.  
  138.     for (i = 0;table[i].b_name;i++)
  139.         if (table[i].b_value == (table[i].b_mask & value))
  140.             printf (" %s", table[i].b_name);
  141. }
  142.  
  143. prttys (string)
  144. char    *string;
  145. {
  146.     char    *cp;
  147.     char    *device;
  148.     int    items[100];
  149.     int    cnt;
  150.     long    addr;
  151.     long    diff;
  152.     int    i, j;
  153.     struct    tty    tty;
  154.  
  155.     while (*string && isspace (*string))
  156.         string++;
  157.  
  158.     device = string;
  159.  
  160.     while (*string && *string != ',')
  161.         string++;
  162.  
  163.     if (*string == ',') {
  164.         *string++ = '\0';
  165.         while (*string && isspace (*string))
  166.             string++;
  167.     }
  168.     if (expr (&device, &addr)) {
  169.         printf ("error in tty address at '%.15s'\n", device);
  170.         return;
  171.     }
  172.     if (! *string) {
  173.         printf ("no ttys requested\n");
  174.         return;
  175.     }
  176.     if ((cnt = list (string, items, 100)) <= 0)
  177.         return;
  178.  
  179.     *string++ = '\0';
  180.  
  181.     if (device = data2sym (addr, &diff))
  182.         if (diff % sizeof tty != 0)
  183.             device = (char *) 0;
  184.  
  185.     for (i = 0;i < cnt;i++) {
  186.         if (l_lseek (memfd, addr + items[i] * sizeof tty, 0) == -1 ||
  187.                 r_read (memfd, &tty, sizeof tty) != sizeof tty)
  188.             return;
  189.  
  190.         if (i != 0)
  191.             putchar ('\n');
  192.  
  193.         if (device)
  194.             printf ("%s[%d]:\n", device,
  195.                 diff / sizeof tty + items[i]);
  196.         else
  197.             printf ("tty[%d]:\n", items[i]);
  198.  
  199.         printf ("iflag:"); prbits (ibits, tty.t_iflag); putchar ('\n');
  200.         printf ("oflag:"); prbits (obits, tty.t_oflag); putchar ('\n');
  201.         printf ("cflag:"); prbits (cbits, tty.t_cflag); putchar ('\n');
  202.         printf ("lflag:"); prbits (lbits, tty.t_lflag); putchar ('\n');
  203.         printf ("state:"); prbits (state, tty.t_state); putchar ('\n');
  204.         printf ("line disc: %d\n", tty.t_line);
  205.         printf ("pgrp: %d\n", tty.t_pgrp);
  206.  
  207.         printf ("special characters:");
  208.         for (j = 0;j < NCC;j++) {
  209.             if (tty.t_cc[j] <= ' ' && tty.t_cc[j] >= 0)
  210.                 printf (" ^%c", tty.t_cc[j] + '@');
  211.             else if (tty.t_cc[j] >= '~')
  212.                 printf (" %0.2x", tty.t_cc[j]);
  213.             else
  214.                 printf (" '%c", tty.t_cc[j]);
  215.         }
  216.         putchar ('\n');
  217.     }
  218. }
  219.