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