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

##### Functions

    addtopl           X
    clrlin            X
    cmore             X
    doredotopl        X
    more              X
    pline             X
    putstr            X
    putsym            X
    redotoplin        X
    remember_topl     X
    xmore             X

##### Variables

    last_redone_topl  X
    old_toplines      X
    tlx               X
    tly               X
    toplines          X

##### Macros

    OTLMAX            X

##### struct's

    topl              X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
       2: /* hack.topl.c - version 1.0.2 */
       3:
       4: #include "hack.h"
       5: #include <stdio.h>
       6: extern char *eos();
       7: extern int CO;
       8:
       9: char toplines[BUFSZ];
      10: xchar tlx, tly;         /* set by pline; used by addtopl */
      11:
      12: struct topl {
      13:     struct topl *next_topl;
      14:     char *topl_text;
      15: } *old_toplines, *last_redone_topl;
      16: #define OTLMAX  3       /* max nr of old toplines remembered */
      17:
      18: doredotopl(){
      19:     if(last_redone_topl)
      20:         last_redone_topl = last_redone_topl->next_topl;
      21:     if(!last_redone_topl)
      22:         last_redone_topl = old_toplines;
      23:     if(last_redone_topl){
      24:         (void) strcpy(toplines, last_redone_topl->topl_text);
      25:     }
      26:     redotoplin();
      27:     return(0);
      28: }
      29:
      30: redotoplin() {
      31:     home();
      32:     if(index(toplines, '\n')) cl_end();
      33:     putstr(toplines);
      34:     cl_end();
      35:     tlx = curx;
      36:     tly = cury;
      37:     flags.toplin = 1;
      38:     if(tly > 1)
      39:         more();
      40: }
      41:
      42: remember_topl() {
      43: register struct topl *tl;
      44: register int cnt = OTLMAX;
      45:     if(last_redone_topl &&
      46:        !strcmp(toplines, last_redone_topl->topl_text)) return;
      47:     if(old_toplines &&
      48:        !strcmp(toplines, old_toplines->topl_text)) return;
      49:     last_redone_topl = 0;
      50:     tl = (struct topl *)
      51:         alloc((unsigned)(strlen(toplines) + sizeof(struct topl) + 1));
      52:     tl->next_topl = old_toplines;
      53:     tl->topl_text = (char *)(tl + 1);
      54:     (void) strcpy(tl->topl_text, toplines);
      55:     old_toplines = tl;
      56:     while(cnt && tl){
      57:         cnt--;
      58:         tl = tl->next_topl;
      59:     }
      60:     if(tl && tl->next_topl){
      61:         free((char *) tl->next_topl);
      62:         tl->next_topl = 0;
      63:     }
      64: }
      65:
      66: addtopl(s) char *s; {
      67:     curs(tlx,tly);
      68:     if(tlx + strlen(s) > CO) putsym('\n');
      69:     putstr(s);
      70:     tlx = curx;
      71:     tly = cury;
      72:     flags.toplin = 1;
      73: }
      74:
      75: xmore(s)
      76: char *s;    /* allowed chars besides space/return */
      77: {
      78:     if(flags.toplin) {
      79:         curs(tlx, tly);
      80:         if(tlx + 8 > CO) putsym('\n'), tly++;
      81:     }
      82:
      83:     if(flags.standout)
      84:         standoutbeg();
      85:     putstr("--More--");
      86:     if(flags.standout)
      87:         standoutend();
      88:
      89:     xwaitforspace(s);
      90:     if(flags.toplin && tly > 1) {
      91:         home();
      92:         cl_end();
      93:         docorner(1, tly-1);
      94:     }
      95:     flags.toplin = 0;
      96: }
      97:
      98: more(){
      99:     xmore("");
     100: }
     101:
     102: cmore(s)
     103: register char *s;
     104: {
     105:     xmore(s);
     106: }
     107:
     108: clrlin(){
     109:     if(flags.toplin) {
     110:         home();
     111:         cl_end();
     112:         if(tly > 1) docorner(1, tly-1);
     113:         remember_topl();
     114:     }
     115:     flags.toplin = 0;
     116: }
     117:
     118: /*VARARGS1*/
     119: pline(line,arg1,arg2,arg3,arg4,arg5,arg6)
     120: register char *line,*arg1,*arg2,*arg3,*arg4,*arg5,*arg6;
     121: {
     122:     char pbuf[BUFSZ];
     123:     register char *bp = pbuf, *tl;
     124:     register int n,n0;
     125:
     126:     if(!line || !*line) return;
     127:     if(!index(line, '%')) (void) strcpy(pbuf,line); else
     128:     (void) sprintf(pbuf,line,arg1,arg2,arg3,arg4,arg5,arg6);
     129:     if(flags.toplin == 1 && !strcmp(pbuf, toplines)) return;
     130:     nscr();     /* %% */
     131:
     132:     /* If there is room on the line, print message on same line */
     133:     /* But messages like "You die..." deserve their own line */
     134:     n0 = strlen(bp);
     135:     if(flags.toplin == 1 && tly == 1 &&
     136:         n0 + strlen(toplines) + 3 < CO-8 &&  /* leave room for --More-- */
     137:         strncmp(bp, "You ", STRLEN("You "))) {
     138:         (void) strcat(toplines, "  ");
     139:         (void) strcat(toplines, bp);
     140:         tlx += 2;
     141:         addtopl(bp);
     142:         return;
     143:     }
     144:     if(flags.toplin == 1) more();
     145:     remember_topl();
     146:     toplines[0] = 0;
     147:     while(n0){
     148:         if(n0 >= CO){
     149:             /* look for appropriate cut point */
     150:             n0 = 0;
     151:             for(n = 0; n < CO; n++) if(bp[n] == ' ')
     152:                 n0 = n;
     153:             if(!n0) for(n = 0; n < CO-1; n++)
     154:                 if(!letter(bp[n])) n0 = n;
     155:             if(!n0) n0 = CO-2;
     156:         }
     157:         (void) strncpy((tl = eos(toplines)), bp, n0);
     158:         tl[n0] = 0;
     159:         bp += n0;
     160:
     161:         /* remove trailing spaces, but leave one */
     162:         while(n0 > 1 && tl[n0-1] == ' ' && tl[n0-2] == ' ')
     163:             tl[--n0] = 0;
     164:
     165:         n0 = strlen(bp);
     166:         if(n0 && tl[0]) (void) strcat(tl, "\n");
     167:     }
     168:     redotoplin();
     169: }
     170:
     171: putsym(c) char c; {
     172:     switch(c) {
     173:     case '\b':
     174:         backsp();
     175:         return;
     176:     case '\n':
     177:         curx = 1;
     178:         cury++;
     179:         if(cury > tly) tly = cury;
     180:         break;
     181:     default:
     182:         if(curx == CO)
     183:             putsym('\n');   /* 1 <= curx <= CO; avoid CO */
     184:         else
     185:             curx++;
     186:     }
     187:     (void) putchar(c);
     188: }
     189:
     190: putstr(s) register char *s; {
     191:     while(*s) putsym(*s++);
     192: }

#### Defined functions

addtopl defined in line 66; used 2 times

- in line 141
- in /usr/src/games/hack/hack.invent.c line 535

clrlin defined in line 108; used 10 times

- in /usr/src/games/hack/hack.cmd.c line 193
- in /usr/src/games/hack/hack.do_name.c line 76, 105, 170
- in /usr/src/games/hack/hack.end.c line 19
- in /usr/src/games/hack/hack.engrave.c line 201
- in /usr/src/games/hack/hack.invent.c line 480
- in /usr/src/games/hack/hack.pager.c line 118
- in /usr/src/games/hack/hack.tty.c line 224
- in /usr/src/games/hack/hack.vault.c line 145

cmore defined in line 102; used 2 times

- in /usr/src/games/hack/hack.pager.c line 151, 249

doredotopl defined in line 18; used 2 times

- in /usr/src/games/hack/hack.cmd.c line 7, 21

more defined in line 98; used 15 times

- in line 39, 144
- in /usr/src/games/hack/hack.end.c line 93
- in /usr/src/games/hack/hack.mkshop.c line 98
- in /usr/src/games/hack/hack.mon.c line 119
- in /usr/src/games/hack/hack.pager.c line 129, 230
- in /usr/src/games/hack/hack.potion.c line 85, 105
- in /usr/src/games/hack/hack.pri.c line 49, 654
- in /usr/src/games/hack/hack.read.c line 278, 308
- in /usr/src/games/hack/hack.unix.c line 339, 407

pline defined in line 119; used 634 times

- in /usr/src/games/hack/hack.apply.c line 43-53(5), 71-75(2), 82, 89, 114-127(4), 176-182(3), 218, 234, 266, 279, 305, 312-316(2), 331, 338-342(2), 366-370(3), 385, 391, 401-411(3), 421-428(3), 437-441(2)
- in /usr/src/games/hack/hack.bones.c line 91
- in /usr/src/games/hack/hack.c line 89, 121-122(2), 142-145(2), 165-166(2), 172-178(3), 186-187(2), 201-210(3), 219, 237, 324-328(2), 343, 362, 377, 386-387(2), 399, 422, 434, 443-446(2), 755
- in /usr/src/games/hack/hack.cmd.c line 181, 191, 201, 243-247(2), 269, 280
- in /usr/src/games/hack/hack.do.c line 30-33(2), 41-51(3), 86-94(3), 105-113(3), 142, 172-173(2), 189, 196-200(2), 220, 264, 272, 289-307(6), 373-374(2), 384, 392, 417-422(3), 485-487(2)
- in /usr/src/games/hack/hack.do_name.c line 15, 28-31(3), 60-74(5), 103, 140, 168
- in /usr/src/games/hack/hack.do_wear.c line 11, 17, 27-31(2), 40, 50, 80, 117-137(6), 144, 152, 173, 179-187(3), 195, 249, 292, 308, 329-333(2)
- in /usr/src/games/hack/hack.dog.c line 133-140(4), 317, 401
- in /usr/src/games/hack/hack.eat.c line 57, 63-74(4), 99, 133-139(3), 163-175(5), 182-183(2), 190-194(3), 201-209(3), 215-217(2), 226-232(3), 308, 319, 332-337(2), 345, 367-381(5), 398, 437, 443, 449
- in /usr/src/games/hack/hack.end.c line 16, 45, 72
- in /usr/src/games/hack/hack.engrave.c line 87-98(4), 134, 152-163(5), 177, 184-198(4), 222
- in /usr/src/games/hack/hack.fight.c line 34, 40, 47-49(2), 59-61(2), 116-121(4), 141-142(2), 159, 174, 181, 188, 210, 231-240(4), 270-276(3), 289, 319-320(2), 340, 350-353(2)
- in /usr/src/games/hack/hack.invent.c line 356, 362-364(2), 375, 385, 411-415(2), 422, 455, 476, 491, 502, 534, 553, 575, 610, 639, 659, 673-678(2), 692, 708-710(2), 719, 729-730(2), 743, 749, 796, 805-809(3), 820, 827, 845
- in /usr/src/games/hack/hack.ioctl.c line 48-51(2)
- in /usr/src/games/hack/hack.lev.c line 171-173(3), 267
- in /usr/src/games/hack/hack.main.c line 246-250(2), 281, 290-293(2), 315, 321-323(2), 347, 444-445(2), 496
- in /usr/src/games/hack/hack.mhitu.c line 23-27(3), 46, 94-99(2), 107-109(2), 119, 147-154(3), 192, 202, 223, 239, 245, 297, 307, 335, 352-357(4)
- in /usr/src/games/hack/hack.mklev.c line 261, 383
- in /usr/src/games/hack/hack.mkshop.c line 53, 89-95(4)
- in /usr/src/games/hack/hack.mon.c line 44, 101, 135, 307-309(2), 566-569(3), 575, 670-676(3), 730, 770-772(3), 835
- in /usr/src/games/hack/hack.o_init.c line 145
- in /usr/src/games/hack/hack.objnam.c line 16
- in /usr/src/games/hack/hack.options.c line 84, 101, 146-156(4), 162-163(2), 178, 198
- in /usr/src/games/hack/hack.pager.c line 25-27(2), 41-43(2), 52, 225, 280, 299, 326, 346, 384
- in /usr/src/games/hack/hack.potion.c line 24, 32-37(2), 47-49(2), 55-59(2), 69-71(2), 84, 97, 104, 110-112(2), 118, 124, 138-145(3), 155, 177, 195, 203, 213-215(2), 235, 241-246(2), 256, 316-331(5), 363, 379-384(3)
- in /usr/src/games/hack/hack.pri.c line 645-646(2)
- in /usr/src/games/hack/hack.read.c line 18-26(4), 42, 48-53(2), 66, 72-78(3), 88-91(2), 110-112(2), 118-127(4), 154, 163, 185-190(2), 198, 206, 246, 253, 267, 274, 296, 306, 316-318(2), 332, 371, 380-385(3), 409-414(3), 457-481(8)
- in /usr/src/games/hack/hack.rumors.c line 36-37(2)
- in /usr/src/games/hack/hack.save.c line 40, 70
- in /usr/src/games/hack/hack.search.c line 58, 78, 85, 110-113(2)
- in /usr/src/games/hack/hack.shk.c line 139-141(2), 159-168(4), 202, 214, 254-257(2), 321, 327-343(5), 359-367(4), 375-389(5), 411, 443, 449, 458, 472-477(2), 517, 586, 597, 608, 615-618(2), 737, 769, 805, 815, 853, 961-967(3)
- in /usr/src/games/hack/hack.steal.c line 19, 27, 48, 72-74(2), 104, 146, 170
- in /usr/src/games/hack/hack.timeout.c line 18-34(5), 57
- in /usr/src/games/hack/hack.trap.c line 44-66(6), 72, 80-81(2), 91-93(2), 101, 122-126(3), 160-164(2), 173, 180, 187-192(2), 199, 209, 215, 230-231(2), 241-251(4), 288, 296, 344-348(2), 388, 399-404(4), 412-418(4), 429-430(2), 440-444(2)
- in /usr/src/games/hack/hack.unix.c line 137-141(2), 292, 310, 335-338(2)
- in /usr/src/games/hack/hack.vault.c line 132-140(3), 146-151(4)
- in /usr/src/games/hack/hack.version.c line 8
- in /usr/src/games/hack/hack.wield.c line 19-39(7), 50-52(2), 72, 79, 85, 94
- in /usr/src/games/hack/hack.wizard.c line 29, 109-112(2), 122-129(3), 137, 156
- in /usr/src/games/hack/hack.worm.c line 156, 165
- in /usr/src/games/hack/hack.zap.c line 129-133(2), 168-171(2), 192, 201-202(2), 276-277(2), 284-285(2), 376, 412, 426, 454-456(2), 466, 481, 488, 498, 505-510(2), 636-639(2)

putstr defined in line 190; used 10 times

- in line 33, 69, 85
- in /usr/src/games/hack/hack.pager.c line 244
- in /usr/src/games/hack/hack.tty.c line 134, 144, 151, 168-170(3)

putsym defined in line 171; used 6 times

- in line 68, 80, 183, 191
- in /usr/src/games/hack/hack.pager.c line 243
- in /usr/src/games/hack/hack.tty.c line 165

redotoplin defined in line 30; used 2 times

- in line 26, 168

remember_topl defined in line 42; used 3 times

- in line 113, 145
- in /usr/src/games/hack/hack.pager.c line 231

xmore defined in line 75; used 2 times

- in line 99, 105

#### Defined variables

last_redone_topl defined in line 15; used 10 times

- in line 19-24(7), 45-49(3)

old_toplines defined in line 15; used 5 times

- in line 22, 47-55(4)

tlx defined in line 10; used 7 times

- in line 35, 67-70(3), 79-80(2), 140

tly defined in line 10; used 13 times

- in line 36-38(2), 67-71(2), 79-80(2), 90-93(2), 112(2), 135, 179(2)

toplines defined in line 9; used 13 times

- in line 24, 32-33(2), 46-54(4), 129, 136-139(3), 146, 157

#### Defined struct's

topl defined in line 12; used 8 times

- in line 13(2), 43(2), 50-51(4)

#### Defined macros

OTLMAX defined in line 16; used 1 times

- in line 44

Last modified: 1985-12-16 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1008 |