1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
/************************************************************************
* This program is Copyright (C) 1986-1996 by Jonathan Payne. JOVE is *
* provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
************************************************************************/
#include "jove.h"
#ifdef TERMCAP /* the body is the rest of the file */
#include "term.h"
#include "disp.h"
#include "fmt.h"
#include "fp.h"
#include "jctype.h"
#include "screen.h"
extern int UNMACRO(tgetent) proto((char */*buf*/, const char */*name*/));
extern int UNMACRO(tgetflag) proto((const char */*id*/));
extern int UNMACRO(tgetnum) proto((const char */*id*/));
extern char *UNMACRO(tgetstr) proto((const char */*id*/, char **/*area*/));
extern void UNMACRO(tputs) proto((const char *, int, void (*) proto((int))));
/* Termcap definitions */
char
*CS, /* change scrolling region */
*SO, /* Start standout */
*SE, /* End standout */
*US, /* Start underlining */
*UE, /* End underlining */
*CM, /* The cursor motion string */
*CL, /* Clear screen */
*CE, /* Clear to end of line */
*HO, /* Home cursor */
*AL, /* Addline (insert line) */
*DL, /* Delete line */
*VS, /* Visual start */
*VE, /* Visual end */
*KS, /* Keypad mode start */
*KE, /* Keypad mode end */
*TI, /* Cursor addressing start */
*TE, /* Cursor addressing end */
*LL, /* Last line, first column */
*SF = "\n", /* Scroll forward (defaults to \n) */
*SR, /* Scroll reverse */
*VB, /* visible bell */
*BL = "\007", /* audible bell (defaults to BEL) */
*lPC, /* pad character (as a string!) */
*NL = "\n", /* newline character (defaults to \n) */
*DO = "\n", /* down one line (defaults to \n capability) */
*M_AL, /* Insert line with arg */
*M_DL, /* Delete line with arg */
*M_SF, /* Scroll forward with arg */
*M_SR; /* Scroll back with arg */
int
UPlen = INFINITY, /* length of the UP string */
HOlen = INFINITY, /* length of Home string */
LLlen = INFINITY, /* length of last line string */
phystab = 8, /* ("it") terminal's tabstop settings */
UG; /* number of magic cookies left by US and UE */
bool
Hazeltine, /* Hazeltine tilde kludge */
UL, /* underscores don't replace chars already on screen */
NP; /* there is No Pad character */
# ifdef DEFINE_PC_BC_UP_OSPEED
/* This is needed for HP-UX, possibly for other SYSVR2 systems */
char
PC, /* pad character, as a char (set from lPC; defaults to NUL) */
*BC, /* back space (defaults to BS) */
*UP; /* Scroll reverse, or up */
short ospeed;
# endif /* DEFINE_PC_BC_UP_OSPEED */
bool CanScroll; /* can this terminal scroll? */
# ifdef ID_CHAR
char
*IC, /* Insert char */
*DC, /* Delete char */
*IM, /* Insert mode */
*EI, /* End insert mode */
*IP, /* insert pad after character inserted */
*M_IC, /* Insert char with arg */
*M_DC; /* Delete char with arg */
bool UseIC = NO; /* VAR: whether or not to use i/d char processesing */
int
IMlen = 0, /* length of insert mode */
EIlen = 0, /* length of end insert mode string */
IClen = 0, /* length of insert char */
DClen = 0, /* length of delete char */
MIClen = INFINITY, /* length of insert char with arg */
MDClen = INFINITY, /* length of delete char with arg */
CElen = 0; /* length of clear to end of line */
bool
MI; /* okay to move while in insert mode */
# endif /* ID_CHAR */
private char tspace[256]; /* space for termcap strings */
/* The ordering of ts and meas must agree !! */
private const char ts[] =
# ifdef ID_CHAR
/* | | | | */
"vsvealdlcssoseusuecmclcehoupbcllsfsrvbksketitepcblnldoALDLSFSRicimdceiipICDC";
# else
"vsvealdlcssoseusuecmclcehoupbcllsfsrvbksketitepcblnldoALDLSFSR";
# endif
private char **const meas[] = {
&VS, &VE, &AL, &DL, &CS, &SO, &SE, &US, &UE, &CM,
&CL, &CE, &HO, &UP, &BC, &LL, &SF, &SR, &VB, &KS,
&KE, &TI, &TE, &lPC, &BL, &NL, &DO, &M_AL, &M_DL, &M_SF,
&M_SR,
# ifdef ID_CHAR
&IC, &IM, &DC, &EI, &IP, &M_IC, &M_DC,
# endif
NULL
};
struct CapLen {
char **cap_var;
int *len_var;
};
private const struct CapLen CapLenTab[] = {
{ &HO, &HOlen },
{ &LL, &LLlen },
{ &UP, &UPlen },
# ifdef ID_CHAR
{ &IM, &IMlen },
{ &EI, &EIlen },
{ &IC, &IClen },
{ &DC, &DClen },
{ &M_IC, &MIClen },
{ &M_DC, &MDClen },
{ &CE, &CElen },
# endif
{ NULL, NULL }
};
private void
tcbad(termname, why)
const char
*termname,
*why;
{
writef("You can't run JOVE on a %s terminal: %s\n", termname, why);
flushscreen();
_exit(1);
}
void
getTERM()
{
char termnmbuf[13],
*termname = getenv("TERM"),
*termp = tspace,
tbuff[2048]; /* Good grief! */
if (termname == NULL || *termname == '\0'
|| strcmp(termname, "dumb") == 0
|| strcmp(termname, "unknown") == 0
|| strcmp(termname, "network") == 0)
{
int len;
putstr("Enter terminal type (e.g, vt100): ");
flushscreen();
len = read(0, (UnivPtr) termnmbuf, sizeof(termnmbuf));
termnmbuf[len > 1? len - 1 : 0] = '\0';
termname = termnmbuf;
}
if (tgetent(tbuff, termname) < 1)
tcbad(termname, "type unknown");
/* get numeric capabilities */
if ((CO = tgetnum("co")) == -1)
tcbad(termname, "co unknown (width)");
if (CO > MAXCOLS)
CO = MAXCOLS;
if ((LI = tgetnum("li")) == -1)
tcbad(termname, "li unknown (height)");
if ((phystab = tgetnum("it")) == -1 || phystab <= 0)
phystab = 8;
if ((SG = tgetnum("sg")) == -1)
SG = 0; /* Used for mode line only */
if ((UG = tgetnum("ug")) == -1)
UG = 0; /* We shan't bother if != 0 */
/* get string capabilities */
{
const char *tsp = ts;
char **const *measp;
for (measp = meas; *measp != NULL; measp++) {
static char nm[3] = "xx";
char *val;
nm[0] = *tsp++;
nm[1] = *tsp++;
val = tgetstr(nm, &termp);
if (val != NULL)
**measp = val;
if (termp > tspace + sizeof(tspace))
tcbad(termname, "too many bytes of termcap strings");
}
}
if (lPC)
PC = *lPC; /* convert lPC string attribute to char PC */
/* get boolean capabilities */
Hazeltine = tgetflag("hz")==YES; /* Hazeltine tilde kludge */
NP = tgetflag("NP")==YES; /* there is No Pad character */
UL = tgetflag("ul")==YES; /* underscores don't replace chars already on screen */
/* adjust capabilities */
if (tgetflag("km") == YES
# if defined(USE_CTYPE) && !defined(NO_SETLOCALE)
&& strcmp(LcCtype, "C") == 0
# endif
)
MetaKey = YES; /* has meta-key and default locale */
if (tgetflag("xs") == YES) {
SO = SE = NULL; /* don't use braindamaged standout mode */
SG = 0;
}
if (SR == NULL && M_SR == NULL)
CS = NULL; /* don't use scrolling region without way of reverse scrolling */
/* Note: the way termcap/terminfo is defined, we must use *both*
* IC and IM to insert, but normally only one will be defined.
* See terminfo(5), under the heading "Insert/Delete Character".
* Because of this, IM might be defined as a null string.
*/
# ifdef ID_CHAR
if (IM != NULL && *IM == '\0')
IM = NULL; /* If IM is empty, supress. */
UseIC = (IC != NULL || IM != NULL || M_IC != NULL);
MI = tgetflag("mi")==YES; /* okay to move while in insert mode */
# endif /* ID_CHAR */
/* strip stupid padding information */
while ('0' <= *NL && *NL <= '9')
NL += 1;
if (*NL == '*')
NL += 1;
if (BC == NULL)
BC = "\b"; /* default back space to BS */
CanScroll = (AL != NULL && DL != NULL) || CS != NULL;
/* calculate lengths */
{
static const struct CapLen *p;
for (p = CapLenTab; p->cap_var != NULL; p++)
if (*p->cap_var != NULL)
*p->len_var = strlen(*p->cap_var);
}
if (!(CM != NULL || HO != NULL))
tcbad(termname, "JOVE needs either cm or ho termcap/terminfo capability");
}
/* Put multi-unit or multiple single-unit strings, as appropriate. */
private void
tputc(c)
char c;
{
scr_putchar(c);
}
void
putmulti(ss, ms, num, lines)
const char
*ss, /* single line */
*ms; /* multiline */
int
num, /* number of iterations */
lines; /* lines affected (for padding) */
{
if (ms && (num > 1 || !ss)) {
/* use the multi string */
tputs(targ1(ms, num), lines, tputc);
} else {
/* repeatedly use single string */
while (num--)
putpad(ss, lines);
}
}
/* put a string with padding */
void
putpad(str, lines)
const char *str;
int lines;
{
if (str != NULL)
tputs(str, lines, tputc);
}
void
dobell(n) /* declared in term.h */
int n;
{
while (--n >= 0) {
if (VisBell && VB)
putstr(VB);
else
putpad(BL, 1);
}
flushscreen();
}
void
clr_page()
{
putpad(CL, LI);
}
#endif /* TERMCAP */
|