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

center defined in line 209; used 7 times
ceol defined in line 132; used 5 times
charout defined in line 42; used 5 times
cmstart defined in line 110; used 1 times
cmstop defined in line 118; used 1 times
cursget defined in line 140; used 5 times

Defined variables

BC declared in line 32; defined in line 29; used 1 times
UP declared in line 33; defined in line 30; used 1 times
atcol defined in line 36; used 2 times
atrow defined in line 35; used 3 times
bufspace defined in line 22; used 1 times
ce defined in line 27; used 3 times
cls defined in line 24; used 3 times
cm defined in line 23; used 3 times
rcsid defined in line 5; never used
te defined in line 26; used 3 times
ti defined in line 25; used 3 times
ttyinit defined in line 21; used 6 times
Last modified: 1988-11-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 786
Valid CSS Valid XHTML 1.0 Strict