1: #
   2: /*
   3:  * getty -- adapt to terminal speed on dialup, and call login
   4:  */
   5: 
   6: /*
   7:  * tty flags
   8:  */
   9: #define HUPCL 01
  10: #define XTABS   02
  11: #define LCASE   04
  12: #define ECHO    010
  13: #define CRMOD   020
  14: #define RAW 040
  15: #define ODDP    0100
  16: #define EVENP   0200
  17: #define ANYP    0300
  18: 
  19: /*
  20:  * Delay algorithms
  21:  */
  22: #define CR1 010000
  23: #define CR2 020000
  24: #define CR3 030000
  25: #define NL1 000400
  26: #define NL2 001000
  27: #define NL3 001400
  28: #define TAB1    002000
  29: #define TAB2    004000
  30: #define TAB3    006000
  31: #define FF1 040000
  32: 
  33: #define ERASE   '#'
  34: #define KILL    '@'
  35: 
  36: /*
  37:  * speeds
  38:  */
  39: #define B110    3
  40: #define B150    5
  41: #define B300    7
  42: #define B9600   13
  43: 
  44: #define SIGINT  2
  45: #define SIGQIT  3
  46: 
  47: struct  sgtty {
  48:     char    sgispd, sgospd;
  49:     char    sgerase, sgkill;
  50:     int sgflag;
  51: } tmode;
  52: 
  53: struct  tab {
  54:     int tname;      /* this table name */
  55:     int nname;      /* successor table name */
  56:     int iflags;     /* initial flags */
  57:     int fflags;     /* final flags */
  58:     int ispeed;     /* input speed */
  59:     int ospeed;     /* output speed */
  60:     char    *message;   /* login message */
  61: } itab[] {
  62: 
  63: /* table '0'-1-2 300,150,110 */
  64: 
  65:     '0', 1,
  66:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CR1,
  67:     B300, B300,
  68:     "\n\r\033;\007login: ",
  69: 
  70:     1, 2,
  71:     ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1,
  72:     B150, B150,
  73:     "\n\r\033:\006\006\017login: ",
  74: 
  75:     2, '0',
  76:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1,
  77:     B110, B110,
  78:     "\n\rlogin: ",
  79: 
  80: /* table '-' -- Console TTY 110 */
  81:     '-', '-',
  82:     ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1,
  83:     B110, B110,
  84:     "\n\rlogin: ",
  85: 
  86: /* table '1' -- 150 */
  87:     '1', '1',
  88:     ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1,
  89:     B150, B150,
  90:     "\n\r\033:\006\006\017login: ",
  91: 
  92: /* table '2' -- 9600 */
  93:     '2', '2',
  94:     ANYP+RAW+NL1+CR1, ANYP+XTABS+ECHO+CRMOD+FF1,
  95:     B9600, B9600,
  96:     "\n\r\033;login: ",
  97: };
  98: 
  99: #define NITAB   sizeof itab/sizeof itab[0]
 100: 
 101: char    name[16];
 102: int crmod;
 103: int upper;
 104: int lower;
 105: 
 106: main(argc, argv)
 107: char **argv;
 108: {
 109:     register struct tab *tabp;
 110:     register tname;
 111: 
 112: /*
 113: 	signal(SIGINT, 1);
 114: 	signal(SIGQIT, 0);
 115: */
 116:     tname = '0';
 117:     if (argc > 1)
 118:         tname = *argv[1];
 119:     for (;;) {
 120:         for(tabp = itab; tabp < &itab[NITAB]; tabp++)
 121:             if(tabp->tname == tname)
 122:                 break;
 123:         if(tabp >= &itab[NITAB])
 124:             tabp = itab;
 125:         tmode.sgispd = tabp->ispeed;
 126:         tmode.sgospd = tabp->ospeed;
 127:         tmode.sgflag = tabp->iflags;
 128:         tmode.sgispd = tabp->ispeed;
 129:         tmode.sgospd = tabp->ospeed;
 130:         stty(0, &tmode);
 131:         puts(tabp->message);
 132:         stty(0, &tmode);
 133:         if(getname()) {
 134:             tmode.sgerase = ERASE;
 135:             tmode.sgkill = KILL;
 136:             tmode.sgflag = tabp->fflags;
 137:             if(crmod)
 138:                 tmode.sgflag =| CRMOD;
 139:             if(upper)
 140:                 tmode.sgflag =| LCASE;
 141:             if(lower)
 142:                 tmode.sgflag =& ~LCASE;
 143:             stty(0, &tmode);
 144:             execl("/bin/login", "login", name, 0);
 145:             exit(1);
 146:         }
 147:         tname = tabp->nname;
 148:     }
 149: }
 150: 
 151: getname()
 152: {
 153:     register char *np;
 154:     register c;
 155:     static cs;
 156: 
 157:     crmod = 0;
 158:     upper = 0;
 159:     lower = 0;
 160:     np = name;
 161:     do {
 162:         if (read(0, &cs, 1) <= 0)
 163:             exit(0);
 164:         if ((c = cs&0177) == 0)
 165:             return(0);
 166:         write(1, &cs, 1);
 167:         if (c>='a' && c <='z')
 168:             lower++;
 169:         else if (c>='A' && c<='Z') {
 170:             upper++;
 171:             c =+ 'a'-'A';
 172:         } else if (c==ERASE) {
 173:             if (np > name)
 174:                 np--;
 175:             continue;
 176:         } else if (c==KILL) {
 177:             np = name;
 178:             continue;
 179:         }
 180:         *np++ = c;
 181:     } while (c!='\n' && c!='\r' && np <= &name[16]);
 182:     *--np = 0;
 183:     if (c == '\r') {
 184:         write(1, "\n", 1);
 185:         crmod++;
 186:     } else
 187:         write(1, "\r", 1);
 188:     return(1);
 189: }
 190: 
 191: puts(as)
 192: char *as;
 193: {
 194:     register char *s;
 195: 
 196:     s = as;
 197:     while (*s)
 198:         write(1, s++, 1);
 199: }

Defined functions

getname defined in line 151; used 1 times
main defined in line 106; never used
puts defined in line 191; used 1 times

Defined variables

crmod defined in line 102; used 3 times
itab defined in line 61; used 6 times
lower defined in line 104; used 3 times
name defined in line 101; used 5 times
tmode defined in line 51; used 14 times
upper defined in line 103; used 3 times

Defined struct's

sgtty defined in line 47; never used
tab defined in line 53; used 2 times
  • in line 109(2)

Defined macros

ANYP defined in line 17; used 10 times
B110 defined in line 39; used 4 times
  • in line 77(2), 83(2)
B150 defined in line 40; used 4 times
  • in line 72(2), 89(2)
B300 defined in line 41; used 2 times
  • in line 67(2)
B9600 defined in line 42; used 2 times
  • in line 95(2)
CR1 defined in line 22; used 9 times
CR2 defined in line 23; used 2 times
CR3 defined in line 24; never used
CRMOD defined in line 13; used 4 times
ECHO defined in line 12; used 6 times
ERASE defined in line 33; used 2 times
EVENP defined in line 16; used 2 times
FF1 defined in line 31; used 3 times
HUPCL defined in line 9; never used
KILL defined in line 34; used 2 times
LCASE defined in line 11; used 4 times
NITAB defined in line 99; used 2 times
NL1 defined in line 25; used 8 times
NL2 defined in line 26; never used
NL3 defined in line 27; never used
ODDP defined in line 15; never used
RAW defined in line 14; used 6 times
SIGINT defined in line 44; never used
SIGQIT defined in line 45; never used
TAB1 defined in line 28; used 2 times
TAB2 defined in line 29; never used
TAB3 defined in line 30; never used
XTABS defined in line 10; used 3 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 959
Valid CSS Valid XHTML 1.0 Strict