1: #
   2: /*
   3:  * getty -- adapt to terminal speed on dialup, and call login
   4:  */
   5: 
   6: #include <sgtty.h>
   7: #include <signal.h>
   8: #define ERASE   '#'
   9: #define KILL    '@'
  10: 
  11: struct sgttyb tmode;
  12: struct tchars tchars = { '\177', '\034', '\021', '\023', '\004', '\377' };
  13: 
  14: struct  tab {
  15:     char    tname;      /* this table name */
  16:     char    nname;      /* successor table name */
  17:     int iflags;     /* initial flags */
  18:     int fflags;     /* final flags */
  19:     int ispeed;     /* input speed */
  20:     int ospeed;     /* output speed */
  21:     char    *message;   /* login message */
  22: } itab[] = {
  23: 
  24: /* table '0'-1-2-3 300,1200,150,110 */
  25: 
  26:     '0', 1,
  27:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CR1,
  28:     B300, B300,
  29:     "\n\r\033;\007login: ",
  30: 
  31:     1, 2,
  32:     ANYP+RAW+NL1+CR1, ANYP+XTABS+ECHO+CRMOD+FF1,
  33:     B1200, B1200,
  34:     "\n\r\033;login: ",
  35: 
  36:     2, 3,
  37:     ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1,
  38:     B150, B150,
  39:     "\n\r\033:\006\006\017login: ",
  40: 
  41:     3, '0',
  42:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1,
  43:     B110, B110,
  44:     "\n\rlogin: ",
  45: 
  46: /* table '-' -- Console TTY 110 */
  47:     '-', '-',
  48:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1,
  49:     B110, B110,
  50:     "\n\rlogin: ",
  51: 
  52: /* table '1' -- 150 */
  53:     '1', '1',
  54:     ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1,
  55:     B150, B150,
  56:     "\n\r\033:\006\006\017login: ",
  57: 
  58: /* table '2' -- 9600 */
  59:     '2', '2',
  60:     ANYP+RAW+NL1+CR1, ANYP+XTABS+ECHO+CRMOD+FF1,
  61:     B9600, B9600,
  62:     "\n\r\033;login: ",
  63: 
  64: /* table '3'-'5' -- 1200,300 */
  65:     '3', '5',
  66:     ANYP+RAW+NL1+CR1, ANYP+XTABS+ECHO+CRMOD+FF1,
  67:     B1200, B1200,
  68:     "\n\r\033;login: ",
  69: 
  70: /* table '5'-'3' -- 300,1200 */
  71:     '5', '3',
  72:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CR1,
  73:     B300, B300,
  74:     "\n\r\033;\007login: ",
  75: 
  76: /* table '4' -- Console Decwriter */
  77:     '4', '4',
  78:     ANYP+RAW, ANYP+ECHO+CRMOD+XTABS,
  79:     B300, B300,
  80:     "\n\rlogin: ",
  81: 
  82: /* table 'i' -- Interdata Console */
  83:     'i', 'i',
  84:     RAW+CRMOD, CRMOD+ECHO+LCASE,
  85:     0, 0,
  86:     "\n\rlogin: ",
  87: 
  88: /* table 'l' -- LSI Chess Terminal */
  89:     'l', 'l',
  90:     ANYP+RAW/*+HUPCL*/, ANYP+ECHO/*+HUPCL*/,
  91:     B300, B300,
  92:     "*",
  93: /* table '6' -- 2400 11/23 line */
  94:     '6', '6',
  95:     ANYP+RAW+NL1+CR1, ANYP+ECHO,
  96:     B2400, B2400,
  97:     "\n\rlogin: ",
  98: 
  99: };
 100: 
 101: #define NITAB   sizeof itab/sizeof itab[0]
 102: #define EOT 04      /* EOT char */
 103: 
 104: char    name[16];
 105: int crmod;
 106: int upper;
 107: int lower;
 108: 
 109: char partab[] = {
 110:     0001,0201,0201,0001,0201,0001,0001,0201,
 111:     0202,0004,0003,0205,0005,0206,0201,0001,
 112:     0201,0001,0001,0201,0001,0201,0201,0001,
 113:     0001,0201,0201,0001,0201,0001,0001,0201,
 114:     0200,0000,0000,0200,0000,0200,0200,0000,
 115:     0000,0200,0200,0000,0200,0000,0000,0200,
 116:     0000,0200,0200,0000,0200,0000,0000,0200,
 117:     0200,0000,0000,0200,0000,0200,0200,0000,
 118:     0200,0000,0000,0200,0000,0200,0200,0000,
 119:     0000,0200,0200,0000,0200,0000,0000,0200,
 120:     0000,0200,0200,0000,0200,0000,0000,0200,
 121:     0200,0000,0000,0200,0000,0200,0200,0000,
 122:     0000,0200,0200,0000,0200,0000,0000,0200,
 123:     0200,0000,0000,0200,0000,0200,0200,0000,
 124:     0200,0000,0000,0200,0000,0200,0200,0000,
 125:     0000,0200,0200,0000,0200,0000,0000,0201
 126: };
 127: 
 128: main(argc, argv)
 129: char **argv;
 130: {
 131:     register struct tab *tabp;
 132:     int tname;
 133: 
 134:     tname = '0';
 135:     if (argc > 1)
 136:         tname = argv[1][0];
 137:     switch (tname) {
 138: 
 139:     case '3':       /* adapt to connect speed (212) */
 140:         ioctl(0, TIOCGETP, &tmode);
 141:         if (tmode.sg_ispeed==B300)
 142:             tname = '0';
 143:         else
 144:             tname = '3';
 145:         break;
 146:     }
 147:     for (;;) {
 148:         for(tabp = itab; tabp < &itab[NITAB]; tabp++)
 149:             if(tabp->tname == tname)
 150:                 break;
 151:         if(tabp >= &itab[NITAB])
 152:             tabp = itab;
 153:         tmode.sg_flags = tabp->iflags;
 154:         tmode.sg_ispeed = tabp->ispeed;
 155:         tmode.sg_ospeed = tabp->ospeed;
 156:         ioctl(0, TIOCSETP, &tmode);
 157:         ioctl(0, TIOCSETC, &tchars);
 158:         puts(tabp->message);
 159:         if(getname()) {
 160:             tmode.sg_erase = ERASE;
 161:             tmode.sg_kill = KILL;
 162:             tmode.sg_flags = tabp->fflags;
 163:             if(crmod)
 164:                 tmode.sg_flags |= CRMOD;
 165:             if(upper)
 166:                 tmode.sg_flags |= LCASE;
 167:             if(lower)
 168:                 tmode.sg_flags &= ~LCASE;
 169:             stty(0, &tmode);
 170:             putchr('\n');
 171:             execl("/bin/login", "login", name, 0);
 172:             exit(1);
 173:         }
 174:         tname = tabp->nname;
 175:     }
 176: }
 177: 
 178: getname()
 179: {
 180:     register char *np;
 181:     register c;
 182:     char cs;
 183: 
 184:     crmod = 0;
 185:     upper = 0;
 186:     lower = 0;
 187:     np = name;
 188:     for (;;) {
 189:         if (read(0, &cs, 1) <= 0)
 190:             exit(0);
 191:         if ((c = cs&0177) == 0)
 192:             return(0);
 193:         if (c==EOT)
 194:             exit(1);
 195:         if (c=='\r' || c=='\n' || np >= &name[16])
 196:             break;
 197:         putchr(cs);
 198:         if (c>='a' && c <='z')
 199:             lower++;
 200:         else if (c>='A' && c<='Z') {
 201:             upper++;
 202:             c += 'a'-'A';
 203:         } else if (c==ERASE) {
 204:             if (np > name)
 205:                 np--;
 206:             continue;
 207:         } else if (c==KILL) {
 208:             putchr('\r');
 209:             putchr('\n');
 210:             np = name;
 211:             continue;
 212:         } else if(c == ' ')
 213:             c = '_';
 214:         *np++ = c;
 215:     }
 216:     *np = 0;
 217:     if (c == '\r')
 218:         crmod++;
 219:     return(1);
 220: }
 221: 
 222: puts(as)
 223: char *as;
 224: {
 225:     register char *s;
 226: 
 227:     s = as;
 228:     while (*s)
 229:         putchr(*s++);
 230: }
 231: 
 232: putchr(cc)
 233: {
 234:     char c;
 235:     c = cc;
 236:     c |= partab[c&0177] & 0200;
 237:     write(1, &c, 1);
 238: }

Defined functions

getname defined in line 178; used 1 times
main defined in line 128; never used
putchr defined in line 232; used 5 times
puts defined in line 222; used 1 times

Defined variables

crmod defined in line 105; used 3 times
itab defined in line 22; used 6 times
lower defined in line 107; used 3 times
name defined in line 104; used 5 times
partab defined in line 109; used 1 times
tchars defined in line 12; used 1 times
tmode defined in line 11; used 13 times
upper defined in line 106; used 3 times

Defined struct's

tab defined in line 14; used 2 times
  • in line 131(2)

Defined macros

EOT defined in line 102; used 1 times
ERASE defined in line 8; used 2 times
KILL defined in line 9; used 2 times
NITAB defined in line 101; used 2 times
Last modified: 1979-05-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 797
Valid CSS Valid XHTML 1.0 Strict