|
|
1.1 ! root 1: #include "parms.h" ! 2: #include "structs.h" ! 3: ! 4: #ifdef RCSIDENT ! 5: static char rcsid[] = "$Header: cursor.c,v 1.7 85/01/18 15:07:42 notes Rel $"; ! 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 ((p = getenv ("TERM")) == NULL) /* a terminal ?? */ ! 157: { ! 158: fprintf (stderr, "You have no TERM environmental variable. This variable tells the\n"); ! 159: fprintf (stderr, "system what type of terminal you are using so it's features may be used.\n"); ! 160: fprintf (stderr, "To set this variable:\n\n"); ! 161: fprintf (stderr, " From csh type 'setenv TERM <term-type>'.\n"); ! 162: fprintf (stderr, " From sh type 'TERM=<termtype>;export TERM'.\n\n"); ! 163: fprintf (stderr, "Where <term-type> is the system designation for your terminal.\n"); ! 164: fprintf (stderr, "(E.g. hp2621, adm3a, aaa40, etc).\n"); ! 165: ttystop (); /* make sure tty is in normal state */ ! 166: exit (BAD); /* and terminate */ ! 167: } ! 168: } ! 169: if (tgetent (bp, p) != 1) ! 170: { ! 171: fprintf (stderr, ! 172: "Can't find capabilities for terminal type \"%s\"\n", p); ! 173: ttystop (); /* reset tty states */ ! 174: exit (BAD); ! 175: } ! 176: q = bufspace; ! 177: cm = tgetstr ("cm", &q); /* get cursor motion */ ! 178: cls = tgetstr ("cl", &q); /* clear screen */ ! 179: ti = tgetstr ("ti", &q); /* start cursor motion */ ! 180: te = tgetstr ("te", &q); /* stop cursor motion */ ! 181: UP = tgetstr ("up", &q); /* cursor up */ ! 182: BC = tgetstr ("bc", &q); /* cursor left */ ! 183: ce = tgetstr ("ce", &q); /* clear to eol */ ! 184: if ((i = tgetnum ("li")) != -1) ! 185: nrows = i; /* rows on screen */ ! 186: if (nrows != 24) /* different screen size */ ! 187: { ! 188: Nindex = nrows - 12; /* header, trailer, prompt */ ! 189: } ! 190: if ((i = tgetnum ("co")) != -1) ! 191: ncols = i; /* cols on screen */ ! 192: } ! 193: ! 194: /* ! 195: * miscellaneous output routines for the terminal ! 196: * ! 197: * center(p,len,row,col) takes a character string pointed at by p and centers it ! 198: * within a field of length n. it is printed on screen at row,col ! 199: * (centered). It is also assumed that p's string is BLANK TERMINATED ! 200: * ! 201: * prdate(w) struct when_f *w; prints the date. Assumes 'at' is already done ! 202: * ! 203: * sprdate(w,str) struct when_f *w; char str[]; formats the date and returns ! 204: * the result in the string pointed to by str. ! 205: * ! 206: */ ! 207: ! 208: center (p, len, row, col) char *p; ! 209: { ! 210: register int i; ! 211: char *r; ! 212: ! 213: i = strlen (p); /* get length */ ! 214: if (i != 0) ! 215: { ! 216: at (row, col + (len - i) / 2); ! 217: fwrite (p, sizeof (char), i, stdout); /* write it */ ! 218: } ! 219: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.