# 2.11BSD#431 - /usr/src/new/notes/src/cursor.c

##### Functions

    at                X
    center            X
    ceol              X
    charout           X
    cmstart           X
    cmstop            X
    cursget           X
    erase             X

       1: #include "parms.h"
       2: #include "structs.h"
       3:
       4: #ifdef  RCSIDENT
       5: static char rcsid[] = "$Header: /usr/local/src/usenet/notes/src/RCS/cursor.c,v 1.8 88/11/11 01:01:05 paul Exp $";
       6: #endif	RCSIDENT
       7:
       8: /*
       9:  *  at(row,col) places cursor on hazeltine at row,col
      10:  *	row = 1 to 24    ( y coords )
      11:  * 	column = 1 to 80   ( x coords )
      12:  *
      13:  *	numbers <=0 will have "nrows" or "ncols" added to them so
      14:  *	as to allow "floating" positioning relative to the bottom
      15:  *	or right side of the screen
      16:  *
      17:  *	-- modified 18-nov-1981 R. Essick to handle different tty types
      18:  *
      19:  */
      20:
      21: static short    ttyinit = 0;                /* whether have gotten termcap */
      22: static char bufspace[1024];             /* term capabilities */
      23: static char *cm = NULL;                 /* cursor motion */
      24: static char *cls = NULL;                /* clear screen string */
      25: static char *ti = NULL;                 /* start cursor motion */
      26: static char *te = NULL;                 /* stop cursor motion */
      27: static char *ce = NULL;                 /* clear to eol */
      28: #ifdef  USG
      29: static char *BC,
      30:            *UP;                     /* backspace, upspave */
      31: #else
      32: extern char *BC;                    /* backspaces */
      33: extern char *UP;                    /* up 1 line */
      34: #endif
      35: static int  atrow,
      36:             atcol;                  /* current position */
      37:
      38: char   *tgoto ();                   /* decodes the cursor via termcap */
      39:
      40: /*	charout - output 1 character */
      41: /*	used by tputs routine in at */
      42: charout (c)
      43: {
      44:     putchar (c);
      45: }
      46:
      47:
      48: at (row, col)
      49: {
      50:     register char  *p;
      51:
      52:     if (ttyinit == 0)
      53:     cursget ();                 /* initialize termcap */
      54:     if (cm != NULL)                 /* was there a cm field? */
      55:     {
      56:     if (row <= 0)
      57:         row += nrows;               /* wraparound - cute */
      58:     if (col <= 0)
      59:         col += ncols;
      60:     p = tgoto (cm, col - 1, row - 1);
      61:     tputs (p, 1, charout);
      62:
      63:     }
      64:     else
      65:     if (atrow != row)
      66:         printf ("\n");
      67:     else
      68:         printf (" ");
      69:     atrow = row;
      70:     atcol = col;
      71: }
      72:
      73: /*
      74:  * erase()  erases the screen
      75:  *	modified R. Essick 18-nov-81 - allow different tty types
      76:  *	Modified R Kolstad Jan '84 for true erase-abort function
      77:  */
      78:
      79: erase ()
      80: {
      81:     clearerr (stdout);                  /* to be sure */
      82:     if (ttyinit == 0)
      83:     cursget ();                 /* initialize termcap */
      84: #ifdef BSD4x
      85:     {
      86: #include <sgtty.h>
      87:     int     flusher = 2;
      88: /*
      89:  *	2 is magic constant used in kernel to mean flush write buffers
      90:  *	only.
      91:  */
      92:     ioctl (1, TIOCFLUSH, &flusher);
      93:     }
      94: #endif	BSD4x
      95:
      96:     if (cls != NULL)
      97:     tputs (cls, 1, charout);
      98:     else
      99:     printf ("\n\n");
     100:     atrow = 1;                      /* back in top of screen */
     101:     atcol = 1;                      /* on left hand side */
     102: }
     103:
     104: /*
     105:  *	cmstart, cmstop
     106:  *
     107:  *	prepare fancy tty's for cursor motion stuff
     108:  *
     109:  */
     110: cmstart ()
     111: {
     112:     if (ttyinit == 0)
     113:     cursget ();
     114:     if (ti != NULL)
     115:     tputs (ti, 1, charout);
     116: }
     117:
     118: cmstop ()
     119: {
     120:     if (ttyinit == 0)
     121:     cursget ();
     122:     if (te != NULL)
     123:     tputs (te, 1, charout);
     124: }
     125:
     126: /*
     127:  *	clear to end of line if the capability exists.
     128:  *
     129:  *	FIX FOR DUMB TERMINALS
     130:  */
     131:
     132: ceol ()
     133: {
     134:     if (ttyinit == 0)
     135:     cursget ();
     136:     if (ce != NULL)
     137:     tputs (ce, 1, charout);
     138: }
     139:
     140: cursget ()
     141: {
     142:     char   *getenv (), *tgetstr ();
     143:     char   *p,
     144:            *q;
     145:     extern char *histty;                /* tty type on control card */
     146:     register int    i;                  /* rows, cols */
     147:     char    bp[1024];                   /* termcap stuff */
     148: /*	bp made dynamic to give the pdp-11 breathing room */
     149:
     150:     ttyinit = 1;                    /* say we got it */
     151: /*
     152:  *	ttyinit set now so don't loop on ttystop/cmstop/cursget/ttystop...
     153:  */
     154:     if ((p = histty) == 0)
     155:     {
     156:     if (isatty (fileno (stderr)) && (p = getenv ("TERM")) == NULL)
     157:         /* a terminal ?? */
     158:     {
     159:         fprintf (stderr, "You have no TERM environmental variable.  This variable tells the\n");
     160:         fprintf (stderr, "system what type of terminal you are using so it's features may be used.\n");
     161:         fprintf (stderr, "To set this variable:\n\n");
     162:         fprintf (stderr, "	From csh type 'setenv TERM <term-type>'.\n");
     163:         fprintf (stderr, "	From sh type 'TERM=<termtype>;export TERM'.\n\n");
     164:         fprintf (stderr, "Where <term-type> is the system designation for your terminal.\n");
     165:         fprintf (stderr, "(E.g. hp2621, adm3a, aaa40, etc).\n");
     166:         ttystop ();                 /* make sure tty is in normal state */
     167:         exit (BAD);                 /* and terminate */
     168:     }
     169:     }
     170:     if (tgetent (bp, p) != 1)
     171:     {
     172:     fprintf (stderr,
     173:         "Can't find capabilities for terminal type \"%s\"\n", p);
     174:     ttystop ();                 /* reset tty states */
     175:     exit (BAD);
     176:     }
     177:     q = bufspace;
     178:     cm = tgetstr ("cm", &q);                /* get cursor motion */
     179:     cls = tgetstr ("cl", &q);               /* clear screen */
     180:     ti = tgetstr ("ti", &q);                /* start cursor motion */
     181:     te = tgetstr ("te", &q);                /* stop cursor motion */
     182:     UP = tgetstr ("up", &q);                /* cursor up */
     183:     BC = tgetstr ("bc", &q);                /* cursor left */
     184:     ce = tgetstr ("ce", &q);                /* clear to eol */
     185:     if ((i = tgetnum ("li")) != -1)
     186:     nrows = i;                  /* rows on screen */
     187:     if (nrows != 24)                    /* different screen size */
     188:     {
     189:     Nindex = nrows - 12;                /* header, trailer, prompt */
     190:     }
     191:     if ((i = tgetnum ("co")) != -1)
     192:     ncols = i;                  /* cols on screen */
     193: }
     194:
     195: /*
     196:  * miscellaneous output routines for the terminal
     197:  *
     198:  * center(p,len,row,col) takes a character string pointed at by p and centers it
     199:  *    within a field of length n.  it is printed on screen at row,col
     200:  *    (centered).  It is also assumed that p's string is BLANK TERMINATED
     201:  *
     202:  * prdate(w) struct when_f *w;  prints the date.  Assumes 'at' is already done
     203:  *
     204:  * sprdate(w,str) struct when_f *w; char str[]; formats the date and returns
     205:  *		the result in the string pointed to by str.
     206:  *
     207:  */
     208:
     209: center (p, len, row, col) char *p;
     210: {
     211:     register int    i;
     212:     char   *r;
     213:
     214:     i = strlen (p);                 /* get length */
     215:     if (i != 0)
     216:     {
     217:     at (row, col + (len - i) / 2);
     218:     fwrite (p, sizeof (char), i, stdout);       /* write it */
     219:     }
     220: }

#### Defined functions

at defined in line 48; used 167 times

- in line 217
- in /usr/src/new/notes/src/access.c line 80, 152, 171, 179, 188, 200, 221, 252, 262, 291-295(3), 366-371(2), 377
- in /usr/src/new/notes/src/adnote.c line 41, 51, 58, 91
- in /usr/src/new/notes/src/adresp.c line 35, 43
- in /usr/src/new/notes/src/asearch.c line 50-54(3), 64, 70, 130
- in /usr/src/new/notes/src/dropt.c line 72, 85, 134-139(2), 149-154(2), 162, 169, 175-187(4), 194, 204-209(2), 230-232(2), 241, 259-264(2), 279-281(2), 290, 319, 361, 404-409(3), 422-427(3), 441, 448, 471-480(4), 519-537(7), 551, 568, 591, 601, 613-619(4), 644
- in /usr/src/new/notes/src/dsply.c line 63, 73-85(4), 93, 99-104(2), 112, 189-202(5), 209, 217, 349, 355
- in /usr/src/new/notes/src/gdate.c line 40-49(4)
- in /usr/src/new/notes/src/index.c line 48, 78, 142, 153, 168, 180, 220-224(2), 251, 262
- in /usr/src/new/notes/src/limindx.c line 37-39(2), 126-129(2), 139-142(2), 157, 164
- in /usr/src/new/notes/src/mailit.c line 59, 88, 121
- in /usr/src/new/notes/src/main.c line 233
- in /usr/src/new/notes/src/miscio.c line 190
- in /usr/src/new/notes/src/nfpipe.c line 96
- in /usr/src/new/notes/src/prtind.c line 32-40(3), 68-73(2), 83-86(2), 113-117(2)
- in /usr/src/new/notes/src/readem.c line 88, 112, 122, 129, 136, 155, 166, 183, 193, 200, 233, 244, 274, 280, 349, 467, 515-520(2), 555, 562, 603, 683, 760, 771, 783-790(3), 844
- in /usr/src/new/notes/src/tsearch.c line 31-34(2), 42

center defined in line 209; used 7 times

- in /usr/src/new/notes/src/dropt.c line 515-516(2)
- in /usr/src/new/notes/src/dsply.c line 70, 80, 89, 193, 206

ceol defined in line 132; used 5 times

- in /usr/src/new/notes/src/control.c line 66, 137
- in /usr/src/new/notes/src/dropt.c line 136, 206, 261

charout defined in line 42; used 5 times

- in line 61, 97, 115, 123, 137

cmstart defined in line 110; used 1 times

- in /usr/src/new/notes/src/miscio.c line 131

cmstop defined in line 118; used 1 times

- in /usr/src/new/notes/src/miscio.c line 158

cursget defined in line 140; used 5 times

- in line 53, 83, 113, 121, 135

erase defined in line 79; used 7 times

- in /usr/src/new/notes/src/access.c line 76, 145, 212
- in /usr/src/new/notes/src/dropt.c line 514
- in /usr/src/new/notes/src/dsply.c line 62, 188
- in /usr/src/new/notes/src/prtind.c line 31

#### Defined variables

BC declared in line 32; defined in line 29; used 1 times

- in line 183

UP declared in line 33; defined in line 30; used 1 times

- in line 182

atcol defined in line 36; used 2 times

- in line 70, 101

atrow defined in line 35; used 3 times

- in line 65-69(2), 100

bufspace defined in line 22; used 1 times

- in line 177

ce defined in line 27; used 3 times

- in line 136-137(2), 184

cls defined in line 24; used 3 times

- in line 96-97(2), 179

cm defined in line 23; used 3 times

- in line 54, 60, 178

rcsid defined in line 5; never used
te defined in line 26; used 3 times

- in line 122-123(2), 181

ti defined in line 25; used 3 times

- in line 114-115(2), 180

ttyinit defined in line 21; used 6 times

- in line 52, 82, 112, 120, 134, 150

Last modified: 1988-11-11 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 878 |