# 2.11BSD#431 - /usr/src/games/hack/hack.tty.c

##### Functions

    cgetret           X
    end_of_input      X
    error             X
    getlin            X
    getret            X
    gettty            X
    parse             X
    readchar          X
    setctty           X
    setftty           X
    settty            X
    xwaitforspace     X

##### Variables

    curttyb           X
    inittyb           X
    morc              X

##### Macros

    CBRKMASK          X
    CBRKON            X
    GTTY              X
    NR_OF_EOFS        X
    OSPEED            X
    STTY              X
    cbrkflgs          X
    echoflgs          X
    erase_sym         X
    kill_sym          X
    tabflgs           X
    termstruct        X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
       2: /* hack.tty.c - version 1.0.4 (2.11BSD) 1997/3/28 */
       3:
       4: #include    "hack.h"
       5: #include    <stdio.h>
       6:
       7: /*
       8:  * Some systems may have getchar() return EOF for various reasons, and
       9:  * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs.
      10:  * Also see the comment in config.h on `VERSION7'.
      11:  */
      12: #define NR_OF_EOFS  20
      13:
      14: #include    <sgtty.h>
      15: #define termstruct  sgttyb
      16: #define kill_sym    sg_kill
      17: #define erase_sym   sg_erase
      18: #define tabflgs     sg_flags
      19: #define echoflgs    sg_flags
      20: #define cbrkflgs    sg_flags
      21: #define CBRKMASK    CBREAK
      22: #define CBRKON      /* empty */
      23: #define OSPEED(x)   (x).sg_ospeed
      24: #define GTTY(x)     (gtty(0, x))
      25: #define STTY(x)     (stty(0, x))
      26:
      27: extern short ospeed;
      28: static char erase_char, kill_char;
      29: static boolean settty_needed = FALSE;
      30: struct termstruct inittyb, curttyb;
      31:
      32: /*
      33:  * Get initial state of terminal, set ospeed (for termcap routines)
      34:  * and switch off tab expansion if necessary.
      35:  * Called by startup() in termcap.c and after returning from ! or ^Z
      36:  */
      37: gettty(){
      38:     if(GTTY(&inittyb) < 0)
      39:         perror("Hack (gettty)");
      40:     curttyb = inittyb;
      41:     ospeed = OSPEED(inittyb);
      42:     erase_char = inittyb.erase_sym;
      43:     kill_char = inittyb.kill_sym;
      44:     getioctls();
      45:
      46:     /* do not expand tabs - they might be needed inside a cm sequence */
      47:     if(curttyb.tabflgs & XTABS) {
      48:         curttyb.tabflgs &= ~XTABS;
      49:         setctty();
      50:     }
      51:     settty_needed = TRUE;
      52: }
      53:
      54: /* reset terminal to original state */
      55: settty(s) char *s; {
      56:     clear_screen();
      57:     end_screen();
      58:     if(s) printf(s);
      59:     (void) fflush(stdout);
      60:     if(STTY(&inittyb) < 0)
      61:         perror("Hack (settty)");
      62:     flags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF;
      63:     flags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF;
      64:     setioctls();
      65: }
      66:
      67: setctty(){
      68:     if(STTY(&curttyb) < 0)
      69:         perror("Hack (setctty)");
      70: }
      71:
      72:
      73: setftty(){
      74: register int ef = 0;            /* desired value of flags & ECHO */
      75: register int cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */
      76: register int change = 0;
      77:     flags.cbreak = ON;
      78:     flags.echo = OFF;
      79:     /* Should use (ECHO|CRMOD) here instead of ECHO */
      80:     if((curttyb.echoflgs & ECHO) != ef){
      81:         curttyb.echoflgs &= ~ECHO;
      82: /*		curttyb.echoflgs |= ef;					*/
      83:         change++;
      84:     }
      85:     if((curttyb.cbrkflgs & CBRKMASK) != cf){
      86:         curttyb.cbrkflgs &= ~CBRKMASK;
      87:         curttyb.cbrkflgs |= cf;
      88:         change++;
      89:     }
      90:     if(change){
      91:         setctty();
      92:     }
      93:     start_screen();
      94: }
      95:
      96:
      97: /* fatal error */
      98: /*VARARGS1*/
      99: error(s,x,y) char *s; {
     100:     if(settty_needed)
     101:         settty((char *) 0);
     102:     printf(s,x,y);
     103:     putchar('\n');
     104:     exit(1);
     105: }
     106:
     107: /*
     108:  * Read a line closed with '\n' into the array char bufp[BUFSZ].
     109:  * (The '\n' is not stored. The string is closed with a '\0'.)
     110:  * Reading can be interrupted by an escape ('\033') - now the
     111:  * resulting string is "\033".
     112:  */
     113: getlin(bufp)
     114: register char *bufp;
     115: {
     116:     register char *obufp = bufp;
     117:     register int c;
     118:
     119:     flags.toplin = 2;       /* nonempty, no --More-- required */
     120:     for(;;) {
     121: /*		(void) fflush(stdout);	/* readchar already does this */
     122:         if((c = readchar()) == EOF) {
     123:             *bufp = 0;
     124:             return;
     125:         }
     126:         if(c == '\033') {
     127:             *obufp = c;
     128:             obufp[1] = 0;
     129:             return;
     130:         }
     131:         if(c == erase_char || c == '\b') {
     132:             if(bufp != obufp) {
     133:                 bufp--;
     134:                 putstr("\b \b"); /* putsym converts \b */
     135:             } else  bell();
     136:         } else if(c == '\n') {
     137:             *bufp = 0;
     138:             return;
     139:         } else if(' ' <= c && c < '\177') {
     140:                 /* avoid isprint() - some people don't have it
     141: 				   ' ' is not always a printing char */
     142:             *bufp = c;
     143:             bufp[1] = 0;
     144:             putstr(bufp);
     145:             if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)
     146:                 bufp++;
     147:         } else if(c == kill_char || c == '\177') { /* Robert Viduya */
     148:                 /* this test last - @ might be the kill_char */
     149:             while(bufp != obufp) {
     150:                 bufp--;
     151:                 putstr("\b \b");
     152:             }
     153:         } else
     154:             bell();
     155:     }
     156: }
     157:
     158: getret() {
     159:     cgetret("");
     160: }
     161:
     162: cgetret(s)
     163: register char *s;
     164: {
     165:     putsym('\n');
     166:     if(flags.standout)
     167:         standoutbeg();
     168:     putstr("Hit ");
     169:     putstr(flags.cbreak ? "space" : "return");
     170:     putstr(" to continue: ");
     171:     if(flags.standout)
     172:         standoutend();
     173:     xwaitforspace(s);
     174: }
     175:
     176: char morc;  /* tell the outside world what char he used */
     177:
     178: xwaitforspace(s)
     179: register char *s;   /* chars allowed besides space or return */
     180: {
     181: register int c;
     182:
     183:     morc = 0;
     184:
     185:     while((c = readchar()) != '\n') {
     186:         if(flags.cbreak) {
     187:         if(c == ' ') break;
     188:         if(s && index(s,c)) {
     189:             morc = c;
     190:             break;
     191:         }
     192:         bell();
     193:         }
     194:     }
     195: }
     196:
     197: char *
     198: parse()
     199: {
     200:     static char inline[COLNO];
     201:     register foo;
     202:
     203:     flags.move = 1;
     204:     if(!Invisible) curs_on_u(); else home();
     205:     while((foo = readchar()) >= '0' && foo <= '9')
     206:         multi = 10*multi+foo-'0';
     207:     if(multi) {
     208:         multi--;
     209:         save_cm = inline;
     210:     }
     211:     inline[0] = foo;
     212:     inline[1] = 0;
     213:     if(foo == 'f' || foo == 'F'){
     214:         inline[1] = readchar();
     215: #ifdef QUEST
     216:         if(inline[1] == foo) inline[2] = readchar(); else
     217: #endif QUEST
     218:         inline[2] = 0;
     219:     }
     220:     if(foo == 'm' || foo == 'M'){
     221:         inline[1] = readchar();
     222:         inline[2] = 0;
     223:     }
     224:     clrlin();
     225:     return(inline);
     226: }
     227:
     228: char
     229: readchar() {
     230:     register int sym;
     231:
     232:     (void) fflush(stdout);
     233:     if((sym = getchar()) == EOF)
     234: #ifdef NR_OF_EOFS
     235:     { /*
     236: 	   * VERSION7 and some SYSV systems seem to return EOFs for various
     237: 	   * reasons (?like when one hits break or for interrupted
     238: 	   * systemcalls?), and we must see several before we quit.
     239: 	   */
     240:         register int cnt = NR_OF_EOFS;
     241:         while (cnt--) {
     242:             clearerr(stdin);    /* omit if clearerr is undefined */
     243:             if((sym = getchar()) != EOF) goto noteof;
     244:         }
     245:         end_of_input();
     246:          noteof:    ;
     247:     }
     248: #else
     249:         end_of_input();
     250: #endif NR_OF_EOFS
     251:     if(flags.toplin == 1)
     252:         flags.toplin = 2;
     253:     return((char) sym);
     254: }
     255:
     256: end_of_input()
     257: {
     258:     settty("End of input?\n");
     259:     clearlocks();
     260:     exit(0);
     261: }

#### Defined functions

cgetret defined in line 162; used 2 times

- in line 159
- in /usr/src/games/hack/hack.pager.c line 262

end_of_input defined in line 256; used 4 times

- in line 245-249(2)
- in /usr/src/games/hack/hack.u_init.c line 118, 148

error defined in line 99; used 22 times

- in /usr/src/games/hack/hack.lev.c line 270
- in /usr/src/games/hack/hack.main.c line 70, 426, 473
- in /usr/src/games/hack/hack.o_init.c line 33, 47
- in /usr/src/games/hack/hack.pri.c line 149
- in /usr/src/games/hack/hack.termcap.c line 32-41(3), 52-55(2), 66, 76
- in /usr/src/games/hack/hack.unix.c line 131, 207, 222, 231-245(5)

getlin defined in line 113; used 11 times

- in /usr/src/games/hack/hack.cmd.c line 192
- in /usr/src/games/hack/hack.do_name.c line 75, 104, 169
- in /usr/src/games/hack/hack.engrave.c line 200
- in /usr/src/games/hack/hack.invent.c line 478
- in /usr/src/games/hack/hack.options.c line 179
- in /usr/src/games/hack/hack.read.c line 191
- in /usr/src/games/hack/hack.trap.c line 389
- in /usr/src/games/hack/hack.vault.c line 136
- in /usr/src/games/hack/hack.zap.c line 172

getret defined in line 158; used 8 times

- in /usr/src/games/hack/hack.end.c line 184
- in /usr/src/games/hack/hack.main.c line 486
- in /usr/src/games/hack/hack.options.c line 171
- in /usr/src/games/hack/hack.pager.c line 397
- in /usr/src/games/hack/hack.rip.c line 73
- in /usr/src/games/hack/hack.termcap.c line 68
- in /usr/src/games/hack/hack.u_init.c line 162
- in /usr/src/games/hack/hack.unix.c line 206

gettty defined in line 37; used 3 times

- in /usr/src/games/hack/hack.ioctl.c line 44
- in /usr/src/games/hack/hack.main.c line 112
- in /usr/src/games/hack/hack.pager.c line 391

parse defined in line 197; used 2 times

- in /usr/src/games/hack/hack.cmd.c line 90, 102

readchar defined in line 228; used 29 times

- in line 122, 185, 205, 214-221(3)
- in /usr/src/games/hack/hack.apply.c line 179-183(2)
- in /usr/src/games/hack/hack.c line 378
- in /usr/src/games/hack/hack.cmd.c line 244
- in /usr/src/games/hack/hack.do_name.c line 19, 141
- in /usr/src/games/hack/hack.do_wear.c line 51, 196
- in /usr/src/games/hack/hack.eat.c line 103
- in /usr/src/games/hack/hack.end.c line 17
- in /usr/src/games/hack/hack.h line 138
- in /usr/src/games/hack/hack.invent.c line 368-372(2), 536, 661
- in /usr/src/games/hack/hack.main.c line 425
- in /usr/src/games/hack/hack.pager.c line 22, 28, 44, 281
- in /usr/src/games/hack/hack.u_init.c line 98, 115, 138

setctty defined in line 67; used 2 times

- in line 49, 91

setftty defined in line 73; used 3 times

- in /usr/src/games/hack/hack.ioctl.c line 45
- in /usr/src/games/hack/hack.main.c line 240
- in /usr/src/games/hack/hack.pager.c line 392

settty defined in line 55; used 6 times

- in line 101, 258
- in /usr/src/games/hack/hack.end.c line 103
- in /usr/src/games/hack/hack.ioctl.c line 41
- in /usr/src/games/hack/hack.pager.c line 375
- in /usr/src/games/hack/hack.save.c line 17

xwaitforspace defined in line 178; used 2 times

- in line 173
- in /usr/src/games/hack/hack.topl.c line 89

#### Defined variables

curttyb defined in line 30; used 9 times

- in line 40, 47-48(2), 68, 80-87(5)

erase_char defined in line 28; used 2 times

- in line 42, 131

inittyb defined in line 30; used 8 times

- in line 38-43(5), 60-63(3)

kill_char defined in line 28; used 2 times

- in line 43, 147

morc defined in line 176; used 5 times

- in line 183, 189
- in /usr/src/games/hack/hack.invent.c line 394-398(2), 607

settty_needed defined in line 29; used 2 times

- in line 51, 100

#### Defined macros

CBRKMASK defined in line 21; used 4 times

- in line 63, 75, 85-86(2)

CBRKON defined in line 22; used 2 times

- in line 63, 75

GTTY defined in line 24; used 1 times

- in line 38

NR_OF_EOFS defined in line 12; used 2 times

- in line 234, 240

OSPEED defined in line 23; used 1 times

- in line 41

STTY defined in line 25; used 2 times

- in line 60, 68

cbrkflgs defined in line 20; used 4 times

- in line 63, 85-87(3)

echoflgs defined in line 19; used 3 times

- in line 62, 80-81(2)

erase_sym defined in line 17; used 1 times

- in line 42

kill_sym defined in line 16; used 1 times

- in line 43

tabflgs defined in line 18; used 2 times

- in line 47-48(2)

termstruct defined in line 15; never used

Last modified: 1997-03-28 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1382 |