Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libcurses/screen/setupterm.c
+++ new/usr/src/lib/libcurses/screen/setupterm.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1988 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /*
31 31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 32 * The Regents of the University of California
33 33 * All Rights Reserved
34 34 *
35 35 * University Acknowledgment- Portions of this document are derived from
36 36 * software developed by the University of California, Berkeley, and its
37 37 * contributors.
38 38 */
39 39
40 40 /*LINTLIBRARY*/
41 41
42 42 #include <stdio.h>
43 43 #include <sys/types.h>
44 44 #include <fcntl.h>
45 45 #include <stdlib.h>
46 46 #include <string.h>
47 47 #include <unistd.h>
48 48 #include <errno.h>
49 49 #include <zone.h>
50 50 #include "curses_inc.h"
51 51
52 52 #define TERMPATH "/usr/share/lib/terminfo/"
53 53 #define TERMPATHLEN 512
54 54
55 55 extern bool _use_env; /* in curses.c */
56 56
57 57 chtype bit_attributes[NUM_ATTRIBUTES] = {
58 58 A_STANDOUT,
59 59 A_UNDERLINE,
60 60 A_ALTCHARSET,
61 61 A_REVERSE,
62 62 A_BLINK,
63 63 A_DIM,
64 64 A_BOLD,
65 65 A_INVIS,
66 66 A_PROTECT
67 67 };
68 68
69 69 char *Def_term = "unknown", /* default terminal type */
70 70 term_parm_err[32], ttytype[BUFSIZ], _frst_tblstr[1400];
71 71
72 72 TERMINAL _first_term, *cur_term = &_first_term;
73 73 struct _bool_struct _frst_bools, *cur_bools = &_frst_bools;
74 74 struct _num_struct _frst_nums, *cur_nums = &_frst_nums;
75 75 struct _str_struct _frst_strs, *cur_strs = &_frst_strs;
76 76
77 77 /* _called_before is used/cleared by delterm.c and restart.c */
78 78 char _called_before = 0;
79 79 short term_errno = -1;
80 80
81 81 #ifdef SYSV
82 82 int prog_istermios = -1;
83 83 int shell_istermios = -1;
84 84 #endif
85 85
86 86 #ifdef DUMPTI
87 87 extern char *boolfnames[], *boolnames[], *boolcodes[],
88 88 *numfnames[], *numnames[], *numcodes[],
89 89 *strfnames[], *strnames[], *strcodes[];
90 90
91 91 main(int argc, char **argv) /* FOR DEBUG ONLY */
92 92 {
93 93 if (argc > 1)
94 94 setupterm(argv[1], 1, (int *)0);
95 95 else
96 96 setupterm((char *)0, 1, (int *)0);
97 97 return (0);
98 98 }
99 99
100 100 _Pr(int ch) /* FOR DEBUG ONLY */
101 101 {
102 102 if (ch >= 0200) {
103 103 printf("M-");
104 104 ch -= 0200;
105 105 }
106 106 if ((ch < ' ') || (ch == 0177))
107 107 printf("^%c", ch ^ 0100);
108 108 else
109 109 printf("%c", ch);
110 110 }
111 111
112 112 _Sprint(int n, char *string) /* FOR DEBUG ONLY */
113 113 {
114 114 int ch;
115 115
116 116 if (n == -1) {
117 117 printf(".\n");
118 118 return;
119 119 }
120 120 printf(", string = '");
121 121 while (ch = *string++)
122 122 _Pr(ch&0377);
123 123
124 124 printf("'.\n");
125 125 }
126 126
127 127 _Mprint(int n, char *memory) /* FOR DEBUG ONLY */
128 128 {
129 129 unsigned char ch;
130 130
131 131 while (ch = *memory++, n-- > 0)
132 132 _Pr(ch&0377);
133 133 }
134 134
135 135 #define _Vr2getshi() _Vr2getsh(ip-2)
136 136
137 137 #if vax || pdp11
138 138 #define _Vr2getsh(ip) (* (short *)(ip))
139 139 #endif /* vax || pdp11 */
140 140
141 141 #ifndef _Vr2getsh
142 142 /*
143 143 * Here is a more portable version, which does not assume byte ordering
144 144 * in shorts, sign extension, etc.
145 145 */
146 146 _Vr2getsh(char *p)
147 147 {
148 148 int rv;
149 149
150 150 if (*p == (char)0377)
151 151 return (-1);
152 152 rv = (unsigned char) *p++;
153 153 rv += (unsigned char) *p * 256;
154 154 return (rv);
155 155 }
156 156 #endif /* _Vr2getsh */
157 157
158 158 #endif /* DUMPTI */
159 159
160 160 #define _Getshi() _Getsh(ip); ip += 2
161 161
162 162 /*
163 163 * "function" to get a short from a pointer. The short is in a standard
164 164 * format: two bytes, the first is the low order byte, the second is
165 165 * the high order byte (base 256). The only negative numbers allowed are
166 166 * -1 and -2, which are represented as 255,255 and 255,254 This format
167 167 * happens to be the same as the hardware on the pdp-11, vax, and 386,
168 168 * making it fast and convenient and small to do this on a pdp-11.
169 169 */
170 170
171 171 #if vax || pdp11 || i386
172 172 #define _Getsh(ip) (* (short *)ip)
173 173 #endif /* vax || pdp11 */
174 174 /*
175 175 * The following macro is partly due to Mike Laman, laman@sdcsvax
176 176 * NCR @ Torrey Pines. - Tony Hansen
177 177 */
178 178 #if u3b || u3b15 || u3b2 || m68000
179 179 #define _Getsh(ip) ((short)(*((unsigned char *)ip) | (*(ip+1) << 8)))
180 180 #endif /* u3b || u3b15 || u3b2 || m68000 */
181 181
182 182 #ifndef _Getsh
183 183 /*
184 184 * Here is a more portable version, which does not assume byte ordering
185 185 * in shorts, sign extension, etc. For the sake of the porters,
186 186 * two alternative implementations, for the machines that don't have
187 187 * casting to "unsigned char", are also given, but commented out.
188 188 * Not ANSI C implementation assumes that the * C preprocessor does
189 189 * sign-extension the same as on the machine being compiled for.
190 190 */
191 191 static int
192 192 _Getsh(char *p)
193 193 {
194 194 int rv, rv2;
195 195
196 196 rv = (unsigned char) p[0];
197 197 rv2 = (unsigned char) p[1];
198 198
199 199 /* the following stuff is only for porting. See the comment above */
200 200
201 201 #ifdef FOR_PORTING
202 202 #if CHAR_MIN < 0
203 203 rv = (*p++) & 0377;
204 204 rv2 = (*p) & 0377;
205 205 #else /* CHAR_MIN < 0 */
206 206 rv = *p++;
207 207 rv2 = *p;
208 208 #endif /* CHAR_MIN < 0 */
209 209
210 210 #endif /* FOR_PORTING */
211 211
212 212 if ((rv2 == 0377) && ((rv == 0377) || (rv == 0376)))
213 213 return (-1);
214 214 return (rv + (rv2 * 256));
215 215 }
216 216 #endif /* _Getsh */
217 217
218 218 /*
219 219 * setupterm: low level routine to dig up terminfo from database
220 220 * and read it in. Parms are terminal type (0 means use getenv("TERM"),
221 221 * file descriptor all output will go to (for ioctls), and a pointer
222 222 * to an int into which the error return code goes (0 means to bomb
223 223 * out with an error message if there's an error). Thus,
224 224 * setupterm((char *)0, 1, (int *)0) is a reasonable way for a simple
225 225 * program to set up.
226 226 */
227 227 int
228 228 setupterm(char *term, int filenum, int *errret)
229 229 /* filenum - This is a UNIX file descriptor, not a stdio ptr. */
230 230 {
231 231 char tiebuf[4096];
232 232 char fname[TERMPATHLEN];
233 233 char *ip;
234 234 char *cp;
235 235 int n, tfd;
236 236 char *lcp, *ccp, **on_sequences, **str_array;
237 237 int snames, nbools, nints, nstrs, sstrtab;
238 238 char *strtab;
239 239 #ifdef DUMPTI
240 240 int Vr2val;
241 241 #endif /* DUMPTI */
242 242
243 243 (void) mbgetwidth();
244 244
245 245 if (term == NULL)
246 246 term = getenv("TERM");
247 247
248 248 if (term == NULL || *term == '\0')
249 249 term = Def_term;
250 250
251 251 tfd = -1;
252 252 errno = 0; /* ehr3 */
253 253
254 254 if (errret != 0)
255 255 *errret = -1;
256 256
257 257 if (((cp = getenv("TERMINFO")) != 0) && *cp) {
258 258 /* $TERMINFO/?/$TERM */
259 259 if (snprintf(fname, sizeof (fname),
260 260 "%s/%c/%s", cp, *term, term) >= sizeof (fname)) {
261 261 term_errno = TERMINFO_TOO_LONG;
262 262 goto out_err;
263 263 }
264 264
265 265 tfd = open(fname, 0);
266 266 #ifdef DUMPTI
267 267 printf("looking in file %s\n", fname);
268 268 #endif /* DUMPTI */
269 269 if ((tfd < 0) && (errno == EACCES))
270 270 goto cant_read;
271 271 }
272 272
273 273 if (tfd < 0) {
274 274 const char *zroot = zone_get_nroot();
275 275 /* /usr/share/lib/terminfo/?/$TERM */
276 276 if (snprintf(fname, sizeof (fname),
277 277 "%s/%s/%c/%s", zroot == NULL ? "" : zroot, TERMPATH,
278 278 *term, term) >= sizeof (fname)) {
279 279 term_errno = TERMINFO_TOO_LONG;
280 280 goto out_err;
281 281 }
282 282
283 283 tfd = open(fname, 0);
284 284 #ifdef DUMPTI
285 285 printf("looking in file %s\n", fname);
286 286 #endif /* DUMPTI */
287 287
288 288 }
289 289
290 290 if (tfd < 0) {
291 291 if (errno == EACCES) {
292 292 cant_read:
293 293 term_errno = NOT_READABLE;
294 294 } else {
295 295 if (access(TERMPATH, 0) == -1)
296 296 term_errno = UNACCESSIBLE;
297 297 else {
298 298 term_errno = NO_TERMINAL;
299 299 if (errret != 0)
300 300 *errret = 0;
301 301 }
302 302 }
303 303 /*
304 304 * if the length of the specified terminal name is longer
305 305 * than 31, it will be chopped after the 31st byte.
306 306 * This should be a rare case.
307 307 */
308 308 (void) strncpy(term_parm_err, term, 31);
309 309 term_parm_err[31] = '\0';
310 310 goto out_err;
311 311 }
312 312
313 313 /* LINTED */
314 314 n = (int)read(tfd, tiebuf, sizeof (tiebuf));
315 315 (void) close(tfd);
316 316
317 317 if (n <= 0) {
318 318 corrupt:
319 319 term_errno = CORRUPTED;
320 320 goto out_err;
321 321 } else
322 322 if (n == sizeof (tiebuf)) {
323 323 term_errno = ENTRY_TOO_LONG;
324 324 goto out_err;
325 325 }
326 326 cp = ttytype;
327 327 ip = tiebuf;
328 328
329 329 /* Pick up header */
330 330 snames = _Getshi();
331 331 #ifdef DUMPTI
332 332 Vr2val = _Vr2getshi();
333 333 printf("Magic number = %d, %#o [%d, %#o].\n", snames,
334 334 snames, Vr2val, Vr2val);
335 335 #endif /* DUMPTI */
336 336 if (snames != MAGNUM)
337 337 goto corrupt;
338 338 snames = _Getshi();
339 339 #ifdef DUMPTI
340 340 Vr2val = _Vr2getshi();
341 341 printf("Size of names = %d, %#o [%d, %#o].\n", snames,
342 342 snames, Vr2val, Vr2val);
343 343 #endif /* DUMPTI */
344 344
345 345 nbools = _Getshi();
346 346 #ifdef DUMPTI
347 347 Vr2val = _Vr2getshi();
348 348 printf("Number of bools = %d, %#o [%d, %#o].\n", nbools,
349 349 nbools, Vr2val, Vr2val);
350 350 #endif /* DUMPTI */
351 351
352 352 nints = _Getshi();
353 353 #ifdef DUMPTI
354 354 Vr2val = _Vr2getshi();
355 355 printf("Number of ints = %d, %#o [%d, %#o].\n", nints, nints,
356 356 Vr2val, Vr2val);
357 357 #endif /* DUMPTI */
358 358
359 359 nstrs = _Getshi();
360 360 #ifdef DUMPTI
361 361 Vr2val = _Vr2getshi();
362 362 printf("Number of strings = %d, %#o [%d, %#o].\n", nstrs, nstrs,
363 363 Vr2val, Vr2val);
364 364 #endif /* DUMPTI */
365 365
366 366 sstrtab = _Getshi();
367 367 #ifdef DUMPTI
368 368 Vr2val = _Vr2getshi();
369 369 printf("Size of string table = %d, %#o [%d, %#o].\n", sstrtab,
370 370 sstrtab, Vr2val, Vr2val);
371 371 printf("Names are: %.*s.\n", snames, ip);
372 372 #endif /* DUMPTI */
373 373
374 374 /* allocate all of the space */
375 375 strtab = NULL;
376 376 if (_called_before) {
377 377 /* 2nd or more times through */
378 378 if ((cur_term = (TERMINAL *)
379 379 calloc(sizeof (TERMINAL), 1)) == NULL)
380 380 goto badmalloc;
381 381 if ((cur_bools = (struct _bool_struct *)
382 382 calloc(sizeof (struct _bool_struct), 1)) == NULL)
383 383 goto freeterminal;
384 384 if ((cur_nums = (struct _num_struct *)
385 385 calloc(sizeof (struct _num_struct), 1)) == NULL)
386 386 goto freebools;
387 387 if ((cur_strs = (struct _str_struct *)
388 388 calloc(sizeof (struct _str_struct), 1)) == NULL) {
389 389 freenums:
390 390 free((char *)cur_nums);
391 391 freebools:
392 392 free((char *)cur_bools);
393 393 freeterminal:
394 394 free((char *)cur_term);
395 395 badmalloc:
396 396 term_errno = TERM_BAD_MALLOC;
397 397 #ifdef DEBUG
398 398 strcpy(term_parm_err, "setupterm");
399 399 #endif /* DEBUG */
400 400 out_err:
401 401 if (errret == 0) {
402 402 termerr();
403 403 exit(-term_errno);
404 404 } else
405 405 return (ERR);
406 406 }
407 407 } else {
408 408 /* First time through */
409 409 _called_before = TRUE;
410 410 cur_term = &_first_term;
411 411 cur_bools = &_frst_bools;
412 412 cur_nums = &_frst_nums;
413 413 cur_strs = &_frst_strs;
414 414 if (sstrtab < sizeof (_frst_tblstr))
415 415 strtab = _frst_tblstr;
416 416 }
417 417
418 418 if (strtab == NULL) {
419 419 if ((strtab = (char *)malloc((unsigned)sstrtab)) == NULL) {
420 420 if (cur_strs != &_frst_strs)
421 421 free((char *)cur_strs);
422 422 goto freenums;
423 423 }
424 424 }
425 425
426 426 /* no more catchable errors */
427 427 if (errret)
428 428 *errret = 1;
429 429
430 430 (void) strncpy(cur_term->_termname, term, 14);
431 431 /* In case the name is exactly 15 characters */
432 432 cur_term->_termname[14] = '\0';
433 433 cur_term->_bools = cur_bools;
434 434 cur_term->_nums = cur_nums;
435 435 cur_term->_strs = cur_strs;
436 436 cur_term->_strtab = strtab;
437 437 cur_term->sgr_mode = cur_term->sgr_faked = A_NORMAL;
438 438
439 439 if (filenum == 1 && !isatty(filenum))
440 440 filenum = 2; /* Allow output redirect */
441 441 /* LINTED */
442 442 cur_term->Filedes = (short)filenum;
443 443 _blast_keys(cur_term);
444 444 cur_term->_iwait = cur_term->fl_typeahdok = cur_term->_chars_on_queue =
445 445 cur_term->_fl_rawmode = cur_term->_ungotten = 0;
446 446 cur_term->_cursorstate = 1;
447 447 cur_term->_delay = cur_term->_inputfd = cur_term->_check_fd = -1;
448 448 (void) memset((char *)cur_term->_regs, 0, 26 * sizeof (short));
449 449
450 450 #ifndef DUMPTI
451 451 (void) def_shell_mode();
452 452 /* This is a useful default for PROGTTY, too */
453 453 #ifdef SYSV
454 454 if (shell_istermios < 0) {
455 455 int i;
456 456
457 457 SHELLTTY.c_lflag = SHELLTTYS.c_lflag;
458 458 SHELLTTY.c_oflag = SHELLTTYS.c_oflag;
459 459 SHELLTTY.c_iflag = SHELLTTYS.c_iflag;
460 460 SHELLTTY.c_cflag = SHELLTTYS.c_cflag;
461 461 for (i = 0; i < NCC; i++)
462 462 SHELLTTY.c_cc[i] = SHELLTTYS.c_cc[i];
463 463 PROGTTY = SHELLTTY;
464 464 prog_istermios = -1;
465 465
466 466 PROGTTYS.c_lflag = PROGTTY.c_lflag;
467 467 PROGTTYS.c_oflag = PROGTTY.c_oflag;
468 468 PROGTTYS.c_iflag = PROGTTY.c_iflag;
469 469 PROGTTYS.c_cflag = PROGTTY.c_cflag;
470 470 for (i = 0; i < NCC; i++)
471 471 PROGTTYS.c_cc[i] = PROGTTY.c_cc[i];
472 472 } else {
473 473 PROGTTYS = SHELLTTYS;
474 474 prog_istermios = 0;
475 475 }
476 476 #else /* SYSV */
477 477 PROGTTY = SHELLTTY;
478 478 #endif /* SYSV */
479 479 #endif /* DUMPTI */
480 480
481 481 /* Skip names of terminals */
482 482 (void) memcpy((char *)cp, (char *)ip, (snames * sizeof (*cp)));
483 483 ip += snames;
484 484
485 485 /*
486 486 * Pull out the booleans.
487 487 * The for loop below takes care of a new curses with an old tic
488 488 * file and visa-versa. nbools says how many bools the tic file has.
489 489 * So, we only loop for as long as there are bools to read.
490 490 * However, if this is an old curses that doesn't have all the
491 491 * bools that this new tic has dumped, then the extra if
492 492 * "if (cp < fp)" says that if we are going to read into our structure
493 493 * passed its size don't do it but we still need to keep bumping
494 494 * up the pointer of what we read in from the terminfo file.
495 495 */
496 496 {
497 497 char *fp = &cur_bools->Sentinel;
498 498 char s;
499 499 #ifdef DUMPTI
500 500 int tempindex = 0;
501 501 #endif /* DUMPTI */
502 502 cp = &cur_bools->_auto_left_margin;
503 503 while (nbools--) {
504 504 s = *ip++;
505 505 #ifdef DUMPTI
506 506 printf("Bool %s [%s] (%s) = %d.\n",
507 507 boolfnames[tempindex], boolnames[tempindex],
508 508 boolcodes[tempindex], s);
509 509 tempindex++;
510 510 #endif /* DUMPTI */
511 511 if (cp < fp)
512 512 *cp++ = s & 01;
513 513 }
514 514 if (cp < fp)
515 515 (void) memset(cp, 0, ((fp - cp) * sizeof (bool)));
516 516 }
517 517
518 518 /* Force proper alignment */
519 519 if (((unsigned long) ip) & 1)
520 520 ip++;
521 521
522 522 /*
523 523 * Pull out the numbers.
524 524 */
525 525 {
526 526 short *sp = &cur_nums->_columns;
527 527 short *fp = &cur_nums->Sentinel;
528 528 int s;
529 529 #ifdef DUMPTI
530 530 int tempindex = 0;
531 531 #endif /* DUMPTI */
532 532
533 533 while (nints--) {
534 534 s = _Getshi();
535 535 #ifdef DUMPTI
536 536 Vr2val = _Vr2getshi();
537 537 printf("Num %s [%s] (%s) = %d [%d].\n",
538 538 numfnames[tempindex], numnames[tempindex],
539 539 numcodes[tempindex], s, Vr2val);
540 540 tempindex++;
541 541 #endif /* DUMPTI */
542 542 if (sp < fp)
543 543 if (s < 0)
544 544 *sp++ = -1;
545 545 else
546 546 /* LINTED */
547 547 *sp++ = (short)s;
548 548 }
549 549 if (sp < fp)
550 550 (void) memset((char *)sp, '\377',
551 551 ((fp - sp) * sizeof (short)));
552 552 }
553 553
554 554 if (_use_env) {
555 555 /*
556 556 * This ioctl defines the window size and overrides what
557 557 * it says in terminfo.
558 558 */
559 559 {
560 560 struct winsize w;
561 561
562 562 if (ioctl(filenum, TIOCGWINSZ, &w) != -1) {
563 563 if (w.ws_row != 0)
564 564 cur_nums->_lines = w.ws_row;
565 565 if (w.ws_col != 0)
566 566 cur_nums->_columns = w.ws_col;
567 567 #ifdef DUMPTI
568 568 printf("ioctl TIOCGWINSZ override: "
569 569 "(lines, columns) = (%d, %d)\n",
570 570 w.ws_row, w.ws_col);
571 571 #endif /* DUMPTI */
572 572 }
573 573 }
574 574
575 575 /*
576 576 * Check $LINES and $COLUMNS.
577 577 */
578 578 {
579 579 int ilines, icolumns;
580 580
581 581 lcp = getenv("LINES");
582 582 ccp = getenv("COLUMNS");
583 583 if (lcp)
584 584 if ((ilines = atoi(lcp)) > 0) {
585 585 /* LINTED */
586 586 cur_nums->_lines = (short)ilines;
587 587 #ifdef DUMPTI
588 588 printf("$LINES override: lines = %d\n",
589 589 ilines);
590 590 #endif /* DUMPTI */
591 591 }
592 592 if (ccp)
593 593 if ((icolumns = atoi(ccp)) > 0) {
594 594 /* LINTED */
595 595 cur_nums->_columns = (short)icolumns;
596 596 #ifdef DUMPTI
597 597 printf("$COLUMNS override: columns = "
598 598 "%d\n", icolumns);
599 599 #endif /* DUMPTI */
600 600 }
601 601 }
602 602 }
603 603
604 604 /* Pull out the strings. */
605 605 {
606 606 char **pp = &cur_strs->strs._back_tab;
607 607 char **fp = &cur_strs->strs4.Sentinel;
608 608 #ifdef DUMPTI
609 609 int tempindex = 0;
610 610 char *startstr = ip + sizeof (short) *
611 611 nstrs;
612 612
613 613 printf("string table = '");
614 614 _Mprint(sstrtab, startstr);
615 615 printf("'\n");
616 616 #endif /* DUMPTI */
617 617
618 618 while (nstrs--) {
619 619 n = _Getshi();
620 620 #ifdef DUMPTI
621 621 Vr2val = _Vr2getshi();
622 622 printf("String %s [%s] (%s) offset = %d [%d]",
623 623 strfnames[tempindex], strnames[tempindex],
624 624 strcodes[tempindex], n, Vr2val);
625 625 tempindex++;
626 626 #endif /* DUMPTI */
627 627 if (pp < fp) {
628 628 #ifdef DUMPTI
629 629 _Sprint(n, startstr+n);
630 630 #endif /* DUMPTI */
631 631 if (n < 0)
632 632 *pp++ = NULL;
633 633 else
634 634 *pp++ = strtab + n;
635 635 }
636 636 #ifdef DUMPTI
637 637 else
638 638 _Sprint(-1, (char *)0);
639 639 #endif /* DUMPTI */
640 640 }
641 641 if (pp < fp)
642 642 (void) memset((char *)pp, 0, ((fp - pp) * sizeof (charptr)));
643 643 }
644 644
645 645 (void) memcpy(strtab, ip, sstrtab);
646 646
647 647 #ifndef DUMPTI
648 648
649 649 /*
650 650 * If tabs are being expanded in software, turn this off
651 651 * so output won't get messed up. Also, don't use tab
652 652 * or backtab, even if the terminal has them, since the
653 653 * user might not have hardware tabs set right.
654 654 */
655 655 #ifdef SYSV
656 656 if ((PROGTTYS.c_oflag & TABDLY) == TAB3) {
657 657 PROGTTYS.c_oflag &= ~TABDLY;
658 658 (void) reset_prog_mode();
659 659 goto next;
660 660 }
661 661 #else /* SYSV */
662 662 if ((PROGTTY.sg_flags & XTABS) == XTABS) {
663 663 PROGTTY.sg_flags &= ~XTABS;
664 664 (void) reset_prog_mode();
665 665 goto next;
666 666 }
667 667 #endif /* SYSV */
668 668 if (dest_tabs_magic_smso) {
669 669 next:
670 670 cur_strs->strs2._tab = cur_strs->strs._back_tab = NULL;
671 671 }
672 672
673 673 #ifdef LTILDE
674 674 ioctl(cur_term -> Filedes, TIOCLGET, &n);
675 675 #endif /* LTILDE */
676 676 #endif /* DUMPTI */
677 677
678 678 #ifdef _VR2_COMPAT_CODE
679 679 (void) memcpy(&cur_term->_b1, &cur_bools->_auto_left_margin,
680 680 (char *)&cur_term->_c1 - (char *)&cur_term->_b1);
681 681 (void) memcpy((char *)&cur_term->_c1, (char *)&cur_nums->_columns,
682 682 (char *)&cur_term->_Vr2_Astrs._s1 - (char *)&cur_term->_c1);
683 683 (void) memcpy((char *)&cur_term->_Vr2_Astrs._s1,
684 684 (char *)&cur_strs->strs._back_tab,
685 685 (char *)&cur_term->Filedes - (char *)&cur_term->_Vr2_Astrs._s1);
686 686 #endif /* _VR2_COMPAT_CODE */
687 687
688 688 on_sequences = cur_term->turn_on_seq;
689 689 str_array = (char **)cur_strs;
690 690 {
691 691 static char offsets[] = {
692 692 35, /* enter_standout_mode, */
693 693 36, /* enter_underline_mode, */
694 694 25, /* enter_alt_charset_mode, */
695 695 34, /* enter_reverse_mode, */
696 696 26, /* enter_blink_mode, */
697 697 30, /* enter_dim_mode, */
698 698 27, /* enter_bold_mode, */
699 699 32, /* enter_secure_mode, */
700 700 33, /* enter_protected_mode, */
701 701 };
702 702
703 703 for (n = 0; n < NUM_ATTRIBUTES; n++) {
704 704 if ((on_sequences[n] = str_array[offsets[n]]) != 0)
705 705 cur_term->bit_vector |= bit_attributes[n];
706 706 }
707 707 }
708 708
709 709 if (!(set_attributes)) {
710 710 static char faked_attrs[] = { 1, 3, 4, 6 },
711 711 offsets[] = {
712 712 43, /* exit_standout_mode, */
713 713 44, /* exit_underline_mode, */
714 714 38, /* exit_alt_charset_mode, */
715 715 };
716 716 char **off_sequences = cur_term->turn_off_seq;
717 717 int i;
718 718
719 719 if ((max_attributes == -1) && (ceol_standout_glitch ||
720 720 (magic_cookie_glitch >= 0)))
721 721 max_attributes = 1;
722 722
723 723 /* Figure out what attributes need to be faked. */
724 724 /* See vidupdate.c */
725 725
726 726 for (n = 0; n < sizeof (faked_attrs); n++) {
727 727 if (on_sequences[0] != NULL) {
728 728 if ((!on_sequences[i = faked_attrs[n]]) ||
729 729 (strcmp(on_sequences[i],
730 730 on_sequences[0]) == 0)) {
731 731 cur_term->sgr_faked |=
732 732 bit_attributes[i];
733 733 }
734 734 } else {
735 735 if (!on_sequences[i = faked_attrs[n]]) {
736 736 cur_term->sgr_faked |=
737 737 bit_attributes[i];
738 738 }
739 739 }
740 740 }
741 741
742 742 cur_term->check_turn_off = A_STANDOUT | A_UNDERLINE |
743 743 A_ALTCHARSET;
744 744
745 745 for (n = 0; n < sizeof (offsets); n++) {
746 746 if ((!(off_sequences[n] = str_array[offsets[n]])) ||
747 747 ((n > 0) && off_sequences[0] &&
748 748 (strcmp(off_sequences[n], off_sequences[0]) ==
749 749 0)) || ((n == 2) && (exit_attribute_mode) &&
750 750 (strcmp(exit_attribute_mode, off_sequences[n]) ==
751 751 0))) {
752 752 cur_term->check_turn_off &= ~bit_attributes[n];
753 753 }
754 754 }
755 755 }
756 756 cur_term->cursor_seq[0] = cursor_invisible;
757 757 cur_term->cursor_seq[1] = cursor_normal;
758 758 cur_term->cursor_seq[2] = cursor_visible;
759 759 cur_term->_pairs_tbl = (_Color_pair *) NULL;
760 760 cur_term->_color_tbl = (_Color *) NULL;
761 761
762 762 return (OK);
763 763 }
764 764
765 765 void
766 766 _blast_keys(TERMINAL *terminal)
767 767 {
768 768 terminal->_keys = NULL;
769 769 terminal->internal_keys = NULL;
770 770 terminal->_ksz = terminal->_first_macro = 0;
771 771 terminal->_lastkey_ordered = terminal->_lastmacro_ordered = -1;
772 772 (void) memset((char *)terminal->funckeystarter, 0, 0400 *
773 773 sizeof (bool));
774 774 }
775 775
776 776 #ifndef DUMPTI
777 777
778 778 int
779 779 reset_prog_mode(void)
780 780 {
781 781 #ifdef SYSV
782 782 if (_BRS(PROGTTYS)) {
783 783 if (prog_istermios < 0) {
784 784 int i;
785 785
786 786 PROGTTY.c_lflag = PROGTTYS.c_lflag;
787 787 PROGTTY.c_oflag = PROGTTYS.c_oflag;
788 788 PROGTTY.c_iflag = PROGTTYS.c_iflag;
789 789 PROGTTY.c_cflag = PROGTTYS.c_cflag;
790 790 for (i = 0; i < NCC; i++)
791 791 PROGTTY.c_cc[i] = PROGTTYS.c_cc[i];
792 792 (void) ioctl(cur_term -> Filedes, TCSETAW, &PROGTTY);
793 793 } else
794 794 (void) ioctl(cur_term -> Filedes, TCSETSW, &PROGTTYS);
795 795 }
796 796 #else /* SYSV */
797 797 if (_BR(PROGTTY))
798 798 (void) ioctl(cur_term -> Filedes, TIOCSETN, &PROGTTY);
799 799 #endif /* SYSV */
800 800
801 801 #ifdef LTILDE
802 802 ioctl(cur_term -> Filedes, TIOCLGET, &cur_term -> oldlmode);
803 803 cur_term -> newlmode = cur_term -> oldlmode & ~LTILDE;
804 804 if (cur_term -> newlmode != cur_term -> oldlmode)
805 805 ioctl(cur_term -> Filedes, TIOCLSET, &cur_term -> newlmode);
806 806 #endif /* LTILDE */
807 807 #ifdef DIOCSETT
808 808 if (cur_term -> old.st_termt == 0)
809 809 ioctl(cur_term->Filedes, DIOCGETT, &cur_term -> old);
810 810 cur_term -> new = cur_term -> old;
811 811 cur_term -> new.st_termt = 0;
812 812 cur_term -> new.st_flgs |= TM_SET;
813 813 ioctl(cur_term->Filedes, DIOCSETT, &cur_term -> new);
814 814 #endif /* DIOCSETT */
815 815 return (OK);
816 816 }
817 817
818 818 int
819 819 def_shell_mode(void)
820 820 {
821 821 #ifdef SYSV
822 822 if ((shell_istermios =
823 823 ioctl(cur_term -> Filedes, TCGETS, &SHELLTTYS)) < 0) {
824 824 int i;
825 825
826 826 (void) ioctl(cur_term -> Filedes, TCGETA, &SHELLTTY);
827 827 SHELLTTYS.c_lflag = SHELLTTY.c_lflag;
828 828 SHELLTTYS.c_oflag = SHELLTTY.c_oflag;
829 829 SHELLTTYS.c_iflag = SHELLTTY.c_iflag;
830 830 SHELLTTYS.c_cflag = SHELLTTY.c_cflag;
831 831 for (i = 0; i < NCC; i++)
832 832 SHELLTTYS.c_cc[i] = SHELLTTY.c_cc[i];
833 833 }
834 834 #else /* SYSV */
835 835 (void) ioctl(cur_term -> Filedes, TIOCGETP, &SHELLTTY);
836 836 #endif /* SYSV */
837 837 return (OK);
838 838 }
839 839
840 840 #endif /* DUMPTI */
|
↓ open down ↓ |
840 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX